Example #1
0
        public string GetSummary()
        {
            StringBuilder builder = new StringBuilder();

            if (Messages.Any())
            {
                builder.AppendLine("Messages:");

                foreach (string messaage in Messages)
                {
                    builder.AppendLine(messaage);
                }

                builder.AppendLine();
            }

            if (Exceptions.Any())
            {
                builder.AppendLine("Errors:");

                foreach (Exception exception in Exceptions)
                {
                    builder.AppendLine(exception.Message);
                }
            }

            return(builder.ToString());
        }
Example #2
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);
        }
Example #3
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine($"AUDIT LOG: [{HttpStatusCode?.ToString() ?? "---"}: {(HttpMethod ?? "-------").PadRight(7)}] {Url}");
            sb.AppendLine($"- UserName - UserId                 : {UserName} - {UserId}");
            sb.AppendLine($"- ClientIpAddress        : {ClientIpAddress}");
            sb.AppendLine($"- ExecutionDuration      : {ExecutionDuration}");

            if (Actions.Any())
            {
                sb.AppendLine("- Actions:");
                foreach (var action in Actions)
                {
                    sb.AppendLine($"  - {action.ServiceName}.{action.MethodName} ({action.ExecutionDuration} ms.)");
                    sb.AppendLine($"    {action.Parameters}");
                }
            }

            if (Exceptions.Any())
            {
                sb.AppendLine("- Exceptions:");
                foreach (var exception in Exceptions)
                {
                    sb.AppendLine($"  - {exception.Message}");
                    sb.AppendLine($"    {exception}");
                }
            }

            return(sb.ToString());
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine($"AUDIT LOG:");
            sb.AppendLine($"- {"User",-20}: {CurrentUser} ");
            sb.AppendLine($"- {"ExecutionDuration",-20}: {ExecutionDuration}");

            if (ExtraProperties.Any())
            {
                foreach (var property in ExtraProperties)
                {
                    sb.AppendLine($"- {property.Key,-20}: {property.Value}");
                }
            }
            if (Actions.Any())
            {
                sb.AppendLine("- Actions:");
                foreach (var action in Actions)
                {
                    sb.AppendLine(action.ToString());
                }
            }

            if (Exceptions.Any())
            {
                sb.AppendLine("- Exceptions:");
                foreach (var exception in Exceptions)
                {
                    sb.AppendLine($"  - {exception.Message}");
                    sb.AppendLine($"    {exception}");
                }
            }
            return(sb.ToString());
        }
        public async Task will_log_an_exception()
        {
            try
            {
                await Bus.Invoke(new Message5 { FailThisManyTimes = 1 });
            }
            catch (Exception)
            {
            }

            Exceptions.Any().ShouldBeTrue();
        }
        /// <summary>
        /// Creates a <see cref="DeliveryEventWebhook"/> with the specified values.
        /// </summary>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="url">The URL to be called when the event occurs.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <DeliveryEventWebhook> Create(string eventName, Uri url)
        {
            var errors = new[]
            {
                ValidateEventName(eventName),
                ValidateUrl(url),
            };

            if (!Exceptions.Any(errors))
            {
                return(Outcomes.Success(new DeliveryEventWebhook(eventName, url)));
            }

            return(Outcomes.Failure <DeliveryEventWebhook>(errors));
        }
Example #7
0
        /// <summary>
        /// Creates an <see cref="JobConstraint"/> instance with a specified name and value.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <JobConstraint> Create(string name, string value)
        {
            var errors = new[]
            {
                ValidateName(name),
                ValidateValue(value),
            };

            if (!Exceptions.Any(errors))
            {
                return(Outcomes.Success(new JobConstraint(name, value)));
            }

            return(Outcomes.Failure <JobConstraint>(errors));
        }
Example #8
0
        protected override void DisposeUnmanagedResources()
        {
            if (Exceptions?.Any() != true)
            {
                return;
            }

            foreach (var exception in Exceptions)
            {
                exception.Dispose();
            }

            Runtime?.Dispose();

            Sdk?.Dispose();

            HttpContext?.Dispose();
        }
