Beispiel #1
0
        /// <summary>
        /// Converts this instance of <see cref="PlatformModule"/> to an instance of <see cref="PlatformModuleDTO"/>.
        /// </summary>
        /// <param name="entity"><see cref="PlatformModule"/> to convert.</param>
        public static PlatformModuleDTO ToDTO(this PlatformModule entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var dto = new PlatformModuleDTO();

            dto.Name               = entity.Name;
            dto.IsEnabled          = entity.IsEnabled;
            dto.AdsPort            = entity.AdsPort;
            dto.PathRootController = entity.PathRootController;
            dto.MaxCapacity        = entity.MaxCapacity;

            dto.State      = entity.State;
            dto.SubState   = entity.SubState;
            dto.StreamType = entity.StreamType;

            if (entity.Entities != null)
            {
                dto.PlatformItems = entity.Entities.PlatformItems.ToList().ToDTOs();
            }
            else
            {
                dto.PlatformItems = new List <PlatformItemDTO>();
            }

            dto.Type = entity.ModuleTypeId;

            dto.MaxCapacity = entity.LimitItemCount > 0 ? entity.LimitItemCount : entity.MaxCapacity;

            dto.HasErrors   = entity.AlarmManager.HasErrors;
            dto.HasWarnings = entity.AlarmManager.HasWarnings;

            // set the most important alarm, first error, if that doesn't exist warning, and if that doesn't exist to an empty string
            var alarm = entity.AlarmManager.CurrentAlarms.FirstOrDefault(a => a.Type == AlarmType.Error) ??
                        entity.AlarmManager.CurrentAlarms.FirstOrDefault(a => a.Type == AlarmType.Warning);

            dto.MostImportantAlarmText = alarm != null ? alarm.Message : string.Empty;

            return(dto);
        }
Beispiel #2
0
        /// <summary>
        /// Converts this instance of <see cref="PlatformModuleDTO"/> to an instance of <see cref="PlatformModule"/>.
        /// </summary>
        /// <param name="dto"><see cref="PlatformModuleDTO"/> to convert.</param>
        public static PlatformModule ToEntity(this PlatformModuleDTO dto)
        {
            if (dto == null)
            {
                return(null);
            }

            var entity = new PlatformModule();

            entity.Name               = dto.Name;
            entity.IsEnabled          = dto.IsEnabled;
            entity.AdsPort            = dto.AdsPort;
            entity.PathRootController = dto.PathRootController;
            entity.MaxCapacity        = dto.MaxCapacity;

            entity.State                  = dto.State;
            entity.SubState               = dto.SubState;
            entity.StreamType             = dto.StreamType;
            entity.Entities.PlatformItems = dto.PlatformItems.ToEntities();

            return(entity);
        }