/// <summary> /// Returns an Entity XElement /// </summary> /// <param name="e"></param> /// <returns></returns> private XElement GetEntityXElement(Entity e) { //var attributeSet = Sexy.ContentContext.GetAttributeSet(e.AttributeSetID); var entityXElement = new Eav.ImportExport.XmlExport(Sexy.ContentContext).GetEntityXElement(e.EntityID); foreach (var value in entityXElement.Elements("Value")) { var valueString = value.Attribute("Value").Value; var valueType = value.Attribute("Type").Value; var valueKey = value.Attribute("Key").Value; // Special cases for Template ContentTypes if (e.Set.StaticName == "2SexyContent-Template-ContentTypes" && !String.IsNullOrEmpty(valueString)) { switch (valueKey) { case "ContentTypeID": var attributeSet = Sexy.ContentContext.AttribSet.GetAllAttributeSets().FirstOrDefault(a => a.AttributeSetID == int.Parse(valueString)); value.Attribute("Value").SetValue(attributeSet != null ? attributeSet.StaticName : String.Empty); break; case "DemoEntityID": var entityID = int.Parse(valueString); var demoEntity = Sexy.ContentContext.SqlDb.Entities.FirstOrDefault(en => en.EntityID == entityID); value.Attribute("Value").SetValue(demoEntity != null ? demoEntity.EntityGUID.ToString() : String.Empty); break; } } // Collect all referenced files for adding a file list to the xml later if (valueType == "Hyperlink") { var fileRegex = new Regex("^File:(?<FileId>[0-9]+)", RegexOptions.IgnoreCase); var a = fileRegex.Match(valueString); if (a.Success && a.Groups["FileId"].Length > 0) _referencedFileIds.Add(int.Parse(a.Groups["FileId"].Value)); } } if (e.KeyGuid.HasValue) entityXElement.Add(new XAttribute("KeyGuid", e.KeyGuid)); //return new XElement("Entity", // new XAttribute("AssignmentObjectType", e.AssignmentObjectType.Name), // new XAttribute("AttributeSetStaticName", attributeSet.StaticName), // new XAttribute("AttributeSetName", attributeSet.Name), // new XAttribute("EntityGUID", e.EntityGUID), // from c in Sexy.ContentContext.GetValues(e.EntityID) // where c.ChangeLogDeleted == null // select GetAttributeValueXElement(c.Attribute.StaticName, c, c.Attribute.Type, attributeSet)); return entityXElement; }
/// <summary> /// Returns an Entity XElement /// </summary> /// <param name="e"></param> /// <returns></returns> private XElement GetEntityXElement(Entity e) { //var attributeSet = Sexy.ContentContext.GetAttributeSet(e.AttributeSetID); var entityXElement = new Eav.ImportExport.XmlExport(_eavAppContext).GetEntityXElement(e.EntityID); foreach (var value in entityXElement.Elements("Value")) { var valueString = value.Attribute("Value").Value; var valueType = value.Attribute("Type").Value; var valueKey = value.Attribute("Key").Value; // Special cases for Template ContentTypes if (e.Set.StaticName == "2SexyContent-Template-ContentTypes" && !string.IsNullOrEmpty(valueString)) { switch (valueKey) { case "ContentTypeID": var attributeSet = _eavAppContext.AttribSet.GetAllAttributeSets().FirstOrDefault(a => a.AttributeSetID == int.Parse(valueString)); value.Attribute("Value").SetValue(attributeSet != null ? attributeSet.StaticName : string.Empty); break; case "DemoEntityID": var entityId = int.Parse(valueString); var demoEntity = _eavAppContext.SqlDb.Entities.FirstOrDefault(en => en.EntityID == entityId); value.Attribute("Value").SetValue(demoEntity?.EntityGUID.ToString() ?? string.Empty); break; } } // Collect all referenced files for adding a file list to the xml later if (valueType == "Hyperlink") { var fileRegex = new Regex("^File:(?<FileId>[0-9]+)", RegexOptions.IgnoreCase); var a = fileRegex.Match(valueString); // try remember the file if (a.Success && a.Groups["FileId"].Length > 0) { AddFileAndFolderToQueue(int.Parse(a.Groups["FileId"].Value)); } } } if (e.KeyGuid.HasValue) { entityXElement.Add(new XAttribute("KeyGuid", e.KeyGuid)); } if (e.KeyNumber.HasValue) { entityXElement.Add(new XAttribute("KeyNumber", e.KeyNumber)); } if (!string.IsNullOrEmpty(e.KeyString)) { entityXElement.Add(new XAttribute("KeyString", e.KeyString)); } //return new XElement("Entity", // new XAttribute("AssignmentObjectType", e.AssignmentObjectType.Name), // new XAttribute("AttributeSetStaticName", attributeSet.StaticName), // new XAttribute("AttributeSetName", attributeSet.Name), // new XAttribute("EntityGUID", e.EntityGUID), // from c in Sexy.ContentContext.GetValues(e.EntityID) // where c.ChangeLogDeleted == null // select GetAttributeValueXElement(c.Attribute.StaticName, c, c.Attribute.Type, attributeSet)); return(entityXElement); }
/// <summary> /// Returns an Entity XElement /// </summary> /// <param name="e"></param> /// <returns></returns> private XElement GetEntityXElement(Entity e) { //Note that this often throws errors in a dev environment, where the data may be mangled manually in the DB XElement entityXElement; try { entityXElement = new Eav.ImportExport.XmlExport(_eavAppContext).GetEntityXElement(e.EntityID); } catch (Exception ex) { throw new Exception("failed on entity id '" + e.EntityID + "' of set-type '" + e.AttributeSetID + "'", ex); } foreach (var value in entityXElement.Elements("Value")) { var valueString = value.Attribute("Value").Value; var valueType = value.Attribute("Type").Value; var valueKey = value.Attribute("Key").Value; // Special cases for Template ContentTypes if (e.Set.StaticName == "2SexyContent-Template-ContentTypes" && !string.IsNullOrEmpty(valueString)) { switch (valueKey) { case "ContentTypeID": var attributeSet = _eavAppContext.AttribSet.GetAllAttributeSets().FirstOrDefault(a => a.AttributeSetID == int.Parse(valueString)); value.Attribute("Value").SetValue(attributeSet != null ? attributeSet.StaticName : string.Empty); break; case "DemoEntityID": var entityId = int.Parse(valueString); var demoEntity = _eavAppContext.SqlDb.Entities.FirstOrDefault(en => en.EntityID == entityId); value.Attribute("Value").SetValue(demoEntity?.EntityGUID.ToString() ?? string.Empty); break; } } // Collect all referenced files for adding a file list to the xml later if (valueType == "Hyperlink") { var fileRegex = new Regex("^File:(?<FileId>[0-9]+)", RegexOptions.IgnoreCase); var a = fileRegex.Match(valueString); // try remember the file if (a.Success && a.Groups["FileId"].Length > 0) AddFileAndFolderToQueue(int.Parse(a.Groups["FileId"].Value)); } } if (e.KeyGuid.HasValue) entityXElement.Add(new XAttribute("KeyGuid", e.KeyGuid)); if (e.KeyNumber.HasValue) entityXElement.Add(new XAttribute("KeyNumber", e.KeyNumber)); if (!string.IsNullOrEmpty(e.KeyString)) entityXElement.Add(new XAttribute("KeyString", e.KeyString)); //return new XElement("Entity", // new XAttribute("AssignmentObjectType", e.AssignmentObjectType.Name), // new XAttribute("AttributeSetStaticName", attributeSet.StaticName), // new XAttribute("AttributeSetName", attributeSet.Name), // new XAttribute("EntityGUID", e.EntityGUID), // from c in Sexy.ContentContext.GetValues(e.EntityID) // where c.ChangeLogDeleted == null // select GetAttributeValueXElement(c.Attribute.StaticName, c, c.Attribute.Type, attributeSet)); return entityXElement; }