protected override string GetComponentName(MethodInfo method, object[] arguments)
        {
            var groupType = arguments.FirstOrDefault() as string;

            // If no name was given use the default type
            if (groupType == null)
            {
                return(Registrations[DetailsConstants.DefaultType]);
            }

            // Directly return the default view if it is known
            if (Registrations.ContainsKey(groupType))
            {
                return(Registrations[groupType]);
            }

            // Start from the current type going upwards the type tree looking for a custom ui
            var typeModel = FindType(groupType, ServiceModel.TypeTree);

            while (typeModel != null)
            {
                if (Registrations.ContainsKey(typeModel.Name))
                {
                    return(Registrations[typeModel.Name]);
                }
                typeModel = FindType(typeModel.BaseType, ServiceModel.TypeTree);
            }

            // If all failed use the default
            return(Registrations[DetailsConstants.DefaultType]);
        }
示例#2
0
        public void Send <T>(T message) where T : XMessage
        {
            var t = message.GetType();

            if (!Registrations.ContainsKey(t)) //nothing has registered for this message
            {
                return;
            }

            var callList = Registrations[t];

            if (callList == null)
            {
                return;
            }

            Event.WaitOne();
            try
            {
                //tries to call the message, if it fails then it removes that message subscription.
                var itemsToRemove = (from item in callList let callResult = item.Action(message) where !callResult select item).ToList();

                foreach (var item in itemsToRemove)
                {
                    callList.Remove(item);
                }
            }
            finally
            {
                Event.Set();
            }
        }
        internal void MethodRegister(string endpoint, string version, MethodInfo methodInfo, string schema = null)
        {
            ValidateVersion(version);
            ValidateEndpoint(endpoint);

            Dictionary <string, CrpcVersionRegistration> registration;
            Type responseType = null;
            var  requestTypes = methodInfo.GetParameters();
            var  responseTask = methodInfo.ReturnType;

            if (responseTask.GenericTypeArguments.Length > 0)
            {
                responseType = responseTask.GenericTypeArguments[0];
            }

            if (requestTypes.Length > 2)
            {
                throw new InvalidOperationException($"The endpoint {version}/{endpoint} has too many arguments");
            }

            if (Registrations.ContainsKey(endpoint))
            {
                registration = Registrations[endpoint];
            }
            else
            {
                registration = new Dictionary <string, CrpcVersionRegistration>();
            }

            if (registration.ContainsKey(version))
            {
                throw new ArgumentException($"Duplicate version found for {version}/{endpoint}", nameof(version));
            }

            var registrationVersion = new CrpcVersionRegistration
            {
                ResponseType = responseType,
                MethodInfo   = methodInfo,
                Version      = version,
            };

            // Request types are optional, and we only need to load the schema in if
            // a request as a payload.
            if (requestTypes.Length > 1)
            {
                if (schema == null)
                {
                    throw new Exception($"No schema specified for {version}/{endpoint}");
                }

                registrationVersion.Schema      = JSchema.Parse(schema);
                registrationVersion.RequestType = requestTypes[1].ParameterType;
            }

            registration.Add(version, registrationVersion);

            Registrations[endpoint] = registration;
        }
 public void Register(Type service, Type implementation)
 {
     if (!Registrations.ContainsKey(service))
     {
         Registrations.Add(service, new List <Type> {
             implementation
         });
     }
     else
     {
         Registrations[service].Add(implementation);
     }
 }
示例#5
0
        private List <ActionRegistration> Get(Type t)
        {
            if (!Registrations.ContainsKey(t))
            {
                Registrations.Add(t, new List <ActionRegistration>());
            }

            var l = Registrations[t];

            if (l != null)
            {
                return(l);
            }

            l = new List <ActionRegistration>();
            Registrations[t] = l;

            return(l);
        }
示例#6
0
 /// <summary>
 /// Checks to see if a type is registered as an injection target
 /// </summary>
 /// <param name="t">The type to check for</param>
 /// <returns>Whether or not the type is registered as an injection target</returns>
 public static bool IsRegistered(Type t)
 {
     return(Registrations.ContainsKey(t));
 }
 private bool IsRegisteredLocal <T>()
 {
     return(Registrations.ContainsKey(typeof(T)));
 }
示例#8
0
        public void RegisterMethod(string method, string internalMethodName, string date)
        {
            if (ServerType == null)
            {
                throw new NullReferenceException("server type must be registered first");
            }

            validateDate(date);
            validateEndpoint(method);
            FieldInfo schema;
            var       methodInfo   = ServerType.GetMethod(internalMethodName);
            var       responseType = methodInfo.ReturnType;
            var       requestType  = methodInfo.GetParameters()[0];

            if (methodInfo.GetParameters().Length != 1)
            {
                throw new Exception("methods can only have 1 parameter");
            }

            if (method == null)
            {
                throw new Exception("no method could be found with that name");
            }

            Dictionary <string, CrpcVersionRegistration> registration;

            if (Registrations.ContainsKey(method))
            {
                registration = Registrations[method];
            }
            else
            {
                registration = new Dictionary <string, CrpcVersionRegistration>();
            }

            if (registration.ContainsKey(date))
            {
                throw new Exception("duplicate date version found");
            }

            var version = new CrpcVersionRegistration
            {
                ResponseType = responseType,
                Method       = methodInfo,
                Date         = date,
            };

            // Request types are optional, and we only need to load the schema in if
            // a request as a payload.
            if (requestType != null)
            {
                schema = ServerType.GetField($"{internalMethodName}Schema");

                if (schema == null)
                {
                    throw new Exception("no schema could be found");
                }

                if (!schema.IsStatic)
                {
                    throw new Exception("schema must be static");
                }

                if (schema.FieldType != typeof(string))
                {
                    throw new Exception("schema field must be a string");
                }

                version.RequestType = requestType.ParameterType;
                version.Schema      = JSchema.Parse(schema.GetValue(null) as string);
            }

            registration.Add(date, version);

            Registrations[method] = registration;
        }