Пример #1
0
        public void WriteToHtml()
        {
            lock (htmlWriteLocker)
            {
                // HTML-Vorlage auslesen und initialisieren
                if (htmlTemplate == null)
                {
                    htmlTemplate = File.ReadAllText(PBEContext.CurrentContext.LogFileTemplate);
                    htmlTemplate = this.ParseParameters(htmlTemplate);

                    // link auf die alte Logdatei einbauen
                    if (File.Exists(this.Logfile))
                    {
                        String oldLogfile = ParallelHelper.FileReadAllText(this.Logfile);
                        Regex  reg        = new Regex("[<]!-- Archive: (?<file>[^>]*) --[>]");
                        var    match      = reg.Match(oldLogfile);
                        if (match != null)
                        {
                            string oldArchive = match.Groups["file"].Value;
                            htmlTemplate = htmlTemplate.Replace(PLACEHOLDER_Archive, PLACEHOLDER_Archive + "&nbsp;&nbsp;&nbsp;<a href=\"" + oldArchive + "\">Previous Logilfe</a>");
                        }
                    }

                    // Aktuelle Achiv-Datei eintragen
                    htmlTemplate = htmlTemplate.Replace(PLACEHOLDER_Archive, "<!-- Archive: " + this.Logarchive + " -->");
                }

                // html-Content aufbereiten
                String htmlContent = htmlTemplate;

                StringBuilder sbParams = new StringBuilder();
                foreach (var pair in this.Parameters)
                {
                    sbParams.AppendFormat("<tr><td class=\"ParamName\">{0}</td><td class=\"ParamValue\">{1}</td></tr>\r\n",
                                          HtmlHelper.HtmlEncode(pair.Key), HtmlHelper.HtmlEncode(pair.Value));
                }
                htmlContent = htmlContent.Replace("<!-- ParamsPlaceholder -->", sbParams.ToString());

                htmlContent = htmlContent.Replace("<!-- PbeXmlPlaceHolder -->", this.XmlFilecontetForLog);

                StringBuilder sbTasks = new StringBuilder();
                this.rootAction.WriteToHtml(sbTasks);
                htmlContent = htmlContent.Replace("<!-- TasksPlaceHolder -->", sbTasks.ToString());

                int tries = 3;
                while (tries > 0)
                {
                    try
                    {
                        tries--;
                        File.WriteAllText(this.Logfile, htmlContent);
                        File.WriteAllText(this.Logarchive, htmlContent);
                        tries = 0;
                    }
                    catch { }
                }
            }
        }
Пример #2
0
        public void Execute()
        {
            StartTime = DateTime.Now;

            int cLeft = 0;
            int cTop  = 0;

            lock (ExecutableContainer.ConsoleLocker)
            {
                string indentString = new string(' ', this.Indent);
                Console.Write(indentString + this.Description + " " + StartTime.Value.ToString("HH:mm") + " - ");
                cLeft = Console.CursorLeft;
                cTop  = Console.CursorTop;
                Console.WriteLine("...");
            }

            StartTime = DateTime.Now;
            Stopwatch stop = new Stopwatch();

            stop.Start();
            try
            {
                this.ExecuteAction();
            }
            catch (Exception ex)
            {
                ExceptionDetails = ex.ToString();
                this.TaskFailed  = true;
            }
            stop.Stop();
            EndTime = DateTime.Now;

            lock (ExecutableContainer.ConsoleLocker)
            {
                int cLeftKeep = Console.CursorLeft;
                int cTopKeep  = Console.CursorTop;

                Console.SetCursorPosition(cLeft, cTop);
                Console.Write(EndTime.Value.ToString("HH:mm") + " (" + stop.ElapsedMilliseconds / 60000 + "min)");
                Console.SetCursorPosition(cLeftKeep, cTopKeep);
            }

            // Logfile einlesen, löschen und verarbeiten
            if (!String.IsNullOrEmpty(this.LogFile))
            {
                // lock wird benötigt, weil evtl. gerade die HTML-Datei geschrieben wird.
                lock (ExecutableContainer.htmlWriteLocker)
                {
                    int tries = 3;
                    while (tries > 0)
                    {
                        try
                        {
                            tries--;
                            this.LogDetails = ParallelHelper.FileReadAllText(this.LogFile);
                            tries           = 0;
                        }
                        catch { System.Threading.Thread.Sleep(50); }
                    }
                    tries = 3;
                    while (tries > 0)
                    {
                        try
                        {
                            tries--;
                            File.Delete(this.LogFile);
                            tries = 0;
                        }
                        catch { System.Threading.Thread.Sleep(50); }
                    }

                    this.ProcessLogdetails();
                }
            }
        }
