Fix missing logfile

This commit is contained in:
2025-03-25 22:28:39 -04:00
parent 5cdc726b2f
commit ca98ebfc74
2 changed files with 96 additions and 64 deletions

View File

@@ -13,6 +13,78 @@ namespace MarketData.Services
{
public class MainService : IMainService
{
/// <summary>
/// This is the main entry point
/// </summary>
/// <param name="args"></param>
/// <param name="configuration"></param>
public void RunService(String[] args,IConfiguration configuration)
{
Profiler profiler = new Profiler();
MDTrace.LogLevel = LogLevel.DEBUG;
String strLogFile = "marketdata.log";
Utility.DeleteFile(strLogFile);
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
DateTime currentDate=DateTime.Now;
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Started @ {Utility.DateTimeToStringYYYYHMMHDDHHMMSSTT(currentDate)}");
GlobalConfig.Instance.Configuration = configuration; // This call sets up configuration stuff so it needs to be first.
DateTime maxHolidayDate =HolidayDA.GetMaxHolidayDate();
if(currentDate>maxHolidayDate)
{
Console.WriteLine(String.Format("There are no holidays defined in the system. Add holidays for year {0} into marketholidays table",currentDate.Year));
return;
}
if (args.Length < 1)
{
DisplayUsage();
return;
}
string arg = args[0].ToUpper();
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Argument {arg}");
try
{
if(arg.Equals("LOADHEADLINESWATCHLIST"))
{
CommandArgs commandArgs=new CommandArgs(args);
if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("LOADHEADLINESWATCHLIST REQUIRES WATCHLIST");return;}
else LoadHeadlinesWatchList(commandArgs.Coalesce<String>("WATCHLIST"));
}
else if(arg.Equals("LOADPREMARKETDATA"))
{
LoadPremarketData();
}
else if (arg.Equals("UPDATEDAILY2"))
{
CommandArgs commandArgs=new CommandArgs(args);
if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEDAILY2 MISSING DATE");return;}
UpdateDaily2(commandArgs.Coalesce<DateTime>("DATE"));
}
else
{
DisplayUsage();
}
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
return;
}
finally
{
LocalPriceCache.GetInstance().Dispose();
GBPriceCache.GetInstance().Dispose();
}
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Done, total took {profiler.End()}(ms)");
}
// *********************************************************************************************************************************
// *********************************************************************************************************************************
// *********************************************************************************************************************************
public static void DisplayUsage()
{
MDTrace.WriteLine(LogLevel.DEBUG,$"USAGE");
@@ -57,7 +129,7 @@ namespace MarketData.Services
String result=Console.ReadLine();
if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return;
}
Utility.RemoveLogFiles();
Utility.RemoveLogFilesExcept("marketdata.log"); // don't remove the current log file
int STAGE_1=0,STAGE_2=1,STAGE_3=2,STAGE_4=3,STAGE_5=4,STAGE_6=5,STAGE_7=6,STAGE_8=7,STAGE_9=8,STAGE_10=9,STAGE_11=10,STAGE_12=11,STAGE_FINAL=12;
DeletePriceWatchList("valuations",startDate.ToShortDateString());
DeletePriceWatchList("Momentum",startDate.ToShortDateString());
@@ -527,67 +599,5 @@ namespace MarketData.Services
return true;
}
public void RunService(String[] args,IConfiguration configuration)
{
Profiler profiler = new Profiler();
MDTrace.LogLevel = LogLevel.DEBUG;
String strLogFile = "marketdata.log";
Utility.DeleteFile(strLogFile);
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
DateTime currentDate=DateTime.Now;
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Started @ {Utility.DateTimeToStringYYYYHMMHDDHHMMSSTT(currentDate)}");
GlobalConfig.Instance.Configuration = configuration; // This call sets up configuration stuff so it needs to be first.
DateTime maxHolidayDate =HolidayDA.GetMaxHolidayDate();
if(currentDate>maxHolidayDate)
{
Console.WriteLine(String.Format("There are no holidays defined in the system. Add holidays for year {0} into marketholidays table",currentDate.Year));
return;
}
if (args.Length < 1)
{
DisplayUsage();
return;
}
string arg = args[0].ToUpper();
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Argument {arg}");
try
{
if(arg.Equals("LOADHEADLINESWATCHLIST"))
{
CommandArgs commandArgs=new CommandArgs(args);
if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("LOADHEADLINESWATCHLIST REQUIRES WATCHLIST");return;}
else LoadHeadlinesWatchList(commandArgs.Coalesce<String>("WATCHLIST"));
}
else if(arg.Equals("LOADPREMARKETDATA"))
{
LoadPremarketData();
}
else if (arg.Equals("UPDATEDAILY2"))
{
CommandArgs commandArgs=new CommandArgs(args);
if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEDAILY2 MISSING DATE");return;}
UpdateDaily2(commandArgs.Coalesce<DateTime>("DATE"));
}
else
{
DisplayUsage();
}
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
return;
}
finally
{
LocalPriceCache.GetInstance().Dispose();
GBPriceCache.GetInstance().Dispose();
}
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Done, total took {profiler.End()}(ms)");
}
}
}
}

View File

@@ -77,6 +77,7 @@ namespace MarketData.Utils
DateTime date=javascriptEpoch+timespan;
return date;
}
public static void RemoveLogFiles(String strFolder=null)
{
if(null==strFolder)strFolder=Directory.GetCurrentDirectory();
@@ -94,6 +95,27 @@ namespace MarketData.Utils
catch(Exception){;}
}
}
public static void RemoveLogFilesExcept(String exceptFile,String strFolder=null)
{
if(null==strFolder)strFolder=Directory.GetCurrentDirectory();
String[] logFiles=Directory.GetFiles(strFolder);
if(null==logFiles || 0==logFiles.Length)return;
logFiles=logFiles
.Where(x => x.EndsWith(".log",StringComparison.InvariantCultureIgnoreCase) &&
!x.Equals(exceptFile,StringComparison.InvariantCultureIgnoreCase)).ToArray<String>();
if(null==logFiles || 0==logFiles.Length)return;
foreach(String logFile in logFiles)
{
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Removing {0}",logFile));
File.Delete(logFile);
}
catch(Exception){;}
}
}
public static String Pad(string str, char filler, int length)
{
int stringLength = str.Length;