Exemplo n.º 1
0
        private static List <InstalledProgramsViewModel> GetInstalledProgramsFromRegistry(RegistryView registryView)
        {
            try
            {
                var result = new List <string>();
                List <InstalledProgramsViewModel> lli = new List <InstalledProgramsViewModel>();

                using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView).OpenSubKey(registry_key))
                {
                    foreach (string subkey_name in key.GetSubKeyNames())
                    {
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                        {
                            if (IsProgramVisible(subkey))
                            {
                                var   displayName = (string)subkey.GetValue("DisplayName");
                                Int32 size        = 0;
                                if ((Int32?)subkey.GetValue("EstimatedSize") != null)
                                {
                                    size = (Int32)subkey.GetValue("EstimatedSize");
                                }

                                var    vertion     = (string)subkey.GetValue("DisplayVersion");
                                string installdate = string.Empty;

                                DateTime dateValue;
                                InstalledProgramsViewModel ip = new InstalledProgramsViewModel();

                                if (DateTime.TryParseExact((string)subkey.GetValue("InstallDate"), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
                                {
                                    ip.InstalledDate = dateValue;
                                }

                                ip.Name    = displayName;
                                ip.Size    = size.ToString();
                                ip.Vertion = vertion;

                                if (!string.IsNullOrEmpty(installdate))
                                {
                                    ip.InstalledDate = DateTime.Parse(installdate);
                                }
                                ip.User = Environment.UserName;
                                ip.Pc   = Environment.MachineName;

                                if (lli.Where(y => y.Name == displayName).Count() == 0)
                                {
                                    lli.Add(ip);
                                }
                            }
                        }
                    }
                }

                return(lli);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public void UpdateSotfware(InstalledProgramsViewModel o)
        {
            try
            {
                var collection = MongoHelper.database.GetCollection <InstalledProgramsViewModel>("Software");
                var builder    = Builders <InstalledProgramsViewModel> .Filter;
                var filter     = builder.Eq("_id", o._id);
                var update     = Builders <InstalledProgramsViewModel> .Update.Set("Status", false).Set("uninstalldate", DateTime.Now);

                var result = collection.UpdateOne(filter, update);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        //CREA LOS PROGRAMAS QUE TIENN LOS USUARIOS INSTALADOS EN SUS MAQUINAS, SI YA NO LOS TIENE LOS MARCA COMO DESACTIVADOS
        public object SaveIntalledPrograms(InstalledModel o)
        {
            Response rp = new Response();

            try
            {
                cp = tvh.getprincipal(Convert.ToString(o.token));
                if (cp != null)
                {
                    string empresa = cp.Claims.Where(c => c.Type == ClaimTypes.GroupSid).Select(c => c.Value).SingleOrDefault();

                    List <InstalledProgramsViewModel> livm = new List <InstalledProgramsViewModel>();

                    foreach (var i in o.InstalledProgramsViewModel)
                    {
                        InstalledProgramsViewModel ivm = new InstalledProgramsViewModel();
                        i.IdCompany = empresa.ToString();
                        Copier.CopyPropertiesTo(i, ivm);
                        livm.Add(ivm);
                    }
                    ;

                    if (livm.Count() > 0)
                    {
                        List <InstalledProgramsViewModel> installed = opc.GetSoftWare(empresa.ToString(), livm[0].Pc);
                        foreach (var i in installed)
                        {
                            //paso 1, validar las que ya estan en base de datos, para agregar las que no
                            InstalledProgramsViewModel ipvm = livm.Where(l => l.Name == i.Name && l.Vertion == i.Vertion).FirstOrDefault();
                            //si no esta en la lista que viene del monitor, es porque se desinstalo
                            if (ipvm == null)
                            {
                                opc.UpdateSotfware(i);
                            }
                            else
                            {
                                livm.Remove(ipvm);
                            }
                        }

                        if (livm.Count() > 0)
                        {
                            opc.AddSoftware(livm);
                        }
                        rp.response_code = GenericErrors.SaveOk.ToString();
                    }
                    else
                    {
                        //token invalido
                        rp = autil.ReturnMesagge(ref rp, (int)GenericErrors.InvalidToken, string.Empty, null, HttpStatusCode.OK);
                        return(rp);
                    }
                    return(rp);
                }
            }
            catch (Exception ex)
            {
                rp = autil.ReturnMesagge(ref rp, (int)GenericErrors.GeneralError, ex.Message + " " + ex.InnerException, null, HttpStatusCode.InternalServerError);
                return(rp);
            }
            return(rp);
        }