/// <summary>
 /// Gets the list of the logical drives in the system
 /// </summary>
 /// <param name="_defragModel"></param>
 public void GetSystemDrives(ref IDefragmentation _defragModel)
 {
     try
     {
         _defragModel.Drives = SystemToolsProxy.GetSystemDrives();
     }
     catch (Exception ex)
     {
         //LogMessage.WriteErrorInfo("DefragmentationService.cs : GetSystemDrives() :: " + ex.Message);
         //ErrorTracker.WriteErrorLog("DefragmentationService.cs", "GetSystemDrives()", "", ex.Message, ex.StackTrace, "Error");
     }
 }
Ejemplo n.º 2
0
        public DefragmentInterface()
        {

            _defragModel = new DefragmentationModel();
            _defragService = new DefragmentationService();
            
            _defragService.GetSystemDrives(ref _defragModel);
            _defragView.Drives = _defragModel.Drives;
           
            //return "234";

            //MainWindow.chromiumBrowser.ExecuteScript("javascript:getDriverDetails('" + driversList + "')");
        }
 public DefragmentationPresenter(IDefragmentation defragView)
 {
     try
     {
         _defragView = defragView;
         _defragService = new DefragmentationService();
         _defragService.StopOperation = new DefragmentationService.StopOperationDelegate(StopOperation);
         _defragService.ClearReport = new DefragmentationService.ClearReportDelegate(ClearReport);
         _defragModel = new DefragmentationModel();
     }
     catch (Exception ex)
     {
         //LogMessage.WriteErrorInfo("DefragmentationPresenter.cs : DefragmentationPresenter() :: " + ex.Message);
         //ErrorTracker.WriteErrorLog("DefragmentationPresenter.cs", "DefragmentationPresenter()", "", ex.Message, ex.StackTrace, "Error");
     }
 }
        /// <summary>
        /// Start / Stop the defragmentation process based on the event triggerred from the GUI
        /// </summary>
        /// <param name="_defragModel"></param>
        public void StartDefragmentation(IDefragmentation _defragModel)
        {
            try
            {
                defragModel = _defragModel;
                //LogMessage.WriteLogInfo("DefragmentationService.cs : PerformOperation() method invoked.");

                //Start the defragmentation coz the user has clicked on Start
                //LogMessage.WriteLogInfo("DefragmentationService.cs : PerformOperation() :: Requested operation is going to start.");

                if (_defragModel.SelectedDrives.Count == 0)
                {
                    //No drives selected? Throw an exception...
                    String message = String.Empty;
                    message = _defragModel.Analyse ? "Select a drive to analyze" : "Select a drive to defragment";
                    //LogMessage.WriteLogInfo("DefragmentationService.cs : PerformOperation() :: " + message);
                    throw new Exception(message);
                }
                else
                {
                    //Good job! We've got something to defragment...

                    _defragModel.Report = String.Empty;

                    if (ClearReport != null)
                    {
                        ClearReport(_defragModel.Report);
                    }

                    List<String> arguments = new List<string>();
                    String argument = String.Empty;

                    //LogMessage.WriteLogInfo("DefragmentationService.cs : PerformOperation() :: Building arguements.");

                    //Now.. Lets build our command with its arguments...
                    /*
                     * -a : Analyse
                     * -f : Force defragment even if free space is lower than required
                     * -v : Get the verbose output (Detailed Analysis Report)
                     */

                    for (int index = 0; index < _defragModel.SelectedDrives.Count; index++)
                    {
                        argument = _defragModel.SelectedDrives[index].ToString().Replace("\\", "").ToLower();

                        if (_defragModel.Analyse)
                        {
                            argument = argument + " -a ";
                        }
                        else if (_defragModel.Defragment && !_defragModel.ForceDefragment)
                        {
                            argument = argument + " ";
                        }
                        else if (_defragModel.Defragment && _defragModel.ForceDefragment)
                        {
                            argument = argument + " -f ";
                        }

                        argument = argument + " -v ";

                        arguments.Add(argument);
                    }


                    Dictionary<String, object> objArgument = new Dictionary<string, object>();
                    objArgument.Add("DefragArguements", arguments);

                    //Let's defragment in the background...
                    BackgroundWorker uxBGProcess1 = new BackgroundWorker();
                    uxBGProcess1.WorkerSupportsCancellation = true;
                    uxBGProcess1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(uxBGProcess_RunWorkerCompleted);
                    uxBGProcess1.DoWork += new DoWorkEventHandler(uxBGProcess_DoWork);
                    //LogMessage.WriteLogInfo("DefragmentationService.cs : PerformOperation() :: uxBGProcess background worker was initiated to start the Analyze/Defragmentation process.");

                    //Trigger the worker thread...
                    uxBGProcess1.RunWorkerAsync((object)objArgument);
                }
            }
            catch (Exception ex)
            {
                //LogMessage.WriteErrorInfo("DefragmentationService.cs : uxBGProcess_DoWork() :: " + ex.Message);
                //ErrorTracker.WriteErrorLog("DefragmentationService.cs", "StartDefragmentation()", "", ex.Message, ex.StackTrace, "Error");
            }
        }
 internal void StopDefragmentation(IDefragmentation _defragModel)
 {
     try
     {
         commandObj.IsCancelled = true;
         //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() : Analyze/Defragmentation process cancelled.");
         Process[] processes = Process.GetProcessesByName(DefragmentationConstants.DEFRAGMENTATIONSUPPORT);
         // if there is one process...
         if (processes.Length > 0)
         {
             processes[0].Kill();
             //LogMessage.WriteLogInfo("DefragmentationService.cs : uxBGProcess_RunWorkerCompleted() : 'dfrgntfs' process was killed.");
         }
         StringBuilder message = new StringBuilder();
         string strMessage = _defragModel.Analyse ? defragModel.Report = Settings.Default.defragerrortemplate.Replace("{$error$}", "Disk analysis was cancelled by the user") : defragModel.Report = Settings.Default.defragerrortemplate.Replace("{$error$}", "Disk defragmentation was cancelled by the user");
         message.AppendLine();
         message.Append(strMessage);
         _defragModel.Report = message.ToString();
     }
     catch (Exception)
     {
         //LogMessage.WriteErrorInfo("DefragmentationService.cs : StopCleanup() :: " + ex.Message);
     }
 }