public void InitAttachments()
        {
            Attachment1 = new Attachment();

            AttachmentFields = new AttachmentFields("Файл", ".txt", null);
            Applicant        = new ApplicantWeb.Models.Applicant();
            Attachment2      = new Attachment(AttachmentFields, Applicant.ApplicantId, Applicant);

            History     = new History();
            Attachment3 = new Attachment(AttachmentFields, Applicant.ApplicantId, Applicant, History.HistoryId, History);
        }
Exemple #2
0
        public Attachment AddAttachmentField(string title, string value, bool isShort)
        {
            AttachmentFields.Add(new AttachmentField
            {
                Title   = title,
                Value   = value,
                IsShort = isShort
            });

            return(this);
        }
Exemple #3
0
        public static void PostResultsToSlack(string bvtResult, string testTester, string testCaseId, string testProject, string testTitle, string testDesc, string _resultsFile, string _jiraTicketNumberWithAutomationResults, string _url, string _urlWithAccessToken, string _slackChannel)
        {
            const string _pass    = "******";
            const string _fail    = "Fail";
            const string _warning = "Warning";
            var          _message = string.Empty;

            // START OF SLACK INTEGRATION
            int numberOfFails    = SlackActions.CountTheNumberOfX(_resultsFile, _fail);
            int numberOfWarnings = SlackActions.CountTheNumberOfX(_resultsFile, _warning);
            int numberOfPasses   = SlackActions.CountTheNumberOfX(_resultsFile, _pass);

            var addedInfo = string.Empty;
            int numberToIncludeInResults = 0;

            if (numberOfWarnings == 0 && numberOfFails == 0)
            {
                bvtResult = _pass;
                addedInfo = "passing";
                numberToIncludeInResults = numberOfPasses;
            }
            else if (numberOfWarnings > 0 && numberOfFails == 0)
            {
                bvtResult = _warning;
                addedInfo = "failing to run - please debug and re-try";
                numberToIncludeInResults = numberOfWarnings;
            }
            else if (numberOfFails > 0)
            {
                bvtResult = _fail;
                addedInfo = "failing";
                numberToIncludeInResults = numberOfFails;
            }


            var testOrTests = numberToIncludeInResults == 1 ? "test" : "tests";

            var bvtResultAddedInfo = string.Format("{0} with {1} {2} {3}", bvtResult, numberToIncludeInResults,
                                                   testOrTests, addedInfo);


            try
            {
                var testTesterFromAlias = string.Format("{0} {1}", testTester, bvtResult);
                SlackActions.CalculateColorOfResult(bvtResult);
                var iconOfResult  = SlackActions.iconOfResult;
                var colorOfResult = SlackActions.colorOfResult;
                var fileNameOnly  = Path.GetFileName(_resultsFile);

                string messageToSendToSlack = SlackActions.CreateMessageToSendToSlack(testCaseId, testProject,
                                                                                      testTitle, testDesc, _jiraTicketNumberWithAutomationResults, testTester, bvtResultAddedInfo, "Live",
                                                                                      fileNameOnly, _url);
                const string pretextText = "Results of Smoke Test";

                SlackClientWebhooks client = new SlackClientWebhooks(_urlWithAccessToken);

                Arguments p = new Arguments();
                p.Channel   = _slackChannel;
                p.Username  = testTesterFromAlias;
                p.Text      = "";
                p.Token     = _urlWithAccessToken;
                p.IconEmoji = iconOfResult;

                Attachment a = new Attachment();
                a.Fallback = testProject;
                a.Color    = colorOfResult;
                a.Pretext  = pretextText;


                AttachmentFields af = new AttachmentFields();
                af.Title = "Field 1";
                af.Value = "Value 1";
                af.Short = false;
                a.Fields.Add(af);

                AttachmentFields af2 = new AttachmentFields();
                af.Title  = "BVT Result";
                af.Value  = messageToSendToSlack;
                af2.Short = true;
                a.Fields.Add(af2);

                p.Attachments.Add(a);

                client.PostMessage(p);
            }
            catch (Exception)
            {
                _message = "Unable to post to Slack";
                Thread.Sleep(500);
                using (var file = new StreamWriter(_resultsFile, true))
                {
                    file.WriteLine(_message);
                }
            }
            // END OF SLACK INTEGRATION
        }
        public static void PostCRMAlert(
            string SlackChannelName,
            string SlackToken,
            string CaseNumber,
            string Url,
            string Description,
            string System,
            DateTime CreatedOn,
            string CustomerName,
            string CustomerEmail,
            string CustomerPhone,
            string Priority,
            string Status,
            string LastNoteBy,
            DateTime LastNoteAddedOn,
            string LastNoteText,
            string Colour)
        {
            var LastNoteAddedOnEpoch = new DateTimeOffset(LastNoteAddedOn).ToUnixTimeSeconds();

            AttachmentFields caseField = new AttachmentFields()
            {
                Title = "Case Number",
                Value = CaseNumber,
                Short = true
            };
            AttachmentFields systemField = new AttachmentFields()
            {
                Title = "System",
                Value = System,
                Short = true
            };
            AttachmentFields priorityField = new AttachmentFields()
            {
                Title = "Priority",
                Value = Priority,
                Short = true
            };
            AttachmentFields statusField = new AttachmentFields()
            {
                Title = "Status",
                Value = Status,
                Short = true
            };
            Attachment crmAttachment = new Attachment()
            {
                Pretext    = $"Priority issue raised for {CustomerName} on {CreatedOn.ToString("dd/MMM/yy")}",
                Fallback   = Description,
                Color      = Colour,
                AuthorName = $"{CustomerName} ({CustomerPhone})",
                AuthorLink = $"mailto:{CustomerEmail}",
                AuthorIcon = "https://cdn4.iconfinder.com/data/icons/48-bubbles/48/29.Mac-256.png",  // bit naughty, direct linking here
                Title      = Description,
                TitleLink  = Url,
                Fields     = { caseField, systemField, priorityField, statusField },
                Footer     = $"{LastNoteBy} - {LastNoteText}",
                FooterIcon = "https://cdn4.iconfinder.com/data/icons/cc_mono_icon_set/blacks/48x48/notepad_2.png",  // bit naughty, direct linking here
                TS         = LastNoteAddedOnEpoch
            };
            Arguments slackMessage = new Arguments()
            {
                Channel     = SlackChannelName,
                Attachments = { crmAttachment }
            };

            // send
            var slack    = new SlackClientAPI(SlackToken);
            var response = slack.PostMessage("chat.postMessage", slackMessage);
        }