本文整理汇总了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();
}
});
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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";
}
示例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;
}
示例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);
}
示例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);
}
}
示例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));
}
示例13: GetAuthorizationInfo
public AuthorizationInfo GetAuthorizationInfo(IServiceRequest requestContext)
{
object cached;
if (requestContext.Items.TryGetValue("AuthorizationInfo", out cached))
{
return (AuthorizationInfo)cached;
}
return GetAuthorization(requestContext);
}
示例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);
}
}
示例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";
}
}