Пример #1
0
        private void BuildTrackerConnectionProgressChanged(object sender, BuildTrackerConnectionProgressEventArgs e)
        {
            if (ShouldExitHandler(e))
            {
                return;
            }

            foreach (var project in e.Projects)
            {
                var projectToUpdate = _projects.SingleOrDefault(p => p.Id == project.Id);

                if (projectToUpdate != null)
                {
                    projectToUpdate.TryUpdate(project.Name);
                }
                else
                {
                    _application.Dispatcher.Invoke(() =>
                    {
                        var projectToAdd = _projectFactory.Create(SettingsId, project.Id, project.Name);

                        var names = _projects.Select(p => p.Name).Concat(new[] { projectToAdd.Name }).OrderBy(name => name).ToArray();

                        var index = Array.IndexOf(names, projectToAdd.Name);

                        _projects.Insert(index, projectToAdd);
                    });
                }
            }

            var projectsToKeep   = e.Projects.Select(project => project.Id).ToArray();
            var projectsToRemove = _projects.Where(project => !projectsToKeep.Contains(project.Id)).ToArray();

            if (_projects.Any())
            {
                _application.Dispatcher.Invoke(() =>
                {
                    _projects.RemoveRange(projectsToRemove);
                });
            }

            _trie = new SuffixTrie <IProjectViewModel>(3);

            foreach (var project in _projects)
            {
                _trie.Add(project.Name.ToLowerInvariant(), project);
            }

            IsErrored = false;
            IsBusy    = false;

            NotifyOfPropertyChange(() => HasProjects);
            NotifyOfPropertyChange(() => HasNoProjects);
            NotifyOfPropertyChange(() => IsViewable);
        }
Пример #2
0
        private void BuildTrackerProjectProgressChanged(object sender, BuildTrackerProjectProgressEventArgs e)
        {
            if (ShouldExitHandler(e))
            {
                return;
            }

            foreach (var build in e.Builds)
            {
                var buildToUpdate = _builds.SingleOrDefault(b => b.Id == build.Id);

                if (buildToUpdate != null)
                {
                    buildToUpdate.TryUpdate(e.Project.Name, build.Status, build.StartTime, build.EndTime, build.RunTime());
                }
                else
                {
                    _application.Dispatcher.Invoke(() =>
                    {
                        var buildToAdd = _buildFactory.Create(e.Project.Name, build.Id, build.Branch, build.VersionNumber(), build.RequestedBy, build.Changes, build.Status, build.StartTime, build.EndTime, build.RunTime(), build.WebUrl);

                        var time = new Tuple <DateTime, DateTime>(buildToAdd.EndTime ?? DateTime.MaxValue, buildToAdd.StartTime ?? DateTime.MaxValue);

                        var times = _builds.Select(b => new Tuple <DateTime, DateTime>(b.EndTime ?? DateTime.MaxValue, b.StartTime ?? DateTime.MaxValue)).Concat(new[] { time }).OrderByDescending(t => t.Item1).ThenByDescending(t => t.Item2).ToArray();

                        var index = Array.IndexOf(times, time);

                        _builds.Insert(index, buildToAdd);
                    });
                }
            }

            var buildsToKeep   = e.Builds.Select(build => build.Id).ToArray();
            var buildsToRemove = _builds.Where(build => !buildsToKeep.Contains(build.Id)).ToArray();

            if (buildsToRemove.Any())
            {
                _application.Dispatcher.Invoke(() =>
                {
                    _builds.RemoveRange(buildsToRemove);
                });
            }

            IsErrored = false;
            IsBusy    = false;

            NotifyOfPropertyChange(() => HasBuilds);
            NotifyOfPropertyChange(() => HasNoBuilds);
            NotifyOfPropertyChange(() => LatestBuild);
            NotifyOfPropertyChange(() => HasLatestBuild);
            NotifyOfPropertyChange(() => QueuedBuilds);
            NotifyOfPropertyChange(() => HasQueuedBuilds);
            NotifyOfPropertyChange(() => IsViewable);
        }
