Inheritance: IDisposable
        protected static void Establish_context()
        {
            sourcesystem = Script.SourceSystemData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(sourcesystem);
            client = new HttpClient();
        }
        protected static void Establish_context()
        {
            curve = CurveData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(curve);
            client = new HttpClient();
        }
 protected static void Establish_context()
 {
     entity = CurveData.CreateBasicEntity();
     var notAMapping = new Contracts.Curve();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
        protected static void Because_of()
        {
            client = new HttpClient(ServiceUrl["Counterparty"] +
                "crossmap?source-system=trayport&destination-system=endur&mapping-string=abc");

            response = client.Get();
        }
        /// <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 HttpClientWrapper(HttpClient httpClient, RequestHeaders requestHeaders = null)
        {
            _httpClient = httpClient;

            if (requestHeaders != null)
                _httpClient.DefaultHeaders = requestHeaders;
        }
        protected static void Establish_context()
        {
            broker = BrokerData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(broker);
            client = new HttpClient();
        }
        /// <summary>
        /// Example of calling the Security.svc/login method to log into ETO.
        /// </summary>
        /// <param name="siteId"></param>
        protected void Logon(string siteId)
        {
            string userName = Session["Username"].ToString();
            string password = Session["Password"].ToString();
            string enterprise = Session["EnterpriseGUID"].ToString();
            string baseurl = WebConfigurationManager.AppSettings["ETOSoftwareWS_BaseUrl"];

            try
            {
                HttpClient client = new HttpClient(baseurl);
                //below is incorrect
                string json = string.Format("{{\"security\":{{\"Email\":\"{0}\",\"Password\":\"{1}\"}}}}", userName, password);

                HttpContent content = HttpContent.Create(json,"application/json");
                HttpResponseMessage resp = client.Post("Security.svc/SSOAuthenticate/", content);
                resp.EnsureStatusIsSuccessful();

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SSOAuthenticateResponseObject));
                SSOAuthenticateResponseObject SSOAuthenticationResponse = serializer.ReadObject(resp.Content.ReadAsStream()) as SSOAuthenticateResponseObject;
                Session["AuthToken"] = SSOAuthenticationResponse.SSOAuthenticateResult.SSOAuthToken;
            }
            catch (Exception ex)
            {
                Response.Redirect("Default.aspx");
            }
        }
        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);
        }
Exemple #10
0
        public void Add(Nut nut)
        {
            Nut response = null;

            string uri = string.Format("{0}/{1}/{2}", Address.AbsoluteUri.ToLower(), Account.ToLower(), nut.Table.ToLower());

            var client = new HttpClient(uri);

            MemoryStream ms = new MemoryStream();

            DataContractSerializer s = new DataContractSerializer(typeof(Nut));
            s.WriteObject(ms, nut);

            ms.Position = 0;
            HttpResponseMessage r = client.Post(uri, HttpContent.Create(ms.ToArray(), "application/xml"));

            ms.Close();

            r.EnsureStatusIsSuccessful();

            if (r.StatusCode == System.Net.HttpStatusCode.OK)
            {
                nut.Uri = uri;

            }
        }
        /// <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 Establish_context()
 {
     entity = Script.SourceSystemData.CreateBasicEntity();
     var notAMapping = new EnergyTrading.Mdm.Contracts.SourceSystem();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
        public RESTService(TestConfiguration config)
        {
            _testConfig = config;

            ServiceURI = _testConfig.ServiceURI;
            //ServicePort = TestConfig.ServicePort;

            AuthRequired = _testConfig.AuthRequired;
            AuthType = (AuthSchema)_testConfig.AuthType;
            Username = _testConfig.Username;
            Password = _testConfig.Password;
            AuthToken = _testConfig.AuthToken;
            IsConfigured = true;
            //IsOnline = true;

            // Now that the service is configured, create an http client that can talk to it...
            _client = new HttpClient();
            
            // Is auth required?
            if (AuthRequired)
            {
                if (AuthType == AuthSchema.Basic)
                    _client.TransportSettings.Credentials = new NetworkCredential(Username, Password);
                else if (AuthType == AuthSchema.Token)
                    _client.DefaultHeaders.Authorization = new Credential(AuthToken);
            }
        }
 protected static void Establish_context()
 {
     entity = PartyRoleData.CreateBasicEntity();
     var notAMapping = new OpenNexus.MDM.Contracts.PartyRole();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
        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);
                            }
                }
            }
        }
        protected static void Establish_context()
        {
            legalentity = LegalEntityData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(legalentity);
            client = new HttpClient();
        }
 protected static void Establish_context()
 {
     entity = BrokerData.CreateBasicEntity();
     var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Broker();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
        protected static void Establish_context()
        {
            exchange = ExchangeData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(exchange);
            client = new HttpClient();
        }
        protected static void Establish_context()
        {
            counterparty = CounterpartyData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(counterparty);
            client = new HttpClient();
        }
        protected static void Establish_context()
        {
            partyrole = PartyRoleData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(partyrole);
            client = new HttpClient();
        }
        protected static void Establish_context()
        {
            person = Script.PersonData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(person);
            client = new HttpClient();
        }
        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();
        }
        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 Establish_context()
        {
            client = new HttpClient();
            entity = CurveData.CreateBasicEntity();

            content = HttpContentExtensions.CreateDataContract(new MDM.Contracts.Curve());
            startVersion = CurrentEntityVersion();
        }
 protected static void Establish_context()
 {
     entity = Script.PersonData.CreateBasicEntityWithOneMapping();
     client = new HttpClient();
     var notAMapping = new MDM.Person();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     startVersion = CurrentEntityVersion();
 }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = Script.PersonData.CreateBasicEntity();

            content = HttpContentExtensions.CreateDataContract(new EnergyTrading.MDM.Contracts.Sample.Person());
            startVersion = CurrentEntityVersion();
        }
Exemple #27
0
        public static string AddWithoutParameter()
        {
            using (HttpResponseMessage response = new HttpClient().Get(uri)){

                int res = response.Content.ReadAsDataContract<int>();
                return res.ToString();
            }
        }
Exemple #28
0
 static String GetLocations(HttpClient client)
 {
     String locations;
     HttpResponseMessage response = client.Get("Locations");
     response.EnsureStatusIsSuccessful();
     locations = response.Content.ReadAsString();
     return locations;
 }
        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 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>();
        }
Exemple #31
0
        public override void Run(TestContainer container)
        {
            try
            {
                var jsonResult = String.Empty;
                var target     = base.GetParameter("Target");
                var methodType = base.GetParameter(@"MethodType").ToUpper();
                var jsonHeader = base.GetParameter(@"Header");
                var jsonBody   = base.GetParameter(@"Body");



                using (Microsoft.Http.HttpClient client = new Microsoft.Http.HttpClient())
                {
                    var headers = JsonConvert.DeserializeObject <Dictionary <String, String> >(jsonHeader);
                    client.DefaultHeaders.Add("Content-Type", "application/json");
                    foreach (KeyValuePair <string, string> item in headers)
                    {
                        client.DefaultHeaders.Add(item.Key, item.Value);
                    }
                    var content = Microsoft.Http.HttpContent.Create(jsonBody.Replace(@"'", @""""));

                    HttpMethod          httpMethod      = (HttpMethod)Enum.Parse(typeof(HttpMethod), methodType);
                    HttpResponseMessage responseMessage = client.Send(httpMethod, new Uri(target), client.DefaultHeaders, content);
                    var stringContent = responseMessage.Content.ReadAsString();
                    var statusCode    = responseMessage.StatusCode;
                    this.PassTest = statusCode == System.Net.HttpStatusCode.OK ? true : false;
                    if (this.PassTest == false)
                    {
                        throw (new Exception(String.Format(@"uri:{0}, methodType:{1}, statusCode:{2}, response message:{3}.", target, methodType, statusCode, stringContent)));
                    }

                    if (string.IsNullOrEmpty(this.Output.Key) == false)
                    {
                        if (String.IsNullOrEmpty(stringContent))
                        {
                            this.Output = new KeyValuePair <String, Tuple <Type, String> >(this.Output.Key, new Tuple <Type, String>(typeof(String), String.Empty));
                        }
                        else
                        {
                            stringContent = stringContent.Trim();
                            if (stringContent.StartsWith("[") == false && stringContent.EndsWith("[") == false)
                            {
                                stringContent = "[" + stringContent + "]";
                                JsonConvert.DeserializeObject <List <Dictionary <String, String> > >(stringContent);
                            }
                            this.Output = new KeyValuePair <String, Tuple <Type, String> >(this.Output.Key, new Tuple <Type, String>(typeof(List <Dictionary <String, String> >), stringContent));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
        }