private void ProcessParameter(XmlElement xmlElement, IExtendedProperties smoObject) { // Delete old ExtendedProperties while (smoObject.ExtendedProperties.Count > 0) { smoObject.ExtendedProperties[0].Drop(); } // AddExtendedProperty("summary", xmlElement.InnerText, smoObject); foreach (XmlAttribute attribute in xmlElement.Attributes) { if (attribute.Name != Constants.AttributeName) { if (Constants.ParameterAttributes.Contains(attribute.Name.ToLower())) { AddExtendedProperty(attribute, smoObject); } else { throw new Exception(String.Format("Invalid attribute: {0}", attribute.Name)); } } } }
public static List <PropertyItem> ToPropertyList(this IExtendedProperties extendedProperties) { var result = new List <PropertyItem>(); foreach (var key in extendedProperties.Properties.Keys) { var k = key.ToString(); var v = extendedProperties.Properties[key]?.ToString(); var item = new PropertyItem { Key = k, Value = v }; result.Add(item); } return(result); }
private void ScriptProperties(IExtendedProperties obj, StreamWriter sw) { if (obj == null) { throw new ArgumentNullException("obj"); } if (sw == null) { throw new ArgumentNullException("sw"); } foreach (ExtendedProperty ep in obj.ExtendedProperties) { WriteScript(ep.Script(), sw); } }
/// <summary> /// Sets the CreatorId and ModifierId properties to the initials of the seller for good records. /// Also sets the Created and Modified date properties to the exact date and time of the sale, /// regardless of the time it was received in Episerver. /// </summary> protected void SetCashier( IExtendedProperties entity, DateTime dateTime, string cashierName) { // All the order system objects we care about have both IExtendedProperties and MetaObject in common. // So we can cast the entity by interface to class, to get access to the four properties below. if (!(entity is MetaObject metaObject)) { return; } metaObject.Created = dateTime; metaObject.CreatorId = cashierName; metaObject.Modified = dateTime; metaObject.ModifierId = cashierName; }
private void AddExtendedProperty(string name, string strValue, IExtendedProperties smoObject) { name = Constants.SchemaMeta + "." + name; object value = ParseString(strValue); ExtendedProperty exp; if (smoObject.ExtendedProperties.Contains(name)) { exp = smoObject.ExtendedProperties[name]; exp.Value = value; exp.Alter(); } else { exp = new ExtendedProperty((SqlSmoObject)smoObject, name, value); smoObject.ExtendedProperties.Add(exp); exp.Create(); } }
public static void MapPropertiesToModel(this IHaveProperties dto, IExtendedProperties model) { foreach (var property in dto.Properties) { if (model.Properties.ContainsKey(property.Key)) { var type = GetMetaFieldType(property.Key, out MetaField metaField); if (type == null || metaField == null) { continue; } if (property.Value == null && !IsNullable(type)) { continue; } var converter = TypeDescriptor.GetConverter(type); var parsedValue = GetValue(metaField.AllowNulls, property, converter); model.Properties[property.Key] = parsedValue; } } }
private void AddExtendedProperty(XmlAttribute xmlAttribute, IExtendedProperties smoObject) { AddExtendedProperty(xmlAttribute.Name, xmlAttribute.Value, smoObject); }
private void AddExtendedProperty(XmlElement xmlElement, IExtendedProperties smoObject) { AddExtendedProperty(xmlElement.Name, xmlElement.InnerXml, smoObject); }
public static Guid GetGuid(this IExtendedProperties extendedProperties, string fieldName) => DefaultIfNull(extendedProperties.Properties[fieldName], Guid.Empty);
private void ProcessObject(XmlElement xmlElement, ObjectType objectType, IExtendedProperties smoObject) { // Delete old ExtendedProperties while (smoObject.ExtendedProperties.Count > 0) { smoObject.ExtendedProperties[0].Drop(); } // Dictionary to hold new properties, required for mergin multiple tags Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (XmlElement e in xmlElement.ChildNodes) { // Try to parse as subitem (column, param) ParameterType pt = ParameterType.Unknown; bool subitem = Enum.TryParse <ParameterType>(e.Name, true, out pt); if (subitem) { // Process tag as subitem if (!Constants.TagPairs[objectType].Contains(pt)) { throw new Exception(String.Format("Invalid tag found, '{0}' cannot be part of '{1}'", pt.ToString(), objectType.ToString())); } IExtendedProperties paramobject; string name = e.Attributes[Constants.AttributeName].Value.Trim('[', ']'); switch (objectType) { case ObjectType.Table: paramobject = ((Table)smoObject).Columns[name]; break; case ObjectType.View: paramobject = ((View)smoObject).Columns[name]; break; case ObjectType.Procedure: paramobject = ((StoredProcedure)smoObject).Parameters[name]; break; case ObjectType.Function: switch (pt) { case ParameterType.Param: paramobject = ((UserDefinedFunction)smoObject).Parameters[name]; break; case ParameterType.Column: paramobject = ((UserDefinedFunction)smoObject).Columns[name]; break; default: throw new NotImplementedException(); } break; default: throw new Exception("Invalid tag found."); } ProcessParameter(e, paramobject); } else { if (properties.Keys.Contains <string>(e.Name)) { // merge string s = properties[e.Name]; s += Environment.NewLine + e.InnerXml; properties[e.Name] = s; } else { // new properties.Add(e.Name, e.InnerXml); } } } // Save extended properties foreach (string key in properties.Keys) { AddExtendedProperty(key, properties[key], smoObject); } }
private void ProcessParameter(XmlElement xmlElement, IExtendedProperties smoObject) { // Delete old ExtendedProperties while (smoObject.ExtendedProperties.Count > 0) smoObject.ExtendedProperties[0].Drop(); // AddExtendedProperty("summary", xmlElement.InnerText, smoObject); foreach (XmlAttribute attribute in xmlElement.Attributes) { if (attribute.Name != Constants.AttributeName) { if (Constants.ParameterAttributes.Contains(attribute.Name.ToLower())) { AddExtendedProperty(attribute, smoObject); } else { throw new Exception(String.Format("Invalid attribute: {0}", attribute.Name)); } } } }
private void ProcessObject(XmlElement xmlElement, ObjectType objectType, IExtendedProperties smoObject) { // Delete old ExtendedProperties while (smoObject.ExtendedProperties.Count > 0) smoObject.ExtendedProperties[0].Drop(); // Dictionary to hold new properties, required for mergin multiple tags Dictionary<string, string> properties = new Dictionary<string, string>(); foreach (XmlElement e in xmlElement.ChildNodes) { // Try to parse as subitem (column, param) ParameterType pt = ParameterType.Unknown; bool subitem = Enum.TryParse<ParameterType>(e.Name, true, out pt); if (subitem) { // Process tag as subitem if (!Constants.TagPairs[objectType].Contains(pt)) { throw new Exception(String.Format("Invalid tag found, '{0}' cannot be part of '{1}'", pt.ToString(), objectType.ToString())); } IExtendedProperties paramobject; string name = e.Attributes[Constants.AttributeName].Value.Trim('[', ']'); switch (objectType) { case ObjectType.Table: paramobject = ((Table)smoObject).Columns[name]; break; case ObjectType.View: paramobject = ((View)smoObject).Columns[name]; break; case ObjectType.Procedure: paramobject = ((StoredProcedure)smoObject).Parameters[name]; break; case ObjectType.Function: switch (pt) { case ParameterType.Param: paramobject = ((UserDefinedFunction)smoObject).Parameters[name]; break; case ParameterType.Column: paramobject = ((UserDefinedFunction)smoObject).Columns[name]; break; default: throw new NotImplementedException(); } break; default: throw new Exception("Invalid tag found."); } ProcessParameter(e, paramobject); } else { if (properties.Keys.Contains<string>(e.Name)) { // merge string s = properties[e.Name]; s += Environment.NewLine + e.InnerXml; properties[e.Name] = s; } else { // new properties.Add(e.Name, e.InnerXml); } } } // Save extended properties foreach (string key in properties.Keys) { AddExtendedProperty(key, properties[key], smoObject); } }
/// <summary> /// Sets the CreatorId and ModifierId properties to the initials of the seller for good records. /// Also sets the Created and Modified date properties to the exact date and time of the sale, /// regardless of the time it was received in Episerver. /// </summary> protected void SetCashier( IExtendedProperties entity, SaleViewModel sale) { SetCashier(entity, sale.Timing.Timestamp, sale.Source.CashierName); }
public static int GetInt32(this IExtendedProperties extendedProperties, string fieldName) => DefaultIfNull(extendedProperties.Properties[fieldName], default(int));
public static bool GetBool(this IExtendedProperties extendedProperties, string fieldName) => DefaultIfNull(extendedProperties.Properties[fieldName], false);
public static string GetString(this IExtendedProperties extendedProperties, string fieldName) => DefaultIfNull(extendedProperties.Properties[fieldName], string.Empty);
public static decimal GetDecimal(this IExtendedProperties extendedProperties, string fieldName) => DefaultIfNull(extendedProperties.Properties[fieldName], default(decimal));
public static DateTime GetDateTime(this IExtendedProperties extendedProperties, string fieldName) => DefaultIfNull(extendedProperties.Properties[fieldName], DateTime.MaxValue);
public static void MapPropertiesToDto(this IExtendedProperties model, IHaveProperties dto) { dto.Properties = model.ToPropertyList(); }
private void ScriptProperties(IExtendedProperties obj, StreamWriter sw) { if (obj == null) throw new ArgumentNullException("obj"); if (sw == null) throw new ArgumentNullException("sw"); foreach (ExtendedProperty ep in obj.ExtendedProperties) { WriteScript(ep.Script(), sw); } }