Ejemplo n.º 1
0
        internal static void NotifyAssetUpdate(Guid?clientId, Altask.Data.Dto.Asset asset)
        {
            if (!clientId.HasValue)
            {
                _context.Clients.All.notifyAssetUpdate(new { asset = asset });
            }
            else
            {
                SignalRConnection connection;

                if (_connections.TryGetValue(clientId.Value, out connection))
                {
                    _context.Clients.AllExcept(connection.ConnectionId).notifyAssetUpdate(new { connection = connection, asset = asset });
                }
                else
                {
                    _context.Clients.All.notifyAssetCreate(new { asset = asset });
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Maps all the non-primary key and tracking properties of a <see cref='Altask.Data.Dto.Asset'/> object to a <see cref='Altask.Data.Model.Asset'/> object.
        /// </summary>
        public static Altask.Data.Model.Asset FromDto(this Altask.Data.Model.Asset model, Altask.Data.Dto.Asset entity)
        {
            model.Active         = entity.Active;
            model.AssetTypeId    = entity.AssetTypeId;
            model.CustomId       = entity.CustomId;
            model.Name           = entity.Name;
            model.Description    = entity.Description;
            model.DepartmentId   = entity.DepartmentId;
            model.ManufacturerId = entity.ManufacturerId;
            model.Model          = entity.Model;
            model.Serial         = entity.Serial;
            model.Metadata       = string.Empty;

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

            return(model);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Maps a <see cref='Altask.Data.Model.Asset'/> object to a <see cref='Altask.Data.Dto.Asset'/> object.
        /// </summary>
        public static Altask.Data.Dto.Asset ToDto(this Altask.Data.Model.Asset entity)
        {
            var dto = new Altask.Data.Dto.Asset();

            dto.Id             = entity.Id;
            dto.Active         = entity.Active;
            dto.AssetTypeId    = entity.AssetTypeId;
            dto.CustomId       = entity.CustomId;
            dto.Name           = entity.Name;
            dto.Description    = entity.Description;
            dto.DepartmentId   = entity.DepartmentId;
            dto.ManufacturerId = entity.ManufacturerId;
            dto.Model          = entity.Model;
            dto.Serial         = entity.Serial;
            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;

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

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

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

            dto.Alerts = new List <Altask.Data.Dto.AssetAlert>();

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

            dto.Groups = new List <Altask.Data.Dto.AssetGrouping>();

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

            return(dto);
        }