private MochaAttributeValue LoadAttributeValue(MarkupTagElement tag) { if (tag == null) { return(null); } if (tag.FullName != "attributeValue") { return(null); } MarkupAttribute attInstanceID = tag.Attributes["attributeInstanceId"]; MarkupAttribute attValue = tag.Attributes["value"]; if (attInstanceID == null || attValue == null) { return(null); } MochaAttributeValue item = new MochaAttributeValue(); item.AttributeInstanceID = new Guid(attInstanceID.Value); item.Value = attValue.Value; return(item); }
private Fill FillFromTag(MarkupTagElement tag) { if (tag == null) { return(null); } MarkupAttribute attFillType = tag.Attributes["Type"]; if (attFillType != null) { switch (attFillType.Value.ToLower()) { case "none": { break; } case "solid": { MarkupAttribute attFillColor = tag.Attributes["Color"]; if (attFillColor != null) { return(new SolidFill(attFillColor.Value)); } break; } case "lineargradient": { MarkupAttribute attOrientation = tag.Attributes["Orientation"]; if (attOrientation == null) { return(null); } MarkupTagElement tagColorStops = (tag.Elements["ColorStops"] as MarkupTagElement); if (tagColorStops != null) { LinearGradientFill fill = new LinearGradientFill(); switch (attOrientation.Value.ToLower()) { case "horizontal": fill.Orientation = LinearGradientFillOrientation.Horizontal; break; case "vertical": fill.Orientation = LinearGradientFillOrientation.Vertical; break; } foreach (MarkupElement elColorStop in tagColorStops.Elements) { MarkupTagElement tagColorStop = (elColorStop as MarkupTagElement); if (tagColorStop == null) { continue; } if (tagColorStop.FullName != "ColorStop") { continue; } MarkupAttribute attPosition = tagColorStop.Attributes["Position"]; if (attPosition == null) { continue; } MarkupAttribute attColor = tagColorStop.Attributes["Color"]; if (attColor == null) { continue; } fill.ColorStops.Add(new LinearGradientFillColorStop(attPosition.Value, attColor.Value)); } return(fill); } break; } } } return(null); }
private Outline OutlineFromTag(MarkupTagElement tag) { if (tag == null) { return(null); } Outline outline = null; MarkupAttribute attOutlineType = tag.Attributes["Type"]; if (attOutlineType != null) { switch (attOutlineType.Value.ToLower()) { case "none": { break; } case "solid": { MarkupAttribute attColor = tag.Attributes["Color"]; if (attColor != null) { SolidOutline realOutline = new SolidOutline(); realOutline.Color = attColor.Value; outline = realOutline; } break; } case "inset": case "outset": { MarkupAttribute attLightColor = tag.Attributes["LightColor"]; MarkupAttribute attDarkColor = tag.Attributes["DarkColor"]; MarkupAttribute attColor = tag.Attributes["Color"]; if ((attLightColor != null && attDarkColor != null) || (attColor != null)) { ThreeDOutline realOutline = new ThreeDOutline(); switch (attOutlineType.Value.ToLower()) { case "inset": { realOutline.Type = ThreeDOutlineType.Inset; break; } case "outset": { realOutline.Type = ThreeDOutlineType.Outset; break; } } if (attLightColor != null && attDarkColor != null) { realOutline.LightColor = attLightColor.Value; realOutline.DarkColor = attDarkColor.Value; } else if (attColor != null) { realOutline.LightColor = attColor.Value; realOutline.DarkColor = attColor.Value; } outline = realOutline; } break; } } MarkupAttribute attOutlineWidth = tag.Attributes["Width"]; if (attOutlineWidth != null && outline != null) { outline.Width = Single.Parse(attOutlineWidth.Value); } } return(outline); }
protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); ThemeObjectModel themes = (objectModels.Pop() as ThemeObjectModel); MarkupTagElement tagThemes = (mom.FindElement("AwesomeControls", "Theming", "Themes") as MarkupTagElement); if (tagThemes != null) { foreach (MarkupElement elTheme in tagThemes.Elements) { MarkupTagElement tagTheme = (elTheme as MarkupTagElement); if (tagTheme == null) { continue; } MarkupAttribute attThemeID = tagTheme.Attributes["ID"]; if (attThemeID == null) { continue; } Theme theme = new Theme(); UniversalEditor.Accessors.FileAccessor fa = (this.Accessor as UniversalEditor.Accessors.FileAccessor); if (fa != null) { theme.BasePath = System.IO.Path.GetDirectoryName(fa.FileName); } theme.ID = new Guid(attThemeID.Value); MarkupAttribute attInheritsThemeID = tagTheme.Attributes["InheritsThemeID"]; if (attInheritsThemeID != null) { theme.InheritsThemeID = new Guid(attInheritsThemeID.Value); } MarkupTagElement tagInformation = (tagTheme.Elements["Information"] as MarkupTagElement); if (tagInformation != null) { MarkupTagElement tagInformationTitle = (tagInformation.Elements["Title"] as MarkupTagElement); if (tagInformationTitle != null) { theme.Title = tagInformationTitle.Value; } } MarkupTagElement tagMetrics = (tagTheme.Elements["Metrics"] as MarkupTagElement); if (tagMetrics != null) { foreach (MarkupElement elMetric in tagMetrics.Elements) { MarkupTagElement tagMetric = (elMetric as MarkupTagElement); if (tagMetric == null) { continue; } MarkupAttribute attMetricName = tagMetric.Attributes["Name"]; if (attMetricName == null) { continue; } switch (tagMetric.FullName.ToLower()) { case "paddingmetric": { PaddingMetric metric = new PaddingMetric(); metric.Name = attMetricName.Value; MarkupAttribute attMetricLeft = tagMetric.Attributes["Left"]; if (attMetricLeft != null) { metric.Left = Single.Parse(attMetricLeft.Value); } MarkupAttribute attMetricTop = tagMetric.Attributes["Top"]; if (attMetricTop != null) { metric.Top = Single.Parse(attMetricTop.Value); } MarkupAttribute attMetricBottom = tagMetric.Attributes["Bottom"]; if (attMetricBottom != null) { metric.Bottom = Single.Parse(attMetricBottom.Value); } MarkupAttribute attMetricRight = tagMetric.Attributes["Right"]; if (attMetricRight != null) { metric.Right = Single.Parse(attMetricRight.Value); } theme.Metrics.Add(metric); break; } } } } MarkupTagElement tagColors = (tagTheme.Elements["Colors"] as MarkupTagElement); if (tagColors != null) { foreach (MarkupElement elColor in tagColors.Elements) { MarkupTagElement tagColor = (elColor as MarkupTagElement); if (tagColor == null) { continue; } if (tagColor.FullName != "Color") { continue; } MarkupAttribute attColorID = tagColor.Attributes["ID"]; MarkupAttribute attColorName = tagColor.Attributes["Name"]; if (attColorID == null && attColorName == null) { continue; } MarkupAttribute attColorValue = tagColor.Attributes["Value"]; if (attColorValue == null) { continue; } ThemeColor color = new ThemeColor(); if (attColorID != null) { color.ID = new Guid(attColorID.Value); } if (attColorName != null) { color.Name = attColorName.Value; } if (attColorValue != null) { color.Value = attColorValue.Value; } theme.Colors.Add(color); } } MarkupTagElement tagFonts = (tagTheme.Elements["Fonts"] as MarkupTagElement); if (tagFonts != null) { foreach (MarkupElement elFont in tagFonts.Elements) { MarkupTagElement tagFont = (elFont as MarkupTagElement); if (tagFont == null) { continue; } if (tagFont.FullName != "Font") { continue; } MarkupAttribute attFontName = tagFont.Attributes["Name"]; if (attFontName == null) { continue; } MarkupAttribute attFontValue = tagFont.Attributes["Value"]; if (attFontValue == null) { continue; } ThemeFont font = new ThemeFont(); font.Name = attFontName.Value; font.Value = attFontValue.Value; theme.Fonts.Add(font); } } MarkupTagElement tagStockImages = (tagTheme.Elements["StockImages"] as MarkupTagElement); if (tagStockImages != null) { foreach (MarkupElement elStockImage in tagStockImages.Elements) { MarkupTagElement tagStockImage = (elStockImage as MarkupTagElement); if (tagStockImage == null) { continue; } if (tagStockImage.FullName != "StockImage") { continue; } MarkupAttribute attStockImageName = tagStockImage.Attributes["Name"]; if (attStockImageName == null) { continue; } MarkupAttribute attStockImageFileName = tagStockImage.Attributes["FileName"]; if (attStockImageFileName == null) { continue; } ThemeStockImage stockImage = new ThemeStockImage(); stockImage.Name = attStockImageName.Value; stockImage.ImageFileName = attStockImageFileName.Value; theme.StockImages.Add(stockImage); } } MarkupTagElement tagProperties = (tagTheme.Elements["Properties"] as MarkupTagElement); if (tagProperties != null) { foreach (MarkupElement elProperty in tagProperties.Elements) { MarkupTagElement tagProperty = (elProperty as MarkupTagElement); if (tagProperty == null) { continue; } if (tagProperty.FullName != "Property") { continue; } MarkupAttribute attName = tagProperty.Attributes["Name"]; if (attName == null) { continue; } ThemeProperty property = new ThemeProperty(); property.Name = attName.Value; MarkupAttribute attValue = tagProperty.Attributes["Value"]; if (attValue != null) { property.Value = attValue.Value; } theme.Properties.Add(property); } } MarkupTagElement tagComponents = (tagTheme.Elements["Components"] as MarkupTagElement); if (tagComponents != null) { foreach (MarkupElement elComponent in tagComponents.Elements) { MarkupTagElement tagComponent = (elComponent as MarkupTagElement); if (tagComponent == null) { continue; } if (tagComponent.FullName != "Component") { continue; } MarkupAttribute attComponentID = tagComponent.Attributes["ID"]; if (attComponentID == null) { continue; } ThemeComponent component = new ThemeComponent(); component.ID = new Guid(attComponentID.Value); MarkupAttribute attInheritsComponentID = tagComponent.Attributes["InheritsComponentID"]; if (attInheritsComponentID != null) { component.InheritsComponentID = new Guid(attInheritsComponentID.Value); } MarkupTagElement tagComponentStates = (tagComponent.Elements["States"] as MarkupTagElement); if (tagComponentStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagComponentStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) { continue; } if (tagState.FullName != "State") { continue; } MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) { continue; } ThemeComponentState state = new ThemeComponentState(); state.ID = new Guid(attStateID.Value); MarkupAttribute attStateName = tagState.Attributes["Name"]; if (attStateName != null) { state.Name = attStateName.Value; } component.States.Add(state); } } MarkupTagElement tagRenderings = (tagComponent.Elements["Renderings"] as MarkupTagElement); if (tagRenderings != null) { foreach (MarkupElement elRendering in tagRenderings.Elements) { MarkupTagElement tagRendering = (elRendering as MarkupTagElement); if (tagRendering == null) { continue; } if (tagRendering.FullName != "Rendering") { continue; } MarkupTagElement tagRenderingActions = (tagRendering.Elements["Actions"] as MarkupTagElement); if (tagRenderingActions == null) { continue; } Rendering rendering = new Rendering(); foreach (MarkupElement elRenderingAction in tagRenderingActions.Elements) { MarkupTagElement tagRenderingAction = (elRenderingAction as MarkupTagElement); if (tagRenderingAction == null) { continue; } switch (tagRenderingAction.FullName) { case "Rectangle": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; RectangleRenderingAction item = new RectangleRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); item.Width = RenderingExpression.Parse(attWidth.Value); item.Height = RenderingExpression.Parse(attHeight.Value); item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); item.Fill = FillFromTag(tagRenderingAction.Elements["Fill"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Line": { LineRenderingAction item = new LineRenderingAction(); MarkupAttribute attX1 = tagRenderingAction.Attributes["X1"]; if (attX1 != null) { item.X1 = RenderingExpression.Parse(attX1.Value); } MarkupAttribute attX2 = tagRenderingAction.Attributes["X2"]; if (attX2 != null) { item.X2 = RenderingExpression.Parse(attX2.Value); } MarkupAttribute attY1 = tagRenderingAction.Attributes["Y1"]; if (attY1 != null) { item.Y1 = RenderingExpression.Parse(attY1.Value); } MarkupAttribute attY2 = tagRenderingAction.Attributes["Y2"]; if (attY2 != null) { item.Y2 = RenderingExpression.Parse(attY2.Value); } item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Text": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; if (attX == null || attY == null) { continue; } MarkupAttribute attHorizontalAlignment = tagRenderingAction.Attributes["HorizontalAlignment"]; MarkupAttribute attVerticalAlignment = tagRenderingAction.Attributes["VerticalAlignment"]; TextRenderingAction item = new TextRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); if (attWidth != null) { item.Width = RenderingExpression.Parse(attWidth.Value); } if (attWidth != null) { item.Height = RenderingExpression.Parse(attHeight.Value); } if (attHorizontalAlignment != null) { switch (attHorizontalAlignment.Value.ToLower()) { case "center": { item.HorizontalAlignment = HorizontalAlignment.Center; break; } case "justify": { item.HorizontalAlignment = HorizontalAlignment.Justify; break; } case "left": { item.HorizontalAlignment = HorizontalAlignment.Left; break; } case "right": { item.HorizontalAlignment = HorizontalAlignment.Right; break; } } } if (attVerticalAlignment != null) { switch (attVerticalAlignment.Value.ToLower()) { case "bottom": { item.VerticalAlignment = VerticalAlignment.Bottom; break; } case "middle": { item.VerticalAlignment = VerticalAlignment.Middle; break; } case "top": { item.VerticalAlignment = VerticalAlignment.Top; break; } } } MarkupAttribute attColor = tagRenderingAction.Attributes["Color"]; if (attColor != null) { item.Color = attColor.Value; } MarkupAttribute attFont = tagRenderingAction.Attributes["Font"]; if (attFont != null) { item.Font = attFont.Value; } MarkupAttribute attValue = tagRenderingAction.Attributes["Value"]; if (attValue != null) { item.Value = attValue.Value; } rendering.Actions.Add(item); break; } } } MarkupTagElement tagRenderingStates = (tagRendering.Elements["States"] as MarkupTagElement); if (tagRenderingStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagRenderingStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) { continue; } if (tagState.FullName != "State") { continue; } MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) { continue; } ThemeComponentStateReference state = new ThemeComponentStateReference(); state.StateID = new Guid(attStateID.Value); rendering.States.Add(state); } } component.Renderings.Add(rendering); } } theme.Components.Add(component); } } themes.Themes.Add(theme); } } }
internal void LoadType(Type type) { if (type == null || type == typeof(object)) { return; } List <PropertyInfoItem> typeProps = null; List <PropertyInfo> props = null; List <Type> innerTypes = null; //double-check lock pattern; optemized thread-safe if (!properties.ContainsKey(type.FullName) && GetPropertyTypeCategory(type) == PropertyTypeCategory.Class) { lock (locker) { innerTypes = new List <Type>(); if (!properties.ContainsKey(type.FullName) && GetPropertyTypeCategory(type) == PropertyTypeCategory.Class) { typeProps = new List <PropertyInfoItem>(); // props = System.ComponentModel.TypeDescriptor.GetProperties(type.GetProperties); props = type.GetProperties().Where(s => s.GetAccessors(false).Any()).ToList(); foreach (var prop in props) { var atts = prop.GetCustomAttributes(false).ToArray(); if (atts.OfType <NotMappedAttribute>().Any()) { continue; } PropertyTypeCategory propTypeCategory = GetPropertyTypeCategory(prop.PropertyType); PropertyInfoItem propInfoItem = new PropertyInfoItem() { Type = type, TypeCategory = propTypeCategory, Property = prop, PropertyName = prop.Name, PropertyType = prop.PropertyType, IsGenericType = prop.PropertyType == typeof(object), IsReadOnly = !prop.CanWrite }; var primaryKeyAtt = atts.OfType <PrimaryKeyAttribute>().FirstOrDefault(); propInfoItem.IsPrimaryKey = null != primaryKeyAtt; var foreignKeyAtts = atts.OfType <ForeignKeyAttribute>(); if (foreignKeyAtts.Any()) { propInfoItem.ForeignKeys = foreignKeyAtts.Cast <ForeignKeyAttribute>().ToList(); } var parentKeyAtts = atts.OfType <ParentKeyAttribute>(); if (parentKeyAtts.Any()) { propInfoItem.ParentKeys = parentKeyAtts.Cast <ParentKeyAttribute>().ToList(); } PropertyAttribute propertyAtt = atts.OfType <PropertyAttribute>().FirstOrDefault(); if (null != propertyAtt) { propInfoItem.Cascade = propertyAtt.Cascade; propInfoItem.IsAutonumber = propertyAtt.AutoNumber; //propInfoItem.ForceAutoNumber = propertyAtt.OverrideAutoNumber; propInfoItem.IsIndexed = propertyAtt.Indexed; propInfoItem.ValuePosition = propertyAtt.Position; propInfoItem.IdentityIncrement = propertyAtt.IdentityIncrement; propInfoItem.IdentitySeed = propertyAtt.IdentitySeed; } RequiredAttribute requiredAtt = atts.OfType <RequiredAttribute>().FirstOrDefault(); propInfoItem.IsRequired = null != requiredAtt; UniqueKeyAttribute uniqueKeyAtt = atts.OfType <UniqueKeyAttribute>().FirstOrDefault(); propInfoItem.IsUnique = null != uniqueKeyAtt; MarkupAttribute markupAtt = atts.OfType <MarkupAttribute>().FirstOrDefault(); propInfoItem.IsMarkup = null != markupAtt; CryptoAttribute cryptoAtt = atts.OfType <CryptoAttribute>().FirstOrDefault(); propInfoItem.Encryption = (null != cryptoAtt) ? cryptoAtt.Method : CryptoMethod.None; ChildrenAttribute childrenAtt = atts.OfType <ChildrenAttribute>().FirstOrDefault(); //InheritedAttribute inheritedAtt = (InheritedAttribute)atts // .FirstOrDefault(s => s.GetType() == typeof(InheritedAttribute)); if (null != childrenAtt) { propInfoItem.ReferenceType = PropertyReferenceType.Children; propInfoItem.Cascade = CascadeOptions.Delete; propInfoItem.ChildParentProperty = childrenAtt.RemoteParentProperty; } GenericTypePropertyAttribute genericTypeAtt = atts.OfType <GenericTypePropertyAttribute>().FirstOrDefault(); if (prop.PropertyType == typeof(object) && null != genericTypeAtt) { propInfoItem.GenericTypeProperty = genericTypeAtt.Name; } //setting reference type if (propInfoItem.ReferenceType != PropertyReferenceType.Children) { if (propTypeCategory == PropertyTypeCategory.None) { propInfoItem.ReferenceType = PropertyReferenceType.None; } else if (foreignKeyAtts.Any()) { if (prop.PropertyType.GetProperties() .Where(s => s.PropertyType == type && null != s.GetCustomAttribute <ForeignKeyAttribute>(false)).Any()) { propInfoItem.ReferenceType = PropertyReferenceType.SelfForeign; } else { propInfoItem.ReferenceType = PropertyReferenceType.Foreign; } } else if (parentKeyAtts.Any()) { propInfoItem.ReferenceType = PropertyReferenceType.Parent; } else { propInfoItem.ReferenceType = PropertyReferenceType.Reference; // PropertyDescriptorCollection propTypeProps = TypeDescriptor.GetProperties(prop.PropertyType); var propTypeProps = type.GetProperties().Where(s => s.GetAccessors(false).Any()).ToList(); System.Collections.IEnumerator propTypePropsItems = propTypeProps.GetEnumerator(); foreach (var propTypeProp in propTypeProps) { var propTypePropAtts = propTypeProp.GetCustomAttributes(false).ToArray(); if (propTypePropAtts.OfType <PrimaryKeyAttribute>().Any()) { propInfoItem.ReferenceType = PropertyReferenceType.Complex; propInfoItem.Cascade = CascadeOptions.Delete; break; } } } } if (propTypeCategory == PropertyTypeCategory.Array) { propInfoItem.CollectionItemType = prop.PropertyType.GetElementType(); } else if (propTypeCategory == PropertyTypeCategory.GenericCollection) { propInfoItem.CollectionItemType = prop.PropertyType.GetGenericArguments().FirstOrDefault(); } typeProps.Add(propInfoItem); if (prop.PropertyType != type && ( propTypeCategory == PropertyTypeCategory.Class || propTypeCategory == PropertyTypeCategory.Array || propTypeCategory == PropertyTypeCategory.GenericCollection)) { if (prop.PropertyType.IsArray && prop.PropertyType.GetArrayRank() == 1) { innerTypes.Add(prop.PropertyType.GetElementType()); } else if (null != prop.PropertyType.GetTypeInfo().GetInterface("ICollection")) { innerTypes.Add(prop.PropertyType.GetGenericArguments().FirstOrDefault()); } else if (prop.PropertyType.GetTypeInfo().IsClass) { innerTypes.Add(prop.PropertyType); } } } properties.Add(type.FullName, typeProps); //if there is no PrimaryKey find a property with name Id and make it PrimaryKey if (!typeProps.Any(s => s.IsPrimaryKey)) { var primaryKeyProperty = typeProps.FirstOrDefault(s => s.PropertyName == "Id"); if (primaryKeyProperty != null) { primaryKeyProperty.IsPrimaryKey = true; if (primaryKeyProperty.PropertyType != typeof(string)) { primaryKeyProperty.IsAutonumber = true; } } } } } //after loading all PropertyInfoItems validate them CheckReservedKeywords(type); //load types of inner reference type properties foreach (var innerType in innerTypes) { LoadType(innerType); } } //else if (properties.ContainsKey(type.FullName)) //{ // typeProps = Properties(type.FullName).ToList(); // props = System.ComponentModel.TypeDescriptor.GetProperties(type); // foreach (PropertyDescriptor prop in props) // { // var propItems = typeProps.Select(s => s.Property).ToArray(); // if (propItems.Contains(prop)) // continue; // var refType = GetPropertyTypeCategory(prop.PropertyType); // if (refType == PropertyTypeCategory.Class || // refType == PropertyTypeCategory.Array || // refType == PropertyTypeCategory.GenericCollection) // { // if (prop.PropertyType.IsArray && prop.PropertyType.GetArrayRank() == 1) // LoadType(prop.PropertyType.GetElementType()); // else if (null != prop.PropertyType.GetInterface("ICollection")) // LoadType(prop.PropertyType.GetGenericArguments().FirstOrDefault()); // else if (prop.PropertyType.IsClass) // LoadType(prop.PropertyType); // } // } //} }
protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); MochaClassLibraryObjectModel mcl = (objectModels.Pop() as MochaClassLibraryObjectModel); MarkupTagElement tagMocha = (mom.Elements["mocha"] as MarkupTagElement); if (tagMocha == null) { throw new InvalidDataFormatException("file does not contain top-level 'mocha' tag"); } MarkupTagElement tagLibraries = (tagMocha.Elements["libraries"] as MarkupTagElement); if (tagLibraries != null) { for (int i = 0; i < tagLibraries.Elements.Count; i++) { MochaLibrary library = LoadLibrary(mcl, tagLibraries.Elements[i] as MarkupTagElement); if (library == null) { continue; } mcl.Libraries.Merge(library); } } MarkupTagElement tagTenants = (tagMocha.Elements["tenants"] as MarkupTagElement); if (tagTenants != null) { foreach (MarkupTagElement tagTenant in tagTenants.Elements.OfType <MarkupTagElement>()) { if (tagTenant == null) { continue; } if (tagTenant.FullName != "tenant") { continue; } MarkupAttribute attTenantID = tagTenant.Attributes["id"]; MarkupAttribute attTenantName = tagTenant.Attributes["name"]; if (attTenantID == null || attTenantName == null) { continue; } MochaTenant tenant = new MochaTenant(); tenant.ID = new Guid(attTenantID.Value); tenant.Name = attTenantName.Value; MarkupTagElement tagLibraryReferences = tagTenant.Elements["libraryReferences"] as MarkupTagElement; if (tagLibraryReferences != null) { foreach (MarkupTagElement tagLibraryReference in tagLibraryReferences.Elements.OfType <MarkupTagElement>()) { MarkupAttribute attLibraryId = tagLibraryReference.Attributes["libraryId"]; if (attLibraryId == null) { continue; } tenant.LibraryReferences.Add(new MochaLibraryReference(new Guid(attLibraryId.Value))); } } MarkupTagElement tagInstances = tagTenant.Elements["instances"] as MarkupTagElement; if (tagInstances != null) { foreach (MarkupTagElement tagInstance in tagInstances.Elements.OfType <MarkupTagElement>()) { MochaInstance inst = LoadInstance(tenant, tagInstance); tenant.Instances.Add(inst); } } mcl.Tenants.Add(tenant); } } }
private MochaInstance LoadInstance(IMochaStore library, MarkupTagElement tag) { if (tag == null) { return(null); } if (tag.FullName != "instance") { return(null); } MarkupAttribute attID = tag.Attributes["id"]; if (attID == null) { return(null); } MarkupAttribute attIndex = tag.Attributes["index"]; int? index = null; if (attIndex != null) { if (Int32.TryParse(attIndex.Value, out int index2)) { index = index2; } } MarkupAttribute attClassInstanceId = tag.Attributes["classInstanceId"]; MarkupAttribute attSuperClassId = tag.Attributes["superClassId"]; Guid instanceId = new Guid(attID.Value); MochaInstance inst = library.Instances[instanceId]; if (inst == null) { inst = new MochaInstance(); inst.ID = instanceId; } inst.Index = index; if (inst.Index != null) { // SetIndex(library, inst); } if (attClassInstanceId != null) { if (Guid.TryParse(attClassInstanceId.Value, out Guid classInstanceId)) { SetParentClass(library, inst.ID, classInstanceId); } else { Console.Error.WriteLine("bad guid for classInstanceId: {0}", attClassInstanceId.Value); } } if (attSuperClassId != null) { if (Guid.TryParse(attSuperClassId.Value, out Guid superClassId)) { SetClass(library, inst.ID); SetOwner(library, inst.ID, global::Mocha.Core.KnownInstanceGuids.Users.XQEnvironments); SetSource(library, inst.ID, library.DefaultObjectSourceID); // global::Mocha.Core.KnownInstanceGuids.ObjectSources.System); SetSuperClass(library, inst.ID, superClassId); } else { Console.Error.WriteLine("bad guid for superClassId: {0}", attSuperClassId.Value); } } MarkupTagElement tagAttributeValues = tag.Elements["attributeValues"] as MarkupTagElement; if (tagAttributeValues != null) { for (int i = 0; i < tagAttributeValues.Elements.Count; i++) { MochaAttributeValue attv = LoadAttributeValue(tagAttributeValues.Elements[i] as MarkupTagElement); if (attv == null) { continue; } inst.AttributeValues.Add(attv); } } MarkupTagElement tagRelationships = tag.Elements["relationships"] as MarkupTagElement; if (tagRelationships != null) { for (int i = 0; i < tagRelationships.Elements.Count; i++) { MarkupTagElement tagRelationship = tagRelationships.Elements[i] as MarkupTagElement; if (tagRelationship == null) { continue; } if (tagRelationship.FullName != "relationship") { continue; } MarkupAttribute attRelationshipInstanceId = tagRelationship.Attributes["relationshipInstanceId"]; if (attRelationshipInstanceId == null) { continue; } if (String.IsNullOrEmpty(attRelationshipInstanceId.Value)) { Console.Error.WriteLine("relationshipInstanceId not specified for relationship"); continue; } MochaRelationship rel = new MochaRelationship(); rel.SourceInstanceID = inst.ID; if (Guid.TryParse(attRelationshipInstanceId.Value, out Guid id)) { rel.RelationshipInstanceID = id; } else { Console.Error.WriteLine("bad guid for relationship: relationshipInstanceId='{0}'", attRelationshipInstanceId.Value); } MarkupTagElement tagTargetInstances = tagRelationship.Elements["targetInstances"] as MarkupTagElement; if (tagTargetInstances != null) { for (int j = 0; j < tagTargetInstances.Elements.Count; j++) { MarkupTagElement tagInstanceReference = tagTargetInstances.Elements[j] as MarkupTagElement; if (tagInstanceReference == null) { continue; } if (tagInstanceReference.FullName != "instanceReference") { continue; } MarkupAttribute attInstanceId = tagInstanceReference.Attributes["instanceId"]; if (attInstanceId == null) { continue; } if (Guid.TryParse(attInstanceId.Value, out Guid instId)) { rel.DestinationInstanceIDs.Add(instId); } else { Console.Error.WriteLine("bad guid for instanceReference: instanceId='{0}'", attInstanceId.Value); } } } library.Relationships.Add(rel); } } MarkupTagElement tagTranslations = tag.Elements["translations"] as MarkupTagElement; if (tagTranslations != null) { for (int i = 0; i < tagTranslations.Elements.Count; i++) { MarkupTagElement tagTranslation = (tagTranslations.Elements[i] as MarkupTagElement); if (tagTranslation == null) { continue; } if (tagTranslation.FullName != "translation") { continue; } MarkupAttribute attRelationshipId = tagTranslation.Attributes["relationshipInstanceId"]; if (attRelationshipId == null) { continue; } MarkupTagElement tagTranslationValues = (tagTranslation.Elements["translationValues"] as MarkupTagElement); if (tagTranslationValues == null) { continue; } MochaInstance instTTC = new MochaInstance(); instTTC.ID = Guid.NewGuid(); SetParentClass(library, instTTC.ID, global::Mocha.Core.KnownInstanceGuids.Classes.Translation); MochaRelationship relInstance__has__Translatable_Text_Constant = new MochaRelationship(); relInstance__has__Translatable_Text_Constant.SourceInstanceID = inst.ID; relInstance__has__Translatable_Text_Constant.RelationshipInstanceID = new Guid(attRelationshipId.Value); relInstance__has__Translatable_Text_Constant.DestinationInstanceIDs.Add(instTTC.ID); library.Relationships.Add(relInstance__has__Translatable_Text_Constant); MochaRelationship relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value = new MochaRelationship(); relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.SourceInstanceID = instTTC.ID; relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Translatable_Text_Constant__has__Translatable_Text_Constant_Value; for (int j = 0; j < tagTranslationValues.Elements.Count; j++) { MarkupTagElement tagTranslationValue = (tagTranslationValues.Elements[j] as MarkupTagElement); if (tagTranslationValue == null) { continue; } if (tagTranslationValue.FullName != "translationValue") { continue; } MarkupAttribute attLanguageInstanceID = tagTranslationValue.Attributes["languageInstanceId"]; MarkupAttribute attValue = tagTranslationValue.Attributes["value"]; if (attLanguageInstanceID == null || attValue == null) { continue; } // create a new TTCValue instance MochaInstance instTranslationValue = new MochaInstance(); instTranslationValue.ID = Guid.NewGuid(); SetParentClass(library, instTranslationValue.ID, global::Mocha.Core.KnownInstanceGuids.Classes.TranslatableTextConstantValue); // associate the TTCValue with the Language MochaRelationship relTranslatable_Text_Constant_Value__has__Language = new MochaRelationship(); relTranslatable_Text_Constant_Value__has__Language.SourceInstanceID = instTranslationValue.ID; relTranslatable_Text_Constant_Value__has__Language.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Translatable_Text_Constant_Value__has__Language; relTranslatable_Text_Constant_Value__has__Language.DestinationInstanceIDs.Add(new Guid(attLanguageInstanceID.Value)); library.Relationships.Add(relTranslatable_Text_Constant_Value__has__Language); // set the Value attribute of the TTCValue MochaAttributeValue mavValue = new MochaAttributeValue(); mavValue.AttributeInstanceID = global::Mocha.Core.KnownAttributeGuids.Text.Value; mavValue.Value = attValue.Value; instTranslationValue.AttributeValues.Add(mavValue); // add the TTCValue to the instance list library.Instances.Add(instTranslationValue); // add the TTCValue to the TTC.has TTC Value relationship relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.DestinationInstanceIDs.Add(instTranslationValue.ID); } library.Relationships.Add(relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value); library.Instances.Add(instTTC); } } return(inst); }
private MochaLibrary LoadLibrary(MochaClassLibraryObjectModel parent, MarkupTagElement tag) { if (tag == null) { return(null); } if (tag.FullName != "library") { return(null); } MarkupAttribute attGuid = tag.Attributes["id"]; if (attGuid == null) { return(null); } Guid id = new Guid(attGuid.Value); MochaLibrary library = parent.Libraries[id]; if (library == null) { library = new MochaLibrary(); library.ID = id; } MarkupAttribute attDefaultObjectSourceId = tag.Attributes["defaultObjectSourceId"]; if (attDefaultObjectSourceId != null) { library.DefaultObjectSourceID = new Guid(attDefaultObjectSourceId.Value); } else { library.DefaultObjectSourceID = global::Mocha.Core.KnownInstanceGuids.ObjectSources.System; } MarkupTagElement tagMetadata = tag.Elements["metadata"] as MarkupTagElement; if (tagMetadata != null) { for (int i = 0; i < tagMetadata.Elements.Count; i++) { MarkupTagElement tagMetadataItem = tagMetadata.Elements[i] as MarkupTagElement; if (tagMetadataItem == null) { continue; } library.Metadata.Add(new MochaLibraryMetadata(tagMetadataItem.Name, tagMetadataItem.Value)); } } MarkupTagElement tagInstances = tag.Elements["instances"] as MarkupTagElement; if (tagInstances != null) { for (int i = 0; i < tagInstances.Elements.Count; i++) { MochaInstance inst = LoadInstance(library, tagInstances.Elements[i] as MarkupTagElement); if (inst == null) { continue; } library.Instances.Add(inst); } } return(library); }