public static bool CheckStr(string name, ref string oldValue, string newValue, Device device) { if (newValue.IndexOf('<') != -1 || newValue.IndexOf('>') != -1 || (newValue.IndexOf('/') != -1 || newValue.IndexOf('"') != -1) || newValue.IndexOf('\'') != -1) { device.AddMessage(Message.ParameterError, name); return(false); } DataView dataView = ProtocolData.SelectFromDT("property='" + name + "'", device.IsNewVersion); if (dataView.Count == 0) { device.AddMessage(Message.ParameterError, name); return(false); } if (Encoding.UTF8.GetByteCount(newValue.Trim()) > (int)(sbyte)dataView[0]["maxLength"]) { device.AddMessage(Message.TooLong, name); return(false); } if (Encoding.UTF8.GetByteCount(newValue.Trim()) < (int)(sbyte)dataView[0]["minLength"]) { device.AddMessage(Message.TooShort, name); return(false); } oldValue = newValue.Trim(); return(true); }
public static void AddOptionValue(int id, string value, IPAddress ipAddr, byte controlType) { OptionListClass optionListClass = (OptionListClass)null; OptionClass optionClass1 = (OptionClass)null; for (int index = 0; index < DataListManger.SendOList.Count; ++index) { if (DataListManger.SendOList[index].IpAddr == ipAddr && (int)DataListManger.SendOList[index].ControlType == (int)controlType) { optionListClass = DataListManger.SendOList[index]; using (List <OptionClass> .Enumerator enumerator = DataListManger.SendOList[index].OptionList.GetEnumerator()) { while (enumerator.MoveNext()) { OptionClass current = enumerator.Current; if ((int)current.OptionType == id) { optionClass1 = current; break; } } break; } } } if (optionListClass == null) { optionListClass = new OptionListClass(ipAddr, controlType); DataListManger.SendOList.Add(optionListClass); } if (optionClass1 == null) { DataView dataView = ProtocolData.SelectFromDT("code=" + (object)id, true); if (dataView.Count != 1) { return; } OptionClass optionClass2 = new OptionClass(dataView[0], Encoding.Default.GetBytes(value)); optionListClass.OptionList.Add(optionClass2); } else { if (!(value != "")) { return; } string s = Encoding.Default.GetString(optionClass1.OptionData) + value; optionClass1.OptionData = Encoding.Default.GetBytes(s); optionClass1.createOption(); } }