Пример #1
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));
        }
        public void Process(UnicornSyncBeginPipelineArgs args)
        {
            var collector = args.Configuration.Resolve <ISyncCompleteDataCollector>();

            if (collector != null)
            {
                collector.Reset();
            }
        }
Пример #3
0
		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();
			}
		}
Пример #4
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>();

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

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

            return true;
        }
Пример #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, 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 collector = args.Configuration.Resolve<ISyncCompleteDataCollector>();

			if (collector != null) collector.Reset();
		}