/// <summary> /// Function which Desialize textual item into Sitecore.Data.Serialization.ObjectModel.SyncItem /// </summary> /// <param name="data">string:Textual representation of data</param> /// <param name="options">Custom.ItemWebAPI.Pipelines.Advance.Serialize.Entities:LoadOption which define how to Serialize</param> /// <returns>Sitecore.Data.Serialization.ObjectModel.SyncItem</returns> public static SyncItem DeSerializeItem(string data, LoadOptions options) { SyncItem result = null; if (data == null || data.Length == 0) { return(result); } bool disabledLocally = Sitecore.Data.Serialization.ItemHandler.DisabledLocally; try { using (TextReader textReader = new StringReader(data)) { _loadOption = getLoadOption(options); if (_loadOption.DisableEvents) { using (new EventDisabler()) { Sitecore.Data.Serialization.ItemHandler.DisabledLocally = true; result = ReadItem(new Sitecore.Data.Serialization.ObjectModel.Tokenizer(textReader), false); } //Sitecore.Data.Serialization.Manager. DeserializationFinished(_loadOption.Database.Name); } else { Sitecore.Data.Serialization.ItemHandler.DisabledLocally = true; result = SyncItem.ReadItem(new Sitecore.Data.Serialization.ObjectModel.Tokenizer(textReader)); } } } catch (ParentItemNotFoundException ex) { SerializeManager.LogLocalizedError("Cannot load item from path '{0}'. Possible reason: parent item with ID '{1}' not found.", new object[] { //PathUtils.UnmapItemPath(path, options.Root), ex.ParentID }); } catch (ParentForMovedItemNotFoundException ex2) { SerializeManager.LogLocalizedError("Item from path '{0}' cannot be moved to appropriate location. Possible reason: parent item with ID '{1}' not found.", new object[] { //PathUtils.UnmapItemPath(path, options.Root), ex2.ParentID }); } catch (Exception ex) { SerializeManager.LogLocalizedError(ex.Message, ex); } finally { Sitecore.Data.Serialization.ItemHandler.DisabledLocally = disabledLocally; } return(result); }
private static Sitecore.Data.Serialization.LoadOptions getLoadOption(LoadOptions loOptions) { Sitecore.Data.Serialization.LoadOptions loadOptions = null; if (loOptions != null) { loadOptions = new Sitecore.Data.Serialization.LoadOptions(); if (loOptions.Database != null && loOptions.Database.Length > 0) { loadOptions.Database = Common.Functions.GetDatabase(loOptions.Database); } loadOptions.DisableEvents = loOptions.DisableEvents; loadOptions.ForceUpdate = loOptions.ForceUpdate; loadOptions.Root = loOptions.Root; loadOptions.UseNewID = loOptions.UseNewID; } return(loadOptions); }