public void SaveTransformFile() { ExtensionFilter[] extensionFilters = new[] { new ExtensionFilter("json") }; string path = SFB.StandaloneFileBrowser.SaveFilePanel("Save Transform File", "", "transforms.json", extensionFilters); GameObject[] RosDeviceGameObjects = GameObject.FindGameObjectsWithTag("RosDevice"); DeviceJson[] deviceJsons = new DeviceJson[RosDeviceGameObjects.Length]; JsonSerializerOptions options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, WriteIndented = true }; int count = 0; foreach (GameObject RosDevice in RosDeviceGameObjects) { Transform transform = RosDevice.GetComponent <Transform>(); deviceJsons[count] = new DeviceJson(RosDevice.name, RosDevice.transform, true); count++; } Debug.Log(path); string jsonString = JsonSerializer.Serialize(deviceJsons, options); File.WriteAllText(path, jsonString); }
public void queryDeviceList() { MojingLog.LogTrace("Enter queryDeviceList"); if (!_javaInit) { return; } //#if UNITY_ANDROID && !UNITY_EDITOR // string jsonStr = _javaClass.CallStatic<string>("getDeviceList"); //#else string jsonStr = "{ \"ClassName\":\"DeviceList\",\"DeviceList\":[{\"ID\":1,\"DeviceName\":\"AirMouse\",\"Connect\":1},{\"ID\":2,\"DeviceName\":\"AirMouse\",\"Connect\":1}]}"; //#endif MojingLog.LogTrace("json=" + jsonStr); DeviceJson devList = JsonMapper.ToObject <DeviceJson>(jsonStr); if (devList != null) { _deviceList.Clear(); MojingLog.LogTrace("DeviceList count=" + devList.DeviceList.Count); for (int i = 0; i < devList.DeviceList.Count; ++i) { Device dev = new Device(devList.DeviceList[i]); _deviceList.Add(dev); MojingLog.LogTrace("DeviceList " + i + " ID: " + dev.id + ", name: " + dev.name + ", connectable: " + dev.connectable + ", connected: " + dev.connected); } DevNum = _deviceList.Count; } }
public static SchemeJson ToJson(InputControlScheme scheme) { DeviceJson[] devices = null; if (scheme.m_DeviceRequirements != null && scheme.m_DeviceRequirements.Length > 0) { var count = scheme.m_DeviceRequirements.Length; devices = new DeviceJson[count]; for (var i = 0; i < count; ++i) { devices[i] = DeviceJson.From(scheme.m_DeviceRequirements[i]); } } return(new SchemeJson { name = scheme.m_Name, basedOn = scheme.m_BaseSchemeName, bindingGroup = scheme.m_BindingGroup, devices = devices, }); }
//Get Connection string from Registry for this Window Service to connect to database to get data //Get all Device data from database, database name for Wcf Web Service from Registry and transform it to Json public string GetDevices(string lastRunDate, string remoteDbName, string connectionString) { _log.Debug("+GetDevices()"); SqlConnection connection = null; SqlDataReader dataReader = null; JavaScriptSerializer jserializer = null; string sqlDevices = @"SELECT d.SerialNumber, d.DeviceNo, d.CompanyID, d.DeviceID, d.DateRegistered, d.DateUpdated, d.DeviceName, d.DeviceRFAddress, d.DeviceSize, d.DeviceSizeTotal, d.DeviceSubType, d.HighLimit, d.LowLimit, d.DeviceHighThreshold, d.OverrideHighThreshhold, d.DeviceLowThreshold, d.OverrideLowThreshold, d.Differential, d.DiffPolarity, d.OverrideDifferential, d.DeviceDrivenInt, d.NoDataInt, d.ThresholdForCollection, d.ErrorRepeatDelay, d.OverrideErrorRepeatDelay, d.DisableInterruptForThisDevice, d.NoDataInterruptSamples, d.Height, d.Length, d.Width, d.BottomOutlet, d.CapacityOfAdjustment, d.DeviceCount, d.SensorOffset, d.UpdateDevice, d.RegisterDevice, d.MarkedForDeletion, d.DeviceLinkTableID, d.Identifier, d.AlertTypeH, d.AlertTypeL, d.AlertTypeD, d.AlertTypeI, d.AlertTypeN, d.AlertDesc, d.UnitMeasurement, d.DTEStatus, d.DeviceApplication, d.OverrideDDEM, d.DwellingFloors, d.DwellingUnits, d.DwellingRooms, d.DwellingArea, d.SubstanceID, d.EquipmentID FROM TBLDevices d WHERE d.DateUpdated > '" + lastRunDate + "'"; try { using (connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(sqlDevices, connection); connection.Open(); using (dataReader = command.ExecuteReader()) { if (dataReader.HasRows) { while (dataReader.Read()) { _numberOfRows++; _deviceObj = new Device(); _deviceObj.SerialNumber = SafeDao.SafeGetString(dataReader, 0); _deviceObj.DeviceNo = SafeDao.SafeGetInt(dataReader, 1); _deviceObj.CompanyID = SafeDao.SafeGetInt(dataReader, 2); _deviceObj.DeviceID = SafeDao.SafeGetInt(dataReader, 3); _deviceObj.DateRegistered = SafeDao.SafeGetDateTime(dataReader, 4); _deviceObj.DateUpdated = SafeDao.SafeGetDateTime(dataReader, 5); _deviceObj.DeviceName = SafeDao.SafeGetString(dataReader, 6); _deviceObj.DeviceRFAddress = SafeDao.SafeGetString(dataReader, 7); _deviceObj.DeviceSize = SafeDao.SafeGetInt(dataReader, 8); _deviceObj.DeviceSizeTotal = SafeDao.SafeGetInt(dataReader, 9); _deviceObj.DeviceSubType = SafeDao.SafeGetInt(dataReader, 10); _deviceObj.HighLimit = SafeDao.SafeGetInt(dataReader, 11); _deviceObj.LowLimit = SafeDao.SafeGetInt(dataReader, 12); _deviceObj.DeviceHighThreshold = SafeDao.SafeGetInt(dataReader, 13); _deviceObj.OverrideHighThreshhold = SafeDao.SafeGetByte(dataReader, 14); _deviceObj.DeviceLowThreshold = SafeDao.SafeGetInt(dataReader, 15); _deviceObj.OverrideLowThreshold = SafeDao.SafeGetByte(dataReader, 16); _deviceObj.Differential = SafeDao.SafeGetInt(dataReader, 17); _deviceObj.DiffPolarity = SafeDao.SafeGetShort(dataReader, 18); _deviceObj.OverrideDifferential = SafeDao.SafeGetByte(dataReader, 19); _deviceObj.DeviceDrivenInt = SafeDao.SafeGetByte(dataReader, 20); _deviceObj.NoDataInt = SafeDao.SafeGetByte(dataReader, 21); _deviceObj.ThresholdForCollection = SafeDao.SafeGetByte(dataReader, 22); _deviceObj.ErrorRepeatDelay = SafeDao.SafeGetInt(dataReader, 23); _deviceObj.OverrideErrorRepeatDelay = SafeDao.SafeGetByte(dataReader, 24); _deviceObj.DisableInterruptForThisDevice = SafeDao.SafeGetByte(dataReader, 25); _deviceObj.NoDataInterruptSamples = SafeDao.SafeGetShort(dataReader, 26); _deviceObj.Height = SafeDao.SafeGetDouble(dataReader, 27); _deviceObj.Length = SafeDao.SafeGetDouble(dataReader, 28); _deviceObj.Width = SafeDao.SafeGetDouble(dataReader, 29); _deviceObj.BottomOutlet = SafeDao.SafeGetDouble(dataReader, 30); _deviceObj.CapacityOfAdjustment = SafeDao.SafeGetDouble(dataReader, 31); _deviceObj.DeviceCount = SafeDao.SafeGetInt(dataReader, 32); _deviceObj.SensorOffset = SafeDao.SafeGetDouble(dataReader, 33); _deviceObj.UpdateDevice = SafeDao.SafeGetByte(dataReader, 34); _deviceObj.RegisterDevice = SafeDao.SafeGetByte(dataReader, 35); _deviceObj.MarkedForDeletion = SafeDao.SafeGetByte(dataReader, 36); _deviceObj.DeviceLinkTableID = SafeDao.SafeGetInt(dataReader, 37); _deviceObj.Identifier = SafeDao.SafeGetString(dataReader, 38); _deviceObj.AlertTypeH = SafeDao.SafeGetInt(dataReader, 39); _deviceObj.AlertTypeL = SafeDao.SafeGetInt(dataReader, 40); _deviceObj.AlertTypeD = SafeDao.SafeGetInt(dataReader, 41); _deviceObj.AlertTypeI = SafeDao.SafeGetInt(dataReader, 42); _deviceObj.AlertTypeN = SafeDao.SafeGetInt(dataReader, 43); _deviceObj.AlertDesc = SafeDao.SafeGetString(dataReader, 44); _deviceObj.UnitMeasurement = SafeDao.SafeGetInt(dataReader, 45); _deviceObj.DTEStatus = SafeDao.SafeGetShort(dataReader, 46); _deviceObj.DeviceApplication = SafeDao.SafeGetShort(dataReader, 47); _deviceObj.OverrideDDEM = SafeDao.SafeGetByte(dataReader, 48); _deviceObj.DwellingFloors = SafeDao.SafeGetInt(dataReader, 49); _deviceObj.DwellingUnits = SafeDao.SafeGetInt(dataReader, 50); _deviceObj.DwellingRooms = SafeDao.SafeGetInt(dataReader, 51); _deviceObj.DwellingArea = SafeDao.SafeGetDouble(dataReader, 52); _deviceObj.SubstanceID = SafeDao.SafeGetInt(dataReader, 53); _deviceObj.EquipmentID = SafeDao.SafeGetInt(dataReader, 54); _devices.Add(_deviceObj); } } dataReader.Close(); } connection.Close(); } _log.Debug("-GetDevices() Devices from database: " + _numberOfRows + "rows of data!"); //Set the composite object with our data.. JsonDevice = new DeviceJson(_devices); JsonDevice.DatabaseName = remoteDbName; //Set Json object to max possible capasity jserializer = new JavaScriptSerializer(); jserializer.MaxJsonLength = Int32.MaxValue; } catch (SqlException ex) { _log.Error("-GetDevices() Message: " + ex.Message + " InnerException: " + ex.InnerException); } finally { if (dataReader != null) { dataReader.Close(); } if (connection != null) { connection.Close(); } } _log.Debug("-GetDevices()"); return(jserializer.Serialize(new { JsonDevice }).ToString()); }
public IEnumerable <ThermometerValuesUpdated> MapToThermometerValuesUpdated(IEnumerable <Temperature> temperature, DeviceJson device) { var thermometerValues = new List <ThermometerValuesUpdated>(); var reference = DateTime.UtcNow; foreach (var t in temperature) { thermometerValues.Add(new ThermometerValuesUpdated(new DeviceId(device.DeviceId.ToGuid()), new EventId( $"{reference.Year:0000}{reference.Month:00}{reference.Day:00}{reference.Hour:00}{reference.Minute:00}{reference.Second:00}{reference.Millisecond:000}"), new DeviceName(device.DeviceName), t, new UnitOfMeasurement("F"), new CommunicationDate(DateTime.UtcNow), this._who, new When(DateTime.UtcNow))); reference = reference.AddMilliseconds(10); } return(thermometerValues); }