Ejemplo n.º 1
0
 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");
     }
 }
Ejemplo n.º 2
0
 /// <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);
     }
 }
Ejemplo n.º 3
0
 /// <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);
     }
 }
Ejemplo n.º 4
0
        /// <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);
                }
            }
        }
Ejemplo n.º 5
0
 public void InvalidName()
 {
     DiscoveryVersion.FromName("foobar");
 }
Ejemplo n.º 6
0
 public void EmptyName()
 {
     DiscoveryVersion.FromName(String.Empty);
 }
Ejemplo n.º 7
0
 public void NullName()
 {
     DiscoveryVersion.FromName(null);
 }
Ejemplo n.º 8
0
 /// <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));
 }
Ejemplo n.º 9
0
 private IService CreateService(DiscoveryVersion version)
 {
     return(version == DiscoveryVersion.Version_0_3 ? CreateLegacyV03Service() : CreateV1Service());
 }
 public UdpSecureAnnouncementEndpoint(DiscoveryVersion discoveryVersion, SigningCertificateSettings signingStoreSettings)
     : base(discoveryVersion)
 {
     this.Intialize(signingStoreSettings);
 }
Ejemplo n.º 11
0
 private IService CreateService(DiscoveryVersion version)
 {
   return version == DiscoveryVersion.Version_0_3 ? CreateLegacyV03Service() : CreateV1Service();
 }
Ejemplo n.º 12
0
 /// <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);
 }
Ejemplo n.º 13
0
 public MethodV1_0(DiscoveryVersion version, KeyValuePair<string, object> kvp)
     : base(version, kvp)
 {
 }
Ejemplo n.º 14
0
        /// <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");
            }
        }
Ejemplo n.º 15
0
 /// <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);
 }
Ejemplo n.º 16
0
 /// <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();
     }
 }