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); } }
public void Deserialize_IgnoresField_ExcludedWithFieldFilter() { var ignoredFieldId = ID.NewID; var fieldFilter = Substitute.For <IFieldFilter>(); fieldFilter.Includes(Arg.Any <Guid>()).Returns(true); fieldFilter.Includes(ignoredFieldId.Guid).Returns(false); var deserializer = new DefaultDeserializer(Substitute.For <IDefaultDeserializerLogger>(), fieldFilter); deserializer.ParentDataStore = new SitecoreDataStore(deserializer); using (var db = new Db()) { var itemId = ID.NewID; db.Add(new DbItem("Test Item", itemId) { { ignoredFieldId, "Test Value" } }); var itemData = new ProxyItem(new ItemData(db.GetItem(itemId))); var fields = new List <IItemFieldValue>(); fields.Add(new FakeFieldValue("Changed Ignored Value", fieldId: ignoredFieldId.Guid)); ((ProxyItemVersion)itemData.Versions.First()).Fields = fields; deserializer.Deserialize(itemData); var fromDb = db.GetItem(itemId); Assert.Equal(fromDb[ignoredFieldId], "Test Value"); } }
public void Deserializer_SetAttributes() { XDocument document = XDocument.Load(testXMLPath); DefaultDeserializer testDeserializer = new DefaultDeserializer(document); testDeserializer.Deserialize(); DeserializedElement root = testDeserializer.Root; Assert.AreEqual(root.Value, "RootTextValue"); }
public void Find_Test() { XDocument document = XDocument.Load(testXMLPath); DefaultDeserializer testDeserializer = new DefaultDeserializer(document); testDeserializer.Deserialize(); DefaultSerializer serializer = new DefaultSerializer(testDeserializer.Root); Assert.AreEqual("VVVVVV", serializer.Find("ElementAsValue").First().Value); }
public void FindChildren_Test() { XDocument document = XDocument.Load(testXMLPath); DefaultDeserializer testDeserializer = new DefaultDeserializer(document); testDeserializer.Deserialize(); DeserializedElement testElement = testDeserializer.Root.FindChildren("Child1").First(); Assert.AreEqual("bar", testElement.Attributes["foo"]); }
public void Deserializer_SetValue() { XDocument document = XDocument.Load(testXMLPath); DefaultDeserializer testDeserializer = new DefaultDeserializer(document); testDeserializer.Deserialize(); DeserializedElement root = testDeserializer.Root; Assert.AreEqual(root.Attributes["att1"], "val1"); Assert.AreEqual(root.Attributes["att2"], "val2"); Assert.AreEqual(root.Attributes["att3"], "val3"); }
public void Deserializer_SetName() { XDocument document = XDocument.Load(testXMLPath); DefaultDeserializer testDeserializer = new DefaultDeserializer(document); testDeserializer.Deserialize(); DeserializedElement root = testDeserializer.Root; Assert.AreEqual(root.Name, "Root"); Assert.AreEqual(root.Children[0].Name, "Child1"); Assert.AreEqual(root.Children[0].Children[0].Name, "ElementAsValue"); }
private static bool ProcessItem(IItemData item) { if (item == null) { return(false); } var consoleLogger = new SitecoreLogger(); var deserializer = new DefaultDeserializer(false, new DefaultDeserializerLogger(consoleLogger), CreateFieldFilter()); consoleLogger.Info(item.Path); deserializer.Deserialize(item, null); return(true); }