Beispiel #1
0
        private void OnDataReceived(object sender, string str)
        {
            DispatcherHelper.RunAsync(() =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    var item = this.Suggestions.FirstOrDefault(x => x.SuggestionItems.Any(y => y.Text == str));
                    if (item == null)
                    {
                        item = new SuggestionItemGroup()
                        {
                            SuggestionItems =
                            {
                                new SuggestionItem()
                                {
                                    Text = str,
                                },
                            },
                        };
                        this.Suggestions.Add(item);
                    }
                    var item2 = item.SuggestionItems.Single(x => x.Text == str);
                    var ip    = sender as IPAddress;
#if !DEBUG
                    if (item2.IPAddresses.All(x => !Equals(x, ip)))
#endif
                    {
                        item2.IPAddresses.Add(ip);
                    }
                });
            });
        }
Beispiel #2
0
        private void OnImportData()
        {
            //TODO: UI auslagern
            try
            {
                var ofd = new OpenFileDialog
                {
                    Filter = "XML-Datei|*.xml"
                };
                if (ofd.ShowDialog() != true)
                {
                    return;
                }

                var doc = XDocument.Load(ofd.FileName);
                this.Suggestions.Clear();
                if (doc.Root == null)
                {
                    return;
                }
                foreach (var group in doc.Root.Elements("Group"))
                {
                    var sig = new SuggestionItemGroup();
                    foreach (var item in @group.Elements("Item"))
                    {
                        var si = new SuggestionItem();
                        foreach (var ip in item.Elements("IP"))
                        {
                            si.IPAddresses.Add(IPAddress.Parse(ip.Value));
                        }
                        si.Text = item.Attribute("Text").Value;
                        sig.SuggestionItems.Add(si);
                    }
                    this.Suggestions.Add(sig);
                }
            }
            catch (Exception ex)
            {
                this.ShowMessage("Unerwarteter Fehler",
                                 $"Die Datei konnte aus einem unbekannten Grund nicht geöffnet werden. \n\nTechnische Informationen:\n{ex.Message}");
            }
        }
        private void OnImportData()
        {
            //TODO: UI auslagern
            try
            {
                var ofd = new OpenFileDialog
                {
                    Filter = "XML-Datei|*.xml"
                };
                if (ofd.ShowDialog() != true)
                {
                    return;
                }

                var doc = XDocument.Load(ofd.FileName);
                this.Suggestions.Clear();
                if (doc.Root == null) { return; }
                foreach (var group in doc.Root.Elements("Group"))
                {
                    var sig = new SuggestionItemGroup();
                    foreach (var item in @group.Elements("Item"))
                    {
                        var si = new SuggestionItem();
                        foreach (var ip in item.Elements("IP"))
                        {
                            si.IPAddresses.Add(IPAddress.Parse(ip.Value));
                        }
                        si.Text = item.Attribute("Text").Value;
                        sig.SuggestionItems.Add(si);
                    }
                    this.Suggestions.Add(sig);
                }
            }
            catch (Exception ex)
            {
                this.ShowMessage("Unerwarteter Fehler",
                    $"Die Datei konnte aus einem unbekannten Grund nicht geöffnet werden. \n\nTechnische Informationen:\n{ex.Message}");
            }
        }
 private void OnDataReceived(object sender, string str)
 {
     DispatcherHelper.RunAsync(() =>
     {
         DispatcherHelper.CheckBeginInvokeOnUI(() =>
         {
             var item = this.Suggestions.FirstOrDefault(x => x.SuggestionItems.Any(y => y.Text == str));
             if (item == null)
             {
                 item = new SuggestionItemGroup()
                 {
                     SuggestionItems =
                     {
                         new SuggestionItem()
                         {
                             Text = str,
                         },
                     },
                 };
                 this.Suggestions.Add(item);
             }
             var item2 = item.SuggestionItems.Single(x => x.Text == str);
             var ip = sender as IPAddress;
     #if !DEBUG
             if (item2.IPAddresses.All(x => !Equals(x, ip)))
     #endif
             {
                 item2.IPAddresses.Add(ip);
             }
         });
     });
 }