public async Task Handle(eFormCompleted message) { #region get case information WriteLogEntry($"eFormCompletedHandler.Handle: we got called for message.caseId {message.caseId} and message.checkId {message.checkId}"); CaseDto caseDto = await _sdkCore.CaseLookup(message.caseId, message.checkId).ConfigureAwait(false); ReplyElement replyElement = await _sdkCore.CaseRead(message.caseId, message.checkId).ConfigureAwait(false); OuterInnerResourceSite machineAreaSite = _dbContext.OuterInnerResourceSites.SingleOrDefault(x => x.MicrotingSdkCaseId == message.caseId); ResourceTimeRegistration machineAreaTimeRegistration = await _dbContext.ResourceTimeRegistrations.SingleOrDefaultAsync(x => x.DoneAt == replyElement.DoneAt && x.SDKCaseId == (int)caseDto.CaseId && x.SDKSiteId == machineAreaSite.MicrotingSdkSiteId).ConfigureAwait(false); if (machineAreaTimeRegistration == null) { machineAreaTimeRegistration = new ResourceTimeRegistration(); if (machineAreaSite != null) { machineAreaTimeRegistration.OuterResourceId = machineAreaSite.OuterInnerResource.OuterResourceId; machineAreaTimeRegistration.InnerResourceId = machineAreaSite.OuterInnerResource.InnerResourceId; machineAreaTimeRegistration.DoneAt = replyElement.DoneAt; if (caseDto.CaseId != null) { machineAreaTimeRegistration.SDKCaseId = (int)caseDto.CaseId; } machineAreaTimeRegistration.SDKSiteId = machineAreaSite.MicrotingSdkSiteId; } CheckListValue dataElement = (CheckListValue)replyElement.ElementList[0]; foreach (var field in dataElement.DataItemList) { Field f = (Field)field; if (f.Label.ToLower().Contains("start/stop tid")) { Console.WriteLine($"The field is {f.Label}"); FieldValue fv = f.FieldValues[0]; String fieldValue = fv.Value; Console.WriteLine($"Current field_value is {fieldValue}"); int registeredTime = int.Parse(fieldValue.Split("|")[3]); Console.WriteLine($"We are setting the registered time to {registeredTime.ToString()}"); machineAreaTimeRegistration.SDKFieldValueId = fv.Id; machineAreaTimeRegistration.TimeInSeconds = (registeredTime / 1000); machineAreaTimeRegistration.TimeInMinutes = ((registeredTime / 1000) / 60); machineAreaTimeRegistration.TimeInHours = ((registeredTime / 1000) / 3600); } } #endregion await machineAreaTimeRegistration.Create(_dbContext).ConfigureAwait(false); } }
public static int Core_CaseRead([MarshalAs(UnmanagedType.BStr)] string microtingUId, [MarshalAs(UnmanagedType.BStr)] string checkUId, [MarshalAs(UnmanagedType.BStr)] ref string jsonReplyElement) { int result = 0; try { ReplyElement replyElement = core.CaseRead(microtingUId, checkUId); jsonReplyElement = new Packer().PackCoreElement(replyElement); } catch (Exception ex) { LastError.Value = ex.Message; result = 1; } return(result); }
public async Task Handle(eFormCompleted message) { var planningCaseSite = await _dbContext.PlanningCaseSites.SingleOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId); using MicrotingDbContext sdkDbContext = _sdkCore.dbContextHelper.GetDbContext(); if (planningCaseSite != null) { planningCaseSite.Status = 100; CaseDto caseDto = await _sdkCore.CaseReadByCaseId(message.caseId); var microtingUId = caseDto.MicrotingUId; var microtingCheckUId = caseDto.CheckUId; if (microtingUId != null && microtingCheckUId != null) { ReplyElement theCase = await _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId); planningCaseSite = await SetFieldValue(planningCaseSite, theCase.Id); planningCaseSite.MicrotingSdkCaseDoneAt = theCase.DoneAt; planningCaseSite.DoneByUserId = theCase.DoneById; var worker = await sdkDbContext.workers.SingleAsync(x => x.Id == planningCaseSite.DoneByUserId); planningCaseSite.DoneByUserName = $"{worker.FirstName} {worker.LastName}"; await planningCaseSite.Update(_dbContext); var planningCase = await _dbContext.PlanningCases.SingleOrDefaultAsync(x => x.Id == planningCaseSite.PlanningCaseId); if (planningCase.Status != 100) { planningCase.Status = 100; planningCase.MicrotingSdkCaseDoneAt = theCase.DoneAt; planningCase.MicrotingSdkCaseId = planningCaseSite.MicrotingSdkCaseId; planningCase.DoneByUserId = theCase.DoneById; planningCase.DoneByUserName = planningCaseSite.DoneByUserName; planningCase.WorkflowState = Constants.WorkflowStates.Processed; // planningCase.DoneByUserName = $"{site.Result.FirstName} {site.Result.LastName}"; planningCase = await SetFieldValue(planningCase, theCase.Id); await planningCase.Update(_dbContext); } await RetractFromMicroting(planningCase.Id); } } }
public async Task <IActionResult> DownloadEFormXml(int templateId) { if (!await _permissionsService.CheckEform(templateId, AuthConsts.EformClaims.EformsClaims.DownloadXml)) { return(Forbid()); } try { var core = await _coreHelper.GetCore(); var caseId = await core.CaseReadFirstId(templateId, "not_revmoed"); CaseDto caseDto = await core.CaseLookupCaseId((int)caseId); var language = await _userService.GetCurrentUserLanguage(); ReplyElement replyElement = await core.CaseRead((int)caseDto.MicrotingUId, (int)caseDto.CheckUId, language).ConfigureAwait(false); if (caseId != null) { var filePath = await core.CaseToJasperXml(caseDto, replyElement, (int)caseId, DateTime.Now.ToString("yyyyMMddHHmmssffff"), $"{core.GetSdkSetting(Settings.httpServerAddress)}/" + "api/template-files/get-image/", "", language); if (!System.IO.File.Exists(filePath)) { return(NotFound()); } var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); return(File(fileStream, "application/xml", Path.GetFileName(filePath))); } else { return(BadRequest()); } } catch (Exception) { return(BadRequest()); } }
public async Task SQL_Check_CheckRead_ReturnsReplyElement() { // Arrance #region Arrance Random rnd = new Random(); #region Template1 DateTime cl1_Ca = DateTime.Now; DateTime cl1_Ua = DateTime.Now; check_lists cl1 = await testHelpers.CreateTemplate(cl1_Ca, cl1_Ua, "A", "D", "CheckList", "Template1FolderName", 1, 1); #endregion #region SubTemplate1 check_lists cl2 = await testHelpers.CreateSubTemplate("A.1", "D.1", "CheckList", 1, 1, cl1); #endregion #region Fields #region field1 fields f1 = await testHelpers.CreateField(1, "barcode", cl2, "e2f4fb", "custom", null, "", "Comment field description", 5, 1, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 0, 0, 1, 0, "Comment field", 1, 55, "55", "0", 0, 0, null, 1, 0, 0, 0, "", 49); #endregion #region field2 fields f2 = await testHelpers.CreateField(1, "barcode", cl2, "f5eafa", "custom", null, "", "showPDf Description", 45, 1, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 0, 1, 0, 0, "ShowPdf", 0, 5, "5", "0", 0, 0, null, 0, 0, 0, 0, "", 9); #endregion #region field3 fields f3 = await testHelpers.CreateField(0, "barcode", cl2, "f0f8db", "custom", 3, "", "Number Field Description", 83, 0, dbContext.field_types.Where(x => x.FieldType == "number").First(), 0, 0, 1, 0, "Numberfield", 1, 8, "4865", "0", 0, 1, null, 1, 0, 0, 0, "", 1); #endregion #region field4 fields f4 = await testHelpers.CreateField(1, "barcode", cl2, "fff6df", "custom", null, "", "date Description", 84, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 0, 0, 1, 0, "Date", 1, 666, "41153", "0", 0, 1, null, 0, 1, 0, 0, "", 1); #endregion #region field5 fields f5 = await testHelpers.CreateField(0, "barcode", cl2, "ffe4e4", "custom", null, "", "picture Description", 85, 0, dbContext.field_types.Where(x => x.FieldType == "comment").First(), 1, 0, 1, 0, "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1); #endregion #endregion #region Worker workers worker = await testHelpers.CreateWorker("*****@*****.**", "Arne", "Jensen", 21); #endregion #region site sites site = await testHelpers.CreateSite("SiteName", 88); #endregion #region units units unit = await testHelpers.CreateUnit(48, 49, site, 348); #endregion #region site_workers site_workers site_workers = await testHelpers.CreateSiteWorker(55, site, worker); #endregion #region Case1 cases aCase = await testHelpers.CreateCase("caseUId", cl1, DateTime.Now, "custom", DateTime.Now, worker, rnd.Next(1, 255), rnd.Next(1, 255), site, 66, "caseType", unit, DateTime.Now, 1, worker, Constants.WorkflowStates.Created); #endregion #region Check List Values check_list_values check_List_Values = await testHelpers.CreateCheckListValue(aCase, cl2, "completed", null, 865); #endregion #region Field Values #region fv1 field_values field_Values1 = await testHelpers.CreateFieldValue(aCase, cl2, f1, null, null, "tomt1", 61234, worker); #endregion #region fv2 field_values field_Values2 = await testHelpers.CreateFieldValue(aCase, cl2, f2, null, null, "tomt2", 61234, worker); #endregion #region fv3 field_values field_Values3 = await testHelpers.CreateFieldValue(aCase, cl2, f3, null, null, "tomt3", 61234, worker); #endregion #region fv4 field_values field_Values4 = await testHelpers.CreateFieldValue(aCase, cl2, f4, null, null, "tomt4", 61234, worker); #endregion #region fv5 field_values field_Values5 = await testHelpers.CreateFieldValue(aCase, cl2, f5, null, null, "tomt5", 61234, worker); #endregion #endregion #endregion // Act ReplyElement match = await sut.CheckRead((int)aCase.MicrotingUid, (int)aCase.MicrotingCheckUid); // Assert #region Assert Assert.AreEqual(1, match.ElementList.Count()); CheckListValue clv = (CheckListValue)match.ElementList[0]; Assert.AreEqual(5, clv.DataItemList.Count); #region casts Field _f1 = (Field)clv.DataItemList[0]; Field _f2 = (Field)clv.DataItemList[1]; Field _f3 = (Field)clv.DataItemList[2]; Field _f4 = (Field)clv.DataItemList[3]; Field _f5 = (Field)clv.DataItemList[4]; #endregion #region Barcode Assert.AreEqual(f1.BarcodeEnabled, 1); Assert.AreEqual(f2.BarcodeEnabled, 1); Assert.AreEqual(f3.BarcodeEnabled, 0); Assert.AreEqual(f4.BarcodeEnabled, 1); Assert.AreEqual(f5.BarcodeEnabled, 0); Assert.AreEqual(f1.BarcodeType, "barcode"); Assert.AreEqual(f2.BarcodeType, "barcode"); Assert.AreEqual(f3.BarcodeType, "barcode"); Assert.AreEqual(f4.BarcodeType, "barcode"); Assert.AreEqual(f5.BarcodeType, "barcode"); #endregion #region chckl_id Assert.AreEqual(f1.CheckListId, cl2.Id); Assert.AreEqual(f2.CheckListId, cl2.Id); Assert.AreEqual(f3.CheckListId, cl2.Id); Assert.AreEqual(f4.CheckListId, cl2.Id); Assert.AreEqual(f5.CheckListId, cl2.Id); #endregion #region Color Assert.AreEqual(f1.Color, _f1.FieldValues[0].Color); Assert.AreEqual(f2.Color, _f2.FieldValues[0].Color); Assert.AreEqual(f3.Color, _f3.FieldValues[0].Color); Assert.AreEqual(f4.Color, _f4.FieldValues[0].Color); Assert.AreEqual(f5.Color, _f5.FieldValues[0].Color); #endregion #region custom // Assert.AreEqual(f1.custom, _f1.FieldValues[0].Id); #endregion #region Decimal_Count Assert.AreEqual(f1.DecimalCount, null); Assert.AreEqual(f2.DecimalCount, null); Assert.AreEqual(f3.DecimalCount, 3); Assert.AreEqual(f4.DecimalCount, null); Assert.AreEqual(f5.DecimalCount, null); #endregion #region Default_value Assert.AreEqual(f1.DefaultValue, ""); Assert.AreEqual(f2.DefaultValue, ""); Assert.AreEqual(f3.DefaultValue, ""); Assert.AreEqual(f4.DefaultValue, ""); Assert.AreEqual(f5.DefaultValue, ""); #endregion #region Description CDataValue f1desc = (CDataValue)_f1.Description; CDataValue f2desc = (CDataValue)_f2.Description; CDataValue f3desc = (CDataValue)_f3.Description; CDataValue f4desc = (CDataValue)_f4.Description; CDataValue f5desc = (CDataValue)_f5.Description; Assert.AreEqual(f1.Description, f1desc.InderValue); Assert.AreEqual(f2.Description, f2desc.InderValue); Assert.AreEqual(f3.Description, f3desc.InderValue); Assert.AreEqual(f4.Description, f4desc.InderValue); Assert.AreEqual(f5.Description, f5desc.InderValue); #endregion #region Displayindex Assert.AreEqual(f1.DisplayIndex, _f1.FieldValues[0].DisplayOrder); Assert.AreEqual(f2.DisplayIndex, _f2.FieldValues[0].DisplayOrder); Assert.AreEqual(f3.DisplayIndex, _f3.FieldValues[0].DisplayOrder); Assert.AreEqual(f4.DisplayIndex, _f4.FieldValues[0].DisplayOrder); Assert.AreEqual(f5.DisplayIndex, _f5.FieldValues[0].DisplayOrder); #endregion #region Dummy Assert.AreEqual(f1.Dummy, 1); Assert.AreEqual(f2.Dummy, 1); Assert.AreEqual(f3.Dummy, 0); Assert.AreEqual(f4.Dummy, 0); Assert.AreEqual(f5.Dummy, 0); #endregion #region geolocation #region enabled Assert.AreEqual(f1.GeolocationEnabled, 0); Assert.AreEqual(f2.GeolocationEnabled, 0); Assert.AreEqual(f3.GeolocationEnabled, 0); Assert.AreEqual(f4.GeolocationEnabled, 0); Assert.AreEqual(f5.GeolocationEnabled, 1); #endregion #region forced Assert.AreEqual(f1.GeolocationForced, 0); Assert.AreEqual(f2.GeolocationForced, 1); Assert.AreEqual(f3.GeolocationForced, 0); Assert.AreEqual(f4.GeolocationForced, 0); Assert.AreEqual(f5.GeolocationForced, 0); #endregion #region hidden Assert.AreEqual(f1.GeolocationHidden, 1); Assert.AreEqual(f2.GeolocationHidden, 0); Assert.AreEqual(f3.GeolocationHidden, 1); Assert.AreEqual(f4.GeolocationHidden, 1); Assert.AreEqual(f5.GeolocationHidden, 1); #endregion #endregion #region isNum Assert.AreEqual(f1.IsNum, 0); Assert.AreEqual(f2.IsNum, 0); Assert.AreEqual(f3.IsNum, 0); Assert.AreEqual(f4.IsNum, 0); Assert.AreEqual(f5.IsNum, 0); #endregion #region Label Assert.AreEqual(f1.Label, _f1.Label); Assert.AreEqual(f2.Label, _f2.Label); Assert.AreEqual(f3.Label, _f3.Label); Assert.AreEqual(f4.Label, _f4.Label); Assert.AreEqual(f5.Label, _f5.Label); #endregion #region Mandatory Assert.AreEqual(f1.Mandatory, 1); Assert.AreEqual(f2.Mandatory, 0); Assert.AreEqual(f3.Mandatory, 1); Assert.AreEqual(f4.Mandatory, 1); Assert.AreEqual(f5.Mandatory, 1); #endregion #region maxLength Assert.AreEqual(f1.MaxLength, 55); Assert.AreEqual(f2.MaxLength, 5); Assert.AreEqual(f3.MaxLength, 8); Assert.AreEqual(f4.MaxLength, 666); Assert.AreEqual(f5.MaxLength, 69); #endregion #region min/max_Value #region max Assert.AreEqual(f1.MaxValue, "55"); Assert.AreEqual(f2.MaxValue, "5"); Assert.AreEqual(f3.MaxValue, "4865"); Assert.AreEqual(f4.MaxValue, "41153"); Assert.AreEqual(f5.MaxValue, "69"); #endregion #region min Assert.AreEqual(f1.MinValue, "0"); Assert.AreEqual(f2.MinValue, "0"); Assert.AreEqual(f3.MinValue, "0"); Assert.AreEqual(f4.MinValue, "0"); Assert.AreEqual(f5.MinValue, "1"); #endregion #endregion #region Multi Assert.AreEqual(f1.Multi, 0); Assert.AreEqual(f2.Multi, 0); Assert.AreEqual(f3.Multi, 0); Assert.AreEqual(f4.Multi, 0); Assert.AreEqual(f5.Multi, 0); #endregion #region Optional Assert.AreEqual(f1.Optional, 0); Assert.AreEqual(f2.Optional, 0); Assert.AreEqual(f3.Optional, 1); Assert.AreEqual(f4.Optional, 1); Assert.AreEqual(f5.Optional, 1); #endregion #region Query_Type Assert.AreEqual(f1.QueryType, null); Assert.AreEqual(f2.QueryType, null); Assert.AreEqual(f3.QueryType, null); Assert.AreEqual(f4.QueryType, null); Assert.AreEqual(f5.QueryType, null); #endregion #region Read_Only Assert.AreEqual(f1.ReadOnly, 1); Assert.AreEqual(f2.ReadOnly, 0); Assert.AreEqual(f3.ReadOnly, 1); Assert.AreEqual(f4.ReadOnly, 0); Assert.AreEqual(f5.ReadOnly, 0); #endregion #region Selected Assert.AreEqual(f1.Selected, 0); Assert.AreEqual(f2.Selected, 0); Assert.AreEqual(f3.Selected, 0); Assert.AreEqual(f4.Selected, 1); Assert.AreEqual(f5.Selected, 1); #endregion #region Split_Screen Assert.AreEqual(f1.SplitScreen, 0); Assert.AreEqual(f2.SplitScreen, 0); Assert.AreEqual(f3.SplitScreen, 0); Assert.AreEqual(f4.SplitScreen, 0); Assert.AreEqual(f5.SplitScreen, 0); #endregion #region Stop_On_Save Assert.AreEqual(f1.StopOnSave, 0); Assert.AreEqual(f2.StopOnSave, 0); Assert.AreEqual(f3.StopOnSave, 0); Assert.AreEqual(f4.StopOnSave, 0); Assert.AreEqual(f5.StopOnSave, 0); #endregion #region Unit_Name Assert.AreEqual(f1.UnitName, ""); Assert.AreEqual(f2.UnitName, ""); Assert.AreEqual(f3.UnitName, ""); Assert.AreEqual(f4.UnitName, ""); Assert.AreEqual(f5.UnitName, ""); #endregion #region Values Assert.AreEqual(1, _f1.FieldValues.Count()); Assert.AreEqual(1, _f2.FieldValues.Count()); Assert.AreEqual(1, _f3.FieldValues.Count()); Assert.AreEqual(1, _f4.FieldValues.Count()); Assert.AreEqual(1, _f5.FieldValues.Count()); Assert.AreEqual(field_Values1.Value, _f1.FieldValues[0].Value); Assert.AreEqual(field_Values2.Value, _f2.FieldValues[0].Value); Assert.AreEqual(field_Values3.Value, _f3.FieldValues[0].Value); Assert.AreEqual(field_Values4.Value, _f4.FieldValues[0].Value); Assert.AreEqual(field_Values5.Value, _f5.FieldValues[0].Value); #endregion #region Version Assert.AreEqual(f1.Version, 49); Assert.AreEqual(f2.Version, 9); Assert.AreEqual(f3.Version, 1); Assert.AreEqual(f4.Version, 1); Assert.AreEqual(f5.Version, 1); #endregion #endregion }
public async Task Handle(eFormCompleted message) { WriteLogEntry($"eFormCompletedHandler.Handle: we got called for message.caseId {message.caseId} and message.checkId {message.checkId}"); await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext(); Language language = await microtingDbContext.Languages.SingleAsync(x => x.LanguageCode == "da"); CaseDto caseDto = await _sdkCore.CaseLookup(message.caseId, message.checkId).ConfigureAwait(false); ReplyElement replyElement = await _sdkCore.CaseRead(message.caseId, message.checkId, language).ConfigureAwait(false); OuterInnerResourceSite machineAreaSite = _dbContext.OuterInnerResourceSites.SingleOrDefault(x => x.MicrotingSdkCaseId == message.caseId); var machineAreaTimeRegistrations = await _dbContext.ResourceTimeRegistrations.Where(x => // x.DoneAt == replyElement.DoneAt && x.SDKCaseId == (int)caseDto.CaseId && x.SDKSiteId == machineAreaSite.MicrotingSdkSiteId).ToListAsync().ConfigureAwait(false); if (machineAreaTimeRegistrations.Count == 0) { ResourceTimeRegistration machineAreaTimeRegistration = new ResourceTimeRegistration(); if (machineAreaSite != null) { var outerInnerResource = await _dbContext.OuterInnerResources.SingleOrDefaultAsync(x => x.Id == machineAreaSite.OuterInnerResourceId); machineAreaTimeRegistration.OuterResourceId = outerInnerResource.OuterResourceId; machineAreaTimeRegistration.InnerResourceId = outerInnerResource.InnerResourceId; machineAreaTimeRegistration.DoneAt = replyElement.DoneAt; if (caseDto.CaseId != null) { machineAreaTimeRegistration.SDKCaseId = (int)caseDto.CaseId; } machineAreaTimeRegistration.SDKSiteId = machineAreaSite.MicrotingSdkSiteId; } CheckListValue dataElement = (CheckListValue)replyElement.ElementList[0]; foreach (var field in dataElement.DataItemList) { Field f = (Field)field; if (f.Label.ToLower().Contains("start/stop tid")) { try { Console.WriteLine($"The field is {f.Label}"); FieldValue fv = f.FieldValues[0]; String fieldValue = fv.Value; if (!string.IsNullOrEmpty(fieldValue)) { Console.WriteLine($"Current field_value is {fieldValue}"); int registeredTime = int.Parse(fieldValue.Split("|")[3]); Console.WriteLine($"We are setting the registered time to {registeredTime.ToString()}"); machineAreaTimeRegistration.SDKFieldValueId = fv.Id; machineAreaTimeRegistration.TimeInSeconds = (registeredTime / 1000); machineAreaTimeRegistration.TimeInMinutes = ((registeredTime / 1000) / 60); machineAreaTimeRegistration.TimeInHours = ((registeredTime / 1000) / 3600); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } await machineAreaTimeRegistration.Create(_dbContext).ConfigureAwait(false); } else { if (machineAreaTimeRegistrations.Count > 1) { int i = 0; foreach (ResourceTimeRegistration machineAreaTimeRegistration in machineAreaTimeRegistrations) { if (i > 0) { await machineAreaTimeRegistration.Delete(_dbContext); } i++; Console.WriteLine("More than one time registration found"); } } else { Console.WriteLine("One time registration found"); } } }
public async Task Handle(eFormCompleted message) { Console.WriteLine("[INF] EFormCompletedHandler.Handle: called"); try { _s3Enabled = _sdkCore.GetSdkSetting(Settings.s3Enabled).Result.ToLower() == "true"; _swiftEnabled = _sdkCore.GetSdkSetting(Settings.swiftEnabled).Result.ToLower() == "true"; string downloadPath = Path.Combine(Path.GetTempPath(), "reports", "results"); Directory.CreateDirectory(downloadPath); // Docx and PDF files string timeStamp = DateTime.UtcNow.ToString("yyyyMMdd") + "_" + DateTime.UtcNow.ToString("hhmmss"); string docxFileName = $"{timeStamp}{message.SiteId}_temp.docx"; string tempPDFFileName = $"{timeStamp}{message.SiteId}_temp.pdf"; string tempPDFFilePath = Path.Combine(downloadPath, tempPDFFileName); string newTaskIdValue = _dbContext.PluginConfigurationValues .SingleOrDefault(x => x.Name == "WorkOrdersBaseSettings:NewTaskId")?.Value; bool newTaskIdParseResult = int.TryParse(newTaskIdValue, out int newTaskId); if (!newTaskIdParseResult) { const string errorMessage = "[ERROR] New task eform id not found in setting"; Console.WriteLine(errorMessage); throw new Exception(errorMessage); } string taskListIdValue = _dbContext.PluginConfigurationValues .SingleOrDefault(x => x.Name == "WorkOrdersBaseSettings:TaskListId")?.Value; bool taskListIdParseResult = int.TryParse(taskListIdValue, out int taskListId); if (!taskListIdParseResult) { const string errorMessage = "[ERROR] Task list eform id not found in setting"; Console.WriteLine(errorMessage); throw new Exception(errorMessage); } string folderIdValue = _dbContext.PluginConfigurationValues .SingleOrDefault(x => x.Name == "WorkOrdersBaseSettings:FolderTasksId")?.Value; int?folderId; if (string.IsNullOrEmpty(folderIdValue) || folderIdValue == "0") { folderId = null; } else { bool folderIdParseResult = int.TryParse(folderIdValue, out int result); if (!folderIdParseResult) { var errorMessage = $"[ERROR] Folder id parse error. folderIdValue: {folderIdValue}"; Console.WriteLine(errorMessage); throw new Exception(errorMessage); } folderId = result; } await using MicrotingDbContext sdkDbContext = _sdkCore.DbContextHelper.GetDbContext(); if (message.CheckId == newTaskId) { WorkOrder workOrder = new WorkOrder(); workOrder.MicrotingId = message.MicrotingId; workOrder.CheckMicrotingUid = message.CheckUId; workOrder.CheckId = message.CheckId; Console.WriteLine("[INF] EFormCompletedHandler.Handle: message.CheckId == createNewTaskEFormId"); Language language = await sdkDbContext.Languages .SingleAsync(x => x.LanguageCode == "da"); ReplyElement replyElement = await _sdkCore.CaseRead(message.MicrotingId, message.CheckUId, language); var doneBy = sdkDbContext.Workers .Single(x => x.Id == replyElement.DoneById).full_name(); CheckListValue checkListValue = (CheckListValue)replyElement.ElementList[0]; List <Field> fields = checkListValue.DataItemList.Select(di => di as Field).ToList(); var picturesOfTasks = new List <string>(); if (fields.Any()) { // field[0] - picture of the task if (!string.IsNullOrEmpty(fields[3]?.FieldValues[0]?.Value)) { workOrder.Description = fields[3].FieldValues[0].Value; } if (!string.IsNullOrEmpty(fields[4]?.FieldValues[0]?.Value)) { workOrder.CorrectedAtLatest = DateTime.Parse(fields[4].FieldValues[0].Value); } if (fields[2].FieldValues.Count > 0) { foreach (FieldValue fieldValue in fields[2].FieldValues) { if (fieldValue.UploadedDataObj != null) { picturesOfTasks.Add($"{fieldValue.UploadedDataObj.Id}_700_{fieldValue.UploadedDataObj.Checksum}{fieldValue.UploadedDataObj.Extension}"); } } } } workOrder.CreatedAt = DateTime.UtcNow; workOrder.CreatedByUserId = replyElement.SiteMicrotingUuid; workOrder.WorkflowState = Constants.WorkflowStates.Created; workOrder.AssignedArea = fields[0].FieldValues[0].ValueReadable; workOrder.AssignedWorker = fields[1].FieldValues[0].ValueReadable; await workOrder.Create(_dbContext); foreach (var picturesOfTask in picturesOfTasks) { var pictureOfTask = new PicturesOfTask { FileName = picturesOfTask, WorkOrderId = workOrder.Id, }; await pictureOfTask.Create(_dbContext); } var folderResult = await _dbContext.PluginConfigurationValues.SingleAsync(x => x.Name == "WorkOrdersBaseSettings:FolderTasksId"); string folderMicrotingUid = sdkDbContext.Folders.Single(x => x.Id == folderId) .MicrotingUid.ToString(); var resourceString = "ServiceWorkOrdersPlugin.Resources.Templates.page.html"; var assembly = Assembly.GetExecutingAssembly(); string html; await using (var resourceStream = assembly.GetManifestResourceStream(resourceString)) { using var reader = new StreamReader(resourceStream ?? throw new InvalidOperationException($"{nameof(resourceStream)} is null")); html = await reader.ReadToEndAsync(); } // Read docx stream resourceString = "ServiceWorkOrdersPlugin.Resources.Templates.file.docx"; var docxFileResourceStream = assembly.GetManifestResourceStream(resourceString); if (docxFileResourceStream == null) { throw new InvalidOperationException($"{nameof(docxFileResourceStream)} is null"); } var docxFileStream = new MemoryStream(); await docxFileResourceStream.CopyToAsync(docxFileStream); await docxFileResourceStream.DisposeAsync(); string basePicturePath = Path.Combine(Path.GetTempPath(), "pictures", "workorders"); Directory.CreateDirectory(basePicturePath); var word = new WordProcessor(docxFileStream); string imagesHtml = ""; foreach (var imagesName in picturesOfTasks) { Console.WriteLine($"Trying to insert image into document : {imagesName}"); imagesHtml = await InsertImage(imagesName, imagesHtml, 700, 650, basePicturePath); } html = html.Replace("{%Content%}", imagesHtml); word.AddHtml(html); word.Dispose(); docxFileStream.Position = 0; // Build docx await using (var docxFile = new FileStream(Path.Combine(Path.GetTempPath(), "reports", "results", docxFileName), FileMode.Create, FileAccess.Write)) { docxFileStream.WriteTo(docxFile); } // Convert to PDF ReportHelper.ConvertToPdf(Path.Combine(Path.GetTempPath(), "reports", "results", docxFileName), downloadPath); File.Delete(docxFileName); // Upload PDF // string pdfFileName = null; string hash = await _sdkCore.PdfUpload(tempPDFFilePath); if (hash != null) { //rename local file FileInfo fileInfo = new FileInfo(tempPDFFilePath); fileInfo.CopyTo(downloadPath + "/" + hash + ".pdf", true); fileInfo.Delete(); await _sdkCore.PutFileToStorageSystem(Path.Combine(downloadPath, $"{hash}.pdf"), $"{hash}.pdf"); // TODO Remove from file storage? } List <AssignedSite> sites = await _dbContext.AssignedSites.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync(); foreach (AssignedSite site in sites) { Site sdkSite = await sdkDbContext.Sites.SingleAsync(x => x.MicrotingUid == site.SiteMicrotingUid); language = await sdkDbContext.Languages.SingleAsync(x => x.Id == sdkSite.LanguageId); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language.LanguageCode); MainElement mainElement = await _sdkCore.ReadeForm(taskListId, language); mainElement.Repeated = 1; mainElement.EndDate = DateTime.Now.AddYears(10).ToUniversalTime(); mainElement.StartDate = DateTime.Now.ToUniversalTime(); mainElement.CheckListFolderName = folderMicrotingUid; DateTime startDate = new DateTime(2020, 1, 1); mainElement.DisplayOrder = (workOrder.CorrectedAtLatest - startDate).Days; DataElement dataElement = (DataElement)mainElement.ElementList[0]; mainElement.Label = fields[3].FieldValues[0].Value; mainElement.PushMessageTitle = mainElement.Label; mainElement.PushMessageBody = (string.IsNullOrEmpty(fields[0].FieldValues[0].ValueReadable) || fields[0].FieldValues[0].ValueReadable == "null") ? "" : $"{fields[0].FieldValues[0].ValueReadable}"; mainElement.PushMessageBody += (string.IsNullOrEmpty(fields[1].FieldValues[0].ValueReadable) || fields[1].FieldValues[0].ValueReadable == "null") ? " (" :$" ({fields[1].FieldValues[0].ValueReadable}"; mainElement.PushMessageBody += string.IsNullOrEmpty(fields[4].FieldValues[0].Value) ? ")" : $"; {DateTime.Parse(fields[4].FieldValues[0].Value).ToString("dd.MM.yyyy")})"; dataElement.Label = fields[3].FieldValues[0].Value; dataElement.Description.InderValue += (string.IsNullOrEmpty(fields[0].FieldValues[0].ValueReadable) || fields[0].FieldValues[0].ValueReadable == "null") ? "" : $"<strong>{Translations.Area}:</strong> {fields[0].FieldValues[0].ValueReadable}<br>"; dataElement.Description.InderValue += (string.IsNullOrEmpty(fields[1].FieldValues[0].ValueReadable) || fields[1].FieldValues[0].ValueReadable == "null") ? "" :$"<strong>{Translations.AssignedTo}:</strong> {fields[1].FieldValues[0].ValueReadable}<br>"; dataElement.Description.InderValue += $"<strong>{Translations.TaskCreatedBy}:</strong> {doneBy}<br>"; dataElement.Description.InderValue += $"<strong>{Translations.DontAtTheLatst}:</strong>"; // Needs i18n support "Corrected at the latest:" dataElement.Description.InderValue += string.IsNullOrEmpty(fields[4].FieldValues[0].Value) ? "" : DateTime.Parse(fields[4].FieldValues[0].Value).ToString("dd.MM.yyyy"); dataElement.DataItemList[0].Description.InderValue = dataElement.Description.InderValue; dataElement.DataItemList[0].Label = dataElement.Label; // Read html and template if (hash != null) { ((ShowPdf)dataElement.DataItemList[1]).Value = hash; } int?caseId = await _sdkCore.CaseCreate(mainElement, "", site.SiteMicrotingUid, folderId); var wotCase = new WorkOrdersTemplateCase() { CheckId = message.CheckId, CheckMicrotingUid = message.CheckUId, WorkOrderId = workOrder.Id, CaseId = (int)caseId, CaseMicrotingUid = message.MicrotingId, SdkSiteMicrotingUid = site.SiteMicrotingUid }; await wotCase.Create(_dbContext); } } else if (message.CheckId == taskListId) { Console.WriteLine("[INF] EFormCompletedHandler.Handle: message.CheckId == createTaskListEFormId"); WorkOrdersTemplateCase workOrdersTemplate = await _dbContext.WorkOrdersTemplateCases.Where(x => x.CaseId == message.MicrotingId).FirstOrDefaultAsync(); WorkOrder workOrder = await _dbContext.WorkOrders.FindAsync(workOrdersTemplate.WorkOrderId); Language language = await sdkDbContext.Languages .SingleAsync(x => x.LanguageCode == "da"); ReplyElement replyElement = await _sdkCore.CaseRead(message.MicrotingId, message.CheckUId, language); CheckListValue checkListValue = (CheckListValue)replyElement.ElementList[0]; List <Field> fields = checkListValue.DataItemList.Select(di => di as Field).ToList(); List <WorkOrdersTemplateCase> wotListToDelete = await _dbContext.WorkOrdersTemplateCases.Where(x => x.WorkOrderId == workOrdersTemplate.WorkOrderId && x.CaseId != message.MicrotingId).ToListAsync(); foreach (WorkOrdersTemplateCase wotToDelete in wotListToDelete) { await _sdkCore.CaseDelete(wotToDelete.CaseId); wotToDelete.WorkflowState = Constants.WorkflowStates.Retracted; await wotToDelete.Update(_dbContext); } if (fields.Any()) { // field[3] - pictures of the done task if (fields[3].FieldValues.Count > 0) { foreach (FieldValue fieldValue in fields[3].FieldValues) { if (fieldValue.UploadedDataObj != null) { var pictureOfTask = new PicturesOfTaskDone { FileName = fieldValue.UploadedDataObj.FileName, WorkOrderId = workOrder.Id, }; await pictureOfTask.Create(_dbContext); } } } if (!string.IsNullOrEmpty(fields[4]?.FieldValues[0]?.Value)) { if (string.IsNullOrEmpty(workOrder.DescriptionOfTaskDone)) { workOrder.DescriptionOfTaskDone = fields[4].FieldValues[0].Value; } } // Add pictures, checkbox if (workOrder.DoneAt == null) { workOrder.DoneBySiteId = message.SiteId; workOrder.DoneAt = DateTime.UtcNow; } await workOrder.Update(_dbContext); } } } catch (Exception ex) { Console.WriteLine($"[ERR] ServiceWorkOrdersPlugin.CaseCompleted: Got the following error: {ex.Message}"); } }
public void SQL_Check_CheckRead_ReturnsReplyElement() { // Arrance #region Arrance #region Template1 DateTime cl1_Ca = DateTime.Now; DateTime cl1_Ua = DateTime.Now; check_lists cl1 = testHelpers.CreateTemplate(cl1_Ca, cl1_Ua, "A", "D", "CheckList", "Template1FolderName", 1, 1); #endregion #region SubTemplate1 check_lists cl2 = testHelpers.CreateSubTemplate("A.1", "D.1", "CheckList", 1, 1, cl1); #endregion #region Fields #region field1 fields f1 = testHelpers.CreateField(1, "barcode", cl2, "e2f4fb", "custom", null, "", "Comment field description", 5, 1, DbContext.field_types.Where(x => x.field_type == "comment").First(), 0, 0, 1, 0, "Comment field", 1, 55, "55", "0", 0, 0, null, 1, 0, 0, 0, "", 49); #endregion #region field2 fields f2 = testHelpers.CreateField(1, "barcode", cl2, "f5eafa", "custom", null, "", "showPDf Description", 45, 1, DbContext.field_types.Where(x => x.field_type == "comment").First(), 0, 1, 0, 0, "ShowPdf", 0, 5, "5", "0", 0, 0, null, 0, 0, 0, 0, "", 9); #endregion #region field3 fields f3 = testHelpers.CreateField(0, "barcode", cl2, "f0f8db", "custom", 3, "", "Number Field Description", 83, 0, DbContext.field_types.Where(x => x.field_type == "number").First(), 0, 0, 1, 0, "Numberfield", 1, 8, "4865", "0", 0, 1, null, 1, 0, 0, 0, "", 1); #endregion #region field4 fields f4 = testHelpers.CreateField(1, "barcode", cl2, "fff6df", "custom", null, "", "date Description", 84, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 0, 0, 1, 0, "Date", 1, 666, "41153", "0", 0, 1, null, 0, 1, 0, 0, "", 1); #endregion #region field5 fields f5 = testHelpers.CreateField(0, "barcode", cl2, "ffe4e4", "custom", null, "", "picture Description", 85, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0, "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1); #endregion #endregion #region Worker workers worker = testHelpers.CreateWorker("*****@*****.**", "Arne", "Jensen", 21); #endregion #region site sites site = testHelpers.CreateSite("SiteName", 88); #endregion #region units units unit = testHelpers.CreateUnit(48, 49, site, 348); #endregion #region site_workers site_workers site_workers = testHelpers.CreateSiteWorker(55, site, worker); #endregion #region Case1 cases aCase = testHelpers.CreateCase("caseUId", cl1, DateTime.Now, "custom", DateTime.Now, worker, "microtingCheckUId", "microtingUId", site, 66, "caseType", unit, DateTime.Now, 1, worker, Constants.WorkflowStates.Created); #endregion #region Check List Values check_list_values check_List_Values = testHelpers.CreateCheckListValue(aCase, cl2, "completed", null, 865); #endregion #region Field Values #region fv1 field_values field_Values1 = testHelpers.CreateFieldValue(aCase, cl2, f1, null, null, "tomt1", 61234, worker); #endregion #region fv2 field_values field_Values2 = testHelpers.CreateFieldValue(aCase, cl2, f2, null, null, "tomt2", 61234, worker); #endregion #region fv3 field_values field_Values3 = testHelpers.CreateFieldValue(aCase, cl2, f3, null, null, "tomt3", 61234, worker); #endregion #region fv4 field_values field_Values4 = testHelpers.CreateFieldValue(aCase, cl2, f4, null, null, "tomt4", 61234, worker); #endregion #region fv5 field_values field_Values5 = testHelpers.CreateFieldValue(aCase, cl2, f5, null, null, "tomt5", 61234, worker); #endregion #endregion #endregion // Act ReplyElement match = sut.CheckRead(aCase.microting_uid, aCase.microting_check_uid); // Assert #region Assert Assert.AreEqual(1, match.ElementList.Count()); CheckListValue clv = (CheckListValue)match.ElementList[0]; Assert.AreEqual(5, clv.DataItemList.Count); #region casts Field _f1 = (Field)clv.DataItemList[0]; Field _f2 = (Field)clv.DataItemList[1]; Field _f3 = (Field)clv.DataItemList[2]; Field _f4 = (Field)clv.DataItemList[3]; Field _f5 = (Field)clv.DataItemList[4]; #endregion #region Barcode Assert.AreEqual(f1.barcode_enabled, 1); Assert.AreEqual(f2.barcode_enabled, 1); Assert.AreEqual(f3.barcode_enabled, 0); Assert.AreEqual(f4.barcode_enabled, 1); Assert.AreEqual(f5.barcode_enabled, 0); Assert.AreEqual(f1.barcode_type, "barcode"); Assert.AreEqual(f2.barcode_type, "barcode"); Assert.AreEqual(f3.barcode_type, "barcode"); Assert.AreEqual(f4.barcode_type, "barcode"); Assert.AreEqual(f5.barcode_type, "barcode"); #endregion #region chckl_id Assert.AreEqual(f1.check_list_id, cl2.id); Assert.AreEqual(f2.check_list_id, cl2.id); Assert.AreEqual(f3.check_list_id, cl2.id); Assert.AreEqual(f4.check_list_id, cl2.id); Assert.AreEqual(f5.check_list_id, cl2.id); #endregion #region Color Assert.AreEqual(f1.color, _f1.FieldValues[0].Color); Assert.AreEqual(f2.color, _f2.FieldValues[0].Color); Assert.AreEqual(f3.color, _f3.FieldValues[0].Color); Assert.AreEqual(f4.color, _f4.FieldValues[0].Color); Assert.AreEqual(f5.color, _f5.FieldValues[0].Color); #endregion #region custom // Assert.AreEqual(f1.custom, _f1.FieldValues[0].Id); #endregion #region Decimal_Count Assert.AreEqual(f1.decimal_count, null); Assert.AreEqual(f2.decimal_count, null); Assert.AreEqual(f3.decimal_count, 3); Assert.AreEqual(f4.decimal_count, null); Assert.AreEqual(f5.decimal_count, null); #endregion #region Default_value Assert.AreEqual(f1.default_value, ""); Assert.AreEqual(f2.default_value, ""); Assert.AreEqual(f3.default_value, ""); Assert.AreEqual(f4.default_value, ""); Assert.AreEqual(f5.default_value, ""); #endregion #region Description CDataValue f1desc = (CDataValue)_f1.Description; CDataValue f2desc = (CDataValue)_f2.Description; CDataValue f3desc = (CDataValue)_f3.Description; CDataValue f4desc = (CDataValue)_f4.Description; CDataValue f5desc = (CDataValue)_f5.Description; Assert.AreEqual(f1.description, f1desc.InderValue); Assert.AreEqual(f2.description, f2desc.InderValue); Assert.AreEqual(f3.description, f3desc.InderValue); Assert.AreEqual(f4.description, f4desc.InderValue); Assert.AreEqual(f5.description, f5desc.InderValue); #endregion #region Displayindex Assert.AreEqual(f1.display_index, _f1.FieldValues[0].DisplayOrder); Assert.AreEqual(f2.display_index, _f2.FieldValues[0].DisplayOrder); Assert.AreEqual(f3.display_index, _f3.FieldValues[0].DisplayOrder); Assert.AreEqual(f4.display_index, _f4.FieldValues[0].DisplayOrder); Assert.AreEqual(f5.display_index, _f5.FieldValues[0].DisplayOrder); #endregion #region Dummy Assert.AreEqual(f1.dummy, 1); Assert.AreEqual(f2.dummy, 1); Assert.AreEqual(f3.dummy, 0); Assert.AreEqual(f4.dummy, 0); Assert.AreEqual(f5.dummy, 0); #endregion #region geolocation #region enabled Assert.AreEqual(f1.geolocation_enabled, 0); Assert.AreEqual(f2.geolocation_enabled, 0); Assert.AreEqual(f3.geolocation_enabled, 0); Assert.AreEqual(f4.geolocation_enabled, 0); Assert.AreEqual(f5.geolocation_enabled, 1); #endregion #region forced Assert.AreEqual(f1.geolocation_forced, 0); Assert.AreEqual(f2.geolocation_forced, 1); Assert.AreEqual(f3.geolocation_forced, 0); Assert.AreEqual(f4.geolocation_forced, 0); Assert.AreEqual(f5.geolocation_forced, 0); #endregion #region hidden Assert.AreEqual(f1.geolocation_hidden, 1); Assert.AreEqual(f2.geolocation_hidden, 0); Assert.AreEqual(f3.geolocation_hidden, 1); Assert.AreEqual(f4.geolocation_hidden, 1); Assert.AreEqual(f5.geolocation_hidden, 1); #endregion #endregion #region isNum Assert.AreEqual(f1.is_num, 0); Assert.AreEqual(f2.is_num, 0); Assert.AreEqual(f3.is_num, 0); Assert.AreEqual(f4.is_num, 0); Assert.AreEqual(f5.is_num, 0); #endregion #region Label Assert.AreEqual(f1.label, _f1.Label); Assert.AreEqual(f2.label, _f2.Label); Assert.AreEqual(f3.label, _f3.Label); Assert.AreEqual(f4.label, _f4.Label); Assert.AreEqual(f5.label, _f5.Label); #endregion #region Mandatory Assert.AreEqual(f1.mandatory, 1); Assert.AreEqual(f2.mandatory, 0); Assert.AreEqual(f3.mandatory, 1); Assert.AreEqual(f4.mandatory, 1); Assert.AreEqual(f5.mandatory, 1); #endregion #region maxLength Assert.AreEqual(f1.max_length, 55); Assert.AreEqual(f2.max_length, 5); Assert.AreEqual(f3.max_length, 8); Assert.AreEqual(f4.max_length, 666); Assert.AreEqual(f5.max_length, 69); #endregion #region min/max_Value #region max Assert.AreEqual(f1.max_value, "55"); Assert.AreEqual(f2.max_value, "5"); Assert.AreEqual(f3.max_value, "4865"); Assert.AreEqual(f4.max_value, "41153"); Assert.AreEqual(f5.max_value, "69"); #endregion #region min Assert.AreEqual(f1.min_value, "0"); Assert.AreEqual(f2.min_value, "0"); Assert.AreEqual(f3.min_value, "0"); Assert.AreEqual(f4.min_value, "0"); Assert.AreEqual(f5.min_value, "1"); #endregion #endregion #region Multi Assert.AreEqual(f1.multi, 0); Assert.AreEqual(f2.multi, 0); Assert.AreEqual(f3.multi, 0); Assert.AreEqual(f4.multi, 0); Assert.AreEqual(f5.multi, 0); #endregion #region Optional Assert.AreEqual(f1.optional, 0); Assert.AreEqual(f2.optional, 0); Assert.AreEqual(f3.optional, 1); Assert.AreEqual(f4.optional, 1); Assert.AreEqual(f5.optional, 1); #endregion #region Query_Type Assert.AreEqual(f1.query_type, null); Assert.AreEqual(f2.query_type, null); Assert.AreEqual(f3.query_type, null); Assert.AreEqual(f4.query_type, null); Assert.AreEqual(f5.query_type, null); #endregion #region Read_Only Assert.AreEqual(f1.read_only, 1); Assert.AreEqual(f2.read_only, 0); Assert.AreEqual(f3.read_only, 1); Assert.AreEqual(f4.read_only, 0); Assert.AreEqual(f5.read_only, 0); #endregion #region Selected Assert.AreEqual(f1.selected, 0); Assert.AreEqual(f2.selected, 0); Assert.AreEqual(f3.selected, 0); Assert.AreEqual(f4.selected, 1); Assert.AreEqual(f5.selected, 1); #endregion #region Split_Screen Assert.AreEqual(f1.split_screen, 0); Assert.AreEqual(f2.split_screen, 0); Assert.AreEqual(f3.split_screen, 0); Assert.AreEqual(f4.split_screen, 0); Assert.AreEqual(f5.split_screen, 0); #endregion #region Stop_On_Save Assert.AreEqual(f1.stop_on_save, 0); Assert.AreEqual(f2.stop_on_save, 0); Assert.AreEqual(f3.stop_on_save, 0); Assert.AreEqual(f4.stop_on_save, 0); Assert.AreEqual(f5.stop_on_save, 0); #endregion #region Unit_Name Assert.AreEqual(f1.unit_name, ""); Assert.AreEqual(f2.unit_name, ""); Assert.AreEqual(f3.unit_name, ""); Assert.AreEqual(f4.unit_name, ""); Assert.AreEqual(f5.unit_name, ""); #endregion #region Values Assert.AreEqual(1, _f1.FieldValues.Count()); Assert.AreEqual(1, _f2.FieldValues.Count()); Assert.AreEqual(1, _f3.FieldValues.Count()); Assert.AreEqual(1, _f4.FieldValues.Count()); Assert.AreEqual(1, _f5.FieldValues.Count()); Assert.AreEqual(field_Values1.value, _f1.FieldValues[0].Value); Assert.AreEqual(field_Values2.value, _f2.FieldValues[0].Value); Assert.AreEqual(field_Values3.value, _f3.FieldValues[0].Value); Assert.AreEqual(field_Values4.value, _f4.FieldValues[0].Value); Assert.AreEqual(field_Values5.value, _f5.FieldValues[0].Value); #endregion #region Version Assert.AreEqual(f1.version, 49); Assert.AreEqual(f2.version, 9); Assert.AreEqual(f3.version, 1); Assert.AreEqual(f4.version, 1); Assert.AreEqual(f5.version, 1); #endregion #endregion }
public async Task Handle(eFormCompleted message) { await using MicrotingDbContext sdkDbContext = _sdkCore.DbContextHelper.GetDbContext(); Console.WriteLine($"Checking PlanningCaseSites with MicrotingSdkCaseId == {message.caseId}"); Console.WriteLine($"Checking Cases with Id == {message.caseId}"); Console.WriteLine($"Checking Cases with MicrotingCheckUid == {message.CheckId}"); var planningCaseSite = await _dbContext.PlanningCaseSites.FirstOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId); var dbCase = await sdkDbContext.Cases.FirstOrDefaultAsync(x => x.Id == message.caseId) ?? await sdkDbContext.Cases.FirstOrDefaultAsync(x => x.MicrotingCheckUid == message.CheckId); if (planningCaseSite == null) { Console.WriteLine($"Checking CheckListSites with MicrotingUid == {message.MicrotingUId}"); var checkListSite = await sdkDbContext.CheckListSites.FirstOrDefaultAsync(x => x.MicrotingUid == message.MicrotingUId); if (checkListSite != null) { Console.WriteLine($"Checking PlanningCaseSites with MicrotingCheckListSitId == {checkListSite.Id}"); planningCaseSite = await _dbContext.PlanningCaseSites.FirstOrDefaultAsync(x => x.MicrotingCheckListSitId == checkListSite.Id); } } if (planningCaseSite != null) { Planning planning = await _dbContext.Plannings.FirstAsync(x => x.Id == planningCaseSite.PlanningId); Site site = await sdkDbContext.Sites.FirstAsync(x => x.Id == dbCase.SiteId); Language language = await sdkDbContext.Languages.FirstAsync(x => x.Id == site.LanguageId); if (dbCase.MicrotingUid != null && dbCase.MicrotingCheckUid != null) { ReplyElement theCase = await _sdkCore.CaseRead((int)dbCase.MicrotingUid, (int)dbCase.MicrotingCheckUid, language); if (planning.RepeatType == RepeatType.Day && planning.RepeatEvery == 0) { var planningCase = await _dbContext.PlanningCases.FirstOrDefaultAsync(x => x.Id == planningCaseSite.PlanningCaseId); if (planningCase != null && planningCase.Status != 100) { planningCase.Status = 100; planningCase.MicrotingSdkCaseDoneAt = theCase.DoneAt; planningCase.MicrotingSdkCaseId = dbCase.Id; planningCase.DoneByUserId = theCase.DoneById; planningCase.DoneByUserName = site.Name; planningCase.MicrotingSdkeFormId = (int)dbCase.CheckListId; planningCase.WorkflowState = Constants.WorkflowStates.Processed; planningCase = await SetFieldValue(planningCase, theCase.Id, language); await planningCase.Update(_dbContext); } else { if (planningCase == null || planningCase.MicrotingSdkCaseId != dbCase.Id) { planningCase = new PlanningCase { Status = 100, MicrotingSdkCaseDoneAt = theCase.DoneAt, MicrotingSdkCaseId = dbCase.Id, DoneByUserId = theCase.DoneById, DoneByUserName = site.Name, WorkflowState = Constants.WorkflowStates.Processed, MicrotingSdkeFormId = (int)dbCase.CheckListId, PlanningId = planning.Id }; await planningCase.Create(_dbContext); planningCase = await SetFieldValue(planningCase, theCase.Id, language); await planningCase.Update(_dbContext); } } } else { planningCaseSite.Status = 100; planningCaseSite = await SetFieldValue(planningCaseSite, theCase.Id, language); planningCaseSite.MicrotingSdkCaseDoneAt = theCase.DoneAt; planningCaseSite.DoneByUserId = theCase.DoneById; var worker = await sdkDbContext.Workers.SingleAsync(x => x.Id == planningCaseSite.DoneByUserId); planningCaseSite.DoneByUserName = $"{worker.FirstName} {worker.LastName}"; await planningCaseSite.Update(_dbContext); var planningCase = await _dbContext.PlanningCases.SingleOrDefaultAsync(x => x.Id == planningCaseSite.PlanningCaseId); if (planningCase.Status != 100) { planningCase.Status = 100; planningCase.MicrotingSdkCaseDoneAt = theCase.DoneAt; planningCase.MicrotingSdkCaseId = dbCase.Id; planningCase.DoneByUserId = theCase.DoneById; planningCase.DoneByUserName = site.Name; planningCase.WorkflowState = Constants.WorkflowStates.Processed; // planningCase.DoneByUserName = $"{site.Result.FirstName} {site.Result.LastName}"; planningCase = await SetFieldValue(planningCase, theCase.Id, language); await planningCase.Update(_dbContext); } planning.DoneInPeriod = true; await planning.Update(_dbContext); await RetractFromMicroting(planningCase.Id); } } } }
#pragma warning disable 1998 public async Task Handle(eFormCompleted message) { Console.WriteLine("[DBG] TrashInspection: We got a message : " + message.caseId); TrashInspectionCase trashInspectionCase = _dbContext.TrashInspectionCases.SingleOrDefault(x => x.SdkCaseId == message.caseId.ToString()); if (trashInspectionCase != null) { #region get case information CaseDto caseDto = await _sdkCore.CaseLookupMUId(message.caseId); await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext(); var microtingUId = caseDto.MicrotingUId; var microtingCheckUId = caseDto.CheckUId; Language language = await microtingDbContext.Languages.SingleAsync(x => x.Name == "Danish"); ReplyElement theCase = await _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language); CheckListValue dataElement = (CheckListValue)theCase.ElementList[0]; bool inspectionApproved = false; string approvedValue = ""; string comment = ""; Console.WriteLine("[DBG] Trying to find the field with the approval value"); foreach (var field in dataElement.DataItemList) { Field f = (Field)field; if (f.Label.Contains("Angiv om læs er Godkendt")) { Console.WriteLine($"The field is {f.Label}"); FieldValue fv = f.FieldValues[0]; String fieldValue = fv.Value; inspectionApproved = (fieldValue == "1"); approvedValue = fieldValue; Console.WriteLine($"[DBG] We are setting the approved state to {inspectionApproved.ToString()}"); } if (f.Label.Equals("Kommentar")) { Console.WriteLine($"[DBG] The field is {f.Label}"); FieldValue fv = f.FieldValues[0]; String fieldValue = fv.Value; comment = fieldValue; Console.WriteLine($"[DBG] We are setting the comment to {comment.ToString()}"); } } #endregion Console.WriteLine("TrashInspection: The incoming case is a trash inspection related case"); trashInspectionCase.Status = 100; await trashInspectionCase.Update(_dbContext); TrashInspection trashInspection = _dbContext.TrashInspections.SingleOrDefault(x => x.Id == trashInspectionCase.TrashInspectionId); if (trashInspection != null) { trashInspection.Status = 100; trashInspection.IsApproved = inspectionApproved; trashInspection.Comment = comment; trashInspection.ApprovedValue = approvedValue; trashInspection.InspectionDone = true; await trashInspection.Update(_dbContext); List <TrashInspectionCase> trashInspectionCases = _dbContext.TrashInspectionCases .Where(x => x.TrashInspectionId == trashInspection.Id).ToList(); foreach (TrashInspectionCase inspectionCase in trashInspectionCases) { if (await _sdkCore.CaseDelete(int.Parse(inspectionCase.SdkCaseId))) { inspectionCase.WorkflowState = Constants.WorkflowStates.Retracted; await inspectionCase.Update(_dbContext); } } #region get settings string callBackUrl = _dbContext.PluginConfigurationValues .SingleOrDefault(x => x.Name == "TrashInspectionBaseSettings:callBackUrl")?.Value; Console.WriteLine("[DBG] callBackUrl is : " + callBackUrl); string callBackCredentialDomain = _dbContext.PluginConfigurationValues.SingleOrDefault(x => x.Name == "TrashInspectionBaseSettings:CallBackCredentialDomain")?.Value; Console.WriteLine("[DBG] callBackCredentialDomain is : " + callBackCredentialDomain); string callbackCredentialUserName = _dbContext.PluginConfigurationValues.SingleOrDefault(x => x.Name == "TrashInspectionBaseSettings:callbackCredentialUserName")?.Value; Console.WriteLine("[DBG] callbackCredentialUserName is : " + callbackCredentialUserName); string callbackCredentialPassword = _dbContext.PluginConfigurationValues.SingleOrDefault(x => x.Name == "TrashInspectionBaseSettings:CallbackCredentialPassword")?.Value; Console.WriteLine("[DBG] callbackCredentialPassword is : " + callbackCredentialPassword); string callbackCredentialAuthType = _dbContext.PluginConfigurationValues.SingleOrDefault(x => x.Name == "TrashInspectionBaseSettings:CallbackCredentialAuthType")?.Value; Console.WriteLine("[DBG] callbackCredentialAuthType is : " + callbackCredentialAuthType); Console.WriteLine($"[DBG] trashInspection.WeighingNumber is {trashInspection.WeighingNumber}"); #endregion switch (callbackCredentialAuthType) { case "NTLM": await CallUrlNtlmAuth(callBackUrl, callBackCredentialDomain, callbackCredentialUserName, callbackCredentialPassword, trashInspection, inspectionApproved); break; case "basic": default: await CallUrlBaiscAuth(callBackUrl, callBackCredentialDomain, callbackCredentialUserName, callbackCredentialPassword, trashInspection, inspectionApproved); break; } } } }