/// <summary> /// 用于执行不带有事务性的多指令操作。 /// </summary> /// <param name="commands"></param> public CommandSet(CommandType commandType, ExecuteMothodType commandSetType, ReturnResultType returnType) { this.commandType = commandType; this.executeType = commandSetType; this.returnType = returnType; Initialize(); }
public CommandSet(CommandType commandType, ExecuteMothodType commandSetType, ReturnResultType returnType, string transactionId) { this.commandType = commandType; this.executeType = commandSetType; this.returnType = returnType; this.transactionId = transactionId; Initialize(); }
void DetermineReturnTypeInfo(MethodInfo methodInfo) { var returnType = methodInfo.ReturnType; if (returnType.IsGenericType && (methodInfo.ReturnType.GetGenericTypeDefinition() != typeof(Task <>) || methodInfo.ReturnType.GetGenericTypeDefinition() != typeof(IObservable <>))) { ReturnType = returnType; ReturnResultType = returnType.GetGenericArguments()[0]; if (ReturnResultType.IsGenericType && (ReturnResultType.GetGenericTypeDefinition() == typeof(ApiResponse <>) || ReturnResultType.GetGenericTypeDefinition() == typeof(IApiResponse <>))) { DeserializedResultType = ReturnResultType.GetGenericArguments()[0]; } else if (ReturnResultType == typeof(IApiResponse)) { DeserializedResultType = typeof(HttpContent); } else { DeserializedResultType = ReturnResultType; } } else if (returnType == typeof(Task)) { ReturnType = methodInfo.ReturnType; ReturnResultType = typeof(void); DeserializedResultType = typeof(void); } else { throw new ArgumentException($"Method \"{methodInfo.Name}\" is invalid. All REST Methods must return either Task<T> or IObservable<T>"); } }
/// <summary> /// 提取PNR的航信指令 /// </summary> /// <param name="pnrCode">旅客订座记录编号</param> public RTCommand(string pnrCode, CommandType commandType = CommandType.PNRModification, ReturnResultType returnType = ReturnResultType.Single) { this.commandType = commandType; this.returnType = returnType; this.pnrCode = pnrCode; this.commandString = string.Format("RT:{0}", pnrCode); Initialize(); }
public RestMethodInfo(Type targetInterface, MethodInfo methodInfo, RefitSettings refitSettings = null) { RefitSettings = refitSettings ?? new RefitSettings(); Type = targetInterface; Name = methodInfo.Name; MethodInfo = methodInfo; var hma = methodInfo.GetCustomAttributes(true) .OfType <HttpMethodAttribute>() .First(); HttpMethod = hma.Method; RelativePath = hma.Path; IsMultipart = methodInfo.GetCustomAttributes(true) .OfType <MultipartAttribute>() .Any(); MultipartBoundary = IsMultipart ? methodInfo.GetCustomAttribute <MultipartAttribute>(true).BoundaryText : string.Empty; VerifyUrlPathIsSane(RelativePath); DetermineReturnTypeInfo(methodInfo); DetermineIfResponseMustBeDisposed(); // Exclude cancellation token parameters from this list var parameterList = methodInfo.GetParameters().Where(p => p.ParameterType != typeof(CancellationToken)).ToList(); ParameterInfoMap = parameterList .Select((parameter, index) => new { index, parameter }) .ToDictionary(x => x.index, x => x.parameter); ParameterMap = BuildParameterMap(RelativePath, parameterList); BodyParameterInfo = FindBodyParameter(parameterList, IsMultipart, hma.Method); Headers = ParseHeaders(methodInfo); HeaderParameterMap = BuildHeaderParameterMap(parameterList); // get names for multipart attachments AttachmentNameMap = new Dictionary <int, Tuple <string, string> >(); if (IsMultipart) { for (var i = 0; i < parameterList.Count; i++) { if (ParameterMap.ContainsKey(i) || HeaderParameterMap.ContainsKey(i)) { continue; } var attachmentName = GetAttachmentNameForParameter(parameterList[i]); if (attachmentName == null) { continue; } AttachmentNameMap[i] = Tuple.Create(attachmentName, GetUrlNameForParameter(parameterList[i])); } } QueryParameterMap = new Dictionary <int, string>(); for (var i = 0; i < parameterList.Count; i++) { if (ParameterMap.ContainsKey(i) || HeaderParameterMap.ContainsKey(i) || (BodyParameterInfo != null && BodyParameterInfo.Item3 == i)) { continue; } QueryParameterMap.Add(i, GetUrlNameForParameter(parameterList[i])); } var ctParams = methodInfo.GetParameters().Where(p => p.ParameterType == typeof(CancellationToken)).ToList(); if (ctParams.Count > 1) { throw new ArgumentException($"Argument list to method \"{methodInfo.Name}\" can only contain a single CancellationToken"); } CancellationToken = ctParams.FirstOrDefault(); IsApiResponse = ReturnResultType.GetTypeInfo().IsGenericType&& (ReturnResultType.GetGenericTypeDefinition() == typeof(ApiResponse <>) || ReturnResultType.GetGenericTypeDefinition() == typeof(IApiResponse <>) || ReturnResultType == typeof(IApiResponse)); }
public ReturnResult(Hire hire, ReturnResultType type) { Hire = hire; Type = type; }