예제 #1
0
        private static IEnumerable <MetricValue> InternalReadMetricData(Uri uri, X509Certificate2 certificate)
        {
            var request = WebRequest.Create(uri) as HttpWebRequest;

            try
            {
                // Add Microsoft Azure subscription management Certificate to the request
                if (request != null)
                {
                    request.ClientCertificates.Add(certificate);
                    request.Accept = JsonContentType;
                    //create the request headers and specify the method required for this type of operation
                    request.Headers.Add(RdfeHeader, RdfeHeaderValue);
                    request.ContentType = JsonContentType;
                    request.Method      = "GET";
                    request.KeepAlive   = true;
                    using (var response = request.GetResponse() as HttpWebResponse)
                    {
                        if (response != null &&
                            response.StatusCode == HttpStatusCode.OK)
                        {
                            using (var stream = response.GetResponseStream())
                            {
                                if (stream != null)
                                {
                                    string metric, entity;
                                    GetMetricAndEntityFromUri(uri, out metric, out entity);

                                    var array  = JsonSerializerHelper.Deserialize <MetricValue[]>(stream);
                                    var length = array != null ? array.Length : 0;
                                    Trace.WriteLine(string.Format(MetricDataSuccessfullyRetrieved,
                                                                  length,
                                                                  metric,
                                                                  WebUtility.UrlDecode(entity)));
                                    return(array);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(CreateExceptionMessage(uri, ex));
                throw;
            }
            return(null);
        }
예제 #2
0
 /// <summary>
 /// Reads the checkpoints for event hub partitions from a JSON file in the current directory.
 /// </summary>
 public static void ReadCheckpoints()
 {
     if (!File.Exists(filePath))
     {
         itemList = new List <EventProcessorCheckpointInfo>();
         return;
     }
     using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
     {
         itemList = JsonSerializerHelper.Deserialize <List <EventProcessorCheckpointInfo> >(stream) ?? new List <EventProcessorCheckpointInfo>();
     }
     if (itemList == null || itemList.Count == 0)
     {
         itemList = new List <EventProcessorCheckpointInfo>();
         return;
     }
     foreach (var item in itemList)
     {
         mapDictionary.Add(string.Format(KeyFormat, item.Namespace, item.EventHub), item);
     }
 }
예제 #3
0
        private async static Task <IEnumerable <MetricInfo> > InternalGetSupportedMetricsAsync(Uri uri, X509Certificate2 certificate)
        {
            var request = WebRequest.Create(uri) as HttpWebRequest;

            try
            {
                // Add Microsoft Azure subscription management Certificate to the request
                if (request != null)
                {
                    request.ClientCertificates.Add(certificate);
                    request.Accept = JsonContentType;
                    //create the request headers and specify the method required for this type of operation
                    request.Headers.Add(RdfeHeader, RdfeHeaderValue);
                    request.ContentType = JsonContentType;
                    request.Method      = "GET";
                    request.KeepAlive   = true;
                    using (var response = await request.GetResponseAsync() as HttpWebResponse)
                    {
                        if (response != null &&
                            response.StatusCode == HttpStatusCode.OK)
                        {
                            using (var stream = response.GetResponseStream())
                            {
                                if (stream != null)
                                {
                                    return(JsonSerializerHelper.Deserialize <MetricInfo[]>(stream));
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }
            return(null);
        }