Example #1
0
        public MainVM()
        {
            MainVm = this;
            Notify = new Notifier(cfg =>
            {
                cfg.PositionProvider = new PrimaryScreenPositionProvider(
                    corner: Corner.TopRight,
                    offsetX: 10,
                    offsetY: 30);
                cfg.LifetimeSupervisor = new CountBasedLifetimeSupervisor(
                    maximumNotificationCount: MaximumNotificationCount.UnlimitedNotifications());
                cfg.DisplayOptions.Width = 800;
                cfg.Dispatcher           = dispatcher;
            });
            ElementsVM = new ElementsVM(this);
            ProjectsVM = new ProjectsVM(this);
#if DEBUG
            ShortcutFolder = @"d:\vildar\test\GP\C3D_Projects";
#endif
            this.WhenAnyValue(v => v.ShortcutFolder).Delay(TimeSpan.FromMilliseconds(200))
            .ObserveOn(dispatcher)
            .Subscribe(s => UpdateExecute());
            Update = CreateCommand(UpdateExecute);
        }
Example #2
0
        private async void UpdateExecute()
        {
            try
            {
                projectWatcher?.Watcher?.Dispose();
                if (inUpdate || !Directory.Exists(ShortcutFolder))
                {
                    return;
                }

//                projectWatcher = new FileWatcherRx(ShortcutFolder, "", (NotifyFilters) 19, WatcherChangeTypes.All);
//                projectWatcher.Watcher.IncludeSubdirectories = true;
//                projectWatcher.Created.ObserveOn(dispatcher).Subscribe(s => OnCreatedProject(s.EventArgs));
//                projectWatcher.Deleted.ObserveOn(dispatcher).Subscribe(s => OnDeletedProject(s.EventArgs));
//                projectWatcher.Renamed.ObserveOn(dispatcher).Subscribe(s => OnRenamedProject(s.EventArgs));
//                projectWatcher.Changed.ObserveOn(dispatcher).Subscribe(s => OnChangedProject(s.EventArgs));
                inUpdate = true;
                var files = new List <FileInfo>();
                AllElements.Clear();
                AllProjects.Clear();
                await ShowProgressDialog(c =>
                {
                    c.SetIndeterminate();
                    if (ShortcutFolder == null || !Directory.Exists(ShortcutFolder))
                    {
                        return;
                    }

                    files = GetShortcutFiles(ShortcutFolder).Result;
                }, "Загрузка элементов...", "", false);

                if (!files.Any())
                {
                    ShowMessage("Не найдены файлы быстрых ссылок (xml)");
                    return;
                }

                foreach (var xmls in files.ChunkBy(50))
                {
                    var items = await GetShortcutItems(xmls);

                    foreach (var i in items)
                    {
                        Checks.CheckElement(i);
                        i.Project.Shortcuts.Add(i);
                        AllElements.Add(i);
                    }
                }

                var projects = Project.GetProjects();
                AllProjects.AddRange(projects);
                ProjectsVM.UpdateProjects();
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
            finally
            {
                inUpdate = false;
            }
        }