Пример #1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     this.Dispatcher.Invoke(() => {
         DoneHelpWindow doneWindow = new DoneHelpWindow();
         doneWindow.Show();
         this.Close();
     });
 }
Пример #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                //  Run the batch file
                Process batchFile                          = new Process();
                batchFile.StartInfo.FileName               = @"onedrivemigrate.bat";
                batchFile.StartInfo.Arguments              = "";
                batchFile.StartInfo.CreateNoWindow         = true;
                batchFile.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                batchFile.StartInfo.RedirectStandardOutput = true;
                batchFile.StartInfo.RedirectStandardError  = true;
                batchFile.StartInfo.RedirectStandardInput  = true;
                batchFile.StartInfo.WorkingDirectory       = System.AppContext.BaseDirectory;
                batchFile.StartInfo.UseShellExecute        = false;
                batchFile.OutputDataReceived              += new DataReceivedEventHandler(dataOutputHandler);

                try
                {
                    batchFile.Start();
                    batchFile.BeginOutputReadLine();
                    batchFile.BeginErrorReadLine();

                    batchFile.WaitForExit();
                    done = true;

                    if (batchFile.ExitCode == 0)
                    {
                        // Create a hidden file in the user's Z: drive to flag it
                        try
                        {
                            using (FileStream fs = new FileStream(markerFileName, FileMode.OpenOrCreate))
                            {
                                using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
                                {
                                    writer.WriteLine(DateTime.Now + "\tOnedrive successfully migrated");
                                }

                                File.SetAttributes(markerFileName, File.GetAttributes(markerFileName) | FileAttributes.Hidden);
                            }
                        }
                        catch { }

                        this.Dispatcher.Invoke(() => {
                            DoneHelpWindow doneWindow = new DoneHelpWindow();
                            doneWindow.Show();
                            this.Close();
                        });
                    }
                    else if (batchFile.ExitCode == 666)
                    {
                        throw new Exception("Unable to migrate as user has no Z: drive");
                    }
                    else
                    {
                        throw new Exception("Unable to migrate - see the output window for more information");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error migrating!" + ex.Message, "NOT COMPLETE", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });
        }