当前位置: 首页>>代码示例>>C#>>正文


C# IServiceRequest类代码示例

本文整理汇总了C#中IServiceRequest的典型用法代码示例。如果您正苦于以下问题:C# IServiceRequest类的具体用法?C# IServiceRequest怎么用?C# IServiceRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IServiceRequest类属于命名空间,在下文中一共展示了IServiceRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertMyObject

        public Task<IServiceResponse<int>> InsertMyObject(IServiceRequest<MyObject> obj)
        {
            obj.MustNotBeNull("obj");

            return Task.Factory.StartNew(() =>
            {
                using (var repo = new ExampleRepo())
                {
                    var toInsert = Mapper.Map<MyEntity>(obj.Argument);
                    try
                    {
                        repo.MyEntities.Insert(toInsert);
                    }
                    catch (Exception ex)
                    {
                        //yes - catching all exceptions is not good - but this is just demonstrating how you might use the exception to
                        //generate a failed response that automatically has the exception on it.

                        //IN SOME CASES, your service layer operations will bubble their exceptions out, of course - it all depends
                        //on how you want to handle it.
                        return ex.AsFailedResponse<int>();
                    }

                    return toInsert.Id.AsSuccessfulResponse();
                }
            });
        }
开发者ID:LordZoltan,项目名称:WebAPIDemos,代码行数:27,代码来源:MyObjectService.cs

示例2: ProcessRequest

        public override void ProcessRequest(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository)
        {
            response.ContentType = Constants.CONTENT_TYPE_JSON;

            EAEPMessages messages = null;

            if (request.GetParameter(Constants.QUERY_STRING_FROM) != null)
            {
                DateTime from = DateTime.ParseExact(request.GetParameter(Constants.QUERY_STRING_FROM), Constants.FORMAT_DATETIME, CultureInfo.InvariantCulture);
                if (request.GetParameter(Constants.QUERY_STRING_TO) != null)
                {
                    messages = monitor.GetMessages(
                        from,
                        DateTime.ParseExact(request.GetParameter(Constants.QUERY_STRING_TO), Constants.FORMAT_DATETIME, CultureInfo.InvariantCulture),
                        request.Query
                        );
                }
                else
                {
                    messages = monitor.GetMessages(from, request.Query);
                }
            }
            else
            {
                messages = monitor.GetMessages(request.Query);
            }
            using (StreamWriter writer = new StreamWriter(response.ContentStream))
            {
                string json = JsonConvert.SerializeObject(messages);
                writer.Write(json);
            }
        }
开发者ID:adambird,项目名称:eaep,代码行数:32,代码来源:SearchService.cs

示例3: GetService

        /// <summary>
        /// Instantiates the service described by the <paramref name="serviceRequest"/>.
        /// </summary>
        /// <param name="serviceRequest">The <see cref="IServiceRequest"/> that describes the service that needs to be instantiated.</param>
        /// <returns>A valid object reference if the service can be found; otherwise, it will return <c>null</c>.</returns>
        public virtual object GetService(IServiceRequest serviceRequest)
        {
            // Allow users to intercept the instantiation process
            if (_preProcessor != null)
                _preProcessor.Preprocess(serviceRequest);

            var factoryRequest = new FactoryRequest
            {
                ServiceType = serviceRequest.ServiceType,
                ServiceName = serviceRequest.ServiceName,
                Arguments = serviceRequest.ActualArguments,
                Container = _container
            };

            var instance = _creator.CreateFrom(factoryRequest, serviceRequest.ActualFactory);

            // Postprocess the results
            var result = new ServiceRequestResult
            {
                ServiceName = serviceRequest.ServiceName,
                ActualResult = instance,
                Container = _container,
                OriginalResult = instance,
                ServiceType = serviceRequest.ServiceType,
                AdditionalArguments = serviceRequest.ActualArguments
            };

            if (_postProcessor != null)
                _postProcessor.PostProcess(result);

            return result.ActualResult ?? result.OriginalResult;
        }
开发者ID:sdether,项目名称:LinFu,代码行数:37,代码来源:DefaultGetServiceBehavior.cs

