using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Windows.Forms; using System.ComponentModel;namespace Tigerleq.Log { public abstract class LogBase : IDisposable { // Pointer to an external unmanaged resource. private IntPtr handle; // Other managed resource this class uses. private Component Components; // Track whether Dispose has been called. private bool disposed = false; // Implement IDisposable. // Do not make this method virtual. // A derived class should not be able to override this method. public void Dispose() { Dispose(true); // Take yourself off the Finalization queue // to prevent finalization code for this object // from executing a second time. GC.SuppressFinalize(this); } // Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. Components.Dispose(); } // Release unmanaged resources. If disposing is false, // only the following code is executed. CloseHandle(handle); handle = IntPtr.Zero; // Note that this is not thread safe. // Another thread could start disposing the object // after the managed resources are disposed, // but before the disposed flag is set to true. // If thread safety is necessary, it must be // implemented by the client. } disposed = true; } // Use C# destructor syntax for finalization code. // This destructor will run only if the Dispose method // does not get called. // It gives your base class the opportunity to finalize. // Do not provide destructors in types derived from this class. ~LogBase() { // Do not re-create Dispose clean-up code here. // Calling Dispose(false) is optimal in terms of // readability and maintainability. Dispose(false); } // Fields /// <summary> /// /// </summary> /// <param name="hObject"> handle to object</param> /// <returns></returns> [System.Runtime.InteropServices.DllImport("kernel32.dll")] private static extern bool CloseHandle(IntPtr hObject); protected string m_AddMsg; protected int m_iProcessID; protected int m_iThreadID; protected string m_sTime; // Methods public LogBase() { this.m_iProcessID = -1; this.m_iThreadID = -1; this.m_sTime = null; this.m_AddMsg = null; } public LogBase(string p_sAddMsg) { this.m_iProcessID = -1; this.m_iThreadID = -1; this.m_sTime = null; this.m_AddMsg = null; this.m_AddMsg = p_sAddMsg.Trim(); this.m_sTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); this.m_iProcessID = Process.GetCurrentProcess().Id; this.m_iThreadID = AppDomain.GetCurrentThreadId(); } // Properties public string AddMsg { get { return this.m_AddMsg; } } public int ProcessID { get { return this.m_iProcessID; } } public int ThreadID { get { return this.m_iThreadID; } } public string Time { get { return this.m_sTime; } } } }
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;namespace Tigerleq.Log
{
public abstract class LogBase : IDisposable
{ // Pointer to an external unmanaged resource.
private IntPtr handle;
// Other managed resource this class uses.
private Component Components;
// Track whether Dispose has been called.
private bool disposed = false; // Implement IDisposable.
// Do not make this method virtual.
// A derived class should not be able to override this method.
public void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue
// to prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
} // Dispose(bool disposing) executes in two distinct scenarios.
// If disposing equals true, the method has been called directly
// or indirectly by a user's code. Managed and unmanaged resources
// can be disposed.
// If disposing equals false, the method has been called by the
// runtime from inside the finalizer and you should not reference
// other objects. Only unmanaged resources can be disposed. protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
Components.Dispose();
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
CloseHandle(handle);
handle = IntPtr.Zero;
// Note that this is not thread safe.
// Another thread could start disposing the object
// after the managed resources are disposed,
// but before the disposed flag is set to true.
// If thread safety is necessary, it must be
// implemented by the client. }
disposed = true;
} // Use C# destructor syntax for finalization code.
// This destructor will run only if the Dispose method
// does not get called.
// It gives your base class the opportunity to finalize.
// Do not provide destructors in types derived from this class.
~LogBase()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
// readability and maintainability.
Dispose(false);
}
// Fields /// <summary>
///
/// </summary>
/// <param name="hObject"> handle to object</param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern bool CloseHandle(IntPtr hObject);
protected string m_AddMsg;
protected int m_iProcessID;
protected int m_iThreadID;
protected string m_sTime; // Methods
public LogBase()
{
this.m_iProcessID = -1;
this.m_iThreadID = -1;
this.m_sTime = null;
this.m_AddMsg = null;
} public LogBase(string p_sAddMsg)
{
this.m_iProcessID = -1;
this.m_iThreadID = -1;
this.m_sTime = null;
this.m_AddMsg = null;
this.m_AddMsg = p_sAddMsg.Trim();
this.m_sTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
this.m_iProcessID = Process.GetCurrentProcess().Id;
this.m_iThreadID = AppDomain.GetCurrentThreadId();
} // Properties
public string AddMsg
{
get
{
return this.m_AddMsg;
}
} public int ProcessID
{
get
{
return this.m_iProcessID;
}
} public int ThreadID
{
get
{
return this.m_iThreadID;
}
} public string Time
{
get
{
return this.m_sTime;
}
}
}
}
private static extern bool CloseHandle(IntPtr hObject);
{
private Queue<ConditionPair> _conditionPairQueue = new Queue<ConditionPair>();
public void Add(string joint, string condition)
{
if (condition != null && joint != null)
{
_conditionPairQueue.Enqueue(new ConditionPair(joint, condition));//队列Count为1,但是里面的数组是null
}//跟踪到这里count又变成0了
} public new string ToString() //不管是new还是override都不行,只要改个函数名就可以了,太妖了
{
int queueSize = _conditionPairQueue.Count;
if (queueSize == 0)
{
return null;
}
StringBuilder sb = new StringBuilder();
sb.Append(_conditionPairQueue.Dequeue().Condition);
bool isPreviousJointOR = false;
for (int i = 1; i < queueSize; i++)
{
ConditionPair conditionPair = _conditionPairQueue.Dequeue();
if (isPreviousJointOR)
{
sb.Insert(0, '(');
sb.Append(')');
}
sb.Append(' ');
sb.Append(conditionPair.Joint);
sb.Append(' ');
sb.Append(conditionPair.Condition);
isPreviousJointOR = conditionPair.Joint.ToLower() == "or";
}
return sb.ToString();
} #region IDisposable Members public void Dispose()
{
throw new Exception("The method or operation is not implemented.");
} #endregion
}