/// <summary> /// Runs the currently selected template with the currently loaded data. /// </summary> /// <param name="templateScriptPath"> /// The path to the template script. /// </param> public void Run(string templateScriptPath) { if (!File.Exists(templateScriptPath)) { this.ProcessingEvent(this, new ProcessingEventArgs(string.Format(CultureInfo.CurrentCulture, Resources.InstalledFileNotFound, templateScriptPath))); return; } var commands = SyncCollection.LoadSyncList(templateScriptPath); if (commands == null) { return; } foreach (var command in commands) { command.SourceCredentials = (command.SourceConnector != null && command.SourceConnector == "{source}") ? this.Source.LogonCredentials : command.SourceCredentials; command.SourceCredentials = (command.SourceConnector != null && command.SourceConnector == "{target}") ? this.Target.LogonCredentials : command.SourceCredentials; command.TargetCredentials = (command.TargetConnector != null && command.TargetConnector == "{source}") ? this.Source.LogonCredentials : command.TargetCredentials; command.TargetCredentials = (command.TargetConnector != null && command.TargetConnector == "{target}") ? this.Target.LogonCredentials : command.TargetCredentials; command.SourceConnector = this.ReplaceToken(command.SourceConnector); command.TargetConnector = this.ReplaceToken(command.TargetConnector); command.SourceStorePath = this.ReplaceToken(command.SourceStorePath); command.TargetStorePath = this.ReplaceToken(command.TargetStorePath); command.CommandParameter = this.ReplaceToken(command.CommandParameter); } var engine = new SyncEngine { WorkingFolder = Config.WorkingFolder, UiProvider = new UiDispatcher(), }; engine.ProcessingEvent += this.HandleProcessingEvent; engine.ProgressEvent += this.ProgressEvent; try { engine.Execute(commands); } catch (ProcessAbortException) { } engine.ProcessingEvent -= this.HandleProcessingEvent; engine.ProgressEvent -= this.ProgressEvent; if (this.FinishedEvent != null) { this.FinishedEvent(new ProgressEventArgs { PercentageDone = 100 }); } }
/// <summary> /// Opens the current working folder using the explorer /// </summary> public static void OpenWorkingFolder() { var engine = new SyncEngine { WorkingFolder = Config.WorkingFolder }; engine.Execute( new SyncDescription { Command = SyncCommand.OpenDocument.ToString(), CommandParameter = "{FS:WorkingFolder}" }); }
/// <summary> /// Executes the list of commands specified as a path to the file containing the serialized list in the first parameter. /// </summary> /// <param name="args"> /// The parameter that contains the path to the list of serialized commands. /// </param> public static void Main(string[] args) { #if (DEBUG) if (args.Length < 1) { args = new[] { @"{FS:ApplicationFolder}\A Copy OutlookCal to Xml.SyncList" }; } #endif if (args.Length >= 1) { var success = false; try { var defaultBaseFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SemSyncCmd"); Console.WriteLine(Resources.MessageInfoWorkingFolder, defaultBaseFolder); // setup the sync engine var engine = new SyncEngine { WorkingFolder = defaultBaseFolder, UiProvider = new UiDispatcher() }; var filename = engine.ReplacePathToken(args[0]); if (!File.Exists(filename)) { Console.WriteLine(Resources.ErrorMessageFileNotFound + filename); } else { // load the list of commands Console.WriteLine(Resources.MessageInfoLoadingList, filename); var syncCommands = SyncCollection.LoadSyncList(filename); // feed dispatcher with credentials if specified by the command line ((UiDispatcher)engine.UiProvider).UserDomain = args.Length > 1 ? args[1] : string.Empty; ((UiDispatcher)engine.UiProvider).UserName = args.Length > 2 ? args[2] : string.Empty; ((UiDispatcher)engine.UiProvider).UserPassword = args.Length > 3 ? args[3] : string.Empty; // connect to events engine.ProcessingEvent += ProcessingEvent; engine.ProgressEvent += ProgressEvent; // execute commands success = engine.Execute(syncCommands); // disconnect from events engine.ProcessingEvent -= ProcessingEvent; engine.ProgressEvent -= ProgressEvent; } } catch (Exception ex) { Console.WriteLine(Resources.MessageErrorException, ex); } Console.WriteLine(Resources.MessageInfoStatus, success ? "success" : "failed"); } else { Console.WriteLine( Resources.MessageInfoUsage, Path.GetFileNameWithoutExtension(Assembly.GetAssembly(typeof(Program)).CodeBase)); } #if (DEBUG) // wait for user input if in debug build Console.WriteLine(Resources.MessageInfoCloseWithEnter); Console.ReadLine(); #endif }