示例4: Preprocess

        /// <summary>
        /// Injects the given factory into the target container.
        /// </summary>
        /// <param name="request">The <see cref="IServiceRequest"/> instance that describes the service that is currently being requested.</param>
        public void Preprocess(IServiceRequest request)
        {
            // Inject the custom factory if no other
            // replacement exists
            if (request.ActualFactory != null)
                return;

            var serviceType = request.ServiceType;

            // Skip any service requests for types that are generic type definitions
            if (serviceType.IsGenericTypeDefinition)
                return;

            // If the current service type is a generic type,
            // its type definition must match the given service type
            if (serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() != _serviceType)
                return;

            // The service types must match
            if (!serviceType.IsGenericType && serviceType != _serviceType)
                return;

            // Inject the custom factory itself
            request.ActualFactory = _factory;
        }
开发者ID:jam231,项目名称:LinFu,代码行数:29,代码来源:CustomFactoryInjector.cs

示例5: IsValidName

            public override bool IsValidName(IServiceRequest req, string actionName, IOperationDescriptor operationDesc)
            {
                if (string.IsNullOrEmpty(this.Name))
                    return false;

                return req.Arguments.ContainsKey(this.Name);
            }
开发者ID:netcasewqs,项目名称:nlite,代码行数:7,代码来源:ActionNameSelectorSpec.cs

示例6: QueryMyObjects

 public System.Threading.Tasks.Task<IServiceResponse<PagedResult<MyObject>>> QueryMyObjects(IServiceRequest<PagedQuery> query)
 {
     //no caching here
     //although - what we could do is check whether any of the objects coming back are in the cache and, if they are,
     //then we replace them for when we do individual gets ONLY
     return _inner.QueryMyObjects(query);
 }
开发者ID:LordZoltan,项目名称:WebAPIDemos,代码行数:7,代码来源:MyCachingObjectService.cs

示例7: Preprocess

 /// <summary>
 /// A method that passes every request result made
 /// to the list of preprocessors.
 /// </summary>
 /// <param name="request">The parameter that describes the context of the service request.</param>
 public void Preprocess(IServiceRequest request)
 {
     foreach (var preprocessor in _preProcessors)
     {
         preprocessor.Preprocess(request);
     }
 }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:12,代码来源:CompositePreProcessor.cs

示例8: ProcessRequest

 public override void ProcessRequest(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository)
 {
     EAEPMessages messages = new EAEPMessages(request.Body);
     monitorStore.PushMessages(messages);
     response.StatusCode = Constants.HTTP_200_OK;
     response.StatusDescription = "OK";
 }
开发者ID:adambird,项目名称:eaep,代码行数:7,代码来源:EventService.cs

示例9: GetOperationDescriptor

        /// <summary>
        /// 得到操作元数据
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public virtual IOperationDescriptor GetOperationDescriptor(IServiceRequest req)
        {
            Guard.NotNull(req, "req");
            var serviceDescriptor = DescriptorManager.GetServiceDescriptor(req.ServiceName);
            if (serviceDescriptor == null)
                throw new ServiceDispatcherException(
                        ServiceDispatcherExceptionCode.ServiceNotFound)
                {
                    ServiceName = req.ServiceName
                    ,
                    OperationName = req.OperationName
                };

            //得到领域Action元数据
            var operationDesc = serviceDescriptor[req.OperationName];
            if (operationDesc == null)
                throw new ServiceDispatcherException(
                        ServiceDispatcherExceptionCode.OperationNotFound)
                {
                    ServiceName = req.ServiceName
                    ,
                    OperationName = req.OperationName
                };

            return operationDesc;
        }
开发者ID:netcasewqs,项目名称:nlite,代码行数:31,代码来源:DefaultServiceDispatcher.cs