Пример #3
0
 private async void InitAsync()
 {
     Regions              = new BindableCollection <MapRegion>(await _settingsService.GetRegions().ConfigureAwait(false));
     DefaultRegion        = Regions.Single(r => r.RegionId == Properties.Settings.Default.DefaultRegionId);
     Stations             = new BindableCollection <StaStation>(DefaultRegion.StaStations);
     DefaultStation       = Stations.SingleOrDefault(s => s.StationId == Properties.Settings.Default.DefaultStationId);
     MarketHistorySources = new BindableCollection <string> {
         "Crest", "EveMarketData"
     };
     MarketHistorySource = Properties.Settings.Default.MarketHistorySource;
 }
        public void Handle(ConfigurationChanged message)
        {
            Task.Run(() =>
            {
                Users = new BindableCollection <User>(_configurationService.Configurations.Select(c => new User {
                    Configuration = c
                }));

                _selectedUser = Users.SingleOrDefault(u => u.Name == _configurationService.ActiveConfiguration.Name);
                NotifyOfPropertyChange(() => SelectedUser);
            });
        }
        public ShellViewModel(
            IInterTabClient caliburnInterTabClient,
            IInterLayoutClient caliburnInterLayoutClient,
            ISnackbarMessageQueue mainMessageQueue,
            IConfigurationService configurationService,
            IEventAggregator eventAggregator,
            MenuViewModel menuViewModel)
        {
            CaliburnInterTabClient    = caliburnInterTabClient;
            CaliburnInterLayoutClient = caliburnInterLayoutClient;
            MainMessageQueue          = mainMessageQueue;
            MenuViewModel             = menuViewModel;
            _configurationService     = configurationService;
            eventAggregator.Subscribe(this);

            Users = new BindableCollection <User>(_configurationService.Configurations.Select(c => new User {
                Configuration = c
            }));
            _selectedUser = Users.SingleOrDefault(u => u.Name == _configurationService.ActiveConfiguration.Name);
            NotifyOfPropertyChange(() => SelectedUser);
        }
Пример #6
0
        /// <summary>
        ///     Uninstall all installed dnscrypt-proxy services.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="NetworkInformationException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public async void UninstallServices()
        {
            var result = _windowManager.ShowMetroMessageBox(
                LocalizationEx.GetUiString("dialog_message_uninstall", Thread.CurrentThread.CurrentCulture),
                LocalizationEx.GetUiString("dialog_uninstall_title", Thread.CurrentThread.CurrentCulture),
                MessageBoxButton.YesNo, BoxType.Default);

            if (result == MessageBoxResult.Yes)
            {
                IsUninstallingServices = true;
                await Task.Run(() =>
                {
                    PrimaryDnsCryptProxyManager.Uninstall();
                    SecondaryDnsCryptProxyManager.Uninstall();
                }).ConfigureAwait(false);

                Thread.Sleep(Global.ServiceUninstallTime);
                IsUninstallingServices = false;
            }

            _isPrimaryResolverRunning = PrimaryDnsCryptProxyManager.IsDnsCryptProxyRunning();
            NotifyOfPropertyChange(() => IsPrimaryResolverRunning);
            _isSecondaryResolverRunning = SecondaryDnsCryptProxyManager.IsDnsCryptProxyRunning();
            NotifyOfPropertyChange(() => IsSecondaryResolverRunning);

            // recover the network interfaces (also the hidden and down cards)
            foreach (var nic in LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(true, false))
            {
                if (!nic.UseDnsCrypt)
                {
                    continue;
                }
                var status = LocalNetworkInterfaceManager.SetNameservers(nic, new List <string>(), NetworkInterfaceComponent.IPv4);
                var card   = _localNetworkInterfaces.SingleOrDefault(n => n.Description.Equals(nic.Description));
                if (card != null)
                {
                    card.UseDnsCrypt = !status;
                }
            }
        }
