Beispiel #1
0
        /// <summary>
        /// Добавление нового св-ва.
        /// </summary>
        /// <param name="prop"></param>
        public void AddNewProperty(ChannelProperty prop)
        {
            #region Validate parameters
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }

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

            if (prop.LINK != 0)
            {
                throw new ArgumentException("Свойство должно иметь LINK = 0.", "prop");
            }
            #endregion

            if (_properties.Any(p => p.Name == prop.Name))
            {
                throw new InvalidOperationException(String.Format("Канал уже содержит свойство {0}.", prop.Name));
            }

            prop.ChannelLINK = this.LINK;
            _properties.Add(prop);
        }
        /// <summary>
        /// Сравнение объектов по Name.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            ChannelProperty prop = obj as ChannelProperty;

            if (prop == null)
            {
                return(false);
            }

            return(this.Name == prop.Name);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propName"></param>
        public void RemoveProperty(string propName)
        {
            #region Validate parameters
            if (String.IsNullOrEmpty(propName))
            {
                throw new ArgumentException("propName");
            }
            #endregion

            ChannelProperty prop = FindProperty(propName);
            if (prop != null)
            {
                _properties.Remove(prop);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="propName"></param>
        /// <returns></returns>
        protected virtual string PropertyValue(string propName)
        {
            if (_properties != null)
            {
                ChannelProperty prop = _properties.SingleOrDefault(p => p.Name == propName);
                if (prop == null)
                {
                    return(null);
                }

                return(prop.Value);
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propName"></param>
        /// <param name="value"></param>
        public void UpdateProperty(string propName, string value)
        {
            #region Validate parameters
            if (String.IsNullOrEmpty(propName))
            {
                throw new ArgumentException("propName");
            }
            #endregion

            ChannelProperty prop = GetProperty(propName);
            if (prop.ReadOnly)
            {
                throw new InvalidOperationException(String.Format("Свойство \"{0}\" только для чтения.", propName));
            }

            prop.Value = value;
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propName"></param>
        /// <returns></returns>
        public ChannelProperty GetProperty(string propName)
        {
            #region Validate parameters
            if (String.IsNullOrEmpty(propName))
            {
                throw new ArgumentException("propName");
            }
            #endregion

            ChannelProperty prop = FindProperty(propName);
            if (prop == null)
            {
                throw new InvalidOperationException(String.Format("Свойство \"{0}\" не найдено.", propName));
            }

            return(prop);
        }
Beispiel #7
0
        public static ChannelProperty ToObj(this DAO.ChannelProperty dao)
        {
            if (dao == null)
            {
                return(null);
            }

            var obj = new ChannelProperty();

            obj.ChannelLINK  = dao.Channel.LINK;
            obj.Comment      = dao.Comment;
            obj.DefaultValue = dao.DefaultValue;
            obj.Format       = dao.Format;
            obj.LINK         = dao.LINK;
            obj.Name         = dao.Name;
            obj.ReadOnly     = (dao.ReadOnly == null ? false : dao.ReadOnly.Value);
            obj.Secret       = (dao.Secret == null ? false : dao.Secret.Value);
            obj.Type         = dao.Type;
            obj.Value        = dao.Value;

            return(obj);
        }
Beispiel #8
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);
            });
        }
Beispiel #9
0
        public static DAO.ChannelProperty ToDao(this ChannelProperty obj, DAO.ChannelInfo channel)
        {
            if (obj == null)
            {
                return(null);
            }

            var dao = new DAO.ChannelProperty();

            dao.Channel = channel;
            //dao.ChannelLINK = obj.ChannelLINK;
            dao.Comment      = (String.IsNullOrEmpty(obj.Comment) ? null : obj.Comment);
            dao.DefaultValue = obj.DefaultValue;
            dao.Format       = (String.IsNullOrEmpty(obj.Format) ? null : obj.Format);
            dao.LINK         = obj.LINK;
            dao.Name         = obj.Name;
            dao.ReadOnly     = (obj.ReadOnly == false ? new Nullable <bool>() : obj.ReadOnly);
            dao.Secret       = (obj.Secret == false ? new Nullable <bool>() : obj.Secret);
            dao.Type         = (String.IsNullOrEmpty(obj.Type) ? null : obj.Type);
            dao.Value        = obj.Value;

            return(dao);
        }