Beispiel #1
0
        public async Task CreateVaultExportThenImport()
        {
            Vault sourceVault = new Vault();

            int count = 5000;

            for (int i = 0; i < count; i++)
            {
                Credential credential = CredentialTests.CreateRandomCredential(_rng);
                credential.AddToVault(sourceVault, false);
            }

            VaultExporter exporter = new VaultExporter(
                Common.ExportFormat.cachyCSV1_0,
                Common.ExportWrapping.Raw);

            byte[] csv       = exporter.Export(sourceVault);
            string csvString = System.Text.Encoding.UTF8.GetString(csv);

            Vault destVault = new Vault();

            CSVImporter importer = new CSVImporter(csvString);
            await importer.ImportToVault(destVault, VaultExporter.GetFieldMappings());

            for (int i = 0; i < count; i++)
            {
                Credential sourceCredential = sourceVault.Credentials[i];
                Credential destCredential   = destVault.Credentials[i];
                Assert.IsTrue(sourceCredential.SimpleCompare(destCredential) == 0);
            }
        }
Beispiel #2
0
 public async void OnClosePopup(View item, object parameter)
 {
     if (item is SelectImportSourceView)
     {
         if (parameter != null)
         {
             Dictionary <string, object> parameters = parameter as Dictionary <string, object>;
             if (parameters != null)
             {
                 CSVImporter  csvImporter  = (CSVImporter)parameters["CSVImporter"];
                 ImportSource importSource = (ImportSource)parameters["ImportSource"];
                 if (importSource.Format != Common.CSVFormat.Unknown)
                 {
                     List <ImportFieldMapping> mappings = CSVImporter.CreateMappings(importSource.Format);
                     await csvImporter.ImportToVault(Vault, mappings);
                 }
                 else
                 {
                     App.Controller.ShowPopup(
                         "vault.importmap",
                         new KeyValuePair <string, object>("CSVImporter", csvImporter),
                         new KeyValuePair <string, object>("ImportHeaders", csvImporter.Headers),
                         new KeyValuePair <string, object>("StandardFields", Credential.StandardFields));
                 }
             }
         }
     }
     else if (item is ImportMappingView)
     {
         Dictionary <string, object> parameters = parameter as Dictionary <string, object>;
         if (parameters != null)
         {
             CSVImporter csvImporter            = (CSVImporter)parameters["CSVImporter"];
             List <ImportFieldMapping> mappings = (List <ImportFieldMapping>)parameters["Mappings"];
             await csvImporter.ImportToVault(Vault, mappings);
         }
     }
     else if (item is VaultReportView)
     {
         string filter = (string)parameter;
         if (!String.IsNullOrEmpty(filter))
         {
             Entry searchEntry = View.FindByName <Entry>("SearchEntry");
             if (searchEntry != null)
             {
                 searchEntry.Text = "@" + filter;
             }
         }
     }
     ResetIdleTime();
     ClearSelectedCredential(true);
     NotifyPropertyChanged("FilteredCredentials");
 }