/// <summary> /// Processes Fulfillment of a Prometheus Service Request /// </summary> /// <param name="request"></param> private void ProcessRequest(IServiceRequest request) { Console.WriteLine("\n"); Displaymessage($"Processing new Request {request.Name}", MessageType.GoodNews); Script script = null; string code = GetCodeFromRequest(request); //see if there is any script for this if (code != null) { using (var context = new ServiceFulfillmentEngineContext()) { script = context.Scripts.FirstOrDefault(x => x.Action == request.Action && x.ApplicableCode == code); } } if (script != null) { Console.WriteLine($"Identified as executable on '{code}'"); ExecuteScriptForRequest(script, request); } ForwardRequest(request); FulfillPrometheusRequest(request); }
/// <summary> /// Returns the appropriate code for a Request provided one exists. /// Otherwise return null /// </summary> /// <param name="request"></param> /// <returns></returns> private string GetCodeFromRequest(IServiceRequest request) { using (var context = new ServiceFulfillmentEngineContext()) { IEnumerable <Script> highPriorityScripts = null; IEnumerable <Script> lowPriorityScripts = null; try { //get scripts highPriorityScripts = from s in context.Scripts where s.Priority == Priority.High select s; lowPriorityScripts = from s in context.Scripts where s.Priority == Priority.Low select s; } catch (Exception) { /* database empty or other db problem */ } string code = null; //try high priority codes available first if (highPriorityScripts != null) { code = (from r in request.ServiceRequestOptions where r.Code == (from s in highPriorityScripts where s.ApplicableCode == r.Code select s.ApplicableCode).FirstOrDefault() select r.Code).FirstOrDefault(); } //if not try for a lower priority codes if (code == null && lowPriorityScripts != null) { code = (from r in request.ServiceRequestOptions where r.Code == (from s in lowPriorityScripts where s.ApplicableCode == r.Code select s.ApplicableCode).FirstOrDefault() select r.Code).FirstOrDefault(); } return(code); } }