private void PushIPXElement(IIPXElement ipxElement) { PackageHost.PushStateObject( (PackageHost.GetSettingValue <bool>("UseLabelAsStateObjectName") && ipxElement is IPXBaseElement baseElement) ? baseElement.Label : ipxElement.Id, ipxElement, metadatas: this.ipx.ElementsConfigurations?.FirstOrDefault(e => e.Id == ipxElement.Id)?.Metadatas ?? null, lifetime: (this.elementTypesToPoll != null && (this.elementTypesToPoll.ContainsKey(GetArgument.All) || this.elementTypesToPoll.Values.Any(t => ipxElement.Type == t))) ? PackageHost.GetSettingValue <int>("PollInterval") * 2 : 0); }
private void ProcessIPXResponse(JObject response) { foreach (var property in response.Properties()) { var elementType = this.ipxElementKnownTypes .Select(t => new { Match = t.Key.Match(property.Name), Type = t.Value }) .Where(t => t.Match.Success) .FirstOrDefault(); if (elementType != null) { string elementId = string.IsNullOrEmpty(elementType.Match.Groups["id"].Value) ? elementType.Match.Groups[0].Value : elementType.Match.Groups["id"].Value; IIPXElement currentElement = null; // Getting the existing element if (this.Elements.ContainsKey(elementId)) { currentElement = this.Elements[elementId]; } // Is a new element ? if (currentElement == null) { // Get the element's configuration IPXElementConfiguration elementConfiguration = this.ElementsConfigurations?.FirstOrDefault(e => e.Id == elementId); // Ignore unknown element ? if (this.ElementsConfigurations != null && elementConfiguration == null && this.IgnoreUnknownElement) { continue; // ignore it ! } else { // Create new instance for the IPX element currentElement = Activator.CreateInstance(elementType.Type.Item1) as IIPXElement; // Set ID and configure currentElement.Id = elementId; currentElement.Type = elementType.Type.Item2; if (currentElement is IPXBaseElement baseElement) { baseElement.Label = elementConfiguration?.Label ?? currentElement.Id; baseElement.Room = elementConfiguration?.Room; } currentElement.Configure(elementConfiguration); // Update the property currentElement.UpdateProperty(property.Name, property.Value); // Add the element to the current IPX and raise event this.Elements.Add(elementId, currentElement); this.ElementAdded?.Invoke(this, new IPXElementEventArgs(currentElement)); } } else { // Just update the property currentElement.UpdateProperty(property.Name, property.Value); } } } }
/// <summary> /// Initializes a new instance of the <see cref="IPXElementEventArgs"/> class. /// </summary> /// <param name="element">The element.</param> public IPXElementEventArgs(IIPXElement element) { this.Element = element; }