Ejemplo n.º 1
0
        private ISettingsOriginator RestoreFromParameters(string parameters)
        {
            //Restore our saved memento
            ISettingsMemento memento = _kernel.Get <ISettingsMemento>(new ConstructorArgument("settingsAsString", parameters));

            //Restore originator from memento
            ISettingsOriginator originator = SettingsOriginatorFactory.Instance.CreateOriginator();

            originator.RestoreFromMemento(memento);

            return(originator);
        }
Ejemplo n.º 2
0
 public void RestoreFromMemento(ISettingsMemento memento)
 {
     _settings.Clear();
     foreach (ISetting setting in memento.Settings)
     {
         ISetting newSetting = new Setting() { Name = setting.Name };
         if (setting.Encrypt & !String.IsNullOrEmpty(setting.Value))
             newSetting.Value = DecryptFromBase64(setting.Value);
         else
             newSetting.Value = setting.Value;
         _settings.Add(newSetting);
     }//end foreach
 }
Ejemplo n.º 3
0
        private ISettingsOriginator RestoreFromCurrentUserSettings()
        {
            //Grab settings as string
            ISettingsService svc = _kernel.Get <ISettingsService>();

            //Restore our saved memento
            ISettingsMemento memento = _kernel.Get <ISettingsMemento>(new ConstructorArgument("settingsAsString", svc.GetAllSettingsAsXML()));

            //Restore originator from memento
            ISettingsOriginator originator = SettingsOriginatorFactory.Instance.CreateOriginator();

            originator.RestoreFromMemento(memento);

            return(originator);
        }
Ejemplo n.º 4
0
 public void RestoreFromMemento(ISettingsMemento memento)
 {
     _settings.Clear();
     foreach (ISetting setting in memento.Settings)
     {
         ISetting newSetting = new Setting()
         {
             Name = setting.Name
         };
         if (setting.Encrypt & !String.IsNullOrEmpty(setting.Value))
         {
             newSetting.Value = DecryptFromBase64(setting.Value);
         }
         else
         {
             newSetting.Value = setting.Value;
         }
         _settings.Add(newSetting);
     }            //end foreach
 }
Ejemplo n.º 5
0
        public void Initalize()
        {
            //Reset our settings memento before we start
            _memento = _settings.GetMemento();

            //Set up the view
            ISetting url = _settings.Get(YurtleTrackPlugin.URLOPTIONNAME);

            if (url != null)
            {
                _view.URL = url.Value;
            }
            else
            {
                _view.URL = string.Empty;
            }

            ISetting user = _settings.Get(YurtleTrackPlugin.USEROPTIONNAME);

            if (url != null)
            {
                _view.UserName = user.Value;
            }
            else
            {
                _view.UserName = string.Empty;
            }

            ISetting pass = _settings.Get(YurtleTrackPlugin.PASSWORDOPTIONNAME);

            if (url != null)
            {
                _view.Password = pass.Value;
            }
            else
            {
                _view.Password = string.Empty;
            }
        }
        public void Originator_Can_Restore_From_Memento()
        {
            MockRepository repo                 = new MockRepository();
            ISetting       mockSetting1         = repo.StrictMock <ISetting>();
            ISetting       mockSettingEncrypted = repo.StrictMock <ISetting>();

            mockSetting1.Expect(setting => setting.Name).Return("Setting1").Repeat.Any();
            mockSetting1.Expect(setting => setting.Value).Return("Setting1Value").Repeat.Any();
            mockSetting1.Expect(setting => setting.Encrypt).Return(false).Repeat.Any();

            mockSettingEncrypted.Expect(setting => setting.Name).Return("SettingEncrypted").Repeat.Any();
            mockSettingEncrypted.Expect(setting => setting.Value).Return("SettingEncryptedValue").Repeat.Any();
            mockSettingEncrypted.Expect(setting => setting.Encrypt).Return(true).Repeat.Any();

            repo.ReplayAll();

            SettingsOriginator org = new SettingsOriginator();

            org.Set(mockSetting1);
            org.Set(mockSettingEncrypted);

            ISettingsMemento memento = org.GetMemento();

            SettingsOriginator orgRestored = new SettingsOriginator();

            orgRestored.RestoreFromMemento(memento);

            ISetting setting1 = orgRestored.Get("Setting1");

            Assert.Equal("Setting1", setting1.Name);
            Assert.Equal("Setting1Value", setting1.Value);

            ISetting settingEncrypted = orgRestored.Get("SettingEncrypted");

            Assert.Equal("SettingEncrypted", settingEncrypted.Name);
            Assert.Equal("SettingEncryptedValue", settingEncrypted.Value);
        }
