Esempio n. 1
0
        /////<summary>Called after file is downloaded.  Throws exceptions.</summary>
        //public static void ImportAdministrativeSex(string tempFileName) ... not necessary.

        ///<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 ImportCdcrec(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated,
                                        bool updateExisting)
        {
            if (tempFileName == null)
            {
                return;
            }
            Dictionary <string, Cdcrec> dictCdcrecs = Cdcrecs.GetAll().ToDictionary(x => x.CdcrecCode, x => x);

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayCDCREC;
            Cdcrec   cdcrec = new Cdcrec();

            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);
                }
                arrayCDCREC = lines[i].Split('\t');
                if (dictCdcrecs.ContainsKey(arrayCDCREC[0]))                 //code already exists
                {
                    cdcrec = dictCdcrecs[arrayCDCREC[0]];
                    if (updateExisting &&
                        (cdcrec.HeirarchicalCode != arrayCDCREC[1] ||
                         cdcrec.Description != arrayCDCREC[2]))
                    {
                        cdcrec.HeirarchicalCode = arrayCDCREC[1];
                        cdcrec.Description      = arrayCDCREC[2];
                        Cdcrecs.Update(cdcrec);
                        numCodesUpdated++;
                    }
                    continue;
                }
                cdcrec.CdcrecCode       = arrayCDCREC[0];
                cdcrec.HeirarchicalCode = arrayCDCREC[1];
                cdcrec.Description      = arrayCDCREC[2];
                Cdcrecs.Insert(cdcrec);
                numCodesImported++;
            }
        }