Esempio n. 1
0
        public void Init()
        {
            if (CheckFieldsINICIAR())
            {
                this.Hide();
                ini.Minimize();
                SaveNewConfig();
                syncingOff();
                TemporalStorage = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\VoxLine\\" + ini.config.CodePc;
                Etc.CreateDir(TemporalStorage);
                CreateFTP();
                initiated = true;
                if (CheckConexionFTP())
                {
                    SyncAsync(ini.config.CodePc);
                    if (!time.Enabled)
                    {
                        InitTime();
                    }
                }

                else
                {
                }
            }
            else
            {
                MessageBox.Show("Los campos obligatorios no se han llenado.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Esempio n. 2
0
        public void Init()
        {
            if (CheckFieldsINICIAR())
            {
                this.Hide();
                ini.Minimize();
                SaveNewConfig();
                TemporalStorage = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\VoxLine\\" + ini.config.CodePc;
                Etc.CreateDir(TemporalStorage);
                if (initiated)
                {
                    StopTime();
                    initiated = false;
                }

                //GUstavo
                //Crear lock para que nadie mas pueda interactuar.

                /*if (Directory.Exists(ini.config.CarpetaRaiz + ini.config.CodePc))
                 * {
                 *      Etc.CreateLock(ini.config.CarpetaRaiz + ini.config.CodePc);
                 *      gLog.SaveLog("134 - create lock en la definitiva pivote");
                 * }else
                 * {
                 *      Directory.CreateDirectory(ini.config.CarpetaRaiz + ini.config.CodePc);
                 *      gLog.SaveLog("141 - crea carpeta  definitiva pivote");
                 *      Etc.CreateLock(ini.config.CarpetaRaiz + ini.config.CodePc);
                 *      gLog.SaveLog("141 - create lock en la definitiva pivote");
                 * }*/

                Sync();
                //Etc.DeleteLock(ini.config.CarpetaRaiz + ini.config.CodePc);
                //gLog.SaveLog("142 - borra el lock de la definitva pivote");

                if (!initiated)
                {
                    InitTime();
                    initiated = true;
                }
            }
            else
            {
                MessageBox.Show("Los campos obligatorios no se han llenado.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Esempio n. 3
0
        private void Sync()
        {
            var dictionary = new Dictionary <int, int>();

            //descargar json
            using (var webClient = new WebClient())
            {
                //string download link
                string downloadLink = ini.config.ModePivote[0].Servidor + "pivot/" + ini.config.CodePc + "/get/" + ini.config.ModePivote[0].Contrasena;
                try
                {
                    //leer string json
                    var jsonPure = webClient.DownloadString(downloadLink);

                    //generar db
                    ConnectionDBCMS(jsonPure);

                    syncingOn();

                    //raiz folder
                    string rootFolder = ini.config.CarpetaRaiz + rootCMS.Code;
                    //crear raiz
                    Etc.CreateDir(rootFolder);
                    //------------------------------------------------------------------------------------
                    //Daniel
                    //Crear archivo Json
                    string json = JsonConvert.SerializeObject(rootCMS);

                    //string path2 = @"C:\\FTP\\Voxline\\Pivotes\\35000" +  "/temp6.json";
                    string path = rootFolder + "/PlayList.json";

                    //Gustavo
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                        File.WriteAllText(path, json);
                    }
                    else
                    {
                        System.IO.File.WriteAllText(path, json);
                    }


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


                    //recorrer computador
                    foreach (var computer in rootCMS.Computers)
                    {
                        //computador string
                        string computerFolder = rootFolder + "/" + computer.Code;
                        // crear string computador
                        Etc.CreateDir(computerFolder);

                        //auxiliar
                        int aux = 0;
                        foreach (Screens screen in computer.Screens)
                        {
                            //crear carpeta pantalla
                            string screenFolder     = computerFolder + "/p" + screen.Code;
                            string screenFolder_TMP = computerFolder + "/p" + screen.Code + "_TMP";


                            //chequear si existe archivo lock
                            if (!Etc.CheckLock(screenFolder_TMP))
                            {
                                //crear carpeta pantalla
                                Etc.CreateDir(screenFolder);
                                Etc.CreateDir(screenFolder_TMP);

                                //crear localmente la variable de la pantalla
                                ScreensGuardian _screen = new ScreensGuardian();
                                //primero?
                                bool first = false;


                                _screen = ini.config.Screens.Find(e => e.Code == screen.Code.ToString());

                                if (_screen == null)
                                {
                                    //Esto no se ocupa ?
                                    _screen               = new ScreensGuardian();
                                    _screen.Alto          = screen.Height.ToString();
                                    _screen.Ancho         = screen.Width.ToString();
                                    _screen.Code          = screen.Code.ToString();
                                    _screen.Nombre        = screen.Name;
                                    _screen.VersionActual = "0";
                                    //_screen.VersionActual = (screen.Version-1).ToString();//cambio gonzalo
                                    //string versionValidate = screenFolder + "/" + "v" + screen.Version.ToString() + ".txt";//cambio gonzalo
                                    //cambio gonzalo
                                    //if (File.Exists(versionValidate))
                                    //{
                                    //	_screen.VersionActual = screen.Version.ToString();
                                    //}
                                    //cambio gonzalo
                                    //if (Etc.CheckEmptyFolder(screenFolder))
                                    //{
                                    //	first = true;
                                    //}

                                    first = true;
                                    ini.config.Screens.Add(_screen);
                                    ini.db.Save(ini.config);

                                    Etc.ClearDir(screenFolder);
                                }


                                //si se asigno recientemente
                                if (first)
                                {
                                    Etc.ClearDir(screenFolder_TMP);
                                    Etc.CreateLock(screenFolder_TMP);
                                    //Etc.CreateLock(screenFolder);
                                    int auxI = 0;
                                    if (screen.Playlist != null)
                                    {
                                        foreach (var content in screen.Playlist)
                                        {
                                            try
                                            {
                                                if (!CheckErrorResponse(content.Download.ToString()))
                                                {
                                                    //  string contentName = content.OriginalID + "-"+ content.defOrder + content.Name + "-" + auxI + ".mp4";


                                                    string contentName = content.OriginalID + "-" + content.Name + ".mp4";

                                                    //Daniel
                                                    //Comparo si el contenName existe en la carpeta de descarga si es asi no lo descargo.
                                                    if (Etc.CheckFile(screenFolder + "/" + contentName))
                                                    {
                                                        File.Copy(screenFolder + "/" + contentName, screenFolder_TMP + "/" + contentName);
                                                    }
                                                    else
                                                    {
                                                        Etc.CreateDir(screenFolder_TMP);                                                          // Daniel
                                                        DownloadFile(content.Download.ToString(), screenFolder_TMP + "/" + contentName);          // Daniel
                                                        //DownloadFile(content.Download.ToString(), screenFolder + "/" + contentName);
                                                        gLog.SaveLog("First: Se descargo " + contentName + " en " + screenFolder_TMP);
                                                        auxI++;
                                                    }
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                gLog.SaveLog("First: No se logro descargar archivos -- " + ex.Message);
                                                //throw;
                                            }
                                        }                                        // End foreach

                                        //GUSTAVO
                                        //Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString()); //Daniel
                                        //Etc.DeleteLock(screenFolder_TMP); // Daniel
                                        //Etc.MoveDir(screenFolder_TMP, screenFolder);
                                        Directory.Delete(screenFolder, true);                                 // Daniel
                                    }
                                    else
                                    {
                                        gLog.SaveLog("First: Sin Contenido asignado");
                                        //Etc.DeleteLock(screenFolder_TMP);
                                        Directory.Delete(screenFolder_TMP, true);
                                        if (Etc.CheckDir(screenFolder))
                                        {
                                            Etc.DeleteFiles(screenFolder);
                                        }
                                    }

                                    /* CAIDA
                                     * Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString()); //Daniel
                                     * Directory.Delete(screenFolder,true); // Daniel
                                     * Etc.DeleteLock(screenFolder_TMP); // Daniel
                                     * Etc.MoveDir(screenFolder_TMP, screenFolder); */


                                    //Etc.CreateVersion(screenFolder, screen.Version.ToString());
                                    //Etc.DeleteLock(screenFolder);

                                    //Etc.DeleteVersion(screenFolder, _screen.VersionActual);
                                    //Etc.CreateVersion(screenFolder, screen.Version.ToString());


                                    _screen.VersionActual   = screen.Version.ToString();
                                    ini.config.Screens[aux] = _screen;
                                    ini.db.Save(ini.config);
                                    Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString());       //Daniel
                                    Etc.DeleteLock(screenFolder_TMP);                                     // Daniel
                                    Etc.MoveDir(screenFolder_TMP, screenFolder);

                                    first = false;
                                }
                                //si la version
                                else if (screen.Version > Int32.Parse(_screen.VersionActual))
                                {
                                    ////------------------------------------------------------------------------------------
                                    ////Daniel
                                    ////Crear archivo Json
                                    //string json = JsonConvert.SerializeObject(rootCMS);
                                    //string path = computerFolder + "/PlayList.json";
                                    //System.IO.File.WriteAllText(path, json);
                                    ////------------------------------------------------------------------------------------
                                    gLog.SaveLog("Version Actual " + _screen.VersionActual + " -- Version Remota " + screen.Version);
                                    //Etc.DeleteFiles(screenFolder);//cambio gonzalo
                                    //Etc.ClearDir(screenFolder);
                                    //Etc.CreateLock(screenFolder_TMP);
                                    // Daniel
                                    Etc.ClearDir(screenFolder_TMP);
                                    Etc.CreateLock(screenFolder_TMP);
                                    //

                                    int auxI = 0;
                                    if (screen.Playlist != null)
                                    {
                                        foreach (var content  in screen.Playlist)
                                        {
                                            try
                                            {
                                                if (!CheckErrorResponse(content.Download.ToString()))
                                                {
                                                    //string contentName = content.defOrder + content.Name + "-" + auxI + ".mp4";
                                                    //Daniel
                                                    string contentName = content.OriginalID + "-" + content.Name + ".mp4";
                                                    //Daniel


                                                    if (Etc.CheckFile(screenFolder + "/" + contentName))
                                                    {
                                                        File.Copy(screenFolder + "/" + contentName, screenFolder_TMP + "/" + contentName);
                                                    }
                                                    else
                                                    {
                                                        DownloadFile(content.Download.ToString(), screenFolder_TMP + "/" + contentName);
                                                        gLog.SaveLog("Se descargo " + contentName + " en " + screenFolder);
                                                        auxI++;
                                                    }
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                gLog.SaveLog("No se logro descargar archivos -- " + ex.Message);
                                                //throw;
                                            }
                                        }                                        //end foreach
                                        Directory.Delete(screenFolder, true);    // Daniel
                                    }
                                    else
                                    {
                                        gLog.SaveLog("Sin Contenido asignado");
                                        //Daniel

                                        Etc.DeleteLock(screenFolder_TMP);
                                        Directory.Delete(screenFolder_TMP, true);
                                        if (Etc.CheckDir(screenFolder))
                                        {
                                            Etc.DeleteFiles(screenFolder);
                                        }
                                        //-------------------
                                    }


                                    //Etc.DeleteVersion(screenFolder, _screen.VersionActual);
                                    //Etc.CreateVersion(screenFolder, screen.Version.ToString());
                                    _screen.VersionActual   = screen.Version.ToString();
                                    ini.config.Screens[aux] = _screen;
                                    ini.db.Save(ini.config);

                                    //GUSTAVO
                                    Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString());       //Daniel
                                    Etc.DeleteLock(screenFolder_TMP);                                     // Daniel
                                    Etc.MoveDir(screenFolder_TMP, screenFolder);
                                    ///////////////////


                                    //Etc.DeleteLock(screenFolder);
                                }
                            }
                            if (Etc.CheckDir(screenFolder_TMP))
                            {
                                Directory.Delete(screenFolder_TMP, true);                                 // Daniel
                            }
                            aux++;
                        }

                        syncingOff();
                    }
                }
                catch (Exception ex)
                {
                    gLog.SaveLog("No se logro sincronizar archivos -- " + ex.Message);

                    //throw;
                }
            }
        }
Esempio n. 4
0
        private void Sync()
        {
            /*if(initiated)
             * {
             *      StopTime();
             *      initiated = false;
             * }*/


            var dictionary = new Dictionary <int, int>();

            //descargar json
            using (var webClient = new WebClient())
            {
                //string download link
                string downloadLink = ini.config.ModePivote[0].Servidor + "pivot/" + ini.config.CodePc + "/get/" + ini.config.ModePivote[0].Contrasena;
                gLog.SaveLog("315 - Genera string downloadLink");
                try
                {
                    //leer string json
                    var jsonPure = webClient.DownloadString(downloadLink);
                    gLog.SaveLog("321 - Se conecta y lee Json CMS");
                    //generar db
                    ConnectionDBCMS(jsonPure);
                    gLog.SaveLog("324 - Genera BD.Json");


                    syncingOn();

                    //raiz folder
                    string rootFolder = ini.config.CarpetaRaiz + rootCMS.Code;
                    //crear raiz
                    Etc.CreateDir(rootFolder);
                    gLog.SaveLog(" 398 - Crea la carpeta raiz : " + rootFolder);
                    //------------------------------------------------------------------------------------
                    //Daniel
                    //Crear archivo Json
                    string json = JsonConvert.SerializeObject(rootCMS);

                    //string path2 = @"C:\\FTP\\Voxline\\Pivotes\\35000" +  "/temp6.json";
                    string path = rootFolder + "\\PlayList.json";


                    gLog.SaveLog("408 - Crea el json en la carpeta raiz");
                    //Gustavo
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                        gLog.SaveLog("342 - File.Delete " + path);
                        File.WriteAllText(path, json);
                    }
                    else
                    {
                        System.IO.File.WriteAllText(path, json);
                    }


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


                    //recorrer computador
                    foreach (var computer in rootCMS.Computers)
                    {
                        //computador string
                        string computerFolder = rootFolder + "\\" + computer.Code;
                        // crear string computador
                        gLog.SaveLog("430 - crea carpeta por computador  : " + computer.Code);

                        if (!(Directory.Exists(computerFolder)))
                        {
                            Etc.CreateDir(computerFolder);
                        }



                        ///////////////GUSTAVO

                        /*Etc.CreateLock((computerFolder));
                         * gLgCreateLock.SaveLog("432 - Creando lock en computer folder : " + computerFolder); */


                        //auxiliar
                        int aux = 0;
                        foreach (Screens screen in computer.Screens)
                        {
                            //URLL carpetas pantalla
                            string screenFolder     = computerFolder + "\\p" + screen.Code;
                            string screenFolder_TMP = computerFolder + "\\p" + screen.Code + "_TMP";

                            if (!(Etc.CheckLock(screenFolder)))
                            {
                                gLog.SaveLog("447 La pantalla se encuentra disponible siguer su curso");
                                //chequear si existe archivo lock
                                gLog.SaveLog("445 - antes del etc.checklock(screenfolder_tmp)");
                                if (!Etc.CheckLock(screenFolder_TMP))
                                {
                                    gLog.SaveLog("448 - despues del etc.checklock(screenfolder_tmp)");
                                    //crear carpeta pantalla
                                    if (!(Directory.Exists(screenFolder)))
                                    {
                                        //Si el diecotrio principal no existe lo crea
                                        Etc.CreateDir(screenFolder);
                                        gLog.SaveLog("405 Crea carpeta definitva pantalla :  " + screenFolder);
                                    }

                                    //CREA lock por pantalla
                                    Etc.CreateLock(screenFolder);
                                    gLog.SaveLog("LOCK creado por pantalla : " + screenFolder);



                                    /*Etc.CreateDir(screenFolder_TMP);
                                     * gLog.SaveLog("375 - Etc.CreateDir " + screenFolder_TMP); */

                                    //crear localmente la variable de la pantalla
                                    ScreensGuardian _screen = new ScreensGuardian();
                                    //primero?
                                    bool first = false;


                                    _screen = ini.config.Screens.Find(e => e.Code == screen.Code.ToString());

                                    if (_screen == null)
                                    {
                                        //Esto no se ocupa ?
                                        _screen               = new ScreensGuardian();
                                        _screen.Alto          = screen.Height.ToString();
                                        _screen.Ancho         = screen.Width.ToString();
                                        _screen.Code          = screen.Code.ToString();
                                        _screen.Nombre        = screen.Name;
                                        _screen.VersionActual = "0";
                                        //_screen.VersionActual = (screen.Version-1).ToString();//cambio gonzalo
                                        //string versionValidate = screenFolder + "/" + "v" + screen.Version.ToString() + ".txt";//cambio gonzalo
                                        //cambio gonzalo
                                        //if (File.Exists(versionValidate))
                                        //{
                                        //	_screen.VersionActual = screen.Version.ToString();
                                        //}
                                        //cambio gonzalo
                                        //if (Etc.CheckEmptyFolder(screenFolder))
                                        //{
                                        //	first = true;
                                        //}

                                        first = true;
                                        ini.config.Screens.Add(_screen);
                                        ini.db.Save(ini.config);
                                        //Etc.ClearDir(screenFolder);
                                        //gLog.SaveLog("414 - Etc.ClearDir " + screenFolder);
                                    }


                                    //si se asigno recientemente
                                    if (first)
                                    {
                                        //Etc.ClearDir(screenFolder_TMP);
                                        //gLog.SaveLog("421 - Etc.ClearDir " + screenFolder_TMP);
                                        //crear carpeta pantalla

                                        if (Directory.Exists(screenFolder_TMP))
                                        {
                                            //SI existe la carpeta temporal la limpia
                                            Etc.ClearDir(screenFolder_TMP);
                                            gLog.SaveLog("459 - Limpia temporal " + screenFolder_TMP);
                                        }
                                        else
                                        {
                                            //Crear carpeta temporal
                                            Etc.CreateDir(screenFolder_TMP);
                                            gLog.SaveLog("465 - Crea temporal " + screenFolder_TMP);
                                        }



                                        Etc.CreateLock(screenFolder_TMP);
                                        //Etc.CreateLock(screenFolder);
                                        int auxI = 0;
                                        if (screen.Playlist != null)
                                        {
                                            foreach (var content in screen.Playlist)
                                            {
                                                try
                                                {
                                                    if (!CheckErrorResponse(content.Download.ToString()))
                                                    {
                                                        //  string contentName = content.OriginalID + "-"+ content.defOrder + content.Name + "-" + auxI + ".mp4";


                                                        string contentName = content.OriginalID + "-" + content.Name + ".mp4";

                                                        //Daniel
                                                        //Comparo si el contenName existe en la carpeta de descarga si es asi no lo descargo.
                                                        if (Etc.CheckFile(screenFolder + "\\" + contentName))
                                                        {
                                                            File.Copy(screenFolder + "\\" + contentName, screenFolder_TMP + "\\" + contentName);
                                                            gLog.SaveLog("First: Se copio a la temporal " + contentName + " en " + screenFolder_TMP);
                                                        }
                                                        else
                                                        {
                                                            Etc.CreateDir(screenFolder_TMP);                                                              // Daniel
                                                            DownloadFile(content.Download.ToString(), screenFolder_TMP + "\\" + contentName);             // Daniel
                                                            //DownloadFile(content.Download.ToString(), screenFolder + "/" + contentName);
                                                            gLog.SaveLog("First: Se descargo a la temporal" + contentName + " en " + screenFolder_TMP);
                                                            auxI++;
                                                        }
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    gLog.SaveLog("First: No se logro descargar archivos a la temporal-- " + ex.Message);
                                                    //throw;
                                                }
                                            }                                            // End foreach cargar contenido a la temporal

                                            //GUSTAVO
                                            //Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString()); //Daniel
                                            //Etc.DeleteLock(screenFolder_TMP); // Daniel
                                            //Etc.MoveDir(screenFolder_TMP, screenFolder);
                                            /////////////Directory.Delete(screenFolder, true); // Daniel
                                            /////////////gLog.SaveLog("468 - FIRST : Directory.Delete " + screenFolder);
                                        }
                                        else
                                        {
                                            gLog.SaveLog("First: Sin Contenido asignado");
                                            //Etc.DeleteLock(screenFolder_TMP);
                                            //////////////Directory.Delete(screenFolder_TMP, true);
                                            //////////gLog.SaveLog("474 - FIRST : Directory.Delete " + screenFolder_TMP);

                                            if (Etc.CheckDir(screenFolder))
                                            {
                                                Etc.DeleteFiles(screenFolder);
                                                gLog.SaveLog("477 - FIRST : Etc.DeleteFile " + screenFolder_TMP);
                                            }
                                        }

                                        /* CAIDA
                                         * Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString()); //Daniel
                                         * Directory.Delete(screenFolder,true); // Daniel
                                         * Etc.DeleteLock(screenFolder_TMP); // Daniel
                                         * Etc.MoveDir(screenFolder_TMP, screenFolder); */


                                        //Etc.CreateVersion(screenFolder, screen.Version.ToString());
                                        //Etc.DeleteLock(screenFolder);

                                        //Etc.DeleteVersion(screenFolder, _screen.VersionActual);
                                        //Etc.CreateVersion(screenFolder, screen.Version.ToString());


                                        _screen.VersionActual   = screen.Version.ToString();
                                        ini.config.Screens[aux] = _screen;
                                        ini.db.Save(ini.config);
                                        Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString());           //Daniel
                                        Etc.DeleteLock(screenFolder_TMP);                                         // Daniel
                                        gLog.SaveLog("500 - FIRST : Etc.DeleteLock " + screenFolder_TMP);
                                        Etc.DeleteLock(screenFolder);
                                        gLog.SaveLog("619 - FIRST Borra el lock de la pantalla antes de mover la temporal a la definitiva Etc.DeleteLock" + screenFolder);
                                        Etc.MoveDir(screenFolder_TMP, screenFolder);
                                        gLog.SaveLog("620 - FIRST : Contenido movido de la temporal " + screenFolder_TMP + " a la definitiva " + screenFolder);

                                        first = false;
                                    }
                                    //si la version
                                    else if (screen.Version > Int32.Parse(_screen.VersionActual))
                                    {
                                        //gustavo
                                        //_screen.VersionActual = screen.Version.ToString();
                                        ////------------------------------------------------------------------------------------
                                        ////Daniel
                                        ////Crear archivo Json
                                        //string json = JsonConvert.SerializeObject(rootCMS);
                                        //string path = computerFolder + "/PlayList.json";
                                        //System.IO.File.WriteAllText(path, json);
                                        ////------------------------------------------------------------------------------------
                                        gLog.SaveLog("Version Actual " + _screen.VersionActual + " -- Version Remota " + screen.Version);
                                        //Etc.DeleteFiles(screenFolder);//cambio gonzalo
                                        //Etc.ClearDir(screenFolder);
                                        //Etc.CreateLock(screenFolder_TMP);
                                        // Daniel
                                        if (Directory.Exists(screenFolder_TMP))
                                        {
                                            //SI existe la carpeta temporal la limpia
                                            Etc.ClearDir(screenFolder_TMP);
                                            gLog.SaveLog("585 - Limpia temporal " + screenFolder_TMP);
                                        }
                                        else
                                        {
                                            //Crear carpeta temporal
                                            Etc.CreateDir(screenFolder_TMP);
                                            gLog.SaveLog("590 - Crea temporal " + screenFolder_TMP);
                                        }



                                        //	Etc.ClearDir(screenFolder_TMP);
                                        gLog.SaveLog("523 - Etc.ClearDir" + screenFolder_TMP);
                                        Etc.CreateLock(screenFolder_TMP);
                                        gLog.SaveLog("525 - CreateLock" + screenFolder_TMP);
                                        //

                                        int auxI = 0;
                                        if (screen.Playlist != null)
                                        {
                                            foreach (var content in screen.Playlist)
                                            {
                                                try
                                                {
                                                    if (!CheckErrorResponse(content.Download.ToString()))
                                                    {
                                                        //string contentName = content.defOrder + content.Name + "-" + auxI + ".mp4";
                                                        //Daniel
                                                        string contentName = content.OriginalID + "-" + content.Name + ".mp4";
                                                        //Daniel


                                                        if (Etc.CheckFile(screenFolder + "\\" + contentName))
                                                        {
                                                            File.Copy(screenFolder + "\\" + contentName, screenFolder_TMP + "\\" + contentName);
                                                            gLog.SaveLog("Se copio a la temporal " + contentName + " en " + screenFolder);
                                                        }
                                                        else
                                                        {
                                                            DownloadFile(content.Download.ToString(), screenFolder_TMP + "\\" + contentName);
                                                            gLog.SaveLog("Se descargo a la temporal " + contentName + " en " + screenFolder);
                                                            auxI++;
                                                        }
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    gLog.SaveLog("No se logro descargar archivos a la temporal -- " + ex.Message);
                                                    //throw;
                                                }
                                            }                                            //end foreach
                                            Directory.Delete(screenFolder, true);        // Daniel
                                        }
                                        else
                                        {
                                            gLog.SaveLog("Sin Contenido asignado");
                                            //Daniel

                                            Etc.DeleteLock(screenFolder_TMP);
                                            gLog.SaveLog("522 - Etc.DeleteLock" + screenFolder_TMP);
                                            Directory.Delete(screenFolder_TMP, true);
                                            gLog.SaveLog("573 - Etc.ClearDir" + screenFolder_TMP);

                                            if (Etc.CheckDir(screenFolder))
                                            {
                                                Etc.DeleteFiles(screenFolder);
                                                gLog.SaveLog("Contenido borrado de la carpeta definitiva");
                                            }
                                            //-------------------
                                        }


                                        //Etc.DeleteVersion(screenFolder, _screen.VersionActual);
                                        //Etc.CreateVersion(screenFolder, screen.Version.ToString());
                                        _screen.VersionActual   = screen.Version.ToString();
                                        ini.config.Screens[aux] = _screen;
                                        ini.db.Save(ini.config);

                                        //GUSTAVO
                                        Etc.CreateVersion(screenFolder_TMP, screen.Version.ToString());           //Daniel
                                        gLog.SaveLog("592 - Etc.CreateVersion" + screenFolder_TMP + " " + screen.Version.ToString());
                                        Etc.DeleteLock(screenFolder_TMP);                                         // Daniel
                                        gLog.SaveLog("594 - Etc.DeleteLock" + screenFolder_TMP);
                                        Etc.DeleteLock(screenFolder);
                                        gLog.SaveLog("732 - Borra el lock de la pantalla antes de mover la temporal a la definitiva Etc.DeleteLock" + screenFolder);

                                        Etc.MoveDir(screenFolder_TMP, screenFolder);
                                        gLog.SaveLog("597 - Contenido movido de latemporal a la definitiva");
                                        ///////////////////


                                        //Etc.DeleteLock(screenFolder);
                                    }
                                    else
                                    {
                                        gLog.SaveLog("758 - No hay cambio de version");
                                        Etc.DeleteLock(screenFolder_TMP);                                         // Daniel
                                        gLog.SaveLog("594 - Etc.DeleteLock" + screenFolder_TMP);
                                        Etc.DeleteLock(screenFolder);
                                        gLog.SaveLog("732 - Borra el lock de la pantalla antes de mover la temporal a la definitiva Etc.DeleteLock" + screenFolder);
                                    }                                    //Fin if comprueba version
                                }

                                //Posible falla
                                if (Etc.CheckDir(screenFolder_TMP))
                                {
                                    ///////////////Directory.Delete(screenFolder_TMP, true); // Daniel
                                    /////////////gLog.SaveLog("609 - Delete " + screenFolder_TMP);
                                }
                                aux++;
                            }
                            else
                            {
                                gLog.SaveLog(" 761 - la carpeta se encuentra ocupada , se encontro LOCK.TXT  pantalla : " + screenFolder);
                            }
                        }                         //Fin foreach descargar contenido y mover a la definitiva

                        //Etc.DeleteLock(computerFolder);
                        //gLog.SaveLog("Borrando lock de computer folder : " + computerFolder );
                        syncingOff();
                    }
                }
                catch (Exception ex)
                {
                    gLog.SaveLog("634 - No se logro sincronizar archivos -- " + ex.Message);

                    InitTime();
                    initiated = true;
                    //throw;
                }
            }
        }
Esempio n. 5
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();
        }