Ejemplo n.º 7
0
        public void Initalize_Sets_URL_On_View()
        {
            MockRepository      repo                   = new MockRepository();
            IOptionsView        mockOptionsView        = repo.StrictMock <IOptionsView>();
            ISettingsOriginator mockSettingsOriginator = repo.StrictMock <ISettingsOriginator>();
            ISettingsMemento    mockSettingsMemento    = repo.StrictMock <ISettingsMemento>();
            ISetting            urlSetting             = repo.StrictMock <ISetting>();
            ISetting            userNameSetting        = repo.StrictMock <ISetting>();
            ISetting            passwordSetting        = repo.StrictMock <ISetting>();
            string url      = "http://www.google.com";
            string userName = "******";
            string password = "******";

            urlSetting.Expect(set => set.Value).Return(url);
            userNameSetting.Expect(set => set.Value).Return(userName);
            passwordSetting.Expect(set => set.Value).Return(password);

            mockSettingsOriginator.Expect(org => org.Get("TrackerURL")).Return(urlSetting);
            mockSettingsOriginator.Expect(org => org.Get("UserName")).Return(userNameSetting);
            mockSettingsOriginator.Expect(org => org.Get("Password")).Return(passwordSetting);
            mockSettingsOriginator.Expect(org => org.GetMemento()).Return(mockSettingsMemento);


            mockOptionsView.Expect(view => view.URL).SetPropertyWithArgument(url);
            mockOptionsView.Expect(view => view.UserName).SetPropertyWithArgument(userName);
            mockOptionsView.Expect(view => view.Password).SetPropertyWithArgument(password);

            repo.ReplayAll();

            IOptionsPresenter pres = new OptionsPresenter(mockOptionsView, mockSettingsOriginator);

            pres.Initalize();

            mockOptionsView.VerifyAllExpectations();
            mockSettingsOriginator.VerifyAllExpectations();
            urlSetting.VerifyAllExpectations();
        }
Ejemplo n.º 8
0
        public void Initalize()
        {
            //Reset our settings memento before we start
            _memento = _settings.GetMemento();

            //Set up the view
            ISetting url = _settings.Get(YurtleTrackPlugin.URLOPTIONNAME);
            if (url != null)
                _view.URL = url.Value;
            else
                _view.URL = string.Empty;

            ISetting user = _settings.Get(YurtleTrackPlugin.USEROPTIONNAME);
            if (url != null)
                _view.UserName = user.Value;
            else
                _view.UserName = string.Empty;

            ISetting pass = _settings.Get(YurtleTrackPlugin.PASSWORDOPTIONNAME);
            if (url != null)
                _view.Password = pass.Value;
            else
                _view.Password = string.Empty;
        }
Ejemplo n.º 9
0
 public SettingsOriginator(ISettingsMemento memento)
     : this()
 {
     RestoreFromMemento(memento);
 }
Ejemplo n.º 10
0
 public SettingsOriginator(ISettingsMemento memento)
     : this()
 {
     RestoreFromMemento(memento);
 }
 public ISettingsOriginator CreateOriginatorFromMemento(ISettingsMemento memento)
 {
     return(new SettingsOriginator(memento));
 }
 public ISettingsOriginator CreateOriginatorFromMemento(ISettingsMemento memento)
 {
     return new SettingsOriginator(memento);
 }