• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IServiceRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Get

        public IServiceResponse Get(IServiceRequest request, IRequestSettings restSettings)
        {
            if (Auth != null)
                client.Authenticator = Auth;

            var restRequest = new RestRequest(request.Uri, Method.GET);
            var response = client.Execute(restRequest);

            return new ServiceResponse
            {
                Data = response.Content,
                StatusCode = response.StatusCode,
                ErrorException = response.ErrorException,
                ErrorMessage = response.ErrorMessage
            };
        }
开发者ID:FilipeDominguesGit,项目名称:GeoserverManager,代码行数:16,代码来源:RestService.cs


示例17: GetSession

        public Task<SessionInfo> GetSession(IServiceRequest requestContext)
        {
            var authorization = _authContext.GetAuthorizationInfo(requestContext);

            //if (!string.IsNullOrWhiteSpace(authorization.Token))
            //{
            //    var auth = GetTokenInfo(requestContext);
            //    if (auth != null)
            //    {
            //        return _sessionManager.GetSessionByAuthenticationToken(auth, authorization.DeviceId, requestContext.RemoteIp, authorization.Version);
            //    }
            //}

            var user = string.IsNullOrWhiteSpace(authorization.UserId) ? null : _userManager.GetUserById(authorization.UserId);
            return _sessionManager.LogSessionActivity(authorization.Client, authorization.Version, authorization.DeviceId, authorization.Device, requestContext.RemoteIp, user);
        }
开发者ID:rezafouladian,项目名称:Emby,代码行数:16,代码来源:SessionContext.cs


示例18: ProcessRequest

        public override void ProcessRequest(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository)
        {
            CountResult[] result = store.Count(
                DateTime.ParseExact(request.GetParameter(Constants.QUERY_STRING_FROM), Constants.FORMAT_DATETIME, CultureInfo.InvariantCulture),
                DateTime.ParseExact(request.GetParameter(Constants.QUERY_STRING_TO), Constants.FORMAT_DATETIME, CultureInfo.InvariantCulture),
                int.Parse(request.GetParameter(Constants.QUERY_STRING_TIMESLICES)),
                request.GetParameter(Constants.QUERY_STRING_GROUPBY),
                request.Query
                );

            response.ContentType = Constants.CONTENT_TYPE_JSON;

            using (StreamWriter writer = new StreamWriter(response.ContentStream))
            {
                writer.Write((string) JsonConvert.SerializeObject(result));
            }
        }
开发者ID:adambird,项目名称:eaep,代码行数:17,代码来源:CountService.cs


示例19: ProcessRequest

        public override void ProcessRequest(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository)
        {
            string[] values = store.Distinct(
                request.GetParameter(Constants.QUERY_STRING_FIELD),
                DateTime.ParseExact(request.GetParameter(Constants.QUERY_STRING_FROM), Constants.FORMAT_DATETIME, CultureInfo.InvariantCulture),
                DateTime.ParseExact(request.GetParameter(Constants.QUERY_STRING_TO), Constants.FORMAT_DATETIME, CultureInfo.InvariantCulture),
                request.Query
                );

            response.ContentType = Constants.CONTENT_TYPE_JSON;

            using (StreamWriter writer = new StreamWriter(response.ContentStream))
            {
                string json = JsonConvert.SerializeObject(values);
                writer.Write(json);
            }
        }
开发者ID:adambird,项目名称:eaep,代码行数:17,代码来源:DistinctService.cs


示例20: GetMyObject

        //note - for testability - a better implementation of this service would accept an IServiceCache abstraction
        //(name is actually irrelevant - it'd be a proprietary type for this solution),
        //and then one implementation of that would operate over the HostingEnvironment.Cache; making it
        //possible to isolate this class in a unit test with a mocked IServiceCache implementation.

        public async System.Threading.Tasks.Task<IServiceResponse<MyObject>> GetMyObject(IServiceRequest<int> id)
        {
            id.MustNotBeNull("id");
            string cacheKey = MyObjectCacheKey(id.Argument);
            //do caching 
            MyObject cached = (MyObject)HostingEnvironment.Cache[cacheKey];
            if (cached != null)
                return cached.AsSuccessfulResponse();

            //try and retrieve the object from the inner service.  The logic here is if we get a successful response, then 
            //we will cache it.  Otherwise we will simply return the response.  So, crucially, failed lookups are never cached in
            //this implementation - which, in practise, might not be desirable.
            var response = await _inner.GetMyObject(id);

            if (response.Success)
                HostingEnvironment.Cache.Insert(cacheKey, response.Result, null, DateTime.UtcNow.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);

            return response;
        }
开发者ID:LordZoltan,项目名称:WebAPIDemos,代码行数:24,代码来源:MyCachingObjectService.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IServiceResponse类代码示例发布时间:2022-05-24
下一篇:
C# IServiceRegistry类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap