private BsonDocument buildPowerCal(KAIAM.DataAccess.PowerCalBeforeTx tcd) { Measurement measurement = null; // Initialize object that will be stored under 'device' in mongo document BsonDocument nestedDevice = null; try { measurement = tcd.Measurement; } catch (Exception exc) { Program.log("ERROR POWER CAL: " + tcd.Id + " - " + exc.Message); } finally { nestedDevice = SyncManager.Instance.getNestedDevice(measurement); } if (nestedDevice == null) return null; // Initialize object that will be stored under 'meta' in mongo document BsonDocument nestedMeta = SyncManager.Instance.getNestedMeta(measurement); if (nestedMeta == null) return null; // Initialize object that will be stored under 'data' in mongo document BsonDocument nestedData = SyncManager.Instance.getNestedData(tcd, excludeDataFields); // Custom code to move some set fields to meta object nestedMeta.Add("SetTemperature_C", nestedData["SetTemperature"]); nestedData.Remove("SetTemperature"); nestedMeta.Add("Channel", nestedData["Channel"]); nestedData.Remove("Channel"); nestedMeta.Add("SetVoltage", nestedData["SetVoltage"]); nestedData.Remove("SetVoltage"); //System.Diagnostics.Trace.WriteLine("D " + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")); // Initialize object in root of the document BsonDocument rootDoc = new BsonDocument { { "_id", tcd.Id.ToString()}, { "mid", measurement.Id.ToString() }, { "timestamp", tcd.Timestamp}, { "type", domain() }, { "subtype", "beforetx" }, { "result", getResult( tcd.Result.ToString()) }, { "downstatus", getDownStatus( tcd.Result.ToString()) }, { "status", getStatus(measurement.Result) } }; rootDoc.Add("device", nestedDevice); rootDoc.Add("meta", nestedMeta); rootDoc.Add("data", nestedData); return rootDoc; }
private BsonDocument buildMongoObject(KAIAM.DataAccess.Packout tcd) { // Initialize all related objects from SQL Measurement measurement = null; // Initialize device object BsonDocument nestedDevice = null; try { if (tcd.Measurement != null) { measurement = tcd.Measurement; } } catch (Exception exc) { Program.log("ERROR PACKOUT: " + tcd.Id + " - " + exc.Message); } finally { nestedDevice = SyncManager.Instance.getNestedDevice(measurement); } if (nestedDevice == null) return null; // Initialize object that will be stored under "meta" in mongo document BsonDocument nestedMeta = SyncManager.Instance.getNestedMeta(measurement); if (nestedMeta == null) return null; // Initialize object that will be stored under "data" in mongo document BsonDocument nestedData = SyncManager.Instance.getNestedData(tcd, excludeDataFields); // Initialize object in root of the document BsonDocument rootDoc = new BsonDocument { { "_id", tcd.Id.ToString()}, { "mid", measurement.Id.ToString() }, { "timestamp", tcd.TimeStamp}, { "type", domain() }, { "subtype", "" }, { "result", !ecns.Contains(nestedDevice["SerialNumber"].ToString()) ? getResult( tcd.Result.ToString()) : "OK" }, { "downstatus", !ecns.Contains(nestedDevice["SerialNumber"].ToString()) ? getDownStatus( tcd.Result.ToString()) : "P" }, { "status", !ecns.Contains(nestedDevice["SerialNumber"].ToString()) ? getStatus(measurement.Result) : "P" } }; rootDoc.Add("device", nestedDevice); rootDoc.Add("meta", nestedMeta); rootDoc.Add("data", nestedData); return rootDoc; }