Skip to content

Commit

Permalink
Add printing support.
Browse files Browse the repository at this point in the history
  • Loading branch information
AKPWebDesign committed Jul 31, 2015
1 parent 3d2a6a9 commit 5553a18
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 85 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -214,3 +214,6 @@ FakesAssemblies/
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# FireLogic logo (get your own)
logo.png
2 changes: 1 addition & 1 deletion BootTimeCheck.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootTimeCheck", "BootTimeCheck\BootTimeCheck.csproj", "{73F708A5-2D7F-4070-A0DE-4DD6D2F4413E}"
EndProject
Expand Down
2 changes: 2 additions & 0 deletions BootTimeCheck/BootTimeCheck.csproj
Expand Up @@ -94,6 +94,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.manifest" />
<None Include="Properties\Settings.settings">
Expand Down Expand Up @@ -128,6 +129,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
<EmbeddedResource Include="logo.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
178 changes: 134 additions & 44 deletions BootTimeCheck/Main.Designer.cs

Large diffs are not rendered by default.

134 changes: 132 additions & 2 deletions BootTimeCheck/Main.cs
Expand Up @@ -3,6 +3,8 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -14,12 +16,17 @@ public partial class Main : Form
{
public Main(EventLogInfoReader eL)
{
EventLogInfoReader eventLog = eL;
this.eventLog = eL;
InitializeComponent();
Random rnd = new Random();

this.data = eL.ReadEventLogData();
cbxBoots.SelectedIndex = 0;

this.printPreviewDialog = new PrintPreviewDialog();
this.printDocument = new PrintDocument();
this.pageSetupDialog = new PageSetupDialog();
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
}

private void drawData(int eventCount)
Expand All @@ -31,6 +38,7 @@ private void drawData(int eventCount)
minBox.Text = FindMinValue(lastX) / 1000 + "s";
avgBox.Text = FindMean(lastX) / 1000 + "s";
improvementBox.Text = FindImprovement(lastX) / 1000 + "s";
barProgress.Value = 50;
}

private int FindMaxValue(List<IEvent> list)
Expand Down Expand Up @@ -86,6 +94,7 @@ private void SetUpChart(List<IEvent> list)
//gather data points from EventLogInfoReader
for (int events = 0; events < list.Count(); events++)
{
barProgress.Value = 0;
int bootTime = list.ToArray()[events].BootTime() / 1000;
int mainPath = list.ToArray()[events].MainPath() / 1000;
int postBoot = list.ToArray()[events].PostBoot() / 1000;
Expand All @@ -104,6 +113,7 @@ private void SetUpChart(List<IEvent> list)
color = Color.LimeGreen;
break;
}
barProgress.Value = 50;

createPoint(events, bootTime, color, list);

Expand All @@ -119,6 +129,7 @@ private void SetUpChart(List<IEvent> list)
//}

chart1.Series["Series"].Points[events].AxisLabel = list.ToArray()[events].DateTime().Date.ToShortDateString();
barProgress.Value = 100;
}
}

Expand All @@ -139,7 +150,17 @@ private void chartLabelCheck(List<IEvent> list, int events, int point)
}
}

private void cbxBoots_SelectedIndexChanged(object sender, System.EventArgs e)
private void refreshData()
{
barProgress.Value = 0;
lblStatus.Text = "Refreshing...";
this.data = this.eventLog.ReadEventLogData();
barProgress.Value = 25;
showData();
lblStatus.Text = "Data Refreshed!";
}

private void showData()
{
int[] math = new int[6];
math[0] = 2;
Expand All @@ -149,15 +170,124 @@ private void cbxBoots_SelectedIndexChanged(object sender, System.EventArgs e)
math[4] = 21;
math[5] = Int32.MaxValue;

barProgress.Value = 30;

int count = math[cbxBoots.SelectedIndex];

if (count > data.Count)
{
count = data.Count;
}

drawData(count);
barProgress.Value = 100;
lblStatus.Text = "Data loaded!";
}

private void cbxBoots_SelectedIndexChanged(object sender, System.EventArgs e)
{
showData();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
refreshData();
}

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Font printFont = new Font("Segoe UI", 12);
Font titleFont = new Font("Segoe UI", 18, FontStyle.Bold);
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

Rectangle titleRect = new Rectangle(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, 40);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Near;

e.Graphics.DrawString("Boot Time Report", titleFont, Brushes.Black, titleRect, format);


Rectangle rect = new Rectangle(e.MarginBounds.Left, e.MarginBounds.Top + 40, e.MarginBounds.Width, e.MarginBounds.Height/2);
chart1.Printing.PrintPaint(e.Graphics, rect);
int lineLocation = e.MarginBounds.Top + e.MarginBounds.Height/2 + 50;
Rectangle pageBounds = new Rectangle(e.MarginBounds.Left, lineLocation, e.MarginBounds.Width, e.MarginBounds.Height / 2);

int pointCount = (chart1.Series["Series"].Points.Count - 1);
String pointWord = (pointCount == 1) ? "boot" : "boots";

double percentageDifference = chart1.Series["Series"].Points[chart1.Series["Series"].Points.Count-1].YValues[0] / chart1.Series["Series"].Points[0].YValues[0];
percentageDifference = 100 - Math.Round(percentageDifference, 2) * 100;

String statsTitleString = "Statistics for last " + pointCount + " " + pointWord + ":\n";
Font statsTitleFont = new Font("Segoe UI", 14, FontStyle.Bold | FontStyle.Underline);

String statsString = "Average boot time: " + avgBox.Text + "\n" +
"Minimum boot time: " + minBox.Text + "\n" +
"Maximum boot time: " + maxBox.Text + "\n" +
"Time savings: " + percentageDifference + "%\n" +
"Time savings (in seconds): " + improvementBox.Text + "\n";

e.Graphics.DrawString(statsTitleString, statsTitleFont, Brushes.Black, pageBounds, format);
pageBounds.Offset(0, 25);
e.Graphics.DrawString(statsString, printFont, Brushes.Black, pageBounds, format);

System.Reflection.Assembly myAss = System.Reflection.Assembly.GetExecutingAssembly();
if (myAss.GetManifestResourceNames().Contains("BootTimeCheck.logo.png"))
{
Stream myStream = myAss.GetManifestResourceStream("BootTimeCheck.logo.png");
Bitmap logo = new Bitmap(myStream);
Rectangle logoRect = new Rectangle(e.MarginBounds.Right - logo.Width / 5, e.MarginBounds.Bottom - logo.Height / 5, logo.Width / 5, logo.Height / 5);
e.Graphics.DrawImage(logo, logoRect);
}
}

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printPreviewDialog.Document = printDocument;
printPreviewDialog.SetDesktopBounds(100, 100, 600, 800);
printPreviewDialog.ShowDialog();
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.P))
{
printPreviewDialog.Document = printDocument;
printPreviewDialog.ShowDialog();
return true;
}

if (keyData == (Keys.Control | Keys.X))
{
Application.Exit();
return true;
}

if (keyData == Keys.F5)
{
refreshData();
return true;
}

return base.ProcessCmdKey(ref msg, keyData);
}

public List<IEvent> data { get; set; }

public EventLogInfoReader eventLog { get; set; }

public PrintPreviewDialog printPreviewDialog { get; set; }

public PrintDocument printDocument { get; set; }

public PageSetupDialog pageSetupDialog { get; set; }
}
}
6 changes: 6 additions & 0 deletions BootTimeCheck/Main.resx
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
42 changes: 17 additions & 25 deletions BootTimeCheck/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions BootTimeCheck/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5553a18

Please sign in to comment.