diff --git a/MarketData/MarketData/Services/MainService.cs b/MarketData/MarketData/Services/MainService.cs index b34cce2..1b18ef3 100755 --- a/MarketData/MarketData/Services/MainService.cs +++ b/MarketData/MarketData/Services/MainService.cs @@ -13,6 +13,78 @@ namespace MarketData.Services { public class MainService : IMainService { + /// + /// This is the main entry point + /// + /// + /// + 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("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("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("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("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)"); - } - } + } } \ No newline at end of file diff --git a/MarketData/MarketDataLib/Utility/Utility.cs b/MarketData/MarketDataLib/Utility/Utility.cs index a2ac51a..cb9f7f0 100755 --- a/MarketData/MarketDataLib/Utility/Utility.cs +++ b/MarketData/MarketDataLib/Utility/Utility.cs @@ -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(); + 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;