Example #1
0
        public static List <string> RemoteGet(List <string> FileDaElaborare)
        {
            DirectoryInfo local = new DirectoryInfo(ConfigFile.LOCAL_DIR_FULL);

            if (local.Exists)
            {
                DirOps.TraverseDirectory(local);
            }

            Logger.PrintLC("## Starting elaboration of remote/local file structure.", 2, ConfigFile.INFO);
            try
            {
                string[]      listSQL          = DirOps.GetFilesToProcess(ConfigFile.ROOT, "*.sql");
                List <string> listSQLdaCopiare = listSQL.ToList();
                DirOps.Copy(ConfigFile.ROOT, ConfigFile.LOCAL_DIR_FULL, FileDaElaborare);
                DirOps.Copy(ConfigFile.ROOT, ConfigFile.LOCAL_DIR_FULL, listSQLdaCopiare);
            }
            catch
            {
                Logger.PrintLC("Error while copying remote structure to local temporary structure.", 2, ConfigFile.ERROR);
                return(new List <string>());
            }
            // SEZIONE AGGIORNAMENTO PATH CARTELLE DI SISTEMA
            ConfigFile.TEMP_REMOTE_ROOT          = ConfigFile.ROOT;
            ConfigFile.FOLDERDESTINATION_GENERAL = Path.Combine(ConfigFile.LOCAL_DIR_FULL, ConfigFile.DEST_FOLD_NAME);
            ConfigFile.FOLDERDESTINATION         = Path.Combine(ConfigFile.FOLDERDESTINATION_GENERAL, ConfigFile.TIMESTAMPFOLDER);
            //###############################################
            if (ConfigFile.LOCAL_DIR_FULL.Substring(ConfigFile.LOCAL_DIR_FULL.Length - 1) != @"\")
            {
                ConfigFile.ROOT = ConfigFile.LOCAL_DIR_FULL + @"\";
            }
            else
            {
                ConfigFile.ROOT = ConfigFile.LOCAL_DIR_FULL;
            }

            //FileDaElaborareRemoto = FileDaElaborare;
            string[]      elencoLocale = DirOps.GetFilesToProcess(ConfigFile.ROOT, "*.xls|.xlsx");
            List <string> FileDaElaborareCompletoLocale = FileOps.GetTrueFilesToProcess(elencoLocale);

            FileDaElaborare = Parser.ParseListOfFileNames(FileDaElaborareCompletoLocale);
            Logger.PrintLC("## Finished elaboration of remote/local file structure.", 2, ConfigFile.INFO);
            return(FileDaElaborare);
        }
Example #2
0
        /// <summary>
        /// Copy the LOCAL structure of files and directories TO the original remote location,
        /// eliminating superflous Excel files.
        /// </summary>
        /// <param name="FileElaborati">List of files originally intended to be elaborated</param>
        /// <returns>State of the elaboration</returns>
        public static bool RemoteSet(List <string> FileElaborati)
        {
            Logger.PrintLC("## Copying back files from local to remote.", 2, ConfigFile.INFO);

            //ConfigFile.ROOT = ConfigFile.TEMP_REMOTE_ROOT;
            try
            {
                DirOps.Copy(ConfigFile.LOCAL_DIR_FULL, ConfigFile.TEMP_REMOTE_ROOT);
            }
            catch
            {
                Logger.PrintLC("Error while copying local temporary structure to remote structure.", 2, ConfigFile.ERROR);
                return(false);
            }
            DirectoryInfo local = new DirectoryInfo(ConfigFile.LOCAL_DIR_FULL);

            if (local != null)
            {
                if (ConfigFile.REMOVE_LOCAL)
                {
                    DirOps.TraverseDirectory(local);
                }
            }

            foreach (var elem in FileElaborati)
            {
                string   file   = elem.Replace(ConfigFile.LOCAL_DIR_FULL + @"\", ConfigFile.TEMP_REMOTE_ROOT);
                FileInfo fileI  = new FileInfo(file);
                FileInfo fileIU = null;
                switch (fileI.Extension)
                {
                case ".xls":
                    fileIU = new FileInfo(Path.Combine(fileI.DirectoryName, Path.GetFileNameWithoutExtension(fileI.FullName) + ".XLS"));
                    //fileI = fileIU;
                    break;

                case ".xlsx":
                    fileIU = new FileInfo(Path.Combine(fileI.DirectoryName, Path.GetFileNameWithoutExtension(fileI.FullName) + ".XLSX"));
                    //fileI = fileIU;
                    break;
                }
                if (fileI.Exists || fileIU.Exists)
                {
                    if (fileIU.Exists)
                    {
                        //fileI = fileIU;
                    }
                    string   name        = fileI.Name;
                    string   dir         = fileI.DirectoryName;
                    string   estensione  = string.Empty;
                    string   textNameOK  = string.Empty;
                    string   textNameKO  = string.Empty;
                    FileInfo fileTestoOK = null;
                    FileInfo fileTestoKO = null;
                    try
                    {
                        if (fileI.Extension == ".xls")
                        {
                            estensione = ".xls";
                            textNameOK = name.Replace(".xls", "_OK.txt");
                            textNameKO = name.Replace(".xls", "_KO.txt");
                        }
                        if (fileI.Extension == ".xlsx")
                        {
                            estensione = ".xlsx";
                            textNameOK = name.Replace(".xlsx", "_OK.txt");
                            textNameKO = name.Replace(".xlsx", "_KO.txt");
                        }
                        if (fileI.Extension == ".XLS")
                        {
                            estensione = ".XLS";
                            textNameOK = name.Replace(".XLS", "_OK.txt");
                            textNameKO = name.Replace(".XLS", "_KO.txt");
                        }
                        if (fileI.Extension == ".XLSX")
                        {
                            estensione = ".XLSX";
                            textNameOK = name.Replace(".XLS", "_OK.txt");
                            textNameKO = name.Replace(".XLSX", "_KO.txt");
                        }
                        fileTestoOK = new FileInfo(Path.Combine(dir, textNameOK));
                        fileTestoKO = new FileInfo(Path.Combine(dir, textNameKO));
                    }
                    catch (Exception exp)
                    {
                        Logger.PrintLC("Errore 9: " + exp.Message);
                        continue;
                    }
                    if (fileTestoKO.Exists)
                    {
                        if (!ConfigFile.DEST_FOLD_UNIQUE)
                        {
                            try
                            {
                                string   dirDestinationKO = Funct.GetFolderDestination(fileI.FullName, estensione);
                                FileInfo fileCopiare      = new FileInfo(dirDestinationKO);
                                try
                                {
                                    fileI.IsReadOnly = false;
                                    //fileI.MoveTo(fileCopiare.DirectoryName);
                                    fileI.MoveTo(dirDestinationKO);
                                    //fileI.Delete();
                                }
                                catch (Exception exp)
                                {
                                    try
                                    {
                                        if (exp.HResult == -2147024713)
                                        {
                                            fileI.Delete();
                                        }
                                        //if (exp.Message == "Impossibile creare un file, se il file esiste giĆ .\r\n")
                                        //    fileI.Delete();
                                    }
                                    catch { }
                                }


                                try
                                {
                                    fileIU.IsReadOnly = false;
                                    fileIU.MoveTo(fileCopiare.DirectoryName + @"\");
                                    fileIU.Delete();
                                }
                                catch (Exception exp)
                                {
                                    try
                                    {
                                        //fileIU.Delete();
                                    }
                                    catch { }
                                }


                                //if (!fileCopiare.Exists)
                                //{
                                //    fileI.MoveTo(fileCopiare.DirectoryName);
                                //}
                                //else
                                //{
                                //    fileCopiare.Delete();
                                //    fileI.MoveTo(fileCopiare.DirectoryName);
                                //}
                            }
                            catch (Exception exp)
                            {
                                Logger.PrintLC("Errore 10: " + exp.Message);
                            }
                        }
                        else
                        {
                            try
                            {
                                fileI.MoveTo(Path.Combine(ConfigFile.ROOT, ConfigFile.DEST_FOLD_NAME));
                            }
                            catch (Exception exp)
                            {
                                Logger.PrintLC("Errore 11: " + exp.Message);
                            }
                        }
                    }
                    if (fileTestoOK.Exists)
                    {
                        try
                        {
                            fileI.Delete();
                        }
                        catch (Exception exp)
                        {
                            Logger.PrintLC("Errore 12: " + exp.Message);
                        }
                        try
                        {
                            string   fileXLSX  = Path.GetFileNameWithoutExtension(fileI.FullName);
                            FileInfo fileIxls  = new FileInfo(Path.Combine(fileI.DirectoryName, fileXLSX + ".xlsx"));
                            FileInfo fileIXLSX = new FileInfo(Path.Combine(fileI.DirectoryName, fileXLSX + ".XLSX"));
                            try
                            {
                                fileIxls.Delete();
                            }
                            catch { }
                            try
                            {
                                fileIXLSX.Delete();
                            }
                            catch { }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return(true);
        }