public virtual bool ReserializeConfigurations(IConfiguration[] configurations, IProgressStatus progress, ILogger additionalLogger) { int taskNumber = 1; try { var startArgs = new UnicornReserializeStartPipelineArgs(OperationType.FullReserialize, configurations, additionalLogger, null); MergePipelineArgs(startArgs); CorePipeline.Run("unicornReserializeStart", startArgs); 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.ReserializeTree(root, false, new[] { configuration }); WebConsoleUtility.SetTaskProgress(progress, taskNumber, configurations.Length, (int)((index / (double)roots.Length) * 100)); index++; } } timer.Stop(); CorePipeline.Run("unicornReserializeComplete", MergePipelineArgs(new UnicornReserializeCompletePipelineArgs(configuration))); logger.Info("{0} reserialization complete in {1}ms.".FormatWith(configuration.Name, timer.ElapsedMilliseconds)); } catch (Exception ex) { logger.Error(ex); return(false); } taskNumber++; } } } finally { ReactorContext.Dispose(); } return(true); }
/// <summary> /// Reserializes an item and all of its children. /// </summary> /// <param name="item">Root item to reserialize</param> /// <param name="runReserializeStartPipeline">Whether this is a standalone reserialize (true) or part of a larger batch (false)</param> /// <param name="configurations">The configuration(s) to allow reserialization of</param> /// <returns>True if the tree was dumped, false if the root item was not included</returns> public virtual bool ReserializeTree(IItemData item, bool runReserializeStartPipeline = true, IConfiguration[] configurations = null) { using (new TransparentSyncDisabler()) { if (configurations == null) { configurations = GetConfigurationsForItem(item); } if (configurations.Length == 0) { return(false); } // check if Dilithium was already running. If it was, we won't dispose it when we're done. bool dilithiumWasStarted = ReactorContext.IsActive; try { if (runReserializeStartPipeline) { var startArgs = new UnicornReserializeStartPipelineArgs(OperationType.PartialReserializeTree, configurations, configurations.First().Resolve <ILogger>(), item); MergePipelineArgs(startArgs); CorePipeline.Run("unicornReserializeStart", startArgs); } foreach (var configuration in configurations) { if (configuration == null) { continue; } var logger = configuration.Resolve <ILogger>(); var predicate = configuration.Resolve <IPredicate>(); var serializationStore = configuration.Resolve <ITargetDataStore>(); var sourceStore = configuration.Resolve <ISourceDataStore>(); var dpConfig = configuration.Resolve <IUnicornDataProviderConfiguration>(); var rootReference = serializationStore.GetByPathAndId(item.Path, item.Id, item.DatabaseName); if (rootReference != null) { logger.Warn("[D] existing serialized items under {0}".FormatWith(rootReference.GetDisplayIdentifier())); serializationStore.Remove(rootReference); } logger.Info("[A] Serializing included items under root {0}".FormatWith(item.GetDisplayIdentifier())); if (!predicate.Includes(item).IsIncluded) { continue; } DumpTreeInternal(item, predicate, serializationStore, sourceStore, logger, dpConfig); } } finally { if (!dilithiumWasStarted) { ReactorContext.Dispose(); } } } return(true); }
/// <returns>True if the item was dumped, false if it was not included</returns> public virtual bool ReserializeItem(IItemData item, IConfiguration[] configurations = null) { using (new TransparentSyncDisabler()) { if (configurations == null) { configurations = GetConfigurationsForItem(item); } // return false; item not part of any configs if (configurations.Length == 0) { return(false); } // check if Dilithium was already running. If it was, we won't dispose it when we're done. bool dilithiumWasStarted = ReactorContext.IsActive; try { var startArgs = new UnicornReserializeStartPipelineArgs(OperationType.PartialReserializeItem, configurations, configurations.First().Resolve <ILogger>(), item); MergePipelineArgs(startArgs); CorePipeline.Run("unicornReserializeStart", startArgs); foreach (var configuration in configurations) { if (configuration == null) { return(false); } var predicate = configuration.Resolve <IPredicate>(); var serializationStore = configuration.Resolve <ITargetDataStore>(); var dpConfig = configuration.Resolve <IUnicornDataProviderConfiguration>(); if (dpConfig.EnableTransparentSync) { CacheManager.ClearAllCaches(); // BOOM! This clears all caches before we begin; // because for a TpSync configuration we could have TpSync items in the data cache which 'taint' the reserialize // from being purely database } var result = DumpItemInternal(item, predicate, serializationStore).IsIncluded; if (dpConfig.EnableTransparentSync) { CacheManager.ClearAllCaches(); // BOOM! And we clear everything again at the end, because now // for a TpSync configuration we might have DATABASE items in cache where we want TpSync. } if (!result) { return(false); } } } finally { if (!dilithiumWasStarted) { ReactorContext.Dispose(); } } return(true); } }
public void Process(UnicornReserializeStartPipelineArgs args) { ProcessInternal(args); }