Пример #1
0
        /// <summary>
        /// 新建或更新
        /// </summary>
        /// <param name="ftpConfigEntity"></param>
        /// <returns></returns>
        public bool InsertOrUpdate(FtpConfigEntity ftpConfigEntity)
        {
            var sql       = @"INSERT INTO T8_FtpConfig (ServerAddress,UserName,UserPassword,ExportFileDirectory,CreateTime,ServerDirectory) 
                       VALUES(@ServerAddress,@UserName,@UserPassword,@ExportFileDirectory,@CreateTime,@ServerDirectory)";
            var existSql  = "SELECT COUNT(*) AS Cnt FROM T8_FtpConfig";
            var updateSql = @"UPDATE T8_FtpConfig SET ServerAddress=@ServerAddress,UserName=@UserName,UserPassword=@UserPassword,ExportFileDirectory=@ExportFileDirectory,ServerDirectory=@ServerDirectory";

            return(base.ExecuteFor((conn) =>
            {
                var prms = new
                {
                    ServerAddress = ftpConfigEntity.ServerAddress,
                    UserName = ftpConfigEntity.UserName,
                    UserPassword = ftpConfigEntity.UserPassword,
                    ExportFileDirectory = ftpConfigEntity.ExportFileDirectory,
                    CreateTime = DateTime.Now.ToString("s"),
                    ServerDirectory = ftpConfigEntity.ServerDirectory
                };

                DataTable table = conn.QueryDT(existSql);
                if (table != null && table.Rows[0]["Cnt"].ToString().ToInt() > 0)
                {
                    return conn.Execute(updateSql, prms) > 0;
                }

                return conn.Execute(sql, prms) > 0;
            }));
        }
Пример #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            Core.Service.FtpService bll       = new Core.Service.FtpService();
            FtpConfigEntity         ftpConfig = new FtpConfigEntity();

            MessageBox.Show("先设置FTP文件夹目录");
            FolderBrowserDialog saveFileDialog = new FolderBrowserDialog();

            saveFileDialog.Description = "设置FTP文件夹目录";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                ftpConfig.ServerAddress       = "ftp://openbook.cn";
                ftpConfig.UserName            = "******";
                ftpConfig.UserPassword        = Common.EncryptData("t8jyqssd");
                ftpConfig.ExportFileDirectory = saveFileDialog.SelectedPath;
            }

            bool state = bll.InsertOrUpdate(ftpConfig);

            if (state)
            {
                MessageBox.Show("添加成功");
                ;
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
Пример #3
0
 /// <summary>
 /// 连接FTP服务器
 /// </summary>
 /// <param name="ftpInfo"></param>
 /// <returns></returns>
 public static bool ConnectFtpServer(FtpConfigEntity ftpInfo)
 {
     try
     {
         using (FTPConnection ftpConn = new FTPConnection
         {
             ServerAddress = ftpInfo.ServerAddress,
             //ServerDirectory = ftpInfo.ServerDirectory,
             UserName = ftpInfo.UserName,
             Password = ftpInfo.UserPassword,
             CommandEncoding = Encoding.GetEncoding("GBK")
         })
         {
             ftpConn.Connect();
             if (!ftpConn.DirectoryExists(ftpInfo.ServerDirectory))
             {
                 throw new Exception($"FTP服务器连接成功,但FTP服务器不存在目录名[{ftpInfo.ServerDirectory}]");
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         string errMsg = $"FTP服务器连接失败,FTP信息[{JsonObj<FtpConfigEntity>.ToJson(ftpInfo)}],异常[{ ex.Message}]";
         LogUtil.WriteLog(errMsg);
         throw new Exception(errMsg);
     }
 }
Пример #4
0
        private void btnJobStart_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtTaskID.Text))
            {
                MessageBox.Show("任务ID不能为空");
                return;
            }

            string taskID = txtTaskID.Text.Trim();

            TaskEntity taskEntity = taskBll.Find(taskID);

            if (taskEntity == null)
            {
                MessageBox.Show("任务ID系统中不存在");
                return;
            }

            FtpConfigEntity ftpConfigEntity = ftpBll.GetFirstFtpInfo();

            taskEntity.FtpConfig = ftpConfigEntity;

            //构造数据文件产品并执行
            DbFileProductDirector director       = new DbFileProductDirector();
            ADbFileProductBuilder productBuilder = new DbFileProductBuilder();

            director.ConstructProduct(productBuilder);
            DbFileProduct product = productBuilder.GetDbFileProduct();

            product.Execute(taskEntity, cts.Token);
        }
