internal async Task <TResult> PostRequestAsync <TResult>(string requestUri, string content)
 {
     using (var httpClient = HttpClientHelpers.CreateHttpClient(Token))
         using (var httpContent = new StringContent(content))
             using (var response = await httpClient.PostAsync(requestUri, httpContent))
                 using (var streamReader = new StreamReader(await response.Content.ReadAsStreamAsync()))
                     return(CheckResponse <TResult>(response, streamReader));
 }
 internal async Task PatchRequestAsync(string requestUri, string content)
 {
     using (var httpClient = HttpClientHelpers.CreateHttpClient(Token))
         using (var httpContent = new StringContent(content))
             using (var message = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri))
             {
                 message.Content = httpContent;
                 using (var response = await httpClient.SendAsync(message))
                     using (var streamReader = new StreamReader(await response.Content.ReadAsStreamAsync()))
                         CheckResponse <object>(response, streamReader);
             }
 }
Exemple #3
0
        private Entity ProcessUriLocation(string uri)
        {
            using (HttpClient client = HttpClientHelpers.CreateHttpClient(_token))
            {
                try
                {
                    var req = client.GetAsync(uri).Result.Content.ReadAsStringAsync().Result;

                    return(ProcessData(req));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Uri: '{0}', Error: '{1}'", uri, e.Message);
                }
            }

            return(null);
        }
Exemple #4
0
        public Dictionary <string, string> GetBaseUris(string baseAddress, string method)
        {
            Stack <KeyValuePair <string, string> > UrisToCheck = new Stack <KeyValuePair <string, string> >();

            Dictionary <string, string> visited = new Dictionary <string, string>();

            UrisToCheck.Push(new KeyValuePair <string, string>("", method));

            using (HttpClient client = HttpClientHelpers.CreateHttpClient(_token))
            {
                while (UrisToCheck.Count > 0)
                {
                    var curr = UrisToCheck.Pop();

                    // We are going to skip all of the uris which don't have a parameter (ie. :albumid)
                    if (curr.Value.IndexOf(':', 6) > 0)
                    {
                        visited.Add(curr.Key, curr.Value);
                    }

                    string uri = baseAddress + curr.Value;
                    ConsolePrinter.Write(ConsoleColor.DarkGreen, "Found: " + uri);
                    var result = client.GetAsync(uri).Result.Content.ReadAsStringAsync().Result;

                    var discUris = DiscoverUris(result);

                    if (discUris == null)
                    {
                        continue;
                    }

                    foreach (var item in discUris)
                    {
                        UrisToCheck.Push(item);
                    }
                }
            }

            return(visited);
        }