public static TraversalResults Parse(JObject response, IBranch branch)
        {
            TraversalResults results = new TraversalResults();

            JObject nodesObj = (JObject)response.GetValue("nodes");

            foreach (var kv in nodesObj)
            {
                string  field   = kv.Key;
                JObject nodeObj = (JObject)kv.Value;

                INode node = (INode)NodeUtil.Node(nodeObj, branch);
                results.Nodes.Add(node);
            }

            JObject associationsObj = (JObject)response.GetValue("associations");

            foreach (var kv in associationsObj)
            {
                string  field          = kv.Key;
                JObject associationObj = (JObject)kv.Value;

                IAssociation association = (IAssociation)NodeUtil.Node(associationObj, branch);
                results.Associations.Add(association);
            }

            return(results);
        }
 /// <summary>
 /// Creates an AssociationProperty from the supplied data.
 /// </summary>
 /// <param name="association"></param>
 /// <param name="property"></param>
 /// <param name="foreignProperty"></param>
 public AssociationProperty(IAssociation association, IProperty property, IProperty foreignProperty)
 {
     Property        = property;
     ForeignProperty = foreignProperty;
     Cascade         = (association.AssociationType == AssociationType.OneToMany && property != null && !property.IsNullable);
     Association     = association;
 }
Exemplo n.º 3
0
        private static string GetRelatedTableParameter(IEntity entity, IAssociation association)
        {
            //AssociationProperty childMember = association[0];
            //foreach (var searchCriteria in entity.SearchCriteria(SearchCriteriaType.ForeignKey))
            //{
            //    bool found = false;
            //    foreach (IProperty property in searchCriteria.Properties)
            //    {
            //        if (childMember.ForeignProperty.ForeignProperty.Equals(property.ForeignProperty) || childMember.ForeignProperty.Equals(property.ForeignProperty))
            //        {
            //            found = true;
            //            foreach (IAssociation association2 in entity.Associations.Where(a => a.AssociationType == AssociationType.ManyToOne || a.AssociationType == AssociationType.ManyToZeroOrOne))
            //            {
            //                foreach (AssociationProperty rootMember in association2)
            //                {
            //                    if (rootMember.Name.Equals(childMember.Name))
            //                    {
            //                        return String.Format(", {0}", Util.NamingConventions.VariableName(rootMember.Name));
            //                    }
            //                }
            //            }
            //        }
            //    }

            //    if(found)
            //    {
            //        return String.Format(", new {0}({1})", childMember.Name, GetRelatedEntity(childMember).Key.Properties.BuildPropertyVariableArguments());
            //    }
            //}

            return ", Nothing";
        }
        private static void UpdateStorageAssociationEndMultiplicity(IAssociation association, AssociationEnd principalEnd, AssociationEnd dependentEnd)
        {
            switch (association.AssociationType)
            {
            case AssociationType.OneToMany:
                principalEnd.Multiplicity = MultiplicityConstants.One;
                dependentEnd.Multiplicity = MultiplicityConstants.Many;
                break;

            case AssociationType.OneToOne:
                principalEnd.Multiplicity = MultiplicityConstants.One;
                dependentEnd.Multiplicity = MultiplicityConstants.One;
                break;

            case AssociationType.OneToZeroOrOne:
                principalEnd.Multiplicity = MultiplicityConstants.One;
                dependentEnd.Multiplicity = MultiplicityConstants.ZeroToOne;
                break;

            case AssociationType.ZeroOrOneToMany:
            case AssociationType.ManyToZeroOrOne:
                principalEnd.Multiplicity = MultiplicityConstants.ZeroToOne;
                dependentEnd.Multiplicity = MultiplicityConstants.Many;
                break;

            default:
                principalEnd.Multiplicity = MultiplicityConstants.One;
                dependentEnd.Multiplicity = MultiplicityConstants.Many;
                break;
            }
        }
