Esempio n. 1
0
        public IEnumerable <uSyncAction> Export(string folder, SyncEventCallback callback = null, SyncUpdateCallback update = null)
        {
            var actions = new List <uSyncAction>();

            var configuredHandlers = syncHandlers.GetValidHandlers("export", settings).ToList();

            var summary = new SyncProgressSummary(configuredHandlers.Select(x => x.Handler), "Exporting", configuredHandlers.Count);

            foreach (var configuredHandler in configuredHandlers)
            {
                var handler = configuredHandler.Handler;
                summary.Count++;

                summary.UpdateHandler(
                    handler.Name, HandlerStatus.Processing, $"Exporting {handler.Name}", 0);

                callback?.Invoke(summary);

                var handlerActions = handler.ExportAll($"{folder}/{handler.DefaultFolder}", configuredHandler.Settings, update);

                actions.AddRange(handlerActions);

                summary.UpdateHandler(handler.Name, HandlerStatus.Complete, ChangeCount(handlerActions));
            }


            summary.Message = "Export Completed";
            callback?.Invoke(summary);

            return(actions);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        public IEnumerable <uSyncAction> Report(string folder, SyncEventCallback callback = null, SyncUpdateCallback update = null)
        {
            var actions = new List <uSyncAction>();

            var configuredHandlers = syncHandlers.GetValidHandlers("report", settings).ToList();

            var summary = new SyncProgressSummary(configuredHandlers.Select(x => x.Handler), "Reporting", configuredHandlers.Count);

            if (settings.ReportDebug)
            {
                // debug - full export into a dated folder.
                summary.Message = "Debug: Creating Extract in Tracker folder";
                callback?.Invoke(summary);
                this.Export($"~/uSync/Tracker/{DateTime.Now.ToString("yyyyMMdd_HHmmss")}/", null, null);
            }

            foreach (var configuredHandler in configuredHandlers)
            {
                var handler         = configuredHandler.Handler;
                var handlerSettings = configuredHandler.Settings;

                summary.Count++;

                summary.UpdateHandler(handler.Name, HandlerStatus.Processing, $"Reporting {handler.Name}", 0);

                callback?.Invoke(summary);

                var handlerActions = handler.Report($"{folder}/{handler.DefaultFolder}", handlerSettings, update);
                actions.AddRange(handlerActions);

                summary.UpdateHandler(handler.Name, HandlerStatus.Complete, ChangeCount(handlerActions));
            }

            summary.Message = "Report Complete";
            callback?.Invoke(summary);

            return(actions);
        }
Esempio n. 5
0
        /// <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);
                }
            }
        }
Esempio n. 6
0
        /// <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();

                try
                {
                    uSync8BackOffice.eventsPaused = true;

                    // 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.Count++;

                        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.Count++;
                    summary.UpdateHandler("Post Import", HandlerStatus.Pending, "Post Import Actions", 0);

                    callbacks?.Callback?.Invoke(summary);

                    var postImportActions = actions.Where(x => x.Success &&
                                                          x.Change > Core.ChangeType.NoChange &&
                                                          x.RequiresPostProcessing);

                    foreach (var configuredHandler in handlers)
                    {
                        var handler         = configuredHandler.Handler;
                        var handlerSettings = configuredHandler.Settings;

                        if (handler is ISyncPostImportHandler postHandler)
                        {
                            var handlerActions = postImportActions.Where(x => x.ItemType == handler.ItemType);

                            if (handlerActions.Any())
                            {
                                var postActions = postHandler.ProcessPostImport($"{folder}/{handler.DefaultFolder}", handlerActions, handlerSettings);
                                if (postActions != null)
                                {
                                    actions.AddRange(postActions);
                                }
                            }
                        }
                    }

                    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);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    uSync8BackOffice.eventsPaused = false;
                }
            }
        }
Esempio n. 7
0
 public static void FireEventMsg(SyncProgressSummary summary)
 {
     EventMsg?.Invoke(summary);
 }
Esempio n. 8
0
        public IEnumerable <uSyncAction> Import(string folder, bool force, SyncEventCallback callback = null, SyncUpdateCallback update = null)
        {
            lock (_importLock)
            {
                var sw = Stopwatch.StartNew();

                try
                {
                    uSync8BackOffice.eventsPaused = true;

                    var actions = new List <uSyncAction>();

                    var configuredHandlers = syncHandlers.GetValidHandlers("import", settings).ToList();

                    var summary = new SyncProgressSummary(configuredHandlers.Select(x => x.Handler), "Importing", configuredHandlers.Count + 1);
                    summary.Handlers.Add(new SyncHandlerSummary()
                    {
                        Icon   = "icon-traffic",
                        Name   = "Post Import",
                        Status = HandlerStatus.Pending
                    });

                    foreach (var configuredHandler in configuredHandlers)
                    {
                        var handler         = configuredHandler.Handler;
                        var handlerSettings = configuredHandler.Settings;

                        summary.Count++;

                        summary.UpdateHandler(
                            handler.Name, HandlerStatus.Processing, $"Importing {handler.Name}", 0);

                        callback?.Invoke(summary);

                        var handlerActions = handler.ImportAll($"{folder}/{handler.DefaultFolder}", handlerSettings, force, update);
                        actions.AddRange(handlerActions);

                        summary.UpdateHandler(handler.Name, HandlerStatus.Complete, ChangeCount(handlerActions));
                    }


                    // postImport things (mainly cleaning up folders)

                    summary.Count++;
                    summary.UpdateHandler("Post Import", HandlerStatus.Pending, "Post Import Actions", 0);

                    callback?.Invoke(summary);

                    var postImportActions = actions.Where(x => x.Success &&
                                                          x.Change > Core.ChangeType.NoChange &&
                                                          x.RequiresPostProcessing);

                    foreach (var configuredHandler in configuredHandlers)
                    {
                        var handler         = configuredHandler.Handler;
                        var handlerSettings = configuredHandler.Settings;

                        if (handler is ISyncPostImportHandler postHandler)
                        {
                            var handlerActions = postImportActions.Where(x => x.ItemType == handler.ItemType);

                            if (handlerActions.Any())
                            {
                                var postActions = postHandler.ProcessPostImport($"{folder}/{handler.DefaultFolder}", handlerActions, handlerSettings);
                                if (postActions != null)
                                {
                                    actions.AddRange(postActions);
                                }
                            }
                        }
                    }

                    sw.Stop();
                    summary.UpdateHandler("Post Import", HandlerStatus.Complete,
                                          $"Import Completed ({sw.ElapsedMilliseconds}ms)", 0);
                    callback?.Invoke(summary);

                    return(actions);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    uSync8BackOffice.eventsPaused = false;
                }
            }
        }