示例#1
0
        private void SetHttpVerbOfAction(RemoteServiceInfo serviceInfo, ActionModel action, RemoteServiceMethodInfo serviceMethod)
        {
            var selector = action.Selectors.FirstOrDefault();

            if (selector?.ActionConstraints != null && selector?.ActionConstraints.Count == 0)
            {
                switch (serviceMethod.HttpMethod)
                {
                case HttpMethod.Get:
                    selector.ActionConstraints.Add(new HttpMethodActionConstraint(new string[] { "GET" }));
                    break;

                case HttpMethod.Post:
                    selector.ActionConstraints.Add(new HttpMethodActionConstraint(new string[] { "POST" }));
                    break;

                case HttpMethod.Delete:
                    selector.ActionConstraints.Add(new HttpMethodActionConstraint(new string[] { "DELETE" }));
                    break;

                case HttpMethod.Put:
                    selector.ActionConstraints.Add(new HttpMethodActionConstraint(new string[] { "PUT" }));
                    break;

                case HttpMethod.Patch:
                    selector.ActionConstraints.Add(new HttpMethodActionConstraint(new string[] { "PATCH" }));
                    break;

                default:
                    throw new NotSupportedException(
                              $"Unsupported HTTP method '{serviceMethod.HttpMethod}' of method '{serviceMethod.Name}' in Remote Service '{serviceInfo.Name}'");
                }
            }
        }
示例#2
0
 public bool TryGetRemoteService(string name, out RemoteServiceInfo serviceInfo)
 {
     if (!_isLoaded)
     {
         throw new InvalidOperationException("Not initialized");
     }
     return(_remoteServices.TryGetValue(name, out serviceInfo));
 }
示例#3
0
 public bool TryGetRemoteService(Type clrType, out RemoteServiceInfo serviceInfo)
 {
     if (!_isLoaded)
     {
         throw new InvalidOperationException("Not initialized");
     }
     serviceInfo = _remoteServices.Values.SingleOrDefault(x => x.ClrType == clrType);
     return(serviceInfo != null ? true : false);
 }
        protected RemoteServiceInfo CreateServiceMetadata(string name, IFeatureInfo featureInfo, Type serviceType, string area)
        {
            var methods =
                serviceType.GetMethods(BindingFlags.Instance | BindingFlags.Public)
                .Where(m => this.IsRemoteServiceMethod(m))
                .Select(method => this.CreateServiceMethodMetadata(method))
                .ToList();

            var rs = new RemoteServiceInfo {
                Feature = featureInfo,
                Name    = name,
                ClrType = serviceType.GetTypeInfo(),
                Methods = methods,
                Area    = area,
            };

            return(rs);
        }
示例#5
0
        private void ClearNonRemoteServiceMethods(ControllerModel controller, RemoteServiceInfo remoteService)
        {
            var serviceMethods = new HashSet <MethodInfo>(remoteService.Methods.Select(x => x.ClrMethodInfo));

            //从控制器的动作里删掉所有的方法
            var actionIndicesToDelete = new List <int>();

            for (var i = 0; i < controller.Actions.Count; i++)
            {
                var oldAction = controller.Actions[i];
                if (!serviceMethods.Contains(oldAction.ActionMethod))
                {
                    actionIndicesToDelete.Add(i);
                }
            }

            foreach (var i in actionIndicesToDelete)
            {
                controller.Actions.RemoveAt(i);
            }
        }
 public Type MakeRemoteServiceProxyType(RemoteServiceInfo service)
 {
     return(service.ClrType);
 }
示例#7
0
        private void ConfigureRemoteServiceControllerActions(ControllerModel controller, RemoteServiceInfo serviceInfo)
        {
            this.ClearNonRemoteServiceMethods(controller, serviceInfo);
            var serviceMethods = serviceInfo.Methods.ToDictionary(x => x.ClrMethodInfo);

            foreach (var action in controller.Actions)
            {
                var serviceMethod = serviceMethods[action.ActionMethod];
                this.SetHttpVerbOfAction(serviceInfo, action, serviceMethod);

                if (action.ActionName.EndsWith("Async"))
                {
                    action.ActionName = action.ActionName.Substring(0, action.ActionName.Length - 5);
                }
            }
        }
示例#8
0
 private void ConfigureRemoteServiceControllerName(ControllerModel controller, RemoteServiceInfo serviceInfo)
 {
     controller.ControllerName = serviceInfo.Name;
 }
示例#9
0
 private void ConfigureRemoteServiceControllerArea(ControllerModel controller, RemoteServiceInfo serviceInfo)
 {
     controller.RouteValues["area"] = serviceInfo.Area;
 }
示例#10
0
        private void TryRegisterRemoteServiceProxyType(
            IServiceProvider sp, IEnumerable <IRemoteServiceProvider> remoteServiceProviders, RemoteServiceInfo s)
        {
            //Register the dynamic API controller type to Orchard's TypeFeatureProvider
            //foreach
            var typeFeatureProvider = sp.GetRequiredService <ITypeFeatureProvider>();

            foreach (var rsp in remoteServiceProviders)
            {
                if (rsp.IsRemoteServiceProxyTypeRequired)
                {
                    var implType = rsp.MakeRemoteServiceProxyType(s);
                    typeFeatureProvider.TryAdd(implType, s.Feature);
                }
            }
        }
示例#11
0
 public Type MakeRemoteServiceProxyType(RemoteServiceInfo service)
 {
     throw new NotSupportedException();
 }