private void ParseDeviceInfoData() { try { FileStream inputStream = File.Open(Settings.ActiveZoneSetTmpFile, FileMode.Open); var jsonObject = JsonDocument.Parse(inputStream, options: default).RootElement; UniqueKey = jsonObject.GetProperty("device-id").GetString(); ActiveZoneSetUUid = jsonObject.GetProperty("active-zoneset").GetProperty("uuid").GetString(); string layoutType = jsonObject.GetProperty("active-zoneset").GetProperty("type").GetString(); if (ActiveZoneSetUUid == "null" || layoutType == "blank") { // Default selection is Focus ActiveZoneSetLayoutType = LayoutType.Focus; _showSpacing = true; _spacing = 16; _zoneCount = 3; } else { switch (layoutType) { case "focus": ActiveZoneSetLayoutType = LayoutType.Focus; break; case "columns": ActiveZoneSetLayoutType = LayoutType.Columns; break; case "rows": ActiveZoneSetLayoutType = LayoutType.Rows; break; case "grid": ActiveZoneSetLayoutType = LayoutType.Grid; break; case "priority-grid": ActiveZoneSetLayoutType = LayoutType.PriorityGrid; break; case "custom": ActiveZoneSetLayoutType = LayoutType.Custom; break; } _showSpacing = jsonObject.GetProperty("editor-show-spacing").GetBoolean(); _spacing = jsonObject.GetProperty("editor-spacing").GetInt32(); _zoneCount = jsonObject.GetProperty("editor-zone-count").GetInt32(); } inputStream.Close(); } catch (Exception ex) { LayoutModel.ShowExceptionMessageBox("Error parsing device info data", ex); } }
private void ParseDeviceInfoData(ParseDeviceMode mode = ParseDeviceMode.Prod) { try { string layoutType = LayoutTypeBlankStr; ActiveZoneSetUUid = NullUuidStr; JsonElement jsonObject = default(JsonElement); if (File.Exists(Settings.ActiveZoneSetTmpFile)) { FileStream inputStream = File.Open(Settings.ActiveZoneSetTmpFile, FileMode.Open); jsonObject = JsonDocument.Parse(inputStream, options: default).RootElement; inputStream.Close(); UniqueKey = jsonObject.GetProperty(DeviceIdJsonTag).GetString(); ActiveZoneSetUUid = jsonObject.GetProperty(ActiveZoneSetJsonTag).GetProperty(UuidJsonTag).GetString(); layoutType = jsonObject.GetProperty(ActiveZoneSetJsonTag).GetProperty(TypeJsonTag).GetString(); } if (mode == ParseDeviceMode.Debug || ActiveZoneSetUUid == NullUuidStr || layoutType == LayoutTypeBlankStr) { // Default or there is no active layout on current device ActiveZoneSetLayoutType = LayoutType.Focus; _showSpacing = true; _spacing = 5; _zoneCount = 3; _sensitivityRadius = 20; } else { switch (layoutType) { case FocusJsonTag: ActiveZoneSetLayoutType = LayoutType.Focus; break; case ColumnsJsonTag: ActiveZoneSetLayoutType = LayoutType.Columns; break; case RowsJsonTag: ActiveZoneSetLayoutType = LayoutType.Rows; break; case GridJsonTag: ActiveZoneSetLayoutType = LayoutType.Grid; break; case PriorityGridJsonTag: ActiveZoneSetLayoutType = LayoutType.PriorityGrid; break; case CustomJsonTag: ActiveZoneSetLayoutType = LayoutType.Custom; break; } _showSpacing = jsonObject.GetProperty(EditorShowSpacingJsonTag).GetBoolean(); _spacing = jsonObject.GetProperty(EditorSpacingJsonTag).GetInt32(); _zoneCount = jsonObject.GetProperty(EditorZoneCountJsonTag).GetInt32(); _sensitivityRadius = jsonObject.GetProperty(EditorSensitivityRadiusJsonTag).GetInt32(); } } catch (Exception ex) { LayoutModel.ShowExceptionMessageBox(ErrorParsingDeviceInfo, ex); } }