protected override void ProcessRecord() { if (Yaml == null && Item == null) { throw new InvalidOperationException("Neither YAML strings or IItemDatas were passed in, cannot process."); } var console = new PowershellProgressStatus(Host, "Deserialize Item"); var consoleLogger = new WebConsoleLogger(console, MessageType.Debug); var yaml = CreateFormatter(CreateFieldFilter()); // Ignoring BranchId should probably be controllable from the outside. For now it will just be wired to false. // See issue 283 in Unicorn. https://github.com/SitecoreUnicorn/Unicorn/issues/283 // Unicorn default for this will be to ignore BranchId var deserializer = new DefaultDeserializer(false, new DefaultDeserializerLogger(consoleLogger), CreateFieldFilter()); if (Yaml != null) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Yaml))) { var item = yaml.ReadSerializedItem(stream, "(from PowerShell)"); consoleLogger.Info(item.Path); deserializer.Deserialize(item, null); } } if (Item != null) { consoleLogger.Info(Item.Path); deserializer.Deserialize(Item, null); } }
protected override void ProcessRecord() { if (Yaml == null && Item == null) { throw new InvalidOperationException("Neither YAML strings or IItemDatas were passed in, cannot process."); } var console = new PowershellProgressStatus(Host, "Deserialize Item"); var consoleLogger = new WebConsoleLogger(console, MessageType.Debug); var yaml = CreateFormatter(CreateFieldFilter()); var deserializer = new DefaultDeserializer(new DefaultDeserializerLogger(consoleLogger), CreateFieldFilter()); if (Yaml != null) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Yaml))) { var item = yaml.ReadSerializedItem(stream, "(from PowerShell)"); consoleLogger.Info(item.Path); deserializer.Deserialize(item); } } if (Item != null) { consoleLogger.Info(Item.Path); deserializer.Deserialize(Item); } }
protected override void ProcessRecord() { var touchedConfigs = new List <IConfiguration>(); IItemData itemData = new ItemData(Item); var configuration = _helper.GetConfigurationsForItem(itemData).FirstOrDefault(); // if multiple configs contain item, load from first one if (configuration == null) { throw new InvalidOperationException($"{itemData.GetDisplayIdentifier()} was not part of any Unicorn configurations."); } touchedConfigs.Add(configuration); var logger = new WebConsoleLogger(new PowershellProgressStatus(Host, "Partial Sync Unicorn"), LogLevel); var helper = configuration.Resolve <SerializationHelper>(); var targetDataStore = configuration.Resolve <ITargetDataStore>(); itemData = targetDataStore.GetByPathAndId(itemData.Path, itemData.Id, itemData.DatabaseName); if (itemData == null) { throw new InvalidOperationException($"Could not do partial sync of {Item.Database.Name}:{Item.Paths.FullPath} because it was not serialized. You may need to perform initial serialization."); } try { logger.Info( $"Processing partial Unicorn configuration {itemData.GetDisplayIdentifier()} (Config: {configuration.Name})"); using (new LoggingContext(logger, configuration)) { if (Recurse.IsPresent) { helper.SyncTree(configuration, partialSyncRoot: itemData); } else { var sourceStore = configuration.Resolve <ISourceDataStore>(); var result = configuration.Resolve <IPredicate>().Includes(itemData); sourceStore.Save(itemData, result.FieldValueManipulator); } } } catch (Exception ex) { logger.Error(ex); throw; } CorePipeline.Run("unicornSyncEnd", new UnicornSyncEndPipelineArgs(new SitecoreLogger(), true, touchedConfigs.ToArray())); }