Пример #3
0
        public void WriteToHtml(StringBuilder sb)
        {
            string tableClass = HTMLClass_Pending;

            if (this.EndTime.HasValue)
            {
                if (this.TaskFailed)
                {
                    tableClass = HTMLClass_CompletedError;
                }
                else if (!this.IsComplex)
                {
                    tableClass = HTMLClass_Completed;
                }
            }
            else if (this.StartTime.HasValue)
            {
                tableClass = HTMLClass_Running;
            }

            sb.AppendFormat(HTMLTag_Td, "SubTask");
            sb.AppendFormat(HTMLTag_Table, "Task " + tableClass);
            sb.Append("<tr>");
            sb.AppendFormat(HTMLTag_TdSpan, "TaskHeader " + tableClass, this.GetHtmlColspan());

            // Aktuellen Stand des Logfiles einlesen
            if (!String.IsNullOrEmpty(this.LogFile))
            {
                {
                    int tries = 3;
                    while (tries > 0)
                    {
                        try
                        {
                            tries--;
                            this.LogDetails = ParallelHelper.FileReadAllText(this.LogFile);
                            tries           = 0;
                        }
                        catch { }
                    }
                }

                // Die Dateien der Unterprozesse Einlesen.
                this.LogDetailsSub = String.Empty;
                FileInfo fi = new FileInfo(this.LogFile);
                try
                {
                    foreach (var file in fi.Directory.EnumerateFiles(Path.GetFileNameWithoutExtension(fi.Name) + "_*.TRACE"))
                    {
                        int tries = 3;
                        while (tries > 0)
                        {
                            try
                            {
                                tries--;
                                string subText = ParallelHelper.FileReadAllText(file.FullName);
                                tries = 0;
                                this.LogDetailsSub += Environment.NewLine +
                                                      "=================== " + file.Name + " ===================" +
                                                      Environment.NewLine +
                                                      subText;
                            }
                            catch { }
                        }
                    }
                }
                catch { }
            }

            string detailsText = String.Empty;

            if (!String.IsNullOrEmpty(this.ExceptionDetails))
            {
                detailsText = ExceptionDetails;
            }
            if (!String.IsNullOrEmpty(this.LogDetails))
            {
                if (!String.IsNullOrEmpty(detailsText))
                {
                    detailsText += "\r\n************************************************\r\n";
                }
                detailsText += this.LogDetails;
            }
            detailsText += this.LogDetailsSub;

            if (!String.IsNullOrEmpty(detailsText))
            {
                sb.AppendFormat(HTMLA_ShowHide, this.Taskid);
            }
            sb.Append(this.Description);

            if (this.EndTime.HasValue)
            {
                if (this.TaskFailed)
                {
                    sb.Append(" <span class=\"TaskState\">");
                    sb.Append("Completed with ERROR");
                    sb.Append("</span>");
                }
                else
                {
                    // COmpleted wid nicht extra ausgegeben.
                    // sb.Append("Completed");
                }
            }
            else if (this.StartTime.HasValue)
            {
                sb.Append(" <span class=\"TaskState\">");
                sb.Append("Running...");
                sb.Append("</span>");
            }
            sb.Append(" <span class=\"TaskDuration\">");
            if (this.EndTime.HasValue)
            {
                //sb.Append(/*"Duration: " + */TimeSpan.FromSeconds((long)(EndTime.Value - StartTime.Value).TotalSeconds).ToString("g")
                //    + " (" + StartTime.Value.ToString("HH:mm") + " - " + EndTime.Value.ToString("HH:mm") + ")");
                sb.Append(StartTime.Value.ToString("HH:mm") + " - " + EndTime.Value.ToString("HH:mm") +
                          " (" + TimeSpan.FromSeconds((long)(EndTime.Value - StartTime.Value).TotalSeconds).ToString("g") + ")");
            }
            else if (this.StartTime.HasValue)
            {
                sb.Append("since " + StartTime.Value.ToString("HH:mm"));
            }
            sb.Append("</span>");

            sb.Append("</td>");
            sb.Append("</tr>");

            this.WriteContentToHtml(sb);

            if (!String.IsNullOrEmpty(detailsText))
            {
                sb.AppendFormat("<tr id=\"Task{0}\" class=\"TaskDetails\"><td><pre class=\"Logdetails\">{1}</pre></td></tr>",
                                this.Taskid,
                                detailsText);
            }

            sb.Append("</table>");
            sb.Append("</td>");
        }