Exemple #1
0
        /// <summary>
        /// Validade the properties.
        /// </summary>
        internal static bool Validade()
        {
            if (!(Exceptions.Any() || Warnings.Any() || Messages.Any() || Successes.Any()))
            {
                //throw new ArgumentException("At least one Exception/Warning/Message/Success expected.");
                return(false);
            }

            if (String.IsNullOrEmpty(ProjectName))
            {
                throw new ArgumentException("Project name must be declared.");
            }

            if (String.IsNullOrEmpty(Folder))
            {
                throw new ArgumentException("You must inform the Folder wich the Log will be writen.");
            }

            if (!Directory.Exists(Folder))
            {
                Directory.CreateDirectory(Folder);
            }

            if (!FileName.StartsWith("\\"))
            {
                FileName = "\\" + FileName;
            }

            if (!FileName.EndsWith(".htm"))
            {
                FileName += ".htm";
            }

            return(true);
        }
Exemple #2
0
        public override bool AddAndCheckIfTriggered(SystemEvent opResult)
        {
            while (Successes.Any() && Successes.Peek() <= DateTime.UtcNow)
            {
                Successes.Dequeue();
            }
            while (Failures.Any() && Failures.Peek() <= DateTime.UtcNow)
            {
                Failures.Dequeue();
            }
            switch (opResult.Result)
            {
            case SystemEvent.OperationResult.Success:
                Successes.Enqueue(DateTime.UtcNow + KeepOperationInPileTime);
                break;

            case SystemEvent.OperationResult.Failure:
                Failures.Enqueue(DateTime.UtcNow + KeepOperationInPileTime);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            var totalOperations = Successes.Count + Failures.Count;
            var failRatio       = (double)Failures.Count / totalOperations;

            if (totalOperations >= MinimumAmountOfOperationsBeforeRuleCanBeTriggered && (failRatio * 100) >= MaxFailurePercent)
            {
                AlarmMessage = $"{MaxFailurePercent}%  failures occured within {KeepOperationInPileTime}.";
                Failures.Clear();
                Successes.Clear();
                return(true);
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Creates the page and writes to disk using properties set before.
        /// </summary>
        public static void Me()
        {
            if (!Validade())
            {
                return;
            }

            var html = new Html();

            #region Head

            html.Head      = new Head();
            html.Head.Meta = new List <Meta>();
            html.Head.Meta.Add(new Meta()
            {
                Content = "en-us", HttpEquiv = "Content-Language"
            });
            html.Head.Meta.Add(new Meta()
            {
                Content = "text/html; charset=utf-16", HttpEquiv = "Content-Type"
            });
            html.Head.Title = Title;

            html.Head.Style  = Style;
            html.Head.Script = Script;

            #endregion

            #region Body

            html.Body        = new Body();
            html.Body.H1     = Header;
            html.Body.Div    = new Div();
            html.Body.Div.Id = "content";

            #region Summary Table (Overview)

            html.Body.Div.Div1               = new Div1();
            html.Body.Div.Div1.H2            = "Overview";
            html.Body.Div.Div1.Div2          = new Div2();
            html.Body.Div.Div1.Div2.Id       = "overview";
            html.Body.Div.Div1.Div2.Table    = new Table();
            html.Body.Div.Div1.Div2.Table.Tr = new List <Tr>();

            #region Header

            var tableRow = new Tr();
            tableRow.Th = new List <Th>();
            tableRow.Th.Add(new Th());
            tableRow.Th.Add(new Th("ProjectTableHeader", "Project"));
            tableRow.Th.Add(new Th("PathTableHeader", "Path"));
            tableRow.Th.Add(new Th("ErrorsTableHeader", "Errors"));
            tableRow.Th.Add(new Th("WarningsTableHeader", "Warnings"));
            tableRow.Th.Add(new Th("MessagesTableHeader", "Messages"));
            tableRow.Th.Add(new Th("SuccessesTableHeader", "Successes"));
            html.Body.Div.Div1.Div2.Table.Tr.Add(tableRow);

            #endregion

            #region Project Summary

            var tableRowItem = new Tr();
            tableRowItem.Td = new List <Td>();

            #region Project Status Icon

            if (Exceptions.Any())
            {
                tableRowItem.Td.Add(new Td("IconErrorEncoded", ""));
            }
            else if (Warnings.Any())
            {
                tableRowItem.Td.Add(new Td("IconWarningEncoded", ""));
            }
            else if (Messages.Any())
            {
                tableRowItem.Td.Add(new Td("IconInfoEncoded", ""));
            }
            else
            {
                tableRowItem.Td.Add(new Td("IconSuccessEncoded", ""));
            }

            #endregion

            tableRowItem.Td.Add(new Td("", "<strong><a href=\"#" + ProjectName + "\">" + ProjectName + "</a></strong>"));
            tableRowItem.Td.Add(new Td("", ProjectPath));

            #region Counters

            #region Exceptions

            if (Exceptions.Any())
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a href=\"#\" onclick=\"ScrollToFirstVisibleRow('" + ProjectName + "', 'Error'); return false;\">" + Exceptions.Count + "</a>"));
            }
            else
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a>0</a>")); //If zero, no href
            }

            #endregion

            #region Warnings

            if (Warnings.Any())
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a href=\"#\" onclick=\"ScrollToFirstVisibleRow('" + ProjectName + "', 'Warning'); return false;\">" + Warnings.Count + "</a>"));
            }
            else
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a>0</a>")); //If zero, no href
            }

            #endregion

            #region Messages

            if (Messages.Any())
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a href=\"#\" onclick=\"ScrollToFirstVisibleRow('" + ProjectName + "', 'Message'); return false;\">" + Messages.Count + "</a>"));
            }
            else
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a>0</a>")); //If zero, no href
            }

            #endregion

            #region Successes

            if (Successes.Any())
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a href=\"#\" onclick=\"ScrollToFirstVisibleRow('" + ProjectName + "', 'Success'); return false;\">" + Successes.Count + "</a>"));
            }
            else
            {
                tableRowItem.Td.Add(new Td("textCentered", "<a>0</a>")); //If zero, no href
            }

            #endregion

            #endregion

            html.Body.Div.Div1.Div2.Table.Tr.Add(tableRowItem);

            #endregion

            #endregion

            #region Projects

            html.Body.Div.H2        = "Details";
            html.Body.Div.Div3      = new Div3();
            html.Body.Div.Div3.Div4 = new List <Div4>();

            #region For Each Project

            var div4 = new Div4();
            div4.A        = new A();
            div4.A.Name   = ProjectName;
            div4.H3       = ProjectName;
            div4.Table    = new Table();
            div4.Table.Tr = new List <Tr>();

            #region Header Row

            var tr = new Tr();
            tr.Id = div4.H3 + "HeaderRow";
            tr.Th = new List <Th>();
            tr.Th.Add(new Th("", "", ""));
            tr.Th.Add(new Th("MessageTableHeader", "Messages", "messageCell"));

            //First cell is empty.
            //second cell is "Messages".
            div4.Table.Tr.Add(tr);

            #endregion

            #region For each Error/Warning/Message/Success

            #region Errors

            foreach (Exception exce in Exceptions)
            {
                var trException = new Tr();

                if (!ExpandErrors)
                {
                    trException.Style = "display: none";
                }

                trException.Name = "ErrorRowClass" + ProjectName;
                trException.Td   = new List <Td>();
                trException.Td.Add(new Td("IconErrorEncoded", "<a name=\"" + ProjectName + "Error\" />"));
                trException.Td.Add(new Td("messageCell", "<span>" + exce.Message + "<br><code>" + exce.StackTrace + "</code>" + "</span>"));

                div4.Table.Tr.Add(trException);
            }

            #region Show/Hide

            if (Exceptions.Count > 0 && !ExpandErrors)
            {
                #region Singular/Plural

                string singularPlural = "error";
                if (Exceptions.Count > 1)
                {
                    singularPlural += "s";
                }

                #endregion

                var trShow = new Tr();
                trShow.Name = "ErrorRowHeaderShow" + ProjectName;
                trShow.Td   = new List <Td>();
                trShow.Td.Add(new Td("IconErrorEncoded", "<a name=\" " + div4.H3 + "Error\" />", "rgb(242,255,255)"));
                trShow.Td.Add(new Td("messageCell", "<a _locid=\"ShowAdditionalErrors\" href=\"#\" name=\"" + ProjectName + "Error\" onclick=\"ToggleErrorVisibility('" + ProjectName + "'); return false;\">Show " + Exceptions.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trShow);

                var trHide = new Tr();
                trHide.Name  = "ErrorRowHeaderHide" + ProjectName;
                trHide.Style = "display: none";
                trHide.Td    = new List <Td>();
                trHide.Td.Add(new Td("IconErrorEncoded", "<a name=\" " + div4.H3 + "Error\" />", "rgb(242,255,255)"));
                trHide.Td.Add(new Td("messageCell", "<a _locid=\"HideAdditionalErrors\" href=\"#\" name=\"" + ProjectName + "Error\" onclick=\"ToggleErrorVisibility('" + ProjectName + "'); return false;\">Hide " + Exceptions.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trHide);
            }

            #endregion

            #endregion

            #region Warnings

            foreach (string warning in Warnings)
            {
                var trWarnings = new Tr();

                if (!ExpandWarnings)
                {
                    trWarnings.Style = "display: none";
                }

                trWarnings.Name = "WarningRowClass" + ProjectName;
                trWarnings.Td   = new List <Td>();
                trWarnings.Td.Add(new Td("IconWarningEncoded", "<a name=\"" + ProjectName + "Warning\" />"));
                trWarnings.Td.Add(new Td("messageCell", "<span>" + warning + "</span>"));

                div4.Table.Tr.Add(trWarnings);
            }

            #region Show/Hide

            if (Warnings.Count > 0 && !ExpandWarnings)
            {
                #region Singular/Plural

                string singularPlural = "warning";
                if (Warnings.Count > 1)
                {
                    singularPlural += "s";
                }

                #endregion

                var trShow = new Tr();
                trShow.Name = "WarningRowHeaderShow" + ProjectName;
                trShow.Td   = new List <Td>();
                trShow.Td.Add(new Td("IconWarningEncoded", "<a name=\" " + div4.H3 + "Warning\" />", "rgb(242,255,255)"));
                trShow.Td.Add(new Td("messageCell", "<a _locid=\"ShowAdditionalWarnings\" href=\"#\" name=\"" + ProjectName + "Error\" onclick=\"ToggleWarningVisibility('" + ProjectName + "'); return false;\">Show " + Warnings.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trShow);

                var trHide = new Tr();
                trHide.Name  = "WarningRowHeaderHide" + ProjectName;
                trHide.Style = "display: none";
                trHide.Td    = new List <Td>();
                trHide.Td.Add(new Td("IconWarningEncoded", "<a name=\" " + div4.H3 + "Warning\" />", "rgb(242,255,255)"));
                trHide.Td.Add(new Td("messageCell", "<a _locid=\"HideAdditionalWarnings\" href=\"#\" name=\"" + ProjectName + "Error\" onclick=\"ToggleWarningVisibility('" + ProjectName + "'); return false;\">Hide " + Warnings.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trHide);
            }

            #endregion

            #endregion

            #region Messages

            foreach (string message in Messages)
            {
                var trMessages = new Tr();

                if (!ExpandMessages)
                {
                    trMessages.Style = "display: none";
                }

                trMessages.Name = "MessageRowClass" + ProjectName;
                trMessages.Td   = new List <Td>();
                trMessages.Td.Add(new Td("IconInfoEncoded", "<a name=\"" + ProjectName + "Message\" />"));
                trMessages.Td.Add(new Td("messageCell", "<span>" + message + "</span>"));

                div4.Table.Tr.Add(trMessages);
            }

            #region Show/Hide

            if (Messages.Count > 0 && !ExpandMessages)
            {
                #region Singular/Plural

                string singularPlural = "message";
                if (Messages.Count > 1)
                {
                    singularPlural += "s";
                }

                #endregion

                var trShow = new Tr();
                trShow.Name = "MessageRowHeaderShow" + ProjectName;
                trShow.Td   = new List <Td>();
                trShow.Td.Add(new Td("IconInfoEncoded", "<a name=\" " + div4.H3 + "Message\" />", "rgb(242,255,255)"));
                trShow.Td.Add(new Td("messageCell", "<a _locid=\"ShowAdditionalMessages\" href=\"#\" name=\"" + ProjectName + "Message\" onclick=\"ToggleMessageVisibility('" + ProjectName + "'); return false;\">Show " + Messages.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trShow);

                var trHide = new Tr();
                trHide.Name  = "MessageRowHeaderHide" + ProjectName;
                trHide.Style = "display: none";
                trHide.Td    = new List <Td>();
                trHide.Td.Add(new Td("IconInfoEncoded", "<a name=\" " + div4.H3 + "Message\" />", "rgb(242,255,255)"));
                trHide.Td.Add(new Td("messageCell", "<a _locid=\"HideAdditionalMessages\" href=\"#\" name=\"" + ProjectName + "Message\" onclick=\"ToggleMessageVisibility('" + ProjectName + "'); return false;\">Hide " + Messages.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trHide);
            }

            #endregion

            #endregion

            #region Successes

            foreach (string success in Successes)
            {
                var trSuccesses = new Tr();

                if (!ExpandSuccesses)
                {
                    trSuccesses.Style = "display: none";
                }

                trSuccesses.Name = "SuccessRowClass" + ProjectName;
                trSuccesses.Td   = new List <Td>();
                trSuccesses.Td.Add(new Td("IconSuccessEncoded", "<a name=\"" + ProjectName + "Success\" />"));
                trSuccesses.Td.Add(new Td("messageCell", "<span>" + success + "</span>"));

                div4.Table.Tr.Add(trSuccesses);
            }

            #region Show/Hide

            if (Successes.Count > 0 && !ExpandSuccesses)
            {
                #region Singular/Plural

                string singularPlural = "success";
                if (Successes.Count > 1)
                {
                    singularPlural += "es";
                }

                #endregion

                var trShow = new Tr();
                trShow.Name = "SuccessRowHeaderShow" + ProjectName;
                trShow.Td   = new List <Td>();
                trShow.Td.Add(new Td("IconSuccessEncoded", "<a name=\" " + div4.H3 + "Success\" />", "rgb(242,255,255)"));
                trShow.Td.Add(new Td("messageCell", "<a _locid=\"ShowAdditionalSuccesses\" href=\"#\" name=\"" + ProjectName + "Success\" onclick=\"ToggleSuccessVisibility('" + ProjectName + "'); return false;\">Show " + Successes.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trShow);

                var trHide = new Tr();
                trHide.Name  = "SuccessRowHeaderHide" + ProjectName;
                trHide.Style = "display: none";
                trHide.Td    = new List <Td>();
                trHide.Td.Add(new Td("IconSuccessEncoded", "<a name=\" " + div4.H3 + "Success\" />", "rgb(242,255,255)"));
                trHide.Td.Add(new Td("messageCell", "<a _locid=\"HideAdditionalSuccesses\" href=\"#\" name=\"" + ProjectName + "Success\" onclick=\"ToggleSuccessVisibility('" + ProjectName + "'); return false;\">Hide " + Successes.Count + " " + singularPlural + "</a>", "background-color: rgb(239,245,249);"));

                div4.Table.Tr.Add(trHide);
            }

            #endregion

            #endregion

            #endregion

            html.Body.Div.Div3.Div4.Add(div4);

            #endregion

            #endregion

            #endregion

            #region Serialize

            XmlDocument doc     = XmlUtils.Serializar <Html>(html);
            string      xmltext = XmlUtils.GetXmlTexto(doc);

            #endregion

            #region Replace's

            xmltext = "<!DOCTYPE html>\r\n" +
                      "<!-- saved from url=(0014)about:internet -->\r\n" + xmltext;
            xmltext = xmltext.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&");
            xmltext = xmltext.Replace("<html>", "<html xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\">\r\n").Replace("<script>", "<script type=\"text/javascript\" language=\"javascript\">").Replace("<value>", "").Replace("</value>", "");

            #endregion

            File.WriteAllText(Folder + FileName, xmltext);
        }