diff --git a/.gitignore b/.gitignore index 874d81c..198dc43 100644 --- a/.gitignore +++ b/.gitignore @@ -353,3 +353,4 @@ MigrationBackup/ *.xlsx *links *db +*/Resources/ diff --git a/Program/ClassDiagram.cd b/Program/ClassDiagram.cd index 36c2609..2dad9ef 100644 --- a/Program/ClassDiagram.cd +++ b/Program/ClassDiagram.cd @@ -1,13 +1,5 @@  - - - - gAIAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAABAA= - DataBase.cs - - - @@ -18,29 +10,28 @@ - AAIAAgQABACAIgAAACAAAAAAAAASUAACAAgAAACgAAA= + AAIAAoQABAAAIgAAACAAAAAIAAASUAAAAAgAAACgAAA= Handler.cs - + - AAAAAAAAAAAAAAQAAAAAAQAACBAAQAgAACAAAAAAAAA= + AAAAAAAAAAAAAAQAAAAAAAAACBAAQAgAACAAAAAAAAA= xmlAdapter.cs - - AAAAAAkAACAAEgBAAAAAAAAAAgAgIABACAAAAAAAAAA= + AAAAoQsAACAgAgBAAAAAAAAAAgEgIABQCAAAAAAAAAA= Platform.cs - AAAIAAAAAAAAAAYIAAAAAAAAAgACAAABAAAFBBBAAAA= + AEAIAAAAAAAAAAYIAAAAAAAAAgADAAABAAGEBBAAAAA= MainWindow.xaml.cs @@ -69,7 +60,7 @@ - AAACAAAAAAACAAAAAAAAAwgAAAAAAACAAgAAAAAAAAA= + AAACAAAAAAACAAAAAAAAAgAAAAAAAACAAgAAAAAAAAA= IDefaultSettings.cs diff --git a/Program/ClassDiagram1.cd b/Program/ClassDiagram1.cd deleted file mode 100644 index a81af13..0000000 --- a/Program/ClassDiagram1.cd +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA= - Content.cs - - - - - - AAAAAQAAACAAAgAAAAEAAAAAAAAAAAAAAAEAAAAUAAA= - Information.xaml.cs - - - - - - - AAIAAoQABAAAIgAAACAAAAAIAAASUAAAAAgAAACgAAA= - Handler.cs - - - - - - AAAAAAAAAAAAAAQAAAAAAAAACBAAQAgAACAAAAAAAAA= - xmlAdapter.cs - - - - - - AAAAAAgAACAggoBAAAAEAAAAAgAAIAAACAAAAAAAAAA= - Platform.cs - - - - - - AAACAAAAAAACAAAAAAAAAgAAAAAAAACAAgAAAAAAAAA= - IDefaultSettings.cs - - - - - - - - \ No newline at end of file diff --git a/Program/Handler.cs b/Program/Handler.cs index 8a7691c..ede1054 100644 --- a/Program/Handler.cs +++ b/Program/Handler.cs @@ -24,21 +24,11 @@ internal class Handler public Handler() { - try - { - _grossWeightQuantity = 0; - _netWeightQuantity = 0; - _positions = 0; - _awb = new List<(string, string)>(); - _data = new List<(string, string)>(); - } - catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } - finally - { - this._grossWeightQuantity = default; - this._netWeightQuantity = default; - this._positions = default; - } + _grossWeightQuantity = 0; + _netWeightQuantity = 0; + _positions = 0; + _awb = new(); + _data = new(); } public List<(string, string)> XmlHandler(in string file) @@ -49,7 +39,8 @@ public Handler() if (File.Exists(file)) document.Load(file); else document.LoadXml(file); } - catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return new List<(string, string)>() { ("Файл повреждён", "Неудалось прочитать файл") }; } + catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return new List<(string, string)>() { ("Файл повреждён", "Неудалось прочитать файл") }; } var book = Open(); @@ -70,7 +61,7 @@ public Handler() break; case "ESADout_CUConsigment": foreach (XmlNode transport in info.ChildNodes) - foreach(XmlNode unused in transport) + foreach (XmlNode unused in transport) Collect(Search("catESAD_cu:TransportIdentifier", info, "Транспорт"), book); break; case "ESADout_CUMainContractTerms": @@ -82,7 +73,10 @@ public Handler() Calc(Search("catESAD_cu:GrossWeightQuantity", info, "Масса брутто").Item2, ref _grossWeightQuantity); Calc(Search("catESAD_cu:NetWeightQuantity", info, "Масса нетто").Item2, ref _netWeightQuantity); break; + default: + break; } + foreach (XmlNode product in info.ChildNodes) { foreach (XmlNode count in product.ChildNodes) @@ -90,6 +84,7 @@ public Handler() foreach (var about in count.Cast().Where(about => about.Name == "catESAD_cu:GoodsGroupQuantity")) Calc(Search("catESAD_cu:GoodsQuantity", about, "Количество товара").Item2, ref _positions); } + foreach (XmlNode doc in info) { if (doc.Name == "ESADout_CUPresentedDocument") @@ -103,15 +98,15 @@ public Handler() } } } - } + } Collect(("Общая масса брутто", this._grossWeightQuantity.ToString(CultureInfo.InvariantCulture)), book); - Collect(("Общая масса нетто", this._netWeightQuantity.ToString(CultureInfo.InvariantCulture)), book); + Collect(("Общая масса нетто", this._netWeightQuantity.ToString(CultureInfo.InvariantCulture)), book); Collect(("Всего позиций", this._positions.ToString(CultureInfo.InvariantCulture)), book); foreach (var pair in _awb.Distinct()) Collect(pair, book); Close(book.Item1); return this._data; } - + //auxiliary methods private static void Close(IWorkbook wb) { @@ -163,6 +158,6 @@ private void Collect((string, string) value, (IWorkbook, ISheet) book) Save(value, book); } private static bool Validation((string, string) value) => !string.IsNullOrWhiteSpace(value.Item1) || !string.IsNullOrWhiteSpace(value.Item2); - + } } diff --git a/Program/IDefaultSettings.cs b/Program/IDefaultSettings.cs index 53a7202..db3792f 100644 --- a/Program/IDefaultSettings.cs +++ b/Program/IDefaultSettings.cs @@ -1,10 +1,19 @@ using System.Collections.Generic; +using System.IO; namespace XmlParser { public interface IDefaultSettings { - const string DefaultPath = "../../../Resources/"; + static string DefaultPath { + get + { + string path = "../../../Resources/"; + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + return path; + } + } static string NameExcelFile => DefaultPath + "declarationInfo.xlsx"; static string IndexFileName => DefaultPath + "links"; static string DataFileName => DefaultPath + "db"; diff --git a/Program/Information.xaml b/Program/Information.xaml index 3404c38..d0fa529 100644 --- a/Program/Information.xaml +++ b/Program/Information.xaml @@ -10,8 +10,7 @@ - + diff --git a/Program/MainWindow.xaml.cs b/Program/MainWindow.xaml.cs index 5829c25..7591060 100644 --- a/Program/MainWindow.xaml.cs +++ b/Program/MainWindow.xaml.cs @@ -14,7 +14,7 @@ public partial class MainWindow private string _fileName; private bool _dataBaseFlag = false; private static void Copy(string text) => Clipboard.SetText(text); - + //получает путь к обрабаываемому файлу private static void GetPath(out string directoryName, out string fileName) { @@ -27,7 +27,7 @@ private static void GetPath(out string directoryName, out string fileName) } catch (Exception exception1) { - if (MessageBox.Show( $"Ошибка - {exception1.HResult}\nНажмите OK чтобы скопировать код ошибки, или нажмите Отмена чтобы переписать самостоятельно", + if (MessageBox.Show($"Ошибка - {exception1.HResult}\nНажмите OK чтобы скопировать код ошибки, или нажмите Отмена чтобы переписать самостоятельно", "Ошибка получения пути", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK) Copy(exception1.HResult.ToString()); @@ -57,11 +57,11 @@ private void SetSource() try { GetPath(out this._directoryName, out this._fileName); - if ( new[] { _directoryName, _fileName }.Any(string.IsNullOrWhiteSpace)) + if (new[] { _directoryName, _fileName }.Any(string.IsNullOrWhiteSpace)) throw new IOException("Null path"); GetFile(); - var declarations = _fileNames.Select(item => new Content - { FileName = item }).ToList(); + var declarations = _fileNames.Select(item => new Content + { FileName = item }).ToList(); Data.ItemsSource = declarations; } @@ -84,14 +84,12 @@ private void Btn_Click(object sender, RoutedEventArgs e) if (Data.SelectedItem is not Content path) return; if (_dataBaseFlag) { - using (XmlAdapter adapter = new()) - { - string path1 = adapter.GetContent(path.FileName); - info = new(path1); - } + using XmlAdapter adapter = new(); + string path1 = adapter.GetContent(path.FileName); + info = new(path1); } else - { + { info = new(path.FileName); AddFile(path.FileName); } @@ -99,28 +97,33 @@ private void Btn_Click(object sender, RoutedEventArgs e) } private static void AddFile(string name) { - using var reader = XmlReader.Create(name); - if (reader.IsEmptyElement) return; - using (XmlAdapter adapter = new()) - { - string xml = ""; - string filename = Path.GetFileName(name); - adapter.CreateLink(xml, filename); - } + using XmlAdapter adapter = new(); + if (adapter.IsLinks(name)) + return; + + XmlDocument document = new(); + document.Load(name); + XmlElement root = document.DocumentElement; + + string xml = root.OuterXml; + string filename = Path.GetFileName(name); + adapter.CreateLink(xml, filename); } - private void OpenFromDatabase() - { - _dataBaseFlag = _dataBaseFlag == false; + private List OpenFromDatabase() + { List contents = new(); - using (XmlAdapter @base = new()) { - var data = @base.GetAllFileNames(); - if(data != default) contents.AddRange(data.Select(para => new Content { FileName = para })); - } - Data.ItemsSource = contents; - Data.Items.Refresh(); + using XmlAdapter @base = new(); + var data = @base.GetAllFileNames(); + if (data != default) contents.AddRange(data.Select(para => new Content { FileName = para })); + return contents; + } + private void Open_Click(object sender, RoutedEventArgs e) + { + _dataBaseFlag = !_dataBaseFlag; + Data.ItemsSource = OpenData(_dataBaseFlag); } - private void Change_Click(object sender, RoutedEventArgs e) {} - private void Open_Click(object sender, RoutedEventArgs e) => OpenFromDatabase(); + private List OpenData(bool _dataBaseFlag) => _dataBaseFlag ? OpenFromDatabase() : OpenFromDirectory(); + private List OpenFromDirectory() => _fileNames.Select(item => new Content { FileName = item }).ToList(); } } diff --git a/Program/Platform.cs b/Program/Platform.cs index 7186637..aab6e9c 100644 --- a/Program/Platform.cs +++ b/Program/Platform.cs @@ -26,11 +26,11 @@ public class Platform : DisposableBase private readonly CachingConverterDecorator _unicodeSequenceToStringConverter; private readonly UInt64SplitMemoryLinks _disposableLinks; protected readonly UInt64Links Links; - public Platform() + public Platform(string DataFileName, string IndexFileName) { - var dataMemory = new FileMappedResizableDirectMemory(IDefaultSettings.DataFileName); - var indexMemory = new FileMappedResizableDirectMemory(IDefaultSettings.IndexFileName); + var dataMemory = new FileMappedResizableDirectMemory(DataFileName); + var indexMemory = new FileMappedResizableDirectMemory(IndexFileName); var linksConstants = new LinksConstants(enableExternalReferencesSupport: true); diff --git a/Program/Properties/Resources.Designer.cs b/Program/Properties/Resources.Designer.cs index 460d832..9609ea5 100644 --- a/Program/Properties/Resources.Designer.cs +++ b/Program/Properties/Resources.Designer.cs @@ -59,15 +59,5 @@ internal Resources() { resourceCulture = value; } } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap button { - get { - object obj = ResourceManager.GetObject("button", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } } } diff --git a/Program/Properties/Resources.resx b/Program/Properties/Resources.resx index b17c26b..1af7de1 100644 --- a/Program/Properties/Resources.resx +++ b/Program/Properties/Resources.resx @@ -117,8 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ..\Resources\button.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - \ No newline at end of file diff --git a/Program/Resources/button.png b/Program/Resources/button.png deleted file mode 100644 index 05927ec..0000000 Binary files a/Program/Resources/button.png and /dev/null differ diff --git a/Program/xmlAdapter.cs b/Program/xmlAdapter.cs index aefa8d6..0923d64 100644 --- a/Program/xmlAdapter.cs +++ b/Program/xmlAdapter.cs @@ -9,17 +9,14 @@ namespace XmlParser public class XmlAdapter : Platform { private readonly ulong _fileNameMarker; - - private Link Query(ulong marker) => new(this.Links.Constants.Any, marker, this.Links.Constants.Any); + public Link Query(ulong marker) => new(this.Links.Constants.Any, marker, this.Links.Constants.Any); public void CreateLink(in string innerXml, string filename) { - var nameLink = ConvertToSequence(filename); var documentLink = ConvertToSequence(innerXml); Links.GetOrCreate(_fileNameMarker, nameLink); Links.GetOrCreate(nameLink, documentLink); } - public List GetAllFileNames() { var names = new List(); @@ -34,10 +31,10 @@ public List GetAllFileNames() }, query); return names; } - public string GetContent(string filename) => ConvertToString(Links.SearchOrDefault(ConvertToSequence(filename), Links.Constants.Any)); - private bool IsLinks(Link query) => this.Links.Count(query) > 0; - - public XmlAdapter() => _fileNameMarker = Links.GetOrCreate(ConvertToSequence(nameof(_fileNameMarker)), ConvertToSequence(nameof(_fileNameMarker))); + public string GetContent(string filename) => ConvertToString(Links.GetTarget(Links.SearchOrDefault(ConvertToSequence(filename), Links.Constants.Any))); + public bool IsLinks(Link query) => this.Links.Count(query) > 0; + public bool IsLinks(string element) => this.Links.Count(Query(ConvertToSequence(element))) > 0; + public XmlAdapter() : base(IDefaultSettings.DataFileName, IDefaultSettings.IndexFileName) => _fileNameMarker = Links.GetOrCreate(ConvertToSequence(nameof(_fileNameMarker)), ConvertToSequence(nameof(_fileNameMarker))); } } \ No newline at end of file diff --git a/Program/xmlparser.csproj b/Program/xmlparser.csproj index 2f86dac..53f0554 100644 --- a/Program/xmlparser.csproj +++ b/Program/xmlparser.csproj @@ -11,10 +11,6 @@ true - - - - @@ -22,10 +18,6 @@ - - - - True