public void Remove(KnownDetType type) { if (type != KnownDetType.Unknown) { this.items.Remove(type); } }
public List <Guid> GetBundles(KnownDetType type) { if (this.items.ContainsKey(type)) { return(this.items[type].BundleIds); } return(null); }
public SampleEventMapItem Get(KnownDetType type) { if (this.items.ContainsKey(type)) { return(this.items[type]); } return(null); }
public bool Add(Guid id, KnownDetType type, bool isPrivate) { if (!Guid.Empty.Equals(id) && type != KnownDetType.Unknown && !this.items.ContainsKey(type)) { this.items[type] = new SampleEventMapItem(type, id, isPrivate); return(true); } return(false); }
protected List <EntityBundle> GetBundles(SampleEventMap map, KnownDetType type) { if (map != null) { if (map.Contains(type)) { List <Guid> bundleIds = map.GetBundles(type); if (bundleIds != null && bundleIds.Count > 0) { return(GetBundles(bundleIds)); } } } return(null); }
public FilestoreFile Get(CompoundIdentity sampleEventId, KnownDetType type) { SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map != null) { SampleEventMapItem it = map.Get(type); if (it != null) { return(Get(it.DetId)); } } return(null); }
protected bool DeleteFile(SampleEventMap map, KnownDetType type) { SampleEventMapItem id = map.Get(type); if (id != null) { IFileStoreProvider p = this.FileStore; if (p != null) { if (p.Delete(id.DetId)) { map.Remove(id.DetId); return(true); } } } return(false); }
//format: int:guid,guid,...|int:guid,guid,... internal void DecodeBundleIds(string item, SampleEventMap map) { if (!string.IsNullOrEmpty(item)) { try { string[] blocks = item.Split('|'); foreach (string cur in blocks) { int idx = cur.IndexOf(':'); KnownDetType tp = (KnownDetType)int.Parse(cur.Substring(0, idx)); string[] ids = cur.Substring(idx + 1).Split(','); List <Guid> parts = map.GetBundles(tp); foreach (string id in ids) { parts.Add(Guid.Parse(id)); } } } catch { } } }
public bool Add(Guid id, KnownDetType type) { return(Add(id, type, false)); }
public SampleEventMapItem(KnownDetType typ, Guid detId, bool isPrivate) { this.DetType = typ; this.DetId = detId; this.IsPrivate = isPrivate; }
public bool Contains(KnownDetType type) { return(this.items.ContainsKey(type)); }
public bool Delete(CompoundIdentity sampleEventId, bool fileOnly, KnownDetType type) { if (type == KnownDetType.WaterQuality) //For each known type, we need to add a block here { WqDetProcessor p = new WqDetProcessor(this.ctx); SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map.Contains(type)) { SampleEventMapItem it = map.Get(type); if (it != null) { if (p.Delete(map, fileOnly)) //note the permission is checked in there { map.Remove(it.DetId); if (!map.IsEmpty) { return(DetRegistry.Instance.Update(map)); } else { return(DetRegistry.Instance.Delete(map.SampleEventId)); } } } } } else if (type == KnownDetType.Fish) { FishDetProcessor f = new FishDetProcessor(this.ctx); SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map.Contains(type)) { SampleEventMapItem it = map.Get(type); if (it != null) { if (f.Delete(map, fileOnly)) //note the permission is checked in there { map.Remove(it.DetId); if (!map.IsEmpty) { return(DetRegistry.Instance.Update(map)); } else { return(DetRegistry.Instance.Delete(map.SampleEventId)); } } } } } else if (type == KnownDetType.Veg) { VegDetProcessor v = new VegDetProcessor(this.ctx); SampleEventMap map = DetRegistry.Instance.Get(sampleEventId); if (map.Contains(type)) { SampleEventMapItem it = map.Get(type); if (it != null) { if (v.Delete(map, fileOnly)) //note the permission is checked in there { map.Remove(it.DetId); if (!map.IsEmpty) { return(DetRegistry.Instance.Update(map)); } else { return(DetRegistry.Instance.Delete(map.SampleEventId)); } } } } } return(false); }
//{eventid:<id>, cascade:<bool>, type:<dettype>} // note that cascade is optional, if omitted, treated as false // note that if cascade==true, that means delete both the file and all stored data in the system for that file -- THIS CANNOT BE UNDONE // note that type is optional, if omitted, treated as all det types otherwise it's a single type such as wq internal static void Delete(UserSecurityContext user, JToken dat, HttpContext context, CancellationToken cancel) { if (dat != null) { JObject payload = dat as JObject; if (payload != null) { CompoundIdentity seId = JsonUtils.ToId(dat["eventid"]); if (seId != null) { bool fileOnly = true; JToken t = payload["cascade"]; if (t != null) { string tmp = t.ToString(); if (tmp != null) { tmp = tmp.Trim().ToLowerInvariant(); if (tmp.StartsWith("tr")) { fileOnly = false; } } else { context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; return; } } KnownDetType type = KnownDetType.Unknown; t = payload[JsonUtils.Type]; if (t != null) { string tmp = KnownDets.Instance.Clean(t.ToString()); if (!KnownDets.Instance.IsValid(tmp)) { context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; return; } type = ToType(tmp); } GeneralDetProcessor prov = DetProcessorManager.Instance.GetProvider(user); if (prov != null) { bool res = false; if (type != KnownDetType.Unknown) { res = prov.Delete(seId, fileOnly, type); } else { res = prov.Delete(seId, fileOnly); } if (res) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } return; } } } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }