コード例 #1
0
        public AccountsResponse.AccountList GetAccounts(string memberID, AccessDetails details)
        {
            AccountsResponse.AccountList accounts = new AccountsResponse.AccountList();
            var    client      = new HttpClient();
            string baseAddress = System.Configuration.ConfigurationManager.AppSettings["BaseAddress"];

            string requestContent = baseAddress + "/_apis/Accounts?memberId=" + memberID + "&api-version=4.1";
            var    request        = new HttpRequestMessage(HttpMethod.Get, requestContent);

            request.Headers.Add("Authorization", "Bearer " + details.access_token);
            try
            {
                var response = client.SendAsync(request).Result;
                if (response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.OK)
                {
                    string result = response.Content.ReadAsStringAsync().Result;
                    accounts = JsonConvert.DeserializeObject <Models.AccountsResponse.AccountsResponse.AccountList>(result);
                    return(accounts);
                }
                else
                {
                    var errorMessage = response.Content.ReadAsStringAsync();
                }
            }
            catch (Exception)
            {
            }
            return(accounts);
        }
コード例 #2
0
        // GET: ExportWIAttachments
        public ActionResult Index()
        {
            AccountsResponse.AccountList accountList = new AccountsResponse.AccountList();
            try
            {
                if (!String.IsNullOrEmpty(Convert.ToString(Session["PAT"])))
                {
                    string token = Convert.ToString(Session["PAT"]);
                    if (Session["AccountList"] != null)
                    {
                        accountList = (AccountsResponse.AccountList)Session["AccountList"];
                    }
                    else
                    {
                        RedirectToAction("../Account/Verify");
                    }

                    return(View(accountList));
                }
                else
                {
                    return(RedirectToAction("../Account/Verify"));
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
コード例 #3
0
 public ActionResult Index(ProjectList.ProjectDetails model)
 {
     try
     {
         AccessDetails accessDetails = new AccessDetails();
         string        pat           = "";
         string        email         = "";
         if (Session["PAT"] != null)
         {
             pat = Session["PAT"].ToString();
         }
         if (Session["Email"] != null)
         {
             email = Session["PAT"].ToString();
         }
         if (string.IsNullOrEmpty(pat))
         {
             return(Redirect("../Account/Verify"));
         }
         else
         {
             accessDetails.access_token = pat;
             ProfileDetails profile = accountService.GetProfile(accessDetails);
             if (profile == null)
             {
                 ViewBag.ErrorMessage = "Could not fetch your profile details, please try to login again";
                 return(View(model));
             }
             if (profile.displayName != null && profile.emailAddress != null)
             {
                 Session["User"]  = profile.displayName;
                 Session["Email"] = profile.emailAddress.ToLower();
             }
             AccountsResponse.AccountList accountList = accountService.GetAccounts(profile.id, accessDetails);
             model.accessToken         = accessDetails.access_token;
             model.accountsForDropdown = new List <string>();
             if (accountList.count > 0)
             {
                 foreach (var account in accountList.value)
                 {
                     model.accountsForDropdown.Add(account.accountName);
                 }
                 model.accountsForDropdown.Sort();
             }
             else
             {
                 model.accountsForDropdown.Add("Select Organization");
                 ViewBag.AccDDError = "Could not load your organizations. Please change the directory in profile page of Azure DevOps Organization and try again.";
             }
             return(View(model));
         }
     }
     catch (Exception ex)
     {
         ExtractorService.logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + ex.Message + "\n" + ex.StackTrace + "\n");
     }
     return(View(model));
 }
コード例 #4
0
 public JsonResult AccountList()
 {
     AccountsResponse.AccountList accountList = new AccountsResponse.AccountList();
     if (Session["AccountList"] != null)
     {
         accountList = (AccountsResponse.AccountList)Session["AccountList"];
     }
     return(Json(accountList.value, JsonRequestBehavior.AllowGet));
 }
コード例 #5
0
        // GET: WIReport
        public ActionResult Index()
        {
            if (Session["visited"] == null)
            {
                return(RedirectToAction("../Account/Verify"));
            }
            if (Session["PAT"] == null)
            {
                InputModel input = new InputModel();
                try
                {
                    AccessDetails _accessDetails = new AccessDetails();

                    AccountsResponse.AccountList accountList = null;
                    string code              = Session["PAT"] == null ? Request.QueryString["code"] : Session["PAT"].ToString();
                    string redirectUrl       = ConfigurationManager.AppSettings["RedirectUri"];
                    string clientId          = ConfigurationManager.AppSettings["ClientSecret"];
                    string accessRequestBody = string.Empty;
                    accessRequestBody = Account.GenerateRequestPostData(clientId, code, redirectUrl);
                    _accessDetails    = Account.GetAccessToken(accessRequestBody);
                    ProfileDetails profile = Account.GetProfile(_accessDetails);

                    if (!string.IsNullOrEmpty(_accessDetails.access_token))
                    {
                        Session["PAT"] = _accessDetails.access_token;

                        if (profile.displayName != null || profile.emailAddress != null)
                        {
                            Session["User"]  = profile.displayName ?? string.Empty;
                            Session["Email"] = profile.emailAddress ?? profile.displayName.ToLower();
                        }
                    }
                    accountList            = Account.GetAccounts(profile.id, _accessDetails);
                    Session["AccountList"] = accountList;
                    string pat = Session["PAT"].ToString();
                    List <SelectListItem> OrganizationList = new List <SelectListItem>();
                    foreach (var i in accountList.value)
                    {
                        OrganizationList.Add(new SelectListItem {
                            Text = i.accountName, Value = i.accountName
                        });
                    }
                    ViewBag.OrganizationList = OrganizationList;
                }
                catch (Exception ex)
                {
                }
            }

            return(View());
        }
コード例 #6
0
        public ActionResult CreateProject()
        {
            try
            {
                AccessDetails _accessDetails = new AccessDetails();
                //AccessDetails _accessDetails = ProjectService.AccessDetails;
                string TemplateSelected = string.Empty;
                if (Session["visited"] != null)
                {
                    Project model = new Project();
                    if (Session["EnableExtractor"] != null)
                    {
                        model.EnableExtractor          = Session["EnableExtractor"].ToString();
                        ProjectService.enableExtractor = model.EnableExtractor.ToLower();
                    }
                    if (Session["templateName"] != null && Session["templateName"].ToString() != "")
                    {
                        model.TemplateName = Session["templateName"].ToString();
                        TemplateSelected   = model.TemplateName;
                    }
                    else
                    {
                        TemplateSelected = System.Configuration.ConfigurationManager.AppSettings["DefaultTemplate"];
                    }

                    if (Session["PAT"] != null)
                    {
                        _accessDetails.access_token = Session["PAT"].ToString();
                        ProfileDetails profile = accountService.GetProfile(_accessDetails);
                        if (profile.displayName != null || profile.emailAddress != null)
                        {
                            Session["User"]  = profile.displayName ?? string.Empty;
                            Session["Email"] = profile.emailAddress ?? profile.displayName.ToLower();
                        }
                        if (profile.id != null)
                        {
                            AccountsResponse.AccountList accountList = accountService.GetAccounts(profile.id, _accessDetails);

                            //New Feature Enabling
                            model.accessToken  = Session["PAT"].ToString();
                            model.refreshToken = _accessDetails.refresh_token;
                            Session["PAT"]     = _accessDetails.access_token;
                            model.MemberID     = profile.id;
                            List <string> accList = new List <string>();
                            if (accountList.count > 0)
                            {
                                foreach (var account in accountList.value)
                                {
                                    accList.Add(account.accountName);
                                }
                                accList.Sort();
                                model.accountsForDropdown = accList;
                                model.hasAccount          = true;
                            }
                            else
                            {
                                accList.Add("Select Organization");
                                model.accountsForDropdown = accList;
                                ViewBag.AccDDError        = "Could not load your organizations. Please check if the logged in Id contains the Azure DevOps Organizations or change the directory in profile page and try again.";
                            }

                            model.Templates          = new List <string>();
                            model.accountUsersForDdl = new List <SelectListItem>();
                            TemplateSelection.Templates templates = new TemplateSelection.Templates();
                            string[] dirTemplates = Directory.GetDirectories(Server.MapPath("~") + @"\Templates");

                            //Taking all the template folder and adding to list
                            foreach (string template in dirTemplates)
                            {
                                model.Templates.Add(Path.GetFileName(template));
                            }
                            // Reading Template setting file to check for private templates
                            if (System.IO.File.Exists(Server.MapPath("~") + @"\Templates\TemplateSetting.json"))
                            {
                                string templateSetting = model.ReadJsonFile(Server.MapPath("~") + @"\Templates\TemplateSetting.json");
                                templates = JsonConvert.DeserializeObject <TemplateSelection.Templates>(templateSetting);
                            }
                            //[for direct URLs] if the incoming template name is not null, checking for Template name in Template setting file.
                            //if exist, will append the template name to Selected template textbox, else will append the SmartHotel360 template
                            if (!string.IsNullOrEmpty(TemplateSelected))
                            {
                                foreach (var grpTemplate in templates.GroupwiseTemplates)
                                {
                                    foreach (var template in grpTemplate.Template)
                                    {
                                        if (template.Name != null)
                                        {
                                            if (template.Name.ToLower() == TemplateSelected.ToLower())
                                            {
                                                model.SelectedTemplate = template.Name;
                                                model.Templates.Add(template.Name);
                                                model.selectedTemplateDescription = template.Description == null ? string.Empty : template.Description;
                                                model.selectedTemplateFolder      = template.TemplateFolder == null ? string.Empty : template.TemplateFolder;
                                                model.Message        = template.Message == null ? string.Empty : template.Message;
                                                model.ForkGitHubRepo = template.ForkGitHubRepo.ToString();
                                                model.templateImage  = template.Image ?? "/Templates/TemplateImages/CodeFile.png";
                                            }
                                        }
                                    }
                                }
                            }
                            return(View(model));
                        }
                    }
                    return(Redirect("../Account/Verify"));
                }
                else
                {
                    Session.Clear();
                    return(Redirect("../Account/Verify"));
                }
            }
            catch (Exception ex)
            {
                ProjectService.logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
                ViewBag.ErrorMessage = ex.Message;
                return(Redirect("../Account/Verify"));
            }
        }