Example #1
0
        ///<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 ImportUcum(string tempFileName, ProgressArgs progress, ref bool quit)
        {
            if (tempFileName == null)
            {
                return;
            }
            HashSet <string> codeHash = new HashSet <string>(Ucums.GetAllCodes());

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayUcum;
            Ucum     ucum = new Ucum();

            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);
                }
                arrayUcum = lines[i].Split('\t');
                if (codeHash.Contains(arrayUcum[0]))                 //code already exists
                {
                    continue;
                }
                ucum.UcumCode    = arrayUcum[0];
                ucum.Description = arrayUcum[1];
                ucum.IsInUse     = false;
                Ucums.Insert(ucum);
            }
        }
Example #2
0
        ///<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 ImportUcum(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated,
                                      bool updateExisting)
        {
            if (tempFileName == null)
            {
                return;
            }
            Dictionary <string, Ucum> dictUcums = Ucums.GetAll().ToDictionary(x => x.UcumCode, x => x);

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayUcum;
            Ucum     ucum = new Ucum();

            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);
                }
                arrayUcum = lines[i].Split('\t');
                if (dictUcums.ContainsKey(arrayUcum[0]))                 //code already exists
                {
                    ucum = dictUcums[arrayUcum[0]];
                    if (updateExisting && ucum.Description != arrayUcum[1])
                    {
                        ucum.Description = arrayUcum[1];
                        Ucums.Update(ucum);
                        numCodesUpdated++;
                    }
                    continue;
                }
                ucum.UcumCode    = arrayUcum[0];
                ucum.Description = arrayUcum[1];
                ucum.IsInUse     = false;
                Ucums.Insert(ucum);
                numCodesImported++;
            }
        }