private void RunGulu(GuluBase _gulu) { if (guluWorkerRunning__) { MessageBox.Show("Running..."); return; } frmFileList fileListForm = null; foreach (frmDummy child in this.MdiChildren) { if (child is frmFileList) { fileListForm = (child as frmFileList); break; } } if (fileListForm != null) { IList<ListViewItem> selectedItems = fileListForm.SelectedItems; if (selectedItems != null && _gulu != null) { Output.Clear(); Output.Add(string.Format(SunnyChen.Gulu.Win.Properties.Resources.TEXT_INIT_GULU, _gulu.ToString())); if (_gulu.Init()) { if (dockManager.ControlPanes["mainTab"].Closed) { dockManager.ControlPanes["mainTab"].Closed = false; dockManager.ControlPanes["mainTab"].Activate(); } GuluWorkerParameter parameter = new GuluWorkerParameter(_gulu, selectedItems /* Sunny Chen Added 2008/07/01 --> */ , globalConfigReader__ /* Sunny Chen Added 2008/07/01 <-- */ ); ParameterizedThreadStart threadStart = new ParameterizedThreadStart(worker__.WorkingThread); workerThread__ = new Thread(threadStart); workerThread__.Priority = ThreadPriority.BelowNormal; guluWorkerThreads__.Add(workerThread__); guluWorkerRunning__ = true; workerThread__.Start(parameter); GetTool("mnuStop").SharedProps.Enabled = true; taskManager.Enabled = false; fileTreeView.Enabled = false; } else Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_GULU_INIT_FAILED); } else MessageBox.Show(SunnyChen.Gulu.Win.Properties.Resources.TEXT_INFO_NOITEM, SunnyChen.Gulu.Win.Properties.Resources.TEXT_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information); } else MessageBox.Show(SunnyChen.Gulu.Win.Properties.Resources.TEXT_INFO_FILELIST_NOT_OPEN, SunnyChen.Gulu.Win.Properties.Resources.TEXT_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// Gulu worker thread procedure. /// </summary> /// <param name="_param">The parameter of the type GuluWorkerParameter</param> public void WorkingThread(object _param) { Progress.Show(); GuluWorkerParameter parameter = (GuluWorkerParameter)_param; shouldStop__ = false; /* Sunny Chen Added 2008/07/01 --> */ BackupHelper backupHelper = new BackupHelper(parameter.ConfigurationReader.BackupDirectory); /* Sunny Chen Added 2008/07/01 <-- */ // Initialize the current value int i = 0; // Gets the maximum count of the files that needs to be processed int max = parameter.Items.Count; foreach (ListViewItem listViewItem in parameter.Items) { // Sets the progress value Progress.SetProgress(i, max); i++; // If stop is required, just get out of the loop if (shouldStop__) { break; } // Gets the full file name of for the current node. Full file name // is stored in the forth sub item of the list view item. string fileName = listViewItem.SubItems[3].Text; // If the file doesn't exist, prompt the error message and go on with // the next file if (!File.Exists(fileName)) { Output.Add(string.Format(Resources.TEXT_FILE_NOT_EXIST, fileName)); continue; } /* Sunny Chen Added 2008/07/01 --> */ // Backup the files if (parameter.ConfigurationReader.BackupEnabled && parameter.Gulu.BackupRequired) { bool result = backupHelper.Backup(fileName); if (!result) { Output.Add(string.Format(Resources.TEXT_BACKUP_FAILED, fileName)); continue; } } /* Sunny Chen Added 2008/07/01 <-- */ // Runs the gulu to process the current file. If the gulu failed processing, // a FALSE value will be returned and the error message will be added to // the system output if (!parameter.Gulu.Execute(fileName)) { Output.Add(string.Format(Resources.TEXT_FILE_OPER_FAILED, fileName)); } } /* Sunny Chen Added 2008/07/01 --> */ // Generates the backup mapping list. if (parameter.ConfigurationReader.BackupEnabled && parameter.Gulu.BackupRequired) { backupHelper.GenerateMappingList(); } /* Sunny Chen Added 2008/07/01 <-- */ // If shouldStop__ is true, that means it is the user who stops the running // of the gulu worker thread, so it is INTERRUPTED by the user. bool interrupted = shouldStop__ == true; // Calls the worker finished event handler OnGuluWorkerFinished(this, new GuluWorkerFinishedEventArgs(parameter.Gulu, interrupted)); }