コード例 #1
0
        private async Task LoadPointsFromServiceAsync()
        {
            const string ErrorMessage = "Получение списка точек от сервиса - ошибка:\n{0}";

            try
            {
                IsGettingPointsFromService = true;

                var source = await FillPointsTree(_rootEmcosGroup);

                IsGettingPointsFromService = false;
                if (source.Count == 0)
                {
                    this.ShowDialogWarning("Список пуст!");
                    EmcosFromSiteModel = null;
                }
                else
                {
                    EmcosFromSiteModel = new TreeModel(new EmcosPoint("ROOT", source));
                }
            }
            catch (Exception ex)
            {
                EmcosSiteWrapperApp.Log("Получение списка точек от сервиса - ошибка");
                IsGettingPointsFromService = false;
                this.ShowDialogError(String.Format(ErrorMessage, EmcosSiteWrapperApp.GetExceptionDetails(ex)));
            }
        }
コード例 #2
0
        private async Task LoadPointsFromServiceAsync()
        {
            const string ErrorMessage = "Получение списка точек от сервиса - ошибка:\n{0}";
            IDialog      dialog       = null;

            try
            {
                dialog = _window.DialogWaitingScreen("Получение данных ...", indeterminate: true, mode: TMPApplication.WpfDialogs.DialogMode.Cancel);
                dialog.Show();
                var source = await FillPointsTree(_rootEmcosGroup);

                if (source.Count == 0)
                {
                    dialog.Close();
                    _window.ShowDialogWarning("Список пуст!", TITLE);
                    EmcosPointsFromSite = null;
                }
                else
                {
                    dialog.Caption = "Создание модели";
                    EmcosSiteWrapperApp.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Threading.ThreadStart(delegate { }));

                    EmcosPointsFromSite = new HierarchicalEmcosPointCollection(null, source);
                    dialog.Caption      = "Поиск изменений";
                    EmcosSiteWrapperApp.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Threading.ThreadStart(delegate { }));

                    // поиск новых точек
                    void checkNewItems(IEnumerable <IHierarchicalEmcosPoint> sourcePoints, IEnumerable <IHierarchicalEmcosPoint> destinationPoints)
                    {
                        foreach (var point in sourcePoints)
                        {
                            IHierarchicalEmcosPoint p = destinationPoints.Where(i => i.Id == point.Id).FirstOrDefault();
                            if (p == null)
                            {
                                point.Tag = "NEW";
                            }
                            else
                            {
                                point.Tag = null;
                                if (point.HasChildren)
                                {
                                    checkNewItems(point.Children, p.Children);
                                }
                            }
                        }
                    }
                    checkNewItems(EmcosPointsFromSite, EmcosPoints);

                    // поиск удаленных точек
                    void checkDeletedItems(IEnumerable <IHierarchicalEmcosPoint> sourcePoints, IEnumerable <IHierarchicalEmcosPoint> destinationPoints)
                    {
                        foreach (var point in sourcePoints)
                        {
                            IHierarchicalEmcosPoint p = destinationPoints.Where(i => i.Id == point.Id).FirstOrDefault();
                            if (p == null)
                            {
                                point.Tag = "DELETED";
                            }
                            else
                            {
                                point.Tag = null;
                                if (point.HasChildren)
                                {
                                    checkDeletedItems(point.Children, p.Children);
                                }
                            }
                        }
                    }
                    checkDeletedItems(EmcosPoints, EmcosPointsFromSite);

                    dialog.Close();
                }
            }
            catch (Exception ex)
            {
                EmcosSiteWrapperApp.Log("Получение списка точек от сервиса - ошибка");
                if (dialog != null)
                {
                    dialog.Close();
                }
                _window.ShowDialogError(String.Format(ErrorMessage, EmcosSiteWrapperApp.GetExceptionDetails(ex)));
            }
        }