示例10: GetMyObject

 public async System.Threading.Tasks.Task<IServiceResponse<MyObject>> GetMyObject(IServiceRequest<int> id)
 {
     // so we use the same validation mechanism that's used over in the Direct service implementation in
     // ../WebAPIDemos.ServiceLayer.Direct/MyObjectService.cs
     id.MustNotBeNull("id");
     //note - I'm using await here to handle the implicit casting of ApiServiceResponse<T> to IServiceResponse<T>
     return await _requestManager.Get<ApiServiceResponse<MyObject>>(string.Format("api/MyObjects/{0}", id.Argument.ToString()), id);
 }
开发者ID:LordZoltan,项目名称:WebAPIDemos,代码行数:8,代码来源:MyObjectService.cs

示例11: WriteContent

 protected void WriteContent(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository)
 {
     response.ContentType = "text/html";
        using (StreamWriter targetWriter = new StreamWriter(response.ContentStream))
     {
         InternalWriteContent(targetWriter, request, response, resourceRepository);
     }
 }
开发者ID:adambird,项目名称:eaep,代码行数:8,代码来源:HtmlPage.cs

示例12: WriteSearchResultHeader

 private static void WriteSearchResultHeader(StreamWriter writer, IServiceRequest request, IResourceRepository resourceRepository, string searchResultText)
 {
     string header = resourceRepository.GetResourceAsString("searchresultheader.htm");
     Hashtable values = new Hashtable();
     values.Add("queryparam", Constants.QUERY_STRING_QUERY);
     values.Add("query", request.Query);
     values.Add("searchresulttext", searchResultText);
     writer.WriteLine(TemplateParser.Parse(header, values));
 }
开发者ID:adambird,项目名称:eaep,代码行数:9,代码来源:SearchPage.cs

示例13: GetAuthorizationInfo

        public AuthorizationInfo GetAuthorizationInfo(IServiceRequest requestContext)
        {
            object cached;
            if (requestContext.Items.TryGetValue("AuthorizationInfo", out cached))
            {
                return (AuthorizationInfo)cached;
            }

            return GetAuthorization(requestContext);
        }
开发者ID:paul-777,项目名称:Emby,代码行数:10,代码来源:AuthorizationContext.cs

示例14: ValidateUser

        private void ValidateUser(IServiceRequest request,
            IAuthenticationAttributes authAttribtues)
        {
            // This code is executed before the service
            var auth = AuthorizationContext.GetAuthorizationInfo(request);

            if (!IsExemptFromAuthenticationToken(auth, authAttribtues))
            {
                var valid = IsValidConnectKey(auth.Token);

                if (!valid)
                {
                    ValidateSecurityToken(request, auth.Token);
                }
            }

            var user = string.IsNullOrWhiteSpace(auth.UserId)
                ? null
                : UserManager.GetUserById(auth.UserId);

            if (user == null & !string.IsNullOrWhiteSpace(auth.UserId))
            {
                throw new SecurityException("User with Id " + auth.UserId + " not found");
            }

            if (user != null)
            {
                ValidateUserAccess(user, request, authAttribtues, auth);
            }

            var info = GetTokenInfo(request);

            if (!IsExemptFromRoles(auth, authAttribtues, info))
            {
                var roles = authAttribtues.GetRoles().ToList();

                ValidateRoles(roles, user);
            }

            if (!string.IsNullOrWhiteSpace(auth.DeviceId) &&
                !string.IsNullOrWhiteSpace(auth.Client) &&
                !string.IsNullOrWhiteSpace(auth.Device))
            {
                SessionManager.LogSessionActivity(auth.Client,
                    auth.Version,
                    auth.DeviceId,
                    auth.Device,
                    request.RemoteIp,
                    user);
            }
        }
开发者ID:rezafouladian,项目名称:Emby,代码行数:51,代码来源:AuthService.cs

示例15: Handle

 public void Handle(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository)
 {
     try
     {
         ProcessRequest(request, response, resourceRepository);
         response.StatusCode = Constants.HTTP_200_OK;
         response.StatusDescription = "OK";
     }
     catch (Exception)
     {
         response.StatusCode = Constants.HTTP_500_SERVER_ERROR;
         response.StatusDescription = "Error, review logs";
     }
 }
开发者ID:adambird,项目名称:eaep,代码行数:14,代码来源:HttpService.cs


注:本文中的IServiceRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。