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

            Console.WriteLine(text);
            Console.ReadLine();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public ActionResult Callback(string code, string state)
        {
            TokenModel token = new TokenModel();
            String     error = null;

            if (!String.IsNullOrEmpty(code))
            {
                error = PerformTokenRequest(GenerateRequestPostData(code), out token);
                if (String.IsNullOrEmpty(error))
                {
                    ViewBag.Token = token;
                }
            }

            var storage = new VsoBotStorage.Token();

            storage.SetToken(Session["userName"].ToString(), ViewBag.Token);

            ViewBag.Error = error;

            return(View("TokenView"));
        }