Пример #7
0
        public void Init()
        {
            DefectInfosCollectionView = DefectInfos.GetDefaultCollectionView();

            // Init SurfaceMonitors
            SurfaceMonitors = new List <SurfaceMonitorViewModel>();

            int surfaceCount = 0;

            surfaceCount = 2;

            for (int i = 0; i < surfaceCount; i++)
            {
                var sm = new SurfaceMonitorViewModel
                {
                    Index                      = i,
                    SurfaceTypeIndex           = i,
                    DisplayDefectInfo          = true,
                    DisplayAllDefectInfos      = false,
                    DisplayMeasurementInfo     = true,
                    DisplayAllMeasurementInfos = false,
                };
                SurfaceMonitors.Add(sm);
            }

            //

            CreateWorkpieceInfoCommand = new DelegateCommand(
                () =>
            {
                var dialog = new OpenFileDialog()
                {
                    Multiselect = false,
                    Title       = "Select Image File",
                };

                var ret = dialog.ShowDialog();

                if (ret != true)
                {
                    return;
                }

                var fn = dialog.FileName;

                var di = ServiceLocator.GetInstance <WorkpieceInfo>();
                //di.StoreImage(fn);
                di.InspectDateTime = DateTime.Now;
                di.IsReject        = true;

                InspectionDomainService.AddWorkpieceInfo(di);
            });

            DeleteWorkpieceInfoCommand = new DelegateCommand <WorkpieceInfoEntryViewModel>(
                (di) =>
            {
                if (di == null)
                {
                    MessageBox.Show("Please select a WorkpieceInfo!");
                    return;
                }

                InspectionDomainService.DeleteWorkpieceInfo(di.Id);
            },
                (x) => { return(SelectedWorkpieceInfo != null); });

            SelectWorkpieceInfoCommand = new DelegateCommand <WorkpieceInfoEntryViewModel>(
                (workpieceInfoEntry) =>
            {
                //           var deferRefresh=  DefectInfosCollectionView.DeferRefresh();
                DefectInfosCollectionView.Filter = null;
                _defectInfos.Clear();

                foreach (var surfaceMonitor in SurfaceMonitors)
                {
                    surfaceMonitor.Reset();
                }

                HideAll();

                UpdateCommandStates();

                if (workpieceInfoEntry == null)
                {
                    return;
                }

                var id            = workpieceInfoEntry.Id;
                var workpieceInfo = InspectionDomainService.GetWorkpieceInfoById(id);
                var defVms        = workpieceInfo.DefectInfos.Select(x => x.ToViewModel());
                _defectInfos.AddRange(defVms);

                for (int i = 0; i < workpieceInfo.StoredImageInfo.Count; i++)
                {
                    var sii = workpieceInfo.StoredImageInfo[i];
                    var bs  = sii.LoadImage();

                    var surfaceMonitor          = SurfaceMonitors[sii.SurfaceTypeIndex];
                    surfaceMonitor.BitmapSource = bs;

                    var ds = _defectInfos.Where(x => x.SurfaceTypeIndex == surfaceMonitor.SurfaceTypeIndex).ToList();

                    if (ds.IsEmpty())
                    {
                        surfaceMonitor.DefectInfos  = null;
                        surfaceMonitor.InspectState = InspectState.InspectedWithAccepted;
                    }
                    else
                    {
                        surfaceMonitor.DefectInfos  = ds;
                        surfaceMonitor.InspectState = InspectState.InspectedWithRejected;
                    }
                }

                //            deferRefresh.Dispose();
                DefectInfosCollectionView.Filter = null;
                DefectInfosCollectionView.Refresh();

                UpdateCommandStates();
            });

            EventAggregator
            .GetEvents <WorkpieceInfoAddedDomainEvent>()
            .Subscribe(evt =>
            {
                var entryVm = evt.WorkpieceInfo.ToEntry().ToViewModel();
                WorkpieceInfoEntries.Add(entryVm);

                UpdateCommandStates();
            });

            EventAggregator
            .GetEvents <WorkpieceInfoRemovedDomainEvent>()
            .Subscribe(evt =>
            {
                var s = WorkpieceInfoEntries.SingleOrDefault(x => x.Id == evt.Id);
                if (s != null)
                {
                    WorkpieceInfoEntries.Remove(s);
                }

                UpdateCommandStates();
            });

            CreateDefectInfoCommand = new DelegateCommand(
                () =>
            {
                if (SelectedWorkpieceInfo == null)
                {
                }
                else
                {
                    var index      = DefectInfos.Count;
                    var defectInfo = new DefectInfo {
                        Width = 200, Height = 200, X = index * 100, Y = index * 100
                    };

                    InspectionDomainService.AddDefectInfo(SelectedWorkpieceInfo.Id, defectInfo);
                }
            },
                () => { return(SelectedWorkpieceInfo != null); });

            DeleteDefectInfoCommand = new DelegateCommand <DefectInfoViewModel>(
                (di) =>
            {
                if (SelectedWorkpieceInfo == null)
                {
                    return;
                }

                if (SelectedDefectInfo == null)
                {
                    return;
                }

                InspectionDomainService.DeleteDefectInfo(SelectedWorkpieceInfo.Id, SelectedDefectInfo.Id);
            },
                (x) => { return(SelectedDefectInfo != null); });



            CleanOldWorkpieceInfosCommand = new DelegateCommand(OnCleanOldWorkpieceInfosCommand);

            SelectDefectInfoCommand = new DelegateCommand <DefectInfoViewModel>(
                (di) =>
            {
                if (di != null)
                {
                    CroppedRegionRect = new Rect(di.X, di.Y, di.Width, di.Height);
                }

                UpdateCommandStates();
            });

            CreateMonithReportCommand = new DelegateCommand(
                () =>
            {
                var report = ReportingDomainService.GetMonthReport(SelectedMonthReportDateTime.Year,
                                                                   SelectedMonthReportDateTime.Month);

                if (report == null)
                {
                    MessageDialogService.Show("没有数据,无法生成报表");
                    return;
                }

                PreviewReportingDialogService
                .Show(report)
                .Subscribe(args =>
                {
                    if (args.IsCanceled)
                    {
                        return;
                    }

                    ReportingDomainService.ExportReport(args.Data);
                });
            });

            QueryMonthRecordsCommand = new DelegateCommand(
                () =>
            {
                var dis = ReportingDomainService.GetWorkpieceInfoEntriesByMonth(SelectedMonthReportDateTime.Year,
                                                                                SelectedMonthReportDateTime.Month);
                WorkpieceInfoEntries.Clear();
                WorkpieceInfoEntries.AddRange(dis.Select(x => x.ToViewModel()));
            });

            CreateDayReportCommand = new DelegateCommand(
                () =>
            {
                var report = ReportingDomainService.GetDayReport(SelectedDayReportDateTime.Year,
                                                                 SelectedDayReportDateTime.Month,
                                                                 SelectedDayReportDateTime.Day);

                if (report == null)
                {
                    MessageDialogService.Show("没有数据,无法生成报表");
                    return;
                }

                PreviewReportingDialogService
                .Show(report)
                .Subscribe(args =>
                {
                    if (args.IsCanceled)
                    {
                        return;
                    }

                    ReportingDomainService.ExportReport(args.Data);
                });
            });

            QueryDayRecordsCommand = new DelegateCommand(
                () =>
            {
                var dis = ReportingDomainService.GetWorkpieceInfoEntriesByDay(SelectedDayReportDateTime.Year,
                                                                              SelectedDayReportDateTime.Month,
                                                                              SelectedDayReportDateTime.Day);
                WorkpieceInfoEntries.Clear();
                WorkpieceInfoEntries.AddRange(dis.Select(x => x.ToViewModel()));
            });


            ZoomInCommand = new DelegateCommand(
                () =>
            {
                if (SelectedSurfaceMonitor != null)
                {
                    SelectedSurfaceMonitor.ZoomIn();
                }
                _isZoomFitDisplayAreaEnabled = false;
                _isZoomActualEnabled         = false;
            },
                () => SelectedSurfaceMonitor != null);

            ZoomOutCommand = new DelegateCommand(
                () =>
            {
                if (SelectedSurfaceMonitor != null)
                {
                    SelectedSurfaceMonitor.ZoomOut();
                }
                _isZoomFitDisplayAreaEnabled = false;
                _isZoomActualEnabled         = false;
            },
                () => SelectedSurfaceMonitor != null);

            ZoomFitCommand = new DelegateCommand(
                () =>
            {
                _isZoomFitDisplayAreaEnabled = !_isZoomFitDisplayAreaEnabled;
                if (_isZoomFitDisplayAreaEnabled)
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomFitDisplayArea();
                    }
                }
                else
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomFit();
                    }
                }
                _isZoomActualEnabled = false;
            },
                () => SelectedSurfaceMonitor != null);

            ZoomActualCommand = new DelegateCommand(
                () =>
            {
                _isZoomActualEnabled = !_isZoomActualEnabled;
                if (_isZoomActualEnabled)
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomActual();
                    }
                }
                else
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomFit();
                    }
                }

                _isZoomFitDisplayAreaEnabled = false;
            },
                () => SelectedSurfaceMonitor != null);



            SaveImageToFileCommand = new DelegateCommand(
                OnSaveImageToFileCommand,
                () => SelectedSurfaceMonitor != null);

            EventAggregator
            .GetEvents <DefectInfoAddedDomainEvent>()
            .Subscribe(evt =>
            {
                if (SelectedWorkpieceInfo == null)
                {
                    return;
                }

                if (SelectedWorkpieceInfo.Id != evt.WorkpieceInfoId)
                {
                    return;
                }

                _defectInfos.Add(evt.DefectInfo.ToViewModel());

                UpdateCommandStates();
            });


            EventAggregator
            .GetEvents <DefectInfoRemovedDomainEvent>()
            .Subscribe(evt =>
            {
                if (SelectedDefectInfo != null && SelectedDefectInfo.Id == evt.DefectInfoId)
                {
                    SelectedDefectInfo = null;
                }

                var di = _defectInfos.SingleOrDefault(x => x.Id == evt.DefectInfoId);
                if (di != null)
                {
                    _defectInfos.Remove(di);
                }

                UpdateCommandStates();
            });

            EventAggregator.GetEvents <ReportExportFailedEvent>()
            .Subscribe(evt => { MessageBox.Show("导出失败!" + "\n\n" + evt.Exception.Message); });

            EventAggregator.GetEvents <ReportExportSuccessfulEvent>()
            .Subscribe(evt => { MessageBox.Show("导出成功!" + "\n\n" + evt.FileName); });


            var thisMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            MonthReportDateTimes.Add(thisMonth);
            for (int i = 0; i < 5; i++)
            {
                MonthReportDateTimes.Add(thisMonth.AddMonths(-i - 1));
            }

            SelectedMonthReportDateTime        = thisMonth;
            SelectedDayReportYearMonthDateTime = thisMonth;
        }