コード例 #1
0
        public void Start()
        {
            running = true;
            while (running)
            {
                List <Database> list = ReadFromXML();


                foreach (Database d in list)
                {
                    ConnectionData connectionData = new ConnectionData(d.ConnectionString);

                    var           builder       = new System.Data.SqlClient.SqlConnectionStringBuilder(d.ConnectionString);
                    string        database      = builder.InitialCatalog;
                    BackupManager backupManager = new BackupManager(connectionData);
                    string        lastRunResult = string.Empty;


                    using (var connection = JobStorage.Current.GetConnection())
                    {
                        var recurringJobs = connection.GetRecurringJobs();
                        if (recurringJobs.Count == 0)
                        {
                            RecurringJob.AddOrUpdate(database, () => BackupM.BackupDB(connectionData, database), d.Cronos);
                        }
                        else
                        {
                            var job = recurringJobs.FirstOrDefault(p => p.Id.Equals(database));

                            if (job != null)
                            {
                                try
                                {
                                    if (job.LastJobId != null)
                                    {
                                        var jobState = connection.GetStateData(job.LastJobId);
                                        lastRunResult = jobState.Name;


                                        if ((!job.Cron.Equals(d.Cronos)) || (lastRunResult.Equals("Failed")) || (lastRunResult.Equals("Expired")))
                                        {
                                            RecurringJob.AddOrUpdate(database, () => BackupM.BackupDB(connectionData, database), d.Cronos);
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Log.Error("Eroor job", e.Message);
                                }
                            }
                            else
                            {
                                RecurringJob.AddOrUpdate(database, () => BackupM.BackupDB(connectionData, database), d.Cronos);
                            }
                        }
                    }
                }
                FTP.FtpConnectionInfo ftpCon    = ReadFTPFromXML();
                FTP.FTPClient         fTPClient = new FTP.FTPClient(ftpCon.Host, ftpCon.Username, ftpCon.Password);

                foreach (var p in BackupM.dict)
                {
                    fTPClient.UploadFile(p.Value);
                }
            }
        }
コード例 #2
0
ファイル: PE_OA_HR_OverTimes.cs プロジェクト: huaminglee/Code
        /// <summary>
        /// 上传图片并保存到数据库中
        /// </summary>
        /// <returns></returns> 
        private DataSet setPhotToSave(Dbconn conn, String strType)
        { 
            DataSet ds_Return = new DataSet();
            String remoteHost = ConfigurationSettings.AppSettings["remoteHostHR"].ToString();
            String remotePath = "";
            String remoteUser = ConfigurationSettings.AppSettings["remoteUserHR"].ToString();
            String remotePass = ConfigurationSettings.AppSettings["remotePassHR"].ToString() + "i";
            String remoteDir = ConfigurationSettings.AppSettings["remotePathHR"].ToString();
            int remotePort = 21;  
            int i = 0;

            //获取条件值
            string strXML = m_request.Tables[0].Rows[0]["XML"].ToString();
            DataSet dsXML = Common.Common.GetDSByExcelXML(strXML);
            string strPhotoPath = dsXML.Tables["LIST"].Rows[0]["photoPath"].ToString();
            string strPhotoID = dsXML.Tables["LIST"].Rows[0]["photoID"].ToString();
            string strActor = dsXML.Tables["LIST"].Rows[0]["actor"].ToString();
            string strActorID = dsXML.Tables["LIST"].Rows[0]["actorid"].ToString();
            string strUpType = dsXML.Tables["LIST"].Rows[0]["upType"].ToString();

            if (strPhotoPath == null || strPhotoPath=="")
            {
                dt_EditResult.Rows.Add(new object[] { false, "文件不能为空!" }); 
                ds_Return.Tables.Add(dt_EditResult);
                return ds_Return;  
            }


            //获取 UNIQUE_KEY
            if (strUpType == "new")
            {
                strPhotoID = getUniqueKey(conn);
                if (strPhotoID == "")
                {
                    dt_EditResult.Rows.Add(new object[] { false, "获取 UNIQUE_KEY失败!" }); 
                    ds_Return.Tables.Add(dt_EditResult);
                    return ds_Return; 
                }
            }

             

            //获取原始文件名
            string filename = strPhotoPath.Substring(strPhotoPath.LastIndexOf("\\") + 1
                , strPhotoPath.Length - strPhotoPath.LastIndexOf("\\") - 1);

            filename = filename.Substring(0, filename.LastIndexOf("-"))
                     + filename.Substring(filename.LastIndexOf("."), filename.Length - filename.LastIndexOf(".")); 
          
            //图片另存为.jpg
            string newfile = strPhotoPath.Substring(0, strPhotoPath.LastIndexOf("\\")+1) + strPhotoID + ".jpg";
            System.IO.File.Copy(strPhotoPath, newfile, true);  
            //上传文件
            var ftcc = new FTP.FTPClient(remoteHost, remotePath, remoteUser, remotePass, remotePort);
            ftcc.Connect();
            ftcc.ChDir(remoteDir);   // 切换到ftp对应目录下的文件夹路径
            ftcc.Put(newfile);  
            //删除图片另存为.jpg 
            System.IO.File.Delete(newfile); 
            
            //保存到数据库
            Byte[] byteSQLData = setPhotoByte(strPhotoPath);
            string strSQL2 = @" insert into B02_BILL.HR6_Blob (hr6_id, hr6_belongid, hr6_filename, hr6_content, hr6_type) 
                                    values( @Param0, @Param1, @Param2, @Param3, @Param4 ) ";
            i = conn.ExcuteQuerryByTran(strSQL2, new object[] { strPhotoID, "0", filename, byteSQLData, "0" }); 
           

            if (i==1)
            {
                dt_EditResult.Rows.Add(new object[] { true, strPhotoID });
            }
            else
            {
                dt_EditResult.Rows.Add(new object[] { false, "上传失败!" });

            }
            ds_Return.Tables.Add(dt_EditResult);
            return ds_Return;  
        }