public async Task Handle(eFormCaseUpdated message)
        {
            ItemCaseSite itemCaseSite = await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId);

            if (itemCaseSite != null)
            {
                var caseDto = await _sdkCore.CaseReadByCaseId(message.caseId);

                var microtingUId      = caseDto.MicrotingUId;
                var microtingCheckUId = caseDto.CheckUId;
                await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext();
                Site site = await microtingDbContext.Sites.SingleAsync(x => x.Id == itemCaseSite.MicrotingSdkSiteId);

                Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId);

                var theCase = await _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language);

                itemCaseSite = await SetFieldValue(itemCaseSite, theCase.Id);

                await itemCaseSite.Update(_dbContext);

                ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.Id == itemCaseSite.ItemCaseId);

                itemCase = await SetFieldValue(itemCase, theCase.Id);

                await itemCase.Update(_dbContext);
            }
        }
コード例 #2
0
        protected override void LoadContent()
        {
            consoleFont         = ContentLoader.Load <SpriteFont>("Console");
            spriteBatch         = new SpriteBatch(GraphicsDevice);
            consoleFont.Spacing = 1;

            TextBox.LoadContent();
            ItemCase.LoadContent();
        }
コード例 #3
0
        protected override void Initialize()
        {
            textBox = new TextBox(new Vector2(200));
            item    = new ItemCase(new Vector2(200));

            info = new List <string>();

            base.Initialize();
        }
コード例 #4
0
        public async Task ItemCase_Save_DoesSave()
        {
            // Arrange
            ItemList itemList = new ItemList
            {
                Name = Guid.NewGuid().ToString()
            };

            await itemList.Create(DbContext);

            Item item = new Item
            {
                Name        = Guid.NewGuid().ToString(),
                Description = Guid.NewGuid().ToString(),
                Enabled     = true,
                ItemListId  = itemList.Id,
            };

            await item.Save(DbContext);

            ItemCase itemCase = new ItemCase
            {
                MicrotingSdkSiteId  = 24,
                MicrotingSdkCaseId  = 34,
                MicrotingSdkeFormId = 234,
                Status = 66,
                ItemId = item.Id,
            };

            // Act
            await itemCase.Create(DbContext);

            List <ItemCase>        itemCases        = DbContext.ItemCases.AsNoTracking().ToList();
            List <ItemCaseVersion> itemCaseVersions = DbContext.ItemCaseVersions.AsNoTracking().ToList();

            // Assert
            Assert.AreEqual(1, itemCases.Count);
            Assert.AreEqual(1, itemCaseVersions.Count);
            Assert.AreEqual(itemCase.MicrotingSdkSiteId, itemCases[0].MicrotingSdkSiteId);
            Assert.AreEqual(itemCase.MicrotingSdkCaseId, itemCases[0].MicrotingSdkCaseId);
            Assert.AreEqual(itemCase.MicrotingSdkeFormId, itemCases[0].MicrotingSdkeFormId);
            Assert.AreEqual(itemCase.Status, itemCases[0].Status);
            Assert.AreEqual(itemCase.ItemId, itemCases[0].ItemId);
            Assert.AreEqual(Constants.WorkflowStates.Created, itemCases[0].WorkflowState);
            Assert.AreEqual(itemCase.Id, itemCases[0].Id);
            Assert.AreEqual(1, itemCases[0].Version);

            Assert.AreEqual(itemCase.MicrotingSdkSiteId, itemCaseVersions[0].MicrotingSdkSiteId);
            Assert.AreEqual(itemCase.MicrotingSdkCaseId, itemCaseVersions[0].MicrotingSdkCaseId);
            Assert.AreEqual(itemCase.MicrotingSdkeFormId, itemCaseVersions[0].MicrotingSdkeFormId);
            Assert.AreEqual(itemCase.Status, itemCaseVersions[0].Status);
            Assert.AreEqual(itemCase.ItemId, itemCaseVersions[0].ItemId);
            Assert.AreEqual(Constants.WorkflowStates.Created, itemCaseVersions[0].WorkflowState);
            Assert.AreEqual(itemCase.Id, itemCaseVersions[0].ItemCaseId);
            Assert.AreEqual(1, itemCaseVersions[0].Version);
        }
