/// <summary> /// performs task /// </summary> /// <param name="fileName">file full path to perform task on</param> public void Execute(string fileName) { if (fileName.Length > 0) { RevertIndexSettings userSettings = (RevertIndexSettings)Control.Options; Progress(0, -1); LogAdded(string.Format(Properties.Resources.logFileProcessing, fileName)); try { TMFileManager manager = new TMFileManager(fileName); manager.OnProgress += new TMFileManager.OnProgressDelegate(Progress); // check password if (manager.IsProtected && !IsPswValid(manager)) { LogAdded(string.Format(Properties.Resources.logCancelledFile, fileName)); } else { // settings DataImportSettings setts = new DataImportSettings(userSettings.Scenario); setts.OverwriteExistingTUs = userSettings.IsOverwriteTUs; setts.PreservePsw = userSettings.IsPreservePsw; setts.CreateBackupFile = false; // progress & perform task manager.ReverseIndex(string.Format(@"{0}\{1}", userSettings.TargetFolder, Path.GetFileName(fileName)), setts); LogAdded(Properties.Resources.logTaskFinished); LogAdded(string.Format(Properties.Resources.logTUDetails, manager.TUsCount, manager.TUsImportedCount)); } } catch (Exception ex) { LogAdded(string.Format(Properties.Resources.errRevertTaskFailed, fileName, ex.Message)); MessageBox.Show(string.Format(Properties.Resources.errRevertTaskFailed, fileName, ex.Message).Replace("\\r\\n", "\r\n"), Properties.Resources.Title); } Progress(100, -1); } }
/// <summary> /// opens AccessRightsForm form, checks TM password entered by user /// </summary> /// <param name="manager"></param> /// <returns>true - if psw was successfully accepted</returns> private bool IsPswValid(TMFileManager manager) { Form parent = this.Control.UControl.ParentForm; if (parent.InvokeRequired) { // not in the UI thread, so need to call BeginInvoke IAsyncResult ar = parent.BeginInvoke(new UpdatePswDelegate(IsPswValid), new object[] { manager }); return((bool)parent.EndInvoke(ar)); } AccessRightsForm pswForm = new AccessRightsForm(manager); pswForm.ShowDialog(); if (!pswForm.IsPswAccepted) { MessageBox.Show(string.Format(Properties.Resources.accessFileSkipped, Path.GetFileNameWithoutExtension(manager.TMFilePath)), Properties.Resources.Title); } return(pswForm.IsPswAccepted); }
/// <summary> /// initializes new AccessRightsForm /// </summary> /// <param name="TM"></param> public AccessRightsForm(TMFileManager TM) { InitializeComponent(); _tm = TM; }