Пример #1
0
        // Get an attribute group information (ModelContextIdentifier for the attribute group) with specified attribute group name, model id, and entity id.
        private static ModelContextIdentifier GetAttributeGroup(Guid modelId, Guid entityId, string attributeGroupName)
        {
            ModelContextIdentifier AttributeGroupIdentifier = new ModelContextIdentifier();

            try
            {
                // Create the request object for getting attribute group information.
                MetadataGetRequest getRequest = new MetadataGetRequest();
                getRequest.SearchCriteria = new MetadataSearchCriteria();
                getRequest.SearchCriteria.SearchOption = SearchOption.UserDefinedObjectsOnly;
                // Set model id, entity id, and attribute group name.
                getRequest.SearchCriteria.Models = new System.Collections.ObjectModel.Collection <Identifier> {
                    new Identifier {
                        Id = modelId
                    }
                };
                getRequest.SearchCriteria.Entities = new System.Collections.ObjectModel.Collection <Identifier> {
                    new Identifier {
                        Id = entityId
                    }
                };
                getRequest.SearchCriteria.AttributeGroups = new System.Collections.ObjectModel.Collection <Identifier> {
                    new Identifier {
                        Name = attributeGroupName
                    }
                };
                getRequest.ResultOptions = new MetadataResultOptions();
                getRequest.ResultOptions.AttributeGroups = ResultType.Details;

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

                if (getResponse.Metadata.AttributeGroups.Count > 0)
                {
                    AttributeGroupIdentifier = getResponse.Metadata.AttributeGroups[0].Identifier;
                }

                HandleOperationErrors(getResponse.OperationResult);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex);
            }

            return(AttributeGroupIdentifier);
        }
Пример #2
0
        // Get an entity information (ModelContextIdentifier for the entity) with specified entity name and model id.
        private static ModelContextIdentifier GetEntity(Guid modelId, string entityName)
        {
            ModelContextIdentifier entityIdentifier = new ModelContextIdentifier();

            try
            {
                // Create the request object for getting entity information.
                MetadataGetRequest getRequest = new MetadataGetRequest();
                getRequest.SearchCriteria = new MetadataSearchCriteria();
                getRequest.SearchCriteria.SearchOption = SearchOption.UserDefinedObjectsOnly;
                // Set the entity name and model id
                getRequest.SearchCriteria.Entities = new System.Collections.ObjectModel.Collection<Identifier> { new Identifier { Name = entityName } };
                getRequest.SearchCriteria.Models = new System.Collections.ObjectModel.Collection<Identifier> { new Identifier { Id = modelId } };
                getRequest.ResultOptions = new MetadataResultOptions();
                getRequest.ResultOptions.Entities = ResultType.Details;
                // Get an entity information.
                MetadataGetResponse getResponse = clientProxy.MetadataGet(getRequest);

                if (getResponse.Metadata.Entities.Count > 0)
                {
                    entityIdentifier = getResponse.Metadata.Entities[0].Identifier;
                }

                HandleOperationErrors(getResponse.OperationResult);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex);
            }

            return entityIdentifier;
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                // Create a service proxy.
                clientProxy = GetClientProxy(mdsURL);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating a service proxy: {0}", ex);
                return;
            }

            // Create a model with a specified name.
            CreateModel("TestModel");

            // Get a model information with specified model and version names.
            // "VERSION_1" is a default version name for a new model.
            Identifier modelIdentifier = GetModel("TestModel", "VERSION_1");

            // Update the model name.
            UpdateModel(modelIdentifier.Id, "TestModelNew");

            // Create an entity with a specified name.
            CreateEntity(modelIdentifier.Id, "TestEntity");

            // Get an entity information with specified entity name and model id.
            ModelContextIdentifier entityIdentifier = GetEntity(modelIdentifier.Id, "TestEntity");

            // Update the entity name.
            UpdateEntity(modelIdentifier.Id, entityIdentifier.Id, "TestEntityNew");

            // Create an attribute with a specified name.
            CreateAttribute(modelIdentifier.Id, entityIdentifier.Id, "TestAttribute");

            // Get an attribute information with specified attribute name, model id, and entity id.
            ModelContextIdentifier attributeIdentifier = GetAttribute(modelIdentifier.Id, entityIdentifier.Id, "TestAttribute");

            // Update the attribute name.
            UpdateAttribute(modelIdentifier.Id, entityIdentifier.Id, attributeIdentifier.Id, "TestAttributeNew");

            // Create an attribute group with a specified name.
            CreateAttributeGroup(modelIdentifier.Id, entityIdentifier.Id, "TestAttributeGroup");

            // Get an attribute group information with specified attribute group name, model id, and entity id.
            ModelContextIdentifier attributeGroupIdentifier = GetAttributeGroup(modelIdentifier.Id, entityIdentifier.Id, "TestAttributeGroup");

            // Update the attribute group name and add an attribute to it.
            UpdateAttributeGroup(modelIdentifier.Id, entityIdentifier.Id, attributeGroupIdentifier.Id, "TestAttributeGroupNew", attributeIdentifier.Id);

            // Delete the attribute group with the specified attribute group id.
            DeleteAttributeGroup(attributeGroupIdentifier.Id);

            // Delete the attribute with the specified attribute id.
            DeleteAttribute(attributeIdentifier.Id);

            // Delete the entity with the specified entity id.
            DeleteEntity(entityIdentifier.Id);

            // Delete the model with the specified model id.
            DeleteModel(modelIdentifier.Id);
        }