/// <summary>
        /// Get the results for the process monitor
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="client"></param>
        public override void GetMetrics(string apiKey, HttpClient client)
        {
            base.GetMetrics(apiKey, client);

            using (HttpResponseMessage response = client.Get("api?action=topProcessByCPUUsage&limit=50&apikey=" + apiKey + "&output=xml&detailedResults=true"))
            {
                response.EnsureStatusIsSuccessful();

                String data = response.Content.ReadAsString();
                XDocument xml = XDocument.Parse(data);

                IEnumerable<XElement> allMetrics = null;
                foreach (MonitorDefinition sm in monitorsDefinitions)
                {
                    // Query the xml data to retrieve each test result matching the ID of the current monitor
                    allMetrics = from metricNode in xml.Descendants("test")
                                 where (string)metricNode.Element("id") == this.Id
                                 select metricNode;

                    // Enumerate the metrics and store them in their own Metric object
                    foreach (XElement xe in allMetrics)
                        foreach (string s in sm.Names)
                            if (xe.Element(s) != null)
                            {
                                Metric m = new Metric(this);
                                m.Name = s;
                                m.Result = xe.Element(s).Value;
                                m.Suffix = sm.Suffixes[sm.Names.IndexOf(s)];
                                this.AddMetric(m);
                            }
                }
            }
        }
        public override void GetMetrics(string apiKey, HttpClient client)
        {
            // Get the 'base' name of the monitor to make sure we requesting the correct monitor results. (drive_C becomes: drive)
            string baseMonitorName = Util.BaseMonitorName(this.Name, '_');

            // Post the requests
            using (HttpResponseMessage response = client.Get("api?action=top" + baseMonitorName + "&apikey=" + apiKey + "&output=xml&detailedResults=true"))
            {
                response.EnsureStatusIsSuccessful();

                String data = response.Content.ReadAsString();
                XDocument xml = XDocument.Parse(data);

                IEnumerable<XElement> allMetrics = null;
                foreach (MonitorDefinition sm in monitorsDefinitions)
                {
                    allMetrics = from metricNode in xml.Descendants("test")
                                 where (string)metricNode.Element("id") == this.Id
                                 select metricNode;

                    foreach (XElement xe in allMetrics)
                        foreach (string s in sm.Names)
                            if (xe.Element(s) != null)
                            {
                                Metric m = new Metric(this);
                                m.Name = s;
                                m.Result = xe.Element(s).Value;
                                m.Suffix = sm.Suffixes[sm.Names.IndexOf(s)];
                                this.AddMetric(m);
                            }
                }
            }
        }
        public void CreateRequestsFast() {
            

            bool stop = false;
            var sw = new Stopwatch();

            int count = 1;
            sw.Start();
            while (!stop) {
                try {
                    Uri url = new Uri("http://tmserver:8700/shopclient");
                    HttpClient hc = new HttpClient();
                    hc.TransportSettings.Credentials = new NetworkCredential("darrel", "olecom");
                    hc.TransportSettings.ConnectionTimeout = TimeSpan.FromMilliseconds(2500);
                    HttpResponseMessage resp = hc.Get(url);
                    string result = resp.Content.ReadAsString();
                }
                catch  {
                    stop = true;
                }
                count++;
                if (count == 100) stop = true;
            }

            sw.Stop();
            var speed = 100.00 / (sw.ElapsedMilliseconds/1000.00);
            Debug.WriteLine("That took " + speed);
        }
        /// <summary>
        /// Example of calling Security.svc/getsites to display a list of sites for the 
        /// specified enterprise GUID.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LoginUser_Authenticate(object sender, EventArgs e)
        {
            Credentials.Visible = false;
            SiteSelector.Visible = true;

            Session.Add("Password", PasswordBox.Text);
            Session.Add("Username", UserNameBox.Text);
            Session.Add("EnterpriseGUID", EnterpriseBox.Text);

            string baseurl = WebConfigurationManager.AppSettings["ETOSoftwareWS_BaseUrl"];

            using (HttpClient client = new HttpClient(baseurl))
            {
                HttpResponseMessage resp = client.Get("Security.svc/getsites/" + EnterpriseBox.Text);
                resp.EnsureStatusIsSuccessful();

                DataContractJsonSerializer siteSer = new DataContractJsonSerializer(typeof(Entry[]));
                Entry[] sites = (Entry[])siteSer.ReadObject(resp.Content.ReadAsStream());

                foreach (Entry site in sites)
                {
                    Label label = new Label();
                    label.Text = "<a href=\"Workbench.aspx?site=" + site.Key.ToString() + "\">" + site.Value + "</a></br>";
                    Panel1.Controls.Add(label);
                }
            }
        }
        protected static void Because_of()
        {
            client = new HttpClient(ServiceUrl["Counterparty"] +
                "crossmap?source-system=trayport&destination-system=endur&mapping-string=abc");

            response = client.Get();
        }
