private void uxBGProcess_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Dictionary<String, object> objArgument =(Dictionary<String, object>)e.Argument;
                List<String> arguements = (List<String>)objArgument["DefragArguements"];

                StringBuilder output = new StringBuilder();
                output.AppendLine();
                foreach (String argument in arguements)
                {
                    string driveName = argument.Substring(0, 1).ToUpper();
                    output.AppendLine("Drive Name :" + driveName.ToUpper());
                    output.AppendLine("-----------------------------------");
                    commandObj = new CommandObj();
                    commandObj.ProcessName = DefragmentationConstants.PROCESS_NAME;
                    String result = commandObj.Run(DefragmentationConstants.DEFRAGMENTATION, argument, DefragmentationConstants.DEFRAGMENTATION + ".out", "");
                    output.AppendLine(result);
                    output.AppendLine(); output.AppendLine();
                    defragModel.AlignedReport += output.ToString();
                    
                    if (commandObj.IsCancelled) return;
                    //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_DoWork() : Analyze/Defragmentation process was completed for " + argument.Substring(0, 1).ToUpper() + "' Drive");
                }

                e.Result = output.ToString();
                //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_DoWork() : Analyze/Defragmentation process was completed for all selected drives.");
            }
            catch (Exception)
            {
                e.Cancel = true;
                //LogMessage.WriteErrorInfo("DefragmentationService.cs : uxBGProcess_DoWork() :: " + ex.Message);
            }
        }
        private void uxBGProcess_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            
            try
            {

                AnalysisReport = string.Empty;
                //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() method invoked.");
                defragModel.SelectedDrives.Clear();
                if (commandObj.IsCancelled)
                {
                    StopDefragmentation(defragModel);
                }
                else if (e.Cancelled)
                {
                    String message = String.Empty;
                    message = defragModel.Analyse ? DefragmentationConstants.ERROR_ANALYSE : DefragmentationConstants.ERROR_DEFRAGMENT;
                    //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() : " + message);
                    defragModel.Report = message;
                }
                else if (e.Result != null)
                {
                    String driveName = String.Empty;
                    for (int index = 0; index < defragModel.SelectedDrives.Count; index++)
                    {
                        driveName += defragModel.SelectedDrives[index].ToString().Replace("\\", "").ToUpper().Replace(":", "") + "-";
                    }

                    String reportType = defragModel.Analyse ? "Analysis" : "Defrag";

                    if (e.Result.ToString().Contains("The disk defragmenter cannot start because you have insufficient priveleges to perform this operation"))
                    {
                        defragModel.Report = Settings.Default.defragerrortemplate.Replace("{$error$}", "The disk defragmenter cannot start because you have insufficient priveleges to perform this operation");
                    }
                    else
                    {
                        defragModel.Report = defragModel.Analyse ? BuildAnalysisReport(e.Result.ToString()) : BuildDefragReport(e.Result.ToString());
                    }
                }
                else
                {
                    if (commandObj.Result.Contains("The disk defragmenter cannot start because you have insufficient priveleges to perform this operation"))
                    {
                        defragModel.Report = "The disk defragmenter cannot start because you have insufficient priveleges to perform this operation";
                    }
                }
                AnalysisReport = defragModel.Report;
                commandObj = null;
                if (StopOperation != null)
                {
                    StopOperation(defragModel.Report);
                }
                MainWindow.chromiumBrowser.ExecuteScript("javascript:showDefragmentReportData()");

            }
            catch (Exception)
            {
                commandObj = null;
                if (StopOperation != null)
                {
                    StopOperation(defragModel.Report);
                }

                //LogMessage.WriteErrorInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() :: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        private void uxBGProcess_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                string junkfilelistCount = string.Empty;
                //isScanningInprogress = false;
                //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() method invoked.");
                if (commandObj.IsCancelled)
                {
                    //uxDPSStatusPictureBox.Enabled = false;
                    //uxDPSStatusPictureBox.Image = Properties.Resources.red;
                    junkfilelistCount = (junkFileSpecificationsList != null) ? junkFileSpecificationsList.Count.ToString() : "0";
                    chromiumBrowser.ExecuteScript("javascript:diskPerformanceShow('" + isJunkFile + "','" + isInternetOptimizer + "','" + isDiskperformancr + "','" + junkfilelistCount + "','False','" + commandObj.IsCancelled + "')");
                    //StopDefragmentation();

                    //uxStatusPanel.Visible = true;
                    //uxJunkFilesProblemStatus.Visible = true;
                    //if (string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) == false)
                    //{
                    //    uxFixAllButton.Visible = true;
                    //    uxShowDetailsButton.Visible = true;
                    //}
                    //uxJunkFilesProblemStatus.Text = string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) ? "Disk Analysis cancelled by user" : uxJunkFilesProblemStatus.Text + " " + " Disk Analysis cancelled by user";
                }
                else if (e.Cancelled)
                {
                    //String message = String.Empty;
                    //message = defragModel.Analyse ? DefragmentationConstants.ERROR_ANALYSE : DefragmentationConstants.ERROR_DEFRAGMENT;
                    //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() : " + message);
                    //defragModel.Report = message;
                }
                else if (e.Result != null)
                {
                    if (commandObj.Result.Contains("The disk defragmenter cannot start because you have insufficient priveleges to perform this operation"))
                    {
                        //uxDPSStatusPictureBox.Enabled = false;
                        //uxDPSStatusPictureBox.Image = Properties.Resources.red;
                        //uxStatusPanel.Visible = true;
                        //uxJunkFilesProblemStatus.Visible = true;
                        //if (string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) == false)
                        //{
                        //    uxFixAllButton.Visible = true;
                        //    uxShowDetailsButton.Visible = true;
                        //}
                        //uxJunkFilesProblemStatus.Text = string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) ? "Insufficient priveleges to perform Disk Analysis" : uxJunkFilesProblemStatus.Text + " " + " Insufficient priveleges to perform Disk Analysis";
                        junkfilelistCount = (junkFileSpecificationsList != null) ? junkFileSpecificationsList.Count.ToString() : "0";
                        chromiumBrowser.ExecuteScript("javascript:diskPerformanceShow('" + isJunkFile + "','" + isInternetOptimizer + "','" + isDiskperformancr + "','" + junkfilelistCount + "','False','" + commandObj.IsCancelled + "')");
                    }
                    else
                    {

                        //uxDPSStatusPictureBox.Enabled = false;
                        //uxDPSStatusPictureBox.Image = Properties.Resources.green;
                        //uxDiskPerformanceScanLinkLabel.Visible = true;
                        formattedAnalysisReport = BuildAnalysisReport(e.Result.ToString());
                        junkfilelistCount = (junkFileSpecificationsList == null) ? "0" : junkFileSpecificationsList.Count.ToString();
                        chromiumBrowser.ExecuteScript("javascript:diskPerformanceShow('" + isJunkFile + "','" + isInternetOptimizer + "','" + isDiskperformancr + "','" + junkfilelistCount + "','True','" + commandObj.IsCancelled + "')");
                        //uxDiskPerformanceScanReportWebBrowser.DocumentText = formattedAnalysisReport;
                        //uxStatusPanel.Visible = true;
                        //uxJunkFilesProblemStatus.Visible = true;
                        //if (string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) == false)
                        //{
                        //    uxFixAllButton.Visible = true;
                        //    uxShowDetailsButton.Visible = true;
                        //}
                        //uxJunkFilesProblemStatus.Text = string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) ? "Disk performance analysis completed." : uxJunkFilesProblemStatus.Text + " " + " Disk performance analysis completed.";
                    }
                }
                else
                {
                    if (commandObj.Result.Contains("The disk defragmenter cannot start because you have insufficient priveleges to perform this operation"))
                    {
                        //uxDPSStatusPictureBox.Enabled = false;
                        //uxDPSStatusPictureBox.Image = Properties.Resources.red;
                        //uxStatusPanel.Visible = true;
                        //uxJunkFilesProblemStatus.Visible = true;
                        //uxJunkFilesProblemStatus.Text = string.IsNullOrEmpty(uxJunkFilesProblemStatus.Text) ? "Insufficient priveleges to perform Disk Analysis" : uxJunkFilesProblemStatus.Text + " " + " Insufficient priveleges to perform Disk Analysis";
                        chromiumBrowser.ExecuteScript("javascript:diskPerformanceShow('" + isJunkFile + "','" + isInternetOptimizer + "','" + isDiskperformancr + "','" + junkFileSpecificationsList.Count.ToString() + "','False','" + commandObj.IsCancelled + "')");
                    }
                }

                commandObj = null;

                //uxJunkFilesFoldersCheckBox.Enabled = true;
                //uxInternetOptimizerCheckBox.Enabled = true;
                //uxDiskPerformanceCheckBox.Enabled = true;
                //uxScanPanel.Visible = false;
                //uxScanningLabel.Text = "Scanning...";
                //uxJunkFileScanButton.Visible = true;
                //uxStopScanButton.Visible = false;
                //uxJunkFileScanButton.Enabled = true;
            }
            catch (Exception ex)
            {
                commandObj = null;
                ErrorTracker.WriteErrorLog("PCOptimizaton.cs", "uxBGProcess_RunWorkerCompleted", "", ex.Message, ex.StackTrace, "ERROR");
                //LogMessage.WriteErrorInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() :: " + ex.Message);
            }
        }