Beispiel #1
0
        public void FromJSON(JToken json)
        {
            if (json is JObject jo)
            {
                Id = jo.Get <string>("id");
                JArray interfaceDefinitions = jo["interfaceDefinitions"] as JArray;

                InterfaceDefinitions = new ServiceInterfaceDefinition[interfaceDefinitions.Count];
                for (int i = 0; i < interfaceDefinitions.Count; i++)
                {
                    var id = new ServiceInterfaceDefinition();
                    InterfaceDefinitions[i] = id;
                    id.FromJSON(interfaceDefinitions[i]);
                }
            }
            else
            {
                throw new ArgumentException("i expected a jobject");
            }
        }
        /// <summary>
        /// create service invoker for definition using the specified host
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        public static IInvoker CreateFrom(ServiceInterfaceDefinition sid, string host = "localhost")
        {
            Type compatibleInvoker = null;

            var attributes = sid.Type.GetCustomAttributes(typeof(CompatibleInvokerAttribute), true);

            if (attributes.Length > 0)
            {
                var att = attributes[0] as CompatibleInvokerAttribute;
                compatibleInvoker = att.Type;
            }
            else
            {
                throw new Exception("Cant find a compatible invoker for this service interface");
            }


            Config.Config config = new Config.Config(sid.Configuration);
            config.Values["host"] = host;

            return((IInvoker)Activator.CreateInstance(compatibleInvoker, config));
        }