コード例 #1
0
ファイル: Ambiente.cs プロジェクト: radtek/winperupdate
        public Ambiente()
        {
            InitializeComponent();

            cmbPerfil.DropDownStyle = ComboBoxStyle.DropDownList;

            try
            {
                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate");

                txtNroLicencia.Text = key.GetValue("Licencia").ToString();
                string ambientes = key.GetValue("Ambientes").ToString();
                string perfil    = key.GetValue("Perfil").ToString();
                key.Close();

                string server = Utils.GetSetting("server");
                string port   = Utils.GetSetting("port");

                var    cliente = new ClienteBo();
                string json    = Utils.StrSendMsg(server, int.Parse(port), "checklicencia#" + txtNroLicencia.Text + "#");
                cliente = JsonConvert.DeserializeObject <ClienteBo>(json);

                if (cliente != null)
                {
                    var lista = new List <AmbienteBo>();
                    json  = Utils.StrSendMsg(server, int.Parse(port), "ambientes#" + cliente.Id + "#");
                    lista = JsonConvert.DeserializeObject <List <AmbienteBo> >(json);
                    if (lista != null)
                    {
                        dgAmbientes.Rows.Clear();

                        foreach (var item in lista)
                        {
                            Microsoft.Win32.RegistryKey keyv = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate\" + item.Nombre);

                            try
                            {
                                string directorio = keyv.GetValue("DirWinper").ToString();
                                dgAmbientes.Rows.Add(item.idAmbientes, item.Nombre, directorio);
                                keyv.Close();
                            }
                            catch (Exception)
                            {
                                dgAmbientes.Rows.Add(item.idAmbientes, item.Nombre, "");
                            }
                        }
                    }

                    int index = cmbPerfil.FindString(perfil);
                    cmbPerfil.SelectedIndex = index;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utils.RegistrarLog("Ambiente.log", ex.ToString());
            }
        }
コード例 #2
0
ファイル: FormPrincipal.cs プロジェクト: radtek/winperupdate
        private void Ambiente_Click(object sender, EventArgs e)
        {
            if (Utils.blockMenu)
            {
                MessageBox.Show("Está corriendo un proceso de instalación en estos momentos, debe esperar a que finalice y vuelva a intentarlo", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //throw new NotImplementedException();
            var form = new Ambiente();

            form.ShowDialog();

            try
            {
                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate");
                string nroLicencia = key.GetValue("Licencia").ToString();
                string ambientecfg = key.GetValue("Ambientes").ToString();
                key.Close();

                if (!string.IsNullOrEmpty(nroLicencia))
                {
                    string server = Utils.GetSetting("server");
                    string port   = Utils.GetSetting("port");

                    try
                    {
                        string json = Utils.StrSendMsg(server, int.Parse(port), "checklicencia#" + nroLicencia + "#");
                        cliente = JsonConvert.DeserializeObject <ClienteBo>(json);
                        if (cliente != null)
                        {
                            json = Utils.StrSendMsg(server, int.Parse(port), "ambientes#" + cliente.Id.ToString() + "#");
                            foreach (var ambiente in JsonConvert.DeserializeObject <List <AmbienteBo> >(json))
                            {
                                if (ambientecfg.Contains(ambiente.Nombre))
                                {
                                    ambientes.Add(ambiente);
                                }
                            }
                            ContextMenu1.MenuItems[0].Enabled     = true;
                            ContextMenu1.MenuItems[2].DefaultItem = false;
                            ContextMenu1.MenuItems[0].DefaultItem = true;
                            timer1.Start();
                        }
                    }
                    catch (Exception)
                    {
                        ContextMenu1.MenuItems[0].Enabled = false;
                        ContextMenu1.MenuItems[1].Enabled = false;
                        MessageBox.Show("WinAct no tiene conexión con el servidor central");
                    }
                }
            }
            catch (Exception) { };
        }
コード例 #3
0
ファイル: Ambiente.cs プロジェクト: radtek/winperupdate
        private void txtNroLicencia_Leave(object sender, EventArgs e)
        {
            string server = Utils.GetSetting("server");
            string port   = Utils.GetSetting("port");

            try
            {
                var    cliente = new ClienteBo();
                string json    = Utils.StrSendMsg(server, int.Parse(port), "checklicencia#" + txtNroLicencia.Text + "#");
                cliente = JsonConvert.DeserializeObject <ClienteBo>(json);
                if (cliente == null)
                {
                    MessageBox.Show("Nro de licencia no existe. Favor intente nuevamente");
                    txtNroLicencia.Text = "";
                    txtNroLicencia.Focus();
                }
                else
                {
                    var ambientes = new List <AmbienteBo>();
                    json      = Utils.StrSendMsg(server, int.Parse(port), "ambientes#" + cliente.Id + "#");
                    ambientes = JsonConvert.DeserializeObject <List <AmbienteBo> >(json);
                    if (ambientes != null)
                    {
                        dgAmbientes.Rows.Clear();

                        foreach (var item in ambientes)
                        {
                            string dir = "";
                            var    key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate\" + item.Nombre);
                            if (key != null)
                            {
                                dir = key.GetValue("DirWinper") == null  ? "" : key.GetValue("DirWinper").ToString();
                                key.Close();
                            }
                            dgAmbientes.Rows.Add(item.idAmbientes, item.Nombre, dir);
                        }
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utils.RegistrarLog("CheckLicencia.log", ex.ToString());
            }
        }
コード例 #4
0
ファイル: FormPrincipal.cs プロジェクト: radtek/winperupdate
        private void FormPrincipal_Load(object sender, EventArgs e)
        {
            Utils.isCentralizado = File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "ProcessWPUI.exe"));
            try
            {
                if (SvcWPUI.Status == System.ServiceProcess.ServiceControllerStatus.Running)
                {
                    SvcWPUI.Stop();
                }
            }
            catch (Exception) { }

            if (string.IsNullOrEmpty(Utils.GetSetting("server")) || string.IsNullOrEmpty(Utils.GetSetting("port")))
            {
                Utils.SetSetting("server", ConfigurationManager.AppSettings["server"]);
                Utils.SetSetting("port", int.Parse(ConfigurationManager.AppSettings["port"]));
                Utils.SetSetting("sql", bool.Parse(ConfigurationManager.AppSettings["sql"]));
                Utils.SetSetting("cftp", ConfigurationManager.AppSettings["cftp"]);
            }


            timerPing.Start();
            Utils.RegistrarLog("Load.log", "UI Iniciado");
            Utils.RegistrarLog("Load.log", "-----");
            ContextMenu1.MenuItems.Add("Configurar Ambiente y Licencia", new EventHandler(this.Ambiente_Click));
            ContextMenu1.MenuItems[0].Enabled = true;

            ContextMenu1.MenuItems.Add("-");
            ContextMenu1.MenuItems.Add("&Acerca de...", new EventHandler(this.AcercaDe_Click));
            ContextMenu1.MenuItems[1].DefaultItem = true;

            ContextMenu1.MenuItems.Add("&Configuración", new EventHandler(this.ConfigGen_Click));

            ContextMenu1.MenuItems.Add("-");
            ContextMenu1.MenuItems.Add("&Salir", new EventHandler(this.Salir_Click));

            notifyIcon2.ContextMenu = ContextMenu1;

            WindowState   = FormWindowState.Minimized;
            ShowInTaskbar = false;
            timer1.Stop();

            string nroLicencia = "";
            string ambientecfg = "";
            string perfil      = "";
            string inRun       = "No";
            string installDir  = Directory.GetCurrentDirectory();
            string statUI      = "updated";

            try
            {
                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate");
                nroLicencia = key.GetValue("Licencia").ToString();
                ambientecfg = key.GetValue("Ambientes").ToString();
                inRun       = key.GetValue("InRun").ToString();
                perfil      = key.GetValue("Perfil").ToString();
                installDir  = key.GetValue("InstallDir").ToString();
                statUI      = key.GetValue("StatUI").ToString();
                key.Close();
            }
            catch (Exception)
            {
                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\WinperUpdate");
                key.SetValue("Licencia", nroLicencia);
                key.SetValue("Ambientes", ambientecfg);
                key.SetValue("InRun", inRun);
                key.SetValue("Perfil", perfil);
                key.SetValue("InstallDir", installDir);
                key.SetValue("StatUI", statUI);
                key.Close();
            }

            string regUI = Path.Combine(Path.GetTempPath(), "regUI.bat");
            string exe   = Path.Combine(installDir, "WinPerUpdateUI.exe");

            int intentos = 0;
            var keyRun   = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\WinperUpdate");

            while (intentos < 3 && inRun.Equals("No"))
            {
                try
                {
                    if (File.Exists(regUI))
                    {
                        File.Delete(regUI);
                    }
                    if (!File.Exists(regUI))
                    {
                        File.WriteAllLines(regUI, new string[] {
                            "@echo off",
                            "cd %windir%\\system32",
                            "REG ADD \"HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" /v  WinperUpdate /t REG_SZ /d \"" + exe + "\"  /f >> regUI.log"
                        });
                    }
                    var pas = Utils.ShowDialogInput(string.Format("Se procederá a configurar WinAct en el arranque de Windows.\nEscriba la clave para el usuario {0}", Environment.UserName), "Clave de Usuario", true);

                    if (string.IsNullOrEmpty(pas))
                    {
                        intentos++;
                        MessageBox.Show(string.Format("No ha escrito ninguna clave, vuelva a intentarlo (Intento {0}/3)", intentos), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        var sec = new System.Security.SecureString();
                        for (int i = 0; i < pas.Length; i++)
                        {
                            sec.AppendChar(pas.ElementAt(i));
                        }

                        Process.Start(regUI, Environment.UserName, sec, Environment.UserDomainName);
                        inRun = "Si";
                        keyRun.SetValue("InRun", inRun);
                        var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                        key.SetValue("WinperUpdate", exe);
                        key.Close();
                        MessageBox.Show("WinAct fue configurado al inicio de Windows correctamente", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    intentos++;
                    MessageBox.Show(string.Format("{0} (Intento {1}/3)", ex.Message, intentos), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (intentos >= 3 && inRun.Equals("No"))
                {
                    MessageBox.Show("El numero de intentos sobrepaso el límite.\n\nWinAct no se pudo configurar al inicio de Windows. Esto NO afectará el funcionamiento de WinAct", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            keyRun.Close();

            if (!string.IsNullOrEmpty(nroLicencia))
            {
                string server = Utils.GetSetting("server");
                string port   = Utils.GetSetting("port");

                try
                {
                    string json = Utils.StrSendMsg(server, int.Parse(port), "checklicencia#" + nroLicencia + "#");
                    cliente = JsonConvert.DeserializeObject <ClienteBo>(json);
                    if (cliente != null)
                    {
                        json = Utils.StrSendMsg(server, int.Parse(port), "ambientes#" + cliente.Id.ToString() + "#");

                        ContextMenu1.MenuItems.Clear();

                        MenuItem addDevice = new MenuItem("&Estado de la Versión");
                        addDevice.Enabled = true;
                        ambientes         = JsonConvert.DeserializeObject <List <AmbienteBo> >(json);
                        foreach (var ambiente in ambientes)
                        {
                            var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate\" + ambiente.Nombre);
                            if (key != null)
                            {
                                string dirwp = key.GetValue("DirWinper") == null ? "" : key.GetValue("DirWinper").ToString();
                                if (Directory.Exists(dirwp))
                                {
                                    addDevice.MenuItems.Add(new MenuItem(ambiente.Nombre, new EventHandler(this.Restaurar_Click)));
                                }
                                key.Close();
                            }
                        }


                        /*Obtiene los modulos contratados del cliente con sus respectivos componentes*/
                        json = Utils.StrSendMsg(server, int.Parse(port), "modulos#" + cliente.Id + "#");
                        Utils.ModulosContratados = JsonConvert.DeserializeObject <List <ModuloBo> >(json);

                        ContextMenu1.MenuItems.Add(addDevice);

                        ContextMenu1.MenuItems.Add("Configurar Ambiente y Licencia", new EventHandler(this.Ambiente_Click));
                        ContextMenu1.MenuItems[1].Enabled = true;

                        ContextMenu1.MenuItems.Add("-");
                        ContextMenu1.MenuItems.Add("&Acerca de...", new EventHandler(this.AcercaDe_Click));
                        ContextMenu1.MenuItems[2].DefaultItem = true;

                        ContextMenu1.MenuItems.Add("&Configuración", new EventHandler(this.ConfigGen_Click));

                        ContextMenu1.MenuItems.Add("-");
                        ContextMenu1.MenuItems.Add("&Salir", new EventHandler(this.Salir_Click));

                        notifyIcon2.ContextMenu = ContextMenu1;
                        timer1.Start();
                        timerUI.Start();

                        TipoVentana = -1;
                        notifyIcon2.BalloonTipIcon  = ToolTipIcon.None;
                        notifyIcon2.BalloonTipTitle = "WinActUI";
                        notifyIcon2.BalloonTipText  = "Acá se encuentra WinAct!";
                        notifyIcon2.ShowBalloonTip(5000);
                    }
                }
                catch (Exception ex)
                {
                    if (ContextMenu1.MenuItems.Count > 0)
                    {
                        ContextMenu1.MenuItems[0].Enabled = false;
                        ContextMenu1.MenuItems[1].Enabled = false;
                    }
                    else
                    {
                        ContextMenu1.MenuItems.Add("Configurar Ambiente y Licencia", new EventHandler(this.Ambiente_Click));
                        ContextMenu1.MenuItems[0].Enabled = false;

                        ContextMenu1.MenuItems.Add("-");
                        ContextMenu1.MenuItems.Add("&Acerca de...", new EventHandler(this.AcercaDe_Click));
                        ContextMenu1.MenuItems[1].DefaultItem = true;

                        ContextMenu1.MenuItems.Add("&Configuración", new EventHandler(this.ConfigGen_Click));

                        ContextMenu1.MenuItems.Add("-");
                        ContextMenu1.MenuItems.Add("&Salir", new EventHandler(this.Salir_Click));
                    }
                    MessageBox.Show("WinAct no pudo iniciarce correctamente, puede revisar el log 'Load.log'");
                    Utils.RegistrarLog("Load.log", ex.ToString());
                }
            }
        }