Exemplo n.º 1
0
        public async Task <IActionResult> ExecuteService(string id, [FromBody] ExecuteServiceRequest executeService)
        {
            var service = dbContext.Services.Include(s => s.Hook).SingleOrDefault(x => x.Id == id);

            if (service == null)
            {
                return(NotFound());
            }

            var(outcomeContextParser, contextParsed) = hookContextParser.Parse(executeService.Context, service.Hook.Context);
            if (outcomeContextParser != null)
            {
                return(BadRequest(outcomeContextParser));
            }

            var(outcomePrefetchResolved, prefetchResolved) = await prefetchResolver.Resolve(executeService.Prefetch, service.Prefetch,
                                                                                            contextParsed, service.Hook.Context.ToDictionary(x => x.Field), executeService.FhirServer,
                                                                                            executeService.FhirAuthorization);

            if (outcomePrefetchResolved != null)
            {
                return(StatusCode(
                           outcomePrefetchResolved.Issue.Exists(x => x.Code == Hl7.Fhir.Model.OperationOutcome.IssueType.Security)
                        ? 412 : 400,
                           outcomePrefetchResolved));
            }

            executeService.Context  = contextParsed;
            executeService.Prefetch = prefetchResolved;

            var result = await dispatchExecuteService.Dispatch(executeService, service);

            return(new JsonResult(result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ejecuta un servicio de negocio.
        /// Si se produce el error:
        /// The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
        /// Se debe a un error que lanza una llamada asincrona en modo debug
        /// </summary>
        /// <param name="req">Clase que imlementa la interfaz IServiceContract datos de entrada para la  ejecución del servicio.</param>
        /// <returns>Clase que imlementa la interfaz IServiceContract con datos de respuesta del servicio.</returns>
        /// <returns>response</returns>
        public TResponse ExecuteService <TRequest, TResponse>(TRequest req)
            where TRequest : IServiceContract
            where TResponse : IServiceContract, new()
        {
            InitHost();

            req.InitializeHostContextInformation();

            ExecuteServiceRequest  wcfReq   = new ExecuteServiceRequest();
            ExecuteServiceResponse wcfRes   = null;
            JsonSerializerSettings settings = null;

            wcfReq.serviceName  = req.ServiceName;
            wcfReq.providerName = _ServiceMetadataProviderName;
            wcfReq.jsonRequets  = Newtonsoft.Json.JsonConvert.SerializeObject(req, Formatting.None);


            using (FwkServiceClient svcProxy = new WCFServiceReference.FwkServiceClient(binding, address))
            {
                svcProxy.Open();
                settings            = new JsonSerializerSettings();
                settings.Formatting = Formatting.None;

                wcfRes = svcProxy.ExecuteService(wcfReq);
            }
            TResponse response = Newtonsoft.Json.JsonConvert.DeserializeObject <TResponse>(wcfRes.ExecuteServiceResult, settings);

            response.InitializeHostContextInformation();
            return(response);
        }
Exemplo n.º 3
0
 public async Task <ExecuteServiceResponse> Dispatch(ExecuteServiceRequest executeService, CDSService service)
 {
     return(service.CodeType switch
     {
         CDSServiceCodeType.JSON => JsonConvert.DeserializeObject <ExecuteServiceResponse>(service.Code),
         CDSServiceCodeType.CSharp => await ServiceCSharpCodeRunner.Evaluate(service.Code,
                                                                             executeService.Context, executeService.Prefetch),
         _ => throw new System.NotImplementedException()
     });
Exemplo n.º 4
0
        /// <summary>
        /// Ejecuta un servicio de negocio.
        /// Si se produce el error:
        /// The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
        /// Se debe a un error que lanza una llamada asincrona en modo debug
        /// </summary>
        /// <param name="req">Clase que imlementa la interfaz IServiceContract datos de entrada para la  ejecución del servicio.</param>
        /// <returns>Clase que imlementa la interfaz IServiceContract con datos de respuesta del servicio.</returns>
        /// <returns>response</returns>
        public virtual TResponse ExecuteService <TRequest, TResponse>(TRequest req)
            where TRequest : IServiceContract
            where TResponse : IServiceContract, new()
        {
            InitilaizeBinding();
            TResponse response;

            req.InitializeHostContextInformation();

            ExecuteServiceRequest  wcfReq = new ExecuteServiceRequest();
            ExecuteServiceResponse wcfRes = null;

            wcfReq.serviceName  = req.ServiceName;
            wcfReq.providerName = _ServiceMetadataProviderName;
            wcfReq.jsonRequets  = Fwk.HelperFunctions.SerializationFunctions.SerializeObjectToJson <TRequest>(req);
            //wcfReq.xmlRequets = Fwk.HelperFunctions.SerializationFunctions.SerializeToXml(req);


            var channelFactory = new ChannelFactory <IFwkService>(binding, address);

            IFwkService client = null;

            try
            {
                client = channelFactory.CreateChannel();
                wcfRes = client.ExecuteService(wcfReq);
                ((ICommunicationObject)client).Close();
            }
            catch (Exception ex)
            {
                if (client != null)
                {
                    ((ICommunicationObject)client).Abort();
                }

                response = (TResponse)Fwk.HelperFunctions.ReflectionFunctions.CreateInstance <TResponse>();

                response.Error         = new ServiceError();
                response.Error.Class   = "WCFRrapperBase";
                response.Error.Message = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex);
                response.InitializeHostContextInformation();

                return(response);
            }



            response = (TResponse)Fwk.HelperFunctions.SerializationFunctions.DeSerializeObjectFromJson <TResponse>(wcfRes.ExecuteServiceResult);
            //TResponse response = (TResponse)Fwk.HelperFunction    s.SerializationFunctions.DeserializeFromXml(typeof(TResponse), wcfRes.ExecuteServiceResult);
            response.InitializeHostContextInformation();
            return(response);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Ejecuta un servicio de negocio.
        /// Si se produce el error:
        /// The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
        /// Se debe a un error que lanza una llamada asincrona en modo debug
        /// </summary>
        /// <param name="req">Clase que imlementa la interfaz IServiceContract datos de entrada para la  ejecución del servicio.</param>
        /// <returns>Clase que imlementa la interfaz IServiceContract con datos de respuesta del servicio.</returns>
        /// <returns>response</returns>
        public TResponse ExecuteService <TRequest, TResponse>(TRequest req)
            where TRequest : IServiceContract
            where TResponse : IServiceContract, new()
        {
            InitilaizeBinding();

            req.InitializeHostContextInformation();

            ExecuteServiceRequest  wcfReq = new ExecuteServiceRequest();
            ExecuteServiceResponse wcfRes = null;

            wcfReq.serviceName  = req.ServiceName;
            wcfReq.providerName = _ServiceMetadataProviderName;
            wcfReq.jsonRequets  = Fwk.HelperFunctions.SerializationFunctions.SerializeObjectToJson <TRequest>(req);


            var channelFactory = new ChannelFactory <IFwkService>(binding, address);

            IFwkService client = null;

            try
            {
                client = channelFactory.CreateChannel();
                client.ExecuteService(wcfReq);
                ((ICommunicationObject)client).Close();
            }
            catch (Exception ex)
            {
                if (client != null)
                {
                    ((ICommunicationObject)client).Abort();
                }
                throw ex;
            }



            TResponse response = (TResponse)Fwk.HelperFunctions.SerializationFunctions.DeSerializeObjectFromJson <TResponse>(wcfRes.ExecuteServiceResult);

            response.InitializeHostContextInformation();
            return(response);
        }