Exemplo n.º 5
0
        public bool IsReadOnly(IAssociation association, string suffix)
        {
            if (association.Properties.Count <= 0)
            {
                return(false);
            }

            string key = String.Format("{0}{1}", association.ForeignEntity.EntityKeyName, suffix);

            if (ContextData.Get(key) == null)
            {
                return(false);
            }

            var value = ContextData[key];

            switch (value)
            {
            case Constants.ReadOnlyChild:
            case Constants.ReadOnlyRoot:
            case Constants.ReadOnlyChildList:
            case Constants.ReadOnlyList:
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
    public override Sage.Platform.Application.UI.ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
    {
        ToolsSmartPartInfo tinfo = new ToolsSmartPartInfo();

        if (BindingSource != null)
        {
            if (BindingSource.Current != null)
            {
                _assoc = (IAssociation)BindingSource.Current;
                if (_assoc.Id != null)
                {
                    Mode.Value  = "UPDATE";
                    tinfo.Title = GetLocalResourceObject("DialogTitleEdit").ToString();
                    divFromIDDialog.Style.Add("display", "none");
                    divFromIDText.Style.Add("display", "blocked");
                    divToIDDialog.Style.Add("display", "none");
                    divToIDText.Style.Add("display", "blocked");
                    divBackRelationToAdd.Style.Add("display", "none");
                    divBackRelationToEdit.Style.Add("display", "blocked");
                }
                else
                {
                    //new association
                    Mode.Value  = "ADD";
                    tinfo.Title = GetLocalResourceObject("DialogTitleEdit").ToString();
                    IAccount account = GetParentEntity() as IAccount;
                    string   Id      = string.Empty;
                    if (account != null)
                    {
                        Id = account.Id.ToString();
                    }
                    divFromIDDialog.Style.Add("display", "none");
                    divFromIDText.Style.Add("display", "blocked");
                    divToIDDialog.Style.Add("display", "blocked");
                    divToIDText.Style.Add("display", "none");
                    divBackRelationToAdd.Style.Add("display", "blocked");
                    divBackRelationToEdit.Style.Add("display", "none");
                    hdtAccountId.Value = Id;
                    luFromIDDialog.LookupResultValue = account.Id;
                    //luToIDDialog.LookupResultValue = null;
                    luFromIDText.LookupResultValue      = account.Id;
                    luFowardRelatedTo.LookupResultValue = account.Id;
                }
            }
        }

        foreach (Control c in AssociationForm_LTools.Controls)
        {
            tinfo.LeftTools.Add(c);
        }
        foreach (Control c in AssociationForm_CTools.Controls)
        {
            tinfo.CenterTools.Add(c);
        }
        foreach (Control c in AssociationForm_RTools.Controls)
        {
            tinfo.RightTools.Add(c);
        }
        return(tinfo);
    }
Exemplo n.º 7
0
        public static string BuildObjectInitializer(this IAssociation association, bool usePropertyName)
        {
            string parameters = String.Empty;

            foreach (IProperty property in association.SearchCriteria.Properties)
            {
                foreach (AssociationProperty associationProperty in association.Properties)
                {
                    if (property.KeyName == associationProperty.Property.KeyName && property == associationProperty.Property)
                    {
                        bool isNullable = property.IsNullable && property.SystemType != "System.String" && property.SystemType != "System.Byte()";
                        if (isNullable)
                        {
                            parameters += String.Format("\r\n                If({1}.HasValue) Then criteria.{0} = {1}.Value",
                                                        associationProperty.ForeignProperty.Name,
                                                        usePropertyName ? property.Name : property.VariableName);
                        }
                        else
                        {
                            parameters += String.Format("\r\n                criteria.{0} = {1}",
                                                        associationProperty.ForeignProperty.Name,
                                                        usePropertyName ? property.Name : property.VariableName);
                        }
                    }
                }
            }

            return(parameters.TrimStart(new[] { '\r', '\n', ' ', ',' }));
        }
Exemplo n.º 8
0
        public async void TestChildOf()
        {
            IBranch master = await Fixture.Repository.MasterAsync();

            JObject nodeObj1 = new JObject(
                new JProperty("title", "Node1")
                );
            INode node1 = (INode)await master.CreateNodeAsync(nodeObj1);

            JObject nodeObj2 = new JObject(
                new JProperty("title", "Node2")
                );
            INode node2 = (INode)await master.CreateNodeAsync(nodeObj2);

            IAssociation association = await node1.ChildOfAsync(node2);

            Assert.NotNull(association);
            Assert.Equal(Directionality.DIRECTED, association.Directionality);

            INode source = await association.ReadSourceNodeAsync();

            Assert.Equal(node2.Id, source.Id);
            INode target = await association.ReadTargetNodeAsync();

            Assert.Equal(node1.Id, target.Id);
        }
        private static string GetAssociationKey(IAssociation association)
        {
            IEnumerable <string> columns;
            string type;

            switch (association.AssociationType)
            {
            case AssociationType.ManyToOne:
            case AssociationType.ManyToZeroOrOne:
                columns = association.Properties.Select(p => p.Property.GetSafeName());
                type    = "ManyTo";
                break;

            case AssociationType.ManyToMany:
            case AssociationType.OneToMany:
            case AssociationType.ZeroOrOneToMany:
                columns = association.Properties.Select(p => p.ForeignProperty.GetSafeName());
                type    = "ToMany";
                break;

            default:
                return(String.Empty);
            }

            return(columns.Aggregate(String.Empty, (current, column) => String.Concat(current, column, "|")) + type);
        }
Exemplo n.º 10
0
        Activity ResolveNextActivity(IAssociation assoc, NavigateResults navResults, ProcessContext processContext)
        {
            var parent = this.FromActivity.Parent as Activity;

            if (parent.Graph.Nodes == null)
            {
                throw new InvalidGraphException("父级节点{0}的图形不正确,没有nodes", parent.Id.ToString());
            }
            var node = parent.Graph.Nodes.FirstOrDefault(node => node.Name == assoc.To);

            if (node == null)
            {
                throw new InvalidGraphException("未在父级节点{0}找到名称为{1}的节点", parent.Id.ToString(), assoc.To);
            }

            var nextActivity = parent.FindUndealedChild(node.Name);

            if (nextActivity != null)
            {
                return(nextActivity);
            }

            nextActivity = new Activity(this.FromActivity.Engine, parent, node, this.FromActivity.Version, navResults.NextInputs, processContext.Dealer, navResults.NextDealer, processContext);
            this.FromActivity.Todo(nextActivity, navResults.NextInputs);
            this.ToActivities.Add(nextActivity);
            this.ActivityEntities.Add(nextActivity.Entity);
            return(nextActivity);
        }
        private static void PrepAssociation(IAssociation assocication)
        {
            bool isNullable;

            switch (assocication.AssociationType)
            {
            case AssociationType.ManyToOne:
            case AssociationType.ManyToZeroOrOne:

                isNullable = assocication.Properties.All(ap => ap.Property.IsNullable);
                assocication.ExtendedProperties.Add(NotNull, !isNullable ? "true" : "false");

                break;

            case AssociationType.OneToMany:
            case AssociationType.ZeroOrOneToMany:

                isNullable = assocication.Properties.Any(ap => ap.Property.IsNullable);
                assocication.ExtendedProperties.Add(Cascade, isNullable ? "all" : "all-delete-orphan");
                assocication.ExtendedProperties.Add(Lazy, "true");

                break;

            case AssociationType.ManyToMany:

                assocication.ExtendedProperties.Add(Cascade, "all");
                assocication.ExtendedProperties.Add(Lazy, "true");

                break;
            }
        }
Exemplo n.º 12
0
        private static string GetRelatedTableParameter(IEntity entity, IAssociation association)
        {
            //AssociationProperty childMember = association[0];
            //foreach (var searchCriteria in entity.SearchCriteria(SearchCriteriaType.ForeignKey))
            //{
            //    bool found = false;
            //    foreach (IProperty property in searchCriteria.Properties)
            //    {
            //        if (childMember.ForeignProperty.ForeignProperty.Equals(property.ForeignProperty) || childMember.ForeignProperty.Equals(property.ForeignProperty))
            //        {
            //            found = true;
            //            foreach (IAssociation association2 in entity.Associations.Where(a => a.AssociationType == AssociationType.ManyToOne || a.AssociationType == AssociationType.ManyToZeroOrOne))
            //            {
            //                foreach (AssociationProperty rootMember in association2)
            //                {
            //                    if (rootMember.Name.Equals(childMember.Name))
            //                    {
            //                        return String.Format(", {0}", Util.NamingConventions.VariableName(rootMember.Name));
            //                    }
            //                }
            //            }
            //        }
            //    }

            //    if(found)
            //    {
            //        return String.Format(", new {0}({1})", childMember.Name, GetRelatedEntity(childMember).Key.Properties.BuildPropertyVariableArguments());
            //    }
            //}

            return(", null");
        }
    public override Sage.Platform.Application.UI.ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
    {
        ToolsSmartPartInfo tinfo = new ToolsSmartPartInfo();
        if (BindingSource != null)
        {
            if (BindingSource.Current != null)
            {
                _assoc = (IAssociation)BindingSource.Current;
                if (_assoc.Id != null)
                {
                    Mode.Value = "UPDATE";
                    tinfo.Title = GetLocalResourceObject("DialogTitleEdit").ToString();
                    divFromIDDialog.Style.Add("display", "none");
                    divFromIDText.Style.Add("display", "blocked");
                    divToIDDialog.Style.Add("display", "none");
                    divToIDText.Style.Add("display", "blocked");
                    divBackRelationToAdd.Style.Add("display", "none");
                    divBackRelationToEdit.Style.Add("display", "blocked");
                }
                else
                {
                    //new association
                    Mode.Value = "ADD";
                    tinfo.Title = GetLocalResourceObject("DialogTitleEdit").ToString();
                    IAccount account = GetParentEntity() as IAccount;
                    string Id = string.Empty;
                    if (account != null)
                    {
                        Id = account.Id.ToString();
                    }
                    divFromIDDialog.Style.Add("display", "none");
                    divFromIDText.Style.Add("display", "blocked");
                    divToIDDialog.Style.Add("display", "blocked");
                    divToIDText.Style.Add("display", "none");
                    divBackRelationToAdd.Style.Add("display", "blocked");
                    divBackRelationToEdit.Style.Add("display", "none");
                    hdtAccountId.Value = Id;
                    luFromIDDialog.LookupResultValue = account.Id;
                    //luToIDDialog.LookupResultValue = null;
                    luFromIDText.LookupResultValue = account.Id;
                    luFowardRelatedTo.LookupResultValue = account.Id;
                }
            }
        }

        foreach (Control c in AssociationForm_LTools.Controls)
        {
            tinfo.LeftTools.Add(c);
        }
        foreach (Control c in AssociationForm_CTools.Controls)
        {
            tinfo.CenterTools.Add(c);
        }
        foreach (Control c in AssociationForm_RTools.Controls)
        {
            tinfo.RightTools.Add(c);
        }
        return tinfo;
    }
Exemplo n.º 14
0
 private void RemoveNormalUser(NormalUser user, IAssociation roleName)
 {
     if (roleName == null)
     {
         throw new Exception("Asocjacja nie moze byc null.");
     }
     RemovePart(roleName, user);
 }
Exemplo n.º 15
0
 private void RemoveAdministrator(UserAdministrator user, IAssociation roleName)
 {
     if (roleName == null)
     {
         throw new Exception("Asocjacja nie moze byc null.");
     }
     RemovePart(roleName, user);
 }
Exemplo n.º 16
0
 public int RoleSize(IAssociation roleName)
 {
     if (ContainsRole(roleName) == false)
     {
         throw new Exception("Nie moge pobrac rozmiaru relacji z uwagi na brak asocjacji: " + roleName);
     }
     return(Links[roleName].Count);
 }
Exemplo n.º 17
0
        public Employee(IAssociation roleNameStorekeeper, IAssociation roleNameServiceman, DateTime birthDate, bool forkliftLicense, string specialization) : base()
        {
            BirthDate = birthDate;

            AddStorekeeper(roleNameStorekeeper, forkliftLicense);

            AddServiceman(roleNameServiceman, specialization);
        }
 public AssociationModel(IAssociation association, string requiredType = SpecializationType)
 {
     if (!requiredType.Equals(association.SpecializationType, StringComparison.InvariantCultureIgnoreCase))
     {
         throw new Exception($"Cannot create a '{GetType().Name}' from association with specialization type '{association.SpecializationType}'. Must be of type '{SpecializationType}'");
     }
     _association = association;
 }
 public void Add(IAssociation assoc)
 {
     if (assoc == null)
     {
         throw new ArgumentNullException("assoc");
     }
     _assocs.Add(assoc);
 }
        private void CreateStorageAssociation(IAssociation association)
        {
            //<Association Name="FK__Product__Categor__0CBAE877">
            //  <End Role="Category" Type="PetShopModel1.Store.Category" Multiplicity="1" />
            //  <End Role="Product" Type="PetShopModel1.Store.Product" Multiplicity="*" />
            //  <ReferentialConstraint>
            //      <Principal Role="Category">
            //          <PropertyRef Name="CategoryId" />
            //      </Principal>
            //      <Dependent Role="Product">
            //          <PropertyRef Name="CategoryId" />
            //      </Dependent>
            //  </ReferentialConstraint>
            //</Association>
            IEntity principalEntity;
            IEntity dependentEntity;
            bool    isParentEntity;
            string  key;
            string  toRole;
            string  fromRole;

            ResolveStorageAssociationValues(association, out principalEntity, out dependentEntity, out isParentEntity, out key, out toRole, out fromRole);

            // The associations are stupid and if an end is added after the ReferentialConstraint, than the API doesn't detect it...
            var assoc = StorageSchema.Associations.Where(a => a.Name.Equals(association.AssociationKeyName)).FirstOrDefault();

            if (assoc != null)
            {
                StorageSchema.Associations.Remove(assoc);
            }
            assoc = new LinqToEdmx.Model.Storage.Association()
            {
                Name = association.AssociationKeyName,
                Ends = new List <AssociationEnd>()
            };

            StorageSchema.Associations.Add(assoc);

            var principalEnd = CreateStorageAssociationEnd(principalEntity, toRole, assoc, IsCascadeDelete(association));
            var dependentEnd = CreateStorageAssociationEnd(dependentEntity, fromRole, assoc, false);

            UpdateStorageAssociationEndMultiplicity(association, principalEnd, dependentEnd);

            assoc.ReferentialConstraint = new LinqToEdmx.Model.Storage.Constraint {
                Principal = new ReferentialConstraintRoleElement()
                {
                    Role = toRole
                },
                Dependent = new ReferentialConstraintRoleElement()
                {
                    Role = fromRole
                }
            };

            CreateStorageAssociationReferentialConstraintProperties(assoc, association.Properties, association.IsParentManyToMany());

            _storageAssociations.Add(association.AssociationKeyName);
        }
Exemplo n.º 21
0
        private void AddNormalUser(UserAdministrator admin, IAssociation roleName)
        {
            if (roleName == null)
            {
                throw new Exception("Asocjacja nie moze byc null.");
            }

            AddPart(roleName, new NormalUser(admin));
        }
        private static bool IsAssociationMatch(IAssociation destination, IAssociation source)
        {
            if (destination.ForeignEntity.Name != source.ForeignEntity.Name)
            {
                return(false);
            }

            return(GetAssociationKey(destination) == GetAssociationKey(source));
        }
Exemplo n.º 23
0
        private void AddGPSModule(IAssociation roleNameGPSModule, string[] supportedSatellites)
        {
            if (roleNameGPSModule == null)
            {
                throw new Exception("Asocjacja nie moze byc null.");
            }

            AddPart(roleNameGPSModule, new GPSModule(supportedSatellites));
        }
Exemplo n.º 24
0
        public virtual NavigateResults Navigate(IActivity activity, IAssociation assoc, object executeResults, ProcessContext processContext)
        {
            //未指定Key,看是否已经完成
            if (string.IsNullOrEmpty(assoc.Key))
            {
                // 未完成,不能进行下一步
                if (activity.Status != ActivityStates.Done)
                {
                    return(null);
                }
            }
            // 看是状态是否满足
            else
            {
                if (activity.State <string>(assoc.Key) != assoc.Value)
                {
                    return(null);
                }
            }
            var nextDealerIdPath = assoc.NextDealerIdPath;

            if (string.IsNullOrEmpty(nextDealerIdPath))
            {
                nextDealerIdPath = processContext.Engine.DefaultNextDealerIdPath;
            }
            var nextDealerNamePath = assoc.NextDealerNamePath;

            if (string.IsNullOrEmpty(nextDealerNamePath))
            {
                nextDealerNamePath = processContext.Engine.DefaultNextDealerNamePath;
            }
            var nextDealerId = activity.State <string>(nextDealerIdPath);

            if (string.IsNullOrEmpty(nextDealerId))
            {
                throw new Exception(string.Format("活动对象{0}在执行导航{1}时,已经通过,但未能找到下一处理人", activity.Id, assoc.Name));
            }
            var nextDealer = new User(nextDealerId, activity.State <string>(nextDealerNamePath));

            object nextInputs;

            if (assoc.NextInputsMaps != null)
            {
                var jObj = new JObject();
                foreach (var pair in assoc.NextInputsMaps)
                {
                    var value = activity.State(pair.Key);
                    JSON.SetPathValue(jObj, pair.Value, value);
                }
                nextInputs = jObj;
            }
            else
            {
                nextInputs = executeResults;
            }
            return(new NavigateResults(nextDealer, nextInputs));
        }
Exemplo n.º 25
0
        private void AddServiceman(IAssociation roleName, string specialization)
        {
            if (roleName == null)
            {
                throw new Exception("Asocjacja nie moze byc null.");
            }

            AddPart(roleName, new EmployeeServiceman(BirthDate, specialization));
        }
Exemplo n.º 26
0
        private void AddStorekeeper(IAssociation roleName, bool forkliftLicense)
        {
            if (roleName == null)
            {
                throw new Exception("Asocjacja nie moze byc null.");
            }

            AddPart(roleName, new EmployeeStorekeeper(BirthDate, forkliftLicense));
        }
Exemplo n.º 27
0
        private void AddAdministrator(NormalUser user, IAssociation roleName)
        {
            if (roleName == null)
            {
                throw new Exception("Asocjacja nie moze byc null.");
            }

            AddPart(roleName, new UserAdministrator(user));
        }
 private static XElement ToXElement(this IAssociation association)
 {
     return(new XElement("Association",
                         new XAttribute("AssociationName", association.AssociationName),
                         new XAttribute("PropertyName", association.PropertyName),
                         new XAttribute("TableName", association.TableName),
                         new XAttribute("ColumnName", association.ColumnName),
                         new XAttribute("RelatedTableName", association.RelatedTableName),
                         new XAttribute("RelatedColumnName", association.RelatedColumnName)));
 }
Exemplo n.º 29
0
 internal Association(IAssociation association)
 {
     this.AssociationName   = association.AssociationName;
     this.PropertyName      = association.PropertyName;
     this.AssociationType   = association.AssociationType;
     this.TableName         = association.TableName;
     this.ColumnName        = association.ColumnName;
     this.RelatedTableName  = association.RelatedTableName;
     this.RelatedColumnName = association.RelatedColumnName;
 }
Exemplo n.º 30
0
        /// <summary>
        /// This is used to detect to see if the context data contains a class. It is used in the case where we want to see if a read-write class exists before a read only..
        /// </summary>
        /// <param name="association"></param>
        /// <param name="suffix"></param>
        /// <returns></returns>
        public bool BusinessObjectExists(IAssociation association, string suffix)
        {
            if (association.Properties.Count <= 0)
            {
                return(false);
            }

            string key = String.Format("{0}{1}", association.Entity.EntityKeyName, suffix);

            return(ContextData.Get(key) != null);
        }
        public static string BuildPropertyVariables(this IAssociation association)
        {
            string parameters = String.Empty;

            foreach (AssociationProperty property in association.Properties)
            {
                parameters += property.ForeignProperty.Name;
            }

            return(parameters);
        }
Exemplo n.º 32
0
        public ObjectPlusPlus[] GetLinks(IAssociation roleName)
        {
            Dictionary <object, ObjectPlusPlus> objectLinks;

            if (Links.ContainsKey(roleName) == false)
            {
                throw new Exception("Brak powiazan dla relacji: " + roleName);
            }
            objectLinks = Links[roleName];

            return(objectLinks.Values.ToArray());
        }
        public void ValidateAssociations(ValidationContext context, IAssociation assoc)
        {
            // All associations between classes must have a stereotype.

            IEnumerable<IStereotypeInstance> assocStereotypes = assoc.AppliedStereotypes;

            if (assocStereotypes.Count() == 0)
            {
                context.LogError(
                    string.Format("Association '{0}' has no stereotype for SQL generation", assoc.Name),
                    "004A", assoc);
            }
            else if (assocStereotypes.Count() > 1)
            {
                context.LogError(
                   string.Format("Association '{0}' has more than one stereotype for SQL generation", assoc.Name),
                   "004B", assoc);
            }
        }
Exemplo n.º 34
0
        public bool IsReadOnly(IAssociation association, string suffix)
        {
            if (association.Properties.Count <= 0)
                return false;

            string key = String.Format("{0}{1}", association.ForeignEntity.EntityKeyName, suffix);
            if (ContextData.Get(key) == null)
                return false;

            var value = ContextData[key];
            switch (value) {
                case Constants.ReadOnlyChild:
                case Constants.ReadOnlyRoot:
                case Constants.ReadOnlyChildList:
                case Constants.ReadOnlyList:
                    return true;
            }

            return false;
        }
Exemplo n.º 35
0
 private void DealWithReflexiveReferences(IProperty ae, IAssociation association)
 {
     if (IsReflexiveAssociation(association))
     {
         // UML tool arbitrarily picks an end as "outgoing" for reflexive associations
         // hence this workaround to pick the Navigable one
         if (IsNavigableAssoc(ae))
         {
             _mySql.AddReferenceProperty(ae);
             _py.AddReferenceProperty(ae);
         }
         else
         {
             _mySql.AddReferenceProperty(ae.Opposite);
             _py.AddReferenceProperty(ae.Opposite);
         }
     }
     else if (IsNavigableAssoc(ae))
     {
         _mySql.AddReferenceProperty(ae);
         _py.AddReferenceProperty(ae);
     }
 }
        public void ValidateFKNameLength(ValidationContext context, IAssociation assoc)
        {
            // All Associations of type "ForeignKey" must either have a name < 64 chars or derived name  < 64 chars.

            IEnumerable<IStereotypeInstance> assocFKColumnStereotypes = assoc.AppliedStereotypes.Where(s => s.Name == "ForeignKey");
            foreach (IStereotypeInstance fk in assocFKColumnStereotypes)
            {

                if (String.IsNullOrEmpty(assoc.Name))
                {
                    string me1 = assoc.MemberEnds.First().Type.Name;
                    string s = me1 + assoc.NavigableOwnedEnds.First().Name;
                    if (!IsValidIdentifierLength(s))
                    {
                        context.LogError(
                        string.Format("Association Name is missing and derived Name '{0}' is too long", s),
                        "008", assoc);
                    }
                }
                else if (!IsValidIdentifierLength(assoc.Name))
                {
                    context.LogError(
                        string.Format("Association Name '{0}' too long", assoc.Name),
                        "008", assoc);
                }

            }
        }
Exemplo n.º 37
0
 private static bool IsSopClassUniqueIdNotSupported(IAssociation association, string sopClassUniqueId, out PresentationContext pc)
 {
     return (pc = association.GetAcceptedPresContext(sopClassUniqueId, UIDs.ImplicitVRLittleEndian)) == null;
 }
Exemplo n.º 38
0
        private static string GetAssociationKey(IAssociation association)
        {
            IEnumerable<string> columns;
            string type;

            switch(association.AssociationType)
            {
                case AssociationType.ManyToOne:
                case AssociationType.ManyToZeroOrOne:
                    columns = association.Properties.Select(p => p.Property.GetSafeName());
                    type = "ManyTo";
                    break;

                case AssociationType.ManyToMany:
                case AssociationType.OneToMany:
                case AssociationType.ZeroOrOneToMany:
                    columns = association.Properties.Select(p => p.ForeignProperty.GetSafeName());
                    type = "ToMany";
                    break;

                default:
                    return String.Empty;
            }

            return columns.Aggregate(String.Empty, (current, column) => String.Concat(current, column, "|")) + type;
        }
Exemplo n.º 39
0
        private static void PrepAssociation(IAssociation assocication)
        {
            bool isNullable;

            switch (assocication.AssociationType)
            {
                case AssociationType.ManyToOne:
                case AssociationType.ManyToZeroOrOne:

                    isNullable = assocication.Properties.All(ap => ap.Property.IsNullable);
                    assocication.ExtendedProperties.Add(NotNull, !isNullable ? "true" : "false");

                    break;

                case AssociationType.OneToMany:
                case AssociationType.ZeroOrOneToMany:

                    isNullable = assocication.Properties.Any(ap => ap.Property.IsNullable);
                    assocication.ExtendedProperties.Add(Cascade, isNullable ? "all" : "all-delete-orphan");
                    assocication.ExtendedProperties.Add(Lazy, "true");

                    break;

                case AssociationType.ManyToMany:

                    assocication.ExtendedProperties.Add(Cascade, "all");
                    assocication.ExtendedProperties.Add(Lazy, "true");

                    break;
            }
        }
Exemplo n.º 40
0
 //private static bool IsDeleteOnNull(TableEntity entity)
 //{
 //   return (entity.ExtendedProperties.ContainsKey("CS_IsDeleteOnNull") && entity.ExtendedProperties["CS_IsDeleteOnNull"] != null &&
 //           entity.ExtendedProperties["CS_IsDeleteOnNull"] is bool && (bool)entity.ExtendedProperties["CS_IsDeleteOnNull"]);
 //}
 private static bool IsCascadeDelete(IAssociation association)
 {
     return (association.ExtendedProperties.ContainsKey("CS_CascadeDelete") && association.ExtendedProperties["CS_CascadeDelete"] != null &&
            association.ExtendedProperties["CS_CascadeDelete"] is bool && (bool)association.ExtendedProperties["CS_CascadeDelete"]);
 }
Exemplo n.º 41
0
        private static void ResolveAssociationValues(IAssociation association, out IEntity principalEntity, out IEntity dependentEntity, out bool isParentEntity)
        {
            bool isManyToManyEntity = association.IsParentManyToMany();
            principalEntity = !isManyToManyEntity ? association.Entity : association.ForeignEntity;
            dependentEntity = !isManyToManyEntity ? association.ForeignEntity : association.Entity;

            isParentEntity = association.IsParentEntity;
            if (association.AssociationType == AssociationType.ManyToMany)
                isParentEntity &= association.IsParentManyToMany();
        }
        private void CreateConceptualAssociation(IAssociation association)
        {
            IEntity principalEntity;
            IEntity dependentEntity;
            bool isParentEntity;
            string key;
            string toRole;
            string fromRole;
            ResolveConceptualAssociationValues(association, out principalEntity, out dependentEntity, out isParentEntity, out key, out toRole, out fromRole);

            if (_conceptualAssociations.Contains(key))
                return;
            //<Association Name="FK__Product__Categor__0CBAE877">
            //  <End Role="Category" Type="PetShopModel1.Category" Multiplicity="1" />
            //  <End Role="Product" Type="PetShopModel1.Product" Multiplicity="*" />
            //  <ReferentialConstraint>
            //      <Principal Role="Category">
            //          <PropertyRef Name="CategoryId" />
            //      </Principal>
            //      <Dependent Role="Product">
            //          <PropertyRef Name="CategoryId" />
            //      </Dependent>
            //  </ReferentialConstraint>
            //</Association>
            var assoc = ConceptualSchema.Associations.Where(a => a.Name.Equals(key)).FirstOrDefault();
            if (assoc != null) ConceptualSchema.Associations.Remove(assoc);
            assoc = new LinqToEdmx.Model.Conceptual.Association()
                            {
                                Name = key,
                                Ends = new List<AssociationEnd>()
                            };

            ConceptualSchema.Associations.Add(assoc);

            var principalEnd = CreateConceptualAssociationEnd(principalEntity, toRole, assoc, false);
            var dependentEnd = CreateConceptualAssociationEnd(dependentEntity, fromRole, assoc, false);

            UpdateConceptualAssociationEndMultiplicity(association, principalEnd, dependentEnd);

            #region ReferentialConstraint

            if (!association.IsParentManyToMany())
            {
                assoc.ReferentialConstraint = new Constraint
                {
                    Principal = new ReferentialConstraintRoleElement() { Role = toRole },
                    Dependent = new ReferentialConstraintRoleElement() { Role = fromRole }
                };

                CreateStorageAssociationReferentialConstraintProperties(assoc, association.Properties, principalEntity, dependentEntity, false);
            }

            #endregion

            _conceptualAssociations.Add(key);
        }
Exemplo n.º 43
0
 public virtual IActiveAssociation NewActiveAssociation(IAssociation association, DcmServiceRegistry services)
 {
     return new ActiveAssociation(association, services);
 }
        private void CreateConceptualNavigationProperty(EntityType entity, IAssociation association)
        {
            IEntity principalEntity;
            IEntity dependentEntity;
            bool isParentEntity;
            string key;
            string toRole;
            string fromRole;
            ResolveConceptualAssociationValues(association, out principalEntity, out dependentEntity, out isParentEntity, out key, out toRole, out fromRole);

            //11/4/2012 If an entity has an association to itself then we will modify the key if it's the child association.
            bool isSelfReferencingChild = !isParentEntity && principalEntity == dependentEntity;
            if (!isSelfReferencingChild && !association.IsParentManyToMany())
            {
                var temp = fromRole;
                fromRole = toRole;
                toRole = temp;
            }

            // 11/4/2012 Updated to check to see if a self referencing entity exists then we check the too and from roles. By checking only the to and from roles if it's a self referencing this allows custom names to be picked up.
            var navigationProperty = principalEntity == dependentEntity
                ? entity.NavigationProperties.FirstOrDefault(n => n.Relationship.Equals(String.Concat(ConceptualSchema.Namespace, ".", key)) && n.ToRole.Equals(toRole) && n.FromRole.Equals(fromRole))
                : entity.NavigationProperties.FirstOrDefault(n => n.Relationship.Equals(String.Concat(ConceptualSchema.Namespace, ".", key)));

            if (navigationProperty == null)
            {
                navigationProperty = new NavigationProperty() { Name = association.Name };
                entity.NavigationProperties.Add(navigationProperty);
            }

            if (String.IsNullOrEmpty(navigationProperty.Name) || association.Name.StartsWith(navigationProperty.Name))
                navigationProperty.Name = association.Name;

            navigationProperty.Relationship = String.Concat(ConceptualSchema.Namespace, ".", key);
            navigationProperty.FromRole = fromRole;
            navigationProperty.ToRole = toRole;
        }
        private void ResolveConceptualAssociationValues(IAssociation association, out IEntity principalEntity, out IEntity dependentEntity, out bool isParentEntity, out string keyName, out string toRole, out string fromRole)
        {
            bool isManyToManyEntity = association.IsParentManyToMany();
            principalEntity = !isManyToManyEntity ? association.Entity : association.ForeignEntity;
            dependentEntity = !isManyToManyEntity ? (association.AssociationType == AssociationType.ManyToMany) ? association.IntermediaryAssociation.Entity : association.ForeignEntity : association.IntermediaryAssociation.ForeignEntity;

            toRole = ResolveEntityMappedName(principalEntity.EntityKey(), principalEntity.Name);
            fromRole = ResolveEntityMappedName(dependentEntity.EntityKey(), dependentEntity.Name);
            if (toRole.Equals(fromRole)) fromRole += 1;

            keyName = ResolveAssociationMappedName(isManyToManyEntity ? association.Entity.EntityKeyName : association.AssociationKeyName);

            isParentEntity = association.IsParentEntity;
            if (association.AssociationType == AssociationType.ManyToMany)
                isParentEntity &= association.IsParentManyToMany();
        }
Exemplo n.º 46
0
        /// <summary>
        /// Merges and creates a list of all of the Properties. <ScalarProperty Name="LineNum" ColumnName="LineNum" />
        /// </summary>
        /// <param name="endProperty">The EndProperty.</param>
        /// <param name="association">The association.</param>
        private void MergeScalarProperties(EndProperty endProperty, IAssociation association)
        {
            var properties = new List<ScalarProperty>();

            foreach (var property in association.Properties)
            {
                var associationProperty = !association.Entity.Name.Equals(property.Property.Entity.Name) ? property.Property : property.ForeignProperty;
                var columnProperty = association.Entity.Name.Equals(property.Property.Entity.Name) ? property.Property : property.ForeignProperty;

                var prop = endProperty.ScalarProperties.Where(p => p.ColumnName.Equals(columnProperty.KeyName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (prop == null)
                {
                    // The property doesn't exist so lets create it.
                    prop = new ScalarProperty() { Name = associationProperty.Name };
                }
                else if (!associationProperty.Name.Equals(prop.Name, StringComparison.OrdinalIgnoreCase)) // Column matches that in the database.. If the names are different, it wins.
                {
                    // The propertyName has been updated.
                    // TODO: Is there a better way to find out if they renamed the Property?
                    //prop.Name = CodeSmith.SchemaHelper.Util.NamingConventions.PropertyName(prop.Name, false);
                }
                else
                {
                    // Update the propertyName so it is always current with SchemaHelper.
                    prop.Name = associationProperty.Name;
                }

                prop.ColumnName = columnProperty.KeyName;
                _mappingEntityPropertyNames[String.Format("{0}-{1}", associationProperty.Entity.Name, associationProperty.KeyName)] = prop.Name;

                properties.Add(prop);
            }

            endProperty.ScalarProperties = properties.Distinct().ToList();
        }
    public override Sage.Platform.Application.UI.ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
    {
        Sage.Platform.WebPortal.SmartParts.ToolsSmartPartInfo tinfo = new Sage.Platform.WebPortal.SmartParts.ToolsSmartPartInfo();
        if (this.BindingSource != null)
        {

            if (this.BindingSource.Current != null)
            {
                //tinfo.Description = this.BindingSource.Current.ToString();
                // tinfo.Title = "this.BindingSource.Current.ToString();

                _assoc = (IAssociation)this.BindingSource.Current;
                if (_assoc.Id != null)
                {
                    tinfo.Title = GetLocalResourceObject("DialogTitleEdit").ToString();
                    divFromIDDialog.Style.Add("display", "none");
                    divFromIDText.Style.Add("display", "blocked");
                    divToIDDialog.Style.Add("display", "none");
                    divToIDText.Style.Add("display", "blocked");
                    divBackRelationToAdd.Style.Add("display", "none");
                    divBackRelationToEdit.Style.Add("display", "blocked");
                    Mode.Value = "UPDATE";
                }
                else
                {
                    //new association
                    tinfo.Title = GetLocalResourceObject("DialogTitleAdd").ToString();

                    IContact contact = this.GetParentEntity() as IContact;
                    string Id = string.Empty;
                    if (contact != null)
                    {
                        Id = contact.Id.ToString();
                    }

                    divFromIDDialog.Style.Add("display", "none");
                    divFromIDText.Style.Add("display", "blocked");
                    divToIDDialog.Style.Add("display", "blocked");
                    divToIDText.Style.Add("display", "none");
                    divBackRelationToAdd.Style.Add("display", "blocked");
                    divBackRelationToEdit.Style.Add("display", "none");
                    luFromIDDialog.LookupResultValue = contact.Id;
                    luFromIDText.LookupResultValue = contact.Id;
                    luFowardRelatedTo.LookupResultValue = contact.Id;
                    hdtContactId.Value = Id;
                    Mode.Value = "ADD";
                }
            }
        }
        foreach (Control c in this.AssociationForm_LTools.Controls)
        {
            tinfo.LeftTools.Add(c);
        }
        foreach (Control c in this.AssociationForm_CTools.Controls)
        {
            tinfo.CenterTools.Add(c);
        }
        foreach (Control c in this.AssociationForm_RTools.Controls)
        {
            tinfo.RightTools.Add(c);
        }
        return tinfo;
    }
Exemplo n.º 48
0
 private bool IsReflexiveAssociation(IAssociation a)
 {
     return (a.MemberEnds.First().Type == a.MemberEnds.Last().Type);
 }
Exemplo n.º 49
0
        private static void ResolveStorageAssociationValues(IAssociation association, out IEntity principalEntity, out IEntity dependentEntity, out bool isParentEntity, out string keyName, out string toRole, out string fromRole)
        {
            bool isManyToManyEntity = association.IsParentManyToMany();
            principalEntity = !isManyToManyEntity ? association.Entity : association.ForeignEntity;
            dependentEntity = !isManyToManyEntity ? association.ForeignEntity : association.Entity;

            toRole = principalEntity.EntityKeyName;
            fromRole = dependentEntity.EntityKeyName;
            if (toRole.Equals(fromRole))
                fromRole += 1;

            keyName = isManyToManyEntity ? association.Entity.EntityKeyName : association.AssociationKeyName;

            isParentEntity = association.IsParentEntity;
            if (association.AssociationType == AssociationType.ManyToMany)
                isParentEntity &= association.IsParentManyToMany();
        }
Exemplo n.º 50
0
 private static void UpdateStorageAssociationEndMultiplicity(IAssociation association, AssociationEnd principalEnd, AssociationEnd dependentEnd)
 {
     switch (association.AssociationType) {
         case AssociationType.OneToMany:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
         case AssociationType.OneToOne:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.One;
             break;
         case AssociationType.OneToZeroOrOne:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.ZeroToOne;
             break;
         case AssociationType.ZeroOrOneToMany:
         case AssociationType.ManyToZeroOrOne:
             principalEnd.Multiplicity = MultiplicityConstants.ZeroToOne;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
         default:
             principalEnd.Multiplicity = MultiplicityConstants.One;
             dependentEnd.Multiplicity = MultiplicityConstants.Many;
             break;
     }
 }
Exemplo n.º 51
0
        private static bool ExcludeAssociation(IAssociation association)
        {
            foreach (var property in association.Properties)
            {
                var invalid = association.IsParentEntity && !association.IsParentManyToMany()
                    ? (property.Property.PropertyType & PropertyType.Key) != PropertyType.Key || (property.ForeignProperty.PropertyType & PropertyType.Foreign) != PropertyType.Foreign
                    : (property.ForeignProperty.PropertyType & PropertyType.Key) != PropertyType.Key || (property.Property.PropertyType & PropertyType.Foreign) != PropertyType.Foreign;

                if (invalid)
                    return true;
            }

            return false;
        }
Exemplo n.º 52
0
        private void CreateStorageAssociation(IAssociation association)
        {
            //<Association Name="FK__Product__Categor__0CBAE877">
            //  <End Role="Category" Type="PetShopModel1.Store.Category" Multiplicity="1" />
            //  <End Role="Product" Type="PetShopModel1.Store.Product" Multiplicity="*" />
            //  <ReferentialConstraint>
            //      <Principal Role="Category">
            //          <PropertyRef Name="CategoryId" />
            //      </Principal>
            //      <Dependent Role="Product">
            //          <PropertyRef Name="CategoryId" />
            //      </Dependent>
            //  </ReferentialConstraint>
            //</Association>
            IEntity principalEntity;
            IEntity dependentEntity;
            bool isParentEntity;
            string key;
            string toRole;
            string fromRole;
            ResolveStorageAssociationValues(association, out principalEntity, out dependentEntity, out isParentEntity, out key, out toRole, out fromRole);

            // The associations are stupid and if an end is added after the ReferentialConstraint, than the API doesn't detect it...
            var assoc = StorageSchema.Associations.Where(a => a.Name.Equals(association.AssociationKeyName)).FirstOrDefault();
            if (assoc != null)
                StorageSchema.Associations.Remove(assoc);
            assoc = new LinqToEdmx.Model.Storage.Association() {
                Name = association.AssociationKeyName,
                Ends = new List<AssociationEnd>()
            };

            StorageSchema.Associations.Add(assoc);

            var principalEnd = CreateStorageAssociationEnd(principalEntity, toRole, assoc, IsCascadeDelete(association));
            var dependentEnd = CreateStorageAssociationEnd(dependentEntity, fromRole, assoc, false);

            UpdateStorageAssociationEndMultiplicity(association, principalEnd, dependentEnd);

            assoc.ReferentialConstraint = new LinqToEdmx.Model.Storage.Constraint {
                Principal = new ReferentialConstraintRoleElement() {
                    Role = toRole
                },
                Dependent = new ReferentialConstraintRoleElement() {
                    Role = fromRole
                }
            };

            CreateStorageAssociationReferentialConstraintProperties(assoc, association.Properties, association.IsParentManyToMany());

            _storageAssociations.Add(association.AssociationKeyName);
        }
Exemplo n.º 53
0
        private static bool IsAssociationMatch(IAssociation destination, IAssociation source)
        {
            if (destination.ForeignEntity.Name != source.ForeignEntity.Name)
                return false;

            return GetAssociationKey(destination) == GetAssociationKey(source);
        }
Exemplo n.º 54
0
        private void CreateStorageAssociationSet(IAssociation association)
        {
            IEntity principalEntity;
            IEntity dependentEntity;
            bool isParentEntity;
            string key;
            string toRole;
            string fromRole;
            ResolveStorageAssociationValues(association, out principalEntity, out dependentEntity, out isParentEntity, out key, out toRole, out fromRole);
            //<AssociationSet Name="FK__Product__Categor__0CBAE877" Association="PetShopModel1.Store.FK__Product__Categor__0CBAE877">
            //    <End Role="Category" EntitySet="Category" />
            //    <End Role="Product" EntitySet="Product" />
            //</AssociationSet>
            var associationSet = StorageSchemaEntityContainer.AssociationSets.Where(e => e.Name.Equals(association.AssociationKeyName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            if (associationSet == null) {
                associationSet = new EntityContainer.AssociationSetLocalType {
                    Name = association.AssociationKeyName,
                    Ends = new List<EntityContainer.AssociationSetLocalType.EndLocalType>()
                };

                StorageSchemaEntityContainer.AssociationSets.Add(associationSet);
            } else {
                // Remove the AssociationEnd's that don't exist.
                var items = associationSet.Ends.Where(e => (!e.Role.Equals(toRole) || !e.Role.Equals(ResolveStorageEntityName(association.Entity.EntityKeyName))) &&
                                                           (!e.Role.Equals(fromRole) || !e.Role.Equals(ResolveStorageEntityName(association.ForeignEntity.EntityKeyName))));
                foreach (var associationEnd in items) {
                    associationSet.Ends.Remove(associationEnd);
                }
            }

            // Set or sync the default values.
            associationSet.Name = association.AssociationKeyName;
            associationSet.Association = String.Concat(StorageSchema.Namespace, ".", association.AssociationKeyName);

            var principalEnd = CreateStorageAssociationSetEnd(principalEntity, toRole, associationSet);
            var dependentEnd = CreateStorageAssociationSetEnd(dependentEntity, fromRole, associationSet, principalEnd);

            // Update the Ends (forces the ends to be grouped in the edmx file).
            associationSet.Ends = (from a in associationSet.Ends orderby a.Role select a).ToList();
        }
Exemplo n.º 55
0
 private IActiveAssociation CreateActiveAssociation(IAssociation association)
 {
     var activeAssociation = mockRepository.DynamicMock<IActiveAssociation>();
     Expect.Call(associationFactory.NewActiveAssociation(association, null)).Return(activeAssociation);
     Expect.Call(activeAssociation.Association).Return(association).Repeat.AtLeastOnce();
     return activeAssociation;
 }
Exemplo n.º 56
0
 private IActiveAssociation SetUpAssociation(IAssociation association)
 {
     //Expect.Call(associationFactory.NewRequestor(HOSTNAME, PORT)).Return(association);
     var mockActiveAssociation = mockRepository.DynamicMock<IActiveAssociation>();
     Expect.Call(associationFactory.NewActiveAssociation(association, null)).Return(mockActiveAssociation);
     Expect.Call(mockActiveAssociation.Association).Return(association);
     return mockActiveAssociation;
 }