Example #9
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine($"AUDIT LOG: [{HttpStatusCode?.ToString() ?? "---"}: {(HttpMethod ?? "-------").PadRight(7)}] {Url}");
            sb.AppendLine($"- UserName - UserId                 : {UserName} - {UserId}");
            sb.AppendLine($"- ClientIpAddress        : {ClientIpAddress}");
            sb.AppendLine($"- ExecutionDuration      : {ExecutionDuration}");

            if (Actions.Any())
            {
                sb.AppendLine("- Actions:");
                foreach (var action in Actions)
                {
                    sb.AppendLine($"  - {action.ServiceName}.{action.MethodName} ({action.ExecutionDuration} ms.)");
                    sb.AppendLine($"    {action.Parameters}");
                }
            }

            if (Exceptions.Any())
            {
                sb.AppendLine("- Exceptions:");
                foreach (var exception in Exceptions)
                {
                    sb.AppendLine($"  - {exception.Message}");
                    sb.AppendLine($"    {exception}");
                }
            }

            if (EntityChanges.Any())
            {
                sb.AppendLine("- Entity Changes:");
                foreach (var entityChange in EntityChanges)
                {
                    sb.AppendLine($"  - [{entityChange.ChangeType}] {entityChange.EntityTypeFullName}, Id = {entityChange.EntityId}");
                    foreach (var propertyChange in entityChange.PropertyChanges)
                    {
                        //sb.AppendLine($"    {propertyChange.PropertyName}: {propertyChange.OriginalValue} -> {propertyChange.NewValue}");
                    }
                }
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Creates a new <see cref="ExtraAddressDetails"/> instance with a specified values.
        /// </summary>
        /// <param name="stateProvince">The state or province.</param>
        /// <param name="country">The country.</param>
        /// <param name="suburbLocality">The suburb locality.</param>
        /// <param name="postcode">The postcode.</param>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <ExtraAddressDetails> Create(string stateProvince, string country, string suburbLocality, string postcode, decimal latitude, decimal longitude)
        {
            var errors = new[]
            {
                ValidateStateProvince(stateProvince),
                ValidateCountry(country),
                ValidateSuburbLocality(suburbLocality),
                ValidatePostcode(postcode),
            };

            if (!Exceptions.Any(errors))
            {
                return(Outcomes.Success(new ExtraAddressDetails(stateProvince, country, suburbLocality, postcode, latitude, longitude)));
            }

            return(Outcomes
                   .Failure <ExtraAddressDetails>()
                   .WithError(errors));
        }
Example #11
0
        static bool HttpPredicate(Exception ex, IEnumerable <int> codes)
        {
            if (ex == null)
            {
                return(false);
            }
            if (Exceptions.Any(t => ex.GetType() == t))
            {
                return(true);
            }

            HttpCommandException commandException = ex as HttpCommandException;

            if (commandException == null ||
                codes == null ||
                codes.Count() == 0)
            {
                return(false);
            }

            return(codes.Any(t => t == commandException.Code));
        }
Example #12
0
            /// <summary>
            ///   Returns a string representation of the minimal critical fault sets.
            /// </summary>
            public override string ToString()
            {
                var builder    = new StringBuilder();
                var percentage = CheckedSets.Count / (float)(1 << Faults.Count()) * 100;

                builder.AppendLine();
                builder.AppendLine("=======================================================================");
                builder.AppendLine("=======      Deductive Cause Consequence Analysis: Results      =======");
                builder.AppendLine("=======================================================================");
                builder.AppendLine();

                if (Exceptions.Any())
                {
                    builder.AppendLine("*** Warning: Unhandled exceptions have been thrown during the analysis. ***");
                    builder.AppendLine();
                }

                if (!IsComplete)
                {
                    builder.AppendLine("*** Warning: Analysis might be incomplete; not all fault sets have been checked. ***");
                    builder.AppendLine();
                }

                Func <IEnumerable <Fault>, string> getFaultString =
                    faults => String.Join(", ", faults.Select(fault => fault.Name).OrderBy(name => name));

                builder.AppendFormat("Elapsed Time: {0}", Time);
                builder.AppendLine();
                builder.AppendFormat("Fault Count: {0}", Faults.Count());
                builder.AppendLine();
                builder.AppendFormat("Faults: {0}", getFaultString(Faults));
                builder.AppendLine();

                if (ForcedFaults.Any())
                {
                    builder.AppendFormat("Forced Faults: {0}", getFaultString(ForcedFaults));
                    builder.AppendLine();
                }

                if (SuppressedFaults.Any())
                {
                    builder.AppendFormat("Suppressed Faults: {0}", getFaultString(SuppressedFaults));
                    builder.AppendLine();
                }

                builder.AppendLine();

                builder.AppendFormat("Checked Fault Sets: {0} ({1:F0}% of all fault sets)", CheckedSets.Count, percentage);
                builder.AppendLine();

                builder.AppendFormat("Minimal Critical Sets: {0}", MinimalCriticalSets.Count);
                builder.AppendLine();
                builder.AppendLine();

                var i = 1;

                foreach (var criticalSet in MinimalCriticalSets)
                {
                    builder.AppendFormat("   ({1}) {{ {0} }}", String.Join(", ", criticalSet.Select(fault => fault.Name).OrderBy(name => name)), i++);

                    Exception e;
                    if (Exceptions.TryGetValue(criticalSet, out e))
                    {
                        builder.AppendLine();
                        builder.AppendFormat(
                            "    An unhandled exception of type {0} was thrown while checking the fault set: {1}",
                            e.GetType().FullName, e.Message);
                    }

                    builder.AppendLine();
                }

                return(builder.ToString());
            }
Example #13
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);
        }
        /// <summary>
        ///   Returns a string representation of the minimal critical fault sets.
        /// </summary>
        public override string ToString()
        {
            var builder        = new StringBuilder();
            var percentage     = CheckedSetCount / (double)(1L << Faults.Count()) * 100;
            var cardinalitySum = MinimalCriticalSets.Sum(set => set.Count);
            var minimalSetCardinalityAverage = cardinalitySum == 0 ? 0 : cardinalitySum / (double)MinimalCriticalSets.Count;

            builder.AppendLine();
            builder.AppendLine("=======================================================================");
            builder.AppendLine("=======      Deductive Cause Consequence Analysis: Results      =======");
            builder.AppendLine("=======================================================================");
            builder.AppendLine();

            if (Exceptions.Any())
            {
                builder.AppendLine("*** Warning: Unhandled exceptions have been thrown during the analysis. ***");
                builder.AppendLine();
            }

            if (!IsComplete)
            {
                builder.AppendLine("*** Warning: Analysis might be incomplete; not all fault sets have been checked. ***");
                builder.AppendLine();
            }

            Func <IEnumerable <Fault>, string> getFaultString =
                faults => String.Join(", ", faults.Select(fault => fault.Name).OrderBy(name => name));

            builder.AppendLine($"Elapsed Time: {Time}");
            builder.AppendLine($"Fault Count: {Faults.Count()}");
            builder.AppendLine($"Faults: {getFaultString(Faults)}");

            if (ForcedFaults.Any())
            {
                builder.AppendLine($"Forced Faults: {getFaultString(ForcedFaults)}");
            }

            if (SuppressedFaults.Any())
            {
                builder.AppendLine($"Suppressed Faults: {getFaultString(SuppressedFaults)}");
            }

            builder.AppendLine();
            builder.AppendLine($"Checked Fault Sets: {CheckedSetCount} ({percentage:F0}% of all fault sets)");
            builder.AppendLine($"Minimal Critical Sets: {MinimalCriticalSets.Count}");
            builder.AppendLine($"Average Minimal Critical Set Cardinality: {minimalSetCardinalityAverage:F1}");
            builder.AppendLine();

            var i = 1;

            foreach (var criticalSet in MinimalCriticalSets)
            {
                builder.AppendFormat("   ({1}) {{ {0} }}", String.Join(", ", criticalSet.Select(fault => fault.Name).OrderBy(name => name)), i++);

                Exception e;
                if (Exceptions.TryGetValue(criticalSet, out e))
                {
                    builder.AppendLine();
                    builder.Append(
                        $"    An unhandled exception of type {e.GetType().FullName} was thrown while checking the fault set: {e.Message}");
                }

                builder.AppendLine();
            }

            var heuristicCount = Heuristics.Count();

            if (heuristicCount != 0)
            {
                builder.AppendLine();

                if (HeuristicSuggestionCount == 0)
                {
                    builder.AppendLine("No suggestions were made by the heuristics.");
                }
                else
                {
                    var nonTriviallyCritical         = HeuristicSuggestionCount - HeuristicNonTrivialSafeCount - HeuristicTrivialCount;
                    var percentageTrivial            = HeuristicTrivialCount / (double)(HeuristicSuggestionCount) * 100;
                    var percentageNonTrivialSafe     = HeuristicNonTrivialSafeCount / (double)(HeuristicSuggestionCount) * 100;
                    var percentageNonTrivialCritical = nonTriviallyCritical / (double)(HeuristicSuggestionCount) * 100;

                    builder.AppendLine($"Of {HeuristicSuggestionCount} fault sets suggested by {heuristicCount} heuristics");
                    builder.AppendLine($"    {HeuristicTrivialCount} ({percentageTrivial:F0}%) were trivially safe or trivially critical,");
                    builder.AppendLine($"    {HeuristicNonTrivialSafeCount} ({percentageNonTrivialSafe:F0}%) were non-trivially safe, and");
                    builder.AppendLine($"    {nonTriviallyCritical} ({percentageNonTrivialCritical:F0}%) were non-trivially critical.");
                    builder.AppendLine($"In total, {TrivialChecksCount} trivial checks were performed.");
                }
            }

            return(builder.ToString());
        }
