Example #1
0
        /// <summary>
        /// Maps a <see cref='Altask.Data.Model.AssetAlert'/> object to a <see cref='Altask.Data.Dto.AssetAlert'/> object.
        /// </summary>
        public static Altask.Data.Dto.AssetAlert ToDto(this Altask.Data.Model.AssetAlert entity)
        {
            var dto = new Altask.Data.Dto.AssetAlert();

            dto.Id             = entity.Id;
            dto.Active         = entity.Active;
            dto.AssetId        = entity.AssetId;
            dto.AssetLogTypeId = entity.AssetLogTypeId;
            dto.Name           = entity.Name;
            dto.Metadata       = JsonConvert.DeserializeObject("{Properties: []}");

            if (!string.IsNullOrEmpty(entity.Metadata))
            {
                try {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(entity.Metadata);
                    string json = Json.SerizlieXmlDocument(doc);
                    dto.Metadata = JsonConvert.DeserializeObject(json);
                } catch (Exception) {}
            }

            dto.CreatedBy = entity.CreatedBy;
            dto.CreatedOn = entity.CreatedOn;
            dto.UpdatedBy = entity.UpdatedBy;
            dto.UpdatedOn = entity.UpdatedOn;

            dto.Users = new List <Altask.Data.Dto.AssetAlertUser>();

            if (entity.Users != null)
            {
                foreach (var item in entity.Users)
                {
                    dto.Users.Add(item.ToDto());
                }
            }

            if (entity.LogType != null)
            {
                dto.LogType = entity.LogType.ToDto();
            }

            return(dto);
        }
Example #2
0
        internal static void NotifyAssetAlertUpdate(Guid?clientId, Altask.Data.Dto.AssetAlert assetAlert)
        {
            if (!clientId.HasValue)
            {
                _context.Clients.All.notifyAssetAlertUpdate(new { assetAlert = assetAlert });
            }
            else
            {
                SignalRConnection connection;

                if (_connections.TryGetValue(clientId.Value, out connection))
                {
                    _context.Clients.AllExcept(connection.ConnectionId).notifyAssetAlertUpdate(new { connection = connection, assetAlert = assetAlert });
                }
                else
                {
                    _context.Clients.All.notifyAssetAlertCreate(new { assetAlert = assetAlert });
                }
            }
        }
Example #3
0
        /// <summary>
        /// Maps all the non-primary key and tracking properties of a <see cref='Altask.Data.Dto.AssetAlert'/> object to a <see cref='Altask.Data.Model.AssetAlert'/> object.
        /// </summary>
        public static Altask.Data.Model.AssetAlert FromDto(this Altask.Data.Model.AssetAlert model, Altask.Data.Dto.AssetAlert entity)
        {
            model.Active         = entity.Active;
            model.AssetId        = entity.AssetId;
            model.AssetLogTypeId = entity.AssetLogTypeId;
            model.Name           = entity.Name;
            model.Metadata       = string.Empty;

            try {
                model.Metadata = ((XmlDocument)JsonConvert.DeserializeXmlNode(entity.Metadata.ToString(), "Properties")).OuterXml;
            } catch (Exception) {}

            return(model);
        }