private void TimerTask(object StateObj) { try { StateObjClass State = (StateObjClass)StateObj; // Use the interlocked class to increment the counter variable. System.Threading.Interlocked.Increment(ref State.SomeValue); log.LogInformation("Launched new thread " + DateTime.Now.ToString()); //System.Diagnostics.Debug.WriteLine("Launched new thread " + DateTime.Now.ToString()); if (State.TimerCanceled) // Dispose Requested. { State.TimerReference.Dispose(); log.LogInformation("Done " + DateTime.Now.ToString()); //System.Diagnostics.Debug.WriteLine("Done " + DateTime.Now.ToString()); } else { log.LogInformation("Looking to Parse files"); if (State.TimerBusy == 0) { System.Threading.Interlocked.Add(ref State.TimerBusy, 1); log.LogInformation(String.Format("Before Parsing Files {0}", State.TimerBusy)); if (!IsProcessRunning()) { log.LogInformation(String.Format("Locking {0}", State.TimerBusy)); //if (LockProcess()) ParseFiles(); // Only SoftwareSandy is running now log.LogInformation(String.Format("Releasing the lock {0}", State.TimerBusy)); //ReleaseLock(); } System.Threading.Interlocked.Add(ref State.TimerBusy, -1); log.LogInformation(String.Format("After Parsing Files {0}", State.TimerBusy)); } } claimLinesList.Clear(); } catch (Exception ex) { log.LogError(String.Format("In Timer Task {0}", ex.Message)); } }
static public void ParseFiles() { QuickCap qc = new QuickCap(); qc.log = log; log = new LogLogger("Application", "SoftwareSandy Claims Scrubber"); log.LogInformation("Starting"); claimLinesList = new Dictionary <string, ClaimLinesIndex>(); qc.ClaimScrubRead(); //log.LogInformation("Parsing Files"); ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["SQLConnection"]; SqlConnection con = new SqlConnection(settings.ConnectionString); using (con) { try { con.Open(); GetCPTExclusions(con); } catch (SqlException sex) { log.LogError(String.Format("Cannot connect {0}", sex.Message)); } string _directories = ConfigurationManager.AppSettings["NetworksLocation"]; string[] networks = getNetworks(_directories); for (int i = 0; i < networks.Length; i++) { gCompany = networks[i].Substring(_directories.Length + 1); FixPercentages(); log.LogInformation("Deliting previous working files"); string[] files = Directory.GetFiles(networks[i] + @"\WORKING"); if (files.Length > 0) { for (int k = 0; k < files.Length; k++) { File.Delete(files[k]); } } files = Directory.GetFiles(networks[i] + @"\IN"); // Looking for files in the "IN" directory if (files.Length > 0) { log.LogInformation("Spliting files"); for (int j = 0; j < files.Length; j++) { try { SplitFiles(files[j], networks[i], con); } catch (Exception ex) { log.LogError(String.Format("Error Spliting Files {0}", ex.Message)); } } for (int j = 0; j < files.Length; j++) { try { if (File.Exists(files[j].Replace(@"\IN", @"\PROCESS"))) { log.LogInformation(String.Format("Deleting file {0}", files[j].Replace(@"\IN", @"\PROCESS"))); File.Delete(files[j].Replace(@"\IN", @"\PROCESS")); } File.Move(files[j], files[j].Replace(@"\IN", @"\PROCESS")); } catch (Exception ef) { log.LogError(String.Format("Moving files {0} {1}", files[j], ef.Message)); } } files = Directory.GetFiles(networks[i] + @"\WORKING"); for (int j = 0; j < files.Length; j++) { log.LogInformation("Sending File: " + files[j]); // had bug using the wrong index try { SendFiles(files[j], networks[i]); } catch (Exception ex) { log.LogError(String.Format("Outside SendFiles {0}", ex.Message)); } } if (claimLinesList.Count() > 0) { claimLinesList.Clear(); } } } } qc.ClaimScrubWrite(); }