Browse Source
create TestReport to read Event log from machine git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5651 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
17 changed files with 496 additions and 70 deletions
@ -0,0 +1,149 @@ |
|||||||
|
/* |
||||||
|
* Erstellt mit SharpDevelop. |
||||||
|
* Benutzer: Peter Forstmeier |
||||||
|
* Datum: 24.03.2010 |
||||||
|
* Zeit: 19:45 |
||||||
|
* |
||||||
|
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.Drawing; |
||||||
|
using System.IO; |
||||||
|
using System.Management; |
||||||
|
using System.Reflection; |
||||||
|
using System.Resources; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.Reports.Core; |
||||||
|
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SharpReportSamples |
||||||
|
{ |
||||||
|
// public class EventList: List<EventLogEntry>{
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
/// <summary>
|
||||||
|
/// Description of EventLogger.
|
||||||
|
/// </summary>
|
||||||
|
public class EventLogger |
||||||
|
{ |
||||||
|
ImageList imageList ; |
||||||
|
string fileName; |
||||||
|
|
||||||
|
public EventLogger(string fileName) |
||||||
|
{ |
||||||
|
this.fileName = fileName; |
||||||
|
this.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
private void Run() { |
||||||
|
|
||||||
|
EventLog ev = new EventLog(); |
||||||
|
ev.Log = "System"; |
||||||
|
ev.MachineName = "."; // Lokale Maschine
|
||||||
|
|
||||||
|
FillImageList(); |
||||||
|
|
||||||
|
// EventLog dosn't implement IList, so we have to convert it to the 'cheapest'
|
||||||
|
// IList implementaion
|
||||||
|
//
|
||||||
|
|
||||||
|
ArrayList ar = new ArrayList(); |
||||||
|
|
||||||
|
foreach (System.Diagnostics.EventLogEntry entry in ev.Entries) |
||||||
|
{ |
||||||
|
if (entry.TimeWritten > DateTime.Now.AddDays(-1)) |
||||||
|
{ |
||||||
|
// Console.WriteLine ("{0} {1}",entry.TimeWritten,entry.Message);
|
||||||
|
ar.Add(entry); |
||||||
|
} |
||||||
|
} |
||||||
|
this.EventLog = ar; |
||||||
|
// ReportEngine engine = new ReportEngine();
|
||||||
|
|
||||||
|
// engine.SectionRendering += new EventHandler<SectionRenderEventArgs>(PushPrinting);
|
||||||
|
// engine.SectionRendered += new EventHandler<SectionRenderEventArgs>(PushPrinted);
|
||||||
|
// engine.PreviewPushDataReport(fileName,ar,null);
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// using (var provider = ProfilingDataSQLiteProvider.FromFile("ProfilingSession.sdps"))
|
||||||
|
// var functions = provider.GetFunctions(0, provider.DataSets.Count - 1);
|
||||||
|
// foreach (CallTreeNode n in functions) Console.WriteLine("{0}: {1} calls, {2:f2}ms", n.Name, n.CallCount, n.TimeSpent);
|
||||||
|
private void filter (EventLog e) |
||||||
|
{ |
||||||
|
/* |
||||||
|
int i = 0; |
||||||
|
foreach (System.Diagnostics.EventLogEntry entry in e.Entries) |
||||||
|
{ |
||||||
|
if (entry.TimeWritten > DateTime.Now.AddDays(-1)) |
||||||
|
{ |
||||||
|
Console.WriteLine ("{0} {1}",entry.TimeWritten,entry.Message); |
||||||
|
i++; |
||||||
|
} |
||||||
|
} |
||||||
|
*/ |
||||||
|
|
||||||
|
//http://blog-mstechnology.blogspot.com/2009/08/filter-eventlog-entries-thru-c-code.html
|
||||||
|
/* |
||||||
|
string SomeDateTime = "20100324000000.000000+000"; |
||||||
|
string Query = String.Format("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Application' AND TimeGenerated > '{0}'", SomeDateTime); |
||||||
|
|
||||||
|
ManagementObjectSearcher mos = new ManagementObjectSearcher(Query); |
||||||
|
object o; |
||||||
|
foreach (ManagementObject mo in mos.Get()) |
||||||
|
{ |
||||||
|
foreach (PropertyData pd in mo.Properties) |
||||||
|
{ |
||||||
|
o = mo[pd.Name]; |
||||||
|
if (o != null) |
||||||
|
{ |
||||||
|
// listBox1.Items.Add(String.Format("{0}: {1}", pd.Name,mo[pd.Name].ToString()));
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
private void FillImageList() { |
||||||
|
string ns = this.GetType().Namespace; |
||||||
|
|
||||||
|
System.Console.WriteLine("{0}",ns); |
||||||
|
|
||||||
|
Assembly a = Assembly.GetExecutingAssembly(); |
||||||
|
string [] resNames = a.GetManifestResourceNames(); |
||||||
|
foreach(string s in resNames) |
||||||
|
{ |
||||||
|
System.Console.WriteLine("{0}",s); |
||||||
|
} |
||||||
|
|
||||||
|
this.imageList = new ImageList(); |
||||||
|
|
||||||
|
Stream imgStream = a.GetManifestResourceStream("SharpReportSamples.Resources.Error.png"); |
||||||
|
this.imageList.Images.Add(Image.FromStream(imgStream)); |
||||||
|
|
||||||
|
imgStream = a.GetManifestResourceStream("SharpReportSamples.Resources.Info.png"); |
||||||
|
this.imageList.Images.Add(Image.FromStream(imgStream)); |
||||||
|
|
||||||
|
imgStream = a.GetManifestResourceStream("SharpReportSamples.Resources.Warning.png"); |
||||||
|
this.imageList.Images.Add(Image.FromStream(imgStream)); |
||||||
|
|
||||||
|
System.Console.WriteLine("imagelist contains {0} images",this.imageList.Images.Count); |
||||||
|
} |
||||||
|
|
||||||
|
public ArrayList EventLog {get;set;} |
||||||
|
|
||||||
|
public ImageList Images |
||||||
|
{ |
||||||
|
get {return this.imageList;} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* Erstellt mit SharpDevelop. |
||||||
|
* Benutzer: Peter Forstmeier |
||||||
|
* Datum: 24.03.2010 |
||||||
|
* Zeit: 19:31 |
||||||
|
* |
||||||
|
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Runtime.Serialization; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reports.Core |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of WrongSectionException.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable()] |
||||||
|
public class WrongSectionException: Exception |
||||||
|
{ |
||||||
|
|
||||||
|
public WrongSectionException():base() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public WrongSectionException(string errorMessage) :base (errorMessage) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public WrongSectionException(string errorMessage, |
||||||
|
Exception exception):base (errorMessage,exception) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected WrongSectionException(SerializationInfo info, |
||||||
|
StreamingContext context) : base(info, context) |
||||||
|
{ |
||||||
|
// Implement type-specific serialization constructor logic.
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,143 @@ |
|||||||
|
/* |
||||||
|
* Erstellt mit SharpDevelop. |
||||||
|
* Benutzer: Peter Forstmeier |
||||||
|
* Datum: 28.03.2010 |
||||||
|
* Zeit: 17:31 |
||||||
|
* |
||||||
|
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern. |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reports.Core.Test.BaseItems |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class BaseSectionFixture |
||||||
|
{ |
||||||
|
#region constructor
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void PlainConstructor() |
||||||
|
{ |
||||||
|
BaseSection section = new BaseSection(); |
||||||
|
Assert.AreEqual(String.Empty,section.Name); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ConstructorWithNameAsParam () |
||||||
|
{ |
||||||
|
BaseSection section = new BaseSection("mysection"); |
||||||
|
Assert.AreEqual("mysection",section.Name); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region initialvalues
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CheckInitialValues () |
||||||
|
{ |
||||||
|
BaseSection section = new BaseSection(); |
||||||
|
Assert.AreEqual(0,section.Items.Count); |
||||||
|
Assert.AreEqual(0,section.SectionMargin); |
||||||
|
Assert.AreEqual(0,section.SectionOffset); |
||||||
|
Assert.AreEqual(false,section.PageBreakAfter); |
||||||
|
Assert.AreEqual(false,section.DrawBorder); |
||||||
|
Assert.AreEqual(System.Drawing.Color.White,section.BackColor); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FindItem_NoContainer() |
||||||
|
{ |
||||||
|
BaseSection section = ConfigurePlainSection(); |
||||||
|
BaseReportItem item = section.FindItem("ImageItem"); |
||||||
|
Assert.That(item != null); |
||||||
|
Assert.IsInstanceOf(typeof(BaseImageItem),item); |
||||||
|
Assert.That(item.Name == "ImageItem"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FindItemNullIfItemNotExist() |
||||||
|
{ |
||||||
|
BaseSection section = ConfigurePlainSection(); |
||||||
|
BaseReportItem item = section.FindItem("notexist"); |
||||||
|
Assert.IsNull(item); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FindItemInRow () |
||||||
|
{ |
||||||
|
BaseSection section = ConfigureSectionWithRow(); |
||||||
|
BaseReportItem item = section.FindItem("TextItem"); |
||||||
|
Assert.That(item != null); |
||||||
|
Assert.IsInstanceOf(typeof(BaseTextItem),item); |
||||||
|
Assert.That(item.Name == "TextItem"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FindItemInRowNullIfItemNotExist () |
||||||
|
{ |
||||||
|
BaseSection section = ConfigureSectionWithRow(); |
||||||
|
BaseReportItem item = section.FindItem("notexist"); |
||||||
|
Assert.IsNull(item); |
||||||
|
} |
||||||
|
|
||||||
|
private BaseSection ConfigureSectionWithRow () |
||||||
|
{ |
||||||
|
BaseSection section = new BaseSection(); |
||||||
|
BaseRowItem row = new BaseRowItem(); |
||||||
|
BaseTextItem bti = new BaseTextItem{ |
||||||
|
Name = "TextItem" |
||||||
|
}; |
||||||
|
|
||||||
|
BaseImageItem bii = new BaseImageItem(){ |
||||||
|
Name = "ImageItem" |
||||||
|
}; |
||||||
|
row.Items.Add(bti); |
||||||
|
row.Items.Add(bii); |
||||||
|
section.Items.Add(row); |
||||||
|
return section; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private BaseSection ConfigurePlainSection () |
||||||
|
{ |
||||||
|
BaseSection section = new BaseSection(); |
||||||
|
BaseTextItem bti = new BaseTextItem{ |
||||||
|
Name = "TextItem" |
||||||
|
}; |
||||||
|
|
||||||
|
BaseImageItem bii = new BaseImageItem(){ |
||||||
|
Name = "ImageItem" |
||||||
|
}; |
||||||
|
section.Items.Add(bti); |
||||||
|
section.Items.Add(bii); |
||||||
|
return section; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
#region
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
// TODO: Add Init code.
|
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
// TODO: Add tear down code.
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue