Beispiel #1
0
        private async void Update()
        {
            // Обновление элементов быстрых ссылок
            var filesXml = await MainVM.GetShortcutFiles(shortcutsDir);

            var items = await MainVM.GetShortcutItems(filesXml);

            foreach (var shortcut in Shortcuts.ToList())
            {
                if (!System.IO.File.Exists(shortcut.XmlFile) && !shortcut.IsDeleted)
                {
                    shortcut.IsDeleted  = true;
                    shortcut.Background = MainVM.eventDeleteBackground;
                    shortcut.Events.Add($"Удалено {DateTime.Now}.");
                    Shortcuts.Remove(shortcut);
                    MainVM.Notify.ShowError($"Удалена быстрая ссылка {shortcut.Name}, {Name}.");
                }
            }

            foreach (var item in items)
            {
                Checks.CheckElement(item);
                var shortcut = Shortcuts.FirstOrDefault(i => i.XmlFile == item.XmlFile);
                if (shortcut == null)
                {
                    shortcut = Shortcuts.FirstOrDefault(i => i.Name == item.Name);
                    if (shortcut != null)
                    {
                        // Переименовался файл
                        shortcut.Background = MainVM.eventBackground;
                        var msg = $"Переименован файл xml {shortcut.XmlFileName} -> {item.XmlFileName}.";
                        shortcut.Events.Add($"{msg} {Name}.");
                        MainVM.Notify.ShowWarning($"{msg} {Name}.");
                        continue;
                    }

                    item.Background = MainVM.eventNewBackground;
                    item.Events.Add($"Создан {DateTime.Now}.");
                    MainVM.AllElements.Insert(0, item);
                    MainVM.Notify.ShowSuccess($"Создан элемент {item.ElementName}. {Name}");
                    item.Project.Shortcuts.Add(item);
                    Shortcuts.Insert(0, item);
                }
                else
                {
                    if (item.Name != shortcut.Name)
                    {
                        // Изменилось ключевое имя быстрой ссылки
                        var msg = $"Переименован ключ быстрой ссылки {shortcut.Name} -> {item.Name}.";
                        shortcut.Events.Add(msg);
                        MainVM.Notify.ShowWarning($"{msg} {Name}.");
                        shortcut.Name = item.Name;
                    }

                    if (item.ElementName != shortcut.ElementName)
                    {
                        // Изменилось имя объекта быстрой ссылки
                        var msg = $"Переименован объект быстрой ссылки {shortcut.ElementName} -> {item.ElementName}.";
                        shortcut.Events.Add(msg);
                        MainVM.Notify.ShowWarning($"{msg} {Name}.");
                        shortcut.ElementName = item.ElementName;
                    }
                }
            }
        }