Пример #5
0
        public FtpConfig AddFtpConfig(FtpConfig ftpConfig)
        {
            FtpConfigEntity entity = ftpConfig.ToEntity();

            this.dbContext.FtpConfigs.Add(entity);
            this.dbContext.SaveChanges();
            return(entity.ToModel());
        }
Пример #6
0
 /// <summary>
 /// 新建或更新
 /// </summary>
 /// <param name="ftpConfigEntity"></param>
 /// <returns></returns>
 public bool InsertOrUpdate(FtpConfigEntity ftpConfigEntity)
 {
     if (!string.IsNullOrEmpty(ftpConfigEntity.UserPassword))
     {
         ftpConfigEntity.UserPassword = Common.EncryptData(ftpConfigEntity.UserPassword);
     }
     return(dao.InsertOrUpdate(ftpConfigEntity));
 }
Пример #7
0
        /// <summary>
        /// 获取首条数据
        /// </summary>
        /// <returns></returns>
        public FtpConfigEntity GetFirstFtpInfo()
        {
            FtpConfigEntity ftpConfigEntity = dao.GetFirstFtpInfo();

            if (ftpConfigEntity != null)
            {
                ftpConfigEntity.UserPassword = Common.DecryptData(ftpConfigEntity.UserPassword);
            }
            return(ftpConfigEntity);
        }
Пример #8
0
        /// <summary>
        /// 获取一条数据
        /// </summary>
        /// <param name="ftpID"></param>
        /// <returns></returns>
        public FtpConfigEntity Find(int ftpID)
        {
            FtpConfigEntity ftpConfigEntity = dao.Find(ftpID);

            if (ftpConfigEntity != null)
            {
                ftpConfigEntity.UserPassword = Common.DecryptData(ftpConfigEntity.UserPassword);
            }
            return(ftpConfigEntity);
        }
Пример #9
0
        private FtpConfigEntity BuildFtpConfigEntity()
        {
            FtpConfigEntity ftpConfig = new FtpConfigEntity();

            ftpConfig.ServerAddress       = txtServerAddress.Text.Trim();
            ftpConfig.ServerDirectory     = txtServerDirectory.Text.Trim();
            ftpConfig.UserName            = txtUserName.Text.Trim();
            ftpConfig.UserPassword        = txtUserPassword.Text.Trim();
            ftpConfig.ExportFileDirectory = txtExportFileDirectory.Text.Trim();
            return(ftpConfig);
        }
Пример #10
0
        private void BindData()
        {
            FtpConfigEntity ftpConfig = ftpBll.GetFirstFtpInfo();

            if (ftpConfig != null)
            {
                txtServerAddress.Text       = ftpConfig.ServerAddress;
                txtServerDirectory.Text     = ftpConfig.ServerDirectory;
                txtUserName.Text            = ftpConfig.UserName;
                txtUserPassword.Text        = ftpConfig.UserPassword;
                txtExportFileDirectory.Text = ftpConfig.ExportFileDirectory;
            }
        }
Пример #11
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="ftpInfo"></param>
        /// <param name="sourceFilepath"></param>
        public static void UploadFile(FtpConfigEntity ftpInfo, string sourceFilepath)
        {
            if (ftpInfo == null)
            {
                throw new Exception("FtpHelper.UploadFile()方法,参数ftpInfo为空");
            }

            if (string.IsNullOrEmpty(sourceFilepath))
            {
                throw new Exception("FtpHelper.UploadFile()方法,参数sourceFilepath为空");
            }

            if (!File.Exists(sourceFilepath))
            {
                throw new Exception($"FtpHelper.UploadFile()方法,参数sourceFilepath[{sourceFilepath}]指定文件路径不存在");
            }

            try
            {
                using (FTPConnection ftpConn = new FTPConnection
                {
                    ServerAddress = ftpInfo.ServerAddress,
                    ServerDirectory = ftpInfo.ServerDirectory,
                    UserName = ftpInfo.UserName,
                    Password = ftpInfo.UserPassword,
                    CommandEncoding = Encoding.GetEncoding("GB2312")
                })
                {
                    ftpConn.Connect();

                    string tempFtpFileName = FileHelper.GetFileName(sourceFilepath) + ".part";
                    string ftpFileName     = FileHelper.GetFileName(sourceFilepath);

                    bool exist_file = ftpConn.Exists(tempFtpFileName);
                    if (exist_file)
                    {
                        LogUtil.WriteLog($"FTP服务器存在同名文件[{tempFtpFileName}],将ResumeNextTransfer");
                        ftpConn.ResumeNextTransfer();
                    }

                    ftpConn.UploadFile(sourceFilepath, tempFtpFileName, exist_file);
                    Thread.Sleep(200);
                    ftpConn.RenameFile(tempFtpFileName, ftpFileName);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"数据文件[{sourceFilepath}]上传失败,异常信息[{ex.Message}][{ex.StackTrace}]");
            }
        }
