示例#1
0
        private static void CreateSitesCsv(CsvDb db, Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict)
        {
            string[] cols = new string[] { "SiteKey", "Name", "Description", "Location", "LocationMark" };

            ITable sites = db.Create("Sites", cols);

            var orderedSites = siteDict.OrderBy(x => x.Value.Item1);

            foreach (var site in orderedSites)
            {
                Site s = site.Value.Item2;
                IRow r = sites.CreateRow();
                r[0] = site.Value.Item1.ToString();
                r[1] = s.Name;
                r[2] = s.Description;
                IGeometry2 <double> geom = s.Location;
                if (geom != null)
                {
                    if (geom is PolygonBag2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as PolygonBag2 <double>).ToString();
                    }
                    else if (geom is Polygon2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as Polygon2 <double>).ToString();
                    }
                    else if (geom is Polyline2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as Polyline2 <double>).ToString();
                    }
                    else if (geom is PolylineBag2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as PolylineBag2 <double>).ToString();
                    }
                    else if (geom is Point2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as Point2 <double>).ToString();
                    }
                }
                else
                {
                    r[3] = "";
                }

                Point2 <double> geom2 = s.LocationMark;
                if (geom2 != null)
                {
                    r[4] = WktUtils.ToWkt(geom2 as Point2 <double>).ToString();
                }
                else
                {
                    r[4] = "";
                }

                sites.AddRow(r);
            }
            sites.Flush();
            return;
        }
