Major upgrade
This commit is contained in:
@@ -18,11 +18,11 @@ UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// A spot to hold application constants
|
||||
///
|
||||
/// </summary>
|
||||
public static class Constants
|
||||
{
|
||||
public const string InstrumentConfigFolder = "InstrumentConfig";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Raytheon.Common
|
||||
/// those which were removed. A typical use of this is to AddData(), then use CheckOutStartOfData()/CheckInStartOfData to get
|
||||
/// a pointer to the data and the amount of bytes that the pointer points to.
|
||||
/// </summary>
|
||||
public class DataBuffer: IDisposable
|
||||
public class DataBuffer : IDisposable
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private unsafe byte[] _buffer;
|
||||
@@ -220,25 +220,11 @@ namespace Raytheon.Common
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
lock (_syncObj)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
Dispose(true);
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,23 +286,9 @@ namespace Raytheon.Common
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
if (disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_pinnedArray.Free();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
_pinnedArray.Free();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Singleton for logging debug information and errors.
|
||||
/// </summary>
|
||||
public class ErrorLogger : IDisposable
|
||||
{
|
||||
#region PublicClassMembers
|
||||
|
||||
/// <summary>
|
||||
/// Enum for tagging the logged data.
|
||||
/// </summary>
|
||||
public enum LogLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// (Ordinal = 0) : Most verbose level. Used for development and seldom enabled in production.
|
||||
/// </summary>
|
||||
TRACE,
|
||||
/// <summary>
|
||||
/// (Ordinal = 1) : Debugging the application behavior from internal events of interest.
|
||||
/// </summary>
|
||||
DEBUG,
|
||||
/// <summary>
|
||||
/// An informational log statement.
|
||||
/// (Ordinal = 2) : Information that highlights progress or application lifetime events.
|
||||
/// </summary>
|
||||
INFO,
|
||||
/// <summary>
|
||||
/// (Ordinal = 3) : Warnings about validation issues or temporary failures that can be recovered.
|
||||
/// </summary>
|
||||
WARN,
|
||||
/// <summary>
|
||||
/// (Ordinal = 4) : Errors where functionality has failed or <see cref="System.Exception"/> have been caught.
|
||||
/// an error log statement.
|
||||
/// </summary>
|
||||
ERROR,
|
||||
/// <summary>
|
||||
/// (Ordinal = 5) : Most critical level. Application is about to abort.
|
||||
/// </summary>
|
||||
FATAL
|
||||
}
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateClassMembers
|
||||
private static ErrorLogger _errorLoggerInstance;
|
||||
#endregion
|
||||
|
||||
#region PublicClassFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Getter for this singleton.
|
||||
/// </summary>
|
||||
/// <param name="loggername">File location for Log.</param>
|
||||
/// <returns>The instance of this class.</returns>
|
||||
public static ErrorLogger Instance(string loggername = "CTS")
|
||||
{
|
||||
if (_errorLoggerInstance == null)
|
||||
{
|
||||
_errorLoggerInstance = new ErrorLogger(loggername);
|
||||
}
|
||||
|
||||
return _errorLoggerInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="logDestination">The logger destination</param>
|
||||
/// <param name="logname">The location of the file to write to.</param>
|
||||
/// <param name="form"></param>
|
||||
private ErrorLogger(string logname)
|
||||
{
|
||||
_logger = LogManager.GetLogger(logname);
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
//TODO: Unhandled exception if no nlog.config
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write data to the log file.
|
||||
/// </summary>
|
||||
/// <param name="message">The data to write.</param>
|
||||
public void Write(string message, LogLevel logLevel = LogLevel.ERROR)
|
||||
{
|
||||
_logger.Log(NLog.LogLevel.FromOrdinal((int)logLevel), message);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
@@ -85,23 +85,9 @@ namespace Raytheon.Common
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
}
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -315,8 +301,6 @@ namespace Raytheon.Common
|
||||
|
||||
try
|
||||
{
|
||||
ErrorLogger.Instance().Write("ExcelReader::ReadAllRows() - for sheet " + sheetName, ErrorLogger.LogLevel.INFO);
|
||||
|
||||
if (startingRow < 1 || startingCol < 1)
|
||||
{
|
||||
throw new Exception("ExcelReader::ReadAllRows() - startingRow and startingCol inputs must be greater than 0");
|
||||
@@ -414,34 +398,20 @@ namespace Raytheon.Common
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
if (disposing)
|
||||
{
|
||||
if (disposing)
|
||||
//close and release
|
||||
if (_excelWorkBook != null)
|
||||
{
|
||||
//close and release
|
||||
if (_excelWorkBook != null)
|
||||
{
|
||||
_excelWorkBook.Close();
|
||||
Marshal.ReleaseComObject(_excelWorkBook);
|
||||
}
|
||||
_excelWorkBook.Close();
|
||||
Marshal.ReleaseComObject(_excelWorkBook);
|
||||
}
|
||||
|
||||
//quit and release
|
||||
if (_excelApp != null)
|
||||
{
|
||||
_excelApp.Quit();
|
||||
Marshal.ReleaseComObject(_excelApp);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
try
|
||||
//quit and release
|
||||
if (_excelApp != null)
|
||||
{
|
||||
ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Do not rethrow. Exception from error logger that has already been garbage collected
|
||||
_excelApp.Quit();
|
||||
Marshal.ReleaseComObject(_excelApp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user