public XsoDriverPropertyDefinition GetRelatedWrapperProperty(PropertyDefinition def)
        {
            if (def == null)
            {
                throw new ArgumentNullException("def");
            }
            if (!(def is StorePropertyDefinition))
            {
                throw new NotSupportedException("GetRelatedWrapperProperty: def: " + def.GetType().FullName);
            }
            XsoDriverPropertyDefinition result;

            if (this.xsoPropertyMappings.TryGetValue(def, out result))
            {
                return(result);
            }
            return(null);
        }
Ejemplo n.º 2
0
        private void FillEntityProperties(PropertyDefinition rp, XmlNode propertiesNode)
        {
            XmlElement propertyElement = null;

            if (rp is ScalarPropertyDefinition)
            {
                propertyElement = CreateElement("Property");
            }
            else if (rp is EntityPropertyDefinition)
            {
                propertyElement = CreateElement("EntityProperty");
            }
            else if (rp is CustomPropertyDefinition)
            {
                propertyElement = CreateElement("CustomProperty");
            }
            else
            {
                throw new NotSupportedException(rp.GetType().ToString());
            }

            if (rp.PropertyAccessLevel == AccessLevel.Private &&
                rp.Interfaces.Any())
            {
                string[] ss = rp.Name.Split(':');
                if (ss.Length > 1)
                {
                    propertyElement.SetAttribute("name", ss[1]);
                }
                else
                {
                    propertyElement.SetAttribute("name", rp.Name);
                }
            }
            else
            {
                propertyElement.SetAttribute("name", rp.Name);
            }

            if (rp.Attributes != Field2DbRelations.None)
            {
                propertyElement.SetAttribute("attributes", rp.Attributes.ToString().Replace(",", ""));
            }

            if (rp.SourceFragment != null)
            {
                propertyElement.SetAttribute("table", rp.SourceFragment.Identifier);
            }

            if (rp.PropertyType != null)
            {
                if (rp is ScalarPropertyDefinition || rp is CustomPropertyDefinition)
                {
                    propertyElement.SetAttribute("type", rp.PropertyType.Identifier);
                }
                else if (rp is EntityPropertyDefinition)
                {
                    propertyElement.SetAttribute("referencedEntity", rp.PropertyType.Entity.Identifier);
                }
                else
                {
                    throw new NotSupportedException(rp.GetType().ToString());
                }
            }

            if (!string.IsNullOrEmpty(rp.Description))
            {
                propertyElement.SetAttribute("description", rp.Description);
            }

            if (rp.FieldAccessLevel != AccessLevel.Private && !(rp is CustomPropertyDefinition))
            {
                propertyElement.SetAttribute("classfieldAccessLevel", rp.FieldAccessLevel.ToString());
            }

            if (rp.PropertyAccessLevel != AccessLevel.Public)
            {
                propertyElement.SetAttribute("propertyAccessLevel", rp.PropertyAccessLevel.ToString());
            }

            if (rp.PropertyAlias != rp.Name)
            {
                propertyElement.SetAttribute("propertyAlias", rp.PropertyAlias);
            }

            if (rp.Disabled)
            {
                propertyElement.SetAttribute("disabled", XmlConvert.ToString(true));
            }

            if (rp.Obsolete != ObsoleteType.None)
            {
                propertyElement.SetAttribute("obsolete", rp.Obsolete.ToString());
            }

            if (!string.IsNullOrEmpty(rp.ObsoleteDescripton))
            {
                propertyElement.SetAttribute("obsoleteDescription", rp.ObsoleteDescripton);
            }

            if (rp.EnablePropertyChanged && !(rp is CustomPropertyDefinition))
            {
                propertyElement.SetAttribute("enablePropertyChanged", XmlConvert.ToString(rp.EnablePropertyChanged));
            }

            if (rp.Action != MergeAction.Merge)
            {
                propertyElement.SetAttribute("action", rp.Action.ToString());
            }

            if (!string.IsNullOrEmpty(rp.DefferedLoadGroup) && !(rp is CustomPropertyDefinition))
            {
                propertyElement.SetAttribute("defferedLoadGroup", rp.DefferedLoadGroup);
            }

            if (!rp.GenerateAttribute && !(rp is CustomPropertyDefinition))
            {
                propertyElement.SetAttribute("generateAttribute", XmlConvert.ToString(rp.GenerateAttribute));
            }

            if (!string.IsNullOrEmpty(rp.AvailableFrom) && !(rp is CustomPropertyDefinition))
            {
                propertyElement.SetAttribute("availableFrom", rp.AvailableFrom);
            }

            if (!string.IsNullOrEmpty(rp.AvailableTo) && !(rp is CustomPropertyDefinition))
            {
                propertyElement.SetAttribute("availableTo", rp.AvailableTo);
            }

            if (!string.IsNullOrEmpty(rp.Feature))
            {
                propertyElement.SetAttribute("feature", rp.Feature);
            }

            if (rp.Interfaces.Any())
            {
                var implElement = CreateElement("implement");
                propertyElement.AppendChild(implElement);

                foreach (var interfaceId in rp.Interfaces)
                {
                    var intElement = CreateElement("interface");
                    implElement.AppendChild(intElement);
                    intElement.SetAttribute("ref", interfaceId.Ref);
                    if (!string.IsNullOrEmpty(interfaceId.Prop))
                    {
                        intElement.SetAttribute("property", interfaceId.Prop);
                    }
                }
            }

            if (rp is ScalarPropertyDefinition)
            {
                ScalarPropertyDefinition property = rp as ScalarPropertyDefinition;

                if (!string.IsNullOrEmpty(property.SourceFieldAlias))
                {
                    propertyElement.SetAttribute("fieldAlias", property.SourceFieldAlias);
                }

                if (property.SourceField != null)
                {
                    propertyElement.SetAttribute("fieldName", property.SourceFieldExpression);

                    if (!string.IsNullOrEmpty(property.SourceType))
                    {
                        propertyElement.SetAttribute("fieldTypeName", property.SourceType);
                    }

                    if (property.SourceTypeSize.HasValue)
                    {
                        propertyElement.SetAttribute("fieldTypeSize", XmlConvert.ToString(property.SourceTypeSize.Value));
                    }

                    if (!property.IsNullable)
                    {
                        propertyElement.SetAttribute("fieldNullable", XmlConvert.ToString(property.IsNullable));
                    }

                    if (!string.IsNullOrEmpty(property.SourceField.DefaultValue))
                    {
                        propertyElement.SetAttribute("fieldDefault", property.SourceField.DefaultValue);
                    }
                }
            }
            else if (rp is EntityPropertyDefinition)
            {
                EntityPropertyDefinition property = rp as EntityPropertyDefinition;
                foreach (EntityPropertyDefinition.SourceField field in property.SourceFields)
                {
                    XmlElement fields = CreateElement("field");

                    fields.SetAttribute("relatedProperty", field.PropertyAlias);

                    if (!string.IsNullOrEmpty(field.SourceFieldExpression))
                    {
                        fields.SetAttribute("fieldName", field.SourceFieldExpression);
                    }

                    if (!string.IsNullOrEmpty(field.SourceType))
                    {
                        fields.SetAttribute("fieldTypeName", field.SourceType);
                    }

                    if (field.SourceTypeSize.HasValue)
                    {
                        fields.SetAttribute("fieldTypeSize", XmlConvert.ToString(field.SourceTypeSize.Value));
                    }

                    if (!field.IsNullable)
                    {
                        fields.SetAttribute("fieldNullable", XmlConvert.ToString(field.IsNullable));
                    }

                    if (!string.IsNullOrEmpty(field.SourceFieldAlias))
                    {
                        fields.SetAttribute("fieldAlias", field.SourceFieldAlias);
                    }

                    if (!string.IsNullOrEmpty(field.DefaultValue))
                    {
                        fields.SetAttribute("fieldDefault", field.DefaultValue);
                    }

                    propertyElement.AppendChild(fields);
                }
            }
            else if (rp is CustomPropertyDefinition)
            {
                CustomPropertyDefinition property = rp as CustomPropertyDefinition;
                XmlElement get = CreateElement("Get");
                FillBody(get, property.GetBody);
                propertyElement.AppendChild(get);

                if (property.SetBody != null)
                {
                    XmlElement set = CreateElement("Set");
                    FillBody(set, property.SetBody);
                    propertyElement.AppendChild(set);
                }
            }
            else
            {
                throw new NotSupportedException(rp.GetType().ToString());
            }

            if (rp.Extensions.Count > 0)
            {
                foreach (var extension in rp.Extensions)
                {
                    FillExtension(propertyElement, extension);
                }
            }

            propertiesNode.AppendChild(propertyElement);
        }
