Exemplo n.º 1
0
        /// <inheritdoc />
        public virtual async Task <List <string> > GetPageOrder(string org, string app, int instanceOwnerId, Guid instanceGuid, string layoutSetId, string currentPage, string dataTypeId, object formData)
        {
            LayoutSettings layoutSettings = null;

            if (string.IsNullOrEmpty(layoutSetId))
            {
                layoutSettings = _resourceService.GetLayoutSettings();
            }
            else
            {
                layoutSettings = _resourceService.GetLayoutSettingsForSet(layoutSetId);
            }

            return(await Task.FromResult(layoutSettings.Pages.Order));
        }
Exemplo n.º 2
0
        public ActionResult GetLayoutSettings(string org, string app, string id)
        {
            string settings = _appResourceService.GetLayoutSettingsForSet(id);

            return(Ok(settings));
        }
Exemplo n.º 3
0
        private async Task GenerateAndStoreReceiptPDF(Instance instance, string taskId, DataElement dataElement, Type dataElementModelType)
        {
            string app             = instance.AppId.Split("/")[1];
            string org             = instance.Org;
            int    instanceOwnerId = int.Parse(instance.InstanceOwner.PartyId);
            Guid   instanceGuid    = Guid.Parse(instance.Id.Split("/")[1]);

            string     layoutSetsString = _resourceService.GetLayoutSets();
            LayoutSets layoutSets       = null;
            LayoutSet  layoutSet        = null;

            if (!string.IsNullOrEmpty(layoutSetsString))
            {
                layoutSets = JsonConvert.DeserializeObject <LayoutSets>(layoutSetsString);
                layoutSet  = layoutSets.Sets.FirstOrDefault(t => t.DataType.Equals(dataElement.DataType) && t.Tasks.Contains(taskId));
            }

            string layoutSettingsFileContent = layoutSet == null?_resourceService.GetLayoutSettings() : _resourceService.GetLayoutSettingsForSet(layoutSet.Id);

            LayoutSettings layoutSettings = null;

            if (!string.IsNullOrEmpty(layoutSettingsFileContent))
            {
                layoutSettings = JsonConvert.DeserializeObject <LayoutSettings>(layoutSettingsFileContent);
            }

            object data = await _dataService.GetFormData(instanceGuid, dataElementModelType, org, app, instanceOwnerId, new Guid(dataElement.Id));

            layoutSettings = await FormatPdf(layoutSettings, data);

            XmlSerializer serializer = new XmlSerializer(dataElementModelType);

            using MemoryStream stream = new MemoryStream();

            serializer.Serialize(stream, data);
            stream.Position = 0;

            byte[] dataAsBytes = new byte[stream.Length];
            await stream.ReadAsync(dataAsBytes);

            string encodedXml = Convert.ToBase64String(dataAsBytes);

            UserContext userContext = await _userHelper.GetUserContext(_httpContextAccessor.HttpContext);

            UserProfile userProfile = await _profileService.GetUserProfile(userContext.UserId);

            // If layoutst exist pick correctr layotFiles
            string formLayoutsFileContent = layoutSet == null?_resourceService.GetLayouts() : _resourceService.GetLayoutsForSet(layoutSet.Id);

            TextResource textResource = await _textService.GetText(org, app, userProfile.ProfileSettingPreference.Language);

            if (textResource == null && !userProfile.ProfileSettingPreference.Equals("nb"))
            {
                // fallback to norwegian if texts does not exist
                textResource = await _textService.GetText(org, app, "nb");
            }

            string textResourcesString = JsonConvert.SerializeObject(textResource);
            Dictionary <string, Dictionary <string, string> > optionsDictionary = await GetOptionsDictionary(formLayoutsFileContent);

            PDFContext pdfContext = new PDFContext
            {
                Data              = encodedXml,
                FormLayouts       = JsonConvert.DeserializeObject <Dictionary <string, object> >(formLayoutsFileContent),
                LayoutSettings    = layoutSettings,
                TextResources     = JsonConvert.DeserializeObject(textResourcesString),
                OptionsDictionary = optionsDictionary,
                Party             = await _registerService.GetParty(instanceOwnerId),
                Instance          = instance,
                UserProfile       = userProfile,
                UserParty         = userProfile.Party
            };

            Stream pdfContent = await _pdfService.GeneratePDF(pdfContext);

            await StorePDF(pdfContent, instance, textResource);

            pdfContent.Dispose();
        }