/// <summary>
        /// Executes the query.
        /// </summary>
        /// <param name="queryText">The query text.</param>
        /// <param name="jsonText">The json text.</param>
        /// <returns>Task.</returns>
        private async Task ExecuteQuery(string queryText, string jsonText = "{}")
        {
            // top level services to execute the query
            var queryPipeline = _serviceProvider.GetService <ISchemaPipeline <GraphSchema, GraphQueryExecutionContext> >();
            var writer        = _serviceProvider.GetService <IGraphResponseWriter <GraphSchema> >();

            // parse the json doc, simulating a request recieved to the QueryController
            var inputVars = InputVariableCollection.FromJsonDocument(jsonText);

            var query = new GraphQueryData()
            {
                Query     = queryText,
                Variables = inputVars ?? InputVariableCollection.Empty,
            };

            var request = new GraphOperationRequest(query);
            var context = new GraphQueryExecutionContext(request, _serviceProvider, null);

            // execute
            await queryPipeline.InvokeAsync(context, default);

            var response = context.Result;

            if (response.Messages.Count > 0)
            {
                throw new InvalidOperationException("Query failed: " + response.Messages[0].Message);
            }

            // simulate writing hte result to an output stream
            string result = null;

            using (var memStream = new MemoryStream())
            {
                await writer.WriteAsync(memStream, response);

                memStream.Seek(0, SeekOrigin.Begin);
                using (var streamReader = new StreamReader(memStream))
                    result = streamReader.ReadToEnd();
            }

            if (result == null)
            {
                throw new InvalidOperationException("Query failed: No Response was serialized");
            }
        }
Ejemplo n.º 2
0
        public async Task <IResolvedVariableCollection> CreateResolvedVariableCollection(string queryText, string jsonDoc)
        {
            var server = new TestServerBuilder()
                         .AddGraphType <VariableTestController>()
                         .Build();

            var plan = await server.CreateQueryPlan(queryText);

            if (plan.Messages.Count > 0)
            {
                Assert.Fail(plan.Messages[0].Message);
            }

            var operation = plan.Operations.First().Value;

            var resolver = new ResolvedVariableGenerator(server.Schema, operation);

            var variableSet = InputVariableCollection.FromJsonDocument(jsonDoc);

            return(resolver.Resolve(variableSet));
        }
        public static string CreateJob(string sessionId, string process_ID, long requestNumber, InputVariableCollection inputVarCollection = null)
        {
            // Set up the create new job method
            // Create a job service client so we call the methods in the job service e.g. createjob etc

            var jobSvc = new KTA_JobServices.JobServiceClient();

            // Set up variables for the CreateJob method. Create job requires sessionid, process identity, and process initialization variables (input variables)
            // CreateJob method returns the Job Identity (Job Id).
            var procIdentity = new KTA_JobServices.ProcessIdentity();
            var jobInit      = new KTA_JobServices.JobInitialization();

            // These variables are used for the return object (job identity)
            var jobIdentity = new KTA_JobServices.JobIdentity();

            // This is the process identity of the Loan Application API process. This Id was obtained by running a select * from the Business_Process table
            procIdentity.Id = process_ID;


            if (inputVarCollection == null)
            {
                inputVarCollection = new KTA_JobServices.InputVariableCollection();

                // Set up each inputvariable to job (process initialization variables)
                // Must use the ID of the variable in the process, not its display name
                KTA_JobServices.InputVariable id = new KTA_JobServices.InputVariable();
                id.Id    = "REQUESTID";
                id.Value = requestNumber;
                inputVarCollection.Add(id);
            }

            // Populate the InputVariables to the job
            jobInit.InputVariables = inputVarCollection;

            // Create the job, passing the session id, process identity and inputvariables. A job identity object containing the job id(string) is returned
            // from the method call
            jobIdentity = jobSvc.CreateJobAsync(sessionId, procIdentity, jobInit).GetAwaiter().GetResult();


            // Return the job id
            return(jobIdentity.Id);
        }