示例#1
0
        public override void Add(ProviderBase provider)
        {
            Assert.ArgumentNotNull(provider, "provider");
            var provider2 = provider as ZipInfoProvider;
            var message   = "The provider type passed to ZipInfoProviderCollection is not assignable to ZipInfoProvider. Actual type: {0}";

            Assert.IsNotNull(provider2, message, new object[] { provider.GetType().FullName });
            this.Add(provider2);
        }
        /// <summary>
        /// Require a specific feature, and that it can be cast properly.
        /// </summary>
        /// <param name="feature">Feature of interest.</param>
        /// <param name="cast">The type to verify assignment for a cast.</param>
        /// <returns>The service or null if one was not present.</returns>
        private ProviderBase RequireServiceInternal(object feature, Type cast)
        {
            ProviderBase pb  = RequireServiceInternal(feature);
            Type         pbt = pb.GetType();

            if (!cast.IsAssignableFrom(pbt))
            {
                throw new InvalidOperationException("A required test service feature was present, but not of the proper type for this application.");
            }
            return(pb);
        }
        public override void Add(ProviderBase provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (!(provider is PersonalizationProvider))
            {
                throw new ArgumentException(
                          SR.GetString(SR.Provider_must_implement_the_interface,
                                       provider.GetType().FullName, "PersonalizationProvider"));
            }

            base.Add(provider);
        }
示例#4
0
 public override void Add(ProviderBase provider)
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if (!(provider is SiteMapProvider))
     {
         throw new InvalidOperationException(String.Format("{0} must implement {1} to act as a site map provider", provider.GetType(), typeof(SiteMapProvider)));
     }
     if (this [provider.Name] != null)
     {
         throw new ArgumentException("Duplicate site map providers");
     }
     base.Add(provider);
 }
        public override void Add(ProviderBase provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (!(provider is SiteMapProvider))
            {
                throw new ArgumentException(SR.GetString(SR.Provider_must_implement_the_interface, provider.GetType().Name, typeof(SiteMapProvider).Name), "provider");
            }

            Add((SiteMapProvider)provider);
        }
        public override void Add(ProviderBase provider)
        {
            Assert.ArgumentNotNull((object)provider, nameof(provider));
            MockLocationFallbackProviderBase provider1 = provider as MockLocationFallbackProviderBase;

            Assert.IsNotNull((object)provider1, "The provider type passed to MockLocationFallbackProviderCollection is not assignable to MockLocationFallbackProviderBase. Actual type: {0}", (object)provider.GetType().FullName);
            this.Add(provider1);
        }
示例#7
0
        public static int DoAdd(CommandLineApplication <AddCommandModel> addCmd, ProviderBase providerBase)
        {
            var newConfigItem = new DomainConfigItem
            {
                Domain = addCmd.Model.Domain,
                Type   = addCmd.Model.Type ?? DomainRecordType.A
                         // 为了便于下面 GetSingle() 模糊查询,这里先不对 Provider 赋值
            };

            // 根据 域名+类型 判断,是否有重复的
            var item = DomainConfigHelper.GetSingle(newConfigItem);

            if (item != null)
            {
                addCmd.Error.WriteLine("Failed to add, because the same configuration already exists: ");
                WriteConfigInfoToConsole(item, addCmd.Error);
                addCmd.Error.WriteLine("Only one record can be added for the same domain name and type, even if the provider is different.");

                return(1);
            }

            // 获取网卡信息
            // 如果只有一个网卡,并且用户没有设置 interface 选项,那么该域名就与该网卡绑定,使用该网卡的 IP 地址
            // 如果只有一个网卡,并且用户设置了 interface 选项,先判断可用网卡和用户设置的是否一致,如果一致则使用;不一致则报错
            // 如果有多个网卡,并且用户没有设置 interface 选项,报错
            // 如果有多个网卡,并且用户设置了 interface 选项,判断用户设置的网卡是否可用,如果不可用则报错
            NetworkInterface iface;
            var interfaces = GetAvailableNetworkInterfaces();

            if (!interfaces.Any())
            {
                return(FailedWithAvailableNetworkInterface(addCmd.Error));
            }

            if (!String.IsNullOrEmpty(addCmd.Model.Interface))
            {
                iface = interfaces.SingleOrDefault(i => i.Name == addCmd.Model.Interface);

                if (iface == null)
                {
                    return(FailedWithInterfaceNameNotFound(addCmd.Error));
                }
            }
            else if (interfaces.Count == 1)
            {
                iface = interfaces.Single();

                if (iface.Name != addCmd.Model.Interface)
                {
                    return(FailedWithInterfaceNameNotFound(addCmd.Error));
                }
            }
            else
            {
                return(FailedWithMultipleInterfaceNameFoundButNoSpecify(addCmd.Error));
            }

            // 准备保存数据了,为 Provider 等内容赋值
            newConfigItem.Provider  = addCmd.Model.Provider;
            newConfigItem.Interface = iface.Name;

            // 保存访问 DNS 提供商 API 时需要用到的参数信息
            var providerOptionNames = ProviderHelper.GetProviderOptions(providerBase.GetType()).Select(o => o.LongName);

            newConfigItem.ProviderInfo = addCmd.Options
                                         .Where(o => providerOptionNames.Contains(o.LongName))
                                         .ToDictionary(k => k.LongName, v => String.Join('|', v.Values));

            DomainConfigHelper.AddItem(newConfigItem);
            addCmd.Out.WriteLine($"Added successfully!");

            return(1);
        }
示例#8
0
 public override void Add(ProviderBase provider)
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if (!(provider is SiteMapProvider))
     {
         throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_the_interface", new object[] { provider.GetType().Name, typeof(SiteMapProvider).Name }), "provider");
     }
     this.Add((SiteMapProvider)provider);
 }