示例#1
0
        private ExportDiagramElement LoadComposition(string strategyFile)
        {
            var password     = _settings.GetValue <SecureString>("Password");
            var hasPassword  = _settings.ContainsKey("Password");
            var savePassword = false;

            var strategy = File.ReadAllText(strategyFile);

            while (true)
            {
                if (!hasPassword)
                {
                    var wnd = new SecretWindow {
                        Secret = password
                    };

                    if (!wnd.ShowModal(this))
                    {
                        return(null);
                    }

                    savePassword = wnd.SaveSecret;
                    password     = wnd.Secret;
                }

                try
                {
                    var data = strategy;

                    if (!password.IsEmpty())
                    {
                        data = data.Decrypt(password.To <string>());
                    }

                    var composition = ConfigManager.GetService <CompositionRegistry>().DeserializeExported(data.LoadSettingsStorage());

                    if (!savePassword)
                    {
                        return(composition);
                    }

                    _settings.SetValue("Password", password);
                    SaveSettings();

                    return(composition);
                }
                catch (Exception ex)
                {
                    ex.LogError();

                    new MessageBoxBuilder()
                    .Error()
                    .Text(LocalizedStrings.StrategyLoadingError)
                    .Owner(this)
                    .Button(MessageBoxButton.OK)
                    .Show();

                    hasPassword = false;
                }
            }
        }
示例#2
0
		private ExportDiagramElement LoadComposition(string strategyFile)
		{
			var password = _settings.GetValue<SecureString>("Password");
			var hasPassword = _settings.ContainsKey("Password");
			var savePassword = false;

			var strategy = File.ReadAllText(strategyFile);

			while (true)
			{
				if (!hasPassword)
				{
					var wnd = new SecretWindow { Secret = password };

					if (!wnd.ShowModal(this))
						return null;

					savePassword = wnd.SaveSecret;
					password = wnd.Secret;
				}

				try
				{
					var data = strategy;

					if (!password.IsEmpty())
						data = data.Decrypt(password.To<string>());

					var composition = ConfigManager.GetService<CompositionRegistry>().DeserializeExported(data.LoadSettingsStorage());

					if (!savePassword)
						return composition;

					_settings.SetValue("Password", password);
					SaveSettings();

					return composition;
				}
				catch (Exception ex)
				{
					ex.LogError();

					new MessageBoxBuilder()
						.Error()
						.Text(LocalizedStrings.StrategyLoadingError)
						.Owner(this)
						.Button(MessageBoxButton.OK)
						.Show();

					hasPassword = false;
				}
			}
		}