Ejemplo n.º 3
0
        private PropertyControl InstantiateControl(PropertyDefinition def)
        {
            GameObject prefab = SelectControl(def);

            if (prefab)
            {
                GameObject      newObject = Instantiate(prefab, ControlParent);
                PropertyControl control   = newObject.GetComponent <PropertyControl>();
                control.Control(def);

                control.OnValueChanged += OnPropertyValueChanged; // Will doing this result in control dangling if destroyed, or will it be cleaned up by GC?

                return(control);
            }

            throw new InvalidOperationException($"There are no controls that can take care of property def type {def.GetType().Name}'.");
        }
Ejemplo n.º 4
0
        private void MergeEntities(WXMLModel mergeWith)
        {
            foreach (EntityDefinition newEntity in mergeWith.GetEntities())
            {
                string newEntityIdentifier = newEntity.Identifier;

                EntityDefinition entity = GetEntities().SingleOrDefault(item => item.Identifier == newEntityIdentifier);
                if (entity != null)
                {
                    if (!string.IsNullOrEmpty(newEntity.Name))
                    {
                        entity.Name = newEntity.Name;
                    }

                    entity.Namespace          = newEntity.Namespace;
                    entity.BaseEntity         = newEntity.BaseEntity;
                    entity.Behaviour          = newEntity.Behaviour;
                    entity.CacheCheckRequired = newEntity.CacheCheckRequired;
                    entity.Description        = newEntity.Description;
                    entity.Disabled           = newEntity.Disabled;
                    entity.InheritsBaseTables = newEntity.InheritsBaseTables;
                    entity.AutoInterface      = newEntity.AutoInterface;
                    entity.UseGenerics        = newEntity.UseGenerics;
                    entity.FamilyName         = newEntity.FamilyName;
                    foreach (var @interface in newEntity.Interfaces)
                    {
                        if (!entity.Interfaces.ContainsKey(@interface.Key))
                        {
                            entity.Interfaces.Add(@interface.Key, @interface.Value);
                        }
                    }

                    entity.ClearSourceFragments();
                    foreach (SourceFragmentRefDefinition newsf in newEntity.OwnSourceFragments)
                    {
                        //string newsfId = newsf.Identifier;
                        //SourceFragmentRefDefinition sf =
                        //    entity.GetSourceFragments().SingleOrDefault(item => item.Identifier == newsfId);

                        //foreach (PropertyDefinition rp in entity.GetProperties()
                        //    .Where(item=>item.SourceFragment == sf))
                        //{
                        //    if (rp is ScalarPropertyDefinition)
                        //    {
                        //        ScalarPropertyDefinition property = rp as ScalarPropertyDefinition;
                        //        property.SourceField.SourceFragment = newsf;
                        //    }
                        //    else if (rp is EntityPropertyDefinition)
                        //    {
                        //        EntityPropertyDefinition property = rp as EntityPropertyDefinition;
                        //        property.SourceFragment = newsf;
                        //    }
                        //}

                        //entity.RemoveSourceFragment(sf);
                        entity.AddSourceFragment(newsf);
                    }
                    //List<SourceFragmentRefDefinition> torem = new List<SourceFragmentRefDefinition>();
                    //foreach (SourceFragmentRefDefinition newsf in newEntity.GetSourceFragments())
                    //{
                    //    string newsfId = newsf.Identifier;
                    //    SourceFragmentRefDefinition sf =
                    //        entity.GetSourceFragments().SingleOrDefault(item => item.Identifier == newsfId);

                    //    if (sf != null)
                    //    {
                    //        if (newsf.Action == MergeAction.Delete)
                    //        {
                    //            entity.RemoveSourceFragment(sf);
                    //            torem.Add(newsf);
                    //        }
                    //        else if (newsf.AnchorTable != null)
                    //        {
                    //            sf.AnchorTable = newsf.AnchorTable;
                    //            sf.JoinType = newsf.JoinType;
                    //            if (newsf.Conditions.Count > 0)
                    //            {
                    //                foreach (SourceFragmentRefDefinition.Condition c in newsf.Conditions)
                    //                {
                    //                    SourceFragmentRefDefinition.Condition ec =
                    //                        sf.Conditions.SingleOrDefault(item =>
                    //                            item.LeftColumn == c.LeftColumn &&
                    //                            item.RightColumn == c.RightColumn
                    //                        );
                    //                    if (ec != null)
                    //                    {
                    //                        if (c.Action == MergeAction.Delete)
                    //                            sf.Conditions.Remove(ec);
                    //                    }
                    //                    else
                    //                        sf.Conditions.Add(c);
                    //                }
                    //            }
                    //        }
                    //    }
                    //    else
                    //        entity.AddSourceFragment(newsf);
                    //}

                    //foreach (SourceFragmentRefDefinition newsf in torem)
                    //{
                    //    newEntity.RemoveSourceFragment(newsf);
                    //}

                    foreach (PropertyDefinition newProperty in newEntity.GetProperties())
                    {
                        string newPropertyName = newProperty.PropertyAlias;

                        PropertyDefinition rp =
                            entity.GetProperties().SingleOrDefault(item => item.PropertyAlias == newPropertyName);

                        if (rp != null)
                        {
                            if (newProperty.Action == MergeAction.Delete)
                            {
                                entity.RemoveProperty(rp);
                            }
                            else
                            {
                                rp.Name = MergeString(rp, newProperty, item => item.Name);
                                rp.ObsoleteDescripton = MergeString(rp, newProperty, item => item.ObsoleteDescripton);
                                rp.DefferedLoadGroup  = MergeString(rp, newProperty, item => item.DefferedLoadGroup);
                                rp.GenerateAttribute  = newProperty.GenerateAttribute;
                                rp.AvailableFrom      = MergeString(rp, newProperty, item => item.AvailableFrom);
                                rp.AvailableTo        = MergeString(rp, newProperty, item => item.AvailableTo);
                                rp.Description        = MergeString(rp, newProperty, item => item.Description);
                                if (newProperty.Attributes != Field2DbRelations.None)
                                {
                                    rp.Attributes = newProperty.Attributes;
                                }
                                rp.Feature               = MergeString(rp, newProperty, item => item.Feature);
                                rp.Group                 = newProperty.Group ?? rp.Group;
                                rp.PropertyType          = newProperty.PropertyType ?? rp.PropertyType;
                                rp.Disabled              = newProperty.Disabled;
                                rp.EnablePropertyChanged = newProperty.EnablePropertyChanged;
                                rp.SourceFragment        = newProperty.SourceFragment ?? rp.SourceFragment;

                                if (newProperty.FieldAccessLevel != default(AccessLevel))
                                {
                                    rp.FieldAccessLevel = newProperty.FieldAccessLevel;
                                }

                                if (newProperty.PropertyAccessLevel != default(AccessLevel))
                                {
                                    rp.PropertyAccessLevel = newProperty.PropertyAccessLevel;
                                }

                                if (newProperty.Obsolete != default(ObsoleteType))
                                {
                                    rp.Obsolete = newProperty.Obsolete;
                                }

                                if (rp.GetType() != newProperty.GetType())
                                {
                                    PropertyDefinition newProp = null;
                                    if (rp is EntityPropertyDefinition && newProperty is ScalarPropertyDefinition)
                                    {
                                        newProp = new ScalarPropertyDefinition(entity, newPropertyName);
                                        rp.CopyTo(newProp);
                                    }
                                    else if (rp is ScalarPropertyDefinition && newProperty is EntityPropertyDefinition)
                                    {
                                        newProp = new EntityPropertyDefinition(rp as ScalarPropertyDefinition);
                                    }
                                    entity.RemoveProperty(rp);
                                    entity.AddProperty(newProp);
                                    rp = newProp;
                                }

                                if (rp is ScalarPropertyDefinition)
                                {
                                    ScalarPropertyDefinition property = rp as ScalarPropertyDefinition;
                                    property.SourceField.SourceType            = MergeString(property, newProperty as ScalarPropertyDefinition, item => item.SourceType);
                                    property.SourceFieldAlias                  = MergeString(property, newProperty as ScalarPropertyDefinition, item => item.SourceFieldAlias);
                                    property.SourceField.SourceFieldExpression = MergeString(property, newProperty as ScalarPropertyDefinition, item => item.SourceFieldExpression);
                                    property.SourceField.IsNullable            = ((ScalarPropertyDefinition)newProperty).IsNullable;
                                    property.SourceField.SourceTypeSize        = ((ScalarPropertyDefinition)newProperty).SourceTypeSize ?? property.SourceTypeSize;
                                }
                            }
                        }
                        else
                        {
                            entity.AddProperty(newProperty);
                        }
                    }

                    MergeExtensions(entity.Extensions, newEntity.Extensions);
                }
                else
                {
                    AddEntity(newEntity);
                }
            }
        }