Exemplo n.º 1
0
        public IActionResult Index()
        {
            FTPManager man = new FTPManager();

            man.Connect();

            return(Content("test"));
        }
Exemplo n.º 2
0
        private void downLoadFile(string consecutivo, string pro_codi, string tableName, int emp_codi, string adj_nomb)
        {
            DAOGnRadju daoRadju = new DAOGnRadju();
            DAOGnAdju  daoAdju  = new DAOGnAdju();
            List <Digitalware.Apps.Utilities.TO.TOGnAdjun> adjun = new List <Digitalware.Apps.Utilities.TO.TOGnAdjun>();

            string download = HttpContext.Current.Server.MapPath("~/download/");
            string ftp      = ConfigurationManager.AppSettings["servidorFTP"];

            try
            {
                List <Digitalware.Apps.Utilities.TO.Gn_Adju.TOGnRadju> radju = daoRadju.GetRadju(emp_codi, pro_codi, consecutivo);

                if (radju == null || !radju.Any())
                {
                    throw new Exception("No hay adjuntos");
                }

                int rad_cont = radju.FirstOrDefault().Rad_Cont;
                adjun = daoAdju.GetAdjun(emp_codi, rad_cont);

                if (adjun.Count == 0)
                {
                    throw new Exception("No hay adjuntos");
                }

                foreach (Digitalware.Apps.Utilities.TO.TOGnAdjun adjunto in adjun)
                {
                    if (adjunto.Adj_Nomb == adj_nomb)
                    {
                        string directoryDefault         = string.Format("ftp://{0}/Seven/docs/{1}/{1}_{2}_{3}_{4}", ftp.ToString(), tableName, emp_codi.ToString(), rad_cont, adjunto.Adj_Cont);
                        List <DirectoryItem> filesExist = FTPManager.GetDirectoryInformation(directoryDefault);
                        if (filesExist != null && filesExist.Count > 0)
                        {
                            DownloadFile(directoryDefault, download + adj_nomb);

                            string data = System.IO.File.ReadAllText(download + adj_nomb);
                            using (FileStream stream = System.IO.File.Create(download + adj_nomb))
                            {
                                byte[] todecode_byte = Convert.FromBase64String(data);
                                stream.Write(todecode_byte, 0, todecode_byte.Length);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Exemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            UploadFiles = new List<string>();
            DownloadFiles = new List<string>();

            localDirectoryTF.Text = Config.DefaultLocalDir;
            LoadLocalDirectoryList();

            ftpManager = new FTPManager();

            LoadServerDirectoryList();
        }
Exemplo n.º 4
0
        private void InsertButtonClick(object sender, EventArgs e)
        {
            //등록 프로세서
            ProductManagement pm = new ProductManagement(dbLoginInfo);
            FTPManager        fm = new FTPManager(Properties.Settings.Default.ftpAddress, Properties.Settings.Default.ftpID, Properties.Settings.Default.ftpPW, Properties.Settings.Default.ftpPort);
            int index, infoIndex;

            //1. DB에 제품정보를 등록한다.
            index = pm.InsertProductData(textBoxProductName.Text, GetIndex("브랜드"), GetIndex("카테고리"), Convert.ToDecimal(textBoxPrice.Text));
            if (index == -1)
            {
                MessageBox.Show("제품 등록에 실패하였습니다.");
                return;
            }
            //1-1. 제품 추가정보를 등록한다
            infoIndex = pm.InsertProductSubData(index, textBoxDiscount.Text);
            if (infoIndex == -1)
            {
                MessageBox.Show("제품정보 등록에 실패하였습니다.");
                pm.DeleteProductData(index);
                return;
            }
            //2. FTP에 올릴파일이름을 추출한다.
            ImageInfo info = GetImageInfo(index);

            //3. FTP에 파일을 업로드한다.
            if (!fm.UploadFiles(info.paths, info.names))
            {
                MessageBox.Show("이미지파일 업로드에 실패하였습니다.");
                pm.DeleteProductSubData(infoIndex);
                pm.DeleteProductData(index);
                return;
            }
            //4. DB에 URL을 등록한다.
            if (!pm.InsertProductImages(info.urls, index))
            {
                MessageBox.Show("이미지정보 등록에 실패하였습니다.");
                pm.DeleteProductSubData(infoIndex);
                pm.DeleteProductData(index);
                fm.DeleteFiles(info.names);
                return;
            }
            MessageBox.Show("등록 완료");

            ClearInsertInfo();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var ftp = new FTPManager<Level2>();
            // stores and read only lvl2 above
            ftp.Store(new Level2());
            ftp.Store(new Level3());

            // have a storer only for Level3s..
            // IStorer is Contravariant
            // which means it can receive
            // a more generic Type T (Level2)
            // and implicit convert to a more
            // specific type T (Level3)
            IStorer<Level3> lvl3Storer = ftp; // stores only lvl3 above
            lvl3Storer.Store(new Level3());
            lvl3Storer.Store(new Level2()); // error

            // have a reader for all levels...
            // IReader is co-variant which means
            // that it can receive a specific type T
            // and implicit convert to a more generic type T
            IReader<Level1> allLevelsReader = ftp; // reads all levels

            // using interfaces correctly
            // using <out T> or <in T>

            // helps us not making mistakes
            // IReader only reads so it can
            // get types of the most generic root of T

            // but IStorer pushes things in
            // so it can't be a type more generic than
            // what ftp variable was created with.
            Console.WriteLine(allLevelsReader.Read(0));
            Console.WriteLine(allLevelsReader.Read(1));
        }
Exemplo n.º 6
0
        public bool Download(Action <string, float> progress = null)
        {
            _downloads.Clear();
            foreach (var config in _config.Downloads)
            {
                List <string> listOfFiles = new List <string>();
                using (var ftp = new FTPManager(config.Ftp))
                {
                    ftp.UsePassiveMode = _config.Passive;
                    ftp.SetUser(_config?.Credentials?.User, _config?.Credentials?.Pwd);
                    var ftpDir   = ftp.Load();
                    var localDir = new DirectoryInfo(config.Directory);
                    IEnumerable <FTPFile> ftpFiles = null;
                    if (config?.Files?.Any() ?? false)
                    {
                        ftpFiles = config.Files.Select(f => ftp.GetFile(f));
                        listOfFiles.AddRange(ftpFiles.Select(f => f.Name));
                    }
                    else
                    {
                        listOfFiles.AddRange(ftp.GetFiles().Select(f => f.Name));
                    }

                    if (ftp.Download(localDir, progress, ftpFiles) == true)
                    {
                        _downloads.Add(new Tuple <Download, List <string> >(config, listOfFiles));
                    }
                }
                if (config?.WhenFinished?.Any() ?? false)
                {
                    HandleFinishedDownloads(config, listOfFiles);
                }
            }
            HandleFinishedDownloads(_downloads);
            return(_config.Downloads.Count == _downloads.Count);
        }
Exemplo n.º 7
0
        public Boolean newGnAdjun(int emp_codi, string pro_codi, int cont, string rad_tabl, byte[] file, string name, string usu_codi, string type = "S")
        {
            try
            {
                var insta = DAO_Gn_Insta.GetGnInsta();


                Stream stream   = new MemoryStream(file);
                string fileName = "";
                switch (type)
                {
                case "S":

                    /*consultar si ya existe algún registro para sacar el consecutivo, sino se busca consecutivo*/
                    int      rad_cont = 0;
                    Gn_Radju rad      = new DAO_Gn_Radju().GetGnRadju(emp_codi, string.Concat(emp_codi, cont), pro_codi);
                    if (rad != null)
                    {
                        rad_cont = rad.rad_cont;
                    }
                    else
                    {
                        var consec = new DAO_Gn_Conse().getGnConse(emp_codi);
                        if (consec == 0)
                        {
                            throw new Exception(string.Format(
                                                    "No se encontró consecutivo para la empresa {0} y código consecutivo {1}",
                                                    emp_codi, "325"));
                        }
                        rad_cont = consec + 1;
                    }


                    int?r = null;

                    if (rad == null)
                    {
                        //Primero guardamos en la tabla de adjuntos
                        r = new DAO_Gn_Radju().InsertarGnRadju(new Gn_Radju()
                        {
                            rad_cont = rad_cont,
                            rad_tabl = rad_tabl,
                            pro_codi = pro_codi,
                            rad_llav = string.Concat(emp_codi, cont),
                            emp_codi = emp_codi
                        }, usu_codi);
                        if (r == null)
                        {
                            throw new Exception("Ha ocurrido un error al guardar el archivo adjunto");
                        }

                        //Actualiza el gn conse
                        //new DAO_Gn_Conse().updateGnConse(rad_cont, 325, double.Parse(string.Concat(emp_codi, cont)));
                    }



                    List <Gn_Adjun> adjunts  = new DAO_Gn_Adjun().GetAdjun(emp_codi, rad_cont);
                    int             adj_cont = adjunts == null || !adjunts.Any() ? 1 : adjunts.Max(o => o.adj_cont) + 1;
                    Gn_Adjun        adjun    = new Gn_Adjun();
                    adjun.rad_cont = rad_cont;
                    adjun.adj_cont = adj_cont;
                    adjun.adj_nomb = name;
                    adjun.adj_tipo = "A";
                    adjun.aud_usua = usu_codi;
                    adjun.emp_codi = emp_codi;
                    r = new DAO_Gn_Adjun().insertGnAdju(adjun);
                    if (r == null)
                    {
                        throw new Exception("Ha ocurrido un error al guardar el archivo adjunto");
                    }
                    fileName = string.Format("{0}_{1}_{2}_{3}", rad_tabl,
                                             emp_codi, rad_cont, adj_cont);
                    //System.IO.FileStream fs = new System.IO.FileStream(pathFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    //System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    //fs.CopyTo(ms);

                    if (insta.par_adju == "F")
                    {
                        Digitalware.Apps.Utilities.TO.ActionResult result = FTPManager
                                                                            .FileUpload(stream, rad_tabl + "/" + fileName);
                        if (!result.State)
                        {
                            throw new Exception(result.Message);
                        }
                    }
                    if (insta.par_adju == "B")
                    {
                        //Consultamos si hay adjuntos para obtener el adj_cont
                        List <Gn_AdJfi> adjfi = new DAO_Gn_AdJfi().GetAdjFi(emp_codi, rad_cont);
                        adj_cont = adjfi == null || !adjfi.Any() ? 1 : adjfi.Max(j => j.adj_cont + 1);

                        //byte[] fileAdj = FTPManager.DownloadFtp(pathFile, Path.GetFileNameWithoutExtension(pathFile));
                        //  string hex = Helpers.ByteArrayToString(files[i].data);
                        new DAO_Gn_AdJfi().insertGnAdjfi(new Gn_AdJfi {
                            adj_cont = adj_cont, adj_file = file, rad_cont = rad_cont, emp_codi = emp_codi
                        }, usu_codi);
                    }

                    return(true);

                case "W":

                    int             doc_cont    = 1;
                    List <Wf_Cdocu> filesExists = new DAO_Wf_Cdocu().GetWfCdocu(emp_codi, cont);
                    if (filesExists != null && filesExists.Any())
                    {
                        doc_cont = filesExists.Max(o => o.doc_cont) + 1;
                    }

                    fileName = string.Format("{0}_{1}_{2}_{3}", emp_codi,
                                             cont, doc_cont, name);
                    if (insta.par_adju == "F" || insta.par_adju == "B")
                    {
                        var newWfCdocu = new DAO_Wf_Cdocu().insertWfCdocu(new Wf_Cdocu()
                        {
                            cas_cont = cont,
                            doc_cont = doc_cont,
                            doc_desc = name,
                            emp_codi = emp_codi,
                            aud_usua = usu_codi,
                            doc_blob = file
                        });

                        Digitalware.Apps.Utilities.TO.ActionResult result = FTPManager
                                                                            .FileUpload(stream, fileName, string.Format("WORKFLOW/{0}/{1}/WF_CDOCU/", emp_codi, DateTime.Now.Year));
                        if (!result.State)
                        {
                            throw new Exception(result.Message);
                        }
                    }

                    return(true);

                default:
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error insertando adjunto:{0}", ex.Message));
            }
        }
Exemplo n.º 8
0
        public TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> > Get(string consecutivo, string pro_codi, string tableName, int emp_codi)
        {
            DAOGnRadju daoRadju = new DAOGnRadju();
            DAOGnAdju  daoAdju  = new DAOGnAdju();
            DAOGnAdjFi daoAdjF  = new DAOGnAdjFi();

            List <Digitalware.Apps.Utilities.TO.TOGnAdjun> adjun = new List <Digitalware.Apps.Utilities.TO.TOGnAdjun>();
            List <TO.TOGnAdjFi> adjfi = new List <TO.TOGnAdjFi>();

            string download = HttpContext.Current.Server.MapPath("~/download/");
            string ftp      = ConfigurationManager.AppSettings["servidorFTP"];
            List <Digitalware.Apps.Utilities.TO.Gn_Adju.TOGnRadju> radju = daoRadju.GetRadju(emp_codi, pro_codi, consecutivo);

            try
            {
                if (radju == null || !radju.Any())
                {
                    throw new Exception("No hay adjuntos");
                }

                int rad_cont = radju.FirstOrDefault().Rad_Cont;
                adjun = daoAdju.GetAdjun(emp_codi, rad_cont);

                if (adjun.Count == 0)
                {
                    throw new Exception("No hay adjuntos");
                }

                foreach (Digitalware.Apps.Utilities.TO.TOGnAdjun adjunto in adjun)
                {
                    string directoryDefault         = string.Format("ftp://{0}/Seven/docs/{1}/{1}_{2}_{3}_{4}", ftp.ToString(), tableName, emp_codi.ToString(), rad_cont, adjunto.Adj_Cont);
                    List <DirectoryItem> filesExist = FTPManager.GetDirectoryInformation(directoryDefault);
                    if (filesExist != null && filesExist.Count > 0)
                    {
                        DownloadFile(directoryDefault, download + adjunto.Adj_Nomb);
                    }
                }

                return(new TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> >()
                {
                    objTransaction = adjun, retorno = 0, txtRetorno = ""
                });
            }
            catch (Exception ex)
            {
                try
                {
                    int rad_cont = radju.FirstOrDefault().Rad_Cont;
                    adjfi = daoAdjF.GetAdjFi(emp_codi, rad_cont);

                    if (adjfi.Count == 0)
                    {
                        throw new Exception("No hay adjuntos");
                    }

                    foreach (TO.TOGnAdjFi adjuntF in adjfi)
                    {
                        DownloadFileFromDb(adjuntF.adj_nomb, adjuntF.adj_file);
                    }

                    return(new TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> >()
                    {
                        objTransaction = adjun, retorno = 0, txtRetorno = ""
                    });
                }
                catch (Exception exc)
                {
                    return(new TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> >()
                    {
                        objTransaction = null, retorno = 1, txtRetorno = exc.Message
                    });
                }
            }
        }