public static void AddNewProperty(this ChannelInfo channelInfo, ChannelInfoProperty prop)
        {
            #region Validate parameters
            if (prop == null)
            {
                throw new ArgumentNullException(nameof(prop));
            }

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

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

            if (channelInfo.Properties.ContainsKey(prop.Name))
            {
                throw new InvalidOperationException($"Канал уже содержит свойство {prop.Name}.");
            }

            prop.ChannelLINK = channelInfo.LINK;
            channelInfo.Properties.Add(prop.Name, prop);
        }
        public static void SetDescription(this ChannelInfo channelInfo, MicroserviceDescription description)
        {
            #region Validate parameters
            if (channelInfo == null)
            {
                throw new ArgumentNullException(nameof(channelInfo));
            }

            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }
            #endregion

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

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

            IDictionary <string, ChannelInfoProperty> properties = channelInfo.Properties;
            List <string> existProps = properties.Values.Select(p => p.Name).Where(prop => description.Properties.Values.Select(p => p.Name).Contains(prop)).ToList();
            List <string> delProps   = properties.Values.Select(p => p.Name).Where(prop => !description.Properties.Values.Select(p => p.Name).Contains(prop)).ToList();
            List <string> newProps   = description.Properties.Values.Select(p => p.Name).Where(prop => !properties.Values.Select(p => p.Name).Contains(prop)).ToList();

            existProps.ForEach(p =>
            {
                MicroserviceDescriptionProperty dp = description.GetProperty(p);
                ChannelInfoProperty prop           = channelInfo.GetProperty(p);
                string value = prop.Value;
                dp.CopyTo(prop);
                prop.Value = value;
            });
            delProps.ForEach(p => channelInfo.RemoveProperty(p));
            newProps.ForEach(p =>
            {
                MicroserviceDescriptionProperty dp = description.GetProperty(p);
                var prop = new ChannelInfoProperty();
                dp.CopyTo(prop);
                channelInfo.AddNewProperty(prop);
            });
        }
Example #3
0
        public static ChannelInfoProperty ToObj(this DAO.ChannelProperty dao)
        {
            if (dao == null)
            {
                return(null);
            }

            var obj = new ChannelInfoProperty();

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

            var dao = new DAO.ChannelProperty();

            dao.Channel      = channel;
            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);
        }
Example #5
0
 public static AppConfigSetting ToAppConfigSetting(this ChannelInfoProperty property)
 {
     return(mapper.Map <ChannelInfoProperty, AppConfigSetting>(property));
 }