protected virtual void Process(HttpContext context, Action<RemoteLogger> action)
 {
     context.Response.Buffer = false;
     context.Response.BufferOutput = false;
     context.Response.ContentType = "text/plain";
     SetSuccessResponse(context);
     using (var outputStream = context.Response.OutputStream)
     {
         using (var streamWriter = new StreamWriter(outputStream))
         {
             var progress = new RemoteLogger(streamWriter);
             using (new UnicornOperationContext())
             {
                 action(progress);
             }
         }
     }
 }
        protected virtual void ProcessReserialize(RemoteLogger progress)
        {
            foreach (var configuration in ResolveConfigurations())
            {
                var logger = configuration.Resolve<ILogger>();
                using (new LoggingContext(progress, configuration))
                {
                    try
                    {
                        var timer = new Stopwatch();
                        timer.Start();

                        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}".FormatWith(targetDataStore.FriendlyName));
                            targetDataStore.Clear();

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

                            int index = 1;
                            foreach (var root in roots)
                            {
                                helper.DumpTree(root, configuration);
                                progress.ReportProgress((int)((index / (double)roots.Length) * 100));
                                index++;
                            }
                        }

                        timer.Stop();

                        logger.Info("{0} reserialization complete in {1}ms".FormatWith(configuration.Name, timer.ElapsedMilliseconds));
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        break;
                    }
                }
            }
        }
        protected virtual void ProcessSync(RemoteLogger progress)
        {
            foreach (var configuration in ResolveConfigurations())
            {
                var logger = configuration.Resolve<ILogger>();
                var helper = configuration.Resolve<SerializationHelper>();

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

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

                            var roots = pathResolver.GetRootSerializedItems();

                            var index = 0;

                            helper.SyncTree(configuration, item =>
                            {
                                progress.ReportProgress((int)(((index + 1) / (double)roots.Length) * 100));
                                index++;
                            }, roots);
                        }

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