PageRenderTime 64ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/WpfApp4/ExtractStyles.cs

https://bitbucket.org/csereat/visualconfigui
C# | 739 lines | 581 code | 128 blank | 30 comment | 145 complexity | d7a86080188b3ec7ddc960a5a28e83be MD5 | raw file
  1. using DocumentFormat.OpenXml.Packaging;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Dynamic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Security.Cryptography;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Controls;
  14. using System.Xml;
  15. using System.Xml.Linq;
  16. using WpfApp4.Properties;
  17. namespace WpfApp4
  18. {
  19. class ExtractStyles
  20. {
  21. static List<string> ExcludedElements = new List<string> { "rsid", "docId" };
  22. static List<string> ExcludedAttributes = new List<string> { "settings", "sectPr"};
  23. dynamic JsonrootElement;
  24. StyleDicList _StyleDicList;
  25. public void extractStyles(string filenamewpath,TextBox resultBox, List<string> stlList, List<string> tblList, List<List<string>> Lists, string Config, StyleDicList _StyleDicList)
  26. {
  27. this._StyleDicList = _StyleDicList;
  28. JsonrootElement = new ExpandoObject();
  29. string path = Path.Combine(Settings.Default.ConfigPath, Config);
  30. var assembly = Assembly.GetExecutingAssembly();
  31. string result = "";
  32. List<ExpandoObject> JsonList = new List<ExpandoObject>();
  33. var resourceName = "WpfApp4.dictionary.ooxml_interop.txt";
  34. using (Stream stream = assembly.GetManifestResourceStream(resourceName))
  35. using (StreamReader reader = new StreamReader(stream))
  36. {
  37. result = reader.ReadToEnd();
  38. }
  39. dynamic O2IDictionary = JObject.Parse(result);
  40. #region FileDefinition
  41. resultBox.AppendText("Extracting file settings..." + Environment.NewLine);
  42. JsonrootElement.FileDefinitionPart = new ExpandoObject();
  43. #region Document Part - sections
  44. XDocument ExtractedDocument = ExtractPart(filenamewpath, "document", false);
  45. XNamespace ns = ExtractedDocument.Root.GetNamespaceOfPrefix("w");
  46. JsonList = new List<ExpandoObject>();
  47. foreach (XElement section in ExtractedDocument.Root.Descendants(ns + "sectPr"))
  48. {
  49. ProcessElements(section, JsonrootElement.FileDefinitionPart, O2IDictionary.document.sectPr, null, JsonList);
  50. }
  51. #endregion
  52. #region Document Part - TOC and fields
  53. var FDPart = (IDictionary<string, Object>)JsonrootElement.FileDefinitionPart;
  54. IList<string> FieldFormats = new List<string>();
  55. XElement prevParent = ExtractedDocument.Root;
  56. string prevNodeValue ="";
  57. foreach (XElement itext in ExtractedDocument.Root.Descendants(ns + "instrText"))
  58. {
  59. if (itext.Value.Length>=8 && itext.Value.Substring(0, 8) != " PAGEREF")
  60. {
  61. if (itext.Parent == prevParent)
  62. {
  63. FieldFormats[FieldFormats.Count - 1] = FieldFormats.Last().Replace(FieldFormats.Last(), FieldFormats.Last() + "|" + itext.Value);
  64. }
  65. else
  66. {
  67. if (!FieldFormats.Contains(itext.Value))
  68. {
  69. FieldFormats.Add(itext.Value);
  70. }
  71. }
  72. prevParent = itext.Parent;
  73. }
  74. }
  75. prevParent = ExtractedDocument.Root;
  76. string NodeValue;
  77. foreach (XElement itext in ExtractedDocument.Root.Descendants(ns + "fldSimple"))
  78. {
  79. if (itext.Parent == prevParent)
  80. {
  81. FieldFormats[FieldFormats.Count-1] = FieldFormats.Last().Replace(FieldFormats.Last(), FieldFormats.Last() + "|" + itext.Attribute(ns + "instr").Value);
  82. }
  83. else
  84. {
  85. if (!FieldFormats.Contains(itext.Attribute(ns + "instr").Value))
  86. {
  87. FieldFormats.Add(itext.Attribute(ns + "instr").Value);
  88. }
  89. }
  90. prevParent = itext.Parent;
  91. }
  92. if (FieldFormats.Count != 0)
  93. FDPart.Add("FieldFormats", FieldFormats.Distinct());
  94. List<CaptionConfig> captionConfigList = new List<CaptionConfig>();
  95. foreach (string field in FieldFormats)
  96. {
  97. if (field.Contains("TOC")) // table of contents - tempTOC
  98. {
  99. }
  100. else if (field.Contains("SEQ")) //captionconfig
  101. {
  102. CaptionConfig tempcc = new CaptionConfig();
  103. if (field.Contains("STYLEREF"))
  104. {
  105. tempcc.IncludeChapterNumber = true;
  106. tempcc.ChapterStyleLevel = Convert.ToInt32(field.Substring(10,1));
  107. }
  108. captionConfigList.Add(tempcc);
  109. }
  110. }
  111. #endregion
  112. #region Table List
  113. Dictionary<string, List<TableView>> TableViewList = new Dictionary<string, List<TableView>>();
  114. int viewInd=0;
  115. foreach (XElement tablePrNode in ExtractedDocument.Root.Descendants(ns + "tblPr"))
  116. {
  117. string ActTableStyleName = "";
  118. foreach (XElement childNode in tablePrNode.Nodes())
  119. {
  120. if (childNode.Name == ns + "tblStyle")
  121. {
  122. ActTableStyleName = childNode.Attribute(ns + "val").Value;
  123. if (!tblList.Any(s => ActTableStyleName.Contains(s)))
  124. {
  125. tblList.Add(ActTableStyleName); //xmlstyleID
  126. if (!TableViewList.Keys.Contains(ActTableStyleName))
  127. {
  128. TableViewList.Add(ActTableStyleName, new List<TableView>());
  129. }
  130. }
  131. }
  132. if ((childNode.Name == ns + "tblLook"))
  133. {
  134. viewInd++;
  135. TableView tempView = new TableView();
  136. tempView.ViewName = "TableView" + viewInd;
  137. foreach (XAttribute xat in childNode.Attributes())
  138. {
  139. if (xat.Name == ns + "firstRow") { tempView.HeaderRow = xat.Value; }
  140. if (xat.Name == ns + "lastRow") { tempView.TotalRow = xat.Value; }
  141. if (xat.Name == ns + "firstColumn") { tempView.FirstColumn = xat.Value; }
  142. if (xat.Name == ns + "lastColumn") { tempView.LastColumn = xat.Value; }
  143. if (xat.Name == ns + "noHBand") { tempView.BandedRows = xat.Value; }
  144. if (xat.Name == ns + "noVBand") { tempView.BandedColumns = xat.Value; }
  145. }
  146. TableViewList[ActTableStyleName].Add(tempView);
  147. }
  148. }
  149. }
  150. #endregion
  151. #region Settings Part
  152. XDocument ExtractedSettings = ExtractPart(filenamewpath, "settings", false);
  153. ns = ExtractedSettings.Root.GetNamespaceOfPrefix("w");
  154. if (ExtractedSettings != null)
  155. ProcessElements(ExtractedSettings.Root, JsonrootElement.FileDefinitionPart, O2IDictionary.settings, null, new List<ExpandoObject>());
  156. #endregion
  157. #region Numbering Extract
  158. resultBox.AppendText("Extracting numberings..." + Environment.NewLine);
  159. XDocument ExtractedNumbering = ExtractPart(filenamewpath, "numbering", false);
  160. JsonList = new List<ExpandoObject>();
  161. bool LinkedListTemplateFound = false;
  162. if (ExtractedNumbering != null)
  163. {
  164. ns = ExtractedNumbering.Root.GetNamespaceOfPrefix("w");
  165. foreach (XElement rootElement in ExtractedNumbering.Root.Elements(ns + "abstractNum"))
  166. {
  167. foreach (XElement listlevel in rootElement.Elements(ns + "lvl").Elements(ns + "pStyle"))
  168. {
  169. LinkedListTemplateFound = true;
  170. }
  171. if (LinkedListTemplateFound)
  172. {
  173. ProcessElements(rootElement, JsonrootElement.FileDefinitionPart, O2IDictionary.numbering, null, JsonList);
  174. LinkedListTemplateFound = false;
  175. }
  176. }
  177. }
  178. int i = 0;
  179. foreach (dynamic _ListTemplate in JsonList)
  180. {
  181. // dynamic _ListTemplate = _ListTemplate1;
  182. if (_ListTemplate.multiLevelType == "OutlineNumbered" || _ListTemplate.multiLevelType == "hybridmulti")
  183. {
  184. i = 0;
  185. List<string> NumberedStyles = new List<string>();
  186. List<string> BulletedStyles = new List<string>();
  187. IDictionary<string, Object> _listLevel = _ListTemplate.ListLevel[i];
  188. while (_listLevel.ContainsKey("LinkedStyle") &&
  189. (_ListTemplate.ListLevel[i].NumberStyle == "wdListNumberStyleBullet"))
  190. {
  191. if (i == 0)
  192. {
  193. BulletedStyles.Add("BulletedList");
  194. }
  195. BulletedStyles.Add(_ListTemplate.ListLevel[i].LinkedStyle);
  196. i++;
  197. if (i > 4)
  198. break;
  199. _listLevel = _ListTemplate.ListLevel[i];
  200. }
  201. if (i > 1)
  202. Lists.Add(BulletedStyles);
  203. i = 0;
  204. while (_listLevel.ContainsKey("LinkedStyle") &&
  205. (_ListTemplate.ListLevel[i].NumberStyle != "wdListNumberStyleBullet"))
  206. {
  207. if (i == 0)
  208. {
  209. NumberedStyles.Add("NumberedList");
  210. }
  211. NumberedStyles.Add(_ListTemplate.ListLevel[i].LinkedStyle);
  212. i++;
  213. if (i > 4)
  214. break;
  215. _listLevel = _ListTemplate.ListLevel[i];
  216. }
  217. if (i > 1)
  218. Lists.Add(NumberedStyles);
  219. }
  220. }
  221. #endregion
  222. #endregion
  223. #region Theme Extract
  224. XDocument ExtractedThemes = ExtractPart(filenamewpath, "theme", false);
  225. ns = ExtractedThemes.Root.GetNamespaceOfPrefix("a");
  226. resultBox.AppendText("Extracting color scheme..." + Environment.NewLine);
  227. XElement ColorScheme = ExtractedThemes.Root.Element(ns + "themeElements").Element(ns + "clrScheme");
  228. resultBox.AppendText("Extracting font scheme..." + Environment.NewLine);
  229. XElement FontScheme = ExtractedThemes.Root.Element(ns + "themeElements").Element(ns + "fontScheme");
  230. resultBox.AppendText("Extracting effects scheme..." + Environment.NewLine);
  231. XElement EffectScheme = ExtractedThemes.Root.Element(ns + "themeElements").Element(ns + "fmtScheme");
  232. string XMLDeclaration = ExtractedThemes.Declaration.ToString();
  233. if (Directory.Exists(path)) Directory.Delete(path, true);
  234. Directory.CreateDirectory(path);
  235. File.WriteAllText(path + @"\color.theme", XMLDeclaration + Environment.NewLine + ColorScheme.ToString());
  236. File.WriteAllText(path + @"\font.theme", XMLDeclaration + Environment.NewLine + FontScheme.ToString());
  237. File.WriteAllText(path + @"\effect.theme", XMLDeclaration + Environment.NewLine + EffectScheme.ToString());
  238. #endregion
  239. #region StyleExtract
  240. resultBox.AppendText("Extracting styles..." + Environment.NewLine);
  241. XDocument ExtractedStyles = ExtractPart(filenamewpath, "styles", false);
  242. ns = ExtractedStyles.Root.GetNamespaceOfPrefix("w");
  243. JsonList = new List<ExpandoObject>();
  244. if (ExtractedStyles != null)
  245. {
  246. JsonrootElement.StyleDefinitionPart = new ExpandoObject();
  247. int ind = 1;
  248. #region Font and Paragraph Defaults
  249. if (ExtractedStyles.Root.Element(ns + "docDefaults") != null)
  250. {
  251. ProcessElements(ExtractedStyles.Root.Element(ns + "docDefaults"), JsonrootElement.FileDefinitionPart, O2IDictionary.docDefaults, null, new List<ExpandoObject>());
  252. }
  253. #endregion
  254. foreach (XElement rootElement in ExtractedStyles.Root.Elements(ns + "style"))
  255. {
  256. if (EnableStyleToExtract(rootElement.Element(ns + "name").Attribute(ns + "val").Value, rootElement, ns))
  257. {
  258. //LogToFile("***************Processing style: " + rootElement.Attribute(ns + "styleId").Value + "******************");
  259. ProcessElements(rootElement, JsonrootElement.StyleDefinitionPart, O2IDictionary.style, null, JsonList);
  260. StyleNameInfo _StyleNameInfo = new StyleNameInfo();
  261. _StyleNameInfo.StyleIndex = ind.ToString();
  262. _StyleNameInfo.XmlName = rootElement.Element(ns + "name").Attribute(ns + "val").Value;
  263. _StyleNameInfo.XmlStyleID = rootElement.Attribute(ns + "styleId").Value;
  264. _StyleNameInfo.BuiltinStyleName = JsonList[ind - 1].FirstOrDefault(x => x.Key == "BuiltinStyleName").Value.ToString();
  265. if (_StyleNameInfo.BuiltinStyleName.Contains("Accent") == true)
  266. {
  267. _StyleNameInfo.BuiltinStyleName = _StyleNameInfo.BuiltinStyleName.Replace(" Accent", " - Accent");
  268. }
  269. //_StyleNameInfo.XmlStyleID_BaseStyle = rootElement.Element(ns + "name")
  270. _StyleNameInfo.PreferredStyle = "Not Applicable";
  271. _StyleNameInfo.StyleDescription = "Not Applicable";
  272. // if (_StyleNameInfo.BuiltinStyleName.Substring(0, 2) != "wd") _StyleNameInfo.BuiltinStyleName = JsonList;
  273. _StyleDicList.StyleNameList.Add(_StyleNameInfo);
  274. //Dropdown list
  275. if (rootElement.Attribute(ns+"type").Value == "paragraph" || rootElement.Attribute(ns + "type").Value == "character") stlList.Add(_StyleNameInfo.XmlName);
  276. ind++;
  277. }
  278. }
  279. }
  280. #endregion
  281. //JsonrootElement.StyleDefinitions;
  282. //
  283. //File.WriteAllText(path + @"\StyleListDic.txt", JsonConvert.SerializeObject(_StyleDicList, Newtonsoft.Json.Formatting.Indented));
  284. // WriteConfig(path);
  285. resultBox.AppendText("Completed." + Environment.NewLine);
  286. resultBox.ScrollToEnd();
  287. }
  288. public List<string> InheritanceList(List<string> SelectedStyles)
  289. {
  290. string BaseStyle;
  291. List<string> StylesToExport = new List<string>();
  292. foreach (string StyleName in SelectedStyles)
  293. {
  294. BaseStyle = StyleName;
  295. while (BaseStyle != "")
  296. {
  297. IDictionary<string, Object> _Style = JsonrootElement.StyleDefinitionPart.StyleSettings[Convert.ToInt32(_StyleDicList.StyleNameList.FirstOrDefault(x => x.XmlStyleID == BaseStyle).StyleIndex)-1];
  298. if (_Style.ContainsKey("BaseStyle"))
  299. {
  300. if (!StylesToExport.Contains(BaseStyle)) StylesToExport.Add(BaseStyle);
  301. BaseStyle = _Style.FirstOrDefault(x => x.Key == "BaseStyle").Value.ToString();
  302. }
  303. else
  304. {
  305. if (!StylesToExport.Contains(BaseStyle)) StylesToExport.Add(BaseStyle);
  306. BaseStyle = "";
  307. }
  308. }
  309. }
  310. return StylesToExport;
  311. }
  312. public void RemoveStylesFromJSON(List<string> SelectedStyles)
  313. {
  314. List<string> StylesToInclude = InheritanceList(SelectedStyles);
  315. int i = 0;
  316. while (i < JsonrootElement.StyleDefinitionPart.StyleSettings.Count)
  317. {
  318. if (JsonrootElement.StyleDefinitionPart.StyleSettings[i].StyleType.ToString() == "wdStyleTypeTable" &&
  319. !StylesToInclude.Contains(JsonrootElement.StyleDefinitionPart.StyleSettings[i].StyleID))
  320. {
  321. List<ExpandoObject> _styles = JsonrootElement.StyleDefinitionPart.StyleSettings;
  322. _StyleDicList.StyleNameList.RemoveAt(i);
  323. _styles.RemoveAt(i);
  324. }
  325. else { i++; }
  326. }
  327. int index = 1;
  328. foreach (dynamic tmpStl in _StyleDicList.StyleNameList)
  329. {
  330. tmpStl.StyleIndex = index.ToString();
  331. index++;
  332. }
  333. }
  334. public void WriteConfig(string path)
  335. {
  336. string DicJson = JsonConvert.SerializeObject(JsonrootElement, Newtonsoft.Json.Formatting.Indented);
  337. File.WriteAllText(path + @"\config.txt", EncryptFile(DicJson));
  338. //File.WriteAllText(path + @"\config_notEncrypted.txt", DicJson);
  339. }
  340. public static XDocument ExtractPart(string fileName, string part2extract, bool getStylesWithEffectsPart = true)
  341. {
  342. XDocument part = null;
  343. using (var document = WordprocessingDocument.Open(fileName, false))
  344. {
  345. var docPart = document.MainDocumentPart;
  346. if (part2extract == "styles")
  347. {
  348. StylesPart stylesPart = null;
  349. if (getStylesWithEffectsPart)
  350. stylesPart = docPart.StylesWithEffectsPart;
  351. else
  352. stylesPart = docPart.StyleDefinitionsPart;
  353. if (stylesPart != null)
  354. {
  355. using (var reader = XmlNodeReader.Create(stylesPart.GetStream(FileMode.Open, FileAccess.Read)))
  356. {
  357. part = XDocument.Load(reader);
  358. }
  359. }
  360. }
  361. if (part2extract == "numbering")
  362. {
  363. NumberingDefinitionsPart numberingPart = null;
  364. numberingPart = docPart.NumberingDefinitionsPart;
  365. if (numberingPart != null)
  366. {
  367. using (var reader = XmlNodeReader.Create(numberingPart.GetStream(FileMode.Open, FileAccess.Read)))
  368. {
  369. part = XDocument.Load(reader);
  370. }
  371. }
  372. }
  373. if (part2extract == "settings")
  374. {
  375. DocumentSettingsPart settingsPart = null;
  376. settingsPart = docPart.DocumentSettingsPart;
  377. if (settingsPart != null)
  378. {
  379. using (var reader = XmlNodeReader.Create(settingsPart.GetStream(FileMode.Open, FileAccess.Read)))
  380. {
  381. part = XDocument.Load(reader);
  382. }
  383. }
  384. }
  385. if (part2extract == "theme")
  386. {
  387. ThemePart themePart = null;
  388. themePart = docPart.ThemePart;
  389. if (themePart != null)
  390. {
  391. using (var reader = XmlNodeReader.Create(themePart.GetStream(FileMode.Open, FileAccess.Read)))
  392. {
  393. part = XDocument.Load(reader);
  394. }
  395. }
  396. }
  397. if (part2extract == "document")
  398. {
  399. if (docPart != null)
  400. {
  401. using (var reader = XmlNodeReader.Create(docPart.GetStream(FileMode.Open, FileAccess.Read)))
  402. {
  403. part = XDocument.Load(reader);
  404. }
  405. }
  406. }
  407. }
  408. return part;
  409. }
  410. public static bool EnableStyleToExtract(string StyleXmlName, XElement rootElement, XNamespace ns)
  411. {
  412. if (StyleXmlName.Length > 4)
  413. if (StyleXmlName.Substring(StyleXmlName.Length - 4) == "Char" && rootElement.Attribute(ns + "type").Value == "character" && rootElement.Elements(ns + "link").Any())
  414. {
  415. return false;
  416. }
  417. return true;
  418. }
  419. public static void ProcessElements(XElement ActualElement, ExpandoObject JsonElement, dynamic O2IDictionaryPart, string OldSequenceValue, List<ExpandoObject> JsonList)
  420. {
  421. var xJsonElement = (IDictionary<string, Object>)JsonElement;
  422. //LogToFile("Processing ActualElement: " + ActualElement.Name.LocalName);
  423. bool SequenceElement;
  424. string SequenceValue = null;
  425. string ActualElementSequenceValue = null;
  426. string ElementInteropValue = O2IDictionaryPart.interop;
  427. //LogToFile("Interop name of the Actual XElement(ElementInteropValue): " + ElementInteropValue);
  428. bool Elementskipped = false;
  429. dynamic NextJsonElement = new ExpandoObject();
  430. var xNextJsonElement = (IDictionary<string, Object>)NextJsonElement;
  431. if (O2IDictionaryPart.GetValue("sequence") != null)
  432. {
  433. SequenceElement = true;
  434. SequenceValue = O2IDictionaryPart.GetValue("sequence");
  435. ActualElementSequenceValue = SequenceValue;
  436. }
  437. else
  438. {
  439. SequenceElement = false;
  440. }
  441. //LogToFile("List(SequenceElement): " + SequenceElement.ToString());
  442. if (SequenceElement)
  443. {
  444. JsonList.Add(NextJsonElement);
  445. ////LogToFile("Adding next JSON node to List");
  446. }
  447. else
  448. {
  449. if (ElementInteropValue != "")
  450. {
  451. xJsonElement.Add(ElementInteropValue, xNextJsonElement);
  452. ////LogToFile("Adding next JSON node to Object");
  453. }
  454. else
  455. {
  456. Elementskipped = true;
  457. // //LogToFile("Skipping main element");
  458. }
  459. }
  460. ////LogToFile("Checking attributes...");
  461. if (ActualElement.HasAttributes)
  462. if (!ExcludedAttributes.Any(s => ActualElement.Name.LocalName.Contains(s)))
  463. // ActualElement.Name.LocalName.ToString() != "settings" && ActualElement.Name.LocalName.ToString() != "sectPr")
  464. {
  465. ////LogToFile("Actual Element has attributes");
  466. foreach (XAttribute Xat in ActualElement.Attributes())
  467. {
  468. //LogToFile("Processing attribute: " + ActualElement.Name.LocalName + @"\@" + Xat.Name.LocalName);
  469. dynamic AttributeInterop = O2IDictionaryPart.GetValue("@" + Xat.Name.LocalName);
  470. dynamic AttributeInteropValue;
  471. if (AttributeInterop.ToString() == "" || AttributeInterop.interop == "")
  472. {
  473. AttributeInterop = O2IDictionaryPart;
  474. AttributeInteropValue = Xat.Value;
  475. xJsonElement[AttributeInterop.interop.ToString()] = AttributeInteropValue.ToString();
  476. }
  477. else
  478. {
  479. AttributeInteropValue = AttributeInterop.GetValue(Xat.Value);
  480. if (AttributeInteropValue == null) AttributeInteropValue = Xat.Value;
  481. if (Elementskipped)
  482. {
  483. xJsonElement.Add(AttributeInterop.interop.ToString(), AttributeInteropValue.ToString());
  484. }
  485. else
  486. {
  487. xNextJsonElement.Add(AttributeInterop.interop.ToString(), AttributeInteropValue.ToString());
  488. }
  489. }
  490. }
  491. //LogToFile("Building JSON object: \r\n Attribute:" + AttributeInterop.interop.ToString() + "\r\n Value: " + AttributeInteropValue.ToString());
  492. }
  493. else
  494. {
  495. ////LogToFile("Actual Element has NO attributes");
  496. }
  497. ////LogToFile("Checking child elements...");
  498. if (ActualElement.HasElements)
  499. {
  500. List<ExpandoObject> NextJsonList = new List<ExpandoObject>();
  501. ////LogToFile("Actual Element has child element(s)");
  502. foreach (XElement ChildElement in ActualElement.Elements())
  503. {
  504. //LogToFile("Processing child element(s): " + ActualElement.Name.LocalName + @"\" + ChildElement.Name.LocalName);
  505. dynamic NextO2IDictionaryPart = O2IDictionaryPart.GetValue(ChildElement.Name.LocalName);
  506. if (NextO2IDictionaryPart != null && !ExcludedElements.Any(s => ChildElement.Name.LocalName.Contains(s)))
  507. //if (!ExcludedElements.Any(s => ChildElement.Name.LocalName.Contains(s)))
  508. {
  509. //dynamic NextO2IDictionaryPart = O2IDictionaryPart.GetValue(ChildElement.Name.LocalName);
  510. string nextSequenceValue = NextO2IDictionaryPart.GetValue("sequence");
  511. if (ActualElementSequenceValue != null && nextSequenceValue != null)
  512. {
  513. ProcessElements(ChildElement, NextJsonElement, NextO2IDictionaryPart, SequenceValue, NextJsonList);
  514. }
  515. else if ((SequenceValue == nextSequenceValue && nextSequenceValue != null) || (SequenceValue == null && nextSequenceValue != null))
  516. {
  517. ProcessElements(ChildElement, NextJsonElement, NextO2IDictionaryPart, SequenceValue, JsonList);
  518. }
  519. else if (nextSequenceValue != SequenceValue && nextSequenceValue != null)
  520. {
  521. JsonList = new List<ExpandoObject>();
  522. ProcessElements(ChildElement, NextJsonElement, NextO2IDictionaryPart, SequenceValue, JsonList);
  523. }
  524. else
  525. {
  526. ProcessElements(ChildElement, NextJsonElement, NextO2IDictionaryPart, SequenceValue, new List<ExpandoObject>());
  527. }
  528. SequenceValue = NextO2IDictionaryPart.GetValue("sequence");
  529. }
  530. else
  531. {
  532. // //LogToFile("Element skipped");
  533. }
  534. };
  535. }
  536. else
  537. {
  538. ////LogToFile("ActualElement has NO child element.");
  539. }
  540. if (!ActualElement.HasAttributes && !ActualElement.HasElements)
  541. {
  542. xJsonElement[ElementInteropValue] = "1";
  543. }
  544. if (SequenceElement)
  545. {
  546. xJsonElement[ElementInteropValue] = JsonList;
  547. }
  548. }
  549. public string EncryptFile(string plainContent)
  550. {
  551. string key = Settings.Default.Config + Settings.Default.ApplicationName;
  552. if (key.Length > 8)
  553. key = key.Substring(0, 8);
  554. else
  555. key = (key + "!@#$%^&*").Substring(0, 8);
  556. byte[] plainContentbytes = Encoding.UTF8.GetBytes(plainContent);
  557. using (var DES = new DESCryptoServiceProvider())
  558. {
  559. DES.IV = Encoding.UTF8.GetBytes(key);
  560. DES.Key = Encoding.UTF8.GetBytes(key);
  561. DES.Mode = CipherMode.CBC;
  562. DES.Padding = PaddingMode.PKCS7;
  563. using (var memStream = new MemoryStream())
  564. {
  565. CryptoStream cryptoStream = new CryptoStream(memStream, DES.CreateEncryptor(), CryptoStreamMode.Write);
  566. cryptoStream.Write(plainContentbytes, 0, plainContentbytes.Length);
  567. cryptoStream.FlushFinalBlock();
  568. memStream.Position = 0;
  569. return Convert.ToBase64String(memStream.ToArray());
  570. }
  571. }
  572. }
  573. public class StyleDicList
  574. {
  575. public IList<StyleNameInfo> StyleNameList { get; set; }
  576. }
  577. public class StyleNameInfo
  578. {
  579. public string StyleIndex { get; set; }
  580. public string XmlStyleID { get; set; }
  581. public string XmlName { get; set; }
  582. public string BuiltinStyleName { get; set; }
  583. //public string XmlStyleID_BaseStyle { get; set; }
  584. public bool IsImported { get; set; }
  585. public string PreferredStyle { get; set; }
  586. public string StyleDescription { get; set; }
  587. }
  588. public class TableView
  589. {
  590. public string ViewName { get; set; }
  591. public string HeaderRow { get; set; }
  592. public string FirstColumn { get; set; }
  593. public string TotalRow { get; set; }
  594. public string LastColumn { get; set; }
  595. public string BandedRows { get; set; }
  596. public string BandedColumns { get; set; }
  597. }
  598. public class CaptionConfig
  599. {
  600. public string CaptionType { get; set; }
  601. public List<string> CaptionLabels { get; set; }
  602. public string Position { get; set; }
  603. public string NumberStyle { get; set; }
  604. public bool IncludeChapterNumber { get; set; }
  605. public string Separator { get; set; }
  606. public int ChapterStyleLevel { get; set; }
  607. public string CaptionStyle { get; set; }
  608. public string TableContentStyle { get; set; }
  609. }
  610. }
  611. }