Пример #1
0
        void ProcessParallelThread()
        {
            var Files = rProcess.GetFileToFolder(rProcess.tmpFolder, "pdf");

            foreach (var xFile in Files)
            {
                try
                {
                    var ftp = new ftp(@"ftp://188.121.43.20/services.danubeco.com/", "ranking");

                    // Upload PDF using FTP to Server Folder -> supplierx
                    var result = ftp.Upload(Path.Combine("ranking", xFile.Name), Path.Combine(new RANKProcess().tmpFolder, xFile.Name));

                    if (result.Success)
                    {
                        var reqIDD = Path.GetFileNameWithoutExtension(xFile.Name);

                        var newObj = db.reqlists.FirstOrDefault(s => s.reqid.Equals(reqIDD));

                        if (newObj.sts.Equals("processing"))
                        {
                            newObj.sts = "processed";

                            newObj.lnk = xFile.Name;

                            db.SaveChanges();
                        }

                        rProcess.moveToBckFolder(xFile);

                        updateLog(xFile, "Success", Color.Green);
                    }
                    else
                    {
                        rProcess.moveToErrFolder(xFile);

                        updateLog(xFile, "ErrorFTP", Color.Red);
                    }
                }
                catch (Exception ex)
                {
                    rProcess.moveToErrFolder(xFile);

                    updateLog(xFile, "ErrorFile : " + ex.Message, Color.Red);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Performs a backup
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        protected override bool Run(object parameters)
        {
            DatabaseBackupOptions options = (DatabaseBackupOptions)parameters;

            try
            {
                string backupFile = String.Format(@"{0}Backup-{4}-{1}{2}{3}.fbk",
                                                  Shared.Utilities.AddTrailingBackSlash(options.Path),
                                                  DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                                  options.UseSiteID ? options.SiteID.ToString() : options.Name);

                //backup database
                DoOnStageChanged(DatabaseBackupStage.BackingUpDatabase);

                try
                {
                    FirebirdSql.Data.Services.FbBackup backupSvc = new FirebirdSql.Data.Services.FbBackup();
                    backupSvc.ConnectionString = options.ConnectionString;

                    backupSvc.BackupFiles.Add(new FirebirdSql.Data.Services.FbBackupFile(backupFile, 2048));
                    backupSvc.Verbose = true;

                    backupSvc.Options = FirebirdSql.Data.Services.FbBackupFlags.IgnoreLimbo |
                                        FirebirdSql.Data.Services.FbBackupFlags.NoGarbageCollect;

                    backupSvc.Execute();
                }
                catch (Exception err)
                {
                    Shared.EventLog.Add(err);

                    if (!System.IO.File.Exists(backupFile))
                    {
                        return(false);
                    }
                }

                DoOnStageChanged(DatabaseBackupStage.DatabaseBackupComplete);

                // compress it
                DoOnStageChanged(DatabaseBackupStage.CompressingBackup);
                Shared.Classes.ZipFiles.CompressFile(backupFile.Replace(".fbk", ".zip"), backupFile, true);
                DoOnStageChanged(DatabaseBackupStage.BackupCompressed);

                if (!System.IO.File.Exists(backupFile.Replace(".fbk", ".zip")))
                {
                    Shared.EventLog.Add("Zip File Not Found");
                    return(false);
                }

                if (options.Upload)
                {
                    //upload the file
                    DoOnStageChanged(DatabaseBackupStage.SendingFileToServer);

                    ftp uploader = new ftp(options.FTPHost, options.FTPUsername, options.FTPPassword, 2048, true, true, true, options.FTPPort);
                    uploader.Upload(Path.GetFileName(backupFile.Replace(".fbk", ".zip")), backupFile.Replace(".fbk", ".zip"));

                    DoOnStageChanged(DatabaseBackupStage.FileSentToServer);
                }
            }
            catch (Exception err)
            {
                Shared.EventLog.Add(err);
            }
            finally
            {
                using (TimedLock.Lock(lockObject))
                {
                    _backups.Remove(options.Name);
                }

                DoOnStageChanged(DatabaseBackupStage.BackupComplete);
            }

            return(false);
        }
Пример #3
0
        public void ProcessParallelThread()
        {
            // Get all PDF -> _mdr
            var Files = FolderPO.GetAllFile(FolderPO.tmpFolder, "pdf");

            dnbmssqlEntities db = new dnbmssqlEntities();

            foreach (var xFile in Files)
            {
                try
                {
                    #region Convert FileInfo to PDF Object

                    // Split PDF Filename into Object
                    var pdf = SplitPdf(xFile);

                    #endregion

                    #region FTP Processes

                    // Set ftp values
                    var ftp = new ftp(@"ftp://188.121.43.20/services.danubeco.com/", "supplier");

                    // Upload PDF using FTP to Server Folder -> supplierx
                    var result = ftp.Upload(Path.Combine("supplier", xFile.Name), Path.Combine(FolderPO.tmpFolder, xFile.Name));

                    if (result.Success)
                    {
                        #region Set PO Object

                        // ----------------------------------------------- PO ---------------------------------------------------------

                        var newPO = new po
                        {
                            sid        = pdf.sid,
                            pono       = pdf.pono,
                            region     = pdf.region,
                            location   = pdf.location,
                            division   = pdf.division,
                            link       = xFile.Name,
                            filestatus = "Available",
                            released   = DateTime.Now.ToString("yyyy-MM-dd"),
                            expiration = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"),
                            isexpired  = "no"
                        };

                        #endregion

                        #region Store PO Object in Database

                        var isExist = db.poes.FirstOrDefault(p => p.pono.Equals(newPO.pono));

                        if (isExist != null)
                        {
                            isExist.filestatus = "Updated";
                            isExist.link       = newPO.link;
                        }
                        else
                        {
                            db.poes.Add(newPO);
                        }

                        #endregion

                        #region Set SMS

                        // ----------------------------------------------- SMS ---------------------------------------------------------

                        var isExists = db.sms.FirstOrDefault(x => x.sid.Equals(newPO.sid) && x.region.Equals(newPO.region));

                        if (isExists == null)
                        {
                            var user = db.supplierregions.FirstOrDefault(s => s.sid.Equals(newPO.sid) && s.region.Equals(newPO.region));

                            if (user != null)
                            {
                                if (user.sms.Equals("y"))
                                {
                                    db.sms.Add(new sm
                                    {
                                        sid      = newPO.sid,
                                        region   = newPO.region,
                                        icurrent = user.mobile,
                                        timesent = DateTime.Now.ToString(),
                                        status   = "waiting"
                                    });
                                }
                            }
                        }

                        #endregion

                        #region Store & Backup File + Log

                        // save changes to Database
                        db.SaveChanges();

                        // move files to backup folder
                        FolderPO.moveToBckFolder(xFile);

                        // write log ni rtbox
                        updateLog(xFile, "Success", Color.Green);

                        #endregion
                    }
                    else
                    {
                        #region Backup File + Log

                        // move to error folder
                        FolderPO.moveToErrFolder(xFile);

                        updateLog(xFile, "ErrorFTP", Color.Red);

                        #endregion
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                    // move to error folder
                    FolderPO.moveToErrFolder(xFile);

                    updateLog(xFile, "ErrorFile" + ex.Message, Color.Red);
                }
            }
        }
Пример #4
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(this, "Are you sure you want to transmit this/these file(s) now to branches?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                sql      = "SELECT code,ftp_username,ftp_password,ftp_url FROM warehouse WHERE deactivated='N' AND ftp_url IS NOT null";
                db       = new database(); dt = new DataTable();
                dt       = db.select(sql, vars.MySqlConnection);
                rowCount = dt.Rows.Count;

                string warehouse, user, pw, url;
                string currentFileName = "", currentFileFullPath = "";
                for (i = 0; i < rowCount; i++)
                {
                    warehouse = dt.Rows[i]["code"].ToString();
                    user      = dt.Rows[i]["ftp_username"].ToString();
                    pw        = dt.Rows[i]["ftp_password"].ToString();
                    url       = dt.Rows[i]["ftp_url"].ToString(); // should be in proper format e.g. ftp://192.168.1.100/incoming/

                    ftp ftpWebRequest = new ftp(user, pw);

                    for (int i2 = 0; i2 < listView1.Items.Count; i2++)
                    {
                        currentFileName     = listView1.Items[i2].Text;
                        currentFileFullPath = listView1.Items[i2].SubItems[1].Text;

                        ftpWebRequest.urlAndFileName = url + currentFileName;
                        ftpWebRequest.filePath       = currentFileFullPath;

                        if (ftpWebRequest.Upload())
                        {
                            sql  = "START TRANSACTION;";
                            sql += "SET @filename='" + currentFileName + "';";
                            sql += "SET @exportedFileId = (SELECT id FROM export_importfiles WHERE filename=@filename LIMIT 1);";
                            sql += "INSERT INTO transmittedfiles(exportedFilesId,warehouse,createdBy) VALUES(@exportedFileId,'" + warehouse + "'," + vars.user_id + ");";
                            sql += "UPDATE export_importfiles SET transmittedBy=" + vars.user_id + " WHERE id=@exportedFileId;";
                            sql += "COMMIT;";

                            database db2 = new database(); DataTable dt2 = new DataTable();
                            db2.executeNonQuery(sql, vars.MySqlConnection);
                            File.Move(currentFileFullPath, Application.StartupPath + @"\json\Transmitted\" + currentFileName);
                            listView1.Items.RemoveAt(i2);
                            i2--;
                        }
                        else
                        {
                            result = MessageBox.Show(this, "Do you want to continue with the rest of the files?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (result == DialogResult.No)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            if (listView1.Items.Count <= 0)
            {
                btnUpload.Enabled = false;
            }
        }