コード例 #1
0
        protected virtual void Process(IProgressStatus progress, ILogger additionalLogger)
        {
            var configurations = ResolveConfigurations();
            int taskNumber     = 1;

            foreach (var configuration in configurations)
            {
                var logger = configuration.Resolve <ILogger>();

                using (new LoggingContext(additionalLogger, configuration))
                {
                    try
                    {
                        var timer = new Stopwatch();
                        timer.Start();

                        logger.Info(string.Empty);
                        logger.Info(configuration.Name + " is being reserialized.");

                        using (new TransparentSyncDisabler())
                        {
                            var targetDataStore = configuration.Resolve <ITargetDataStore>();
                            var helper          = configuration.Resolve <SerializationHelper>();

                            // nuke any existing items in the store before we begin. This is a full reserialize so we want to
                            // get rid of any existing stuff even if it's not part of existing configs
                            logger.Warn("[D] Clearing existing items from {0} (if any)".FormatWith(targetDataStore.FriendlyName));
                            targetDataStore.Clear();

                            var roots = configuration.Resolve <PredicateRootPathResolver>().GetRootSourceItems();

                            int index = 1;
                            foreach (var root in roots)
                            {
                                helper.DumpTree(root, new[] { configuration });
                                WebConsoleUtility.SetTaskProgress(progress, taskNumber, configurations.Length, (int)((index / (double)roots.Length) * 100));
                                index++;
                            }
                        }

                        timer.Stop();

                        CorePipeline.Run("unicornReserializeComplete", new UnicornReserializeCompletePipelineArgs(configuration));

                        logger.Info("{0} reserialization complete in {1}ms.".FormatWith(configuration.Name, timer.ElapsedMilliseconds));
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        break;
                    }

                    taskNumber++;
                }
            }
        }
コード例 #2
0
ファイル: SyncVerb.cs プロジェクト: sw08023/UNICORN
        protected virtual void Process(IProgressStatus progress, ILogger additionalLogger)
        {
            var configurations = ResolveConfigurations();
            int taskNumber     = 1;

            foreach (var configuration in configurations)
            {
                var logger = configuration.Resolve <ILogger>();
                var helper = configuration.Resolve <SerializationHelper>();

                using (new LoggingContext(additionalLogger, configuration))
                {
                    try
                    {
                        logger.Info(configuration.Name + " is being synced.");

                        using (new TransparentSyncDisabler())
                        {
                            var pathResolver = configuration.Resolve <PredicateRootPathResolver>();

                            var roots = pathResolver.GetRootSerializedItems();

                            var index = 0;

                            helper.SyncTree(configuration, item =>
                            {
                                WebConsoleUtility.SetTaskProgress(progress, taskNumber, configurations.Length, (int)((index / (double)roots.Length) * 100));
                                index++;
                            }, roots);
                        }
                    }
                    catch (DeserializationSoftFailureAggregateException ex)
                    {
                        logger.Error(ex);
                        // allow execution to continue, because the exception was non-fatal
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        break;
                    }
                }

                taskNumber++;
            }

            try
            {
                CorePipeline.Run("unicornSyncEnd", new UnicornSyncEndPipelineArgs(progress, configurations));
            }
            catch (Exception exception)
            {
                Log.Error("Error occurred in unicornSyncEnd pipeline.", exception);
                progress.ReportException(exception);
            }
        }
コード例 #3
0
        public virtual bool SyncConfigurations(IConfiguration[] configurations, IProgressStatus progress, ILogger additionalLogger)
        {
            int taskNumber = 1;

            bool success = true;

            try
            {
                var startArgs = new UnicornSyncStartPipelineArgs(OperationType.FullSync, configurations, additionalLogger, null);
                MergePipelineArgs(startArgs);
                CorePipeline.Run("unicornSyncStart", startArgs);

                if (startArgs.SyncIsHandled)
                {
                    additionalLogger.Info("Unicorn Sync Start pipeline signalled that it handled the sync for all configurations.");
                    return(true);
                }

                foreach (var configuration in configurations)
                {
                    var logger = configuration.Resolve <ILogger>();
                    var helper = configuration.Resolve <SerializationHelper>();

                    using (new LoggingContext(additionalLogger, configuration))
                    {
                        try
                        {
                            var startStatement = new StringBuilder();
                            startStatement.Append(configuration.Name);
                            startStatement.Append(" is being synced");

                            if (configuration.EnablesDilithium())
                            {
                                startStatement.Append(" with Dilithium");
                                if (configuration.EnablesDilithiumSql())
                                {
                                    startStatement.Append(" SQL");
                                }
                                if (configuration.EnablesDilithiumSql() && configuration.EnablesDilithiumSfs())
                                {
                                    startStatement.Append(" +");
                                }
                                if (configuration.EnablesDilithiumSfs())
                                {
                                    startStatement.Append(" Serialized");
                                }
                                startStatement.Append(" enabled.");
                            }
                            else
                            {
                                startStatement.Append(".");
                            }

                            logger.Info(startStatement.ToString());

                            using (new TransparentSyncDisabler())
                            {
                                var predicate = configuration.Resolve <IPredicate>();

                                var roots = predicate.GetRootPaths();

                                var index = 0;
                                helper.SyncTree(
                                    configuration: configuration,
                                    rootLoadedCallback: item =>
                                {
                                    WebConsoleUtility.SetTaskProgress(progress, taskNumber, configurations.Length, (int)((index / (double)roots.Length) * 100));
                                    index++;
                                },
                                    runSyncStartPipeline: false
                                    );
                            }
                        }
                        catch (DeserializationSoftFailureAggregateException ex)
                        {
                            logger.Error(ex);
                            // allow execution to continue, because the exception was non-fatal
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex);
                            success = false;
                            break;
                        }
                    }

                    taskNumber++;
                }
            }
            finally
            {
                ReactorContext.Dispose();
            }

            try
            {
                CorePipeline.Run("unicornSyncEnd", MergePipelineArgs(new UnicornSyncEndPipelineArgs(additionalLogger, success, configurations)));
            }
            catch (Exception exception)
            {
                Log.Error("Error occurred in unicornSyncEnd pipeline.", exception);
                additionalLogger.Error(exception);
            }

            return(success);
        }
コード例 #4
0
        public void ProgressBarCalculationTests()
        {
            var progress = Substitute.For <IProgressStatus>();

            WebConsoleUtility.SetTaskProgress(progress, 1, 201, (int)((1 / (double)201) * 100));
        }