예제 #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));
        }
        public ActionResult LayoutSettings(string org, string app)
        {
            string settings = _appResourceService.GetLayoutSettings();

            return(Ok(settings));
        }
예제 #3
0
        /// <inheritdoc/>
        public async Task GenerateAndStoreReceiptPDF(Instance instance, DataElement dataElement)
        {
            string      app             = instance.AppId.Split("/")[1];
            string      org             = instance.Org;
            int         instanceOwnerId = int.Parse(instance.InstanceOwner.PartyId);
            Application application     = _appResourcesService.GetApplication();
            Guid        instanceGuid    = Guid.Parse(instance.Id.Split("/")[1]);

            Stream dataStream = await _dataService.GetBinaryData(org, app, instanceOwnerId, instanceGuid, new Guid(dataElement.Id));

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

            string encodedXml = Convert.ToBase64String(dataAsBytes);

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

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

            string       formLayoutsString = _appResourcesService.GetLayouts();
            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);

            string layoutSettings = _appResourcesService.GetLayoutSettings();

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

            Stream pdfContent;

            try
            {
                pdfContent = await GeneratePDF(pdfContext);
            }
            catch (Exception exception)
            {
                _logger.LogError($"Could not generate pdf for {instance.Id}, failed with message {exception.Message}");
                return;
            }

            try
            {
                await StorePDF(pdfContent, instance, textResource);
            }
            catch (Exception exception)
            {
                _logger.LogError($"Could not store pdf for {instance.Id}, failed with message {exception.Message}");
                return;
            }
            finally
            {
                pdfContent.Dispose();
            }
        }
예제 #4
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();
        }