Exemplo n.º 1
0
        internal ModelImportStatus BatchImportLasFiles(string[] filePaths, Guid currentProjectID)
        {

            ModelImportStatus finalStatus = new ModelImportStatus();

            LASBatchImportTools ll = new LASBatchImportTools();
            List<string> messages = new List<string>();
            int importCount = 0;
            int failCount = 0;
            string report = "";
            Dictionary<string, ModelImportStatus> mosList = new Dictionary<string, ModelImportStatus>();
            bool reportStatus = false;
            if (this.backgroundWorker != null)
            {
                reportStatus = true;
            }
            

            int fileCount = filePaths.Length;
            int thisFileNum = 0;

            var dataDict = new Dictionary<string, List<object>>();

            foreach (string file in filePaths)
            {
                var data = new List<object>();
                double pct = ((double)thisFileNum / (double)fileCount) * 100.0;
                thisFileNum++; 
               
                
                if (reportStatus)
                {
                    backgroundWorker.ReportProgress((int)pct, "Processing las file "+thisFileNum+" of "+fileCount+", "+file);
                }

                ModelImportStatus mis = new ModelImportStatus();

                NKD.Import.Client.Processing.LASImport li = new NKD.Import.Client.Processing.LASImport();
                LASFile lf = li.GetLASFile(file, mis);
                if (lf == null)
                {
                    
                    mis.errorMessages.Add("Failed to load LAS file " + file);
                    mosList.Add(file, mis);
                    continue;
                }

                data = ll.ProcessLASFile(lf, file, mis, currentProjectID, this.backgroundWorker);
                string msg = "";
                if (msg != null)
                {
                    messages.Add(msg);
                    report += msg + "\n";
                    failCount++;
                }
                else
                {
                    importCount++;
                }

                mosList.Add(file, mis);
                dataDict.Add(file, data);

                //if (thisFileNum % 2 == 0 || (filePaths.Length-thisFileNum) < 1) //FIXME magic number, should look at used memory and make a choice on that
                //{
                    //insert into DB to avoid memory issues
                    //var subdict = dataDict;
                PushToDB(dataDict);    
                dataDict = new Dictionary<string, List<object>>();

                    //PushToDB(subdict);
                    //subdict = null;
                
                GC.Collect();
                GC.WaitForPendingFinalizers();
                //}
            }

            string finalReport = "Immport status:\nFiles imported:" + importCount + "\nFailed files:" + failCount + "\n\nMessages:\n";

            finalReport += report;
            int totRecordsAddedCount = 0;
            int totLinesReadCount = 0;
            foreach (KeyValuePair<string, ModelImportStatus> kvp in mosList) {
                string lfName = kvp.Key;
                ModelImportStatus ms = kvp.Value;
                totRecordsAddedCount += ms.recordsAdded;
                totLinesReadCount += ms.linesReadFromSource;
                if (ms.finalErrorCode != ModelImportStatus.OK) {
                    finalStatus.finalErrorCode = ModelImportStatus.GENERAL_LOAD_ERROR;
                }
                foreach (string m in ms.warningMessages) {
                    finalStatus.warningMessages.Add(m);
                }
                foreach (string m in ms.errorMessages)
                {
                    finalStatus.errorMessages.Add(m);
                }
            }
            finalStatus.linesReadFromSource = totLinesReadCount;
            finalStatus.recordsAdded = totRecordsAddedCount;

            return finalStatus;

        }
Exemplo n.º 2
0
        internal ModelImportStatus BatchImportLasFiles(string[] filePaths, Guid currentProjectID)
        {
            ModelImportStatus finalStatus = new ModelImportStatus();

            LASBatchImportTools ll       = new LASBatchImportTools();
            List <string>       messages = new List <string>();
            int    importCount           = 0;
            int    failCount             = 0;
            string report = "";
            Dictionary <string, ModelImportStatus> mosList = new Dictionary <string, ModelImportStatus>();
            bool reportStatus = false;

            if (this.backgroundWorker != null)
            {
                reportStatus = true;
            }


            int fileCount   = filePaths.Length;
            int thisFileNum = 0;

            var dataDict = new Dictionary <string, List <object> >();

            foreach (string file in filePaths)
            {
                var    data = new List <object>();
                double pct  = ((double)thisFileNum / (double)fileCount) * 100.0;
                thisFileNum++;


                if (reportStatus)
                {
                    backgroundWorker.ReportProgress((int)pct, "Processing las file " + thisFileNum + " of " + fileCount + ", " + file);
                }

                ModelImportStatus mis = new ModelImportStatus();

                NKD.Import.Client.Processing.LASImport li = new NKD.Import.Client.Processing.LASImport();
                LASFile lf = li.GetLASFile(file, mis);
                if (lf == null)
                {
                    mis.errorMessages.Add("Failed to load LAS file " + file);
                    mosList.Add(file, mis);
                    continue;
                }

                data = ll.ProcessLASFile(lf, file, mis, currentProjectID, this.backgroundWorker);
                string msg = "";
                if (msg != null)
                {
                    messages.Add(msg);
                    report += msg + "\n";
                    failCount++;
                }
                else
                {
                    importCount++;
                }

                mosList.Add(file, mis);
                dataDict.Add(file, data);

                //if (thisFileNum % 2 == 0 || (filePaths.Length-thisFileNum) < 1) //FIXME magic number, should look at used memory and make a choice on that
                //{
                //insert into DB to avoid memory issues
                //var subdict = dataDict;
                PushToDB(dataDict);
                dataDict = new Dictionary <string, List <object> >();

                //PushToDB(subdict);
                //subdict = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();
                //}
            }

            string finalReport = "Immport status:\nFiles imported:" + importCount + "\nFailed files:" + failCount + "\n\nMessages:\n";

            finalReport += report;
            int totRecordsAddedCount = 0;
            int totLinesReadCount    = 0;

            foreach (KeyValuePair <string, ModelImportStatus> kvp in mosList)
            {
                string            lfName = kvp.Key;
                ModelImportStatus ms     = kvp.Value;
                totRecordsAddedCount += ms.recordsAdded;
                totLinesReadCount    += ms.linesReadFromSource;
                if (ms.finalErrorCode != ModelImportStatus.OK)
                {
                    finalStatus.finalErrorCode = ModelImportStatus.GENERAL_LOAD_ERROR;
                }
                foreach (string m in ms.warningMessages)
                {
                    finalStatus.warningMessages.Add(m);
                }
                foreach (string m in ms.errorMessages)
                {
                    finalStatus.errorMessages.Add(m);
                }
            }
            finalStatus.linesReadFromSource = totLinesReadCount;
            finalStatus.recordsAdded        = totRecordsAddedCount;

            return(finalStatus);
        }