示例#1
0
 /// <summary>
 ///     Creates the attribute.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <param name="rule">The rule.</param>
 /// <param name="type">The type.</param>
 /// <returns>Attribute instance.</returns>
 private static Attribute CreateAttribute(string name, bool required, string rule, AttributeType type = AttributeType.String)
 {
     var attribute = new Attribute
     {
         Name = name,
         AttributeType = type,
         Required = required,
         Rule = rule
     };
     return attribute;
 }
示例#2
0
 /// <summary>
 ///     Posts the attribute to service.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="attribute">The attribute.</param>
 private static HttpResponseMessage PostAttributeToService(string url, Attribute attribute)
 {
     if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
     {
         throw new ArgumentException("Invalid url");
     }
     using (var client = new HttpClient())
     {
         using (var request = new HttpRequestMessage(HttpMethod.Post, url))
         {
             request.Content = new StringContent(JsonConvert.SerializeObject(attribute), Encoding.UTF8, "application/json");
             var response = client.SendAsync(request, CancellationToken.None).Result;
             if (!response.IsSuccessStatusCode)
             {
                 throw new Exception(
                     "Ingesting Attribute to service returns insuccess response");
             }
             return response;
         }
     }
 }