Пример #12
0
 public static FtpConfig ToModel(this FtpConfigEntity ftpConfig)
 {
     return(new FtpConfig()
     {
         Id = ftpConfig.Id,
         Name = ftpConfig.Name,
         Description = ftpConfig.Description,
         IP = ftpConfig.IP,
         Port = ftpConfig.Port,
         IsNeedAuthentication = ftpConfig.IsNeedAuthentication,
         VirticalDir = ftpConfig.VirticalDir,
         UserName = ftpConfig.UserName,
         Password = ftpConfig.Password
     });
 }
Пример #13
0
        public FtpConfig GetFtpConfigByName(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            DbParameter[] parameters = new DbParameter[]
            {
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Select_FtpConfigByName_Name,
                    Value         = name
                }
            };

            using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfFtpConfig.Sp_Select_FtpConfigById, parameters))
            {
                FtpConfigEntity entity = null;

                if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows.Count != 0)
                {
                    DataRow dataRow = dataSet.Tables[0].Rows[0];
                    DataColumnCollection dataColumns = dataSet.Tables[0].Columns;

                    entity = new FtpConfigEntity()
                    {
                        Id                   = (int)dataRow[dataColumns[0]],
                        Name                 = dataRow[dataColumns[1]].ToString(),
                        Description          = dataRow[dataColumns[2]].ToString(),
                        IP                   = dataRow[dataColumns[3]].ToString(),
                        Port                 = (int)dataRow[dataColumns[4]],
                        IsNeedAuthentication = (bool)dataRow[dataColumns[5]],
                        VirticalDir          = dataRow[dataColumns[6]].ToString(),
                        UserName             = dataRow[dataColumns[7]].ToString(),
                        Password             = dataRow[dataColumns[8]].ToString()
                    };
                }

                if (entity == null)
                {
                    return(null);
                }

                return(entity.ToModel());
            }
        }
Пример #14
0
        /// <summary>
        /// 读取数据库中全部的任务
        /// </summary>
        /// <returns></returns>
        public List <TaskEntity> GetAllTaskList()
        {
            var sql = @"SELECT * FROM T8_Task WHERE IsDelete=0  Order By CreateTime desc;
                        SELECT * FROM T8_FtpConfig Limit 1;";

            return(base.ExecuteFor((conn) =>
            {
                var multiResult = conn.QueryMultiple(sql);
                List <TaskEntity> list = multiResult.Read <TaskEntity>().ToList();
                FtpConfigEntity ftpConfigEntity = multiResult.Read <FtpConfigEntity>().FirstOrDefault();
                foreach (TaskEntity task in list)
                {
                    task.FtpConfig = ftpConfigEntity;
                }
                return list;
            }));
        }
Пример #15
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (ValidateData())
     {
         FtpConfigEntity ftpConfig = BuildFtpConfigEntity();
         bool            isSuccess = ftpBll.InsertOrUpdate(ftpConfig);
         if (isSuccess)
         {
             base.ShowMessage("FTP配置成功");
             this.Close();
         }
         else
         {
             base.ShowErrorMessage("FTP配置失败");
         }
     }
 }
