Пример #1
0
        public ActionResult SelectDfServer(DownloadChangeModel model)
        {
            CurrentDownload = model;

            if (model.TargetServerGuid == null)
            {
                return(RedirectToAction("SelectManagedWorld"));
            }

            ManagedServerModel managedWorld = CurrentUser.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid);

            if (managedWorld == null)
            {
                return(RedirectToAction("SelectManagedWorld"));
            }

            ApiAccountModel currentUser = CurrentUser;

            currentUser.SelectedManagedWorldGuid = managedWorld.ManagedServerGuid.Value;
            currentUser.SelectedManagedWorld     = managedWorld.ServerName;
            CurrentUser = currentUser;

            if (string.IsNullOrWhiteSpace(managedWorld.CachedToken))
            {
                return(RedirectToAction("LogIntoManagedWorld"));
            }

            return(RedirectToAction("SendToDfServer"));
        }
Пример #2
0
 public ActionResult SendToDfServer(uint id, string userGuid, bool preview = false)
 {
     CurrentDownload = new DownloadChangeModel()
     {
         WeenieId = id, FromUserGuid = userGuid, PreviewOnly = preview
     };
     return(RedirectToAction("SendChangeToServer"));
 }
Пример #3
0
        public ActionResult LogIntoManagedWorld(DownloadChangeModel model)
        {
            if (string.IsNullOrWhiteSpace(model?.TargetServerUsername) || string.IsNullOrWhiteSpace(model?.TargetServerPassword))
            {
                model.ErrorMessages.Add("Username and password are required.");
                return(View(model));
            }

            ApiAccountModel    user         = CurrentUser;
            ManagedServerModel managedWorld = user.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid);

            if (managedWorld == null)
            {
                return(RedirectToAction("SelectManagedWorld"));
            }

            string token;

            try
            {
                // attempt to log into the managed world
                token = ContentProviderHost.ManagedWorldProvider.Authenticate(managedWorld.Address, model.TargetServerUsername, model.TargetServerPassword);
            }
            catch (Exception ex)
            {
                model.ErrorMessages.Add(ex.Message);
                return(View(model));
            }

            managedWorld.CachedToken = token;

            // because pointers are fun, we can now update the current user with the user we pulled out earlier
            CurrentUser = user;

            return(RedirectToAction("SendChangeToServer"));
        }
Пример #4
0
        public ActionResult SendChangeToServer()
        {
            DownloadChangeModel model = CurrentDownload;
            WeenieChange        wc    = SandboxContentProviderHost.CurrentProvider.GetSandboxedChange(Guid.Parse(model.FromUserGuid), model.WeenieId);

            if (wc == null)
            {
                return(RedirectToAction("Sandbox"));
            }

            ApiAccountModel user = CurrentUser;

            if (user.SelectedManagedWorldGuid == null)
            {
                if (user.ManagedWorlds?.Count == 1)
                {
                    // use the only server they have
                    model.TargetServerGuid = user.ManagedWorlds[0].ManagedServerGuid.ToString();
                }
                else
                {
                    // user needs to select a managed server
                    return(RedirectToAction("SelectManagedWorld"));
                }
            }
            else
            {
                model.TargetServerGuid = user.SelectedManagedWorldGuid.ToString();
            }

            CurrentDownload = model;

            ManagedServerModel managedWorld = user.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid);

            if (managedWorld == null)
            {
                return(RedirectToAction("SelectManagedWorld"));
            }

            if (string.IsNullOrWhiteSpace(managedWorld.CachedToken))
            {
                return(RedirectToAction("LogIntoManagedWorld"));
            }

            IRestResponse restResponse;

            if (model.PreviewOnly)
            {
                wc.Weenie.ReplaceLiveObjects = true;
                restResponse = ContentProviderHost.ManagedWorldProvider.PreviewWeenie(managedWorld.Address, managedWorld.CachedToken, wc.Weenie);
            }
            else
            {
                restResponse = ContentProviderHost.ManagedWorldProvider.UpdateWeenie(managedWorld.Address, managedWorld.CachedToken, wc.Weenie);
            }

            if (restResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                BaseModel baseModel = CurrentBaseModel ?? new BaseModel();
                baseModel.SuccessMessages.Add("Weenie sent to server.");
                CurrentBaseModel = baseModel;
                return(RedirectToAction("Sandbox"));
            }

            if (restResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                model.ErrorMessages.Add("Authorization denied.");
                CurrentDownload = model;
                return(RedirectToAction("LogIntoManagedWorld"));
            }

            model.InfoMessages.Add($"Unexpected result from server: {restResponse.StatusCode} - {restResponse.Content}");
            CurrentDownload = model;
            return(RedirectToAction("LogIntoManagedWorld"));
        }
Пример #5
0
        public ActionResult SelectManagedWorld()
        {
            DownloadChangeModel model = CurrentDownload;

            return(View(model));
        }