public EditorStateHelper(LayoutEditorPopulation layoutEditorPopulation, UserSettingsModel userSettings)
 {
     _layoutEditorPopulation = layoutEditorPopulation;
     _userSettings = userSettings;
     if (_layoutEditorPopulation.EraseOnly)
     {
         erasableTypes = layoutEditorPopulation.GetErasableTypes();
     }
     ResetState();
 }
 public void FillSettings(StartupEventArgs e)
 {
     var tempSettings = GetSettingsFromApp(e);
     if (!_settingsStorage.Contains("UserId") || (string)GetSettingByKey("UserId") != tempSettings.UserId)
     {
         UserSettings = tempSettings;
         UpdateSettingsInStorage(UserSettings);
     }
     else
         UserSettings = GetSettingsFromStorage();
 }
        private void LoadLayoutForFlagMode(UserSettingsModel userSettings)
        {
            // In Flag mode layout ID is either a guid or a single number to represent a fixed layout
            Debug.Assert(!string.IsNullOrEmpty(userSettings.UserId));
            Debug.Assert(!string.IsNullOrEmpty(userSettings.LayoutId));

            // If using a previous run which is from a different user (i.e. a support using looking at someone elses dat)
            // Then use the id of the actual originator
            if (!string.IsNullOrEmpty(userSettings.PreviousRunOriginator) && (userSettings.UserId != userSettings.PreviousRunOriginator))
                UserSettings.UserId = userSettings.PreviousRunOriginator;
            if (userSettings.LayoutId.Length == 1)
            {
                int layoutNum = int.Parse(userSettings.LayoutId);
                _userLayoutService.LoadFixedLayoutXmlWithFlagsFromService(userSettings.UserId, userSettings.AssociatedAssayId, layoutNum, userSettings.PreviousRunId);
            }
            else
                _userLayoutService.LoadUserLayoutWithFlagsXmlFromService(userSettings.AssociatedAssayId, userSettings.UserId, userSettings.LayoutId, userSettings.PreviousRunId);
        }
 private void LoadLayoutForEdit(UserSettingsModel userSettings)
 {
     // If a layout ID has been specified then load it now from the service
     if (!string.IsNullOrEmpty(userSettings.LayoutId))
     {
         Debug.Assert(!string.IsNullOrEmpty(userSettings.UserId));
         _userLayoutService.LoadUserLayoutXmlFromService(userSettings.UserId, userSettings.LayoutId);
         // If the user has selected to edit a layout which belongs to a previous run then we don not want to edit that layout as it will
         // affect the previously stored run data.  Instead any changes made should be stored to a new layout.
         // To achieve this we reset the layout id, this will mean when the SaveUserLayoutToService is called the changes will be stored
         // to a new MLO, rather than overwrite the existing.
         if (userSettings.IsPreviousRunEdit)
             userSettings.LayoutId = string.Empty;
     }
     else
     {
         // If no layout ID has specified we are creating a new layout
         // To save bothering the server just create it here first
         if (_userLayoutService.InitEmptyUserLayout(LayoutEditorPopulation))
         {
             // If using an empty layout (no default layout) then fill is the default selection tool.
             // However, EraseOnly as been set (which == !AllowFillMode) then there is a problem
             SelectionCommand = SelectionCommand.Fill;
         }
         else
         {
             // If using an default layout then set the default selection tool
             SelectionCommand = userSettings.IsFlagMode ? SelectionCommand.Flag : SelectionCommand.Erase;
         }
     }
 }
        private UserSettingsModel GetSettingsFromApp(StartupEventArgs e)
        {
            var userSettings = new UserSettingsModel();
            if (e.InitParams.ContainsKey("LayoutId"))
                userSettings.LayoutId = e.InitParams["LayoutId"];

            if (e.InitParams.ContainsKey("UserId"))
                userSettings.UserId = e.InitParams["UserId"];
            else
                userSettings.UserId = "0";

            if (e.InitParams.ContainsKey("ServiceAddress"))
            {
                userSettings.ServiceAddress = e.InitParams["ServiceAddress"];
                string serviceName = "ServiceLayouts.svc";
                if (!userSettings.ServiceAddress.EndsWith(serviceName))
                    throw new ArgumentException(string.Format("Service name is not expected, {0} is expected, however it is ", serviceName, userSettings.ServiceAddress));
                userSettings.ServerRoot = userSettings.ServiceAddress.Replace(serviceName, "");
            }

            if (e.InitParams.ContainsKey("AssociatedAssayId"))
                userSettings.AssociatedAssayId = long.Parse(e.InitParams["AssociatedAssayId"]);

            if (e.InitParams.ContainsKey("IsPreviousRunEdit"))
                userSettings.IsPreviousRunEdit = bool.Parse(e.InitParams["IsPreviousRunEdit"]);

            if (userSettings.IsPreviousRunEdit)
            {
                if (e.InitParams.ContainsKey("PreviousRunId"))
                    userSettings.PreviousRunId = e.InitParams["PreviousRunId"];
                if (e.InitParams.ContainsKey("PreviousRunOriginator"))
                    userSettings.PreviousRunOriginator = e.InitParams["PreviousRunOriginator"];
            }
            else
            {
                // Not a previous run
                userSettings.PreviousRunOriginator = userSettings.PreviousRunId = "";
            }

            if (e.InitParams.ContainsKey("IsFlagMode"))
                userSettings.IsFlagMode = bool.Parse(e.InitParams["IsFlagMode"]);

            if (e.InitParams.ContainsKey("ResultsPathFormat"))
                userSettings.ResultsPathFormat = e.InitParams["ResultsPathFormat"];
            else
            {
                // For MyAssays 1.0 (on local or Amazon EC2)
                userSettings.ResultsPathFormat = "Local";
            }

            // Setup the UserSettings Key/Value pairs (if they have not been setup already)
            userSettings.FillDirection = Direction.Down;
            userSettings.Replicates = 1;
            userSettings.RectangleMode = false;
            userSettings.ReplicateDirection = RepDirection.ByRow;
            userSettings.ShowNextTime = true;
            return userSettings;
        }
 private void UpdateSettingsInStorage(UserSettingsModel userSettings)
 {
     if (userSettings == null)
     {
         _settingsStorage.Clear();
         return;
     }
     var properties = userSettings.GetType().GetProperties();
     foreach (var item in properties)
         if (!_settingsStorage.Contains(item.Name))
             _settingsStorage.Add(item.Name, item.GetValue(userSettings, null));
         else
             _settingsStorage[item.Name] = item.GetValue(userSettings, null);
 }
 private UserSettingsModel GetSettingsFromStorage()
 {
     var userSettings = new UserSettingsModel();
     var properties = userSettings.GetType().GetProperties();
     foreach (var item in properties)
         if (_settingsStorage.Contains(item.Name))
             item.SetValue(userSettings, _settingsStorage[item.Name], null);
     if (!_settingsStorage.Contains("ShowNextTime"))
         userSettings.ShowNextTime = true;
     return userSettings;
 }
 public void ApplyUserSettings(UserSettingsModel userSettings)
 {
     _userSettings = userSettings;
     if (string.IsNullOrEmpty(_userSettings.UserId))
         throw new ArgumentException(ErrorHelper.UserIdErrorMessage);
     if (_userSettings.IsFlagMode)
     {
         UpdateTipMessage("Delete Flags");
         if (_userSettings.IsPreviousRunEdit)
             UpdateTipMessage("Displayed flags are from previous analysis.  Save will store flags to your settings for this assay.");
     }
 }
 public FillSettingsModel(UserSettingsModel userSettings)
 {
     _userSettings = userSettings;
 }