internal BaseMethod(DiscoveryVersion version, KeyValuePair<string, object> kvp) { discoveryVersion = version; Name = kvp.Key; information = kvp.Value as JsonDictionary; if (information == null) { throw new ArgumentException("got no valid dictionary"); } }
/// <summary> /// Create a service object for a specific version of discovery. /// </summary> /// <param name="version">Version of discovery to use.</param> /// <param name="param">Parameters intended to initialize the factory.</param> /// <returns></returns> public IService GetService(DiscoveryVersion version, FactoryParameters param) { var factory = ServiceFactory.Get(version); using (var documentStream = DiscoveryDevice.Fetch()) { // Parse the document. var dictionary = Json.JsonReader.Parse(documentStream) as Json.JsonDictionary; return factory.CreateService(dictionary, param); } }
/// <summary> /// Returns a parameter with the given values. /// </summary> internal static IParameter GetParameter(DiscoveryVersion version, KeyValuePair<string, object> kvp) { switch (version) { case DiscoveryVersion.Version_0_3: return new ParameterV0_3(kvp); case DiscoveryVersion.Version_1_0: return new ParameterV1_0(kvp); default: throw new NotSupportedException("Unsupported version of Discovery " + version); } }
/// <summary> /// Creates a new resource for the specified discovery version with the specified name and json dictionary. /// </summary> internal BaseResource(DiscoveryVersion version, KeyValuePair<string, object> kvp) { kvp.ThrowIfNull("kvp"); kvp.Key.ThrowIfNull("kvp"); DiscoveryVersion = version; logger.Debug("Constructing Resource [{0}]", kvp.Key); Name = kvp.Key; information = kvp.Value as JsonDictionary; if (information == null) { throw new ArgumentException("got no valid dictionary"); } // Initialize subresources. if (information.ContainsKey("resources")) { var resourceJson = (JsonDictionary)information["resources"]; resources = new Dictionary<string, IResource>(); foreach (KeyValuePair<string, object> pair in resourceJson) { // Create the subresource. var subResource = (BaseResource)CreateResource(pair); subResource.Parent = this; resources.Add(pair.Key, subResource); } } }
public void InvalidName() { DiscoveryVersion.FromName("foobar"); }
public void EmptyName() { DiscoveryVersion.FromName(String.Empty); }
public void NullName() { DiscoveryVersion.FromName(null); }
/// <summary> /// Create a service object for a specific version of discovery. /// </summary> /// <param name="version">Version of discovery to use.</param> /// <returns></returns> public IService GetService(DiscoveryVersion version) { return(this.GetService(version, null)); }
private IService CreateService(DiscoveryVersion version) { return(version == DiscoveryVersion.Version_0_3 ? CreateLegacyV03Service() : CreateV1Service()); }
public UdpSecureAnnouncementEndpoint(DiscoveryVersion discoveryVersion, SigningCertificateSettings signingStoreSettings) : base(discoveryVersion) { this.Intialize(signingStoreSettings); }
private IService CreateService(DiscoveryVersion version) { return version == DiscoveryVersion.Version_0_3 ? CreateLegacyV03Service() : CreateV1Service(); }
/// <summary> /// Create a service object for a specific version of discovery. /// </summary> /// <param name="version">Version of discovery to use.</param> /// <returns></returns> public IService GetService(DiscoveryVersion version) { return this.GetService(version, null); }
public MethodV1_0(DiscoveryVersion version, KeyValuePair<string, object> kvp) : base(version, kvp) { }
/// <summary> /// Creates a service factory for the discovery version requested, with the given parameters /// </summary> /// <param name="discovery">A stream which contains information about the service to construct</param> /// <param name="version">The discovery version to use</param> /// <param name="parameters"> /// A set of (optional) factory parameters used to construct the service. /// If this parameter is null, then a default set of FactoryParameters is created /// </param> public static IServiceFactory CreateServiceFactory(Stream discovery, DiscoveryVersion version, IFactoryParameter parameters) { discovery.ThrowIfNull("discovery"); version.ThrowIfNull("version"); JsonDictionary information = JsonReader.Parse(discovery) as JsonDictionary; switch (version) { case DiscoveryVersion.Version_0_3: return new ServiceFactoryDiscoveryV0_3( information, (FactoryParameterV0_3) (parameters ?? new FactoryParameterV0_3())); case DiscoveryVersion.Version_1_0: return new ServiceFactoryDiscoveryV1_0( information, (FactoryParameterV1_0) (parameters ?? new FactoryParameterV1_0())); default: throw new NotSupportedException("The Version " + version + " is not supported"); } }
/// <summary> /// Creates a service factory for the discovery version requested /// </summary> /// <param name="discovery">A stream which contains information about the service to construct</param> /// <param name="version">The discovery version to use</param> public static IServiceFactory CreateServiceFactory(Stream discovery, DiscoveryVersion version) { return CreateServiceFactory(discovery, version, null); }
/// <summary> /// Get an IServiceFactory instance for a specific version of the discovery service. /// </summary> /// <remarks> /// Currently supports discovery versions 0.3 and 1.0 /// </remarks> public static IServiceFactory Get(DiscoveryVersion version) { switch (version) { case DiscoveryVersion.Version_0_3: return ServiceFactoryDiscoveryV0_3.GetInstance(); case DiscoveryVersion.Version_1_0: return ServiceFactoryDiscoveryV1_0.GetInstance(); default: throw new NotSupportedException(); } }