Esempio n. 1
0
 public string Application_GetServiceResponse(string url, ClientResponsePOSTRequest req)
 {
     try
     {
         // Create a request using a URL that can receive a post.
         WebRequest request = WebRequest.Create(url);
         // Set the Method property of the request to POST.
         request.Method = "POST";
         // Create POST data and convert it to a byte array.
         string postData  = req.ToString();
         byte[] byteArray = Encoding.UTF8.GetBytes(postData);
         // Set the ContentType property of the WebRequest.
         request.ContentType = "application/x-www-form-urlencoded";
         // Set the ContentLength property of the WebRequest.
         request.ContentLength = byteArray.Length;
         // Get the request stream.
         Stream dataStream = request.GetRequestStream();
         // Write the data to the request stream.
         dataStream.Write(byteArray, 0, byteArray.Length);
         // Close the Stream object.
         dataStream.Close();
         // Get the response.
         WebResponse response = request.GetResponse();
         using (Stream a = response.GetResponseStream())
         {
             StreamReader b = new StreamReader(a, Encoding.UTF8);
             string       c = b.ReadToEnd();
             return(c);
         }
     }
     catch (Exception ex)
     {
     }
     return("Unable to get response");
 }
Esempio n. 2
0
        private void WriteToCell(Excel.Worksheet ws)
        {
            Excel.Worksheet activeWorksheet = ws;

            var servicePath = "http://plot.ly/clientresp";
            var username    = "******";
            var apiKey      = "4n5n0qb2hi";
            ClientResponsePOSTRequest reqArgs = new ClientResponsePOSTRequest()
            {
                un       = activeWorksheet.get_Range("L1").Value2,
                key      = activeWorksheet.get_Range("L2").Value2,
                origin   = activeWorksheet.get_Range("L3").Value2,
                platform = activeWorksheet.get_Range("L4").Value2,
                kwargs   = new Kwargs()
                {
                    filename = activeWorksheet.get_Range("L5").Value2,
                    fileopt  = activeWorksheet.get_Range("L6").Value2
                },
                args = "[[0, 1, 2], [3, 4, 5], [1, 2, 3], [6, 6, 5]]"
            };
            string result = new PlotlyService().Application_GetServiceResponse(activeWorksheet.get_Range("K1").Value2, reqArgs);

            Excel.Range firstRow = activeWorksheet.get_Range("A1");
            firstRow.Value2 = result;
        }
Esempio n. 3
0
        private void ButtonSubmit_Click(object sender, EventArgs e)
        {
            ClientResponsePOSTRequest reqArgs = new ClientResponsePOSTRequest()
            {
                un       = textBoxUsername.Text,
                key      = textBoxAPIKey.Text,
                origin   = textBoxOrigin.Text,
                platform = textBoxPlatform.Text,
                kwargs   = new Kwargs()
                {
                    filename = textBoxFilename.Text,
                    fileopt  = textBoxFileOption.Text
                },
                args = "[[0, 1, 2], [3, 4, 5], [1, 2, 3], [6, 6, 5]]"
            };

            string x = textBoxXColumn.Text;
            string y = textBoxYColumn.Text;

            Excel.Range   xCols = ws.get_Range(x + "1").EntireColumn;
            Excel.Range   yCols = ws.get_Range(y + "1").EntireColumn;
            List <string> xList = new List <string>();
            List <string> yList = new List <string>();

            if (xCols != null && yCols != null && xCols.Count > 0 && yCols.Count > 0)
            {
                foreach (Excel.Range c in xCols.Cells)
                {
                    if (c.Value2 == null || string.IsNullOrEmpty(c.Value2.ToString()))
                    {
                        break;
                    }
                    xList.Add(c.Value2.ToString());
                }
                foreach (Excel.Range c in yCols.Cells)
                {
                    if (c.Value2 == null || string.IsNullOrEmpty(c.Value2.ToString()))
                    {
                        break;
                    }
                    yList.Add(c.Value2.ToString());
                }

                List <string> coords = new List <string>();
                for (int i = 0; i < (xList.Count > yList.Count ? yList.Count : xList.Count); i++)
                {
                    coords.Add(string.Format("[{0},{1}]", xList[i], yList[i]));
                }
                reqArgs.args = string.Format("[{0}]", string.Join(",", coords));
                string result = new PlotlyService().Application_GetServiceResponse(textBoxServiceURL.Text, reqArgs);
                textBox10.Text = result;
            }
        }