Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new channel setting to the collection
        /// of channel settings in this monitor settings record.
        /// </summary>
        /// <param name="channelDefinition">Channel definition to use for looking up channel definition index of new channel setting.</param>
        /// <returns>New channel setting.</returns>
        public ChannelSetting AddNewChannelSetting(ChannelDefinition channelDefinition)
        {
            CollectionElement channelSettingElement = new CollectionElement()
            {
                TagOfElement = OneChannelSettingTag
            };
            ChannelSetting channelSetting = new ChannelSetting(channelSettingElement, this);

            channelSetting.ChannelDefinitionIndex = (uint)channelDefinition.DataSource.ChannelDefinitions.IndexOf(channelDefinition);

            CollectionElement?channelSettingsElement = PhysicalRecord.Body.Collection.GetCollectionByTag(ChannelSettingsArrayTag);

            if (channelSettingsElement == null)
            {
                channelSettingsElement = new CollectionElement()
                {
                    TagOfElement = OneChannelSettingTag
                };
                PhysicalRecord.Body.Collection.AddElement(channelSettingsElement);
            }

            channelSettingsElement.AddElement(channelSettingElement);

            return(channelSetting);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes the given channel setting from the collection of channel settings.
        /// </summary>
        /// <param name="channelSetting">The channel setting to be removed.</param>
        public void Remove(ChannelSetting channelSetting)
        {
            CollectionElement?channelSettingsElement = PhysicalRecord.Body.Collection.GetCollectionByTag(ChannelSettingsArrayTag);

            if (channelSettingsElement == null)
            {
                return;
            }

            List <CollectionElement> channelSettingElements = channelSettingsElement.GetElementsByTag(OneChannelSettingTag).Cast <CollectionElement>().ToList();

            foreach (CollectionElement channelSettingElement in channelSettingElements)
            {
                ChannelSetting setting = new ChannelSetting(channelSettingElement, this);

                if (Equals(channelSetting, setting))
                {
                    channelSettingsElement.RemoveElement(channelSettingElement);
                }
            }
        }