Example #1
0
 private static void AddMetric(IDictionary<string, double> metrics)
 {
     if (metrics != null)
     {
         metrics.AsParallel().ForAll(m =>
            {
                NRClient.AddCustomParameter(m.Key, m.Value);
            }); 
     }
 }
Example #2
0
        public IObservable<WebResponse> HttpRequest(string url, IDictionary<string, string> postData, Encoding enc, IEnumerable<IPostFile> postFiles)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.Credentials = Credentials;
            req.CookieContainer = Cookie;

            if (postData != null)
            {
                return Observable.Using(() => new PostFileData(), _ => new[] { _ }.ToObservable()
                        .ObserveOn(Scheduler.TaskPool)
                        .Do(post => req.ContentType = "multipart/form-data; boundary=" + post.Boundary)
                        .Do(post => postData.AsParallel().ForAll(line => post.Add(line.Key, line.Value)) )
                        .Do(post => postFiles.AsParallel().ForAll(postFile => post.Add(postFile)))
                        .Select(post => post.ToBytes()))
                    .Do(data => { req.ContentLength = data.Length; })
                    .Do(data =>
                        req.GetRequestStreamAsObserverable()
                            .DisposeSubscribe(stream => stream.Write(data, 0, data.Length)
                        , ex => { throw ex; }))
                    .SelectMany(_ => req.GetResponseAsObserverable());
            }
            else
            {
                return req.GetResponseAsObserverable();
            }
        }
Example #3
0
 private static void AddProperties(IDictionary<string, string> properties)
 {
     if (properties != null)
     {
         properties.AsParallel().ForAll(p =>
         {
             NRClient.AddCustomParameter(p.Key, p.Value);
         }); 
     }
 }