/// <remarks>All roots must live within the same configuration! Make sure that the roots are from the target data store.</remarks>
        public virtual bool SyncTree(IConfiguration configuration, Action <IItemData> rootLoadedCallback = null, params IItemData[] roots)
        {
            var logger = configuration.Resolve <ILogger>();

            var beginArgs = new UnicornSyncBeginPipelineArgs(configuration);

            CorePipeline.Run("unicornSyncBegin", beginArgs);

            if (beginArgs.Aborted)
            {
                logger.Error("Unicorn Sync Begin pipeline was aborted. Not executing sync for this configuration.");
                return(false);
            }

            if (beginArgs.SyncIsHandled)
            {
                logger.Info("Unicorn Sync Begin pipeline signalled that it handled the sync for this configuration.");
                return(true);
            }

            var syncStartTimestamp = DateTime.Now;

            using (new TransparentSyncDisabler())
            {
                var retryer            = configuration.Resolve <IDeserializeFailureRetryer>();
                var consistencyChecker = configuration.Resolve <IConsistencyChecker>();
                var loader             = configuration.Resolve <SerializationLoader>();

                loader.LoadAll(roots, retryer, consistencyChecker, rootLoadedCallback);
            }

            CorePipeline.Run("unicornSyncComplete", new UnicornSyncCompletePipelineArgs(configuration, syncStartTimestamp));

            return(true);
        }
Exemple #2
0
        protected override void Process(IProgressStatus progress)
        {
            var configurations = ResolveConfigurations();

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

                using (new LoggingContext(new WebConsoleLogger(progress), configuration))
                {
                    try
                    {
                        logger.Info("Control Panel Sync: Processing Unicorn configuration " + configuration.Name);

                        var beginArgs = new UnicornSyncBeginPipelineArgs(configuration);
                        CorePipeline.Run("unicornSyncBegin", beginArgs);

                        if (beginArgs.Aborted)
                        {
                            logger.Error("Unicorn Sync Begin pipeline was aborted. Not executing sync for this configuration.");
                            continue;
                        }

                        if (beginArgs.SyncIsHandled)
                        {
                            logger.Info("Unicorn Sync Begin pipeline signalled that it handled the sync for this configuration.");
                            continue;
                        }

                        var pathResolver       = configuration.Resolve <PredicateRootPathResolver>();
                        var retryer            = configuration.Resolve <IDeserializeFailureRetryer>();
                        var consistencyChecker = configuration.Resolve <IConsistencyChecker>();
                        var loader             = configuration.Resolve <SerializationLoader>();

                        var roots = pathResolver.GetRootSerializedItems();

                        var index = 0;

                        loader.LoadAll(roots, retryer, consistencyChecker, item =>
                        {
                            progress.Report((int)(((index + 1) / (double)roots.Length) * 100));
                            index++;
                        });

                        CorePipeline.Run("unicornSyncComplete", new UnicornSyncCompletePipelineArgs(configuration));

                        logger.Info("Control Panel Sync: Completed syncing Unicorn configuration " + configuration.Name);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        break;
                    }
                }
            }

            CorePipeline.Run("unicornSyncEnd", new UnicornSyncEndPipelineArgs(configurations));
        }
