Exemplo n.º 1
0
        private void buttonGenerate_Click(object sender, RoutedEventArgs e)
        {
            bool dialogResult = false;

            Microsoft.Win32.SaveFileDialog dlg = CreateDialog();
            dialogResult = (checkBoxFile.IsChecked != true || (checkBoxFile.IsChecked == true && dlg.ShowDialog() == true));
            string fileName = null;

            if (dialogResult == true)
            {
                fileName = dlg.FileName;
            }
            BeforeGenerate();
            string keysText = textBoxKeyList.Text.Trim();
            IDictionary <string, IEnumerable <IEnumerable <string> > > resultData = null;

            statusWindow = new StatusWindow((_SelectedFiles != null) ? _SelectedFiles.Count : 0)
            {
                Owner = this,
            };
            statusWindow.Start(() =>
            {
                resultData = Generate(dialogResult, keysText);
            },
                               () =>
            {
                AfterGenerate(resultData, fileName);
            });
        }
Exemplo n.º 2
0
 private void ShowOutputWindow(IDictionary <string, IEnumerable <IEnumerable <string> > > outputdata)
 {
     Application.Current.Dispatcher.Invoke((Action) delegate
     {
         StringBuilder text = new StringBuilder();
         statusWindow       = new StatusWindow((_SelectedFiles != null) ? _SelectedFiles.Count : 0)
         {
             Owner = this,
         };
         statusWindow.Start(() =>
         {
             int line = 0;
             MaxStatusWindow(outputdata.Sum(x => x.Value.Count()));
             UpdateStatusWindow(line, string.Format("Start Generating Output"));
             foreach (var kvp in outputdata.OrderBy(x => x.Key))
             {
                 foreach (var row in kvp.Value)
                 {
                     text.AppendLine("\"" + kvp.Key.Replace(fisrtLineKeyConst, "Key") + "\";" + string.Join(";", row.Select(x => "\"" + x + "\"")));
                     if ((line + 1) % 1000 == 0)
                     {
                         UpdateStatusWindow(line + 1, string.Format("Generating Output"));
                     }
                     line++;
                 }
             }
             UpdateStatusWindow(line, string.Format("Loading Output"));
         },
                            () =>
         {
             if (Dispatcher.CheckAccess())
             {
                 buttonGenerate.IsEnabled = true;
                 InitOutputWindow(text.ToString());
             }
             else
             {
                 Dispatcher.BeginInvoke(new Action(() =>
                 {
                     buttonGenerate.IsEnabled = true;
                     InitOutputWindow(text.ToString());
                 }));
             }
         });
     });
 }
Exemplo n.º 3
0
 private void DisplayResult(IDictionary <string, IEnumerable <IEnumerable <string> > > finalData = null, string fileName = null)
 {
     statusWindow = new StatusWindow((_SelectedFiles != null) ? _SelectedFiles.Count : 0)
     {
         Owner = this,
     };
     statusWindow.Start(() =>
     {
         if (fileOutput == true && finalData != null)
         {
             try
             {
                 using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
                 {
                     int line = 0;
                     UpdateStatusWindow(line, string.Format("Start Writing File"));
                     foreach (var kvp in finalData.OrderBy(x => x.Key))
                     {
                         foreach (var row in kvp.Value)
                         {
                             var o = "\"" + kvp.Key.Replace(fisrtLineKeyConst, "Key") + "\";" + string.Join(";", row.Select(x => "\"" + x + "\""));
                             writer.WriteLine(o);
                             if ((line + 1) % 1000 == 0)
                             {
                                 UpdateStatusWindow(line + 1, string.Format("Writing File"));
                                 writer.Flush();
                             }
                             line++;
                         }
                     }
                     UpdateStatusWindow(line, string.Format("Closing File"));
                     writer.Flush();
                 }
             }
             catch (Exception ex)
             {
                 ShowOutputWindow(finalData);
                 throw ex;
             }
         }
     },
                        () =>
     {
         if (fileOutput != true && finalData != null)
         {
             ShowOutputWindow(finalData);
         }
         else
         {
             if (Dispatcher.CheckAccess())
             {
                 buttonGenerate.IsEnabled = true;
             }
             else
             {
                 Dispatcher.BeginInvoke(new Action(() =>
                 {
                     buttonGenerate.IsEnabled = true;
                 }));
             }
         }
     });
 }