コード例 #1
0
        private bool TryReloadStorage()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                LocalStorage = new SecureLocalStorage(
                    new CustomLocalStorageConfig(null, "DotnetsaferShieldForVisualStudio").WithDefaultKeyBuilder()
                    );

                ExtensionConfiguration = LocalStorage.Exists(ExtensionConfigurationFile)
                    ? LocalStorage.Get <ShieldExtensionConfiguration>(ExtensionConfigurationFile)
                    : null;
            }
            catch (Exception e)
            {
                WriteLine(e.Message);
            }

            return(ExtensionConfiguration != null);
        }
コード例 #2
0
        public ConfigurationWindowControl(ConfigurationViewModel viewModel)
        {
            InitializeComponent();

            _viewModel  = viewModel;
            DataContext = viewModel;

            LocalStorage = new SecureLocalStorage(
                new CustomLocalStorageConfig(null, "DotnetsaferShieldForVisualStudio").WithDefaultKeyBuilder()
                );

            ExtensionConfiguration = LocalStorage.Exists(ExtensionConfigurationFile) ?
                                     LocalStorage.Get <ShieldExtensionConfiguration>(ExtensionConfigurationFile) :
                                     new ShieldExtensionConfiguration();

            if (!string.IsNullOrEmpty(ExtensionConfiguration.ApiToken))
            {
                try
                {
                    _ = ShieldClient.CreateInstance(ExtensionConfiguration.ApiToken);
                    _viewModel.IsValidClient = true;
                    ApiKeyBox.Password       = ExtensionConfiguration.ApiToken;
                    ConnectButton.Content    = ExtensionConfiguration.ApiToken != ApiKeyBox.Password ? "Connect and save" : "Retry connection";
                }
                catch (Exception)
                {
                    _viewModel.IsValidClient = false;
                }
            }
            else
            {
                _viewModel.IsValidClient = false;
            }

            if (!_viewModel.IsValidClient)
            {
                ShieldControl.SelectedIndex = 1;
            }
        }