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}'"); } } }
public bool TryGetRemoteService(string name, out RemoteServiceInfo serviceInfo) { if (!_isLoaded) { throw new InvalidOperationException("Not initialized"); } return(_remoteServices.TryGetValue(name, out serviceInfo)); }
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); }
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); }
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); } } }
private void ConfigureRemoteServiceControllerName(ControllerModel controller, RemoteServiceInfo serviceInfo) { controller.ControllerName = serviceInfo.Name; }
private void ConfigureRemoteServiceControllerArea(ControllerModel controller, RemoteServiceInfo serviceInfo) { controller.RouteValues["area"] = serviceInfo.Area; }
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); } } }
public Type MakeRemoteServiceProxyType(RemoteServiceInfo service) { throw new NotSupportedException(); }