public void AddBlobVector(IBlobVector v) { IBlobVector vector = GetBlobVector(v.Name); if (vector != null) { GetBlobVector(v.Name).Change(v); return; } Blobs.Add(v); }
public virtual void isNewBlob(Object sender, IsNewBlobEventArgs e) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); if (e.Device == Name) { IBlobVector v = GetBlobVector(e.Vector.Name); if (v == null) { AddBlobVector(e.Vector); } } }
public INDIBlob GetBlob(string vector, string name) { IBlobVector v = GetBlobVector(vector); if (v != null) { for (Int32 i = 0; i < v.Values.Count; i++) { if (v.Values[i].Name == name) { return(v.Values[i]); } } } return(null); }
public string SetBlob(string vector, string name, byte[] value) { IBlobVector v = GetBlobVector(vector); if (v == null) { throw new ArgumentException(); } byte[][] values = new byte[v.Values.Count][]; for (Int32 i = 0; i < values.Length; i++) { if (v.Values[i].Name == name) { values[i] = value; } else { values[i] = v.Values[i].value; } } return(SetBlobVector(vector, values)); }
public void Change(IBlobVector v) { base.Change(v); Values = v.Values; }
bool ParseXML(String xml) { string action = ""; string target = ""; string device = ""; string name = ""; string label = ""; string vectorname = ""; string vectorlabel = ""; string group = ""; string permission = ""; string rule = ""; string format = ""; string length = ""; string minimum = ""; string maximum = ""; string step = ""; IBlobVector blobvector = new IBlobVector("", "", "", "", "", "", null); List <INDIBlob> blobs = new List <INDIBlob> (); ISwitchVector switchvector = new ISwitchVector("", "", "", "", "", "", null); List <INDISwitch> switches = new List <INDISwitch> (); INumberVector numbervector = new INumberVector("", "", "", "", "", "", null); List <INDINumber> numbers = new List <INDINumber> (); ITextVector textvector = new ITextVector("", "", "", "", "", "", null); List <INDIText> texts = new List <INDIText> (); try { XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader reader = XmlReader.Create(new StringReader(RemoveInvalidXmlChars(xml)), settings); while (reader.Read()) { try { switch (reader.NodeType) { case XmlNodeType.Element: action = reader.Name.ToLower().Substring(0, 3); target = reader.Name.Substring(3, reader.Name.Length - 3).ToLower(); action = action == null ? "" : action; target = target == null ? "" : target; if (action == "mes") { try { if (IsNewMessage != null) { IsNewMessage(this, new IsNewMessageEventArgs(reader.GetAttribute("message"), DateTime.Parse(reader.GetAttribute("timestamp")), reader.GetAttribute("device"))); } } catch { } } if (action == "del" && target.Contains("property")) { try { if (IsDelProperty != null && name != "") { IsDelProperty(this, new IsDelPropertyEventArgs(name, reader.GetAttribute("device"))); } } catch { } } if (action == "get" && target.Contains("properties")) { try { DefineProperties(reader.GetAttribute("device")); } catch { } } if (target.Contains("vector")) { device = reader.GetAttribute("device"); vectorname = reader.GetAttribute("name"); vectorlabel = reader.GetAttribute("label"); group = reader.GetAttribute("group"); permission = reader.GetAttribute("perm"); rule = reader.GetAttribute("rule"); device = device == null ? "" : device; vectorname = vectorname == null ? "" : vectorname; vectorlabel = vectorlabel == null ? "" : vectorlabel; group = group == null ? "" : group; permission = permission == null ? "ro" : permission; rule = rule == null ? "" : rule; if (device == "" || vectorname == "") { break; } AddDevice(new INDIDevice(device, this)); if (target.Contains("blob")) { blobs = new List <INDIBlob> (); blobvector = GetDevice(device).GetBlobVector(vectorname); if (blobvector == null) { blobvector = new IBlobVector(device, vectorname, vectorlabel, group, permission, rule, blobs); } blobvector.Values = blobs; } if (target.Contains("switch")) { switches = new List <INDISwitch> (); switchvector = GetDevice(device).GetSwitchVector(vectorname); if (switchvector == null) { switchvector = new ISwitchVector(device, vectorname, vectorlabel, group, permission, rule, switches); } switchvector.Values = switches; } if (target.Contains("number")) { numbers = new List <INDINumber> (); numbervector = GetDevice(device).GetNumberVector(vectorname); if (numbervector == null) { numbervector = new INumberVector(device, vectorname, vectorlabel, group, permission, rule, numbers); } numbervector.Values = numbers; } if (target.Contains("text")) { texts = new List <INDIText> (); textvector = GetDevice(device).GetTextVector(vectorname); if (textvector == null) { textvector = new ITextVector(device, vectorname, vectorlabel, group, permission, rule, texts); } textvector.Values = texts; } } else { name = reader.GetAttribute("name"); label = reader.GetAttribute("label"); name = name == null ? "" : name; label = label == null ? "" : label; if (target.Contains("blob")) { format = reader.GetAttribute("format"); length = reader.GetAttribute("size"); format = format == null ? "" : format; length = length == null ? "1" : length; } if (target.Contains("number")) { format = reader.GetAttribute("format"); minimum = reader.GetAttribute("min"); maximum = reader.GetAttribute("max"); step = reader.GetAttribute("step"); format = format == null ? "" : format; minimum = minimum == null ? "1" : minimum; maximum = maximum == null ? "1" : maximum; step = step == null ? "1" : step; } } break; case XmlNodeType.Text: if (!target.Contains("vector")) { if (target.Contains("blob")) { try { blobs.Add(new INDIBlob(name, label, format, Convert.FromBase64String(reader.Value.Replace("\n", "")), Int32.Parse(length))); } catch { blobs.Add(new INDIBlob(name, label, format, new byte[Int32.Parse(length)], Int32.Parse(length))); } } if (target.Contains("switch")) { switches.Add(new INDISwitch(name, label, reader.Value.Replace("\n", "").Contains("On"))); } if (target.Contains("number")) { numbers.Add(new INDINumber(name, label, format, Double.Parse(minimum), Double.Parse(maximum), Double.Parse(step), Double.Parse(reader.Value.Replace("\n", "")))); } if (target.Contains("text")) { texts.Add(new INDIText(name, label, reader.Value.Replace("\n", ""))); } } break; case XmlNodeType.XmlDeclaration: Console.WriteLine("<?xml version='1.0'?>"); break; case XmlNodeType.EntityReference: Console.WriteLine(reader.Name); break; case XmlNodeType.EndElement: if (reader.Name.ToLower().Contains("vector")) { if (device == "" || vectorname == "") { break; } if (target.Contains("blob")) { if (IsNewBlob != null) { IsNewBlob(this, new IsNewBlobEventArgs(blobvector, device)); } } if (target.Contains("switch")) { if (IsNewSwitch != null) { IsNewSwitch(this, new IsNewSwitchEventArgs(switchvector, device)); } } if (target.Contains("number")) { if (IsNewNumber != null) { IsNewNumber(this, new IsNewNumberEventArgs(numbervector, device)); } } if (target.Contains("text")) { if (IsNewText != null) { IsNewText(this, new IsNewTextEventArgs(textvector, device)); } } } break; } } catch (XmlException ex) { Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); return(false); } catch (Exception ex) { Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); return(false); } } reader.Close(); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); return(false); } }
public IsNewBlobEventArgs(IBlobVector vector, string dev) { Vector = vector; Device = dev; }