Пример #1
0
 public static void QuickCopy(List <KeyVaultModel> keyVaults)
 {
     try
     {
         string json = KeyVault.ConvertDictionaryToJson(keyVaults);
         Clipboard.SetText(json);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
 public static void Export(List <KeyVaultModel> keyVaults)
 {
     try
     {
         string json             = KeyVault.ConvertDictionaryToJson(keyVaults);
         bool   saveSuccessfully = KeyVault.SaveJson(json);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
        private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            string uri = KeyVault.BrowseFile();

            if (uri != "")
            {
                try
                {
                    List <DataGridModel> dataGridValues = KeyVault.LoadFile(uri, txtUri);
                    dataGridConfigValues.ItemsSource = dataGridValues;
                    lblStatusMessage.Content         = "";
                }
                catch (Exception ex)
                {
                    lblStatusMessage.Foreground = new SolidColorBrush(Colors.Red);
                    lblStatusMessage.Content    = ex.Message;
                }
            }
        }
Пример #4
0
        private void btnExportJson_Click(object sender, RoutedEventArgs e)
        {
            List <KeyVaultModel> keyVaults = new List <KeyVaultModel>();

            try
            {
                if (dataGridConfigValues.ItemsSource != null)
                {
                    foreach (DataGridModel keyPair in dataGridConfigValues.ItemsSource)
                    {
                        if (keyPair.isSelected == true)
                        {
                            KeyVaultModel keyVault = new KeyVaultModel();
                            keyVault.secretName  = keyPair.key;
                            keyVault.secretValue = keyPair.value;
                            keyVaults.Add(keyVault);
                        }
                    }
                    if (keyVaults.Count > 0)
                    {
                        KeyVault.Export(keyVaults);
                        lblStatusMessage.Foreground = new SolidColorBrush(Colors.LightGreen);
                        lblStatusMessage.Content    = "Exported Successfully.";
                    }
                    else
                    {
                        lblStatusMessage.Foreground = new SolidColorBrush(Colors.Red);
                        lblStatusMessage.Content    = "Must select at least one value pair to export.";
                    }
                }
                else
                {
                    lblStatusMessage.Foreground = new SolidColorBrush(Colors.Red);
                    lblStatusMessage.Content    = "No values to export.";
                }
            }
            catch (Exception ex)
            {
                lblStatusMessage.Foreground = new SolidColorBrush(Colors.Red);
                lblStatusMessage.Content    = ex.Message;
            }
        }
Пример #5
0
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            string uri = txtUri.Text.ToLower();

            if (uri != "")
            {
                try
                {
                    _dataGridValues = new List <DataGridModel>();
                    _dataGridValues = KeyVault.LoadFile(uri, txtUri);
                    dataGridConfigValues.ItemsSource = _dataGridValues;
                    lblStatusMessage.Foreground      = new SolidColorBrush(Colors.LightGreen);
                    lblStatusMessage.Content         = "Loaded Values Successfully.";
                }
                catch (Exception ex)
                {
                    lblStatusMessage.Foreground = new SolidColorBrush(Colors.Red);
                    lblStatusMessage.Content    = ex.Message;
                }
            }
        }
Пример #6
0
 public static List <DataGridModel> LoadFile(string uri, TextBox txtUri)
 {
     try
     {
         if (uri.Contains(".config"))
         {
             ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
             configFileMap.ExeConfigFilename = txtUri.Text;
             List <DataGridModel> keyValues = KeyVault.ConvertConfig(configFileMap);
             return(keyValues);
         }
         else if (uri.Contains(".json") || uri.Contains(".txt"))
         {
             using (StreamReader r = new StreamReader(uri))
             {
                 List <DataGridModel> keyValues = new List <DataGridModel>();
                 string json      = r.ReadToEnd();
                 bool   validJson = KeyVault.IsValidJson(json);
                 if (validJson)
                 {
                     List <KeyVaultModel> keyVaultValues = JsonConvert.DeserializeObject <List <KeyVaultModel> >(json);
                     foreach (KeyVaultModel item in keyVaultValues)
                     {
                         DataGridModel kvm = new DataGridModel();
                         kvm.key   = item.secretName;
                         kvm.value = item.secretValue;
                         keyValues.Add(kvm);
                     }
                 }
                 else
                 {
                     throw new Exception("Invalid format");
                 }
                 return(keyValues);
             }
         }
         else //if not .config file, check to see if uri pasted is json.
         {
             List <DataGridModel> keyValues = new List <DataGridModel>();
             bool validJson = KeyVault.IsValidJson(txtUri.Text);
             if (validJson)
             {
                 List <KeyVaultModel> keyVaultValues = JsonConvert.DeserializeObject <List <KeyVaultModel> >(txtUri.Text);
                 foreach (KeyVaultModel item in keyVaultValues)
                 {
                     DataGridModel kvm = new DataGridModel();
                     kvm.key   = item.secretName;
                     kvm.value = item.secretValue;
                     keyValues.Add(kvm);
                 }
             }
             else
             {
                 throw new Exception("Invalid format");
             }
             return(keyValues);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }