Example #1
0
        //DESCARGA
        private void DownloadFilesAsync(FtpClient _ftpclient, string _remotePath)
        {
            string Path = _remotePath;
            string TemporalLocalFolder = TemporalStorage;

            Downloaded = false;



            //GUSTAVO
            //string root_temp_adress = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\VoxLine\\PlayList.json";
            //Descargae el json a la carpeta raiz
            //JSON var directorio = _ftpclient.GetListing("PlayList.json");
            //var directorio = _ftpclient.GetListing(Path + "\\p859");
            //var pantalla = directorio[0];
            ftpClient.DownloadFile(TemporalLocalFolder + "\\PLayList.json", "PlayList.json", FtpLocalExists.Overwrite, FtpVerify.Retry);

            //

            Etc.CreateDir(TemporalLocalFolder);

            int auxI = 0;

            //ini.config.Screens.Clear();
            //getScreens
            foreach (FtpListItem item in _ftpclient.GetListing(Path).OrderByDescending(item => item.Name))
            {
                //if the folder is the player folder, enter and download
                if (item.Type == FtpFileSystemObjectType.Directory && item.Name.Substring(0, 1) == "p")
                {
                    string code = item.Name.Substring(1, item.Name.Length - 1);
                    if (ini.config.Screens.Exists(x => x.Code == code))
                    {
                        int idx = ini.config.Screens.FindIndex(x => x.Code == code);
                        ini.config.Screens[idx].Nombre    = item.Name;
                        ini.config.Screens[idx].Path      = item.FullName;
                        ini.config.Screens[idx].Code      = code;
                        ini.config.Screens[idx].LocalPath = ini.config.CarpetaRaiz + "\\p" + code;
                    }
                    else
                    {
                        ScreensGuardian _screen = new ScreensGuardian();
                        _screen.Nombre        = item.Name;
                        _screen.Path          = item.FullName;
                        _screen.Code          = code;
                        _screen.LocalPath     = ini.config.CarpetaRaiz + "\\p" + code;
                        _screen.VersionActual = "0";
                        ini.config.Screens.Add(_screen);
                    }

                    ini.db.Save(ini.config);
                    auxI++;
                }
            }

            var _screens = ini.config.Screens.ToArray();

            int aux = 0;

            foreach (ScreensGuardian screen in _screens)
            {
                int _versionRemota = GetRemoteVersion(_ftpclient, screen.Path);
                screen.VersionRemota    = _versionRemota;
                ini.config.Screens[aux] = screen;
                ini.db.Save(ini.config);

                //----------------------------------------------------------
                //


                if (!Etc.CheckDir(screen.LocalPath) || screen.VersionRemota > Int32.Parse(screen.VersionActual))
                {
                    string ScreenTemporal = TemporalLocalFolder + '\\' + screen.Nombre;
                    Etc.CreateDir(ScreenTemporal);
                    try
                    {
                        Etc.ClearDir(ScreenTemporal);
                    }
                    catch (Exception ex)
                    {
                        gLog.SaveLog("ERROR CLEAR DOWNLOAD " + ex.Message);
                    }

                    //Descarga los dentro de la carpeta correspondiendte a la pantalla en el ftp
                    foreach (FtpListItem item in _ftpclient.GetListing(screen.Path).OrderByDescending(item => item.Name))
                    {
                        if (item.Type == FtpFileSystemObjectType.File)
                        {
                            string   downloadFileName = ScreenTemporal + "\\" + item.Name;
                            FileInfo f = new FileInfo(downloadFileName);
                            try
                            {
                                //GUSTAVO
                                string rutaarchivoftp = screen.LocalPath + "\\" + item.Name;                                 //Ruta del archivo en la carpeta definitiva
                                var    directorio     = Directory.Exists(rutaarchivoftp);

                                if (Directory.Exists(screen.LocalPath))
                                {
                                    if (File.Exists(rutaarchivoftp))
                                    {
                                        Etc.CopyFile(rutaarchivoftp, ScreenTemporal + "\\" + item.Name);
                                        gLog.SaveLog("COPIADO " + item.Name);
                                        Downloaded = true;
                                    }
                                    else
                                    {
                                        if (ftpClient.DownloadFile(downloadFileName, item.FullName, FtpLocalExists.Overwrite, FtpVerify.Retry))
                                        {
                                            Downloaded = true;
                                            gLog.SaveLog("DESCARGADO " + item.Name);
                                        }
                                        else
                                        {
                                            gLog.SaveLog("ERROR EN " + item.Name);
                                        }
                                    }
                                }
                                else
                                {
                                    if (ftpClient.DownloadFile(downloadFileName, item.FullName, FtpLocalExists.Overwrite, FtpVerify.Retry))
                                    {
                                        Downloaded = true;
                                        gLog.SaveLog("DESCARGADO " + item.Name);
                                    }
                                    else
                                    {
                                        gLog.SaveLog("ERROR EN " + item.Name);
                                    }
                                }


                                /* ANTES
                                 *  if (ftpClient.DownloadFile(downloadFileName, item.FullName, FtpLocalExists.Overwrite, FtpVerify.Retry))
                                 * {
                                 *       Downloaded = true;
                                 *       gLog.SaveLog("DESCARGADO " + item.Name);
                                 * }
                                 * else
                                 * {
                                 *      gLog.SaveLog("ERROR EN " + item.Name);
                                 * }*/
                            }
                            catch (Exception ex)
                            {
                                gLog.SaveLog(ex.Message);
                                //throw;
                            }
                        }
                    }
                }
                aux++;
            }

            CloseConnection();
        }