示例#1
0
        private async void ButtonUrlCheck_ClickAsync(object sender, RibbonControlEventArgs e)
        {
            ExcelStatic.StartTask();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            StatusForm statusForm = new StatusForm();

            statusForm.FormClosing += (object s, FormClosingEventArgs eventArgs) => cancellationTokenSource.Cancel();
            AccessibilityChecker accessibilityChecker = new AccessibilityChecker()
            {
                ResultOffSet = this.OffSet
            };

            accessibilityChecker.Reportor.ProgressChange += statusForm.ChangeProgress;
            accessibilityChecker.Reportor.MessageChange  += statusForm.ChangeMessage;
            try
            {
                await accessibilityChecker.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
        }
示例#2
0
        private async void CheckAsync_Click(object sender, RoutedEventArgs e)
        {
            ExcelStatic.StartTask();
            MediaInfoChecker mediaDurationChecker = new MediaInfoChecker()
            {
                ResultOffSet    = ExcelStatic.ResultOffset,
                CheckDuration   = this.CheckDuration.IsChecked.HasValue ? (bool)this.CheckDuration.IsChecked : false,
                CheckHasVideo   = this.CheckHasVideo.IsChecked.HasValue ? (bool)this.CheckHasVideo.IsChecked : false,
                CheckHasAudio   = this.CheckHasAudio.IsChecked.HasValue ? (bool)this.CheckHasAudio.IsChecked : false,
                CheckResolution = this.CheckResolution.IsChecked.HasValue ? (bool)this.CheckResolution.IsChecked : false
            };

            mediaDurationChecker.Reportor.ProgressChange += Reportor_ProgressChange;
            mediaDurationChecker.Reportor.MessageChange  += Reportor_MessageChange;
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            this.Unloaded += (object s, System.Windows.RoutedEventArgs routedEventArgs) =>
            {
                cancellationTokenSource.Cancel();
            };
            try
            {
                await mediaDurationChecker.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
        }
示例#3
0
 private async void ButtonToEnglish_ClickAsync(object sender, RibbonControlEventArgs e)
 {
     ExcelStatic.StartTask();
     try
     {
         Translator translator = new Translator(Properties.Resources.AzureCognitiveBaseUrl, Properties.Resources.AzureCognitiveKey);
         await Controller.TranslateSelectionAsync("en", translator);
     }
     catch (Exception Ex)
     {
         System.Windows.Forms.MessageBox.Show(Ex.Message);
     }
     finally
     {
         ExcelStatic.EndTask();
     }
 }
示例#4
0
        private async void ButtonQRAsync_Click(object sender, RibbonControlEventArgs e)
        {
            ExcelStatic.StartTask();
            string selectedPath;

            using (System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog())
            {
                folderBrowserDialog.Description = "请选择二维码的保存位置:";
                if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    selectedPath = folderBrowserDialog.SelectedPath;
                }
                else
                {
                    return;
                }
            }
            QRGenerator qRGenerator = new QRGenerator(selectedPath)
            {
                ResultOffSet = this.OffSet
            };
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            StatusForm statusForm = new StatusForm();

            statusForm.Show();
            statusForm.FormClosing              += (object s, System.Windows.Forms.FormClosingEventArgs formClosingEventArgs) => cancellationTokenSource.Cancel();
            qRGenerator.Reportor.MessageChange  += statusForm.ChangeMessage;
            qRGenerator.Reportor.ProgressChange += statusForm.ChangeProgress;
            try
            {
                await qRGenerator.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
        }
示例#5
0
        private async void SplitButtonMediaDuration_Click(object sender, RibbonControlEventArgs e)
        {
            //我有点搞不懂了
            //如果这个事件处理程序作为Async void方法,在Ribbon里直接运行,就会有大量内存无法释放
            //但改成普通void方法,在方法内部用action封装一个async方法运行,就不会出现内存无法释放的情况
            //Action action = async() =>
            //  {
            ExcelStatic.StartTask();
            MediaInfoChecker mediaDurationChecker = new MediaInfoChecker()
            {
                ResultOffSet  = this.OffSet,
                CheckDuration = true
            };
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            StatusForm statusForm = new StatusForm();

            statusForm.Show();
            mediaDurationChecker.Reportor.MessageChange  += statusForm.ChangeMessage;
            mediaDurationChecker.Reportor.ProgressChange += statusForm.ChangeProgress;
            statusForm.FormClosing += (object s, System.Windows.Forms.FormClosingEventArgs formClosingEventArgs) => cancellationTokenSource.Cancel();
            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            try
            {
                await mediaDurationChecker.StartAsync(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                mediaDurationChecker.Reportor.MessageChange  -= statusForm.ChangeMessage;
                mediaDurationChecker.Reportor.ProgressChange -= statusForm.ChangeProgress;
                mediaDurationChecker = null;
                System.GC.Collect();
                ExcelStatic.EndTask();
            }
            //  };
            //action.Invoke();
        }
示例#6
0
        private async void ButtonStartTranslate_ClickAsync(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            ExcelStatic.StartTask();
            System.Threading.CancellationTokenSource cancellationTokenSource = new System.Threading.CancellationTokenSource();
            this.Unloaded += (object s, RoutedEventArgs routedEvent) =>
            {
                cancellationTokenSource.Cancel();
            };
            try
            {
                Translator translator           = new Translator(Properties.Resources.AzureCognitiveBaseUrl, Properties.Resources.AzureCognitiveKey);
                string     toLanguageNativeName = (string)this.ComboBoxToLanguage.SelectedItem;
                string     toLanguageCode       = string.Empty;
                foreach (string code in translator.TranslatableLanguages.Keys)
                {
                    if (translator.TranslatableLanguages[code].nativeName == toLanguageNativeName)
                    {
                        toLanguageCode = code;
                        break;
                    }
                }
                translator.ProgressChange += Translator_ProgressChange;
                await Controller.TranslateSelectionAsync(toLanguageCode, translator, cancellationTokenSource.Token);

                this?.Dispatcher.Invoke(() => this.TextBlockTime.Text = "耗时: " + stopwatch.Elapsed.TotalSeconds + "秒");
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
                stopwatch.Stop();
            }
        }
示例#7
0
        private async void ButtonAntiMerge_ClickAsync(object sender, RibbonControlEventArgs e)
        {
#if DEBUG
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            ExcelStatic.StartTask();
            MergeAreas mergeAreas = new MergeAreas();
            StatusForm statusForm = new StatusForm();
            statusForm.Show();
            statusForm.SetStyle(ProgressBarStyle.Marquee);
            mergeAreas.Found += ((object s, EventArgs ea) => statusForm.SetStyle(ProgressBarStyle.Continuous));
            mergeAreas.Reportor.MessageChange  += statusForm.ChangeMessage;
            mergeAreas.Reportor.ProgressChange += statusForm.ChangeProgress;
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            cancellationTokenSource.Token.Register(() => ExcelStatic.EndTask());
            statusForm.FormClosing += delegate
            {
                cancellationTokenSource.Cancel();
            };

            try
            {
                await mergeAreas.SafelyUnMergeAndFill(cancellationTokenSource.Token);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(Ex.Message);
            }
            finally
            {
                ExcelStatic.EndTask();
            }
#if DEBUG
            System.Windows.Forms.MessageBox.Show($"耗时{stopwatch.Elapsed.TotalSeconds.ToString()}秒");
#endif
        }