/// <summary> /// Report the changes for a folder /// </summary> /// <param name="folder">Folder to run the report for</param> /// <param name="handlers">List of SyncHandlers to use for the report</param> /// <param name="callbacks">Callback functions to keep UI uptodate</param> /// <returns>List of actions detailing what would and wouldn't change</returns> public IEnumerable <uSyncAction> Report(string folder, IEnumerable <ExtendedHandlerConfigPair> handlers, uSyncCallbacks callbacks) { var sw = Stopwatch.StartNew(); fireBulkStarting(ReportStarting); logger.Debug <uSyncService>("Reporting For [{0}]", string.Join(",", handlers.Select(x => x.Handler.Name))); var actions = new List <uSyncAction>(); var summary = new SyncProgressSummary(handlers.Select(x => x.Handler), "Reporting", handlers.Count()); if (GlobalSettings.DebugMode && settings.ReportDebug) { // debug - full export into a dated folder. summary.UpdateMessage("Debug: Creating Extract in Tracker folder"); logger.Warn <uSyncService>("Running Report Debug - this can be a slow process, don't enable unless you need it"); callbacks?.Callback?.Invoke(summary); this.Export($"~/uSync/Tracker/{DateTime.Now.ToString("yyyyMMdd_HHmmss")}/", handlers, callbacks); } foreach (var configuredHandler in handlers) { var handler = configuredHandler.Handler; var handlerSettings = configuredHandler.Settings; summary.Increment(); summary.UpdateHandler(handler.Name, HandlerStatus.Processing, $"Reporting {handler.Name}", 0); callbacks?.Callback?.Invoke(summary); var handlerActions = handler.Report($"{folder}/{handler.DefaultFolder}", handlerSettings, callbacks?.Update); actions.AddRange(handlerActions); summary.UpdateHandler(handler.Name, HandlerStatus.Complete, handlerActions.CountChanges(), handlerActions.ContainsErrors()); } summary.UpdateMessage("Report Complete"); callbacks?.Callback?.Invoke(summary); fireBulkComplete(ReportComplete, actions); sw.Stop(); logger.Info <uSyncService>("uSync Report: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms", handlers.Count(), actions.Count, actions.CountChanges(), sw.ElapsedMilliseconds); callbacks?.Update?.Invoke($"Processed {actions.Count} items in {sw.ElapsedMilliseconds}ms", 1, 1); return(actions); }
/// <summary> /// Export items from umbraco into a given folder /// </summary> /// <param name="folder">folder to place items</param> /// <param name="handlerAliases">List of handlers to use for export</param> /// <param name="callbacks">callback functions to update the UI</param> /// <returns>List of actions detailing what was exported</returns> public IEnumerable <uSyncAction> Export(string folder, IEnumerable <ExtendedHandlerConfigPair> handlers, uSyncCallbacks callbacks) { var sw = Stopwatch.StartNew(); fireBulkStarting(ExportStarting); var actions = new List <uSyncAction>(); var summary = new SyncProgressSummary(handlers.Select(x => x.Handler), "Exporting", handlers.Count()); foreach (var configuredHandler in handlers) { var handler = configuredHandler.Handler; summary.Increment(); summary.UpdateHandler( handler.Name, HandlerStatus.Processing, $"Exporting {handler.Name}", 0); callbacks?.Callback?.Invoke(summary); var handlerActions = handler.ExportAll($"{folder}/{handler.DefaultFolder}", configuredHandler.Settings, callbacks?.Update); actions.AddRange(handlerActions); summary.UpdateHandler(handler.Name, HandlerStatus.Complete, handlerActions.CountChanges(), handlerActions.ContainsErrors()); } summary.UpdateMessage("Export Completed"); callbacks?.Callback?.Invoke(summary); fireBulkComplete(ExportComplete, actions); sw.Stop(); logger.Info <uSyncService>("uSync Export: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms", handlers.Count(), actions.Count, actions.CountChanges(), sw.ElapsedMilliseconds); callbacks?.Update?.Invoke($"Processed {actions.Count} items in {sw.ElapsedMilliseconds}ms", 1, 1); return(actions); }
/// <summary> /// Import items into umbraco from a given folder /// </summary> /// <param name="folder">Folder to use for the import</param> /// <param name="force">Push changes in even if there is no difference between the file and the item in umbraco</param> /// <param name="handlers">List of Handlers & config to use for import</param> /// <param name="callbacks">Callbacks to keep UI informed</param> /// <returns>List of actions detailing what did and didn't change</returns> public IEnumerable <uSyncAction> Import(string folder, bool force, IEnumerable <ExtendedHandlerConfigPair> handlers, uSyncCallbacks callbacks) { // if its blank, we just throw it back empty. if (handlers == null || !handlers.Any()) { return(Enumerable.Empty <uSyncAction>()); } lock (_importLock) { var sw = Stopwatch.StartNew(); using (var pause = new uSyncImportPause()) { // pre import event fireBulkStarting(ImportStarting); var actions = new List <uSyncAction>(); var summary = new SyncProgressSummary(handlers.Select(x => x.Handler), "Importing", handlers.Count() + 1); summary.Handlers.Add(new SyncHandlerSummary() { Icon = "icon-defrag", Name = "Post Import", Status = HandlerStatus.Pending }); foreach (var configuredHandler in handlers) { var handler = configuredHandler.Handler; var handlerSettings = configuredHandler.Settings; summary.Increment(); summary.UpdateHandler( handler.Name, HandlerStatus.Processing, $"Importing {handler.Name}", 0); callbacks?.Callback?.Invoke(summary); var handlerActions = handler.ImportAll($"{folder}/{handler.DefaultFolder}", handlerSettings, force, callbacks?.Update); actions.AddRange(handlerActions); summary.UpdateHandler(handler.Name, HandlerStatus.Complete, handlerActions.CountChanges(), handlerActions.ContainsErrors()); } // postImport things (mainly cleaning up folders) summary.Increment(); summary.UpdateHandler("Post Import", HandlerStatus.Pending, "Post Import Actions", 0); callbacks?.Callback?.Invoke(summary); actions.AddRange(PerformPostImport(folder, handlers, actions)); sw.Stop(); summary.UpdateHandler("Post Import", HandlerStatus.Complete, "Import Completed", 0); callbacks?.Callback?.Invoke(summary); // fire complete fireBulkComplete(ImportComplete, actions); logger.Info <uSyncService>("uSync Import: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms", handlers.Count(), actions.Count, actions.CountChanges(), sw.ElapsedMilliseconds); callbacks?.Update?.Invoke($"Processed {actions.Count} items in {sw.ElapsedMilliseconds}ms", 1, 1); return(actions); } } }