public override Instrument Create(CompoundIdentity ownerId, string name, CompoundIdentity typeId, string description, string serialNumber, CompoundIdentity manufId) { if (!string.IsNullOrEmpty(name) && ownerId != null && typeId != null && this.CanCreate()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.InsertInstrument; Guid id = Guid.NewGuid(); cmd.Parameters.AddWithValue("id", id); cmd.Parameters.AddWithValue("osid", ownerId.DataStoreIdentity); cmd.Parameters.AddWithValue("owner", ownerId.Identity); cmd.Parameters.AddWithValue("name", name); cmd.Parameters.AddWithValue("tid", typeId.Identity); if (string.IsNullOrEmpty(description)) { cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("desc", NpgsqlTypes.NpgsqlDbType.Varchar)); } else { cmd.Parameters.AddWithValue("desc", description); } if (string.IsNullOrEmpty(serialNumber)) { cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("sn", NpgsqlTypes.NpgsqlDbType.Varchar)); } else { cmd.Parameters.AddWithValue("sn", serialNumber); } if (manufId.IsNullOrEmpty()) { cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("msid", NpgsqlTypes.NpgsqlDbType.Uuid)); cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("mid", NpgsqlTypes.NpgsqlDbType.Uuid)); } else { cmd.Parameters.AddWithValue("msid", manufId.DataStoreIdentity); cmd.Parameters.AddWithValue("mid", manufId.Identity); } Db.ExecuteNonQuery(cmd); return(new Instrument(new CompoundIdentity(Db.DataStoreIdentity, id), ownerId, name, typeId, description, serialNumber, manufId)); } catch { } } return(null); }
internal static Archetypes.WingedBagNet ToWingedBagNet(JObject ob) { if (ob != null) { if (ob["InstrumentId"] != null && ob["Length"] != null && ob["Depth"] != null && ob["MeshSizeWings"] != null && ob["MeshSizeBag"] != null) { CompoundIdentity c = ToId(ob["InstrumentId"]); double l = double.Parse(ob["Length"].ToString()); double d = double.Parse(ob["Depth"].ToString()); double w = double.Parse(ob["MeshSizeWings"].ToString()); double b = double.Parse(ob["MeshSizeBag"].ToString()); return(new Archetypes.WingedBagNet(c, l, d, w, b)); } } return(null); }
public override bool RemoveParent(IEnumerable <CompoundIdentity> children, CompoundIdentity parent) { if (parent != null && children != null && this.CanUpdate()) { bool res = true; foreach (CompoundIdentity cur in children) { if (!RemoveParent(cur, parent)) { res = false; } } return(res); } return(false); }
internal static bool MatchesType(CompoundIdentity entityId, BundleDataType type) { if (type == BundleDataType.Site) { return(entityId.DataStoreIdentity.Equals(siteDomainId)); } else if (type == BundleDataType.TaxaUnit) { return(entityId.DataStoreIdentity.Equals(taxaDomainId)); } else if (type == BundleDataType.Instrument) { return(entityId.DataStoreIdentity.Equals(instrumentDomainId)); } return(entityId.DataStoreIdentity.Equals(plotTypeDomainId)); }
public override bool Remove(CompoundIdentity parentId, IEnumerable <CompoundIdentity> childId) { if (!parentId.IsNullOrEmpty() && childId != null && this.CanRemove()) //short circuit quit { bool res = true; foreach (CompoundIdentity cur in childId) { if (!cur.IsNullOrEmpty()) { res = res & Remove(parentId, cur); } } return(res); } return(false); }
private Tuple <CompoundIdentity, Point2 <double> > GetLocation(VegDataDTO item, EntityBundle sites) { CompoundIdentity id = null; if (!string.IsNullOrEmpty(item.SiteId) && sites.Contains(item.SiteId)) { id = sites.Get(item.SiteId).EntityId; } Point2 <double> loc = null; if (item.AdHocLat.HasValue && item.AdHocLon.HasValue && !MathUtils.IsInfiniteOrNaN(item.AdHocLat.Value) && !MathUtils.IsInfiniteOrNaN(item.AdHocLon.Value)) { loc = GeometryFactory2Double.Instance.ConstructPoint(item.AdHocLon.Value, item.AdHocLat.Value); } return(new Tuple <CompoundIdentity, Point2 <double> >(id, loc)); }
public override bool Move(CompoundIdentity oldParentId, CompoundIdentity newParentId, IEnumerable <CompoundIdentity> childId) { if (oldParentId != null && newParentId != null && childId != null && CanMove()) { bool res = true; foreach (CompoundIdentity o in childId) { if (!o.IsNullOrEmpty()) { res = res & Move(oldParentId, newParentId, o); } } return(res); } return(false); }
public WaterQualityMeasurement(CompoundIdentity deploymentId, DateTime sampleDate, double?surfaceElevation, double?temperature, double?ph, double?dissolvedOxygen, double?conductivity, double?salinity, double?velocity) { MethodContract.NotNullOrEmpty(deploymentId, nameof(deploymentId)); MethodContract.Assert(sampleDate <DateTime.UtcNow && sampleDate> WQUtils.GlobalMinDate, nameof(sampleDate)); MethodContract.Assert(surfaceElevation.HasValue || temperature.HasValue || ph.HasValue || dissolvedOxygen.HasValue || conductivity.HasValue || salinity.HasValue || velocity.HasValue, "values"); this.deploymentId = deploymentId; this.sampleDate = sampleDate; this.surfaceElevation = surfaceElevation; this.temperature = temperature; this.ph = ph; this.dissolvedOxygen = dissolvedOxygen; this.conductivity = conductivity; this.salinity = salinity; this.velocity = velocity; }
public CompoundIdentity CreateSampleEvent(CompoundIdentity fieldTripId, CompoundIdentity princOrgId, string name, string desc, ValueRange <DateTime> range) { if (fieldTripId != null && !fieldTripId.IsEmpty && princOrgId != null && !princOrgId.IsEmpty && !string.IsNullOrEmpty(name)) { ISampleEventProvider prov = FieldActivityManager.Instance.GetSampleEventProvider(this.ctx); if (prov != null) { SamplingEvent evt = prov.Create(name, fieldTripId, princOrgId, range, desc); if (evt != null) { return(evt.Identity); } } } return(null); }
public override bool Delete(CompoundIdentity instrumentId) { if (instrumentId != null && this.CanDelete()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteInstrumentArchetypeInstance; cmd.Parameters.AddWithValue("iid", instrumentId.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
private UpdateStatus DeltaLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle instruments, WaterQualityDET curdet, WaterQualityDET olddet, IWQDeploymentProvider depl, IWQMeasurementProvider meas, SampleEventMap map) { UpdateStatus stat = new UpdateStatus(UpdateIssue.SystemIssue); //Not implemented if (curdet.Deployments.Count < 1) //ok, old file had data, this file has none { //what do we want to do? -- could just do a delete all stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.WaterQuality); //fetch it back if (this.Delete(map, false)) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } else { //data in both files, this is a change/append situation stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.WaterQuality); //fetch it back if (this.DeleteData(map)) { if (this.InitialLoad(seId, sites, instruments, curdet, depl, meas, tmp.IsPrivate) != null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Create", UpdateIssue.Security, stat); } } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } return(stat); }
private UpdateStatus DeltaLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, VegDET curdet, VegDET olddet, IVegSurveyProvider depl, IVegSampleProvider meas, SampleEventMap map) { UpdateStatus stat = null; if (curdet.Surveys.Count < 1) //ok, old file had data, this file has none { //what do we want to do? -- could just do a delete all stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Veg); //fetch it back if (this.Delete(map, false)) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } else { //data in both files, this is a change/append situation stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Veg); //fetch it back if (this.DeleteData(map)) { if (this.InitialLoad(seId, sites, plotTypes, shrubSpecies, treeSpecies, herbSpecies, nonLiving, curdet, depl, meas, tmp.IsPrivate) != null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Create", UpdateIssue.Security, stat); } } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } return(stat); }
public override bool Delete(CompoundIdentity id) { if (!id.IsNullOrEmpty() && this.CanDelete()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteInstrumentFamily; cmd.Parameters.AddWithValue("id", id.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public Project Build(DbDataReader reader) { CompoundIdentity parentId = null; Guid parentSysId = DbReaderUtils.GetGuid(reader, 5); if (!Guid.Empty.Equals(parentSysId)) { parentId = new CompoundIdentity(parentSysId, DbReaderUtils.GetGuid(reader, 6)); } Project p = new Project(new CompoundIdentity(DbReaderUtils.GetGuid(reader, 0), DbReaderUtils.GetGuid(reader, 1)), DbReaderUtils.GetString(reader, 2), new CompoundIdentity(DbReaderUtils.GetGuid(reader, 3), DbReaderUtils.GetGuid(reader, 4)), parentId, DbReaderUtils.GetString(reader, 7)); Db.LoadAffiliates(p); return(p); }
public override bool RemoveInstrumentType(CompoundIdentity instrumentTypeId) { if (instrumentTypeId != null && this.CanDelete()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = "DELETE FROM oncor.\"InstrumentTypeKnownArchetypes\" WHERE \"InstrumentTypeId\"=:itid"; cmd.Parameters.AddWithValue("itid", instrumentTypeId.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public ProjectInformation(CompoundIdentity projectId, Guid entryId, string infoText, DateTime?startDate, DateTime?endDate) { MethodContract.NotNullOrEmpty(projectId, nameof(projectId)); MethodContract.NotNullOrEmpty(infoText, nameof(infoText)); MethodContract.Assert(!Guid.Empty.Equals(entryId), nameof(entryId)); if (startDate.HasValue && endDate.HasValue) { MethodContract.Assert(startDate <= endDate, "startDate must be <= endDate"); } this.ProjectIdentity = projectId; this.Identity = entryId; this.infoText = infoText; this.startDate = startDate; this.endDate = endDate; }
private bool DeleteMembers(CompoundIdentity id) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteFieldTeamMembers; cmd.Parameters.AddWithValue("sid", id.DataStoreIdentity); cmd.Parameters.AddWithValue("id", id.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } return(false); }
private UpdateStatus DeltaLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, FishDET curdet, FishDET olddet, ICatchEffortProvider depl, ICatchHaulProvider haul, IFishProvider fish, SampleEventMap map) { UpdateStatus stat = null; if (curdet.CatchEfforts.Count < 1) //ok, old file had data, this file has none { //what do we want to do? -- could just do a delete all stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Fish); //fetch it back if (this.Delete(map, false)) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } else { //data in both files, this is a change/append situation stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("NoData", "Delete then create")); SampleEventMapItem tmp = map.Get(KnownDetType.Fish); //fetch it back if (this.DeleteData(map)) { if (this.InitialLoad(seId, sites, nets, fishSpecies, macroSpecies, curdet, depl, haul, fish, tmp.IsPrivate) != null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } else { this.Add("Failure", "Create", UpdateIssue.Security, stat); } } else { this.Add("Failure", "Delete", UpdateIssue.Security, stat); } } return(stat); }
public Fish(Guid id, CompoundIdentity catchEffortId, CompoundIdentity taxaId, float lengthStandard, float lengthFork, float lengthTotal, float weight, bool?adClipped, bool?cwt, string description) { MethodContract.Assert(!Guid.Empty.Equals(id), nameof(id)); MethodContract.NotNullOrEmpty(catchEffortId, nameof(catchEffortId)); MethodContract.NotNullOrEmpty(taxaId, nameof(taxaId)); this.Identity = id; this.catchEffortId = catchEffortId; this.taxaId = taxaId; this.LengthStandard = lengthStandard; this.LengthFork = lengthFork; this.LengthTotal = lengthTotal; this.Weight = weight; this.AdClipped = adClipped; this.CWT = cwt; this.Description = description; }
public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel) { if (context.Request.Method == "POST") { if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { TaxaCommonNameProviderBase cnprovider = TaxonomyManager.Instance.GetTaxaCommonNameProvider(user); TaxaUnitProviderBase uprovider = TaxonomyManager.Instance.GetTaxaUnitProvider(user); JToken token = JsonUtils.GetDataPayload(context.Request); JArray jcommonNames = null; if (cnprovider != null && uprovider != null && token != null) { CompoundIdentity unitId = JsonUtils.ToId(token["unitid"]); TaxaUnit unit = uprovider.Get(unitId); if (unit != null) { IEnumerable <TaxaCommonName> names = cnprovider.GetCommonNamesByTaxa(unit); jcommonNames = Jsonifier.ToJson(names); } if (jcommonNames != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, jcommonNames.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); return; } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }
//Methods for InstrumentTypeKnownArchetypes public override bool AddInstrumentTypeArchetype(CompoundIdentity archetypeId, CompoundIdentity instrumentTypeId) { if (archetypeId != null && instrumentTypeId != null && this.CanCreate()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.InsertInstrumentTypeKnownArchetype; cmd.Parameters.AddWithValue("itid", instrumentTypeId.Identity); cmd.Parameters.AddWithValue("aid", archetypeId.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public override bool Remove(CompoundIdentity taxaUnitId, CompoundIdentity commonNameId) { if (!taxaUnitId.IsNullOrEmpty() && commonNameId.IsNullOrEmpty() && this.CanDelete()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteTaxaCommonNameTaxa; cmd.Parameters.AddWithValue("tcnid", commonNameId.Identity); cmd.Parameters.AddWithValue("tuid", taxaUnitId.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public override bool Move(CompoundIdentity oldParentId, CompoundIdentity newParentId, CompoundIdentity childId) { if (!oldParentId.IsNullOrEmpty() && !newParentId.IsNullOrEmpty() && !childId.IsNullOrEmpty() && CanMove(childId)) { IEnumerable <CompoundIdentity> ids = GetChildrenIds(oldParentId, false); if (ids != null) { foreach (CompoundIdentity cur in ids) { if (cur.Equals(childId)) //we have a match { return(Up(newParentId, childId)); } } } } return(false); }
public override bool Delete(CompoundIdentity id) { if (!id.IsNullOrEmpty() && this.CanDelete()) { try { InstrumentKnownArchetypeProviderBase archprov = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(this.Context); NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteInstrument; cmd.Parameters.AddWithValue("id", id.Identity); Db.ExecuteNonQuery(cmd); archprov.Delete(id); return(true); } catch { } } return(false); }
public IEnumerable <CatchMetric> GetMetrics(CompoundIdentity catchEffortId, string metricType) { if (!catchEffortId.IsNullOrEmpty() && Db.DataStoreIdentity.Equals(catchEffortId.DataStoreIdentity) && this.CanGet()) { if (string.IsNullOrEmpty(metricType)) { return(new List <CatchMetric>()); //can't have any with null or empty metric type, so always an empty set } NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishCatchMetrics + Db.Where + Db.WhereEffort + " AND " + Db.GetWhere("MetricType", "metric", StringComparison.OrdinalIgnoreCase); cmd.Parameters.AddWithValue("ceid", catchEffortId.Identity); cmd.Parameters.AddWithValue("metric", metricType); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); CatchMetric o = null; List <CatchMetric> permissions = new List <CatchMetric>(); if (rdr != null) { try { while (rdr.Read()) { o = this.catchBuilder.Build(rdr); if (o != null) { permissions.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(permissions); } return(null); }
public static HashSet <CompoundIdentity> ToIds(JObject dataPayload) { if (dataPayload != null) { try { CompoundIdentity id = ToId(dataPayload); if (id != null) { HashSet <CompoundIdentity> ids = new HashSet <CompoundIdentity>(); ids.Add(id); return(ids); } } catch { } } return(null); }
public override IEnumerable <CompoundIdentity> GetParentIds(CompoundIdentity orgId) { if (!orgId.IsNullOrEmpty()) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectMem + Db.WhereElem; cmd.Parameters.AddWithValue("sid", this.Identity.DataStoreIdentity); cmd.Parameters.AddWithValue("id", this.Identity.Identity); cmd.Parameters.AddWithValue("csid", orgId.DataStoreIdentity); cmd.Parameters.AddWithValue("cid", orgId.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); if (rdr != null) { HashSet <CompoundIdentity> res = new HashSet <CompoundIdentity>(); try { while (rdr.Read()) { res.Add(new CompoundIdentity(DbReaderUtils.GetGuid(rdr, 0), DbReaderUtils.GetGuid(rdr, 1))); } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } return(res); } } catch { } } return(null); }
public IEnumerable <Fish> GetFish(CompoundIdentity catchEffortId, IEnumerable <CompoundIdentity> taxaId) { if (!catchEffortId.IsNullOrEmpty() && Db.DataStoreIdentity.Equals(catchEffortId.DataStoreIdentity) && this.CanGet()) { string wh = Db.GetWhere(taxaId, "taxasid", "taxaid"); if (wh != null && wh.Length > 0) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishIndividual + Db.Where + Db.WhereEffort + " AND " + wh; cmd.Parameters.AddWithValue("ceid", catchEffortId.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); Fish o = null; List <Fish> permissions = new List <Fish>(); if (rdr != null) { try { while (rdr.Read()) { o = this.fishBuilder.Build(rdr); if (o != null) { permissions.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(permissions); } } return(null); }
//:sid,:id,:psid,:pid,:csid,:cid private bool Up(CompoundIdentity parentId, CompoundIdentity childId) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.UpdateMem; cmd.Parameters.AddWithValue("sid", this.Identity.DataStoreIdentity); cmd.Parameters.AddWithValue("id", this.Identity.Identity); cmd.Parameters.AddWithValue("psid", parentId.DataStoreIdentity); cmd.Parameters.AddWithValue("pid", parentId.Identity); cmd.Parameters.AddWithValue("csid", childId.DataStoreIdentity); cmd.Parameters.AddWithValue("cid", childId.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } return(false); }
internal bool Delete(CompoundIdentity sampleEventId) { if (this.connString != null && sampleEventId != null && !sampleEventId.IsEmpty) { try { NpgsqlCommand cmd = GetCmd(this.connString); cmd.CommandText = DeleteSql; cmd.Parameters.AddWithValue("sid", sampleEventId.DataStoreIdentity); cmd.Parameters.AddWithValue("id", sampleEventId.Identity); ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }