public FilestoreFile CreateVeg(CompoundIdentity sampleEventId, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, bool isPrivate) { if (!sampleEventId.IsNullOrEmpty() && sites != null && plotTypes != null && shrubSpecies != null && treeSpecies != null && herbSpecies != null && sites.DataType == BundleDataType.Site && plotTypes.DataType == BundleDataType.PlotType && shrubSpecies.DataType == BundleDataType.TaxaUnit && treeSpecies.DataType == BundleDataType.TaxaUnit && herbSpecies.DataType == BundleDataType.TaxaUnit) { if (nonLiving != null) { if (nonLiving.DataType != BundleDataType.TaxaUnit) { return(null); //if we have nonLiving, they better be taxaunits } } SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map == null) { map = DetRegistry.Instance.Create(sampleEventId); } else if (map.Contains(KnownDetType.Veg)) { return(null); //can't have more than 1 } VegDetProcessor wq = new VegDetProcessor(this.ctx); FilestoreFile fil = wq.Create(map, sites, plotTypes, shrubSpecies, treeSpecies, herbSpecies, nonLiving, isPrivate); //note the permission is checked in there if (fil != null) { map.Add(fil.FileId, KnownDetType.Veg, isPrivate); List <Guid> bundles = map.Get(KnownDetType.Veg).BundleIds; bundles.Add(sites.Id); bundles.Add(plotTypes.Id); bundles.Add(shrubSpecies.Id); bundles.Add(treeSpecies.Id); bundles.Add(herbSpecies.Id); if (nonLiving != null) { bundles.Add(nonLiving.Id); } DetRegistry.Instance.Update(map); SamplingEvent e = this.GetSampleEvent(map.SampleEventId); if (e != null) { string tmp = e.Name.Trim().Replace(' ', '_'); if (tmp.Length > 25) { tmp = tmp.Substring(0, 24); } fil.FileName = tmp + "_Veg.xlsx"; FileStoreManager.Instance.GetProvider().Update(fil); } } return(fil); } return(null); }
public FilestoreFile CreateFish(CompoundIdentity sampleEventId, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, bool isPrivate) { if (!sampleEventId.IsNullOrEmpty() && sites != null && nets != null && fishSpecies != null && sites.DataType == BundleDataType.Site && nets.DataType == BundleDataType.Instrument && fishSpecies.DataType == BundleDataType.TaxaUnit) { if (macroSpecies != null) { if (macroSpecies.DataType != BundleDataType.TaxaUnit) { return(null); //if we have macroSpecies, they better be taxaunits } } SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map == null) { map = DetRegistry.Instance.Create(sampleEventId); } else if (map.Contains(KnownDetType.Fish)) { return(null); //can't have more than 1 } FishDetProcessor wq = new FishDetProcessor(this.ctx); FilestoreFile fil = wq.Create(map, sites, nets, fishSpecies, macroSpecies, isPrivate); //note the permission is checked in there if (fil != null) { map.Add(fil.FileId, KnownDetType.Fish, isPrivate); List <Guid> bundles = map.Get(KnownDetType.Fish).BundleIds; bundles.Add(sites.Id); bundles.Add(nets.Id); bundles.Add(fishSpecies.Id); if (macroSpecies != null) { bundles.Add(macroSpecies.Id); } DetRegistry.Instance.Update(map); SamplingEvent e = this.GetSampleEvent(map.SampleEventId); if (e != null) { string tmp = e.Name.Trim().Replace(' ', '_'); if (tmp.Length > 25) { tmp = tmp.Substring(0, 24); } fil.FileName = tmp + "_Fish.xlsx"; FileStoreManager.Instance.GetProvider().Update(fil); } } return(fil); } return(null); }
internal SampleEventMap Get(CompoundIdentity sampleEventId) { if (this.connString != null && sampleEventId != null && !sampleEventId.IsEmpty) { NpgsqlCommand cmd = GetCmd(connString); cmd.CommandText = Select + " WHERE \"SampleEventSystemId\"=:sid AND \"SampleEventId\"=:id"; cmd.Parameters.AddWithValue("sid", sampleEventId.DataStoreIdentity); cmd.Parameters.AddWithValue("id", sampleEventId.Identity); NpgsqlDataReader rdr = ExecuteReader(cmd); try { if (rdr.Read()) { int[] fileTypes = (int[])rdr[2]; Guid[] fileIds = (Guid[])rdr[3]; bool[] privacies = (bool[])rdr[5]; SampleEventMap tmp = SampleEventMap.Create(sampleEventId); for (int i = 0; i < fileTypes.Length; i++) { tmp.Add(fileIds[i], (KnownDetType)fileTypes[i], privacies[i]); } if (!DBNull.Value.Equals(rdr[4])) { DecodeBundleIds((string)rdr[4], tmp); } return(tmp); } } catch { } finally { cmd.Dispose(); } } return(null); }
internal SampleEventMap Get(Guid fileId) { if (this.connString != null && !Guid.Empty.Equals(fileId)) { NpgsqlCommand cmd = GetCmd(connString); cmd.CommandText = Select + " WHERE :id = ANY(\"FileIds\")"; cmd.Parameters.AddWithValue("id", fileId); NpgsqlDataReader rdr = ExecuteReader(cmd); try { if (rdr.Read()) { CompoundIdentity id = new CompoundIdentity((Guid)rdr[0], (Guid)rdr[1]); int[] fileTypes = (int[])rdr[2]; Guid[] fileIds = (Guid[])rdr[3]; bool[] privacies = (bool[])rdr[5]; SampleEventMap tmp = SampleEventMap.Create(id); for (int i = 0; i < fileTypes.Length; i++) { tmp.Add(fileIds[i], (KnownDetType)fileTypes[i], privacies[i]); } if (!DBNull.Value.Equals(rdr[4])) { DecodeBundleIds((string)rdr[4], tmp); } return(tmp); } } catch { } finally { cmd.Dispose(); } } return(null); }
public FilestoreFile CreateWQ(CompoundIdentity sampleEventId, EntityBundle sites, EntityBundle instruments, bool isPrivate) { if (!sampleEventId.IsNullOrEmpty() && sites != null && instruments != null && sites.DataType == BundleDataType.Site && instruments.DataType == BundleDataType.Instrument) { SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map == null) { map = DetRegistry.Instance.Create(sampleEventId); } else if (map.Contains(KnownDetType.WaterQuality)) { return(null); //can't have more than 1 } WqDetProcessor wq = new WqDetProcessor(this.ctx); FilestoreFile fil = wq.Create(map, sites, instruments); //note the permission is checked in there if (fil != null) { map.Add(fil.FileId, KnownDetType.WaterQuality, isPrivate); List <Guid> bundles = map.Get(KnownDetType.WaterQuality).BundleIds; bundles.Add(sites.Id); bundles.Add(instruments.Id); DetRegistry.Instance.Update(map); SamplingEvent e = this.GetSampleEvent(map.SampleEventId); if (e != null) { string tmp = e.Name.Trim().Replace(' ', '_'); if (tmp.Length > 25) { tmp = tmp.Substring(0, 24); } fil.FileName = tmp + "_WQ.xlsx"; FileStoreManager.Instance.GetProvider().Update(fil); } } return(fil); } return(null); }