///<summary>Called after file is downloaded. Throws exceptions. It is assumed that this is called from a worker thread. Progress delegate will be called every 100th iteration to inform thread of current progress. Quit flag can be set at any time in order to quit importing prematurely.</summary> public static void ImportSop(string tempFileName, ProgressArgs progress, ref bool quit) { if (tempFileName == null) { return; } HashSet <string> codeHash = new HashSet <string>(Sops.GetAllCodes()); string[] lines = File.ReadAllLines(tempFileName); string[] arraySop; Sop sop = new Sop(); for (int i = 0; i < lines.Length; i++) //each loop should read exactly one line of code. and each line of code should be a unique code { if (quit) { return; } if (i % 100 == 0) { progress(i + 1, lines.Length); } arraySop = lines[i].Split('\t'); if (codeHash.Contains(arraySop[0])) //code already exists { continue; } sop.SopCode = arraySop[0]; sop.Description = arraySop[1]; Sops.Insert(sop); } }
///<summary>Called after file is downloaded. Throws exceptions. It is assumed that this is called from a worker thread. Progress delegate will be called every 100th iteration to inform thread of current progress. Quit flag can be set at any time in order to quit importing prematurely.</summary> public static void ImportSop(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numcodesUpdated, bool updateExisting) { if (tempFileName == null) { return; } Dictionary <string, Sop> dictSops = Sops.GetDeepCopy().ToDictionary(x => x.SopCode, x => x); string[] lines = File.ReadAllLines(tempFileName); string[] arraySop; Sop sop = new Sop(); for (int i = 0; i < lines.Length; i++) //each loop should read exactly one line of code. and each line of code should be a unique code { if (quit) { return; } if (i % 100 == 0) { progress(i + 1, lines.Length); } arraySop = lines[i].Split('\t'); if (dictSops.ContainsKey(arraySop[0])) //code already exists { sop = dictSops[arraySop[0]]; if (updateExisting && sop.Description != arraySop[1]) { sop.Description = arraySop[1]; Sops.Update(sop); numcodesUpdated++; } continue; } sop.SopCode = arraySop[0]; sop.Description = arraySop[1]; Sops.Insert(sop); numCodesImported++; } }