/// <summary> /// Report the changes for a folder /// </summary> /// <param name="folder">Folder to run the report for</param> /// <param name="handlerOptions">Options to use for the report - used to load the handlers.</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, SyncHandlerOptions handlerOptions, uSyncCallbacks callbacks = null) { if (handlerOptions == null) { handlerOptions = new SyncHandlerOptions(); } handlerOptions.Action = HandlerActions.Report; var handlers = _handlerFactory.GetValidHandlers(handlerOptions); return(Report(folder, handlers, callbacks)); }
/// <summary> /// Export items from umbraco into a given folder /// </summary> /// <param name="folder">folder to place items</param> /// <param name="handlerAliases">aliases for the handlers to use while exporting</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 <string> handlerAliases, uSyncCallbacks callbacks) { var handlers = _handlerFactory.GetDefaultHandlers(handlerAliases); return(Export(folder, handlers, callbacks)); }
/// <summary> /// Export items from umbraco into a given folder /// </summary> /// <param name="folder">folder to place items</param> /// <param name="handlers">Handler config pairs</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 <HandlerConfigPair> handlers, uSyncCallbacks callbacks) { var sw = Stopwatch.StartNew(); _mutexService.FireBulkStarting(new uSyncExportStartingNotification()); 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); _mutexService.FireBulkComplete(new uSyncExportCompletedNotification(actions)); sw.Stop(); _logger.LogInformation("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 <HandlerConfigPair> 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 = _mutexService.ImportPause()) { // pre import event _mutexService.FireBulkStarting(new uSyncImportStartingNotification()); 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 _mutexService.FireBulkComplete(new uSyncImportCompletedNotification(actions)); _logger.LogInformation("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); } } }