コード例 #5
0
 private void InitBlock(List <ItemCase> itemCases, RectTransform rectTransform)
 {
     for (int i = 0; i < arrayLeft.Length; i++)
     {
         ItemCase itemCase = Instantiate(prefabCase, rectTransform);
         itemCase.name = $"ItemCase -> {i}";
         itemCase.SetIndex(i);
         itemCases.Add(itemCase);
     }
 }
コード例 #6
0
    public void OnEndDrag(PointerEventData eventData)
    {
        canvasGroup.blocksRaycasts = true;

        if (rectTransform.parent != canvas.transform)
        {
            SetParent(rectTransform);
        }
        else
        {
            itemCaseParent = null;
            // Added to list
            EventManager.OnAddedItemThings(this);
            SetParent(transformParentDefault.GetComponent <RectTransform>());
        }
    }
        public async Task Handle(eFormCompleted message)
        {
            ItemCaseSite itemCaseSite = await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId);

            if (itemCaseSite != null)
            {
                itemCaseSite.Status = 100;
                var caseDto           = _sdkCore.CaseReadByCaseId(message.caseId);
                var microtingUId      = caseDto.Result.MicrotingUId;
                var microtingCheckUId = caseDto.Result.CheckUId;
//                if (microtingUId != null && microtingCheckUId != null) {}
                if (microtingUId != null && microtingCheckUId != null)
                {
                    Language language = await _sdkCore.DbContextHelper.GetDbContext().Languages
                                        .SingleAsync(x => x.LanguageCode == "da");

                    var theCase = _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language);

                    itemCaseSite = await SetFieldValue(itemCaseSite, theCase.Id);

                    itemCaseSite.MicrotingSdkCaseDoneAt = theCase.Result.DoneAt;
                    itemCaseSite.DoneByUserId           = itemCaseSite.MicrotingSdkSiteId;
                    var site = _sdkCore.SiteRead(itemCaseSite.MicrotingSdkSiteId);
                    itemCaseSite.DoneByUserName = $"{site.Result.FirstName} {site.Result.LastName}";
                    await itemCaseSite.Update(_dbContext);

                    ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.Id == itemCaseSite.ItemCaseId);

                    if (itemCase.Status != 100)
                    {
                        itemCase.Status = 100;
                        itemCase.MicrotingSdkCaseDoneAt = theCase.Result.DoneAt;
                        itemCase.MicrotingSdkCaseId     = itemCaseSite.MicrotingSdkCaseId;
                        itemCase.DoneByUserId           = itemCaseSite.MicrotingSdkSiteId;
                        itemCase.DoneByUserName         = $"{site.Result.FirstName} {site.Result.LastName}";

                        itemCase = await SetFieldValue(itemCase, theCase.Id);

                        await itemCase.Update(_dbContext);
                    }

                    await RetractFromMicroting(itemCase.Id);
                }
            }
        }
