Beispiel #1
0
        Task <IMessageForSend> ResolveMessageAsync(IDataModel dm)
        {
            var templateName = dm.Eval <String>("Message.Template");
            var key          = dm.Eval <String>("Message.Key");
            var templatePath = _host.ApplicationReader.MakeFullPath(templateName, String.Empty);
            var fullPath     = Path.ChangeExtension(templatePath, "xaml");

            var env     = dm.Eval <List <ExpandoObject> >("Message.Environment");
            var hostObj = new ExpandoObject();

            hostObj.Set("Name", "Host");
            hostObj.Set("Value", _host.AppHost);
            env.Add(hostObj);

            using (var stream = _host.ApplicationReader.FileStreamFullPath(fullPath)) {
                var tml             = XamlServices.Load(stream) as Template;
                TemplatedMessage tm = tml.Get(key);
                if (tm == null)
                {
                    throw new MessagingException($"Message not found. Key = '{key}'");
                }
                var resolver = new MessageResolver(_host, _dbContext, dm);
                return(tm.ResolveAndSendAsync(resolver));
            }
        }
Beispiel #2
0
        public async Task <String> ResolveDataModelAsync(TemplatedMessage msg, String text)
        {
            if (text.IndexOf("{{") == -1)
            {
                return(text);
            }
            var dm = await msg.GetDataModelAsync(_dbContext, _msgParams);

            return(dm.Root.Resolve(text));
        }
Beispiel #3
0
        public async Task <String> ResolveAsync(TemplatedMessage msg, String text)
        {
            if (text == null)
            {
                return(null);
            }
            var sb = new StringBuilder(text);

            text = await ResolveDataModelAsync(msg, text);

            text = ResolveEnvironment(text);
            text = ResolveParameters(text);
            return(text);
        }
Beispiel #4
0
        public Task <String> ResolveFileAsync(TemplatedMessage msg, String fileName)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                return(null);
            }
            String fileText = _host.ApplicationReader.ReadTextFile(fileName, String.Empty);

            if (fileText == null)
            {
                throw new MessagingException($"File not found '{fileName}'");
            }
            return(ResolveAsync(msg, fileText));
        }
Beispiel #5
0
        public async Task <Stream> ResolveReportAsync(TemplatedMessage msg, MessageReport rep)
        {
            if (rep == null)
            {
                return(null);
            }
            _reportHelper.SetupLicense();
            var dm = await msg.GetDataModelAsync(_dbContext, _msgParams);

            // get report source
            using (Stream input = await ResolveStreamStringAsync(msg, rep.Report))
            {
                if (input == null)
                {
                    throw new MessagingException($"ReportStream not found ({rep.Report}).");
                }
                // get report datamodel
                IDataModel repDataModel = null;
                if (rep.Model != null)
                {
                    var repPrms = new ExpandoObject();
                    if (rep.Model.Parameters != null)
                    {
                        foreach (var p in rep.Model.Parameters)
                        {
                            repPrms.Set(p.Key, await ResolveAsync(msg, p.Value?.Value));
                        }
                    }
                    repDataModel = await _dbContext.LoadModelAsync(rep.Model.Source, $"[{rep.Model.Schema}].[{rep.Model.Model}.Report]", repPrms);
                }
                var ms      = new MemoryStream();
                var repName = await _reportHelper.ExportDocumentAsync(input, repDataModel, ms);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
        }
Beispiel #6
0
        public async Task <Stream> ResolveStreamAsync(TemplatedMessage msg, String text)
        {
            if (text == null)
            {
                return(null);
            }
            if (text.StartsWith("`"))
            {
                text = text.Substring(1);
            }
            if (text.IndexOf("{{") == -1)
            {
                return(null);
            }
            var dm = await msg.GetDataModelAsync(_dbContext, _msgParams);

            var bytes = dm.Root.Eval <Byte[]>(text.Substring(2, text.Length - 4));

            if (bytes == null || bytes.Length == 0)
            {
                return(null);
            }
            return(new MemoryStream(bytes));
        }
Beispiel #7
0
        public async Task <Stream> ResolveStreamStringAsync(TemplatedMessage msg, String text)
        {
            if (text == null)
            {
                return(null);
            }
            if (text.StartsWith("`"))
            {
                text = text.Substring(1);
            }
            if (text.IndexOf("{{") == -1)
            {
                return(null);
            }
            var dm = await msg.GetDataModelAsync(_dbContext, _msgParams);

            var data = dm.Root.Eval <String>(text.Substring(2, text.Length - 4));

            if (String.IsNullOrEmpty(data))
            {
                return(null);
            }
            return(new MemoryStream(Encoding.UTF8.GetBytes(data)));
        }