Ejemplo n.º 1
0
        // Update an entity member (change name) with the member code.
        public static void UpdateEntityMember(string modelName, string versionName, string entityName, string memberCode, MemberType memberType
                                              , string updatedField, string updatedFieldValue, string changesetName = null)
        {
            // Create the request object for entity update.
            EntityMembersUpdateRequest updateRequest = new EntityMembersUpdateRequest();

            updateRequest.Members = new EntityMembers();
            // Set the modelName, the versionName, and the entityName.
            updateRequest.Members.ModelId = new Identifier {
                Name = modelName
            };
            updateRequest.Members.VersionId = new Identifier {
                Name = versionName
            };
            updateRequest.Members.EntityId = new Identifier {
                Name = entityName
            };
            updateRequest.Members.MemberType = MemberType.Leaf;
            updateRequest.Members.Members    = new Collection <Member> {
            };
            Member aMember = new Member();

            // Set the member code.
            aMember.MemberId = new MemberIdentifier()
            {
                Code = memberCode, MemberType = memberType
            };
            aMember.Attributes = new Collection <MasterDataServices.Attribute> {
            };
            // Set the new member name into the Attribute object.
            MasterDataServices.Attribute anAttribute = new MasterDataServices.Attribute();

            anAttribute.Identifier = new Identifier()
            {
                Name = updatedField
            };
            anAttribute.Type  = AttributeValueType.String;
            anAttribute.Value = updatedFieldValue;
            aMember.Attributes.Add(anAttribute);
            updateRequest.Members.Members.Add(aMember);

            if (!string.IsNullOrEmpty(changesetName))
            {
                updateRequest.Members.ChangesetId = new Identifier {
                    Name = changesetName
                };
            }

            // Update the entity member (change the name).
            EntityMembersUpdateResponse createResponse = ServiceReferencesSettings.clientProxy.EntityMembersUpdate(updateRequest);

            ServiceReferencesSettings.HandleOperationErrors(createResponse.OperationResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// update operation on givem member
        /// </summary>
        /// <param name="proxy"></param>
        static void UpdateMember(ServiceClient proxy)
        {
            var memberList = new Member[1];

            memberList[0] = new Member()
            {
                MemberId = new MemberIdentifier()
                {
                    Code = "-999", Name = "Do not use! For test only!"
                }
                //, ValidationStatus = ValidationStatus.ValidationSucceeded
            };

            memberList[0].MemberId.Name = "UPD";

            EntityMembers toInsert = new EntityMembers()
            {
                EntityId = new Identifier()
                {
                    Id = new Guid("1B5F25C0-C887-4B6D-A418-58766581066F")
                },
                ModelId = new Identifier()
                {
                    Id = new Guid("467F56C7-1531-4C1F-8074-D9B58B149B62")
                },
                VersionId = new Identifier()
                {
                    Name = "VERSION_1"
                },
                Members = memberList
            };

            var attr = new MasterDataServices.Attribute()
            {
                Identifier = new Identifier()
                {
                    Name = "Name"
                }, Value = "UPD"
            };

            memberList[0].Attributes    = new MasterDataServices.Attribute[1];
            memberList[0].Attributes[0] = attr;
            var vysl = proxy.EntityMembersUpdate(new International(), MemberTransactionBehavior.AllOrNothingByMember, toInsert, new Guid());
        }
Ejemplo n.º 3
0
        public static Collection <MasterDataServices.Attribute> GetEntityAttributes(string model, string entity)
        {
            Collection <MasterDataServices.MetadataAttribute> metadataAttributes;
            var attributes = new Collection <MasterDataServices.Attribute>();

            try
            {
                // Create the request object for getting attribute information.
                var getRequest = new MetadataGetRequest();
                getRequest.SearchCriteria = new MetadataSearchCriteria();
                getRequest.SearchCriteria.SearchOption = SearchOption.UserDefinedObjectsOnly;
                // Set model id, entity id, and attribute name.
                getRequest.SearchCriteria.Entities = new Collection <Identifier> {
                    new Identifier {
                        Name = entity
                    }
                };
                getRequest.SearchCriteria.Models = new Collection <Identifier> {
                    new Identifier {
                        Name = model
                    }
                };
                getRequest.ResultOptions            = new MetadataResultOptions();
                getRequest.ResultOptions.Attributes = ResultType.Details;

                // Get an attribute information.
                MetadataGetResponse getResponse = ServiceReferencesSettings.clientProxy.MetadataGet(getRequest);

                metadataAttributes = getResponse.Metadata.Attributes;

                ServiceReferencesSettings.HandleOperationErrors(getResponse.OperationResult);

                foreach (var item in metadataAttributes)
                {
                    var attribute = new MasterDataServices.Attribute();

                    if (item.AttributeType == AttributeType.Domain || item.AttributeType == AttributeType.File)
                    {
                        switch (item.AttributeType)
                        {
                        case AttributeType.Domain:
                            attribute.Type = AttributeValueType.Domain;
                            break;

                        case AttributeType.File:
                            attribute.Type = AttributeValueType.File;
                            break;
                        }
                    }
                    else if (item.AttributeType == AttributeType.FreeForm)
                    {
                        switch (item.DataType)
                        {
                        case AttributeDataType.DateTime:
                            attribute.Type = AttributeValueType.DateTime;
                            break;

                        case AttributeDataType.Number:
                            attribute.Type = AttributeValueType.Number;
                            break;

                        case AttributeDataType.Text:
                            attribute.Type = AttributeValueType.String;
                            break;
                        }
                    }
                    attributes.Add(attribute);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex);
            }

            //return AttributeIdentifier;

            return(attributes);
        }