Ejemplo n.º 1
0
        /// <summary>
        /// Overridden. Renders the JobView as a table.
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            /* TODO: rewrite this to use child WebControls instead of a bunch of writer.writes. */
            if (HttpContext.Current == null)
            {
                StringBuilder sb = new StringBuilder();

                sb.Append("<p style=\"font-family: " + this.Font.Name + "; font-size: " + this.Font.Size.ToString() + "; color: #FFFF99; border: outset 1px #000000; padding: 0; background-color: #5a7ab8\">");
                {
                    sb.Append("<b>JobView</b>");
                }
                sb.Append("</p>");

                writer.Write(sb.ToString());
                base.Render(writer);
            }
            else
            {
                AddAttributesToRender(writer);

                StringBuilder sb = new StringBuilder();
                sb.Append("No jobs found at web.config");

                Jobs jobInstance = Jobs.Instance();
                if (jobInstance != null)
                {
                    string tableClass                = string.Empty,
                           tableHeaderClass          = string.Empty,
                           tableCellClass            = string.Empty,
                           tableEnumeratingCellClass = string.Empty,
                           cellValueTrue             = string.Empty,
                           cellValueFalse            = string.Empty;

                    #region get styles
                    switch (Theme)
                    {
                    case JobViewTheme.None:
                        tableClass                = string.IsNullOrEmpty(TableCssClass) ? "" : (" class=\"" + TableCssClass + "\"");
                        tableHeaderClass          = string.IsNullOrEmpty(TableHeaderCssClass) ? "" : (" class=\"" + TableHeaderCssClass + "\"");
                        tableCellClass            = string.IsNullOrEmpty(TableCellCssClass) ? "" : (" class=\"" + TableCellCssClass + "\"");
                        tableEnumeratingCellClass = string.IsNullOrEmpty(TableEnumeratingCellCssClass) ? "" : (" class=\"" + TableEnumeratingCellCssClass + "\"");
                        break;

                    case JobViewTheme.Default:
                        tableClass       = @" style=""width: 100%; border: Solid 2px #5a7ab8; font-family: " + this.Font.Name + @"; font-size: " + this.Font.Size.ToString() + @"""";
                        tableHeaderClass = @" style=""background-color: #5A7AB8; color: #FFFFFF; padding: 2px 4px 2px 4px; border: Solid 1px #5A7AB8; border-collapse: collapse;""";
                        tableCellClass   = @" style=""background-color: {0}; color: #000000; padding: 2px 2px 2px 2px; border-left: Solid 1px #000000; border-right: Solid 1px #dddddd; border-bottom: Solid 1px #dddddd; border-top: Solid 1px #000000; border-collapse: collapse;""";
                        break;
                    }
                    #endregion

                    sb = new StringBuilder();
                    sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin-bottom: 20px;\">");
                    sb.Append(
                        @"
<tr>
    <td align=""left""><strong>Created:</strong></td>
    <td align=""left"" style=""padding-left: 12px;"">" + jobInstance.Created.ToString("HH:mm:ss") + @"</td>
</tr>
<tr>
    <td align=""left""><strong>IsRunning:</strong></td>
    <td align=""left"" style=""padding-left: 12px;"">" + jobInstance.IsRunning + @"</td>
</tr>
<tr>
    <td align=""left""><strong>Last start:</strong></td>
    <td align=""left"" style=""padding-left: 12px;"">" + jobInstance.LastStart.ToString("HH:mm:ss") + @"</td>
</tr>
<tr>
    <td align=""left""><strong>Last stop:</strong></td>
    <td align=""left"" style=""padding-left: 12px;"">" + jobInstance.LastStop.ToString("HH:mm:ss") + @"</td>
</tr>
<tr>
    <td align=""left""><strong>Default Interval:</strong></td>
    <td align=""left"" style=""padding-left: 12px;"">" + jobInstance.Minutes.ToString() + @" minutes</td>
</tr>
");
                    sb.Append("</table>");

                    sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"" + tableClass + ">");
                    sb.Append(
                        @"
<tr>
    <th" + tableHeaderClass + @">Name</th>
    <th" + tableHeaderClass + @">Type</th>
    <th" + tableHeaderClass + @">IsRunning</th>
    <th" + tableHeaderClass + @">LastStart</th>
    <th" + tableHeaderClass + @">LastEnd</th>
    <th" + tableHeaderClass + @">LastSuccess</th>
    <th" + tableHeaderClass + @">Single Thread</th>
    <th" + tableHeaderClass + @">Interval</th>
</tr>
");
                    DateTime nullTime = new DateTime();
                    foreach (Job job in Jobs.Instance().CurrentJobs)
                    {
                        string lastEnd = "&nbsp;";
                        if (job.LastEnd.CompareTo(nullTime) != 0)
                        {
                            lastEnd = job.LastEnd.ToString("HH:mm:ss");
                        }
                        string lastStart = "&nbsp;";
                        if (job.LastStarted.CompareTo(nullTime) != 0)
                        {
                            lastStart = job.LastStarted.ToString("HH:mm:ss");
                        }
                        string lastSuccess = "&nbsp;";
                        if (job.LastSuccess.CompareTo(nullTime) != 0)
                        {
                            lastSuccess = job.LastSuccess.ToString("HH:mm:ss");
                        }

                        sb.AppendFormat(
                            @"
<tr>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + job.Name + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + job.JobType.ToString() + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetBooleanValueColor(Theme, job.IsRunning)) : tableCellClass) + @" align=""center"">" + job.IsRunning.ToString() + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + lastStart + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + lastEnd + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + lastSuccess + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetBooleanValueColor(Theme, job.ExecuteOnOwnThread)) : tableCellClass) + @" align=""center"">" + job.ExecuteOnOwnThread.ToString() + @"</td>
    <td" + (Theme != JobViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + (job.Interval.ToString()) + @"</td>
