public override FieldActivity Get(CompoundIdentity id) { if (!id.IsNullOrEmpty() && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectActivities + Db.SelectById; cmd.Parameters.AddWithValue("sid", id.DataStoreIdentity); cmd.Parameters.AddWithValue("id", id.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); FieldActivity o = null; if (rdr != null) { try { rdr.Read(); o = FieldActivityBuilder.Instance.Build(rdr); if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(o); } return(null); }
public override bool ExistsForActivity(FieldActivity activity) { if (activity != null) { return(this.ExistsForActivity(activity.Identity)); } return(false); }
public override IEnumerable <FieldTrip> GetForActivity(FieldActivity activity) { if (activity != null) { return(this.GetForActivity(activity.Identity)); } return(null); }
public override bool Contains(FieldTeam team, FieldActivity item) { if (team != null && item != null && this.CanGet()) { return(ContainsImpl(team.Identity, item.Identity, FieldActivityUtils.FieldActivityWktId)); } return(false); }
public override IEnumerable <FieldTeam> Get(FieldActivity item) { if (item != null && this.CanGet()) { return(Get(item.Identity, FieldActivityUtils.FieldActivityWktId)); } return(null); }
public override bool Add(FieldTeam team, FieldActivity item) { if (team != null && item != null && this.CanCreate()) { return(this.AddImpl(team.Identity, item.Identity, FieldActivityUtils.FieldActivityWktId)); } return(false); }
public override bool Remove(FieldTeam team, FieldActivity item) { if (team != null && item != null) { return(Remove(team.Identity, item.Identity, FieldActivityUtils.FieldActivityWktId)); } return(false); }
public override bool Delete(FieldActivity item) { if (item != null && this.CanDelete(item)) { return(this.Delete(item.Identity)); } return(false); }
public virtual void Init(FieldActivity activity) { if (activity == null) { return; } _Activity = activity; }
public IGenerator GetGenerator(FieldActivity activity) { var generator = _Generators.FirstOrDefault(g => g.Name.Equals(activity.Type)); if (generator == null) { throw new Exception($"Could not find generator for {activity.Type}"); } generator.Init(activity); return(generator); }
static FieldTrip CreateFT(FieldTripProviderBase prov, FieldActivity act) { string name = "hello field trip"; if (prov.Exists(name)) { IEnumerable <FieldTrip> acts = prov.Get(name); if (acts != null) { foreach (FieldTrip cur in acts) { if (cur.Identity.Equals(act.Identity)) { if (prov.Delete(cur)) { Console.WriteLine("Exists, got and deleted"); break; } else { Console.WriteLine("Exists, got, but didn't delete"); } } } } else { Console.WriteLine("Exists and didn't get"); } } FieldTrip trip = prov.Create(name, act, new Osrs.Data.CompoundIdentity(Guid.NewGuid(), Guid.NewGuid())); if (trip != null) { Console.WriteLine("Created"); trip.Description = "woof"; if (prov.Update(trip)) { Console.WriteLine("updated"); } else { Console.WriteLine("didn't update"); } } else { Console.WriteLine("didn't create"); } return(trip); }
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; }
private async Task SendScan(FieldActivity activity) { if ((activity == null) || (activity.State != ActivityState.Waiting)) { return; } try { if (_PauseOnly) { MessageBox.Show(this, "Click ok after scanning a lanyard.", "Scan Pause", MessageBoxButtons.OK); activity.ReadyUp(DateTimeOffset.Now.ToUnixTimeMilliseconds()); return; } var frm = new InputForm("Barcode", "Scan/Enter Barcode", string.Empty); if (frm.ShowDialog(this) == DialogResult.Cancel) { return; } // create player activity object var player = new PlayerActivity { ActivityId = activity.Id, LanyardId = frm.Result, Scanned = DateTimeOffset.UtcNow, StartTime = DateTime.UtcNow, State = 1 }; var s = Serializer.Serialize(player); // create new player activity record using (var restService = new RestService()) { restService.EchoOn = true; var result = await restService.PostAsync <ServiceResult <PlayerActivity>, PlayerActivity>(string.Format($"{_BaseUrl}playeractivity/set", "activity"), player); if (result.Status != ServiceResultStatus.Success) { throw new Exception(result.Message); } activity.CurrentPlayer = result.Payload; activity.ReadyUp(DateTimeOffset.Now.ToUnixTimeMilliseconds()); } } catch (Exception ex) { Debug.WriteLine($"Exception: {ex}"); } }
static FieldActivity CreateFA(FieldActivityProviderBase prov) { string name = "hello field activity"; if (prov.Exists(name)) { IEnumerable <FieldActivity> acts = prov.Get(name); if (acts != null) { foreach (FieldActivity cur in acts) { if (prov.Delete(cur)) { Console.WriteLine("Exists, got and deleted"); break; } else { Console.WriteLine("Exists, got, but didn't delete"); } } } else { Console.WriteLine("Exists and didn't get"); } } FieldActivity act = prov.Create(name, new Osrs.Data.CompoundIdentity(Guid.NewGuid(), Guid.NewGuid()), new Osrs.Data.CompoundIdentity(Guid.NewGuid(), Guid.NewGuid()), new ValueRange <DateTime>(DateTime.MinValue, DateTime.UtcNow), null); if (act != null) { Console.WriteLine("Created"); act.Description = "woof"; if (prov.Update(act)) { Console.WriteLine("updated"); } else { Console.WriteLine("didn't update"); } } else { Console.WriteLine("didn't create"); } return(act); }
public override bool Update(FieldActivity item) { if (item != null && this.CanUpdate(item)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.UpdateActivity; cmd.Parameters.AddWithValue("sid", item.Identity.DataStoreIdentity); cmd.Parameters.AddWithValue("id", item.Identity.Identity); cmd.Parameters.AddWithValue("psid", item.ProjectId.DataStoreIdentity); cmd.Parameters.AddWithValue("pid", item.ProjectId.Identity); cmd.Parameters.AddWithValue("osid", item.PrincipalOrgId.DataStoreIdentity); cmd.Parameters.AddWithValue("oid", item.PrincipalOrgId.Identity); if (item.DateRange != null) { item.DateRange = Db.CleanRange(item.DateRange); cmd.Parameters.AddWithValue("start", item.DateRange.Min); cmd.Parameters.AddWithValue("end", item.DateRange.Max); } else { cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("start", NpgsqlTypes.NpgsqlDbType.TimestampTZ)); cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("end", NpgsqlTypes.NpgsqlDbType.TimestampTZ)); } cmd.Parameters.AddWithValue("name", item.Name); if (string.IsNullOrEmpty(item.Description)) { cmd.Parameters.Add(NpgSqlCommandUtils.GetNullInParam("desc", NpgsqlTypes.NpgsqlDbType.Varchar)); } else { cmd.Parameters.AddWithValue("desc", item.Description); } Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
private void ActivitySetupMenu_Click(object sender, EventArgs e) { FieldActivity activity = null; ToolStripMenuItem item = null; if (sender != null) { item = (ToolStripMenuItem)sender; activity = (FieldActivity)item.Tag; } else { activity = _SetupActivity; foreach (var child in SetupMenu.DropDownItems) { if (((ToolStripMenuItem)child).Tag == activity) { item = (ToolStripMenuItem)child; break; } } } if (activity.ActivityMode != ActivityMode.Ready) { Debug.WriteLine($"{_SetupActivity.Name} already in setup mode - cancel"); _SetupActivity.ActivityMode = ActivityMode.Ready; foreach (var child in item.GetCurrentParent().Items) { SetEnabled((ToolStripMenuItem)child, true); } return; } foreach (var child in item.GetCurrentParent().Items) { SetEnabled((ToolStripMenuItem)child, false); } _SetupActivity = activity; StartSetup(); }
public override IEnumerable <FieldActivity> GetForProject(CompoundIdentity projectId) { if (!projectId.IsNullOrEmpty() && this.CanGet()) { string where = " WHERE \"ProjectSystemId\"=:sid AND \"ProjectId\"=:id"; NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectActivities + where; cmd.Parameters.AddWithValue("sid", projectId.DataStoreIdentity); cmd.Parameters.AddWithValue("id", projectId.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); FieldActivity o = null; List <FieldActivity> permissions = new List <FieldActivity>(); if (rdr != null) { try { while (rdr.Read()) { o = FieldActivityBuilder.Instance.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 JObject ToJson(FieldActivity activity) { if (activity != null) { JObject o = new JObject(); o.Add(JsonUtils.Id, JsonUtils.ToJson(activity.Identity)); o.Add(JsonUtils.Name, activity.Name); o.Add(JsonUtils.OwnerId, JsonUtils.ToJson(activity.PrincipalOrgId)); o.Add(JsonUtils.ProjectId, JsonUtils.ToJson(activity.ProjectId)); if (activity.Description != null) { o.Add(JsonUtils.Description, activity.Description); } if (activity.DateRange != null) { if (activity.DateRange.Min.Equals(DateTime.MinValue)) { o.Add(JsonUtils.Start, null); } else { o.Add(JsonUtils.Start, activity.DateRange.Min.ToString()); } if (activity.DateRange.Max.Equals(DateTime.MinValue) || activity.DateRange.Max.Equals(DateTime.MaxValue)) //never set or closed { o.Add(JsonUtils.Finish, null); } else { o.Add(JsonUtils.Finish, activity.DateRange.Max.ToString()); } } return(o); } return(null); }
public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel) { if (context.Request.Method == "POST") { if (method.Equals("all", StringComparison.OrdinalIgnoreCase)) { Get(user, context, cancel); return; } else if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { JToken token = JsonUtils.GetDataPayload(context.Request); if (token != null) { if (token["name"] != null) { string name = token["name"].ToString(); GetName(name, user, context, cancel); return; } else if (token["orgid"] != null) { CompoundIdentity org_id = JsonUtils.ToId(token["orgid"]); GetByOrg(org_id, user, context, cancel); return; } else if (token["activityid"] != null) { CompoundIdentity activity_id = JsonUtils.ToId(token["activityid"]); GetByActivity(activity_id, user, context, cancel); return; } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("in", StringComparison.OrdinalIgnoreCase)) { try { HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request)); if (ids != null) { GetIds(ids, user, context, cancel); return; } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } } else if (method.Equals("create", StringComparison.OrdinalIgnoreCase)) { JToken token = null; FieldTripProviderBase provider = null; FieldTrip trip = null; FieldActivity activity = null; CompoundIdentity org_id = null; CompoundIdentity act_id = null; string name; string desc = null; try { //token and provider token = JsonUtils.GetDataPayload(context.Request); provider = FieldActivityManager.Instance.GetFieldTripProvider(user); if (provider != null && token != null) { //required inputs name = token["name"].ToString(); org_id = JsonUtils.ToId(token["orgid"]); act_id = JsonUtils.ToId(token["activityid"]); activity = FieldActivityManager.Instance.GetFieldActivityProvider(user).Get(act_id); if (org_id != null && activity != null && !string.IsNullOrEmpty(name)) { desc = token["desc"] != null ? token["desc"].ToString() : null; //start and end dates //ValueRange<DateTime> range = JsonUtils.ToRange(token, "start", "end"); //create trip = provider.Create(name, activity, org_id, desc); if (trip != null) { JObject jtrip = Jsonifier.ToJson(trip); RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jtrip.ToString())); return; } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("update", StringComparison.OrdinalIgnoreCase)) { JToken token = null; FieldTripProviderBase provider = null; FieldTrip trip = null; CompoundIdentity cid = null; CompoundIdentity org_id = null; CompoundIdentity act_id = null; string name; string desc = null; try { //token and provider token = JsonUtils.GetDataPayload(context.Request); provider = FieldActivityManager.Instance.GetFieldTripProvider(user); if (provider != null && token != null) { //GUID must be provided cid = JsonUtils.ToId(token["id"]); //fetch stored object bool dirty = false; trip = provider.Get(cid); if (trip != null) { //## REQUIRED ## //name if (token.SelectToken("name") != null) { name = token["name"].ToString(); if (!string.IsNullOrEmpty(name)) { trip.Name = name; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable return; } } //owning org if (token.SelectToken("orgid") != null) { org_id = JsonUtils.ToId(token["orgid"]); if (org_id != null) { trip.PrincipalOrgId = org_id; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable return; } } //field activity if (token.SelectToken("activityid") != null) { act_id = JsonUtils.ToId(token["activityid"]); if (act_id != null) { trip.FieldActivityId = act_id; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //project is required and not nullable return; } } //## OPTIONALS ## //description if (token.SelectToken("desc") != null) { desc = (token["desc"] != null) ? token["desc"].ToString() : null; trip.Description = desc; dirty = true; } //start and end dates //if (token.SelectToken("start") != null) //{ //} if (dirty) { //update bool result = provider.Update(trip); if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } else { //return ok - no values were modified RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase)) { try { JToken t = JsonUtils.GetDataPayload(context.Request); HashSet <CompoundIdentity> cids = JsonUtils.ToIds(t); FieldTripProviderBase provider = FieldActivityManager.Instance.GetFieldTripProvider(user); if (cids != null && provider != null) { bool result = true; foreach (CompoundIdentity cid in cids) { result &= provider.Delete(cid); } if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }
private void MainImage_MouseUp(object sender, MouseEventArgs e) { if (_Field == null) { return; } // debounce the click if (DateTime.Now.Subtract(_LastClick).TotalMilliseconds < 700) { return; } _LastClick = DateTime.Now; if ((_Field == null) || (_Field.Activities == null)) { return; } float x = e.X / _ScaleX, y = (_Height - e.Y) / _ScaleY; x -= _Field.Padding.X0; y -= _Field.Padding.Y0; Debug.WriteLine($"Mouse click: {e.X} ({x}), {e.Y} ({y})"); foreach (var activity in _Field.Activities) { if (activity.ActivityMode == ActivityMode.Cone1) { Debug.WriteLine($"{activity.Name} - placing cone 1"); _SetupActivity.Cones[0].X = x; _SetupActivity.Cones[0].Y = y; Status.Text = $"{activity.Name} - Place cone 2"; activity.ActivityMode = ActivityMode.Cone2; } else if (activity.ActivityMode == ActivityMode.Cone2) { Debug.WriteLine($"{activity.Name} - placing cone 2"); _SetupActivity.Cones[1].X = x; _SetupActivity.Cones[1].Y = y; Status.Text = $"{activity.Name} - Place cone 3"; activity.ActivityMode = ActivityMode.Cone3; } else if (activity.ActivityMode == ActivityMode.Cone3) { Debug.WriteLine($"{activity.Name} - placing cone 3"); _SetupActivity.Cones[2].X = x; _SetupActivity.Cones[2].Y = y; Status.Text = $"{activity.Name} - Place cone 4"; activity.ActivityMode = ActivityMode.Cone4; } else if (activity.ActivityMode == ActivityMode.Cone4) { Debug.WriteLine($"{activity.Name} - placing cone 4"); _SetupActivity.Cones[3].X = x; _SetupActivity.Cones[3].Y = y; // find min and max float dx0 = float.MaxValue, dy0 = float.MaxValue, dx1 = float.MinValue, dy1 = float.MinValue; foreach (var cone in _SetupActivity.Cones) { if (cone.X < dx0) { dx0 = cone.X; } if (cone.X > dx1) { dx1 = cone.X; } if (cone.Y < dy0) { dy0 = cone.Y; } if (cone.Y > dy1) { dy1 = cone.Y; } } Status.Text = $"{activity.Name} - Waiting for calibratrion"; activity.ActivityMode = ActivityMode.Calibration; new Thread(StartCallibration).Start(null); } else if (activity.ActivityMode == ActivityMode.Calibration) { Debug.WriteLine($"{activity.Name} - Cancel calibration"); Status.Text = $"{activity.Name} - Cancel calibration"; activity.ActivityMode = ActivityMode.Fail; } else if (activity.ActivityMode == ActivityMode.Fail) { Debug.WriteLine($"{activity.Name} - Calibration failed"); Status.Text = $"{activity.Name} - Cancel calibration"; _SetupActivity = null; activity.ActivityMode = ActivityMode.Ready; } else { Status.Text = string.Empty; var h = activity.Y1 - activity.Y0; var w = activity.X1 - activity.X0; Debug.WriteLine($"Checking activity: {activity.Name} - {activity.X0}, {activity.Y0}, {w}, {h}"); var rect = new Rectangle((int)activity.X0, (int)activity.Y0, (int)w, (int)h); if (rect.IntersectsWith(new Rectangle((int)x, (int)y, 1, 1))) { Debug.WriteLine($"You have clicked {activity.Name} - ({activity.X0},{activity.Y0},{activity.X1},{activity.Y1})"); if (e.Button == MouseButtons.Left) { SendScan(activity); } } } } }
public static IGenerator Create(FieldActivity activity) { _Instance = _Instance ?? new GeneratorFactory(); return(_Instance.GetGenerator(activity)); }
public override bool CanUpdate(FieldActivity item) { return(this.CanUpdate()); //TODO -- add fine grained security }
static void Main(string[] args) { ConfigurationManager.Instance.Bootstrap(); ConfigurationManager.Instance.Initialize(); ConfigurationManager.Instance.Start(); Console.WriteLine("Config state: " + ConfigurationManager.Instance.State); LogManager.Instance.Bootstrap(); LogManager.Instance.Initialize(); LogManager.Instance.Start(); Console.WriteLine("Log state: " + LogManager.Instance.State); AuthorizationManager.Instance.Bootstrap(); AuthorizationManager.Instance.Initialize(); AuthorizationManager.Instance.Start(); Console.WriteLine("Auth state: " + AuthorizationManager.Instance.State); LocalSystemUser usr = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active); UserSecurityContext context = new UserSecurityContext(usr); if (AuthorizationManager.Instance.State == Osrs.Runtime.RunState.Running) { //RegisterPermissions(context); //Grant(context); } FieldActivityManager.Instance.Initialize(); Console.WriteLine("FA state: " + FieldActivityManager.Instance.State); FieldActivityManager.Instance.Start(); Console.WriteLine("FA state: " + FieldActivityManager.Instance.State); if (FieldActivityManager.Instance.State == Osrs.Runtime.RunState.Running) { FieldActivity fa = null; FieldTrip ft = null; FieldActivityProviderBase prov = FieldActivityManager.Instance.GetFieldActivityProvider(context); if (prov != null) { Console.WriteLine("GOT PROVIDER: FAP"); fa = CreateFA(prov); if (fa != null) { fa = prov.Get(fa.Identity); } if (fa != null) { Console.WriteLine("Fetched back"); } } FieldTripProviderBase tprov = FieldActivityManager.Instance.GetFieldTripProvider(context); if (tprov != null) { Console.WriteLine("GOT PROVIDER: FTP"); if (fa != null) { ft = CreateFT(tprov, fa); } else { Console.WriteLine("no activity, not trying trip"); } } } Console.WriteLine("ALL DONE"); Console.ReadLine(); }
private Guid CreateExcelFile(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 file and Excel Workbook FilestoreFile deployFile = provider.MakeTemp(DateTime.UtcNow.AddHours(4)); XlWorkbook book = new XlWorkbook(); XlWorksheets sheets = book.Worksheets; //Generating Sampling Event Sheet XlSchema eventSchema = GetSampleEventSchema(); XlWorksheet eventSheet = sheets.AddWorksheet("SamplingEvents", XlColor.White, eventSchema); XlRows eventRows = eventSheet.Rows; 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; } } } List <string> evtItems = new List <string>(); evtItems.Add(orgName); evtItems.Add(projName); evtItems.Add(factivityName); evtItems.Add(ftripName); evtItems.Add(evt.Value.Item2.Name); evtItems.Add(evt.Value.Item1.ToString()); evtItems.Add(evt.Value.Item2.Description); //evtItems.Add(evt.Value.Item2.DateRange.Min.ToString()); //evtItems.Add(evt.Value.Item2.DateRange.Max.ToString()); SchemaRowData row = new SchemaRowData(eventSchema, evtItems); eventRows.AddRow(row); } //Generating Deployment/Measurement Sheet XlSchema measSchema = GetDeployMeasurementSchema(); XlWorksheet measSheet = sheets.AddWorksheet("WaterQualityMeasurements", XlColor.White, measSchema); XlRows measRows = measSheet.Rows; 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(); } List <string> measItems = new List <string>(); measItems.Add(meas.Item1.ToString()); measItems.Add(deploy.Name); measItems.Add(deploy.Description); measItems.Add(eventIndex.ToString()); measItems.Add(siteFK); measItems.Add(deploy.Range.StartDate.ToString()); measItems.Add(deploy.Range.EndDate.ToString()); measItems.Add(measurement.SampleDate.ToString()); measItems.Add(measurement.SurfaceElevation.ToString()); measItems.Add(measurement.Temperature.ToString()); measItems.Add(measurement.pH.ToString()); measItems.Add(measurement.DissolvedOxygen.ToString()); measItems.Add(measurement.Conductivity.ToString()); measItems.Add(measurement.Salinity.ToString()); measItems.Add(measurement.Velocity.ToString()); SchemaRowData row = new SchemaRowData(measSchema, measItems); measRows.AddRow(row); } //Generating Site Sheet XlSchema siteSchema = GetSiteSchema(); XlWorksheet siteSheet = sheets.AddWorksheet("Sites", XlColor.White, siteSchema); XlRows siteRows = siteSheet.Rows; var orderedSites = siteDict.OrderBy(x => x.Value.Item1); foreach (var site in orderedSites) { Site s = site.Value.Item2; List <string> siteItems = new List <string>(); siteItems.Add(site.Value.Item1.ToString()); siteItems.Add(s.Name); siteItems.Add(s.Description); IGeometry2 <double> geom = s.Location; if (geom != null) { if (geom is PolygonBag2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as PolygonBag2 <double>).ToString()); } else if (geom is Polygon2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as Polygon2 <double>).ToString()); } else if (geom is Polyline2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as Polyline2 <double>).ToString()); } else if (geom is PolylineBag2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as PolylineBag2 <double>).ToString()); } else if (geom is Point2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as Point2 <double>).ToString()); } } else { siteItems.Add(""); } Point2 <double> geom2 = s.LocationMark; if (geom2 != null) { siteItems.Add(WktUtils.ToWkt(geom2 as Point2 <double>).ToString()); } else { siteItems.Add(""); } SchemaRowData row = new SchemaRowData(siteSchema, siteItems); siteRows.AddRow(row); } book.Save(deployFile); deployFile.Flush(); deployFile.Close(); deployFile.Dispose(); return(deployFile.FileId); }