Exemple #6
0
 static String GetLocations(HttpClient client)
 {
     String locations;
     HttpResponseMessage response = client.Get("Locations");
     response.EnsureStatusIsSuccessful();
     locations = response.Content.ReadAsString();
     return locations;
 }
        protected static void Because_of()
        {
            client = new HttpClient(ServiceUrl["Exchange"] +
                    "map?source-system=Trayport&mapping-string=" + exchange.Mappings[0].MappingValue + "&as-of=" +
                    exchange.Validity.Start.ToString(DateFormatString));

            response = client.Get();
        }
        protected static void Because_of()
        {
            var entity = CurveData.CreateBasicEntityWithOneMapping();

            client = new HttpClient(ServiceUrl["Curve"] + string.Format("{0}/mapping/{1}", entity.Id, int.MaxValue));

            response = client.Get();
        }
Exemple #9
0
        /*
        static void UploadFile(string baseAddress)
        {
            string uploadUri = "UploadFile/" + "jsonData.zip";
            Console.WriteLine("Uplaoding location data");
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(baseAddress + uploadUri);
            req.ContentType = "text/plain";
            Stream reqStream = req.GetRequestStream();

            HttpContent content = HttpContentExtensions.CreateDataContract<string>(data);
            HttpResponseMessage response = client.Post(uploadUri, content);
            response.EnsureStatusIsSuccessful();
            return response.Content.ReadAsString();
        }*/
        static Location GetLocation(HttpClient client, int id)
        {
            // Getting the response as a string
            Console.WriteLine("Location: {0}", id);
            string getUri = "Locations/" + id.ToString();
            HttpResponseMessage response = client.Get(getUri);
            response.EnsureStatusIsSuccessful();
            return response.Content.ReadAsJsonDataContract<Location>();
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = BrokerData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["Broker"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>();
            content = HttpContentExtensions.CreateDataContract(BrokerData.MakeChangeToContract(updatedContract));
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = Script.SourceSystemData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["SourceSystem"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.SourceSystem>();
            content = HttpContentExtensions.CreateDataContract(Script.SourceSystemData.MakeChangeToContract(updatedContract));
        }
        protected static void Because_of()
        {
            entity = BrokerData.CreateBasicEntityWithOneMapping();
            mapping = entity.Mappings[0];
            client = new HttpClient(ServiceUrl["Broker"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id));

            response = client.Get();
            mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.MappingResponse>();
        }
        public string TestConnection()
        {
            HttpClient client = new HttpClient(URL);
            client.TransportSettings.Credentials = new NetworkCredential(APIToken, "");

            HttpResponseMessage msg = client.Get("account.xml");
            msg.EnsureStatusIsSuccessful();
            return msg.Content.ReadAsString();
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = PartyRoleData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["PartyRole"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract<OpenNexus.MDM.Contracts.PartyRole>();
            content = HttpContentExtensions.CreateDataContract(PartyRoleData.MakeChangeToContract(updatedContract));
        }
        protected static void Because_of()
        {
            client = new HttpClient(ServiceUrl["Location"] +
                "crossmap?source-system=" + trayport.Name + "&destination-system=" + endur.Name + "&mapping-string=" + trayportMapping.MappingValue);

            response = client.Get();

            mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.Fault>();
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = Script.PersonData.CreateBasicEntityWithOneMapping();
            var getResponse = client.Get(ServiceUrl["Person"] + entity.Id);
            person = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Person>();
            mappingId = person.Identifiers.Where(x => !x.IsMdmId).First();

            var mappingGetResponse = client.Get(ServiceUrl["Person"] +  person.NexusId() + "/mapping/" + mappingId.MappingId);
            var mapping_etag = mappingGetResponse.Headers.ETag;
            var mappingFromService = mappingGetResponse.Content.ReadAsDataContract<MappingResponse>();

            MdmId postMapping = mappingFromService.Mappings[0];
            newEndDate = mappingFromService.Mappings[0].EndDate.Value.AddDays(1);
            postMapping.EndDate = newEndDate;
            var content = HttpContentExtensions.CreateDataContract(postMapping);
            client.DefaultHeaders.Add("If-Match", mapping_etag != null ? mapping_etag.Tag : string.Empty);
            mappingUpdateResponse = client.Post(ServiceUrl["Person"] +  string.Format("{0}/Mapping/{1}", entity.Id, mappingFromService.Mappings[0].MappingId), content);
        }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Party"] + "list"))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedPartys = response.Content.ReadAsDataContract<PartyList>();
         }
     }
 }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["PartyRole"] +
         partyrole.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedPartyRole = response.Content.ReadAsDataContract<OpenNexus.MDM.Contracts.PartyRole>();
         }
     }
 }
        protected static void Because_of()
        {
            entity = BrokerData.CreateEntityWithTwoDetailsAndTwoMappings();

            client = new HttpClient(ServiceUrl["Broker"] +
                "crossmap?source-system=trayport&destination-system=endur&mapping-string=" + entity.Mappings[0].MappingValue
                + "&as-of=" + entity.Mappings[0].Validity.Start.ToString(DateFormatString));

            response = client.Get();
            mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.MappingResponse>();
        }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["SourceSystem"] +
         sourcesystem.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedSourceSystem = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.SourceSystem>();
         }
     }
 }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Exchange"] +
         exchange.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedExchange = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Exchange>();
         }
     }
 }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = Script.PartyData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["Party"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Party>();
            updatedContract.Details.Name = "Bob";
            updatedContract.Identifiers.Remove(updatedContract.Identifiers.Where(id => id.IsMdmId).First());
            content = HttpContentExtensions.CreateDataContract(updatedContract);
        }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Broker"] +
         broker.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedBroker = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>();
         }
     }
 }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Curve"] +
         curve.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedCurve = response.Content.ReadAsDataContract<Contracts.Curve>();
         }
     }
 }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Counterparty"] +
         counterparty.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedCounterparty = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Counterparty>();
         }
     }
 }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Location"] +
         location.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedLocation = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Location>();
         }
     }
 }
        static void Main(string[] args)
        {
            using(HttpClient restClient = new HttpClient())
            {
                HttpResponseMessage resp = restClient.Get("http://localhost:1234/CarPool");
                resp.EnsureStatusIsSuccessful();
                Console.WriteLine(resp.Headers.ToString());

                var result = resp.Content.ReadAsString();
                Console.WriteLine(result);

                string newCar = "<Car xmlns=\"http://schemas.datacontract.org/2004/07/Wrox\"><Make> Seat </Make> <Name> Leon </Name><Seats> 5 </Seats> <Type> Sport Car </Type> </Car> ";
                restClient.Put("http://localhost:1234/CarPool/Leon", "application/xml", HttpContent.Create(newCar));
                Console.WriteLine(resp.StatusCode);

                resp = restClient.Get("http://localhost:1234/CarPool");
                resp.EnsureStatusIsSuccessful();
                var result1 = resp.Content.ReadAsString();
                Console.WriteLine(result1);
            }
        }
 public Package GetPackage(string packageId, string packageVersion) {
     using (var client = new HttpClient(_serviceRoot.Value)) {
         string uri = _serviceUriBuilder.BuildServiceUri(ServiceConstants.PackageServiceName, packageId, packageVersion);
         using (HttpResponseMessage response = client.Get(uri)) {
             if (response.StatusCode != HttpStatusCode.OK) {
                 _orchardServices.Notifier.Error(T(response.ReadContentAsStringWithoutQuotes()));
                 return null;
             }
             return response.Content.ReadAsJsonDataContract<Package>();
         }
     }
 }
        /// <summary>Issues a Get request to the target server to retreive data.</summary>
        /// <param name="urlPath">The part of the path after the base Url (see the 'Url' property).</param>
        public HttpResult Get(string urlPath)
        {
            // Setup initial conditions.
            if (urlPath.IsNullOrEmpty(true)) return null;
            urlPath = FormatPath(urlPath);

            // Pass GET call to the target server.
            using (var client = new HttpClient(GetBaseUrl()))
            {
                using (var response = client.Get(urlPath))
                {
                    return ProcessResponse(response);
                }
            }
        }
        // private List<Agent> agents;
        public InternalAgent()
        {
            client = new HttpClient("http://www.monitis.com/");
            using (HttpResponseMessage response = client.Get("api?action=agents&apikey=" + apiKey + "&output=xml"))
            {
                response.EnsureStatusIsSuccessful();

                agents root = response.Content.ReadAsDataContract<agents>();

                foreach (agent ag in root.agentList)
                {
                    Console.WriteLine(ag.Id);
                    Console.WriteLine(ag.Key);
                }

            }
        }