public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode) { _channels.Clear(); _channels.AddRange(executableObject.FullChannels); _setupData = setupData; _setupNode = setupNode; if (_setupNode.Attributes != null) { _startChannel = Convert.ToInt32(_setupNode.Attributes["from"].Value) - 1; } setupData.GetBytes(_setupNode, "BackgroundImage", new byte[0]); }
/// <summary> /// The load data from setup node. /// </summary> private void LoadDataFromSetupNode() { // get the attribute collection and the from/to attributes if available var setupNodeAttributes = this._setupNode.Attributes; var fromAttribute = setupNodeAttributes.GetNamedItem("from"); var toAttribute = setupNodeAttributes.GetNamedItem("to"); var imageData = _setupData.GetBytes(_setupNode, "BackgroundImage", new byte[0]); if (imageData.Length > 0) { var decoder = new JpegBitmapDecoder(new MemoryStream(imageData), BitmapCreateOptions.None, BitmapCacheOption.OnLoad); _background = decoder.Frames[0]; } else { _background = null; } // if we got both attributes, try and parse them if (fromAttribute != null && toAttribute != null) { // try to parse both attributes this._pluginChannelsFrom = fromAttribute.Value.TryParseInt32(0); this._pluginChannelsTo = toAttribute.Value.TryParseInt32(0); // if either is zero, make both zero to indicate not setup if (this._pluginChannelsFrom == 0 || this._pluginChannelsTo == 0) { this._pluginChannelsFrom = 0; this._pluginChannelsTo = 0; } } var heightAttribute = setupNodeAttributes.GetNamedItem("displayHeight"); var widthAttribute = setupNodeAttributes.GetNamedItem("displayWidth"); if (widthAttribute != null && heightAttribute != null) { _displayHeight = heightAttribute.Value.TryParseInt32(0); _displayWidth = widthAttribute.Value.TryParseInt32(0); } this._elements.Clear(); foreach (XmlNode node in this._setupNode.ChildNodes) { var attributes = node.Attributes; if (attributes == null || attributes.Count == 0) { continue; } var columns = attributes.GetNamedItem("Columns").Value.TryParseInt32(0); var rows = attributes.GetNamedItem("Rows").Value.TryParseInt32(0); var height = attributes.GetNamedItem("Height").Value.TryParseInt32(0); var width = attributes.GetNamedItem("Width").Value.TryParseInt32(0); var topOffset = attributes.GetNamedItem("TopOffset").Value.TryParseInt32(0); var leftOffset = attributes.GetNamedItem("LeftOffset").Value.TryParseInt32(0); var item = attributes.GetNamedItem("IsUnlocked"); var isUnlocked = item == null ? true : bool.Parse(item.Value); var mappedChannels = new List <PixelMapping>(); foreach (XmlNode mappedNode in node.ChildNodes) { IPixel pixel; var channelNode = mappedNode.FirstChild; if (channelNode == null) { pixel = new EmptyPixel(); } else { var type = channelNode.Attributes.GetNamedItem("Type").Value; switch (type) { case "Single": var channelIdValue = channelNode.GetAttributeValue("ChannelId"); var channelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; var color = (Color) ColorConverter.ConvertFromString(channelNode.Attributes.GetNamedItem("Color").Value); pixel = new SingleColorPixel( this._channels.FirstOrDefault(x => x.Name == channelId), color); break; case "RGB": channelIdValue = channelNode.GetAttributeValue("RedChannel"); var redChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; var redChannel = this._channels.FirstOrDefault(x => x.Name == redChannelId); channelIdValue = channelNode.GetAttributeValue("GreenChannel"); var blueChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; var greenChannel = this._channels.FirstOrDefault(x => x.Name == blueChannelId); channelIdValue = channelNode.GetAttributeValue("BlueChannel"); var greenChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; var blueChannel = this._channels.FirstOrDefault(x => x.Name == greenChannelId); pixel = new RedGreenBluePixel(redChannel, greenChannel, blueChannel); break; case "RGBW": channelIdValue = channelNode.GetAttributeValue("RedChannel"); redChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; redChannel = this._channels.FirstOrDefault(x => x.Name == redChannelId); channelIdValue = channelNode.GetAttributeValue("GreenChannel"); blueChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; greenChannel = this._channels.FirstOrDefault(x => x.Name == blueChannelId); channelIdValue = channelNode.GetAttributeValue("BlueChannel"); greenChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; blueChannel = this._channels.FirstOrDefault(x => x.Name == greenChannelId); channelIdValue = channelNode.GetAttributeValue("WhiteChannel"); var whiteChannelId = string.IsNullOrEmpty(channelIdValue) ? string.Empty : channelIdValue; var whiteChannel = this._channels.FirstOrDefault(x => x.Name == whiteChannelId); pixel = new RedGreenBlueWhitePixel(redChannel, greenChannel, blueChannel, whiteChannel); break; default: pixel = new EmptyPixel(); break; } } var mappedChannel = new PixelMapping(pixel); mappedChannels.Add(mappedChannel); } var displayElement = new DisplayElement( columns, rows, height, leftOffset, topOffset, width, mappedChannels, isUnlocked) { Name = attributes.GetNamedItem("Name").Value }; this._elements.Add(displayElement); } }