예제 #1
0
        public static IMessageResponse SoapMessage(string controller, string body, IWebSocketConnection socket)
        {
            if (string.IsNullOrWhiteSpace(controller))
            {
                throw new ArgumentException("API cannot be Empty.");
            }

            var method = WebSocketEntryClass.GetMethod(controller, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

            if (method == null)
            {
                throw new ArgumentException(string.Format("API'{0}' cannot found.", controller));
            }

            var type = ReflectHepler.GetMethodTypes(method).FirstOrDefault();

            IMessageRequest request = null;

            if (body != null)
            {
                request = JsonConvert.DeserializeObject(body, type) as IMessageRequest;
                if (request != null)
                {
                    request.Head        = request.Head ?? new MessageHead();
                    request.Head.Socket = socket;
                }
            }
            var response = method.Invoke(null, new object[] { request }) as IMessageResponse;

            if (response != null)
            {
                response.Status = ResponseStatus.Success();
            }
            return(response);
        }
예제 #2
0
        public static JSchemaResponse GetJSchema(JSchemaRequest request)
        {
            var result = new JSchemaResponse
            {
                Assembly = request.Assembly,
                Class    = request.Class
            };
            var type = ReflectHepler.GetClass(request.Assembly, request.Class);

            if (type != null)
            {
                var ctors = type.GetConstructors();
                ctors.ForEachOfUnNone(ctor =>
                {
                    if (ctor.GetCustomAttributes(typeof(JSchemaAttribute)).ToList().CanBeCount())
                    {
                        if (ctor.GetParameters().CanBeCount())
                        {
                            result.HasArgCtor = true;
                        }
                    }
                });
                result.MemberList = GetJsMapInfo(type);
            }
            return(result);
        }
예제 #3
0
        public static InstanceResponse Instance(InstanceRequest request)
        {
            object obj = null;
            var    instanceParameters = ReflectHepler.ToParameters(request.InstanceParameters);
            var    memberParameters   = ReflectHepler.ToParameters(request.MemberParameters);

            switch (request.Operate)
            {
            case "InvokeMethod":
                obj = InstanceHelper.InvokeMethod(request.MemberPath, instanceParameters, memberParameters);
                break;

            case "GetProperty":
                obj = InstanceHelper.GetProperty(request.MemberPath, instanceParameters, memberParameters);
                break;

            case "SetProperty":
                InstanceHelper.SetProperty(request.MemberPath, instanceParameters, memberParameters);
                break;

            case "GetField":
                obj = InstanceHelper.GetField(request.MemberPath, instanceParameters);
                break;

            case "SetField":
                InstanceHelper.SetField(request.MemberPath, instanceParameters, memberParameters);
                break;

            case "AddEvent":
                InstanceHelper.AddEvent(request.MemberPath, instanceParameters, request.EventId, request.PluginKey, request.JsCallback);
                break;

            case "RemoveEvent":
                InstanceHelper.RemoveEvent(request.MemberPath, instanceParameters, request.EventId);
                break;
            }
            return(new InstanceResponse {
                Result = obj
            });
        }