</tr>
");
                    }
                    sb.Append("</table>");
                }

                writer.Write(sb.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <see cref="JobView.Render"/>
        protected override void Render(HtmlTextWriter writer)
        {
            if (HttpContext.Current == null)
            {
                StringBuilder sb = new StringBuilder();

                sb.Append("<p style=\"font-family: " + this.Font.Name + "; font-size: " + this.Font.Size.ToString() + "; color: #FFFF99; border: outset 1px #000000; padding: 0; background-color: #5a7ab8\">");
                {
                    sb.Append("<b>CacheView</b>");
                }
                sb.Append("</p>");

                writer.Write(sb.ToString());
                base.Render(writer);
            }
            else
            {
                AddAttributesToRender(writer);

                StringBuilder sb = new StringBuilder();

                List <CachedElement> elements   = new List <CachedElement>();
                ICacheController     controller = CacheControllerFactory.CreateCacheController();
                foreach (ICacheItem item in controller.CacheItems.Values)
                {
                    elements.Add(new CachedElement(item, controller));
                }

                sb.Append("No cache item definitions found at the web configuration cache section.");
                if (elements.Count > 0)
                {
                    string tableClass                = string.Empty,
                           tableHeaderClass          = string.Empty,
                           tableCellClass            = string.Empty,
                           tableEnumeratingCellClass = string.Empty,
                           cellValueTrue             = string.Empty,
                           cellValueFalse            = string.Empty,
                           cellValueCIP              = string.Empty,
                           cellValueCIPNotRemovable  = string.Empty,
                           cellValueCIPHigh          = string.Empty,
                           cellValueCIPAboveNormal   = string.Empty,
                           cellValueCIPNormal        = string.Empty,
                           cellValueCIPBelowNormal   = string.Empty,
                           cellValueCIPLow           = string.Empty;

                    #region get styles
                    switch (Theme)
                    {
                    case CacheViewTheme.None:
                        tableClass                = string.IsNullOrEmpty(TableCssClass) ? "" : (" class=\"" + TableCssClass + "\"");
                        tableHeaderClass          = string.IsNullOrEmpty(TableHeaderCssClass) ? "" : (" class=\"" + TableHeaderCssClass + "\"");
                        tableCellClass            = string.IsNullOrEmpty(TableCellCssClass) ? "" : (" class=\"" + TableCellCssClass + "\"");
                        tableEnumeratingCellClass = string.IsNullOrEmpty(TableEnumeratingCellCssClass) ? "" : (" class=\"" + TableEnumeratingCellCssClass + "\"");
                        break;

                    case CacheViewTheme.Default:
                        tableClass                = @" style=""width: 100%; border: Solid 2px #5a7ab8; font-family: " + this.Font.Name + @"; font-size: " + this.Font.Size.ToString() + @"""";
                        tableHeaderClass          = @" style=""background-color: #5A7AB8; color: #FFFFFF; padding: 2px 4px 2px 4px; border: Solid 1px #5A7AB8; border-collapse: collapse;""";
                        tableCellClass            = @" style=""background-color: {0}; color: #000000; padding: 2px 2px 2px 2px; border-left: Solid 1px #000000; border-right: Solid 1px #dddddd; border-bottom: Solid 1px #dddddd; border-top: Solid 1px #000000; border-collapse: collapse;""";
                        tableEnumeratingCellClass =
                            @" style=""width: 100%; background-color: {0}; color: #000000; padding: 2px 2px 2px 16px; border-left: Solid 1px #000000; border-right: Solid 1px #dddddd; border-bottom: Solid 1px #dddddd; border-top: None; border-collapse: collapse;""";
                        break;
                    }
                    #endregion

                    sb = new StringBuilder();
                    sb.Append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"" + tableClass + ">");
                    sb.Append(
                        @"
<tr>
    <th" + tableHeaderClass + @">Name</th>
    <th" + tableHeaderClass + @">Type</th>
    <th" + tableHeaderClass + @">Enabled</th>
    <th" + tableHeaderClass + @">IsUsed</th>
    <th" + tableHeaderClass + @">Interval (minutes)</th>
    <th" + tableHeaderClass + @">Objects</th>
    <th" + tableHeaderClass + @">Priority</th>
</tr>
");
                    foreach (CachedElement element in elements)
                    {
                        sb.Append(
                            @"
<tr>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + element.Name + @"</td>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""left"">" + element.Type.ToString() + @"</td>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetBooleanValueColor(Theme, element.Enabled)) : tableCellClass) + @" align=""center"">" + element.Enabled.ToString() + @"</td>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetBooleanValueColor(Theme, element.IsUsed)) : tableCellClass) + @" align=""center"">" + element.IsUsed.ToString() + @"</td>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""center"">" + element.Minutes.ToString() + @"</td>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableCellClass) + @" align=""center"">" + element.NumberOfObjects.ToString() + @"</td>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableCellClass, ThemeColors.GetCacheItemPriorityColor(Theme, element.CacheItemPriority)) : tableCellClass) + @" align=""center"">" + element.CacheItemPriority.ToString() + @"</td>
</tr>
");

                        if (element.IsIterating)
                        {
                            foreach (string name in element.EnumeratedElements)
                            {
                                sb.Append(
                                    @"
<tr>
    <td" + (Theme != CacheViewTheme.None ? String.Format(tableEnumeratingCellClass, ThemeColors.GetDefaultCellBgColor(Theme)) : tableEnumeratingCellClass) + @" colspan=""7"" align=""left"">-&gt; " + name + @"</td>
</tr>
");
                            }
                        }
                    }
                    sb.Append("</table>");
                }

                writer.Write(sb.ToString());
            }
        }