public static void LoadCheckPoint() { if (!File.Exists(CPFile)) { return; } BinaryFormatter formatter = new BinaryFormatter(); using (FileStream s = File.OpenRead(CPFile)) { CP = (CheckPoint)formatter.Deserialize(s); } }
static void Main(string[] args) { // Refer to http://stackoverflow.com/questions/4470700/c-sharp-how-to-save-console-writeline-outputs-to-text-file // LogFile = string.Format("log-{0:MMddyy-HHmmss}.txt", DateTime.Now); FileStream fileStream = new FileStream(LogFile, FileMode.Create); StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.AutoFlush = true; TextWriter savedCons = Console.Out; Console.SetOut(streamWriter); Console.SetError(streamWriter); if (CPEnabled) { LoadCheckPoint(); if (CP == null) { CP = new CheckPoint(); } } string strConnHis = "MultiEndpoint.Properties.Settings.hiscentralConnectionString"; SqlConnection sqlConnHis = GetDatabaseConnection(strConnHis); HisSC = new hiscentralSeriesCatalog(sqlConnHis); string strConnQuery = "MultiEndpoint.Properties.Settings.HealthQueryConnectionString"; SqlConnection sqlConnHealth = GetDatabaseConnection(strConnQuery); HQT = new HealthQueryTimeseries(sqlConnHealth); HDV = new HealthDataValue(sqlConnHealth); HSC = new HealthSeriesCatalog(sqlConnHealth); LastDbConnTime = DateTime.Now; // Read HISNetworks Table and get List of networkID,NetworkName,ServiceWSDL string strCommHISNetworks = @"SELECT NetworkID, NetworkName, ServiceWSDL FROM HISNetworks WHERE IsPublic=1 and IsApproved=1 and ServiceWSDL like '%cuahsi_1_1_%' and ServiceWSDL not like '%sdsc%' and ServiceWSDL not like '%cuahsi.org%'"; Network network = new Network(strCommHISNetworks, sqlConnHis); int networkid; string networkname, url; Console.WriteLine("Found {0} Web Services from HISNetworks.", network.networknameList.Count); // Loop over each ServiceWSDL for (int i = 0; i < network.networknameList.Count; i++) { if (CPEnabled) { if (CP.urlIndex > i) { continue; } } networkid = network.networkidList[i]; networkname = network.networknameList[i]; url = network.urlList[i]; Console.WriteLine(".............................................................."); Console.WriteLine("Processing web service {0} of {1}: {2},{3},{4} Time {5:HH:mm:ss}.", i + 1, network.networknameList.Count, networkid, networkname, url, DateTime.Now); if (CPEnabled) { CP.urlIndex = i; CP.networkId = networkid; } if (url.Contains("cuahsi_1_1")) { HandleSites_1_1(url); } else { //HandleSites_1_0(sqlConnHis, url); } if (CPEnabled) { // Remember to set siteIndex to 0 to allow to process all // sites for next networks/URLs CP.siteIndex = 0; CP.siteCode = null; } } Console.WriteLine("Program finished. Switch to standard output."); Console.Out.Close(); Console.SetOut(savedCons); Console.WriteLine("Program finished. Press any key to exit."); Console.ReadLine(); File.Delete(CPFile); }