Пример #16
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="ftpConfigEntity"></param>
        /// <returns></returns>
        public bool Update(FtpConfigEntity ftpConfigEntity)
        {
            var sql = @"UPDATE T8_FtpConfig SET ServerAddress=@ServerAddress,UserName=@UserName,UserPassword=@UserPassword,ExportFileDirectory=@ExportFileDirectory WHERE FtpID=@FtpID";

            return(base.ExecuteFor((conn) =>
            {
                var prms = new
                {
                    FtpID = ftpConfigEntity.FtpID,
                    ServerAddress = ftpConfigEntity.ServerAddress,
                    UserName = ftpConfigEntity.UserName,
                    UserPassword = ftpConfigEntity.UserPassword,
                    ExportFileDirectory = ftpConfigEntity.ExportFileDirectory,
                    CreateTime = DateTime.Now.ToString("s")
                };
                return conn.Execute(sql, prms) > 0;
            }));
        }
        private bool checkFtpUseable()
        {
            FtpConfigEntity ftpConfig = ftpBll.GetFirstFtpInfo();

            if (ftpConfig == null)
            {
                base.ShowErrorMessage("您未配置FTP信息,请点击[FTP配置]菜单进行配置");
                return(false);
            }

            if (!FtpHelper.ConnectFtpServer(ftpConfig))
            {
                base.ShowErrorMessage("FTP配置信息错误,未能连接上FTP服务器");
                return(false);
            }

            return(true);
        }
Пример #18
0
        private bool CheckFtpConnect()
        {
            if (Validate(true))
            {
                try
                {
                    FtpConfigEntity ftpConfig = BuildFtpConfigEntity();
                    FtpHelper.ConnectFtpServer(ftpConfig);
                    base.ShowMessage("FTP服务器连接成功");
                    return(true);
                }
                catch (Exception ex)
                {
                    base.ShowErrorMessage(ex.Message);
                    return(false);
                }
            }

            return(false);
        }
Пример #19
0
        /// <summary>
        /// 检测系统配置
        /// </summary>
        protected void CheckSystemConfiguration()
        {
            if (!Common.IsExistSQLiteDB())
            {
                ShowErrorMessage("系统未检测到数据库,请联系开卷客服人员");
                return;
            }

            List <SystemConfigEntity> systemConfigList = systemConfigService.GetSystemConfigList();

            if (systemConfigList.Count == 0)
            {
                ShowErrorMessage("系统配置表不存在,请联系开卷客服人员");
                return;
            }

            //1检测客户密钥
            SystemConfigEntity systemConfig = systemConfigList.Find(item => item.SysConfigID == (int)SystemConfigs.EncryptKey);

            if (systemConfig == null)
            {
                ShowErrorMessage("系统配置表不存在客户密钥数据记录,请联系开卷客服人员");
                return;
            }
            if (string.IsNullOrEmpty(systemConfig.ExSetting01))
            {
                ShowErrorMessage("未配置客户密钥,请先配置客户密钥");
                EncryptKeyConfigFrm frm = new EncryptKeyConfigFrm();
                frm.StartPosition = FormStartPosition.CenterParent;
                frm.ShowDialog();;
            }

            //2检测FTP配置
            FtpConfigEntity ftpConfig = ftpService.GetFirstFtpInfo();

            if (ftpConfig == null)
            {
                ShowErrorMessage("未配置FTP信息,请先配置FTP数据");
                FtpConfigFrm frm = new FtpConfigFrm();
                frm.StartPosition = FormStartPosition.CenterParent;
                frm.ShowDialog();
            }
            systemConfig = systemConfigList.Find(item => item.SysConfigID == (int)SystemConfigs.FtpUpoladService);
            if (systemConfig == null)
            {
                ShowErrorMessage("系统配置表不存在FTP上传服务数据记录,请联系开卷客服人员");
                return;
            }
            if (systemConfig.Status == 1)
            {
                try
                {
                    FtpHelper.ConnectFtpServer(ftpConfig);
                }
                catch (Exception ex)
                {
                    ShowErrorMessage($"请检查FTP配置信息。错误信息[{ex.Message}]");
                    FtpConfigFrm frm = new FtpConfigFrm();
                    frm.StartPosition = FormStartPosition.CenterParent;
                    frm.ShowDialog();
                }
            }
        }
