Exemple #1
0
        static void Main(string[] args)
        {
            var bot  = new VsoBotStorage.Token();
            var text = bot.GetToken("*****@*****.**");

            Console.WriteLine(text);
            Console.ReadLine();
        }
        public string Get(string id)
        {
            var userName = id.Trim().Split('$')[1];

            id = id.Trim().Split('$')[0];
            var            error           = String.Empty;
            var            strResponseData = String.Empty;
            string         postData        = "{\"query\":\"Select [State], [Title] From WorkItems  Where [Work Item Type] = '" + id + "' and [System.AssignedTo] = @Me Order By [State] Asc, [Changed Date] Desc\"}";
            HttpWebRequest webRequest      = (HttpWebRequest)WebRequest.Create(
                "https://microsoftit.visualstudio.com/DefaultCollection/OneITVSO/_apis/wit/wiql?api-version=1.0");

            webRequest.Method        = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType   = ApiHelper.ContentType;
            var storage = new VsoBotStorage.Token();
            var token   = storage.GetToken(userName);

            if (token == null)
            {
                return(string.Empty);
            }
            webRequest.Headers.Add("Authorization", ApiHelper.AuthorizationToken + token.accessToken);

            using (StreamWriter swRequestWriter = new StreamWriter(webRequest.GetRequestStream()))
            {
                swRequestWriter.Write(postData);
            }

            try
            {
                HttpWebResponse hwrWebResponse = (HttpWebResponse)webRequest.GetResponse();

                if (hwrWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    using (StreamReader srResponseReader = new StreamReader(hwrWebResponse.GetResponseStream()))
                    {
                        strResponseData = srResponseReader.ReadToEnd();
                    }

                    var rootObject = JsonConvert.DeserializeObject <Rootobject>(strResponseData);
                    if (rootObject != null && rootObject.workItems.Any())
                    {
                        return(GetItemList(rootObject.workItems, id, token.accessToken));
                    }
                }
            }
            catch (WebException wex)
            {
                error = "Request Issue: " + wex.Message;
            }
            catch (Exception ex)
            {
                error = "Issue: " + ex.Message;
            }

            throw new Exception(error);
        }