Example #1
0
        /// <summary>
        /// reads the dtflines for this version and populates a graph with all blpu, lpis etc
        /// </summary>
        /// <param name="versionId"></param>
        /// <returns></returns>
        private DtfGraph GetGraphFromLinesInDatabase(int versionId)
        {
            var sql    = string.Format(Config.SqlSelectLinesForVersion, versionId);
            var reader = _sqlManager.BulkRead(sql);
            var graph  = new DtfGraph();

            Console.Write("Building records for version " + versionId + " ");

            var index = 0;

            while (reader.Read())
            {
                var textLine = reader.GetString(DtfLine.FULLTEXTFIELDINDEX);
                var line     = DtfLine.Create(textLine, versionId);

                graph.Add(line);

                if (index++ % Config.CONSOLEDOTEVERY == 0)
                {
                    Console.Write(".");
                }
            }
            Console.WriteLine();

            return(graph);
        }
Example #2
0
        /// <summary>
        /// writes data for blpu, lpi etc to database from the graph
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="conn"></param>
        /// <param name="keepLog"></param>
        private void WriteGraphToDb(DtfGraph graph)
        {
            DeleteRecords(Config.SqlDeleteByUprn, Config.TableBlpu, graph.DeleteBlpuUprns);
            DeleteRecords(Config.SqlDeleteByUprn, Config.TableLpi, graph.DeleteLpiUprns);
            DeleteRecords(Config.SqlDeleteByUsrn, Config.TableStreetRecord, graph.DeleteStreetRecordUsrns);
            DeleteRecords(Config.SqlDeleteByUsrn, Config.TableStreetDescriptor, graph.DeleteStreetDescriptorUsrns);

            InsertRecords(graph.Blpus, Config.TableBlpu, graph.Blpus.Count);
            InsertRecords(graph.Lpis, Config.TableLpi, graph.Lpis.Count);
            InsertRecords(graph.StreetRecords, Config.TableStreetRecord, graph.StreetRecords.Count);
            InsertRecords(graph.StreetDescriptors, Config.TableStreetDescriptor, graph.StreetDescriptors.Count);
        }
Example #3
0
        /// <summary>
        /// parses the file and turn it into a list of dtflines
        /// </summary>
        /// <param name="fullFileName"></param>
        /// <param name="versionId"></param>
        /// <returns></returns>
        private List <DtfLine> GetLinesFromFile(string fullFileName, int versionId)
        {
            string[] textLines = null;
            DtfGraph graph     = new DtfGraph();

            try
            {
                textLines = File.ReadAllLines(fullFileName);
                AddMessage(string.Format("File has {0:#,##0} lines", textLines.Count()));
            }
            catch (FileNotFoundException)
            {
                throw new ApplicationException("Can't find file'" + fullFileName + "'");
            }
            catch
            {
                throw;
            }

            var lines = new List <DtfLine>();
            var index = 0;

            Console.Write("Reading file");
            foreach (var textLine in textLines)
            {
                var line = DtfLine.Create(textLine, versionId);
                lines.Add(line);

                if (index++ % Config.CONSOLEDOTEVERY == 0)
                {
                    Console.Write(".");
                }
            }
            Console.WriteLine();
            return(lines);
        }