Пример #1
0
        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);
            }
        }
Пример #2
0
        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
        }
Пример #3
0
        public async Task Handle(eFormCompleted message)
        {
            Console.WriteLine("[INF] EFormCompletedHandler.Handle: called");

            _s3Enabled    = _sdkCore.GetSdkSetting(Settings.s3Enabled).Result.ToLower() == "true";
            _swiftEnabled = _sdkCore.GetSdkSetting(Settings.swiftEnabled).Result.ToLower() == "true";
            string downloadPath = await _sdkCore.GetSdkSetting(Settings.fileLocationPdf);

            // 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;
            }

            if (message.CheckId == newTaskId)
            {
                WorkOrder workOrder = new WorkOrder();
                workOrder.MicrotingId = message.MicrotingId;
                workOrder.CheckUId    = message.CheckUId;
                workOrder.CheckId     = message.CheckId;

                Console.WriteLine("[INF] EFormCompletedHandler.Handle: message.CheckId == createNewTaskEFormId");
                ReplyElement replyElement = await _sdkCore.CaseRead(message.MicrotingId, message.CheckUId);

                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[1]?.FieldValues[0]?.Value))
                    {
                        workOrder.Description = fields[1].FieldValues[0].Value;
                    }

                    if (!string.IsNullOrEmpty(fields[2]?.FieldValues[0]?.Value))
                    {
                        workOrder.CorrectedAtLatest = DateTime.Parse(fields[2].FieldValues[0].Value);
                    }

                    if (fields[0].FieldValues.Count > 0)
                    {
                        foreach (FieldValue fieldValue in fields[0].FieldValues)
                        {
                            if (fieldValue.UploadedDataObj != null)
                            {
                                picturesOfTasks.Add(fieldValue.UploadedDataObj.FileName);
                            }
                        }
                    }
                }

                workOrder.CreatedAt       = DateTime.UtcNow;
                workOrder.CreatedByUserId = replyElement.SiteMicrotingUuid;
                workOrder.WorkflowState   = Constants.WorkflowStates.Created;
                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 = _sdkCore.dbContextHelper.GetDbContext().folders.Single(x => x.Id == folderId)
                                            .MicrotingUid.ToString();

                MainElement mainElement = await _sdkCore.TemplateRead(taskListId);

                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[1].FieldValues[0].Value;
                mainElement.PushMessageTitle = mainElement.Label;
                mainElement.PushMessageBody  = string.IsNullOrEmpty(fields[2].FieldValues[0].Value)
                    ? ""
                    : "Senest udbedret d.: " + DateTime.Parse(fields[2].FieldValues[0].Value).ToString("dd-MM-yyyy");
                dataElement.Label = fields[1].FieldValues[0].Value;
                dataElement.Description.InderValue  = "<strong>Senest udbedret d.: "; // Needs i18n support "Corrected at the latest:"
                dataElement.Description.InderValue += string.IsNullOrEmpty(fields[2].FieldValues[0].Value)
                    ? ""
                    : DateTime.Parse(fields[2].FieldValues[0].Value).ToString("dd-MM-yyyy");
                dataElement.Description.InderValue += "</strong>";

                dataElement.DataItemList[0].Description.InderValue = workOrder.Description;

                // Read html and template
                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 = await _sdkCore.GetSdkSetting(Settings.fileLocationPicture);

                var    word       = new WordProcessor(docxFileStream);
                string imagesHtml = "";

                foreach (var imagesName in picturesOfTasks)
                {
                    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(docxFileName, FileMode.Create, FileAccess.Write))
                {
                    docxFileStream.WriteTo(docxFile);
                }

                // Convert to PDF
                ReportHelper.ConvertToPdf(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?

                    ((ShowPdf)dataElement.DataItemList[1]).Value = hash;
                }

                List <AssignedSite> sites = await _dbContext.AssignedSites.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync();

                foreach (AssignedSite site in sites)
                {
                    int?caseId = await _sdkCore.CaseCreate(mainElement, "", site.SiteId, folderId);

                    var wotCase = new WorkOrdersTemplateCase()
                    {
                        CheckId     = message.CheckId,
                        CheckUId    = message.CheckUId,
                        WorkOrderId = workOrder.Id,
                        CaseId      = (int)caseId,
                        CaseUId     = message.MicrotingId,
                        SdkSiteId   = site.SiteId
                    };
                    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);

                ReplyElement replyElement = await _sdkCore.CaseRead(message.MicrotingId, message.CheckUId);

                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);
                }
            }
        }