示例#2
0
        //public string MP3DBFileName { get; set; }

        #region Events

        private void btnCreatePdbTableFile_Click(object sender, EventArgs e)
        {
            DataTable       dt = (DataTable)dataGridView1.DataSource;
            OperationResult op = new OperationResult();

            CsvDb.CreateCsvTable(dt, @"C:\temp\music.txt", ref op, ",", ",");
            if (!op.Success)
            {
                rtbMessages.Text = op.GetAllErrorsAndExceptions("\n");
                return;
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            string     fil = "B:\\Data\\test.zip";
            FileStream s   = File.Open(fil, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            CsvDb tmp = CsvDb.Create(s);

            CreateTable(tmp, "mytab1");
            CreateTable(tmp, "my tabs\\my tab2.off");
            tmp.Flush();
            tmp.Dispose();
        }
示例#4
0
        private static void CreateSampleEventCsv(CsvDb db, Dictionary <CompoundIdentity, Tuple <int, SamplingEvent> > eventDict,
                                                 Dictionary <CompoundIdentity, Organization> orgDict, Dictionary <CompoundIdentity, FieldTrip> fieldTripDict,
                                                 Dictionary <CompoundIdentity, FieldActivity> fieldActivityDict, Dictionary <CompoundIdentity, Project> projectDict)
        {
            //string[] cols = new string[] { "Org", "FieldTrip", "Activity", "Project", "SampleEvent", "SampleEventKey","SampleEventDesc", "SampleEventStart", "SampleEventEnd" };
            string[] cols = new string[] { "Org", "FieldTrip", "Activity", "Project", "SampleEvent", "SampleEventKey", "SampleEventDesc" };

            ITable samp = db.Create("SamplingEvents", cols);

            const string na            = "Unknown or Not Authorized";
            var          orderedEvents = eventDict.OrderBy(x => x.Value.Item1);

            foreach (var evt in orderedEvents)
            {
                string orgName = na;
                if (orgDict.ContainsKey(evt.Value.Item2.PrincipalOrgId))
                {
                    orgName = orgDict[evt.Value.Item2.PrincipalOrgId].Name;
                }
                string ftripName     = na;
                string factivityName = na;
                string projName      = na;
                if (fieldTripDict.ContainsKey(evt.Value.Item2.FieldTripId))
                {
                    FieldTrip ftrip = fieldTripDict[evt.Value.Item2.FieldTripId];
                    ftripName = ftrip.Name;
                    if (fieldActivityDict.ContainsKey(ftrip.FieldActivityId))
                    {
                        FieldActivity factivity = fieldActivityDict[ftrip.FieldActivityId];
                        factivityName = factivity.Name;
                        if (projectDict.ContainsKey(factivity.ProjectId))
                        {
                            projName = projectDict[factivity.ProjectId].Name;
                        }
                    }
                }

                IRow r = samp.CreateRow();
                r[0] = orgName;
                r[1] = ftripName;
                r[2] = factivityName;
                r[3] = projName;
                r[4] = evt.Value.Item2.Name;
                r[5] = evt.Value.Item1.ToString();
                r[6] = evt.Value.Item2.Description;
                //r[7] = evt.Value.Item2.DateRange.Min.ToString();
                //r[8] = evt.Value.Item2.DateRange.Max.ToString();
                samp.AddRow(r);
            }
            samp.Flush();
            return;
        }
示例#5
0
文件: CsvDbTests.cs 项目: fmpfmp/X-1
        private CsvDb <PageParameter> GetDb(String name)
        {
            var file = $"data/{name}.csv".GetFullPath();

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            var db = new CsvDb <PageParameter>((x, y) => x.PageIndex == y.PageIndex)
            {
                FileName = file
            };

            return(db);
        }
示例#6
0
        private CsvDb <GeoArea> GetDb(String name)
        {
            var file = $"data/{name}.csv".GetFullPath();

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            var db = new CsvDb <GeoArea>((x, y) => x.Code == y.Code)
            {
                FileName = file
            };

            return(db);
        }
示例#7
0
        private static void CreateMeasurementsCsv(CsvDb db, Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict, Dictionary <CompoundIdentity, Tuple <int, SamplingEvent> > eventDict,
                                                  Dictionary <CompoundIdentity, Tuple <int, WaterQualityDeployment> > deploymentDict, List <Tuple <int, WaterQualityMeasurement> > measurementList)
        {
            string[] cols = new string[] { "DataKey", "Deployment", "DeployDesc", "SamplingEventKey", "SiteKey", "DeployStart",
                                           "DeployEnd", "SampleDate", "SurfaceElevation", "Temperature", "pH", "DissolvedOxygen", "Conductivity", "Salinity", "Velocity" };

            ITable measurements = db.Create("WaterQualityMeasurements", cols);

            var orderedMeasurements = measurementList.OrderBy(x => x.Item1);

            foreach (var meas in orderedMeasurements)
            {
                WaterQualityDeployment  deploy      = deploymentDict[meas.Item2.DeploymentId].Item2;
                WaterQualityMeasurement measurement = meas.Item2;
                int eventIndex = eventDict[deploy.SampleEventId].Item1;

                //deploy.SiteId could be a dangling reference
                string siteFK = na;
                if (siteDict.ContainsKey(deploy.SiteId))
                {
                    siteFK = siteDict[deploy.SiteId].Item1.ToString();
                }

                IRow r = measurements.CreateRow();
                r[0]  = meas.Item1.ToString();
                r[1]  = deploy.Name;
                r[2]  = deploy.Description;
                r[3]  = eventIndex.ToString();
                r[4]  = siteFK;
                r[5]  = deploy.Range.StartDate.ToString();
                r[6]  = deploy.Range.EndDate.ToString();
                r[7]  = measurement.SampleDate.ToString();
                r[8]  = measurement.SurfaceElevation.ToString();
                r[9]  = measurement.Temperature.ToString();
                r[10] = measurement.pH.ToString();
                r[11] = measurement.DissolvedOxygen.ToString();
                r[12] = measurement.Conductivity.ToString();
                r[13] = measurement.Salinity.ToString();
                r[14] = measurement.Velocity.ToString();
                measurements.AddRow(r);
            }
            measurements.Flush();
            return;
        }
示例#8
0
        static void CreateTable(CsvDb db, string name)
        {
            string[] cols = new string[] { "ColA", "ColB", "Col\"Tricky", "Col S" };

            ITable tab = db.Create(name, cols);

            string[] vals = new string[] { "klsdkfs", "1231432", "sdfsdj' sdf'' sdf\"sdfs\"'sd sd ", ConvertUtils.F(DateTime.Now) };

            for (int i = 0; i < 1000; i++)
            {
                IRow r = tab.CreateRow();

                r.Write(vals);
                tab.AddRow(r);
            }
            tab.Flush();

            for (int i = 0; i < 1000; i++)
            {
                IRow r = tab.CreateRow();

                r[0] = ConvertUtils.F(new CompoundIdentity(Guid.NewGuid(), Guid.NewGuid()));
                r[1] = ConvertUtils.F((float)i);
                r[2] = "Hoos " + i;
                r[3] = ConvertUtils.F(Math.PI);

                tab.AddRow(r);
            }
            tab.Flush();

            for (int i = 0; i < 1000; i++)
            {
                IRow r = tab.CreateRow();

                r.S(0, new CompoundIdentity(Guid.NewGuid(), Guid.NewGuid()));
                r.S(1, (float)i);
                r.S(2, "Hoos " + i);
                r.S(3, Math.PI);

                tab.AddRow(r);
            }
            tab.Flush();
        }
示例#9
0
        private Guid CreateCsvFile(Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict, Dictionary <CompoundIdentity, Tuple <int, SamplingEvent> > eventDict,
                                   Dictionary <CompoundIdentity, Tuple <int, WaterQualityDeployment> > deploymentDict, List <Tuple <int, WaterQualityMeasurement> > measurementList,
                                   Dictionary <CompoundIdentity, Organization> orgDict, Dictionary <CompoundIdentity, FieldTrip> fieldTripDict,
                                   Dictionary <CompoundIdentity, FieldActivity> fieldActivityDict, Dictionary <CompoundIdentity, Project> projectDict)
        {
            IFileStoreProvider provider = FileStoreManager.Instance.GetProvider();

            //Setting up temp file
            FilestoreFile deployFile = provider.MakeTemp(DateTime.UtcNow.AddHours(4));
            CsvDb         csv        = CsvDb.Create(deployFile);

            CreateSampleEventCsv(csv, eventDict, orgDict, fieldTripDict, fieldActivityDict, projectDict);
            CreateMeasurementsCsv(csv, siteDict, eventDict, deploymentDict, measurementList);
            CreateSitesCsv(csv, siteDict);

            csv.Flush();
            csv.Dispose();
            deployFile.Close();
            return(deployFile.FileId);
        }