示例#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);
        }
示例#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);
        }
示例#3
0
        /// <summary>
        /// MAIN process
        /// </summary>
        /// <returns></returns>
        public static int StartProcess()
        {
            try
            {
                string[]      ElencoExcel = DirOps.GetFilesToProcess(ConfigFile.ROOT, "*.xls|.xlsx");
                List <string> gg          = FileOps.GetTrueFilesToProcess(ElencoExcel);
                //####################################
                //Ciclo MAIN
                foreach (var file in gg)
                {
                    string TemplateFile = null;
                    if (ExcelOps.FileValidation(file))
                    {
                        FileT  fileT      = Parser.ParseFileName(file);
                        string destERFile = null;
                        if (fileT != null)
                        {
                            switch (fileT.TipoDBMS)
                            {
                            case ConfigFile.DB2_NAME:
                                TemplateFile = ConfigFile.ERWIN_TEMPLATE_DB2;
                                break;

                            case ConfigFile.ORACLE:
                                TemplateFile = ConfigFile.ERWIN_TEMPLATE_ORACLE;
                                break;

                            default:
                                TemplateFile = ConfigFile.ERWIN_TEMPLATE_DB2;
                                break;
                            }
                            FileInfo origin   = new FileInfo(file);
                            string   fileName = Path.GetFileNameWithoutExtension(file);
                            destERFile = Path.Combine(ConfigFile.FOLDERDESTINATION, fileName + Path.GetExtension(TemplateFile));
                            if (!FileOps.CopyFile(TemplateFile, destERFile))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                        //Apertura connessione per il file attuale
                        ConnMng connessione = new ConnMng();
                        if (!connessione.openModelConnection(destERFile))
                        {
                            continue;
                        }
                        //Aggiornamento della struttura dati per il file attuale
                        if (!connessione.SetRootObject())
                        {
                            continue;
                        }
                        if (!connessione.SetRootCollection())
                        {
                            continue;
                        }

                        FileInfo       fInfo    = new FileInfo(file);
                        List <EntityT> DatiFile = ExcelOps.ReadXFileEntity(fInfo, fileT.TipoDBMS);
                        foreach (var dati in DatiFile)
                        {
                            connessione.CreateEntity(dati, TemplateFile);
                        }
                        fInfo = new FileInfo(Path.Combine(ConfigFile.FOLDERDESTINATION, Path.GetFileNameWithoutExtension(file) + ".xlsx"));
                        List <AttributeT> AttrFile = null;
                        if (File.Exists(fInfo.FullName))
                        {
                            AttrFile = ExcelOps.ReadXFileAttribute(fInfo, fileT.TipoDBMS);
                        }
                        //ATTRIBUTI - PASSAGGIO UNO
                        //Aggiornamento dati struttura
                        if (!connessione.SetRootObject())
                        {
                            continue;
                        }
                        if (!connessione.SetRootCollection())
                        {
                            continue;
                        }
                        //############################
                        foreach (var dati in AttrFile)
                        {
                            connessione.CreateAttributePassOne(dati, TemplateFile);
                        }

                        //ATTRIBUTI - PASSAGGIO DUE
                        //Aggiornamento dati struttura
                        if (!connessione.SetRootObject())
                        {
                            continue;
                        }
                        if (!connessione.SetRootCollection())
                        {
                            continue;
                        }
                        //############################
                        foreach (var dati in AttrFile)
                        {
                            connessione.CreateAttributePassTwo(dati, TemplateFile);
                        }

                        //Chiusura connessione per il file attuale.
                        connessione.CloseModelConnection();
                    }
                }
                return(0);
            }
            catch (Exception exp)
            {
                //return exp.HResult;
                return(6);
            }
            return(6);
        }