/// <summary> /// Build the dashBoard grid /// </summary> /// <param name="userId">Id from User</param> public async Task BuildStructureGrid(long userId) { List <DashBoardWorkflowModel> _dashBoardWorkflows = new List <DashBoardWorkflowModel>(); AbstractServiceFactory service = _serviceFacade[ServiceFacade.SERVICENAME_USER]; HttpResponseMessageResult result = await service.Get("GetWorkflowInstance", new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("userId", userId.ToString()) }); if (result != null && !string.IsNullOrWhiteSpace(result.Json)) { IEnumerable <WorkflowInstance> workflowInstances = JsonConvert.DeserializeObject <List <WorkflowInstance> >(result.Json); foreach (WorkflowInstance workflowInstance in workflowInstances) { _dashBoardWorkflows.Add(await SetDashBoardWorkflowModel(workflowInstance)); } } DashBoardWorkflows = _dashBoardWorkflows; }
/// <summary> /// This method permits to initialize the workflow model. /// </summary> /// <param name="workflowInstance"></param> /// <returns></returns> private async Task <DashBoardWorkflowModel> SetDashBoardWorkflowModel(WorkflowInstance workflowInstance) { DashBoardWorkflowModel workflow = new DashBoardWorkflowModel(); workflow.WorkflowInstanceId = workflowInstance.Id; workflow.Title = string.IsNullOrWhiteSpace(workflowInstance.Name) ? $"WorkflowInstance{workflowInstance.Id}" : workflowInstance.Name; long workflowModifyTotal = 0, workflowValidatedTotal = 0; List <DashBoardSectionModel> sections = new List <DashBoardSectionModel>(); AbstractServiceFactory service = _serviceFacade[ServiceFacade.SERVICENAME_SELECTORCONFIG]; HttpResponseMessageResult result = await service.Get("Selectors", new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("WorkflowInstanceId", workflowInstance.Id.ToString()) }); if (result != null && !string.IsNullOrWhiteSpace(result.Json)) { IEnumerable <SelectorConfig> selectorConfigs = JsonConvert.DeserializeObject <List <SelectorConfig> >(result.Json); if (selectorConfigs != null) { foreach (SelectorConfig selectorConfig in selectorConfigs) { DashBoardSectionModel section = new DashBoardSectionModel(); long toDoTotal = 0, pendingValidationTotal = 0, validatedModifTotal = 0, validatedValidTotal = 0, toBeValidatedTotal = 0, notSubmitedTotal = 0; section.Modification = new DashBoardModificationActionModel(); section.Modification.Activities = SetModifications(selectorConfig, ref workflowModifyTotal, ref toDoTotal, ref pendingValidationTotal, ref validatedModifTotal); section.Modification.ToDoTotal = toDoTotal; section.Modification.PendingValidationTotal = pendingValidationTotal; section.Modification.ValidatedTotal = validatedModifTotal; section.Validation = new DashBoardValidationActionModel(); section.Validation.Activities = SetValidations(selectorConfig, ref workflowValidatedTotal, ref notSubmitedTotal, ref toBeValidatedTotal, ref validatedValidTotal); section.Validation.NotSubmitedTotal = notSubmitedTotal; section.Validation.ToBeValidatedTotal = toBeValidatedTotal; section.Validation.ValidatedTotal = validatedValidTotal; section.Description = selectorConfig.Description; section.DeadLine = null; sections.Add(section); } } } workflow.ModificationTotal = workflowModifyTotal; workflow.ValidationTotal = workflowValidatedTotal; workflow.Sections = sections; return(workflow); }
/// <summary> /// Effectue l'injection des services demandés. /// </summary> /// <param name="factory">Factory pour la communication avec le BusinessCore.</param> /// <returns>Message de retour</returns> public async Task <HttpResponseMessageResult> InjectConfig(ServiceFacade factory) { int cpt = 1; HttpResponseMessageResult res = new HttpResponseMessageResult() { IsSuccess = true }; foreach (Tuple <string, string, string, IEnumerable <KeyValuePair <string, string> >, KeyValuePair <string, string>, string> elt in _jsonServiceObjects) { try { string serviceName = elt.Item1; string httpVerb = elt.Item2; string subServiceName = elt.Item3; List <KeyValuePair <string, string> > qryStr = null; KeyValuePair <string, string> pairedReturn = elt.Item5; string body = elt.Item6; AbstractServiceFactory service = factory[serviceName]; if (service == null) { res.IsSuccess = false; res.Message += $"Service n° {cpt} - Le nom de service [{serviceName}] n'est pas connu."; return(res); } if (!string.IsNullOrWhiteSpace(pairedReturn.Value) && _references.ContainsKey(pairedReturn.Value)) { res.IsSuccess = false; res.Message += $"Service n° {cpt} - Une référence ({pairedReturn.Value}) existe déjà."; return(res); } // Transforme le body body = ReplaceGoodIds(body); // Transforme les querystring if (elt.Item4 != null) { qryStr = new List <KeyValuePair <string, string> >(); foreach (KeyValuePair <string, string> kvp in elt.Item4) { qryStr.Add(new KeyValuePair <string, string>(kvp.Key, ReplaceGoodIds(kvp.Value))); } } res.Message += $"Appel au service : [{serviceName}]/{subServiceName} ({httpVerb})"; // Globalisation HttpResponseMessageResult call = new HttpResponseMessageResult() { IsSuccess = true }; if (httpVerb == HTTP_VERB_POST) { call = await service.Post(subServiceName, qryStr, body); } if (httpVerb == HTTP_VERB_PUT) { call = await service.Put(subServiceName, qryStr, body); } if (httpVerb == HTTP_VERB_GET) { call = await service.Get(subServiceName, qryStr); } if ((call != null) && !call.IsSuccess) { res.IsSuccess = false; res.Message += $"Service n° {cpt} - Retour en erreur : {call.Message}"; res.Append(call); return(res); } JToken returnObj = null; if ((call != null) && !string.IsNullOrWhiteSpace(call.Json)) { returnObj = JsonConvert.DeserializeObject(call.Json, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }) as JToken; } if (!string.IsNullOrWhiteSpace(pairedReturn.Key) && !string.IsNullOrWhiteSpace(pairedReturn.Value) && (returnObj != null) && (returnObj[pairedReturn.Key] != null)) { long id = JsonConvert.DeserializeObject <long>(returnObj[pairedReturn.Key].ToString()); _references.Add(pairedReturn.Value, id); } res.Append(call); } catch (Exception ex) { res.IsSuccess = false; res.Message += $"Service n° {cpt} - Exception : {ex.Message}"; } cpt++; } return(res); }