Пример #20
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                CancellationToken ct = (CancellationToken)context.JobDetail.JobDataMap["CanellationTokenParam"];
                ct.ThrowIfCancellationRequested();

                SystemConfigEntity systemConfig = sysConfigService.FindSystemConfig((int)SystemConfigs.FtpUpoladService);
                if (systemConfig == null || systemConfig.Status == 0)
                {
                    return;
                }


                FtpConfigEntity ftpConfig = ftpService.GetFirstFtpInfo();
                if (ftpConfig == null)
                {
                    throw new Exception("传8未配置FTP信息");
                }

                if (!Directory.Exists(ftpConfig.ExportFileDirectory))
                {
                    throw new Exception($"传8配置的FTP目录[{ftpConfig.ExportFileDirectory}]不存在");
                }

                string fileBackupPath = Path.Combine(AppPath.DataFolder, ConfigHelper.GetConfig("UploadFileBackpath", "UploadFileBackup"), DateTime.Now.ToString("yyyyMM"));

                if (!Directory.Exists(fileBackupPath))
                {
                    Directory.CreateDirectory(fileBackupPath);
                }

                //获得源文件下所有文件
                List <string> files = new List <string>(Directory.GetFiles(ftpConfig.ExportFileDirectory));
                ct.ThrowIfCancellationRequested();

                files.ForEach(sourceFile =>
                {
                    ct.ThrowIfCancellationRequested();
                    try
                    {
                        FtpHelper.UploadFile(ftpConfig, sourceFile);
                        string backupfileFullpath = Path.Combine(fileBackupPath, FileHelper.GetFileName(sourceFile));

                        //备份上传文件
                        FileHelper.CopyFile(sourceFile, backupfileFullpath);
                        Thread.Sleep(200);
                        File.Delete(sourceFile);

                        LogUtil.WriteLog($"数据文件[{sourceFile}]上传成功");
                    }
                    catch (Exception ex)
                    {
                        LogUtil.WriteLog(ex.Message);
                    }
                });
            }
            catch (Exception ex)
            {
                //JobExecutionException jex = new JobExecutionException(ex);
                //jex.RefireImmediately = true;
                LogUtil.WriteLog($"FtpJob作业类异常,异常信息[{ex.Message}][{ex.StackTrace}]");
            }
        }
Пример #21
0
        public FtpConfig AddFtpConfig(FtpConfig ftpConfig)
        {
            if (ftpConfig == null)
            {
                return(null);
            }

            DbParameter[] parameters = new DbParameter[]
            {
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_Name,
                    Value         = ftpConfig.Name
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_Discription,
                    Value         = ftpConfig.Description
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_IP,
                    Value         = ftpConfig.IP
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_Port,
                    Value         = ftpConfig.Port
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_IsNeedAuthenticationt,
                    Value         = ftpConfig.IsNeedAuthentication
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_VirticalDir,
                    Value         = ftpConfig.VirticalDir
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_UserName,
                    Value         = ftpConfig.UserName
                },
                new SqlParameter()
                {
                    ParameterName = SpParamsOfFtpConfig.Sp_Insert_FtpConfig_Password,
                    Value         = ftpConfig.Password
                }
            };

            using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfFtpConfig.Sp_Insert_FtpConfig, parameters))
            {
                FtpConfigEntity entity = null;

                if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows.Count != 0)
                {
                    DataRow dataRow = dataSet.Tables[0].Rows[0];
                    DataColumnCollection dataColumns = dataSet.Tables[0].Columns;

                    entity = new FtpConfigEntity()
                    {
                        Id                   = (int)dataRow[dataColumns[0]],
                        Name                 = dataRow[dataColumns[1]].ToString(),
                        Description          = dataRow[dataColumns[2]].ToString(),
                        IP                   = dataRow[dataColumns[3]].ToString(),
                        Port                 = (int)dataRow[dataColumns[4]],
                        IsNeedAuthentication = (bool)dataRow[dataColumns[5]],
                        VirticalDir          = dataRow[dataColumns[6]].ToString(),
                        UserName             = dataRow[dataColumns[7]].ToString(),
                        Password             = dataRow[dataColumns[8]].ToString()
                    };
                }

                if (entity == null)
                {
                    return(null);
                }

                return(entity.ToModel());
            }
        }
Пример #22
0
        public FtpConfig GetFtpConfigByName(string name)
        {
            FtpConfigEntity entity = this.dbContext.FtpConfigs.FirstOrDefault(fc => fc.Name == name);

            return(entity == null ? null : entity.ToModel());
        }
Пример #23
0
        public FtpConfig GetFtpConfigById(int id)
        {
            FtpConfigEntity entity = this.dbContext.FtpConfigs.FirstOrDefault(fc => fc.Id == id);

            return(entity == null ? null : entity.ToModel());
        }
Пример #24
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="ftpConfigEntity"></param>
 /// <returns></returns>
 public bool Update(FtpConfigEntity ftpConfigEntity)
 {
     return(dao.Update(ftpConfigEntity));
 }