Esempio n. 1
0
 public string AddStateInfo(BasespaceActionInfo info)
 {
     var key = Guid.NewGuid().ToString();
     _stateCache[key] = info;
     info.Key = key;
     return key;
 }
Esempio n. 2
0
 /// <summary>
 /// This method drives the population of the web page from the stored data
 /// </summary>
 ActionResult MainApplicationHandler(UserStateInfo stateInfo, BasespaceActionInfo model)
 {
     return View("DisplayBasespaceData", model);
 }
Esempio n. 3
0
        private ActionResult HandleInitialTrigger(string actionuri, string returnuri)
        {
            try
            {
                // fetch the action info. This will tell you what the user selected in BaseSpace
                string uri;
                if (actionuri.ToLower().StartsWith("http"))
                    uri = actionuri;
                else
                    uri = ConfigurationManager.AppSettings["BasespaceAppServerUri"] + actionuri;
                var request = WebRequest.Create(uri);
                request.ContentType = "application/json";
                SetBasicAuthHeader(request, ConfigurationManager.AppSettings["MyClientId"],
                    ConfigurationManager.AppSettings["MyClientSecret"]);
                var response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Message = string.Format("Error fetching action info from '{0}'", actionuri);
                }
                else
                {
                    using (var stm = new StreamReader(response.GetResponseStream()))
                    {
                        dynamic dict = DeserializeResponse(stm);
                        var model = new BasespaceActionInfo(dict);

                        var userId = model.UserId;

                        var stateInfo = GetUserStateInfo(userId);
                        var stateId = stateInfo.AddStateInfo(model);

                        // do we have an authorization code for this user yet? If not, we need to get it
                        // redirect the browser
                        if (string.IsNullOrEmpty(stateInfo.AuthToken))
                        {
                            var oauthUrl = BuildOAuthUrl(userId, stateId, null, model.GetRequestedScope());

                            return Redirect(oauthUrl);
                        }
                        return MainApplicationHandler(stateInfo, model);
                    }
                }
            }
            catch (Exception e)
            {
                ViewBag.Message = string.Format("Error fetching action info from '{0}': {1}", actionuri, e);
            }

            return View("ShowRawText");
        }