mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Initial checkin
This commit is contained in:
121
Bwg.Logging/Bwg.Logging.csproj
Normal file
121
Bwg.Logging/Bwg.Logging.csproj
Normal file
@@ -0,0 +1,121 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F2DFEB00-BB35-4665-85EA-CB8C7729A6B7}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Bwg.Logging</RootNamespace>
|
||||
<AssemblyName>Bwg.Logging</AssemblyName>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
<SccLocalPath>
|
||||
</SccLocalPath>
|
||||
<SccAuxPath>
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\Bwg.Logging.XML</DocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\Bwg.Logging.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile>bin\Debug\Bwg.Logging.XML</DocumentationFile>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile>bin\Release\Bwg.Logging.XML</DocumentationFile>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile>bin\Debug\Bwg.Logging.XML</DocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile>bin\Release\Bwg.Logging.XML</DocumentationFile>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConsoleSink.cs" />
|
||||
<Compile Include="FileSink.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="MemorySink.cs" />
|
||||
<Compile Include="MessageAddedArgs.cs" />
|
||||
<Compile Include="TeeSink.cs" />
|
||||
<Compile Include="UserMessage.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sink.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
47
Bwg.Logging/ConsoleSink.cs
Normal file
47
Bwg.Logging/ConsoleSink.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
|
||||
//
|
||||
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330,
|
||||
// Boston, MA 02111-1307 USA
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// A message sink class that writes messages to the console
|
||||
/// </summary>
|
||||
public class ConsoleSink : Sink
|
||||
{
|
||||
/// <summary>
|
||||
/// Log the message to the console
|
||||
/// </summary>
|
||||
/// <param name="m">the message</param>
|
||||
public override void LogMessage(UserMessage m)
|
||||
{
|
||||
if (m.Code == 0)
|
||||
System.Console.WriteLine(m.MType.ToString() + ": " + m.Text);
|
||||
else
|
||||
System.Console.WriteLine(m.MType.ToString() + " " + m.Code.ToString() + ": " + m.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
Bwg.Logging/FileSink.cs
Normal file
67
Bwg.Logging/FileSink.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO ;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is a message sink that writes the message to a file
|
||||
/// </summary>
|
||||
public class FileSink : Sink, IDisposable
|
||||
{
|
||||
#region private member variables
|
||||
private TextWriter m_writer;
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
/// <summary>
|
||||
/// Create a new file sink given the name of the output file
|
||||
/// </summary>
|
||||
/// <param name="filename">the output file</param>
|
||||
public FileSink(string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_writer = new StreamWriter(filename);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
m_writer = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public methods
|
||||
/// <summary>
|
||||
/// Dispose of the class, close the file
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close the file
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
if (m_writer != null)
|
||||
{
|
||||
m_writer.Flush();
|
||||
m_writer.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log the message
|
||||
/// </summary>
|
||||
/// <param name="m">the message to log</param>
|
||||
public override void LogMessage(UserMessage m)
|
||||
{
|
||||
if (m_writer != null)
|
||||
m_writer.WriteLine(m.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
213
Bwg.Logging/Logger.cs
Normal file
213
Bwg.Logging/Logger.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
//
|
||||
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
|
||||
//
|
||||
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330,
|
||||
// Boston, MA 02111-1307 USA
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// This class allows for the logging of messages
|
||||
/// </summary>
|
||||
public class Logger
|
||||
{
|
||||
/// <summary>
|
||||
/// This is used to lock the logger when multiple threads are
|
||||
/// trying to log messages concurrently
|
||||
/// </summary>
|
||||
private Object m_lock_object;
|
||||
|
||||
/// <summary>
|
||||
/// This is a map from message type to sinks
|
||||
/// </summary>
|
||||
private IDictionary<UserMessage.Category, Sink> m_sinks;
|
||||
|
||||
/// <summary>
|
||||
/// This is a map from the message type to the level that is being filtered. Anything
|
||||
/// below the value found here is not displayed
|
||||
/// </summary>
|
||||
private IDictionary<UserMessage.Category, int> m_level;
|
||||
|
||||
/// <summary>
|
||||
/// Create the logging object
|
||||
/// </summary>
|
||||
public Logger()
|
||||
{
|
||||
m_lock_object = new Object();
|
||||
m_sinks = new Dictionary<UserMessage.Category, Sink>();
|
||||
m_level = new Dictionary<UserMessage.Category, int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assocated a sink with a given type of message
|
||||
/// </summary>
|
||||
/// <param name="c">the category of message</param>
|
||||
/// <param name="s">the sink for this category of message</param>
|
||||
public void SetSink(UserMessage.Category c, Sink s)
|
||||
{
|
||||
lock (m_lock_object)
|
||||
{
|
||||
m_sinks[c] = s;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the sink given the type of message
|
||||
/// </summary>
|
||||
/// <param name="c">the type of sink</param>
|
||||
/// <returns>the sink associated with the message type</returns>
|
||||
public Sink GetSink(UserMessage.Category c)
|
||||
{
|
||||
Sink s = null;
|
||||
|
||||
lock (m_lock_object)
|
||||
{
|
||||
m_sinks.TryGetValue(c, out s);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets a level, below which messages are filtered
|
||||
/// </summary>
|
||||
/// <param name="c">the category to filter</param>
|
||||
/// <param name="level">the level to display</param>
|
||||
public void SetLevel(UserMessage.Category c, int level)
|
||||
{
|
||||
lock (m_lock_object)
|
||||
{
|
||||
m_level[c] = level;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given the category, this method returns the current
|
||||
/// level for this type of message
|
||||
/// </summary>
|
||||
/// <param name="c">the type of message</param>
|
||||
/// <returns>the current level</returns>
|
||||
public int GetLevel(UserMessage.Category c)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
lock (m_lock_object)
|
||||
{
|
||||
if (m_level.ContainsKey(c))
|
||||
ret = m_level[c];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove the sink associated with a specific category of message.
|
||||
/// </summary>
|
||||
/// <param name="c">the category of message</param>
|
||||
public void RemoveSink(UserMessage.Category c)
|
||||
{
|
||||
lock (m_lock_object)
|
||||
{
|
||||
m_sinks.Remove(c);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function returns TRUE if the logger has a message sink for the given
|
||||
/// category of message. Otherwise it returns FALSE.
|
||||
/// </summary>
|
||||
/// <param name="c">the category of interest</param>
|
||||
/// <returns>true if a sink is present, false otherwise</returns>
|
||||
public bool HasSink(UserMessage.Category c)
|
||||
{
|
||||
return m_sinks.Keys.Contains(c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a message
|
||||
/// </summary>
|
||||
/// <param name="m">the message to log</param>
|
||||
public void LogMessage(UserMessage m)
|
||||
{
|
||||
lock (m_lock_object)
|
||||
{
|
||||
if (m_sinks.ContainsKey(m.MType))
|
||||
{
|
||||
int level = 0;
|
||||
|
||||
if (m_level.ContainsKey(m.MType))
|
||||
level = m_level[m.MType];
|
||||
|
||||
if (m.Level <= level)
|
||||
{
|
||||
Sink s = m_sinks[m.MType];
|
||||
s.LogMessage(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dump a data buffer to the log file, used for debugging
|
||||
/// </summary>
|
||||
/// <param name="loglevel">the log level</param>
|
||||
/// <param name="title">the title</param>
|
||||
/// <param name="buffer">the buffer</param>
|
||||
/// <param name="size">the buffer size</param>
|
||||
public void DumpBuffer(uint loglevel, string title, IntPtr buffer, int size)
|
||||
{
|
||||
UserMessage m;
|
||||
|
||||
m = new UserMessage(UserMessage.Category.Debug, loglevel, "Dumping data for structure '" + title + "'");
|
||||
LogMessage(m);
|
||||
|
||||
int index = 0;
|
||||
int linebytes = 0;
|
||||
string str = string.Empty;
|
||||
while (index < size)
|
||||
{
|
||||
if (linebytes == 16)
|
||||
{
|
||||
m = new UserMessage(UserMessage.Category.Debug, loglevel, str);
|
||||
LogMessage(m);
|
||||
linebytes = 0;
|
||||
str = string.Empty;
|
||||
}
|
||||
|
||||
byte b = Marshal.ReadByte(buffer, index++);
|
||||
str += b.ToString("X2") + " ";
|
||||
linebytes++;
|
||||
}
|
||||
|
||||
if (linebytes != 0)
|
||||
{
|
||||
m = new UserMessage(UserMessage.Category.Debug, loglevel, str);
|
||||
LogMessage(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
114
Bwg.Logging/MemorySink.cs
Normal file
114
Bwg.Logging/MemorySink.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
|
||||
//
|
||||
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330,
|
||||
// Boston, MA 02111-1307 USA
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is a message sink that stores all of the messages
|
||||
/// in a list.
|
||||
/// </summary>
|
||||
public class MemorySink : Sink
|
||||
{
|
||||
private Object m_lock;
|
||||
private IList<UserMessage> m_list ;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public EventHandler<MessageAddedArgs> MessageAdded;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MemorySink()
|
||||
{
|
||||
m_lock = new Object();
|
||||
m_list = new List<UserMessage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetMessageCount()
|
||||
{
|
||||
int cnt;
|
||||
|
||||
lock (m_lock)
|
||||
{
|
||||
cnt = m_list.Count;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
/// <returns></returns>
|
||||
public UserMessage GetMessage(int n)
|
||||
{
|
||||
UserMessage m;
|
||||
|
||||
lock (m_lock)
|
||||
{
|
||||
m = m_list[n];
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
public override void LogMessage(UserMessage m)
|
||||
{
|
||||
lock (m_lock)
|
||||
{
|
||||
m_list.Add(m);
|
||||
}
|
||||
|
||||
if (MessageAdded != null)
|
||||
{
|
||||
MessageAddedArgs args = new MessageAddedArgs(m);
|
||||
MessageAdded(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
lock (m_lock)
|
||||
{
|
||||
m_list.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Bwg.Logging/MessageAddedArgs.cs
Normal file
49
Bwg.Logging/MessageAddedArgs.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
|
||||
//
|
||||
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330,
|
||||
// Boston, MA 02111-1307 USA
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MessageAddedArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public UserMessage AddedMessage;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
public MessageAddedArgs(UserMessage m)
|
||||
{
|
||||
AddedMessage = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Bwg.Logging/Properties/AssemblyInfo.cs
Normal file
35
Bwg.Logging/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Bwg.Logging")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BwgSoftware")]
|
||||
[assembly: AssemblyProduct("BwgBurn")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2006 by Jack W. Griffin, Jr.")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("216f12e9-2978-457c-95d6-32b4b87a361d")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("0.0.7.1")]
|
||||
[assembly: AssemblyFileVersion("0.0.7.1")]
|
||||
43
Bwg.Logging/Sink.cs
Normal file
43
Bwg.Logging/Sink.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
|
||||
//
|
||||
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330,
|
||||
// Boston, MA 02111-1307 USA
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract class that provides a place to send messages meant for the
|
||||
/// user. A class derived from this class is used to allow for GUI versus
|
||||
/// console applications
|
||||
/// </summary>
|
||||
abstract public class Sink
|
||||
{
|
||||
/// <summary>
|
||||
/// This method sends a message to a sink.
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
abstract public void LogMessage(UserMessage m);
|
||||
}
|
||||
}
|
||||
59
Bwg.Logging/TeeSink.cs
Normal file
59
Bwg.Logging/TeeSink.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is a message sink that forwards a message to a set of receiving sinks
|
||||
/// </summary>
|
||||
public class TeeSink : Sink
|
||||
{
|
||||
#region private member variables
|
||||
/// <summary>
|
||||
/// The list of sinks to send the message to
|
||||
/// </summary>
|
||||
IList<Sink> m_sinks;
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
/// <summary>
|
||||
/// The constructor to creat the object
|
||||
/// </summary>
|
||||
public TeeSink()
|
||||
{
|
||||
m_sinks = new List<Sink>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public methods
|
||||
/// <summary>
|
||||
/// Add the sink to the list of receiving sinks
|
||||
/// </summary>
|
||||
/// <param name="s">the sink to add</param>
|
||||
public void AddSink(Sink s)
|
||||
{
|
||||
m_sinks.Add(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the sink to the list of receiving sinks
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public void RemoveSink(Sink s)
|
||||
{
|
||||
m_sinks.Remove(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a message to the receiving sinks
|
||||
/// </summary>
|
||||
/// <param name="m">the message</param>
|
||||
public override void LogMessage(UserMessage m)
|
||||
{
|
||||
foreach (Sink s in m_sinks)
|
||||
s.LogMessage(m);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
117
Bwg.Logging/UserMessage.cs
Normal file
117
Bwg.Logging/UserMessage.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
|
||||
//
|
||||
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
// for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330,
|
||||
// Boston, MA 02111-1307 USA
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bwg.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// A message to be logged to the u
|
||||
/// </summary>
|
||||
public class UserMessage
|
||||
{
|
||||
#region Public Types
|
||||
/// <summary>
|
||||
/// Message types
|
||||
/// </summary>
|
||||
public enum Category
|
||||
{
|
||||
/// <summary>
|
||||
/// An error occurred
|
||||
/// </summary>
|
||||
Error,
|
||||
|
||||
/// <summary>
|
||||
/// A warning occurred
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// Information about the process
|
||||
/// </summary>
|
||||
Info,
|
||||
|
||||
/// <summary>
|
||||
/// Debugging information
|
||||
/// </summary>
|
||||
Debug
|
||||
} ;
|
||||
#endregion
|
||||
|
||||
#region Public Data Members
|
||||
/// <summary>
|
||||
/// The category for the message (error, warning, info, debug)
|
||||
/// </summary>
|
||||
public readonly Category MType ;
|
||||
|
||||
/// <summary>
|
||||
/// The numeric error code
|
||||
/// </summary>
|
||||
public readonly uint Code ;
|
||||
|
||||
/// <summary>
|
||||
/// The text for the error message
|
||||
/// </summary>
|
||||
public readonly string Text;
|
||||
|
||||
/// <summary>
|
||||
/// The level for the message, used to filter out messages
|
||||
/// </summary>
|
||||
public readonly uint Level;
|
||||
|
||||
/// <summary>
|
||||
/// This member contains a time stamp for the message
|
||||
/// </summary>
|
||||
public readonly DateTime When;
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
/// <summary>
|
||||
/// Constructor for a message
|
||||
/// </summary>
|
||||
/// <param name="t">Category of the message</param>
|
||||
/// <param name="level">Level of the message</param>
|
||||
/// <param name="s">Text of the message</param>
|
||||
public UserMessage(Category t, uint level, string s)
|
||||
{
|
||||
MType = t;
|
||||
Text = s;
|
||||
Level = level;
|
||||
When = DateTime.Now;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public member functions
|
||||
/// <summary>
|
||||
/// This method converts a user message to a single string
|
||||
/// </summary>
|
||||
/// <returns>the string that represnts the message</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return When.ToLongDateString() + " " + When.ToLongTimeString() + " : " + MType.ToString() + " : Level " + Level.ToString() + " : " + Text;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user