コード例 #8
0
        public async Task Handle(ItemCaseCreate message)
        {
            Item item = await _dbContext.Items.SingleOrDefaultAsync(x => x.Id == message.ItemId);

            if (item != null)
            {
                var siteIds = await _dbContext.PluginConfigurationValues.FirstOrDefaultAsync(x => x.Name == "ItemsPlanningBaseSettings:SiteIds");

                Language language = await _sdkCore.DbContextHelper.GetDbContext().Languages
                                    .SingleAsync(x => x.LanguageCode == "da");

                var    mainElement = _sdkCore.ReadeForm(message.RelatedEFormId, language);
                string folderId    = GetFolderId(message.Name).ToString();

                ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.ItemId == item.Id && x.WorkflowState != Constants.WorkflowStates.Retracted);

                if (itemCase != null)
                {
                    itemCase.WorkflowState = Constants.WorkflowStates.Retracted;
                    await itemCase.Update(_dbContext);
                }

                itemCase = new ItemCase
                {
                    ItemId = item.Id,
                    Status = 66,
                    MicrotingSdkeFormId = message.RelatedEFormId
                };
                await itemCase.Create(_dbContext);

                foreach (var siteIdString in siteIds.Value.Split(','))
                {
                    var siteId        = int.Parse(siteIdString);
                    var casesToDelete = _dbContext.ItemCaseSites.
                                        Where(x => x.ItemId == item.Id && x.MicrotingSdkSiteId == siteId && x.WorkflowState != Constants.WorkflowStates.Retracted);

                    foreach (ItemCaseSite caseToDelete in casesToDelete)
                    {
                        CaseDto caseDto = await _sdkCore.CaseLookupCaseId(caseToDelete.MicrotingSdkCaseId);

                        if (caseDto.MicrotingUId != null)
                        {
                            await _sdkCore.CaseDelete((int)caseDto.MicrotingUId);
                        }
                        caseToDelete.WorkflowState = Constants.WorkflowStates.Retracted;
                        await caseToDelete.Update(_dbContext);
                    }

                    mainElement.Result.Label = string.IsNullOrEmpty(item.ItemNumber) ? "" : item.ItemNumber;
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        mainElement.Result.Label += string.IsNullOrEmpty(mainElement.Result.Label) ? $"{item.Name}" : $" - {item.Name}";
                    }

                    if (!string.IsNullOrEmpty(item.BuildYear))
                    {
                        mainElement.Result.Label += string.IsNullOrEmpty(mainElement.Result.Label) ? $"{item.BuildYear}" : $" - {item.BuildYear}";
                    }

                    if (!string.IsNullOrEmpty(item.Type))
                    {
                        mainElement.Result.Label += string.IsNullOrEmpty(mainElement.Result.Label) ? $"{item.Type}" : $" - {item.Type}";
                    }
                    mainElement.Result.ElementList[0].Label = mainElement.Result.Label;
                    mainElement.Result.CheckListFolderName  = folderId;
                    mainElement.Result.StartDate            = DateTime.Now.ToUniversalTime();
                    mainElement.Result.EndDate = DateTime.Now.AddYears(10).ToUniversalTime();

                    ItemCaseSite itemCaseSite =
                        await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.ItemCaseId == itemCase.Id && x.MicrotingSdkSiteId == siteId);

                    if (itemCaseSite == null)
                    {
                        itemCaseSite = new ItemCaseSite
                        {
                            MicrotingSdkSiteId  = siteId,
                            MicrotingSdkeFormId = message.RelatedEFormId,
                            Status     = 66,
                            ItemId     = item.Id,
                            ItemCaseId = itemCase.Id
                        };

                        await itemCaseSite.Create(_dbContext);
                    }

                    if (itemCaseSite.MicrotingSdkCaseId >= 1)
                    {
                        continue;
                    }
                    int?caseId = await _sdkCore.CaseCreate(await mainElement, "", siteId, null);

                    if (caseId != null)
                    {
                        CaseDto caseDto = await _sdkCore.CaseLookupMUId((int)caseId);

                        if (caseDto?.CaseId != null)
                        {
                            itemCaseSite.MicrotingSdkCaseId = (int)caseDto.CaseId;
                        }
                        await itemCaseSite.Update(_dbContext);
                    }
                }
            }
        }
        public async Task <string> DownloadEFormPdf(int caseId, string token, string fileType)
        {
            PluginConfigurationValue pluginConfigurationValue =
                await _dbContext.PluginConfigurationValues.SingleOrDefaultAsync(x => x.Name == "ItemsPlanningBaseSettings:Token");

            if (token == pluginConfigurationValue.Value)
            {
                try
                {
                    var core = await _core.GetCore();

                    int      eFormId  = 0;
                    ItemCase itemCase = await _dbContext.ItemCases.FirstOrDefaultAsync(x => x.Id == caseId);

                    Item item = await _dbContext.Items.SingleOrDefaultAsync(x => x.Id == itemCase.ItemId);

                    ItemList itemList = await _dbContext.ItemLists.SingleOrDefaultAsync(x => x.Id == item.ItemListId);

                    await using MicrotingDbContext microtingDbContext = core.DbContextHelper.GetDbContext();
                    var locale = await _userService.GetCurrentUserLocale();

                    Language language = microtingDbContext.Languages.Single(x => x.LanguageCode.ToLower() == locale.ToLower());
                    if (itemList != null)
                    {
                        eFormId = itemList.RelatedEFormId;
                    }

                    string xmlContent = new XElement("ItemCase",
                                                     new XElement("ItemId", item.Id),
                                                     new XElement("ItemNumber", item.ItemNumber),
                                                     new XElement("ItemName", item.Name),
                                                     new XElement("ItemDescription", item.Description),
                                                     new XElement("ItemLocationCode", item.LocationCode),
                                                     new XElement("ItemBuildYear", item.BuildYear),
                                                     new XElement("ItemType", item.Type)
                                                     ).ToString();

                    if (caseId != 0 && eFormId != 0)
                    {
                        var filePath = await core.CaseToPdf(itemCase.MicrotingSdkCaseId, eFormId.ToString(),
                                                            DateTime.Now.ToString("yyyyMMddHHmmssffff"),
                                                            $"{core.GetSdkSetting(Settings.httpServerAddress)}/" + "api/template-files/get-image/", fileType, xmlContent, language);

                        if (!System.IO.File.Exists(filePath))
                        {
                            throw new FileNotFoundException();
                        }

                        return(filePath);
                    }
                    else
                    {
                        throw new Exception("could not find case of eform!");
                    }
                }
                catch (Exception exception)
                {
                    Log.LogException($"ItemListCaseService.DownloadEFormPdf: Got exception {exception.Message}");
                    throw new Exception("Something went wrong!", exception);
                }
            }

            throw new UnauthorizedAccessException();
        }
