コード例 #1
0
        } // Update()

        //Update the UI to reflect the progress value that is passed back.
        private void UpdaterProgress(blfwkdll.Updater.UpdaterOperationProgressData opData)
        {
//            Value = (Int32)opData.Tasks[opData.CurrentTaskIndex].CurrentPosition;
//            LogTextBox.AppendText(String.Format("Progress: {0} Current: {1}\r\n", opData.Tasks[opData.CurrentTaskIndex].TaskDescription.ToString(), opData.Tasks[opData.CurrentTaskIndex].CurrentPosition));
            Status = opData.Tasks[opData.CurrentTaskIndex].TaskDescription.Description;
            Value  = ((opData.CurrentTaskIndex) * 100) / opData.Tasks.Count;
//            return !_UserStopped;
        }
コード例 #2
0
        private async Task Update(UpdaterViewModel updaterModel,
                                  IProgress <blfwkdll.Updater.UpdaterOperationProgressData> progress,
                                  CancellationToken token = new CancellationToken())
        {
#if (TEST_WINDOW_LOGIC)
            blfwkdll.Updater.UpdaterOperationProgressData dummyOpData =
                new blfwkdll.Updater.UpdaterOperationProgressData(new blfwkdll.Updater.UpdaterEnum(0, "Updating..."));
            dummyOpData.Tasks.Add(new blfwkdll.Updater.UpdaterTask(new blfwkdll.Updater.UpdaterEnum(0, "Erasing..."), 0, 100));
            dummyOpData.Tasks.Add(new blfwkdll.Updater.UpdaterTask(new blfwkdll.Updater.UpdaterEnum(1, "Writing..."), 0, 100));

            for (int j = 0; j < dummyOpData.Tasks.Count; ++j)
            {
                dummyOpData.CurrentTaskIndex = j;
                if (progress != null)
                {
                    progress.Report(dummyOpData);
                }

                for (UInt32 i = 10; i <= dummyOpData.Tasks[j].Total; i += 10)
                {
                    dummyOpData.Tasks[j].CurrentPosition = i;
                    if (progress != null)
                    {
                        progress.Report(dummyOpData);
                    }

                    await Task.Delay(TimeSpan.FromSeconds(.1), token).ConfigureAwait(false);

                    if (j == 1 && i == 20)
                    {
                        throw new Exception("The updater threw an error.");
                    }
                }
            }
#else
            Updater.setCallback(UpdaterProgress);
            await Task.Run(() =>
            {
                try
                {
                    if (DeviceModel.IsSerial)
                    {
                        IsConnectedTimer.Stop();
                    }

                    if (InSecurity)
                    {
                        if (UnlockWithBackdoorKey == true)
                        {
                            Updater.unlockWithKey(BackdoorKey);
                        }
                        else if (FlashEraseAllUnsecure == true)
                        {
                            Updater.eraseAllUnsecure();
                        }
                        Status = "Unlocked";
                    }
                    //Updater.flashFirmware(ImageFileModel.FullPath, ImageFileModel.BaseAddress);
                    Updater.flashFirmware(this.ImageFileModel.FullPath, this.ImageFileModel.BaseAddress);   // TODO: handle exceptions! (see below ...)

                    Reset();
                    if (DeviceModel.IsSerial)
                    {
                        Status = "Complete! Waiting for application to start.";
                    }
                    else
                    {
                        Status = "Complete! Press Reset button to start application.";
                    }
                    Value = 100;

                    if (DeviceModel.IsSerial)
                    {
                        IsConnectedTimer.Interval = new TimeSpan(0, 0, 10);
                        IsConnectedTimer.Start();
                    }
                }
                catch (Exception e)
                {
                    if (DeviceModel.IsSerial)
                    {
                        IsConnectedTimer.Start();
                    }
                    throw e;
                }
            }, token);
#endif
        } // Update()