Example #15
0
        private void UpdateGroupedSeries()
        {
            // data validation
            if (Exceptions != null && Exceptions.Any())
            {
                this.Exceptions.Clear();
            }

            // ensure that caption of series is not null, otherwise all other series would be ignored (data from the same series are collection to the same datapointgroup)
            if (this.Series.Any(series => string.IsNullOrEmpty(series.SeriesTitle)))
            {
                Exceptions.Add("Series with empty caption cannot be used.");
            }

            //ensure that each series has a different name
            if (this.Series.GroupBy(series => series.SeriesTitle).Any(group => group.Count() > 1))
            {
                Exceptions.Add("Series with duplicate name cannot be used.");
            }

            if (!HasExceptions)
            {
                List <DataPointGroup> result = new List <DataPointGroup>();
                try
                {
                    if (GetIsRowColumnSwitched())
                    {
                        ///sammle erst alle Gruppen zusammen
                        foreach (ChartSeries initialSeries in this.Series)
                        {
                            int itemIndex = 0;
                            foreach (var seriesItem in initialSeries.Items)
                            {
                                string         seriesItemCaption = GetPropertyValue(seriesItem, initialSeries.DisplayMember); //Security
                                DataPointGroup dataPointGroup    = result.Where(group => group.Caption == seriesItemCaption).FirstOrDefault();
                                if (dataPointGroup == null)
                                {
                                    dataPointGroup = new DataPointGroup(this, seriesItemCaption, this.Series.Count > 1 ? true : false);
                                    dataPointGroup.PropertyChanged += dataPointGroup_PropertyChanged;
                                    result.Add(dataPointGroup);

                                    CreateDataPointGroupBindings(dataPointGroup);

                                    int seriesIndex = 0;
                                    foreach (ChartSeries allSeries in this.Series)
                                    {
                                        DataPoint datapoint = new DataPoint(this);
                                        datapoint.SeriesCaption    = allSeries.SeriesTitle;
                                        datapoint.ValueMember      = allSeries.ValueMember;
                                        datapoint.DisplayMember    = allSeries.DisplayMember;
                                        datapoint.ItemBrush        = this.Series.Count == 1 ? GetItemBrush(itemIndex) : GetItemBrush(seriesIndex); //if only one series, use different color for each datapoint, if multiple series we use different color for each series
                                        datapoint.PropertyChanged += groupdItem_PropertyChanged;

                                        CreateDataPointBindings(datapoint, dataPointGroup);

                                        dataPointGroup.DataPoints.Add(datapoint);
                                        seriesIndex++;
                                    }
                                    itemIndex++;
                                }
                            }
                        }

                        ///gehe alle Series durch (Security, Naming etc.)
                        foreach (ChartSeries series in this.Series)
                        {
                            foreach (var seriesItem in series.Items)
                            {
                                string seriesItemCaption = GetPropertyValue(seriesItem, series.DisplayMember); //Security

                                //finde die gruppe mit dem Namen
                                DataPointGroup addToGroup = result.Where(group => group.Caption == seriesItemCaption).FirstOrDefault();

                                //finde in der Gruppe
                                DataPoint groupdItem = addToGroup.DataPoints.Where(item => item.SeriesCaption == series.SeriesTitle).FirstOrDefault();
                                groupdItem.ReferencedObject = seriesItem;
                            }
                        }
                    }
                    else
                    {
                        foreach (ChartSeries initialSeries in this.Series)
                        {
                            //erstelle für jede Series einen DataPointGroup, darin wird dann für jedes Item in jeder Serie ein DataPoint angelegt
                            DataPointGroup dataPointGroup = new DataPointGroup(this, initialSeries.SeriesTitle, this.Series.Count > 1 ? true : false);
                            dataPointGroup.PropertyChanged += dataPointGroup_PropertyChanged;
                            result.Add(dataPointGroup);

                            CreateDataPointGroupBindings(dataPointGroup);

                            //stelle nun sicher, dass alle DataPointGruppen die gleichen Datapoints hat
                            foreach (ChartSeries allSeries in this.Series)
                            {
                                int seriesIndex = 0;
                                foreach (var seriesItem in allSeries.Items)
                                {
                                    string    seriesItemCaption = GetPropertyValue(seriesItem, initialSeries.DisplayMember); //Security
                                    DataPoint existingDataPoint = dataPointGroup.DataPoints.Where(datapoint => datapoint.SeriesCaption == seriesItemCaption).FirstOrDefault();
                                    if (existingDataPoint == null)
                                    {
                                        DataPoint datapoint = new DataPoint(this);
                                        datapoint.SeriesCaption    = seriesItemCaption;
                                        datapoint.ValueMember      = allSeries.ValueMember;
                                        datapoint.DisplayMember    = allSeries.DisplayMember;
                                        datapoint.ItemBrush        = GetItemBrush(seriesIndex);
                                        datapoint.PropertyChanged += groupdItem_PropertyChanged;

                                        CreateDataPointBindings(datapoint, dataPointGroup);

                                        dataPointGroup.DataPoints.Add(datapoint);
                                    }
                                    seriesIndex++;
                                }
                            }
                        }

                        ///gehe alle Series durch (Security, Naming etc.)
                        foreach (ChartSeries series in this.Series)
                        {
                            foreach (var seriesItem in series.Items)
                            {
                                //finde die gruppe mit dem Namen
                                DataPointGroup addToGroup = result.Where(group => group.Caption == series.SeriesTitle).FirstOrDefault();

                                //finde in der Gruppe das richtige Element
                                string seriesItemCaption = GetPropertyValue(seriesItem, series.DisplayMember); //Security

                                DataPoint groupdItem = addToGroup.DataPoints.Where(item => item.SeriesCaption == seriesItemCaption).FirstOrDefault();
                                groupdItem.ReferencedObject = seriesItem;
                            }
                        }
                    }
                }
                catch
                {
                }

                //finished, copy all to the array
                groupedSeries.Clear();
                foreach (var item in result)
                {
                    groupedSeries.Add(item);
                }

                UpdateColorsOfDataPoints();

                chartLegendItems.Clear();
                DataPointGroup firstgroup = groupedSeries.FirstOrDefault();
                if (firstgroup != null)
                {
                    foreach (DataPoint dataPoint in firstgroup.DataPoints)
                    {
                        ChartLegendItemViewModel legendItem = new ChartLegendItemViewModel();

                        var captionBinding = new Binding();
                        captionBinding.Source = dataPoint;
                        captionBinding.Mode   = BindingMode.OneWay;
                        captionBinding.Path   = new PropertyPath("SeriesCaption");
                        BindingOperations.SetBinding(legendItem, ChartLegendItemViewModel.CaptionProperty, captionBinding);

                        var brushBinding = new Binding();
                        brushBinding.Source = dataPoint;
                        brushBinding.Mode   = BindingMode.OneWay;
                        brushBinding.Path   = new PropertyPath("ItemBrush");
                        BindingOperations.SetBinding(legendItem, ChartLegendItemViewModel.ItemBrushProperty, brushBinding);

                        chartLegendItems.Add(legendItem);
                    }
                }
                RecalcSumOfDataPointGroup();
            }
        }