Exemple #3
0
        /// <remarks>All roots must live within the same configuration! Make sure that the roots are from the target data store.</remarks>
        public virtual bool SyncTree(IConfiguration configuration, Action <IItemData> rootLoadedCallback = null, params IItemData[] roots)
        {
            var logger = configuration.Resolve <ILogger>();

            var beginArgs = new UnicornSyncBeginPipelineArgs(configuration);

            CorePipeline.Run("unicornSyncBegin", beginArgs);

            if (beginArgs.Aborted)
            {
                logger.Error("Unicorn Sync Begin pipeline was aborted. Not executing sync for this configuration.");
                return(false);
            }

            if (beginArgs.SyncIsHandled)
            {
                logger.Info("Unicorn Sync Begin pipeline signalled that it handled the sync for this configuration.");
                return(true);
            }

            var syncStartTimestamp = DateTime.Now;

            using (new TransparentSyncDisabler())
            {
                var retryer            = configuration.Resolve <IDeserializeFailureRetryer>();
                var consistencyChecker = configuration.Resolve <IConsistencyChecker>();
                var loader             = configuration.Resolve <SerializationLoader>();

                if (roots.Length > 0)
                {
                    loader.LoadAll(roots, retryer, consistencyChecker, rootLoadedCallback);
                }
                else
                {
                    logger.Warn($"{configuration.Name} had no root paths included to sync. If you're only syncing roles, this is expected. Otherwise it indicates that your predicate has no included items and you need to add some.");
                }
            }

            CorePipeline.Run("unicornSyncComplete", new UnicornSyncCompletePipelineArgs(configuration, syncStartTimestamp));

            return(true);
        }
        public void Process(UnicornSyncBeginPipelineArgs args)
        {
            var serializationProvider = args.Configuration.Resolve <ISerializationProvider>();
            var logger = args.Configuration.Resolve <ILogger>();

            var remotingSerializationProvider = serializationProvider as IRemotingSerializationProvider;

            if (remotingSerializationProvider == null)
            {
                return;
            }

            // get package
            if (string.IsNullOrWhiteSpace(remotingSerializationProvider.RemoteUrl))
            {
                logger.Error("Remoting URL was not set on " + remotingSerializationProvider.GetType().Name + "; cannot update remote.");
                args.AbortPipeline();
                return;
            }

            if (HttpContext.Current != null && HttpContext.Current.Request.Url.Host.Equals(new Uri(remotingSerializationProvider.RemoteUrl).Host, StringComparison.OrdinalIgnoreCase))
            {
                logger.Warn("Remoting: Remote URL was local instance - skipping this configuration as it is by definition already synced.");
                args.SyncIsHandled = true;
                return;
            }

            var lastLoaded = GetLastLoadedTime(args.Configuration.Name);

            // if you pass the force parameter, we do not use the history engine differential sync
            if (remotingSerializationProvider.DisableDifferentialSync || (HttpContext.Current != null && HttpContext.Current.Request.QueryString["force"] != null))
            {
                lastLoaded = _unsyncedDateTimeValue;
            }

            var url = string.Format("{0}?c={1}&ts={2}", remotingSerializationProvider.RemoteUrl, args.Configuration.Name, lastLoaded);

            var webClient = new SuperWebClient();

            // TODO; add signature to request

            RemotingPackage package = null;

            try
            {
                logger.Info("Remoting: Downloading updated items from {0} newer than {1}".FormatWith(remotingSerializationProvider.RemoteUrl, lastLoaded.ToLocalTime()));

                var tempFileName = HostingEnvironment.MapPath("~/temp/" + Guid.NewGuid() + ".zip");

                try
                {
                    webClient.DownloadFile(url, tempFileName);
                    using (var stream = File.OpenRead(tempFileName))
                    {
                        package = RemotingPackage.FromStream(stream);
                    }
                }
                finally
                {
                    if (File.Exists(tempFileName))
                    {
                        File.Delete(tempFileName);
                    }
                }

                WritePackageToProvider(package, args.Configuration);

                if (package.Manifest.Strategy == RemotingStrategy.Differential)
                {
                    logger.Info("Remoting: received differential package with {0} changes. Replaying instead of sync.".FormatWith(package.Manifest.HistoryEntries.Length));

                    var replayer = new DifferentialPackageReplayer(package);

                    if (!replayer.Replay(logger))
                    {
                        logger.Error("Remoting package replay signalled an error. Aborting.");
                        args.AbortPipeline();
                        return;
                    }
                    else
                    {
                        args.SyncIsHandled = true;
                    }
                }
                else
                {
                    logger.Info("Remoting: received full package from remote. Deployed and executing sync.");
                }

                SetLastLoadedTime(args.Configuration.Name, package.Manifest.LastSynchronized);
            }
            finally
            {
                // clean up temp files
                if (package != null)
                {
                    package.Dispose();
                }
            }
        }
Exemple #5
0
        /// <remarks>All roots must live within the same configuration! Make sure that the roots are from the target data store.</remarks>
        public virtual bool SyncTree(IConfiguration configuration, Action <IItemData> rootLoadedCallback = null, bool runSyncStartPipeline = true, IItemData partialSyncRoot = null)
        {
            var logger = configuration.Resolve <ILogger>();

            // check if Dilithium was already running. If it was, we won't dispose it when we're done.
            bool dilithiumWasStarted = ReactorContext.IsActive;

            var syncStartTimestamp = DateTime.Now;

            try
            {
                if (runSyncStartPipeline)
                {
                    var startArgs = new UnicornSyncStartPipelineArgs(OperationType.PartialSync, new[] { configuration }, logger, partialSyncRoot);
                    MergePipelineArgs(startArgs);
                    CorePipeline.Run("unicornSyncStart", startArgs);

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

                var beginArgs = new UnicornSyncBeginPipelineArgs(configuration);
                MergePipelineArgs(beginArgs);
                CorePipeline.Run("unicornSyncBegin", beginArgs);

                if (beginArgs.Aborted)
                {
                    if (!dilithiumWasStarted)
                    {
                        ReactorContext.Dispose();
                    }

                    logger.Error("Unicorn Sync Begin pipeline was aborted. Not executing sync for this configuration.");
                    return(false);
                }

                if (beginArgs.SyncIsHandled)
                {
                    if (!dilithiumWasStarted)
                    {
                        ReactorContext.Dispose();
                    }

                    logger.Info("Unicorn Sync Begin pipeline signalled that it handled the sync for this configuration.");
                    return(true);
                }

                using (new TransparentSyncDisabler())
                {
                    var retryer            = configuration.Resolve <IDeserializeFailureRetryer>();
                    var consistencyChecker = configuration.Resolve <IConsistencyChecker>();
                    var loader             = configuration.Resolve <SerializationLoader>();

                    IItemData[] roots;

                    if (partialSyncRoot != null)
                    {
                        roots = new[] { partialSyncRoot }
                    }
                    ;
                    else
                    {
                        var pathResolver = configuration.Resolve <PredicateRootPathResolver>();

                        roots = pathResolver.GetRootSerializedItems();
                    }

                    if (roots.Length > 0)
                    {
                        loader.LoadAll(roots, retryer, consistencyChecker, rootLoadedCallback);
                    }
                    else
                    {
                        logger.Warn($"{configuration.Name} had no root paths included to sync. If you're only syncing roles, this is expected. Otherwise it indicates that your predicate has no included items and you need to add some.");
                    }
                }
            }
            finally
            {
                if (!dilithiumWasStarted)
                {
                    ReactorContext.Dispose();
                }
            }

            CorePipeline.Run("unicornSyncComplete", MergePipelineArgs(new UnicornSyncCompletePipelineArgs(configuration, syncStartTimestamp)));

            return(true);
        }