internal ChannelDescriptionProperty GetProperty(string propName)
        {
            #region Validate parameters
            if (String.IsNullOrEmpty(propName))
            {
                throw new ArgumentException(nameof(propName));
            }
            #endregion

            ChannelDescriptionProperty prop = FindProperty(propName);
            if (prop == null)
            {
                throw new InvalidOperationException($"Свойство \"{propName}\" не найдено.");
            }

            return(prop);
        }
        internal void AddProperty(ChannelDescriptionProperty prop)
        {
            #region Validate parameters
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }

            if (String.IsNullOrEmpty(prop.Name))
            {
                throw new ArgumentException("Отсутствует имя свойства.", nameof(prop.Name));
            }
            #endregion

            if (_properties.Any(p => p.Name == prop.Name))
            {
                throw new InvalidOperationException($"Описание канала уже содержит свойство {prop.Name}.");
            }

            _properties.Add(prop);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="description"></param>
        public void SetDescription(ChannelDescription description)
        {
            #region Validate parameters
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }
            #endregion

            if (this.Description != null)
            {
                throw new InvalidOperationException("Описание канала уже задано.");
            }

            this.Description = description;
            this.Provider    = description.Provider;

            List <string> existProps = _properties.Select(p => p.Name).Where(prop => description.Properties.Select(p => p.Name).Contains(prop)).ToList();
            List <string> delProps   = _properties.Select(p => p.Name).Where(prop => !description.Properties.Select(p => p.Name).Contains(prop)).ToList();
            List <string> newProps   = description.Properties.Select(p => p.Name).Where(prop => !_properties.Select(p => p.Name).Contains(prop)).ToList();

            existProps.ForEach(p =>
            {
                ChannelDescriptionProperty dp = description.GetProperty(p);
                ChannelProperty prop          = GetProperty(p);
                string value = prop.Value;
                dp.CopyTo(prop);
                prop.Value = value;
            });
            delProps.ForEach(p => RemoveProperty(p));
            newProps.ForEach(p =>
            {
                ChannelDescriptionProperty dp = description.GetProperty(p);
                var prop = new ChannelProperty();
                dp.CopyTo(prop);
                AddNewProperty(prop);
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="_appSettings"></param>
        public ChannelDescription(IDictionary <string, AppConfigSetting> appSettings)
        {
            string prefix = ".";

            _addinSettings = new Dictionary <string, AppConfigSetting>(appSettings.Where(p => p.Key.StartsWith(prefix)));
            _properties    = new List <ChannelDescriptionProperty>();
            foreach (string key in appSettings.Keys.Where(k => !k.StartsWith(prefix)))
            {
                AppConfigSetting setting = appSettings[key];
                var descProp             = new ChannelDescriptionProperty()
                {
                    Comment  = setting.Comment,
                    Format   = setting.Format,
                    Default  = setting.Default,
                    Name     = setting.Name,
                    ReadOnly = setting.ReadOnly,
                    Secret   = setting.Secret,
                    Type     = setting.Type,
                    Value    = setting.Value
                };
                _properties.Add(descProp);
            }
        }