Example #1
0
        public void O365ConnectorCardOpenUriInitsWithNoArgs()
        {
            var openUri = new O365ConnectorCardOpenUri();

            Assert.NotNull(openUri);
            Assert.IsType <O365ConnectorCardOpenUri>(openUri);
        }
Example #2
0
        /// <summary>
        /// Add link button
        /// </summary>
        /// <param name="linkButtonText">Button text</param>
        /// <param name="linkTargetUri">Target Uri</param>
        public void AddLinkToCurrentMessageCard(string linkTargetUri, string linkButtonText)
        {
            var link = new O365ConnectorCardOpenUri("OpenUri", linkButtonText, null, new List <O365ConnectorCardOpenUriTarget>
            {
                new O365ConnectorCardOpenUriTarget("default", linkTargetUri)
            });

            if (_currentSection == null)
            {
                _currentSection = new O365ConnectorCardSection();
                _card.Sections  = new List <O365ConnectorCardSection> {
                    _currentSection
                };
            }

            if (_currentSection.PotentialAction == null || !_currentSection.PotentialAction.Any())
            {
                _currentSection.PotentialAction = new List <O365ConnectorCardActionBase> {
                    link
                };
            }
            else
            {
                _currentSection.PotentialAction.Add(link);
            }
        }
Example #3
0
        public void O365ConnectorCardOpenUriInits()
        {
            var type    = "OpenUri";
            var name    = "Go to Bing";
            var id      = "goToBing";
            var targets = new List <O365ConnectorCardOpenUriTarget>()
            {
                new O365ConnectorCardOpenUriTarget("default", "www.bing.com")
            };

            var openUri = new O365ConnectorCardOpenUri(type, name, id, targets);

            Assert.NotNull(openUri);
            Assert.IsType <O365ConnectorCardOpenUri>(openUri);
            Assert.Equal(name, openUri.Name);
            Assert.Equal(id, openUri.Id);
            Assert.Equal(targets, openUri.Targets);
            Assert.Equal(1, openUri.Targets.Count);
        }
Example #4
0
        private O365MessageCard BuildBody(Event <LogEventData> evt)
        {
            // Build action
            var url = BaseUrl;

            if (string.IsNullOrWhiteSpace(url))
            {
                url = Host.BaseUri;
            }

            var openTitle = "Open Seq Event";
            var openUrl   = $"{url}#/events?filter=@Id%20%3D%3D%20%22{evt.Id}%22&show=expanded";

            if (IsAlert(evt))
            {
                openTitle = "Open Seq Alert";
                openUrl   = SafeGetProperty(evt, "ResultsUrl");
            }

            O365ConnectorCardOpenUri action = new O365ConnectorCardOpenUri()
            {
                Name    = openTitle,
                Type    = "OpenUri", //Failure to provide this will cause a 400 badrequest
                Targets = new[]
                {
                    new O365ConnectorCardOpenUriTarget {
                        Uri = openUrl,
                        Os  = "default" //Failure to provide this will cause a 400 badrequest
                    }
                }
            };

            // Build message
            var msg = evt.Data.RenderedMessage;

            if (msg.Length > 1000)
            {
                msg = msg.EscapeMarkdown().Substring(0, 1000);
            }

            var color = Color;

            if (string.IsNullOrWhiteSpace(color))
            {
                color = _levelColorMap[evt.Data.Level];
            }

            O365MessageCard body = new O365MessageCard
            {
                Title           = evt.Data.Level.ToString().EscapeMarkdown(),
                ThemeColor      = color,
                Text            = msg,
                PotentialAction = new[]
                {
                    action
                }
            };

            // Build sections
            var sections = new List <O365ConnectorCardSection>();

            if (!ExcludeProperties && evt.Data.Properties != null)
            {
                var jsonSerializedProperties = JsonSerializedProperties?.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList() ?? new List <string>();
                var jsonSettings             = new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = JsonSerializedPropertiesAsIndented ? Formatting.Indented : Formatting.None
                };

                var facts = evt.Data.Properties
                            .Where(i => i.Value != null)
                            .Select(i => new O365ConnectorCardFact
                {
                    Name  = i.Key,
                    Value = (jsonSerializedProperties.Contains(i.Key) ? JsonConvert.SerializeObject(i.Value, jsonSettings) : i.Value.ToString()).EscapeMarkdown()
                })
                            .ToArray();

                if (facts.Any())
                {
                    sections.Add(new O365ConnectorCardSection {
                        Facts = facts
                    });
                }
            }

            if (!string.IsNullOrWhiteSpace(evt.Data.Exception))
            {
                sections.Add(new O365ConnectorCardSection {
                    Title = "Exception", Text = evt.Data.Exception.EscapeMarkdown()
                });
            }

            body.Sections = sections.ToArray();

            return(body);
        }
Example #5
0
        private O365MessageCard BuildBody(Event <LogEventData> evt)
        {
            // Build action
            var url = BaseUrl;

            if (string.IsNullOrWhiteSpace(url))
            {
                url = Host.BaseUri;
            }

            var(openTitle, openUrl) = SeqEvents.GetOpenLink(url, evt);
            var action = new O365ConnectorCardOpenUri
            {
                Name    = openTitle,
                Type    = "OpenUri", //Failure to provide this will cause a 400 badrequest
                Targets = new[]
                {
                    new O365ConnectorCardOpenUriTarget
                    {
                        Uri = openUrl,
                        Os  = "default" //Failure to provide this will cause a 400 badrequest
                    }
                }
            };

            // Build message
            var msg = evt.Data.RenderedMessage;

            if (msg.Length > 1000)
            {
                msg = msg.EscapeMarkdown().Substring(0, 1000);
            }

            var color = Color;

            if (string.IsNullOrWhiteSpace(color))
            {
                color = LevelColorMap[evt.Data.Level];
            }

            var body = new O365MessageCard
            {
                Title           = evt.Data.Level.ToString().EscapeMarkdown(),
                ThemeColor      = color,
                Text            = msg,
                PotentialAction = new O365ConnectorCardActionBase[]
                {
                    action
                }
            };

            // Build sections
            var sections = new List <O365ConnectorCardSection>();
            var config   = new PropertyConfig
            {
                ExcludedProperties                 = ExcludedProperties?.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList() ?? new List <string>(),
                JsonSerializedProperties           = JsonSerializedProperties?.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList() ?? new List <string>(),
                JsonSerializedPropertiesAsIndented = JsonSerializedPropertiesAsIndented
            };

            if (!config.ExcludedProperties.Contains(ExcludeAllPropertyName))
            {
                var properties = SeqEvents.GetProperties(evt, config);

                var facts = properties.Where(x => !string.IsNullOrEmpty(x.Value)).Select(x => new O365ConnectorCardFact
                {
                    Name  = x.Key,
                    Value = x.Value
                }).ToArray();

                if (facts.Any())
                {
                    sections.Add(new O365ConnectorCardSection {
                        Facts = facts
                    });
                }
            }

            if (!string.IsNullOrWhiteSpace(evt.Data.Exception))
            {
                sections.Add(new O365ConnectorCardSection {
                    Title = "Exception", Text = evt.Data.Exception.EscapeMarkdown()
                });
            }

            body.Sections = sections.ToArray();

            return(body);
        }