Exemplo n.º 1
0
        private static bool RestaurarDatos(string archivo)
        {
            bool          restaurarDatos = false;
            List <string> credentials    = UtilVarios.GetCredentialsDB();
            string        server         = credentials[0];
            string        user           = credentials[1];
            string        database       = credentials[2];
            string        pass           = credentials[3];

            UtilDB.UnzipDB(archivo);
            archivo = archivo.Substring(0, archivo.Length - 3);
            UtilDB.RestoreDB(server, 3306, user, pass, database, archivo);
            // compruebo si se restauraron los datos
            Char delimiter = '_';

            String[] substrings         = archivo.Split(delimiter);
            int      pc                 = Convert.ToInt32(substrings[2].Substring(2));
            string   fecha              = substrings[3].Substring(0, 10);
            int      registroRestaurado = DAL.DatosDAL.RegistroRestaurado(fecha, pc);

            if (registroRestaurado > 0)
            {
                restaurarDatos = true;
            }
            return(restaurarDatos);
        }
Exemplo n.º 2
0
        public static void DownloadFile(string nombreLocal, string nombreServidor)
        {
            List <String> credentials = UtilVarios.GetCredentialsFTP();
            string        server      = credentials[0];
            string        user        = credentials[1];
            string        pass        = credentials[2];
            FtpWebRequest request     = (FtpWebRequest)WebRequest.Create("ftp://" + server + nombreServidor);

            request.Method      = WebRequestMethods.Ftp.DownloadFile;
            request.Credentials = new NetworkCredential(user, pass);
            FtpWebResponse objResponse = (FtpWebResponse)request.GetResponse();

            byte[] buffer = new byte[32768];
            using (Stream input = objResponse.GetResponseStream())
            {
                if (File.Exists(nombreLocal))
                {
                    File.Delete(nombreLocal);
                }
                using (FileStream output = new FileStream(nombreLocal, FileMode.CreateNew))
                {
                    int bytesRead;
                    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        output.Write(buffer, 0, bytesRead);
                    }
                }
            }
            objResponse.Close();
        }
Exemplo n.º 3
0
        public static void ConfigurarMySQL()
        {
            List <string> credentials = UtilVarios.GetCredentialsDB();
            string        server      = credentials[0];
            string        user        = credentials[1];
            string        database    = credentials[2];
            string        pass        = credentials[3];
            string        pathMysql   = string.Empty;

            if (Directory.Exists(@"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin"))
            {
                pathMysql = @"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin";
            }
            else if (Directory.Exists(@"C:\Program Files\MySQL\MySQL Server 5.5\bin"))
            {
                pathMysql = @"C:\Program Files\MySQL\MySQL Server 5.5\bin";
            }
            else if (Directory.Exists(@"C:\Archivos de programa\MySQL\MySQL Server 5.5\bin"))
            {
                pathMysql = @"C:\Archivos de programa\MySQL\MySQL Server 5.5\bin";
            }
            else if (Directory.Exists(@"C:\Archivos de programa (x86)\MySQL\MySQL Server 5.5\bin"))
            {
                pathMysql = @"C:\Archivos de programa (x86)\MySQL\MySQL Server 5.5\bin";
            }
            Process process = new Process();

            process.StartInfo.FileName = pathMysql + @"\mysqlinstanceconfig.exe";
            string args = "-i -q ServiceName=MySQL ServerType=DEVELOPER DatabaseType=INODB Port=3306 Charset=utf8 RootPassword="******"\Mysql\mysql.exe";
            //   string filename = Application.StartupPath + @"\Mysql\ncsoftwa_re_install.sql";
            string filename = Application.StartupPath + @"\Mysql\ncsoftwa_re.sql";

            process = new Process();
            process.StartInfo.FileName = pathEjecutable;
            args = "-C -B --host=" + server + " -P 3306 --user="******" --password="******" -e \"\\. " + filename + "\"";
            process.StartInfo.Arguments   = args;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.Start();
            process.WaitForExit();

            filename = Application.StartupPath + @"\Mysql\dump_admin.sql";
            process  = new Process();
            process.StartInfo.FileName = pathEjecutable;
            args = "-C -B --host=" + server + " -P 3306 --user="******" --password="******" -e \"\\. " + filename + "\"";
            process.StartInfo.Arguments   = args;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.Start();
            process.WaitForExit();
        }
Exemplo n.º 4
0
        public static FtpWebRequest FtpRequest(string path)
        {
            List <String> credentials = UtilVarios.GetCredentialsFTP();
            string        server      = credentials[0];
            string        user        = credentials[1];
            string        pass        = credentials[2];
            FtpWebRequest ftpRequest  = (FtpWebRequest)WebRequest.Create("ftp://" + server + path);

            ftpRequest.Credentials = new NetworkCredential(user, pass);
            return(ftpRequest);
        }
