Exemplo n.º 1
0
        public async Task <StreamUploadResponse> UpdateWtmSettings(StreamUploadRequest request)
        {
            var memoryStream = new MemoryStream();

            try
            {
                await request.Stream.CopyToAsync(memoryStream);

                var wtmSettings = NetHelper.DeserializeFromStream <WtmSettingsObject>(memoryStream);
                if (request.ProxyPassword.Length != 0)
                {
                    wtmSettings.ProxyPassword          = request.ProxyPassword.ToSecureString();
                    wtmSettings.ProxyPasswordEncrypted = request.ProxyPassword.Encrypt();
                    Array.Clear(request.ProxyPassword, 0, request.ProxyPassword.Length);
                }
                ViewModel.Instance.WtmSettings = wtmSettings.Clone();
                ViewModel.Instance.SaveWtmSettings();
                var date = WtmSettingsObject.GetWtmSettingsLastUpdateTime();
                return(new StreamUploadResponse {
                    ResponseFlag = true, Date = date
                });
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
            finally
            {
                memoryStream.Dispose();
            }
        }
Exemplo n.º 2
0
        private void MassUpdateWtmSettingsCommand(object obj)
        {
            var massUpdateWindow = new MassUpdate();
            var vm = new MassUpdateVM(Workers.GetComputers(Computer.OperationStatus.OperationInProgress));

            vm.Header       = $"Update Settings";
            vm.WindowTitle  = $"Mass Update";
            vm.ColumnHeader = "Settings Date";
            vm.SubHeader    = $"{Environment.MachineName}: {WtmSettingsObject.GetWtmSettingsLastUpdateTime()}";
            massUpdateWindow.DataContext = vm;
            var dialogResult = massUpdateWindow.ShowDialog();
        }
Exemplo n.º 3
0
        public async Task ScanLan()
        {
            ScanIsInProgress = true;

            UpdateCancelSource = new CancellationTokenSource();
            var token = UpdateCancelSource.Token;
            var tasks = new List <Task>();

            var appVersion      = new Version(Helpers.ApplicationVersion());
            var workersDate     = Workers.GetWorkersLastUpdateTime();
            var wtmSettingsDate = WtmSettingsObject.GetWtmSettingsLastUpdateTime();

            foreach (var pc in Computers)
            {
                Task task = null;
                switch (ColumnHeader)
                {
                case "Version":
                    task = Task.Run(async() => await QueryRemoteVersion(pc, token, appVersion));
                    break;

                case "Workers Date":
                    task = Task.Run(async() => await QueryRemoteWorkersDate(pc, token, workersDate));
                    break;

                case "Settings Date":
                    task = Task.Run(async() => await QueryRemoteWtmSettingsDate(pc, token, wtmSettingsDate));
                    break;
                }
                tasks.Add(task);
            }

            await Task.WhenAll(tasks);

            ScanIsInProgress = false;
        }
Exemplo n.º 4
0
        public Task <DateTime> GetWtmSettingsDateAsync()
        {
            DateTime updateTime = WtmSettingsObject.GetWtmSettingsLastUpdateTime();

            return(Task.FromResult(updateTime));
        }
Exemplo n.º 5
0
        private async void UpdateCommand(object obj)
        {
            UpdateIsInProgress = true;

            var workersDate     = Workers.GetWorkersLastUpdateTime();
            var wtmSettingsDate = WtmSettingsObject.GetWtmSettingsLastUpdateTime();

            UpdateCancelSource = new CancellationTokenSource();
            var token = UpdateCancelSource.Token;

            var          taskList   = new List <Task>();
            var          failList   = new List <ProfitTable>();
            FlowDocument report     = new FlowDocument();
            int          errorCount = 0;

            string appVersion = Helpers.ApplicationVersion();

            var jobCount = Computers.Count;

            ReportTitle = $"Progress: 0 of {jobCount}.";
            for (int i = 0; i < jobCount; i++)
            {
                var pc = Computers[i];
                if (!pc.Switch)
                {
                    continue;
                }
                Task task = null;
                switch (ColumnHeader)
                {
                case "Version":
                    task = Task.Run(async() => { errorCount = await UpdateVersion(pc, token, errorCount, i, jobCount, appVersion); });
                    break;

                case "Workers Date":
                    task = Task.Run(async() => { errorCount = await UpdateWorkers(pc, token, errorCount, i, jobCount, workersDate); });
                    break;

                case "Settings Date":
                    task = Task.Run(async() => { errorCount = await UpdateWtmSettings(pc, token, errorCount, i, jobCount, wtmSettingsDate); });
                    break;
                }
                taskList.Add(task);
            }

            await Task.WhenAll(taskList);

            if (errorCount == 0)
            {
                ReportTitle = "Report:";
                var paragraph = new Paragraph();
                paragraph.Inlines.Add(new Run("Operation has finished successfully."));
                NewParagraph = paragraph;
            }
            else
            {
                ReportTitle = "Error report:";
            }

            UpdateIsInProgress = false;
            UpdateIsFinished   = true;
        }