Пример #4
0
        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
        }
Пример #5
0
        public void EventCaseCompleted(object sender, EventArgs args)
        {
            lock (_lockLogic)
            {
                try
                {
                    Case_Dto trigger  = (Case_Dto)sender;
                    int      siteId   = trigger.SiteUId;
                    string   caseType = trigger.CaseType;
                    string   caseUid  = trigger.CaseUId;
                    string   mUId     = trigger.MicrotingUId;
                    string   checkUId = trigger.CheckUId;


                    //--------------------
                    Random rdn = new Random();

                    #region create offering
                    if (caseType == "Step one")
                    {
                        CoreElement reply = core.CaseRead(mUId, checkUId);

                        CheckListValue replyDataE = (CheckListValue)reply.ElementList[0];
                        FieldValue     answer     = (FieldValue)replyDataE.DataItemList[0];

                        MainElement mainElement = core.TemplateRead(step2tId);
                        DataElement dataE       = (DataElement)mainElement.ElementList[0];
                        None        none        = (None)dataE.DataItemList[0];


                        none.Label                  = "Container with stat:" + answer.Value + " is ready for collection";
                        none.Description            = new CDataValue();
                        none.Description.InderValue = DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString();


                        foreach (int siteIdTemp in siteIdsSA)
                        {
                            core.CaseCreate(mainElement, "", siteIdTemp);
                        }
                    }
                    #endregion

                    #region create replies (winner/others)
                    if (caseType == "Step two")
                    {
                        #region is the first?
                        bool isFirst = false;
                        int  found   = 0;
                        try
                        {
                            List <Case_Dto> lst = core.CaseLookupCaseUId(caseUid);

                            foreach (var item in lst)
                            {
                                if (item.Stat == "Completed")
                                {
                                    found++;
                                }
                            }

                            if (found == 1)
                            {
                                isFirst = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("isFirst failed", ex);
                        }
                        #endregion

                        if (isFirst)
                        {
                            #region send win eForm
                            CoreElement reply = core.CaseRead(mUId, checkUId);

                            DataElement replyDataE = (DataElement)reply.ElementList[0];
                            FieldValue  answer     = (FieldValue)replyDataE.DataItemList[0];

                            MainElement mainElement = core.TemplateRead(step3WtId);
                            DataElement dataE       = (DataElement)mainElement.ElementList[0];
                            Date        date        = (Date)dataE.DataItemList[0];

                            dataE.Description            = new CDataValue();
                            dataE.Description.InderValue = DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString();

                            date.MinValue     = DateTime.Now;
                            date.MaxValue     = DateTime.Now.AddDays(1);
                            date.DefaultValue = DateTime.Now.AddMinutes(1).ToString("u");


                            core.CaseCreate(mainElement, "", siteId);
                            #endregion
                        }
                        else
                        {
                            #region send loss eForm
                            CoreElement reply = core.CaseRead(mUId, checkUId);

                            DataElement replyDataE = (DataElement)reply.ElementList[0];
                            FieldValue  answer     = (FieldValue)replyDataE.DataItemList[0];

                            MainElement mainElement = core.TemplateRead(step3LtId);
                            DataElement dataE       = (DataElement)mainElement.ElementList[0];
                            None        none        = (None)dataE.DataItemList[0];

                            none.Description            = new CDataValue();
                            none.Description.InderValue = "Collection missed at:" + DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString();


                            core.CaseCreate(mainElement, "", siteId);
                            #endregion
                        }
                    }
                    #endregion

                    #region final step
                    if (caseType == "Step three")
                    {
                        CoreElement reply = core.CaseRead(mUId, checkUId);

                        DataElement replyDataE = (DataElement)reply.ElementList[0];
                        FieldValue  answer     = (FieldValue)replyDataE.DataItemList[0];

                        #region is the winner?
                        bool isWinner = false;
                        try
                        {
                            if (replyDataE.Label == "Won - Container collection")
                            {
                                isWinner = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("isWinner failed", ex);
                        }
                        #endregion

                        if (isWinner)
                        {
                            MainElement mainElement = core.TemplateRead(step4tId);
                            DataElement dataE       = (DataElement)mainElement.ElementList[0];
                            None        none        = (None)dataE.DataItemList[0];

                            none.Label = "Container collect at:" + answer.Value;

                            foreach (int siteIdTemp in siteIdsDW)
                            {
                                core.CaseCreate(mainElement, "", siteIdTemp);
                            }
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    EventMessage(ex.ToString(), EventArgs.Empty);
                }
            }
        }