Ejemplo n.º 1
0
 public static BaseResponse Process(Request request)
 {
     BaseResponse response = null;
     var config = new ConfigReader(HostingEnvironment.MapPath("~/App_Data/ServerConfig.xml")).Read();
     var handlers = HandlerFactory.Find(request);
     try
     {
         foreach (var handler in handlers)
         {
             DataResponse dataResponse;
             if (handler.Process(request, config, out dataResponse))
             {
                 response = dataResponse;
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         var errorResponse = Utils.CreateResponse<ErrorResponse>();
         errorResponse.Message = ex.Message;
         errorResponse.Detail = ex.ToString();
         response = errorResponse;
     }
     return response;
 }
Ejemplo n.º 2
0
 public static IEnumerable<BaseHandler> Find(Request request)
 {
     if (string.IsNullOrEmpty(request.Handler))
         return _handlers.Take(1);
     var result = _handlers.Where(h => h.Handler == request.Handler);
     return result;
 }
Ejemplo n.º 3
0
 public Response Accept(Request id)
 {
     Response response = null;
     var config = new ConfigReader(HostingEnvironment.MapPath("~/App_Data/ServerConfig.xml")).Read();
     var handlers = HandlerFactory.Find(id);
     foreach (var handler in handlers)
     {
         if (handler.Process(id, config, out response))
             break;
     }
     return response;
 }
Ejemplo n.º 4
0
        public async Task<Response> Send(Request request)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = _uri;
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.PostAsJsonAsync("api/service/accept", request);
                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsAsync<Response>();
                    return content;
                }
                return null;
            }
        }
Ejemplo n.º 5
0
 public override bool Process(Request request, ServerConfig config, out Response response)
 {
     var schema = config.Schemas.FirstOrDefault(s => s.Id == request.Payload.Schema);
     if (schema != null)
     {
         var connection = config.Connections.FirstOrDefault(c => c.Id == schema.Connection);
         if (connection != null)
         {
             var dataAccess = DataFactory.Find(connection);
             if (dataAccess != null)
             {
                 var dataList = dataAccess.Process(request, connection, schema);
                 response = new Response { CreatedDate = DateTime.Now, Id = request.Id, Payload = new Payload { Schema = request.Payload.Schema, Data = dataList }, Tag = request.Tag };
                 return true;
             }
         }
     }
     response = null;
     return true;
 }
Ejemplo n.º 6
0
 public override bool Process(Request request, ServerConfig config, out DataResponse dataResponse)
 {
     var schema = config.Schemas.FirstOrDefault(s => s.Id == request.Payload.Schema);
     if (schema != null)
     {
         var connection = config.Connections.FirstOrDefault(c => c.Id == schema.Connection);
         if (connection != null)
         {
             var dataAccess = DataFactory.Find(connection);
             if (dataAccess != null)
             {
                 var dataList = dataAccess.Process(request, connection, schema);
                 dataResponse = Utils.CreateResponse<DataResponse>(true, request.Tag);
                 dataResponse.Payload = new Payload { Schema = request.Payload.Schema, Data = dataList };
                 return true;
             }
         }
     }
     dataResponse = null;
     return true;
 }
Ejemplo n.º 7
0
 public abstract bool Process(Request request, ServerConfig config, out DataResponse dataResponse);
Ejemplo n.º 8
0
 public abstract DataList Process(Request request, Connection connection, Schema schema);
Ejemplo n.º 9
0
 public BaseResponse Accept(Request id)
 {
     return DataProcessor.Process(id);
 }