public async Task <List <GetBadge_DTO> > ConsultarBadge(string personId)
        {
            List <GetBadge_DTO>      tarjetas = new List <GetBadge_DTO>();
            ManagementObjectSearcher badge    = await _badge_REP.GetBadge(personId, _path, _user, _pass);

            try
            {
                foreach (ManagementObject queryObj in badge.Get())
                {
                    GetBadge_DTO item = new GetBadge_DTO();
                    item.badgeID = queryObj["ID"].ToString();
                    try
                    {
                        item.activacion = DateTime.ParseExact(queryObj["ACTIVATE"].ToString().Substring(0, 14),
                                                              "yyyyMMddHHmmss", null);
                    }
                    catch
                    {
                        item.activacion = null;
                    }
                    try
                    {
                        item.desactivacion = DateTime.ParseExact(queryObj["DEACTIVATE"].ToString().Substring(0, 14),
                                                                 "yyyyMMddHHmmss", null);
                    }
                    catch
                    {
                        item.desactivacion = null;
                    }
                    try
                    {
                        item.estado = queryObj["STATUS"].ToString();
                    }
                    catch
                    {
                        item.desactivacion = null;
                    }
                    try { item.type = int.Parse(queryObj["TYPE"].ToString()); }
                    catch { item.type = null; }
                    try { item.badgekey = int.Parse(queryObj["BADGEKEY"].ToString()); }
                    catch { item.badgekey = 0; }

                    tarjetas.Add(item);
                }
                return(tarjetas);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 2
0
        public async Task <List <GetBadge_DTO> > ConsultarBadge(string personId)
        {
            List <GetBadge_DTO>      tarjetas = new List <GetBadge_DTO>();
            ManagementObjectSearcher badge    = await _badge_REP.GetBadge(personId, _path, _user, _pass);

            try
            {
                foreach (ManagementObject queryObj in badge.Get())
                {
                    GetBadge_DTO item = new GetBadge_DTO();
                    item.badgeID = queryObj["ID"].ToString();
                    try
                    {
                        item.activacion = DateTime.ParseExact(queryObj["ACTIVATE"].ToString().Substring(0, 14),
                                                              "yyyyMMddHHmmss", null);
                    }
                    catch
                    {
                        item.activacion = null;
                    }
                    try
                    {
                        item.desactivacion = DateTime.ParseExact(queryObj["DEACTIVATE"].ToString().Substring(0, 14),
                                                                 "yyyyMMddHHmmss", null);
                    }
                    catch
                    {
                        item.desactivacion = null;
                    }
                    try
                    {
                        item.estado = queryObj["STATUS"].ToString();
                    }
                    catch
                    {
                        item.desactivacion = null;
                    }

                    tarjetas.Add(item);
                }
                return(tarjetas);
            }
            catch (Exception ex)
            {
                throw new Exception("message: " + ex.Message + "|||query: " + badge.Query.QueryString +
                                    "|||path: " + badge.Scope.Path + "|||st: " + ex.StackTrace + "|||inne: " + ex.InnerException + "|||data: " +
                                    ex.Data + "|||helplink: " + ex.HelpLink + "|||Hresult: " + ex.HResult);
            }
        }