コード例 #10
0
        public async Task UploadedData_Update_DoesUpdate()
        {
            //Arrange
            ItemList itemList = new ItemList
            {
                Name = Guid.NewGuid().ToString()
            };

            await itemList.Create(DbContext);

            Item item = new Item
            {
                Name        = Guid.NewGuid().ToString(),
                Description = Guid.NewGuid().ToString(),
                Enabled     = true,
                ItemListId  = itemList.Id,
            };

            await item.Create(DbContext);

            ItemCase itemCase = new ItemCase
            {
                MicrotingSdkSiteId  = 24,
                MicrotingSdkCaseId  = 34,
                MicrotingSdkeFormId = 234,
                Status = 66,
                ItemId = item.Id,
            };

            await itemCase.Create(DbContext);

            UploadedData uploadedData = new UploadedData
            {
                ItemCaseId   = itemCase.Id,
                Checksum     = Guid.NewGuid().ToString(),
                Extension    = Guid.NewGuid().ToString(),
                CurrentFile  = Guid.NewGuid().ToString(),
                UploaderType = Guid.NewGuid().ToString(),
                FileLocation = Guid.NewGuid().ToString(),
                FileName     = Guid.NewGuid().ToString()
            };
            await uploadedData.Create(DbContext);

            string newCheckSum     = Guid.NewGuid().ToString();
            string newExtension    = Guid.NewGuid().ToString();
            string newCurrentFile  = Guid.NewGuid().ToString();
            string newUploaderType = Guid.NewGuid().ToString();
            string newFileLocation = Guid.NewGuid().ToString();
            string newFileName     = Guid.NewGuid().ToString();

            uploadedData.Checksum     = newCheckSum;
            uploadedData.Extension    = newExtension;
            uploadedData.CurrentFile  = newCurrentFile;
            uploadedData.UploaderType = newUploaderType;
            uploadedData.FileLocation = newFileLocation;
            uploadedData.FileName     = newFileName;
            //Act
            await uploadedData.Update(DbContext);

            UploadedData               dbUploadedData          = DbContext.UploadedDatas.AsNoTracking().First();
            List <UploadedData>        uploadedDataList        = DbContext.UploadedDatas.AsNoTracking().ToList();
            List <UploadedDataVersion> uploadedDataVersionList = DbContext.UploadedDataVersions.AsNoTracking().ToList();

            //Assert
            Assert.NotNull(dbUploadedData);

            Assert.AreEqual(1, uploadedDataList.Count);
            Assert.AreEqual(2, uploadedDataVersionList.Count);

            Assert.AreEqual(newCheckSum, dbUploadedData.Checksum);
            Assert.AreEqual(newExtension, dbUploadedData.Extension);
            Assert.AreEqual(newCurrentFile, dbUploadedData.CurrentFile);
            Assert.AreEqual(newUploaderType, dbUploadedData.UploaderType);
            Assert.AreEqual(newFileLocation, dbUploadedData.FileLocation);
            Assert.AreEqual(newFileName, dbUploadedData.FileName);
            Assert.AreEqual(uploadedData.ItemCaseId, dbUploadedData.ItemCaseId);
        }
        private async Task <ItemCase> SetFieldValue(ItemCase itemCase, int caseId)
        {
            Item       item     = _dbContext.Items.SingleOrDefault(x => x.Id == itemCase.ItemId);
            ItemList   itemList = _dbContext.ItemLists.SingleOrDefault(x => x.Id == item.ItemListId);
            List <int> caseIds  = new List <int>();

            caseIds.Add(itemCase.MicrotingSdkCaseId);

            await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext();
            Site site = await microtingDbContext.Sites.SingleAsync(x => x.Id == itemCase.MicrotingSdkSiteId);

            Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId);

            List <FieldValue> fieldValues = await _sdkCore.Advanced_FieldValueReadList(caseIds, language);

            if (itemList == null)
            {
                return(itemCase);
            }

            if (itemList.SdkFieldEnabled1)
            {
                itemCase.SdkFieldValue1 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId1)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled2)
            {
                itemCase.SdkFieldValue2 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId2)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled3)
            {
                itemCase.SdkFieldValue3 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId3)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled4)
            {
                itemCase.SdkFieldValue4 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId4)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled5)
            {
                itemCase.SdkFieldValue5 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId5)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled6)
            {
                itemCase.SdkFieldValue6 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId6)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled7)
            {
                itemCase.SdkFieldValue7 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId7)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled8)
            {
                itemCase.SdkFieldValue8 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId8)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled9)
            {
                itemCase.SdkFieldValue9 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId9)?.ValueReadable;
            }
            if (itemList.SdkFieldEnabled10)
            {
                itemCase.SdkFieldValue10 =
                    fieldValues.SingleOrDefault(x => x.FieldId == itemList.SdkFieldId10)?.ValueReadable;
            }
            if (itemList.NumberOfImagesEnabled)
            {
                itemCase.NumberOfImages = 0;
                foreach (FieldValue fieldValue in fieldValues)
                {
                    if (fieldValue.FieldType == Constants.FieldTypes.Picture)
                    {
                        if (fieldValue.UploadedData != null)
                        {
                            itemCase.NumberOfImages += 1;
                        }
                    }
                }
            }

            return(itemCase);
        }
コード例 #12
0
 public void SetItemCase(ItemCase itemCase)
 {
     itemCaseParent = itemCase;
 }
コード例 #13
0
 public void SetParentDefault()
 {
     itemCaseParent = null;
     SetParent(transformParentDefault.GetComponent <RectTransform>());
 }