コード例 #1
0
        protected override void ProcessRecord()
        {
            var pc = new ProviderConfig
            {
                Id = EntityHelper.NewId(),
                Alias = Alias,
                Label = Label,
                Memo = Memo,
                DnsProvider = DnsProvider,
                WebServerProvider = WebServerProvider,
                FilePath = FilePath
            };

            using (var vp = InitializeVault.GetVaultProvider(VaultProfile))
            {
                vp.OpenStorage();
                var v = vp.LoadVault();

                if (v.ProviderConfigs == null)
                    v.ProviderConfigs = new EntityDictionary<ProviderConfig>();
                v.ProviderConfigs.Add(pc);

                vp.SaveVault(v);

                // TODO: this is *so* hardcoded, clean
                // up this provider resolution mechanism
                Stream s = null;
                if (!string.IsNullOrEmpty(DnsProvider))
                {
                    s = ProviderConfigSamples.Loader.LoadDnsProviderConfig(
                            DnsProvider);
                }
                if (!string.IsNullOrEmpty(WebServerProvider))
                {
                    s = ProviderConfigSamples.Loader.LoadWebServerProviderConfig(
                            WebServerProvider);
                }

                var temp = Path.GetTempFileName();
                if (string.IsNullOrWhiteSpace(FilePath))
                {
                    using (var fs = new FileStream(temp, FileMode.Create))
                    {
                        s.CopyTo(fs);
                    }
                    EditFile(temp, EditWith);
                }
                else
                {
                    var config = new ProviderConfigDto
                    {
                        Provider = new Provider
                        {
                            Type = "ACMESharp.WebServer.ManualWebServerProvider, ACMESharp",
                            FilePath = FilePath
                        }
                    };

                    var output = JsonConvert.SerializeObject(config);

                    s = new MemoryStream(Encoding.UTF8.GetBytes(output));
                    using (var fs = new FileStream(temp, FileMode.Create))
                    {
                        s.CopyTo(fs);
                    }
                }

                var pcAsset = vp.CreateAsset(VaultAssetType.ProviderConfigInfo, $"{pc.Id}.json");
                using (Stream fs = new FileStream(temp, FileMode.Open),
                        assetStream = vp.SaveAsset(pcAsset))
                {
                    fs.CopyTo(assetStream);
                }
                File.Delete(temp);

                s.Close();
                s.Dispose();
            }
        }
コード例 #2
0
        protected override void ProcessRecord()
        {
            var pc = new ProviderConfig
            {
                Id = EntityHelper.NewId(),
                Alias = Alias,
                Label = Label,
                Memo = Memo,
                DnsProvider = DnsProvider,
                WebServerProvider = WebServerProvider,
            };

            using (var vp = InitializeVault.GetVaultProvider(VaultProfile))
            {
                vp.OpenStorage();
                var v = vp.LoadVault();

                if (v.ProviderConfigs == null)
                    v.ProviderConfigs = new EntityDictionary<ProviderConfig>();
                v.ProviderConfigs.Add(pc);

                vp.SaveVault(v);

                // TODO: this is *so* hardcoded, clean
                // up this provider resolution mechanism
                Stream s = null;
                if (!string.IsNullOrEmpty(DnsProvider))
                {
                    s = ProviderConfigSamples.Loader.LoadDnsProviderConfig(
                            DnsProvider);
                }
                if (!string.IsNullOrEmpty(WebServerProvider))
                {
                    s = ProviderConfigSamples.Loader.LoadWebServerProviderConfig(
                            WebServerProvider);
                }

                var temp = Path.GetTempFileName();
                using (var fs = new FileStream(temp, FileMode.Create))
                {
                    s.CopyTo(fs);
                }
                EditFile(temp, EditWith);

                var pcAsset = vp.CreateAsset(VaultAssetType.ProviderConfigInfo, $"{pc.Id}.json");
                using (Stream fs = new FileStream(temp, FileMode.Open),
                        assetStream = vp.SaveAsset(pcAsset))
                {
                    fs.CopyTo(assetStream);
                }
                File.Delete(temp);

                s.Close();
                s.Dispose();
            }
        }