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"; }
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); } }
/// <summary> /// 创建ResponseData /// </summary> /// <param name="response"></param> /// <param name="attachments"></param> /// <returns></returns> private async Task <ResponseData> CreateResponseDataAsync(IServiceResponse response, IDictionary <string, byte[]> attachments) { return(new ResponseData() { Attachments = attachments, Data = await serializer.SerializeAsync(response) }); }
public virtual IServiceResponse Remove(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, InventoryItemServiceRemoveParameters> serviceRequest) { AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken); IServiceResponse results = null; OnRemove(serviceRequest, ref results); return(CompleteResponse(results)); }
public ApiServiceResponse(IServiceResponse source) { if (source == null) throw new ArgumentNullException("source"); ErrorMessage = source.ErrorMessage; Success = source.Success; Exception = source.Exception; }
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); } }
// como manejar esto ? // un SaveChanges por cada operacion (insert, update, ...) // o un solo SaveChanges por un batch de operaciones? public IServiceResponse SaveChanges() { DataServiceResponse resp = null; IServiceResponse queryResponse = null; if (this.container == null) { return(null); } try { resp = this.container.SaveChanges(SaveChangesOptions.ReplaceOnUpdate); // there should be only one! foreach (OperationResponse response in resp) { string message = "Cambios guardados satisfactoriamente."; int statusCode = response.StatusCode; Exception respEx = response.Error; // response.Headers queryResponse = new ServiceResponse(statusCode, message, respEx); break; } } catch (DataServiceRequestException e) { resp = e.Response; // there should be only one! foreach (OperationResponse response in resp) { string message = e.Message; int statusCode = response.StatusCode; Exception respEx = response.Error; // response.Headers queryResponse = new ServiceResponse(statusCode, message, respEx); break; } } catch (InvalidOperationException invalidOper) { queryResponse = new ServiceResponse(invalidOper); } catch (Exception Ex) { Type alas = Ex.GetType(); queryResponse = new ServiceResponse(Ex); } return(queryResponse); }
/// <summary> /// Invokes the specified action if <paramref name="serviceResponse"/>.IsLeft. /// Returns the current instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="action">The action to invoke.</param> /// <returns>The current <see cref="IServiceResponse{T}" /> instance.</returns> public static IServiceResponse <T> Catch <T>(this IServiceResponse <T> serviceResponse, Action <Error> action) { if (serviceResponse.IsLeft) { action.Invoke(serviceResponse.GetLeft()); } return(serviceResponse); }
/// <summary> /// Invokes the specified action if <see cref="IServiceResponse{T}.Error" /> is null. /// Returns the current <see cref="IServiceResponse{T}" /> instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="action">The action to invoke.</param> /// <returns>The current <see cref="IServiceResponse{T}" /> instance.</returns> public static IServiceResponse <T> Let <T>(this IServiceResponse <T> serviceResponse, Action <T> action) { if (serviceResponse.Error == null) { action.Invoke(serviceResponse.Data); } return(serviceResponse); }
public override void Update(object entity) { IServiceResponse resp = null; if (this.templateService != null) { resp = this.templateService.Update(entity); } }
protected void HandleSystemException(Exception ex, IServiceResponse response) { if (response != null) { response.Message = ex.Message; response.AddError(description: ex.ToString(), status: StatusCode.InternalServerError); } Logger.LogException(ex); }
public override async Task <int> SaveChangesAsync <T, C>(IServiceResponse <T, C> response) { SaveChangesInternal(); var returnValue = await base.SaveChangesAsync(); PostSave(response); return(returnValue); }
/// <summary> /// Sends the response for the specified request. /// </summary> public void SendResponse(uint requestId, IServiceResponse response) { if (response == null) throw new ArgumentNullException(nameof(response)); lock (DataLock) { // must queue the response if the channel is in the faulted state. if (State == TcpChannelState.Faulted) { m_queuedResponses[requestId] = response; return; } Utils.Trace("Channel {0}: SendResponse {1}", ChannelId, requestId); BufferCollection buffers = null; try { // note that the server does nothing if the message limits are exceeded. bool limitsExceeded = false; buffers = WriteSymmetricMessage( TcpMessageType.Message, requestId, CurrentToken, response, false, out limitsExceeded); } catch (Exception e) { SendServiceFault( CurrentToken, requestId, ServiceResult.Create(e, StatusCodes.BadEncodingError, "Could not encode outgoing message.")); return; } try { BeginWriteMessage(buffers, null); buffers = null; } catch (Exception) { if (buffers != null) { buffers.Release(BufferManager, "SendResponse"); } m_queuedResponses[requestId] = response; return; } } }
void IServiceDispatchListener.OnExceptionFired(IServiceRequest req, IServiceResponse resp, IOperationDescriptor operationDesc) { var handler = ExceptionFired; if (handler != null) { handler(req, resp, operationDesc); } }
/// <summary> /// Returns the error. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <returns>Error.</returns> /// <exception cref="System.InvalidOperationException">There is nothing to return from left of either - Error or Data.</exception> public static Error FromLeft <T>(this IServiceResponse <T> serviceResponse) { if (!serviceResponse.IsLeft) { throw new InvalidOperationException("There is nothing to return from left of either - Error or Data."); } return(serviceResponse.Error); }
/// <summary> /// If <paramref name="serviceResponse"/>.IsLeft, returns a new <see cref="IServiceResponse{T2}" /> instance with the current /// <paramref name="serviceResponse"/>.Error. Otherwise, it binds the <paramref name="serviceResponse"/>.Data into the specified /// <paramref name="bindingFunction" />. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="T2">The type of the next <see cref="IServiceResponse{T2}" /> to return.</typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="bindingFunction">The binding function.</param> /// <returns>Instance of <see cref="IServiceResponse{T2}" />.</returns> public static IServiceResponse <T2> Bind <T, T2>(this IServiceResponse <T> serviceResponse, Func <T, IServiceResponse <T2> > bindingFunction) { if (serviceResponse.IsLeft) { return(serviceResponse.CreateGenericErrorResponse <T, T2>(serviceResponse.GetLeft())); } return(bindingFunction.Invoke(serviceResponse.GetRight())); }
public virtual IServiceResponse CheckIn(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, InventoryItemServiceCheckInParameters> serviceRequest) { AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken); CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId); IServiceResponse results = null; OnCheckIn(serviceRequest, ref results); return(CompleteResponse(results)); }
public Task <int>[] CompleteAsync <T, C>(IServiceResponse <T, C> response) where T : class where C : class { var tasks = new List <Task <int> >(); UnitsOfWork.Values.Each(u => tasks.Add(u.SaveChangesAsync(response))); return(tasks.ToArray()); }
private static Boolean IsBuiltInErrorResponse <T>(this IServiceResponse <T> originalResponse) { var typeInfo = originalResponse.GetType().GetTypeInfo(); return(originalResponse is ErrorResponse <T> || (typeInfo.IsGenericType && typeof(ErrorResponse <>) .GetTypeInfo() .IsAssignableFrom(typeInfo.GetGenericTypeDefinition().GetTypeInfo()))); }
/// <summary> /// Returns the value of <typeparamref name="T"/> if there is no error. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <returns><typeparamref name="T"/>.</returns> /// <exception cref="System.InvalidOperationException">Cannot return right of either when left (errors) exist.</exception> public static T FromRight <T>(this IServiceResponse <T> serviceResponse) { if (serviceResponse.IsRight) { throw new InvalidOperationException("Cannot return right of either when left (errors) exist."); } return(serviceResponse.Data); }
/// <summary> /// If <seealso cref="IServiceResponse{T}.Error" /> is not null, returns a new <see cref="IServiceResponse{T2}" /> instance with the current /// <seealso cref="IServiceResponse{T}.Error" />. Else, binds the <seealso cref="IServiceResponse{T}.Data" /> into the specified <paramref name="bindingFunction" />. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="T2">The type of the next <see cref="IServiceResponse{T2}" /> to return.</typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="bindingFunction">The binding function.</param> /// <returns>Instance of <see cref="IServiceResponse{T2}" />.</returns> public static IServiceResponse <T2> Bind <T, T2>(this IServiceResponse <T> serviceResponse, Func <T, IServiceResponse <T2> > bindingFunction) { if (serviceResponse.Error != null) { return(CreateGenericErrorResponse <T, T2>(serviceResponse, serviceResponse.Error)); } return(bindingFunction.Invoke(serviceResponse.Data)); }
/// <summary> /// Invokes the specified action if <seealso cref="IServiceResponse{T}.Error" /> is not null. Returns the current instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="action">The action to invoke.</param> /// <returns>The current <see cref="IServiceResponse{T}" /> instance.</returns> public static IServiceResponse <T> Catch <T>(this IServiceResponse <T> serviceResponse, Action <Error> action) { if (serviceResponse.Error != null) { action.Invoke(serviceResponse.Error); } return(serviceResponse); }
/// <summary> /// Invokes the specified function if <seealso cref="IServiceResponse{T}.Error" /> is not null. Allows you to re-direct control flow with a new <typeparamref name="T" /> value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="continueWithFunction">The continue with function.</param> /// <returns>If errors exist, returns the instance of IServiceResponse{T} returned by <paramref name="continueWithFunction" />, else returns current instance.</returns> public static IServiceResponse <T> CatchAndContinue <T>(this IServiceResponse <T> serviceResponse, Func <Error, IServiceResponse <T> > continueWithFunction) { if (serviceResponse.Error != null) { return(continueWithFunction.Invoke(serviceResponse.Error)); } return(serviceResponse); }
/// <summary> /// Invokes the specified action if <paramref name="serviceResponse"/>.IsRight. /// Returns the current <see cref="IServiceResponse{T}" /> instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="action">The action to invoke.</param> /// <returns>The current <see cref="IServiceResponse{T}" /> instance.</returns> public static IServiceResponse <T> Let <T>(this IServiceResponse <T> serviceResponse, Action <T> action) { if (serviceResponse.IsRight) { action.Invoke(serviceResponse.GetRight()); } return(serviceResponse); }
/// <summary> /// Maps the <paramref name="responseTransferObject" /> to a new instance of <see cref="IServiceResponse{T2}" /> /// using AutoMapper. If errors exist, then this will act similarly to Bind{T2}() /// and return a new <see cref="ServiceResponse{T2}" /> with errors. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TTarget">The type of data to map to.</typeparam> /// <param name="responseTransferObject">The current service response instance.</param> /// <param name="mappingOperationOptions">The mapping operation options.</param> /// <returns>Maps the <paramref name="responseTransferObject" /> to a new instance of <see cref="IServiceResponse{T2}" /> /// using AutoMapper. If errors exist, then this will act similarly to Bind{T2}() /// and return a new <see cref="ServiceResponse{T2}" /> with errors.</returns> public static IServiceResponse <TTarget> Map <TSource, TTarget>(this IServiceResponse <TSource> responseTransferObject, Action <IMappingOperationOptions> mappingOperationOptions = null) { if (responseTransferObject.Error != null) { return(new ErrorResponse <TTarget>(responseTransferObject.Error)); } return(new DataResponse <TTarget>(Mapper.Map <TTarget>(responseTransferObject, mappingOperationOptions ?? (o => { })))); }
/// <summary> /// Returns the value of <typeparamref name="T"/> if there is no error. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <returns><typeparamref name="T"/>.</returns> /// <exception cref="System.InvalidOperationException">Cannot return right of either when left (errors) exist.</exception> public static T FromRight <T>(this IServiceResponse <T> serviceResponse) { if (!serviceResponse.IsRight) { throw new InvalidOperationException("Cannot return right of either when is left."); } return(serviceResponse.GetRight()); }
/// <summary> /// Returns the error. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <returns>Error.</returns> /// <exception cref="System.InvalidOperationException">There is nothing to return from left of either - Error or Data.</exception> public static Error FromLeft <T>(this IServiceResponse <T> serviceResponse) { if (!serviceResponse.IsLeft) { throw new InvalidOperationException("Cannot return left of either when is right."); } return(serviceResponse.GetLeft()); }
public override int SaveChanges <T, C>(IServiceResponse <T, C> response) { SaveChangesInternal(); var returnValue = base.SaveChanges(); PostSave(response); return(returnValue); }
/// <summary> /// If <paramref name="serviceResponse"/>.IsLeft, returns a new <see cref="IServiceResponse{T2}" /> instance with the current /// <paramref name="serviceResponse"/>.Error. Otherwise, it binds the <paramref name="serviceResponse"/>.Data into /// the specified <paramref name="mappingFunction" />. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="T2">The type of the next <see cref="IServiceResponse{T2}" /> to return.</typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="mappingFunction">The mapping function.</param> /// <returns>Instance of <see cref="IServiceResponse{T2}" />.</returns> public static IServiceResponse <T2> Fmap <T, T2>(this IServiceResponse <T> serviceResponse, Func <T, T2> mappingFunction) { if (serviceResponse.IsLeft) { return(serviceResponse.CreateGenericErrorResponse <T, T2>(serviceResponse.GetLeft())); } T2 result = mappingFunction.Invoke(serviceResponse.GetRight()); return(serviceResponse.CreateGenericDataResponse(result)); }
/// <summary> /// Invokes the specified <paramref name="continueWithFunction"/> function if <see cref="IServiceResponse{T}.IsLeft"/>. /// Allows you to re-direct control flow with a new <typeparamref name="T" /> value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="continueWithFunction">The continue with function.</param> /// <returns>If <paramref name="serviceResponse"/>.IsLeft, then the instance of <see cref="IServiceResponse{T}" /> /// returned by <paramref name="continueWithFunction" />, else returns current <paramref name="serviceResponse"/>.</returns> public static Task <IServiceResponse <T> > CatchAndContinueAsync <T>( this IServiceResponse <T> serviceResponse, Func <Error, Task <IServiceResponse <T> > > continueWithFunction) { if (serviceResponse.IsLeft) { return(continueWithFunction.Invoke(serviceResponse.GetLeft())); } return(Task.FromResult(serviceResponse)); }
/// <summary> /// Invokes the specified <paramref name="continueWithFunction"/> function if <paramref name="serviceResponse"/>.IsLeft. /// Allows you to re-direct control flow with a new <typeparamref name="T" /> value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="continueWithFunction">The continue with function.</param> /// <returns>If errors exist, returns the instance of IServiceResponse{T} returned by <paramref name="continueWithFunction" />, else returns current instance.</returns> public static IServiceResponse <T> CatchAndContinue <T>(this IServiceResponse <T> serviceResponse, Func <Error, T> continueWithFunction) { if (serviceResponse.IsLeft) { T result = continueWithFunction.Invoke(serviceResponse.GetLeft()); return(new DataResponse <T>(result)); } return(serviceResponse); }
/// <summary> /// If <seealso cref="IServiceResponse{T}.IsLeft" />, returns a new <see cref="IServiceResponse{T2}" /> instance with the current /// <seealso cref="IServiceResponse{T}.Error" />. Else, binds the <seealso cref="IServiceResponse{T}.Data" /> into the /// specified <paramref name="bindFunc" />. /// </summary> /// <typeparam name="T">The type of the current <see cref="IServiceResponse{T}"/>.</typeparam> /// <typeparam name="T2">The type of the next <see cref="IServiceResponse{T2}" /> to return.</typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="bindFunc">The binding function.</param> /// <returns>Instance of <see cref="IServiceResponse{T2}" />.</returns> public static Task <IServiceResponse <T2> > BindAsync <T, T2>( this IServiceResponse <T> serviceResponse, Func <T, Task <IServiceResponse <T2> > > bindFunc) { if (serviceResponse.IsLeft) { return(Task.FromResult(serviceResponse.CreateGenericErrorResponse <T, T2>(serviceResponse.GetLeft()))); } return(bindFunc(serviceResponse.GetRight())); }
/// <summary> /// If <seealso cref="IServiceResponse{T}.Error" /> is not null, returns a new <see cref="IServiceResponse{T2}" /> instance with the current /// <seealso cref="IServiceResponse{T}.Error" />. Else, binds the <seealso cref="IServiceResponse{T}.Data" /> into the specified <paramref name="mappingFunction" />. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="T2">The type of the next <see cref="IServiceResponse{T2}" /> to return.</typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="mappingFunction">The mapping function.</param> /// <returns>Instance of <see cref="IServiceResponse{T2}" />.</returns> public static IServiceResponse <T2> Fmap <T, T2>(this IServiceResponse <T> serviceResponse, Func <T, T2> mappingFunction) { if (serviceResponse.Error != null) { return(CreateGenericErrorResponse <T, T2>(serviceResponse, serviceResponse.Error)); } T2 result = mappingFunction.Invoke(serviceResponse.Data); return(CreateGenericDataResponse(serviceResponse, result)); }
/// <summary> /// Invokes the specified function if <seealso cref="IServiceResponse{T}.Error" /> is not null. Allows you to re-direct control flow with a new <typeparamref name="T" /> value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="serviceResponse">The service response.</param> /// <param name="continueWithFunction">The continue with function.</param> /// <returns>If errors exist, returns the instance of IServiceResponse{T} returned by <paramref name="continueWithFunction" />, else returns current instance.</returns> public static IServiceResponse <T> CatchAndContinue <T>(this IServiceResponse <T> serviceResponse, Func <Error, T> continueWithFunction) { if (serviceResponse.Error != null) { T result = continueWithFunction.Invoke(serviceResponse.Error); return(CreateGenericDataResponse <T>(serviceResponse, result)); } return(serviceResponse); }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { FindServersResponse body = response as FindServersResponse; if (body == null) { body = new FindServersResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new FindServersResponseMessage(body); }
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"; } }
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)); } }
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); } }
/// <summary> /// 监听异常 /// </summary> /// <param name="req"></param> /// <param name="resp"></param> /// <param name="operationDesc"></param> public override void OnExceptionFired(IServiceRequest req, IServiceResponse resp, IOperationDescriptor operationDesc) { IRedirectToErrorResult errorNav = null; if (operationDesc != null) { if (operationDesc.Extensions.ContainsKey(ControllerListener.ErrorNavigation)) errorNav = operationDesc.Extensions[ControllerListener.ErrorNavigation] as IRedirectToErrorResult; else if (operationDesc.ServiceDescriptor.Extensions.ContainsKey(ControllerListener.ErrorNavigation)) errorNav = operationDesc.ServiceDescriptor.Extensions[ControllerListener.ErrorNavigation] as IRedirectToErrorResult; } //执行失败后, 设置mvc的 controller serviceDispatcherName 和 ActionName if (errorNav != null) { req.Context[ControllerListener.NavigationResult] = errorNav; if (errorNav.IsSaveModelState) resp.Result = req.Arguments.FirstOrDefault();//TODO: } }
protected override void InternalWriteContent(StreamWriter writer, IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository) { resourceRepository.WriteResource("header.htm", writer); bool activeSearch = (request.Query != null); try { EAEPMessages messages = new EAEPMessages(); string searchResultText = string.Empty; if (activeSearch) { messages = monitor.GetMessages(request.Query); searchResultText = string.Format("{0} message(s) found", messages.Count); } WriteSearchResultHeader(writer, request, resourceRepository, searchResultText); int maxItems = 100; if (maxItems > messages.Count) { maxItems = messages.Count; } string messageTemplate = resourceRepository.GetResourceAsString("eaepmsg.htm"); for (int i = 0; i < maxItems; i++) { WriteResultItem(writer, messageTemplate, messages[i]); } } catch (Exception ex) { writer.WriteLine(ReplaceCRLFwithHTMLLineBreaks(ex.ToString())); } resourceRepository.WriteResource("searchresultfooter.htm", writer); resourceRepository.WriteResource("footer.htm", writer); }
/// <summary> /// Used to indicate that the asynchronous operation has completed. /// </summary> /// <param name="response">The response. May be null if an error is provided.</param> /// <param name="error"></param> public void OperationCompleted(IServiceResponse response, ServiceResult error) { // save response and/or error. m_error = null; m_response = response; if (ServiceResult.IsBad(error)) { m_error = new ServiceResultException(error); m_response = SaveExceptionAsResponse(m_error); } // operation completed. OperationCompleted(); }
/// <summary> /// Called when a response sent via the endpoint. /// </summary> /// <param name="response">The response.</param> protected virtual void OnResponseSent(IServiceResponse response) { }
private static void Dispose(IServiceResponse response) { IDisposable disposable = response as IDisposable; if (disposable != null) disposable.Dispose(); }
/// <summary> /// Sends the response for the specified request. /// </summary> public void SendResponse(uint requestId, IServiceResponse response) { if (response == null) throw new ArgumentNullException("response"); lock (DataLock) { // must queue the response if the channel is in the faulted state. if (State == TcpChannelState.Faulted) { m_queuedResponses[requestId] = response; return; } // Utils.Trace("Channel {0}: SendResponse {1}", ChannelId, requestId); BufferCollection buffers = null; try { // note that the server does nothing if the message limits are exceeded. bool limitsExceeded = false; buffers = WriteSymmetricMessage( TcpMessageType.Message, requestId, CurrentToken, response, false, out limitsExceeded); } catch (Exception e) { SendServiceFault( CurrentToken, requestId, ServiceResult.Create(e, StatusCodes.BadEncodingError, "Could not encode outgoing message.")); return; } try { BeginWriteMessage(buffers, Int32.MaxValue, null); buffers = null; } catch (Exception) { if (buffers != null) { buffers.Release(BufferManager, "SendResponse"); } m_queuedResponses[requestId] = response; return; } } }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { SetPublishingModeResponse body = response as SetPublishingModeResponse; if (body == null) { body = new SetPublishingModeResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new SetPublishingModeResponseMessage(body); }
/// <summary> /// Will write the resourcename as an html document. If sub class overrides this then /// sub class method must specify the content type. /// </summary> /// <param name="writer"></param> /// <param name="request"></param> /// <param name="response"></param> /// <param name="resourceRepository"></param> protected virtual void InternalWriteContent(StreamWriter writer, IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository) { writer.Write(resourceRepository.GetResourceAsString(request.ResourceName)); }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { DeleteSubscriptionsResponse body = response as DeleteSubscriptionsResponse; if (body == null) { body = new DeleteSubscriptionsResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new DeleteSubscriptionsResponseMessage(body); }
private void ProcessResponse(IServiceResponse response) { if (response.Token != null) { WaitFuture<IServiceRequest, IServiceResponse> f; if (_waitingRequests.TryRemove(response.Token, out f)) f.Response = response; } //_channel.FireResponseReceived(response); }
public abstract void ProcessRequest(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository);
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { ModifyMonitoredItemsResponse body = response as ModifyMonitoredItemsResponse; if (body == null) { body = new ModifyMonitoredItemsResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new ModifyMonitoredItemsResponseMessage(body); }
/// <summary> /// Called when a request completes. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="serviceName">The name of the service.</param> protected virtual void RequestCompleted(IServiceRequest request, IServiceResponse response, string serviceName) { uint requestHandle = 0; StatusCode statusCode = StatusCodes.Good; if (request != null) { requestHandle = request.RequestHeader.RequestHandle; } else if (response != null) { requestHandle = response.ResponseHeader.RequestHandle; statusCode = response.ResponseHeader.ServiceResult; } int pendingRequestCount = Interlocked.Decrement(ref m_pendingRequestCount); if (statusCode != StatusCodes.Good) { Utils.Trace( (int)Utils.TraceMasks.Service, "{0} Completed. RequestHandle={1}, PendingRequestCount={3}, StatusCode={2}", serviceName, requestHandle, statusCode, pendingRequestCount); } else { Utils.Trace( (int)Utils.TraceMasks.Service, "{0} Completed. RequestHandle={1}, PendingRequestCount={2}", serviceName, requestHandle, pendingRequestCount); } }
public void Handle(IServiceRequest request, IServiceResponse response) { Handle(request, response, new ResourceRepository()); }
/// <summary> /// 输出服务响应结果 /// </summary> /// <param name="httpContext"></param> /// <param name="serviceResponse"></param> public void Execute(IHttpContext httpContext, IServiceResponse serviceResponse) { if (!serviceResponse.Success && serviceResponse.Exception != null) return; //throw serviceResponse.Exception; var response = httpContext.Response; var contentType = httpContext.Request.AcceptTypes != null && httpContext.Request.AcceptTypes.Length > 0 ? httpContext.Request.AcceptTypes[0] :"json"; response.ContentType = contentType; try { var responseResult = ServiceResponseResolver.Resolve(httpContext, serviceResponse); var serializer = ContentHandlerTable.GetHandler(contentType); var strContent = serializer.Serialize(responseResult); response.Write(strContent); //response.Flush(); } catch (Exception ex) { throw new ServiceDispatcherException(ServiceDispatcherExceptionCode.ResponseSerializerException, ex); } }
/// <summary> /// 解析服务响应结果 /// </summary> /// <param name="httpContext"></param> /// <param name="serviceResponse"></param> /// <returns></returns> public object Resolve(IHttpContext httpContext, IServiceResponse serviceResponse) { var jsonResponse = httpContext.Request["_cs_"] != null ? new DotNetSuccessResponse(serviceResponse.Result) : new SuccessResponse(serviceResponse.Result); return jsonResponse; }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { ActivateSessionResponse body = response as ActivateSessionResponse; if (body == null) { body = new ActivateSessionResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new ActivateSessionResponseMessage(body); }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { GetEndpointsResponse body = response as GetEndpointsResponse; if (body == null) { body = new GetEndpointsResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new GetEndpointsResponseMessage(body); }
public void Handle(IServiceRequest request, IServiceResponse response, IResourceRepository resourceRepository) { WriteContent(request, response, resourceRepository); response.StatusCode = Constants.HTTP_200_OK; response.StatusDescription = "OK"; }
public void Send(IServiceResponse response) { _sendingQueue.Enqueue(response); }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { CloseSecureChannelResponse body = response as CloseSecureChannelResponse; if (body == null) { body = new CloseSecureChannelResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new CloseSecureChannelResponseMessage(body); }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { HistoryUpdateResponse body = response as HistoryUpdateResponse; if (body == null) { body = new HistoryUpdateResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new HistoryUpdateResponseMessage(body); }