Exemplo n.º 1
0
        public void StartCompile(string platform, string program = null, string repo = null, bool clean = false)
        {
            int retryCount = 5;

            while (true)
            {
                try
                {
                    WebRequest request = WebRequest.Create("https://os.mbed.com/api/v2/tasks/compiler/start/");
                    request.Headers["Authorization"] = "Basic " + authInfo;
                    request.Method      = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    string requestPayload = string.Format("platform={0}&clean={1}", platform, clean ? "True" : "False");
                    if (!string.IsNullOrEmpty(program))
                    {
                        requestPayload += string.Format("&program={0}", program);
                    }
                    if (!string.IsNullOrEmpty(repo))
                    {
                        requestPayload += string.Format("&repo={0}", repo);
                    }
                    byte[] encodedPayload = Encoding.UTF8.GetBytes(requestPayload);
                    request.GetRequestStream().Write(encodedPayload, 0, Encoding.UTF8.GetBytes(requestPayload).Length);
                    WebResponse          response        = request.GetResponse();
                    CompileStartResponse compileResponse = new JavaScriptSerializer().Deserialize <CompileStartResponse>(new StreamReader(response.GetResponseStream()).ReadToEnd());
                    taskId       = compileResponse.result.data.task_id;
                    lastResponse = compileResponse;

                    break;
                }
                catch (WebException webException)
                {
                    retryCount--;
                    System.Console.WriteLine("Error sending request :{0}, retries left: {1}", webException.Message, retryCount);

                    if (retryCount == 0)
                    {
                        throw webException;
                    }
                }
            }
        }
        public void StartCompile(string platform, string program = null, string repo = null, bool clean = false)
        {
            int retryCount = 5;
            while (true)
            {
                try
                {
                    WebRequest request = WebRequest.Create("https://developer.mbed.org/api/v2/tasks/compiler/start/");
                    request.Headers["Authorization"] = "Basic " + authInfo;
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    string requestPayload = string.Format("platform={0}&clean={1}", platform, clean ? "True" : "False");
                    if (!string.IsNullOrEmpty(program))
                    {
                        requestPayload += string.Format("&program={0}", program);
                    }
                    if (!string.IsNullOrEmpty(repo))
                    {
                        requestPayload += string.Format("&repo={0}", repo);
                    }
                    byte[] encodedPayload = Encoding.UTF8.GetBytes(requestPayload);
                    request.GetRequestStream().Write(encodedPayload, 0, Encoding.UTF8.GetBytes(requestPayload).Length);
                    WebResponse response = request.GetResponse();
                    CompileStartResponse compileResponse = new JavaScriptSerializer().Deserialize<CompileStartResponse>(new StreamReader(response.GetResponseStream()).ReadToEnd());
                    taskId = compileResponse.result.data.task_id;
                    lastResponse = compileResponse;

                    break;
                }
                catch (WebException webException)
                {
                    retryCount--;
                    System.Console.WriteLine("Error sending request :{0}, retries left: {1}", webException.Message, retryCount);

                    if (retryCount == 0)
                    {
                        throw webException;
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void StartCompile(string platform, string program = null, string repo = null, bool clean = false)
 {
     WebRequest request = WebRequest.Create("https://developer.mbed.org/api/v2/tasks/compiler/start/");
     request.Headers["Authorization"] = "Basic " + authInfo;
     request.Method = "POST";
     request.ContentType = "application/x-www-form-urlencoded";
     string requestPayload = string.Format("platform={0}&clean={1}", platform, clean ? "True" : "False");
     if (!string.IsNullOrEmpty(program))
     {
         requestPayload += string.Format("&program={0}", program);
     }
     if (!string.IsNullOrEmpty(repo))
     {
         requestPayload += string.Format("&repo={0}", repo);
     }
     byte[] encodedPayload = Encoding.UTF8.GetBytes(requestPayload);
     request.GetRequestStream().Write(encodedPayload, 0, Encoding.UTF8.GetBytes(requestPayload).Length);
     WebResponse response = request.GetResponse();
     CompileStartResponse compileResponse = new JavaScriptSerializer().Deserialize<CompileStartResponse>(new StreamReader(response.GetResponseStream()).ReadToEnd());
     taskId = compileResponse.result.data.task_id;
     lastResponse = compileResponse;
 }
Exemplo n.º 4
0
        public bool PollStatus(ICollection<string> messages, out bool failed)
        {
            string requestURL = string.Format("https://developer.mbed.org/api/v2/tasks/compiler/output/{0}", HttpUtility.UrlEncode(taskId));
            WebRequest request = WebRequest.Create(requestURL);
            request.Headers["Authorization"] = "Basic " + authInfo;
            request.Method = "GET";
            
            WebResponse response = request.GetResponse();
            string jsonResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
            
            CompileStartResponse compileResponse = new JavaScriptSerializer().Deserialize<CompileStartResponse>(jsonResponse);
            lastResponse = compileResponse;

            foreach (CompileMessage msg in compileResponse.result.data.new_messages)
            {
                if (msg.type == "cc")
                {
                    messages.Add(string.Format("{0}: {1}: {2}: {3}", msg.severity, msg.file, msg.line, msg.message));
                    messages.Add(string.Format("{0}", msg.text));
                }
                else if (msg.type == "progress")
                {
                    messages.Add(string.Format("{0}: {1} ({2:F} %)", msg.action, msg.file, msg.percent));
                }
                else if (msg.type ==  "tool_error")
                {
                    messages.Add(string.Format("{0}: {1}", msg.type, msg.message));
                }
            }
            
            failed = !compileResponse.result.data.compilation_success;
            if (failed && compileResponse.result.data.task_complete)
            {
                messages.Add(string.Format("Raw response: {0}", jsonResponse));
            }
            return compileResponse.result.data.task_complete;
        }
        public bool PollStatus(ICollection<string> messages, out bool failed)
        {
            string requestURL = string.Format("https://developer.mbed.org/api/v2/tasks/compiler/output/{0}", HttpUtility.UrlEncode(taskId));
            bool complete = false;
            failed = true;
            CompileStartResponse compileResponse;

            int retryCount = 5;
            while (true)
            {
                try
                {
                    WebRequest request = WebRequest.Create(requestURL);
                    request.Headers["Authorization"] = "Basic " + authInfo;
                    request.Method = "GET";

                    // 30s should be enough
                    request.Timeout = 30000;
                    WebResponse response = request.GetResponse();
                    string jsonResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();

                    compileResponse = new JavaScriptSerializer().Deserialize<CompileStartResponse>(jsonResponse);
                    lastResponse = compileResponse;

                    foreach (CompileMessage msg in compileResponse.result.data.new_messages)
                    {
                        if (msg.type == "cc")
                        {
                            messages.Add(string.Format("{0}: {1}: {2}: {3}", msg.severity, msg.file, msg.line, msg.message));
                            messages.Add(string.Format("{0}", msg.text));
                        }
                        else if (msg.type == "progress")
                        {
                            messages.Add(string.Format("{0}: {1} ({2:F} %)", msg.action, msg.file, msg.percent));
                        }
                        else if (msg.type == "tool_error")
                        {
                            messages.Add(string.Format("{0}: {1}", msg.type, msg.message));
                        }
                    }

                    failed = !compileResponse.result.data.compilation_success;
                    if (failed && compileResponse.result.data.task_complete)
                    {
                        messages.Add(string.Format("Raw response: {0}", jsonResponse));
                    }

                    complete = compileResponse.result.data.task_complete;

                    break;
                }
                catch (WebException webException)
                {
                    retryCount--;
                    System.Console.WriteLine("Error sending request :{0}, retries left: {1}", webException.Message, retryCount);

                    if (retryCount == 0)
                    {
                        throw webException;
                    }
                }
            }

            if (retryCount < 0)
            {
                complete = true;
            }

            return complete;
        }
Exemplo n.º 6
0
        public bool PollStatus(ICollection <string> messages, out bool failed)
        {
            string requestURL = string.Format("https://os.mbed.com/api/v2/tasks/compiler/output/{0}", HttpUtility.UrlEncode(taskId));
            bool   complete   = false;

            failed = true;
            CompileStartResponse compileResponse;

            int retryCount = 5;

            while (true)
            {
                try
                {
                    WebRequest request = WebRequest.Create(requestURL);
                    request.Headers["Authorization"] = "Basic " + authInfo;
                    request.Method = "GET";

                    // 30s should be enough
                    request.Timeout = 30000;
                    WebResponse response     = request.GetResponse();
                    string      jsonResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();

                    compileResponse = new JavaScriptSerializer().Deserialize <CompileStartResponse>(jsonResponse);
                    lastResponse    = compileResponse;

                    foreach (CompileMessage msg in compileResponse.result.data.new_messages)
                    {
                        if (msg.type == "cc")
                        {
                            messages.Add(string.Format("{0}: {1}: {2}: {3}", msg.severity, msg.file, msg.line, msg.message));
                            messages.Add(string.Format("{0}", msg.text));
                        }
                        else if (msg.type == "progress")
                        {
                            messages.Add(string.Format("{0}: {1} ({2:F} %)", msg.action, msg.file, msg.percent));
                        }
                        else if (msg.type == "tool_error")
                        {
                            messages.Add(string.Format("{0}: {1}", msg.type, msg.message));
                        }
                    }

                    failed = !compileResponse.result.data.compilation_success;
                    if (failed && compileResponse.result.data.task_complete)
                    {
                        messages.Add(string.Format("Raw response: {0}", jsonResponse));
                    }

                    complete = compileResponse.result.data.task_complete;

                    break;
                }
                catch (WebException webException)
                {
                    retryCount--;
                    System.Console.WriteLine("Error sending request :{0}, retries left: {1}", webException.Message, retryCount);

                    if (retryCount == 0)
                    {
                        throw webException;
                    }
                }
            }

            if (retryCount < 0)
            {
                complete = true;
            }

            return(complete);
        }