Exemplo n.º 5
0
        private static void DescargarArchivos(List <string> directories, string idRazonSocial, bool diarios)
        {
            if (Directory.Exists(@"c:\windows\temp\data_import"))
            {
                Directory.Delete(@"c:\windows\temp\data_import", true);
            }
            Directory.CreateDirectory(@"c:\windows\temp\data_import");
            credentials = UtilVarios.GetCredentialsFTP();
            server      = credentials[0] + "/datos";
            user        = credentials[1];
            pass        = credentials[2];
            WebClient ftpClient = new WebClient();

            ftpClient.Credentials = new System.Net.NetworkCredential(user, pass);
            using (ftpClient)
            {
                foreach (string archivo in directories)
                {
                    if (archivo.Contains(idRazonSocial))
                    {
                        if (!archivo.Contains("datos") && !archivo.Contains("locales") && !archivo.Contains("pcs") && !archivo.Contains("bck"))
                        {
                            Char     delimitador = '_';
                            String[] cadena      = archivo.Split(delimitador);
                            string   strFecha    = cadena[2].Substring(0, 10);
                            DateTime fecha       = Convert.ToDateTime(strFecha);
                            if (diarios)
                            {
                                if (fecha == DateTime.Today)
                                {
                                    string ftpPath   = "ftp://" + server + "/" + archivo;
                                    string localPath = @"c:\windows\temp\data_import\" + archivo;
                                    ftpClient.DownloadFile(ftpPath, localPath);
                                }
                            }
                            else
                            {
                                if (fecha < DateTime.Today)
                                {
                                    string ftpPath   = "ftp://" + server + "/" + archivo;
                                    string localPath = @"c:\windows\temp\data_import\" + archivo;
                                    ftpClient.DownloadFile(ftpPath, localPath);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        // EXPORTAR DATOS POS

        public static void ExportarDatos()
        {
            credentials = UtilVarios.GetCredentialsDB();
            server      = credentials[0];
            user        = credentials[1];
            database    = credentials[2];
            pass        = credentials[3];
            DataTable tbl = BL.GetDataBLL.RazonSocial();

            idRazonSocial = tbl.Rows[0][0].ToString();
            strFile       = idRazonSocial + "_datos.sql";
            UtilDB.DumpDatos(server, user, pass, database, @"c:\windows\temp\" + strFile);
            if (ValidarDump())
            {
                if (File.Exists(@"c:\windows\temp\" + strFile + ".xz"))
                {
                    File.Delete(@"c:\windows\temp\" + strFile + ".xz");
                }
                UtilDB.ZipDB(@"c:\windows\temp\" + strFile);
                strFile = strFile + ".xz";
Reintentar:
                UtilFTP.UploadFromFile(@"c:\windows\temp\" + strFile, "/datos/" + strFile);
                UtilFTP.DownloadFile(@"c:\windows\temp\tmp_" + strFile, "/datos/" + strFile);
                if (!UtilVarios.FileCompare(@"c:\windows\temp\tmp_" + strFile, @"c:\windows\temp\" + strFile))
                {
                    if (intentosUpload < 5)
                    {
                        intentosUpload++;
                        goto Reintentar;
                    }
                }
            }
            else
            {
                if (intentosDump < 5)
                {
                    intentosDump++;
                    ExportarDatos();
                }
            }
            intentosUpload = 0;
            intentosDump   = 0;
        }
Exemplo n.º 7
0
        public static void UploadFromFile(string nombreLocal, string nombreServidor)
        {
            List <String> credentials = UtilVarios.GetCredentialsFTP();
            string        server      = credentials[0];
            string        user        = credentials[1];
            string        pass        = credentials[2];
            FtpWebRequest request     = (FtpWebRequest)WebRequest.Create("ftp://" + server + nombreServidor);

            request.Method      = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(user, pass);
            byte[] fileContents = File.ReadAllBytes(nombreLocal);
            request.ContentLength = fileContents.Length;
            Stream requestStream = request.GetRequestStream();

            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            response.Close();
        }
Exemplo n.º 8
0
        public static void UploadFromMemoryStream(MemoryStream memoryStream, string nombreRemoto, string servidor)
        {
            List <String> credentials = UtilVarios.GetCredentialsFTP();
            string        server      = credentials[0] + "/datos";
            string        user        = credentials[1];
            string        pass        = credentials[2];
            FtpWebRequest reqFTP;

            reqFTP             = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + server + "/" + nombreRemoto));
            reqFTP.Credentials = new NetworkCredential(user, pass);
            // By default KeepAlive is true, where the control connection is not closed
            // after a command is executed.
            reqFTP.KeepAlive = false;
            reqFTP.Method    = WebRequestMethods.Ftp.UploadFile;
            // Specify the data transfer type.
            reqFTP.UseBinary = true;
            // Notify the server about the size of the uploaded file
            reqFTP.ContentLength = memoryStream.Length;
            int buffLength = 2048;

            byte[] buff = new byte[buffLength];
            int    contentLen;
            // Stream to which the file to be upload is written
            Stream strm = reqFTP.GetRequestStream();

            // Read from the file stream 2kb at a time
            memoryStream.Seek(0, SeekOrigin.Begin);
            contentLen = memoryStream.Read(buff, 0, buffLength);
            // Till Stream content ends
            while (contentLen != 0)
            {
                // Write Content from the file stream to the FTP Upload Stream
                strm.Write(buff, 0, contentLen);
                contentLen = memoryStream.Read(buff, 0, buffLength);
            }

            // Close the file stream and the Request Stream
            strm.Close();
            memoryStream.Close();
        }