コード例 #1
0
        static VaultProfileManager()
        {
            var sysAppData = Environment.GetFolderPath(
                Environment.SpecialFolder.CommonApplicationData);
            var userAppData = Environment.GetFolderPath(
                Environment.SpecialFolder.LocalApplicationData);

            APP_SYS_ROOT_PATH  = Path.Combine(sysAppData, APP_ROOT_NAME);
            APP_USER_ROOT_PATH = Path.Combine(userAppData, APP_ROOT_NAME);
            PROFILES_ROOT_PATH = Path.Combine(APP_USER_ROOT_PATH, PROFILES_ROOT_NAME);

            PROFILE_DEFAULT_SYS = new VaultProfile(
                PROFILE_DEFAULT_SYS_NAME,
                Providers.LocalDiskVaultProvider.PROVIDER_NAME, new Dictionary <string, object>
            {
                [Providers.LocalDiskVaultProvider.ROOT_PATH.Name] =
                    Path.Combine(APP_SYS_ROOT_PATH, PROFILE_DEFAULT_SYS_ROOT_NAME),
                [Providers.LocalDiskVaultProvider.CREATE_PATH.Name] = true,
            });

            PROFILE_DEFAULT_USER = new VaultProfile(
                PROFILE_DEFAULT_USER_NAME,
                Providers.LocalDiskVaultProvider.PROVIDER_NAME, new Dictionary <string, object>
            {
                [Providers.LocalDiskVaultProvider.ROOT_PATH.Name] =
                    Path.Combine(APP_USER_ROOT_PATH, PROFILE_DEFAULT_USER_ROOT_NAME),
                [Providers.LocalDiskVaultProvider.CREATE_PATH.Name] = true,
            });

            BUILTIN_PROFILES = new KeyValuePair <string, VaultProfile>[]
            {
                new KeyValuePair <string, VaultProfile>(PROFILE_DEFAULT_SYS_NAME, PROFILE_DEFAULT_SYS),
                new KeyValuePair <string, VaultProfile>(PROFILE_DEFAULT_USER_NAME, PROFILE_DEFAULT_USER),
            };
        }
コード例 #2
0
        public static void SetProfile(string name, string providerName,
                                      IReadOnlyDictionary <string, object> providerParams = null,
                                      IReadOnlyDictionary <string, object> vaultParams    = null)
        {
            if (name.StartsWith(":"))
            {
                throw new ArgumentException("invalid profile name", nameof(name))
                      .With(nameof(name), name);
            }

            if (!Directory.Exists(PROFILES_ROOT_PATH))
            {
                Directory.CreateDirectory(PROFILES_ROOT_PATH);
            }

            var profileFile = Path.Combine(PROFILES_ROOT_PATH, name);
            var profile     = new VaultProfile(name, providerName, providerParams, vaultParams);

            using (var fs = new FileStream(profileFile, FileMode.Create))
            {
                JsonHelper.Save(fs, profile);
            }
        }
コード例 #3
0
        public static void SetProfile(string name, string providerName,
                IReadOnlyDictionary<string, object> providerParams = null,
                IReadOnlyDictionary<string, object> vaultParams = null)
        {
            if (name.StartsWith(":"))
                throw new ArgumentException("invalid profile name", nameof(name))
                        .With(nameof(name), name);

            if (!Directory.Exists(PROFILES_ROOT_PATH))
                Directory.CreateDirectory(PROFILES_ROOT_PATH);

            var profileFile = Path.Combine(PROFILES_ROOT_PATH, name);
            var profile = new VaultProfile(name, providerName, providerParams, vaultParams);

            using (var fs = new FileStream(profileFile, FileMode.Create))
            {
                JsonHelper.Save(fs, profile);
            }
        }
コード例 #4
0
        static VaultProfileManager()
        {
            var sysAppData = Environment.GetFolderPath(
                    Environment.SpecialFolder.CommonApplicationData);
            var userAppData = Environment.GetFolderPath(
                    Environment.SpecialFolder.LocalApplicationData);

            APP_SYS_ROOT_PATH = Path.Combine(sysAppData, APP_ROOT_NAME);
            APP_USER_ROOT_PATH = Path.Combine(userAppData, APP_ROOT_NAME);
            PROFILES_ROOT_PATH = Path.Combine(APP_USER_ROOT_PATH, PROFILES_ROOT_NAME);

            PROFILE_DEFAULT_SYS = new VaultProfile(
                    PROFILE_DEFAULT_SYS_NAME,
                    Providers.LocalDiskVaultProvider.PROVIDER_NAME, new Dictionary<string, object>
                    {
                        [Providers.LocalDiskVaultProvider.ROOT_PATH.Name] =
                                Path.Combine(APP_SYS_ROOT_PATH, PROFILE_DEFAULT_SYS_ROOT_NAME),
                        [Providers.LocalDiskVaultProvider.CREATE_PATH.Name] = true,
                    });

            PROFILE_DEFAULT_USER = new VaultProfile(
                    PROFILE_DEFAULT_USER_NAME,
                    Providers.LocalDiskVaultProvider.PROVIDER_NAME, new Dictionary<string, object>
                    {
                        [Providers.LocalDiskVaultProvider.ROOT_PATH.Name] =
                                Path.Combine(APP_USER_ROOT_PATH, PROFILE_DEFAULT_USER_ROOT_NAME),
                        [Providers.LocalDiskVaultProvider.CREATE_PATH.Name] = true,
                    });

            BUILTIN_PROFILES = new KeyValuePair<string, VaultProfile>[]
            {
                new KeyValuePair<string, VaultProfile>(PROFILE_DEFAULT_SYS_NAME, PROFILE_DEFAULT_SYS),
                new KeyValuePair<string, VaultProfile>(PROFILE_DEFAULT_USER_NAME, PROFILE_DEFAULT_USER),
            };
        }