Exemplo n.º 1
0
        /// <summary>
        /// Creates a document for the specified file id.
        ///
        /// Searches for the import template contract with the specified import
        /// template id and assigns the template to the document contract. It also
        /// takes over the protection domain and the info store from the import
        /// template and assigns it to the document contract. It reads out the
        /// properties passed in the hash map and sets the properties' keys and
        /// values for the document contract. Furthermore, it sets the name of
        /// the document. Calls the createDocument method on an instance of the
        /// InfoShareService class and passes the connection id, the document
        /// contract, and the file id as arguments. Returns the document contract,
        /// if the contract is successfully created.
        ///
        /// Before creating a document you must call either the uploadFileBytes or
        /// uploadFileBytesInChunks method on an instance of the File class. These
        /// methods return the file id you need to create a document.
        ///
        /// </summary>
        /// <param name="documentClient">the document client of the info share WCF service</param>
        /// <param name="commonClient">the common client of the info share WCF service</param>
        /// <param name="connectionID">the connection id</param>
        /// <param name="fileID">the file name</param>
        /// <param name="documentName">the document name</param>
        /// <param name="importTemplateID">the import template id</param>
        /// <param name="schemaCulture">the schema culture</param>
        /// <param name="dictionaryProperties">the dictionary that contains the properties as key/value pairs</param>
        /// <returns>the document contract</returns>
        public DocumentContract CreateDocument(CommonService commonService, string connectionID, string fileID,
                                               string documentName, string importTemplateID, string schemaCulture, Dictionary <string, string[]> dictionaryProperties)
        {
            DocumentContract documentContract = null;

            // Gets the import template contract for the specified import template id
            ImportTemplateContract importTemplateContract = commonService.GetImportTemplateContract(importTemplateID);

            string propertyPageTemplateID = importTemplateContract.PropertyPageTemplateId;
            // Gets the property page template contract assigned to the import template contract
            PropertyPageTemplateContract propertyPageTemplateContract = commonService.GetPropertyPageTemplateContract(propertyPageTemplateID);

            if (propertyPageTemplateContract != null)
            {
                // Gets an array of all property template contracts assigned to the property page template
                PropertyTemplateContract[] arrayOfPropertyTemplateContract = propertyPageTemplateContract.PropertyTemplates;

                // Array of property contracts to be set on the document contract further down (see A)
                IList <PropertyContract> listOfPropertyContract = new List <PropertyContract>();

                foreach (PropertyTemplateContract template in arrayOfPropertyTemplateContract)
                {
                    string propertyTypeID = template.PropertyTypeId;
                    PropertyTypeContract propertyTypeContract = commonService.GetPropertyTypeContract(propertyTypeID);

                    string propertyName = Utility.GetValue(propertyTypeContract.Name, schemaCulture);
                    if (!String.IsNullOrEmpty(propertyName))
                    {
                        string[] values;
                        dictionaryProperties.TryGetValue(propertyName, out values); // Gets value for key from dictionary

                        PropertyContract propertyContract = new PropertyContract
                        {
                            PropertyTypeId = propertyTypeID,
                            Values         = values
                        };

                        listOfPropertyContract.Add(propertyContract); // Adds property contract
                    }
                }

                // Sets mandatory fields
                documentContract = new DocumentContract
                {
                    ImportTemplateId   = importTemplateID,
                    ProtectionDomainId = importTemplateContract.ProtectionDomainId,
                    InfoStoreId        = importTemplateContract.InfoStoreId,
                    Properties         = listOfPropertyContract.ToArray(), // Sets all property contracts (A)
                    Name = documentName
                };

                //documentContract = this.DocumentClient.CreateDocument(connectionID, documentContract, fileID, options: null);
            }

            return(documentContract);
        }
Exemplo n.º 2
0
 static void ValidateProperty(
     PropertyContract contract,
     ApiManagementTestBase testBase,
     string propertyId,
     string propertyDisplayName,
     string propertyValue,
     bool isSecret,
     List <string> tags = null)
 {
     Assert.NotNull(contract);
     Assert.Equal(propertyDisplayName, contract.DisplayName);
     Assert.Equal(propertyValue, contract.Value);
     Assert.Equal(isSecret, contract.Secret);
     Assert.Equal(propertyId, contract.Name);
     if (tags != null)
     {
         Assert.NotNull(contract.Tags);
         Assert.Equal(tags.Count, contract.Tags.Count);
     }
 }
Exemplo n.º 3
0
 public IContractResolver Clone()
 {
     return(new ContractResolver(PropertyContract.Clone(), ObjectContract.Clone()));
 }
Exemplo n.º 4
0
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var parentProperty = base.CreateProperty(member, memberSerialization);

            return(PropertyContract.CreateProperty(parentProperty, member, memberSerialization));
        }
Exemplo n.º 5
0
        public async Task CreateListUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                string propertyId       = TestUtilities.GenerateName("newproperty");
                string secretPropertyId = TestUtilities.GenerateName("secretproperty");

                try
                {
                    string propertyDisplayName = TestUtilities.GenerateName("propertydisplay");
                    string propertyValue       = TestUtilities.GenerateName("propertyValue");
                    var    createParameters    = new PropertyContract(propertyDisplayName, propertyValue);

                    // create a property
                    var propertyResponse = testBase.client.Property.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        propertyId,
                        createParameters);

                    ValidateProperty(propertyResponse, testBase, propertyId, propertyDisplayName, propertyValue, false);

                    // get the property
                    var getResponse = testBase.client.Property.Get(
                        testBase.rgName,
                        testBase.serviceName,
                        propertyId);

                    ValidateProperty(propertyResponse, testBase, propertyId, propertyDisplayName, propertyValue, false);

                    // create  secret property
                    string        secretPropertyDisplayName = TestUtilities.GenerateName("secretPropertydisplay");
                    string        secretPropertyValue       = TestUtilities.GenerateName("secretPropertyValue");
                    List <string> tags = new List <string> {
                        "secret"
                    };
                    var secretCreateParameters = new PropertyContract(secretPropertyDisplayName, secretPropertyValue)
                    {
                        Secret = true,
                        Tags   = tags
                    };

                    var secretPropertyResponse = testBase.client.Property.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        secretPropertyId,
                        secretCreateParameters);

                    ValidateProperty(secretPropertyResponse, testBase, secretPropertyId, secretPropertyDisplayName, secretPropertyValue, true);

                    // list the properties
                    var listResponse = testBase.client.Property.ListByService(testBase.rgName, testBase.serviceName, null);
                    Assert.NotNull(listResponse);
                    Assert.Equal(2, listResponse.Count());

                    // delete a property
                    testBase.client.Property.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        propertyId,
                        "*");

                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Property.Get(testBase.rgName, testBase.serviceName, propertyId));

                    // get the property etag
                    var propertyTag = await testBase.client.Property.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        secretPropertyId);

                    Assert.NotNull(propertyTag);
                    Assert.NotNull(propertyTag.ETag);

                    // patch the secret property
                    var updateProperty = new PropertyUpdateParameters()
                    {
                        Secret = false
                    };
                    testBase.client.Property.Update(
                        testBase.rgName,
                        testBase.serviceName,
                        secretPropertyId,
                        updateProperty,
                        propertyTag.ETag);

                    // check it is patched
                    var secretResponse = await testBase.client.Property.GetAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        secretPropertyId);

                    ValidateProperty(
                        secretResponse,
                        testBase,
                        secretPropertyId,
                        secretPropertyDisplayName,
                        secretPropertyValue,
                        false);

                    // delete this property
                    testBase.client.Property.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        secretPropertyId,
                        "*");

                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Property.Get(testBase.rgName, testBase.serviceName, secretPropertyId));
                }
                finally
                {
                    testBase.client.Property.Delete(testBase.rgName, testBase.serviceName, propertyId, "*");
                    testBase.client.Property.Delete(testBase.rgName, testBase.serviceName, secretPropertyId, "*");
                }
            }
        }
 /// <summary>
 /// Creates or updates a property.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='propId'>
 /// Identifier of the property.
 /// </param>
 /// <param name='parameters'>
 /// Create parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. Not required when creating an entity, but required when
 /// updating an entity.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PropertyContract> CreateOrUpdateAsync(this IPropertyOperations operations, string resourceGroupName, string serviceName, string propId, PropertyContract parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, propId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates a property.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='propId'>
 /// Identifier of the property.
 /// </param>
 /// <param name='parameters'>
 /// Create parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. Not required when creating an entity, but required when
 /// updating an entity.
 /// </param>
 public static PropertyContract CreateOrUpdate(this IPropertyOperations operations, string resourceGroupName, string serviceName, string propId, PropertyContract parameters, string ifMatch = default(string))
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, propId, parameters, ifMatch).GetAwaiter().GetResult());
 }
Exemplo n.º 8
0
 public void MergeMarkerPropertiesToDocument(DocumentContract doc)
 {
     //Merge new properties to current document properties.
     foreach (MarkerProperty mProp in markerProperties)
     {
         var prop = doc.Properties.Where(x => x.PropertyTypeId == mProp.propertyTypeID).FirstOrDefault();
         if (mProp.updateAction == MarkerProperty.UpdateAction.ADD)
         {
             //If prop exists. Add at the end.
             if (prop != null)
             {
                 List <string> vals = prop.Values.ToList();
                 vals.AddRange(mProp.values);
                 prop.Values = vals.ToArray();
             }
             //Create new
             else
             {
                 PropertyContract newProp = new PropertyContract()
                 {
                     PropertyTypeId = mProp.propertyTypeID,
                     Values         = mProp.values
                 };
                 var props = this.document.Properties.ToList();
                 props.Add(newProp);
                 this.document.Properties = props.ToArray();
             }
         }
         if (mProp.updateAction == MarkerProperty.UpdateAction.UPDATE)
         {
             //If prop exists. Replace values.
             if (prop != null)
             {
                 prop.Values = mProp.values.ToArray();
             }
             //Create new
             else
             {
                 PropertyContract newProp = new PropertyContract()
                 {
                     PropertyTypeId = mProp.propertyTypeID,
                     Values         = mProp.values
                 };
                 var props = this.document.Properties.ToList();
                 props.Add(newProp);
                 this.document.Properties = props.ToArray();
             }
         }
         if (mProp.updateAction == MarkerProperty.UpdateAction.DELETE)
         {
             //Remove property if it exists.
             if (prop != null)
             {
                 var props = this.document.Properties.ToList();
                 props.Remove(prop);
                 this.document.Properties = props.ToArray();
             }
         }
         if (mProp.updateAction == MarkerProperty.UpdateAction.NONE)
         {
             //Do Nothing
         }
     }
 }