///<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 ImportCvx(string tempFileName, ProgressArgs progress, ref bool quit) { if (tempFileName == null) { return; } HashSet <string> codeHash = new HashSet <string>(Cvxs.GetAllCodes()); string[] lines = File.ReadAllLines(tempFileName); string[] arrayCvx; Cvx cvx = new Cvx(); 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); } arrayCvx = lines[i].Split('\t'); if (codeHash.Contains(arrayCvx[0])) //code already exists { continue; } cvx.CvxCode = arrayCvx[0]; cvx.Description = arrayCvx[1]; Cvxs.Insert(cvx); } }
///<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 ImportCvx(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated, bool updateExisting) { if (tempFileName == null) { return; } Dictionary <string, Cvx> dictCodes = Cvxs.GetAll().ToDictionary(x => x.CvxCode, x => x); string[] lines = File.ReadAllLines(tempFileName); string[] arrayCvx; Cvx cvx = new Cvx(); 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); } arrayCvx = lines[i].Split('\t'); if (dictCodes.ContainsKey(arrayCvx[0])) //code already exists { cvx = dictCodes[arrayCvx[0]]; if (updateExisting && cvx.Description != arrayCvx[1]) //We do want to update and description is different. { cvx.Description = arrayCvx[1]; Cvxs.Update(cvx); numCodesUpdated++; } continue; } cvx.CvxCode = arrayCvx[0]; cvx.Description = arrayCvx[1]; Cvxs.Insert(cvx); numCodesImported++; } }