public override string Render(int depthLimit, int currentDepth) { var rowDataSb = new StringBuilder(); if (base.Metadata.IsEnumerable && base.Metadata.IsPrimitiveElement) { // check the collection to see if it's all strongly typed, or all primitives so the columns can be built. foreach (var item in (IEnumerable)this.Metadata.SourceObject) { rowDataSb.Append("<tr>"); //TODO: I don't think we need all this code if it's just going to render primitive types. var renderedValue = ValueDisplay.GetDisplayValue(item); var newTag = HtmlTag.WrapValue("td", renderedValue); rowDataSb.Append(newTag); rowDataSb.Append("</tr>"); } } else { throw new InvalidOperationException( "Cannot render rows for a type which does not implement IEnumerable<T>."); } return(rowDataSb.ToString()); }
public override string Render(int depthLimit, int currentDepth) { var rowDataSb = new StringBuilder(); if (this.Metadata.IsEnumerable) { // check the collection to see if it's all strongly typed, or all primitives so the columns can be built. foreach (var item in (IEnumerable)this.Metadata.SourceObject) { rowDataSb.Append("<tr>"); foreach (var propertyInfo in base.Metadata.Properties) { object value = propertyInfo.GetValue(item); string formattedDisplay = ValueDisplay.DisplayValue(value, depthLimit, currentDepth); var newTag = HtmlTag.WrapValue("td", formattedDisplay); rowDataSb.Append(newTag); } rowDataSb.Append("</tr>"); } } else { throw new InvalidOperationException( "Cannot render rows for a type which does not implement IEnumerable."); } return rowDataSb.ToString(); }
public override string Render(int depthLimit, int currentDepth) { var source = base.Metadata.SourceObject; var sourceObjectType = base.Metadata.SourceObjectType; var value = ValueDisplay.GetDisplayValue(source, sourceObjectType); return(HtmlTag.WrapValue("span", value).ToString()); }
void GenerateGrid() { resultBoxes = new ResultBox[width, height]; cardLabels.Clear(); starLabels.Clear(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { ResultBox clone = Instantiate(resultBoxPrefab); RectTransform rect = clone.GetComponent <RectTransform>(); rect.SetParent(rectTransform); rect.anchoredPosition = new Vector2(i * offset.x, j * offset.y); resultBoxes[i, j] = clone; clone.SetValue(10 * j + i - 30, "0"); } } for (int i = 0; i < width; i++) { ValueDisplay clone = Instantiate(cardPrefab); cardLabels.Add(cardPrefab); RectTransform rect = clone.GetComponent <RectTransform>(); rect.SetParent(rectTransform); rect.anchoredPosition = new Vector2(i * offset.x, labelsOffset.y); clone.SetValue(i + 1); } for (int i = 0; i < height; i++) { ValueDisplay clone = Instantiate(starPrefab); starLabels.Add(starPrefab); RectTransform rect = clone.GetComponent <RectTransform>(); rect.SetParent(rectTransform); rect.anchoredPosition = new Vector2(labelsOffset.x, i * offset.y); clone.SetValue(i + 1); } }
public void NewValueDisplay(string value, Sprite image) { values.Add(Instantiate(valuePrefab, self.position, Quaternion.identity, self).GetComponent <ValueDisplay>()); ValueDisplay vd = values[values.Count - 1]; /* * vd.self.anchorMin = new Vector2(0.5f, 1f); * vd.self.anchorMax = new Vector2(0.5f, 1f); * vd.self.pivot = new Vector2(0.5f, 1f); */ //vd.self.localPosition = new Vector2(0f, -vd.self.sizeDelta.y * valueCount); vd.valueImage.sprite = image; vd.valueText.text = value; requiredHeight += shiftValue + vd.self.sizeDelta.y; valueCount++; }
public override string Render(int depthLimit, int currentDepth) { var rowDataSb = new StringBuilder(); foreach (var propertyInfo in this.Metadata.Properties) { rowDataSb.Append("<tr>"); rowDataSb.AppendFormat( "<th class='member' title='{0}'>{1}</th>", propertyInfo.MemberType, propertyInfo.Name); object value = propertyInfo.GetValue(this.Metadata.SourceObject); var displayValue = ValueDisplay.DisplayValue(value, depthLimit, currentDepth); rowDataSb.Append(HtmlTag.WrapValue("td", displayValue)); rowDataSb.Append("</tr>"); } return(rowDataSb.ToString()); }
private void AdditionalValue_BindingContextChanged(object sender, EventArgs e) { ValueDisplay.SetBinding(Label.TextProperty, ValuePath); NameDisplay.Text = Text; }
public bool ConvertDisplayTypes(ValueDisplay inValueDisplay, string inStr, ref ValueDisplay outValueDisplay, ref string outStr, bool displayMsg) { bool flag = true; if (inStr == null || inStr.Length == 0) { outStr = inStr; flag = true; } else if (outStr == null) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Out String Cannot Be Null\nDeviceFormUtils\n"); flag = false; } else if (inValueDisplay == outValueDisplay) { outStr = inStr; } else { string str1 = ""; switch (inValueDisplay) { case ValueDisplay.Hex: try { str1 = inStr; break; } catch (Exception ex) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Convert The Incoming String Value From Hex\n\n{0}\n", ex.Message) + "DeviceFormUtils\n"); flag = false; break; } case ValueDisplay.Dec: try { uint bits = Convert.ToUInt32(inStr, 10); int index1 = 0; bool dataErr = false; byte[] data = new byte[4]; m_dataUtils.Load32Bits(ref data, ref index1, bits, ref dataErr, false); if (dataErr) throw new ApplicationException("Error Loading 32 Bit Value"); int num = 0; for (int index2 = data.Length - 1; index2 >= 0 && data[index2] == 0; --index2) ++num; if (num == 4) num = 3; byte[] numArray = new byte[4 - num]; Array.Copy(data, numArray, numArray.Length); for (int index2 = 0; index2 < numArray.Length; ++index2) { str1 = str1 + numArray[index2].ToString("X2"); if (index2 < numArray.Length - 1) str1 = str1 + ":"; } break; } catch (Exception ex) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Convert The Incoming String Value From Decimal\n\n{0}\n", ex.Message) + "DeviceFormUtils\n"); flag = false; break; } case ValueDisplay.Ascii: try { if (!m_dataUtils.CheckAsciiString(inStr)) throw new ApplicationException("Ascii String Value Contains Unprintable Characters"); byte[] bytesFromAsciiString = m_dataUtils.GetBytesFromAsciiString(inStr); for (int index = 0; index < bytesFromAsciiString.Length; ++index) { str1 = str1 + string.Format("{0:S}", bytesFromAsciiString[index].ToString("X2")); if (index < bytesFromAsciiString.Length - 1) str1 = str1 + ":"; } break; } catch (Exception ex) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Convert The Incoming String Value From Ascii\n\n{0}\n", ex.Message) + "DeviceFormUtils\n"); flag = false; break; } default: if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Unknown Incoming String Type #{0}\n", inValueDisplay) + "DeviceFormUtils\n"); flag = false; break; } if (flag) { string[] strArray = str1.Split(new char[] { ' ', ':' }, StringSplitOptions.RemoveEmptyEntries); foreach (string str2 in strArray) { if (str2.Length == 0) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Incoming String Conversion Missing Byte In Delimited Format\nDeviceFormUtils\n"); flag = false; break; } else if (str2.Length != 2) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Incoming String Conversion Not In Single Byte Delimited Format\nDeviceFormUtils\n"); flag = false; break; } } if (flag) { switch (outValueDisplay) { case ValueDisplay.Hex: try { outStr = str1; break; } catch (Exception ex) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Convert The Outgoing String Value To Hex\n\n{0}\n", ex.Message) + "DeviceFormUtils\n"); flag = false; break; } case ValueDisplay.Dec: try { foreach (string str2 in strArray) outStr = outStr + str2; if (strArray.Length > 4) throw new ApplicationException("Conversion String Exceeds Four Hex Bytes"); uint num1 = 0U; for (int index = 0; index < strArray.Length; ++index) num1 += (uint)Convert.ToByte(strArray[index], 16) << (8 * index); outStr = string.Format("{0:D}", num1); Convert.ToUInt32(outStr, 10); break; } catch (Exception ex) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Convert The Outgoing String Value To Decimal\n\n{0}\n", ex.Message) + "DeviceFormUtils\n"); flag = false; break; } case ValueDisplay.Ascii: try { foreach (string str2 in strArray) outStr += string.Format("{0:S}", Convert.ToChar(Convert.ToByte(str2, 16)).ToString()); if (!m_dataUtils.CheckAsciiString(outStr)) throw new ApplicationException("Ascii String Value Contains Unprintable Characters"); else break; } catch (Exception ex) { if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Convert The Outgoing String Value To Ascii\n\n{0}\n", ex.Message) + "DeviceFormUtils\n"); flag = false; break; } default: if (displayMsg) m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Unknown Out String Type #{0}\n", outValueDisplay) + "DeviceFormUtils\n"); flag = false; break; } } } } if (outStr != null && !flag) { outStr = inStr; outValueDisplay = inValueDisplay; } return flag; }
private void cbDataType_SelectedIndexChanged(object sender, EventArgs e) { formDataAccess.WaitOne(); ComboBox comboBox = sender as ComboBox; string outStr = string.Empty; ValueDisplay outValueDisplay = (ValueDisplay)comboBox.SelectedIndex; bool flag = devUtils.ConvertDisplayTypes(lastValueDisplay, tbValue.Text, ref outValueDisplay, ref outStr, true); comboBox.SelectedIndex = (int)outValueDisplay; if (flag) { lastValueDisplay = (ValueDisplay)comboBox.SelectedIndex; lastValueDisplaySet = true; } else comboBox.SelectedIndex = (int)lastValueDisplay; tbValue.Text = outStr; formDataAccess.ReleaseMutex(); }
public void LoadData(string dataKey) { if (InvokeRequired) { try { Invoke((Delegate)new AttrDataItemForm.LoadDataDelegate(LoadData), dataKey); } catch { } } else { formDataAccess.WaitOne(); key = dataKey; dataAttr = new DataAttr(); bool dataChanged = false; if (attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, key, "LoadData")) { if (dataChanged) { tbConnHnd.Text = "0x" + dataAttr.ConnHandle.ToString("X4"); tbHandle.Text = "0x" + dataAttr.Handle.ToString("X4"); if (dataAttr.UuidHex != string.Empty && dataAttr.UuidHex != null) tbUuid.Text = "0x" + dataAttr.UuidHex; tbUuidDesc.Text = dataAttr.UuidDesc; string outStr = string.Empty; if (lastValueDisplaySet) { devUtils.ConvertDisplayTypes(ValueDisplay.Hex, dataAttr.Value, ref lastValueDisplay, ref outStr, false); } else { devUtils.ConvertDisplayTypes(ValueDisplay.Hex, dataAttr.Value, ref dataAttr.ValueDisplay, ref outStr, false); lastValueDisplay = dataAttr.ValueDisplay; lastValueDisplaySet = true; cbDataType.SelectedIndex = (int)lastValueDisplay; } tbValue.Text = outStr; tbValueDesc.Text = dataAttr.ValueDesc; tbProperties.Text = dataAttr.PropertiesStr; bool flag = false; if (dataAttr.PropertiesStr != null && dataAttr.PropertiesStr != string.Empty) { flag = true; Color green = Color.Green; Color red = Color.Red; if ((dataAttr.Properties & 0x01) == 0x01) lblBroadcast.ForeColor = green; else lblBroadcast.ForeColor = red; if ((dataAttr.Properties & 0x02) == 0x02) lblRead.ForeColor = green; else lblRead.ForeColor = red; if ((dataAttr.Properties & 0x04) == 0x04) lblWriteWithoutResponse.ForeColor = green; else lblWriteWithoutResponse.ForeColor = red; if ((dataAttr.Properties & 0x08) == 0x08) lblWrite.ForeColor = green; else lblWrite.ForeColor = red; if ((dataAttr.Properties & 0x10) == 0x10) lblNotify.ForeColor = green; else lblNotify.ForeColor = red; if ((dataAttr.Properties & 0x20) == 0x20) lblIndicate.ForeColor = green; else lblIndicate.ForeColor = red; if ((dataAttr.Properties & 0x40) == 0x40) lblAuthenticatedSignedWrites.ForeColor = green; else lblAuthenticatedSignedWrites.ForeColor = red; if ((dataAttr.Properties & 0x80) == 0x80) lblExtendedProperties.ForeColor = green; else lblExtendedProperties.ForeColor = red; } gbProperties.Enabled = flag; tbProperties.Enabled = flag; lblProperties.Enabled = flag; lblBroadcast.Enabled = flag; lblRead.Enabled = flag; lblWriteWithoutResponse.Enabled = flag; lblWrite.Enabled = flag; lblNotify.Enabled = flag; lblIndicate.Enabled = flag; lblAuthenticatedSignedWrites.Enabled = flag; lblExtendedProperties.Enabled = flag; } if (dataAttr.ValueEdit == ValueEdit.ReadOnly) { btnWriteValue.Enabled = false; tbValue.ReadOnly = true; } else { btnWriteValue.Enabled = true; tbValue.ReadOnly = false; } if (!lastValueDisplaySet) cbDataType.SelectedIndex = (int)dataAttr.ValueDisplay; } formDataAccess.ReleaseMutex(); } }