//Lat.Long.DataPoints.2
        //lat	long	eventdate	street	vomit	blood	urine	humanfouling	dogfouling	graffiti
        public IEnumerable<AnitSocialV1> GetAntiSocialDataV1()
        {
            var sourceFile = @"C:\ldn\Lat.Long.DataPoints.2.csv";

            var reader = new Kent.Boogaart.KBCsv.CsvReader(File.OpenRead(sourceFile));

            reader.ReadHeaderRecord();

            DataRecord row;

            AnitSocialV1 antiSocial;
            while ((row = reader.ReadDataRecord()) != null)
            {
                if (row.Count != 10) continue;

                antiSocial = null;
                try
                {
                    //lat	long	eventdate	street	vomit	blood	urine	humanfouling	dogfouling	graffiti
                    antiSocial = new AnitSocialV1
                    {
                        EventDate = DateTime.Parse(row["eventdate"]),
                        StreetName = row["street"],
                        Location = new Location
                        {
                            Latitude = double.Parse(row["lat"]),
                            Longitude = double.Parse(row["long"]),
                        },
                        Vomit = row["vomit"] == "0" ? false : true,
                        Blood = row["blood"] == "0" ? false : true,
                        Urine = row["urine"] == "0" ? false : true,
                        HumanFouling = row["humanfouling"] == "0" ? false : true,
                        DogFouling = row["dogfouling"] == "0" ? false : true,
                        Graffiti = row["graffiti"] == "0" ? false : true,
                    };
                }
                catch
                {
                    continue;
                }

                if (antiSocial != null)
                    yield return antiSocial;
            }
        }
        private void ParserTableStr(string content)
        {
            StringReader rdr = new StringReader(content);
            using (var reader = new CsvReader(rdr))
            {
                HeaderRecord header = reader.ReadHeaderRecord();
                while (reader.HasMoreRecords)
                {
                    DataRecord data = reader.ReadDataRecord();
                    if (data[0].StartsWith("#"))
                        continue;

                    SkillInfoTableRecord record = new SkillInfoTableRecord(data);
                    Records.Add(record.Id, record);
                }

            }
        }
        public IEnumerable<AnitSocial> GetAntiSocialData()
        {
            var sourceFile = @"C:\ldn\antisocial.csv";

            var reader = new Kent.Boogaart.KBCsv.CsvReader(File.OpenRead(sourceFile));

            reader.ReadHeaderRecord();

            DataRecord row;

            AnitSocial antiSocial;
            while ((row = reader.ReadDataRecord()) != null)
            {
                if (row.Count != 10) continue;

                antiSocial = null;
                try
                {
                    antiSocial = new AnitSocial
                    {
                        EventDate = DateTime.Parse(row["eventdate"]),
                        StreetName = row["street"],
                        Location = new Location
                        {
                            Latitude = double.Parse(row["lat"]),
                            Longitude = double.Parse(row["long"]),
                            X = double.Parse(row["x"]),
                            Y = double.Parse(row["y"])
                        },
                        Vomit = row["vomit"] == "NO" ? false : true,
                        Blood = row["blood"] == "NO" ? false : true,
                        Urine = row["urine"] == "NO" ? false : true,
                        HumanFouling = row["humanfouling"] == "NO" ? false : true,
                    };
                }
                catch
                {
                    continue;
                }

                if(antiSocial != null)
                    yield return antiSocial;
            }
        }
        private void ParserTableContent(string content)
        {
            using (var rdr = new StringReader(content))
            using (var reader = new CsvReader(rdr))
            {
                HeaderRecord header = reader.ReadHeaderRecord();
                const string tableName = "SkillStepTable";
                int lastId = -1;

                while (reader.HasMoreRecords)
                {
                    DataRecord data = reader.ReadDataRecord();
                    var r = new SkillStepTableRecord();
                    if (data[0].StartsWith("#"))
                        continue;


                    Records.Add(data[0], r);
                }
            }
        }
示例#5
0
        public static void ReadContentFile(ConstructFile construct, ref ContentFile contentFile)
        {
            string path = TableGlobalConfig.Instance.ResTablePath + "/" + construct.Name + ".csv";
            if (!string.IsNullOrEmpty(construct.OldName))
            {
                path = TableGlobalConfig.Instance.ResTablePath + "/" + construct.OldName + ".csv";
            }

            if (!File.Exists(path))
            {
                CreateNewFile(construct);
                return;
            }

            string[] lines = File.ReadAllLines(path, Encoding.Default);
            if (lines.Length == 0)
                return;

            contentFile.ContentRow.Clear();
            lines[0] = lines[0].Replace("\r\n", "\n");
            StringReader rdr = new StringReader(string.Join("\n", lines));
            using (var reader = new CsvReader(rdr))
            {
                HeaderRecord header = reader.ReadHeaderRecord();
                //string curGourpName = "";
                //string curClassName = "";

               

                var columnTitles = construct.GetColumnTitles();
                while (reader.HasMoreRecords)
                {
                    DataRecord data = reader.ReadDataRecord();
                    //if (data[0].StartsWith("###"))
                    //{
                    //    curGourpName = data[0].TrimStart('#');
                    //    continue;
                    //}

                    //if (data[0].StartsWith("##"))
                    //{
                    //    curClassName = data[0].TrimStart('#');
                    //    continue;
                    //}

                    ContentRow clumn = ReadRow(construct, data, contentFile);
                    contentFile.AddContentRow(clumn);
                }

                if (IsHeaderMatch(construct, header))
                {
                    contentFile.WriteFlag = false;
                }
                else
                {
                    contentFile.WriteFlag = true;
                }
                contentFile.IsInit = false;
                TableContentManager.Instance.AddContentFile(contentFile);
            }
        }
        public IEnumerable<Graffiti> GetGraffitiData()
        {
            var sourceFile = @"C:\ldn\graffiti.csv";

            var reader = new Kent.Boogaart.KBCsv.CsvReader(File.OpenRead(sourceFile));

            reader.ReadHeaderRecord();

            DataRecord row;

            while ((row = reader.ReadDataRecord()) != null)
            {
                yield return new Graffiti
                {
                    EventDate = DateTime.Parse(row["eventdate"]),
                    StreetName = row["street"],
                    Location = new Location
                    {
                        Latitude = double.Parse(row["long"]),
                        Longitude = double.Parse(row["lat"]),
                        X = double.Parse(row["x"]),
                        Y = double.Parse(row["y"])
                    }
                };
            }
        }
        //antisocial.top.csv
        public IEnumerable<AnitSocialV2> GetAntiSocialDataV2()
        {
            var sourceFile = @"C:\ldn\antisocial.top.csv";

            var reader = new Kent.Boogaart.KBCsv.CsvReader(File.OpenRead(sourceFile));

            reader.ReadHeaderRecord();

            DataRecord row;

            AnitSocialV2 antiSocial;
            while ((row = reader.ReadDataRecord()) != null)
            {
                if (row.Count != 4) continue;

                antiSocial = null;
                try
                {
                    //lat	long	eventdate	street	vomit	blood	urine	humanfouling	dogfouling	graffiti
                    antiSocial = new AnitSocialV2
                    {
                        Location = new Location
                        {
                            Latitude = double.Parse(row["lat"]),
                            Longitude = double.Parse(row["long"]),
                        },
                        Category = row["Antisocial"],
                        Radius = float.Parse(row["Radius"]),
                    };
                }
                catch
                {
                    continue;
                }

                if (antiSocial != null)
                    yield return antiSocial;
            }
        }