예제 #1
0
 /// <summary>
 /// 任务控制:覆盖
 /// </summary>
 /// <returns></returns>
 private bool CoverSite()
 {
     if (!this.multiCover)
     {
         string name  = this.SiteObj.SiteBaseInfo.NAME;
         int    count = this.SiteObj.SiteBaseInfo.SERVLIST.Count;
         int    num   = 0;
         foreach (WebSiteServer ServObj in this.SiteObj.SiteBaseInfo.SERVLIST)
         {
             string coverStatus = num.ToString() + (object)"/" + (string)(object)count;
             foreach (TaskFileInfo filePair in this.SiteObj.FilePairList)
             {
                 if (this.CoverServ(ServObj, filePair, name, new FtpAtomOperation(this.dbLog)))
                 {
                     this.dbLog.Trace("[覆盖]单个服务器", name, "[成功]___服务器名:" + ServObj.NAME + "文件路径:" + filePair.AimFile);
                     UploadTrace.FileCoverSuccess(filePair, this.block, coverStatus);
                 }
                 else
                 {
                     UploadTrace.FileCoverFail(filePair, this.block, ServObj.NAME, coverStatus);
                     this._coverErrorFile   = filePair;
                     this._coverErrorServer = ServObj;
                     UploadTrace.AddLog(filePair, this.block, "覆盖文件:" + filePair.FileName + "到:" + ServObj.NAME + "出错.准备回滚");
                     this.dbLog.Trace("[覆盖]单个服务器", name, "[失败]___服务器名:" + ServObj.NAME + "文件路径:" + filePair.AimFile);
                     return(false);
                 }
             }
             ++num;
         }
         return(true);
     }
     else
     {
         this.successnum = 0;
         if (UploadTrace.IsTaskCancel(this.block))
         {
             return(false);
         }
         try
         {
             foreach (WebSiteServer serv in this.SiteObj.SiteBaseInfo.SERVLIST)
             {
                 TaskWorker.doCover doCover = new TaskWorker.doCover(this.CoverSiteThread);
                 doCover.BeginInvoke(serv, new AsyncCallback(this.doCoverCallBack), (object)doCover);
             }
         }
         catch
         {
             return(false);
         }
         while (!this.hasError && this.successnum != this.SiteObj.FilePairList.Count * this.SiteObj.SiteBaseInfo.SERVLIST.Count)
         {
             Thread.Sleep(100);
         }
         return(!this.hasError);
     }
 }
예제 #2
0
        private void BackSiteThread(int threadid)
        {
            string name = this.SiteObj.SiteBaseInfo.NAME;

            foreach (TaskFileInfo filePair in this.file[threadid])
            {
                if (filePair != null && !this.hasError)
                {
                    if (UploadTrace.IsTaskCancel(this.block))
                    {
                        this.hasError = true;
                        break;
                    }
                    else
                    {
                        try
                        {
                            string fileName      = filePair.FileName;
                            byte[] backFileBytes = this.GetBackFileBytes(this.SiteObj.SiteBaseInfo.SERVLIST[0], filePair, this.SiteObj.SiteBaseInfo.LOCALBAKTRANSFOLDER, this.SiteObj.SiteBaseInfo.NAME);
                            if (backFileBytes != null)
                            {
                                foreach (WebSiteServer ServObj in this.SiteObj.SiteBaseInfo.SERVLIST)
                                {
                                    if (UploadTrace.IsTaskCancel(this.block))
                                    {
                                        this.hasError = true;
                                        return;
                                    }
                                    else if (this.BackupServ(ServObj, backFileBytes, name, filePair, this._BackupBlock, new FtpAtomOperation(this.dbLog)))
                                    {
                                        this.LogRollBack(ServObj, filePair, name, this._BackupBlock, "COVER");
                                        this.dbLog.Trace("[备份]单个服务器", name, "[成功]___服务器名:" + ServObj.NAME + ",文件名:" + fileName);
                                    }
                                    else
                                    {
                                        UploadTrace.FileBackupFail(filePair, this.block, ServObj.NAME);
                                        UploadTrace.AddLog(filePair, this.block, "文件备份:" + filePair.FileName + "到:" + ServObj.NAME + "出错.");
                                        this.dbLog.Trace("[备份]单个服务器", name, "[失败]___服务器名:" + ServObj.NAME + ",文件名:" + fileName);
                                        this.hasError = true;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            UploadTrace.AddLog(filePair, this.block, "文件备份:" + filePair.FileName + "出错.出错原因:" + ex.Message + ex.StackTrace);
                            UploadTrace.FileUploadFail(filePair, this.block, "");
                            this.hasError = true;
                            break;
                        }
                        UploadTrace.FileBackupSuccess(filePair, this.block);
                        ++this.successnum;
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// 任务控制:线程上传
 /// </summary>
 /// <param name="threadid"></param>
 private void UploadSiteThread(int threadid)
 {
     foreach (TaskFileInfo filePair in this.file[threadid])
     {
         if (filePair != null && !this.hasError)
         {
             if (UploadTrace.IsTaskCancel(this.block))
             {
                 this.hasError = true;
                 break;
             }
             else
             {
                 try
                 {
                     FileStream fileStream = File.Open(filePair.SrcFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                     byte[]     numArray   = new byte[fileStream.Length];
                     fileStream.Read(numArray, 0, numArray.Length);
                     fileStream.Close();
                     fileStream.Dispose();
                     string name = this.SiteObj.SiteBaseInfo.NAME;
                     foreach (WebSiteServer ServObj in this.SiteObj.SiteBaseInfo.SERVLIST)
                     {
                         if (UploadTrace.IsTaskCancel(this.block))
                         {
                             this.hasError = true;
                             return;
                         }
                         else if (!this.UploadServ(ServObj, numArray, name, filePair, new FtpAtomOperation(this.dbLog)))
                         {
                             this.hasError = true;
                             return;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     UploadTrace.AddLog(filePair, this.block, "文件上传:" + filePair.FileName + "出错.出错原因:" + ex.Message);
                     UploadTrace.FileUploadFail(filePair, this.block, "");
                     this.hasError = true;
                     break;
                 }
                 UploadTrace.FileUploadSuccess(filePair, this.block);
                 ++this.successnum;
             }
         }
     }
 }
예제 #4
0
 /// <summary>
 /// 任务控制:上传
 /// </summary>
 /// <returns></returns>
 private bool UploadSite()
 {
     if (UploadTrace.IsTaskCancel(this.block))
     {
         return(false);
     }
     try
     {
         for (int threadid = 0; threadid < this.file.Length; ++threadid)
         {
             TaskWorker.doUpload doUpload = new TaskWorker.doUpload(this.UploadSiteThread);
             doUpload.BeginInvoke(threadid, new AsyncCallback(this.AddMsgCallBack), (object)doUpload);
         }
     }
     catch
     {
         return(false);
     }
     while (!this.hasError && this.successnum != this.SiteObj.FilePairList.Count)
     {
         Thread.Sleep(100);
     }
     return(!this.hasError);
 }
예제 #5
0
        /// <summary>
        /// 同步
        /// </summary>
        public void Execute()
        {
            try
            {
                //记录开始日志
                this.dbLog.Trace("站点同步", this.SiteObj.SiteBaseInfo.NAME, "开始同步");

                #region  务器检查
                Msg msg = this.CheckServs(this.SiteObj);
                if (!msg.MsgResult)
                {
                    this.dbLog.Trace("检查服务器状态", this.SiteObj.SiteBaseInfo.NAME, "服务器网络连接出现问题:" + msg.MsgContent + "有服务器出现网络连接错误,请立即通知技术人员维护");
                    UploadTrace.TaskFailed(this.block);
                    return;
                }
                else
                {
                    this.dbLog.Trace("检查服务器状态", this.SiteObj.SiteBaseInfo.NAME, "一切正常");
                }
                #endregion

                #region 判定是否用户取消任务
                if (UploadTrace.IsTaskCancel(this.block))
                {
                    this.dbLog.Trace("上传站点", this.SiteObj.SiteBaseInfo.NAME, "失败,用户取消");
                    return;
                }
                #endregion

                #region  照线程分割文件列表到线程任务中
                this.file = new TaskFileInfo[this.threadNumber][];
                for (int index = 0; index < this.threadNumber; ++index)
                {
                    this.file[index] = new TaskFileInfo[this.SiteObj.FilePairList.Count / this.threadNumber + 1];
                }

                for (int index = 0; index < this.SiteObj.FilePairList.Count; ++index)
                {
                    TaskFileInfo filePair = this.SiteObj.FilePairList[index];
                    this.file[index / (this.SiteObj.FilePairList.Count / this.threadNumber + 1)][index % (this.SiteObj.FilePairList.Count / this.threadNumber + 1)] = filePair;
                }
                #endregion

                #region 步骤一:上传文件到所有任务服务器
                if (!this.UploadSite())
                {
                    this.dbLog.Trace("上传站点", this.SiteObj.SiteBaseInfo.NAME, "失败,任务终止");
                    UploadTrace.TaskFailed(this.block);
                    return;
                }
                else
                {
                    this.dbLog.Trace("上传站点", this.SiteObj.SiteBaseInfo.NAME, "成功");
                }
                #endregion

                #region 判定是否用户取消任务
                if (UploadTrace.IsTaskCancel(this.block))
                {
                    this.dbLog.Trace("上传站点", this.SiteObj.SiteBaseInfo.NAME, "失败,用户取消");
                    return;
                }
                #endregion

                #region 步骤二:备份文件到所有任务服务器
                if (!this.BackupSite())
                {
                    this.dbLog.Trace("备份站点", this.SiteObj.SiteBaseInfo.NAME, "失败,任务终止");
                    UploadTrace.TaskFailed(this.block);
                    return;
                }
                else
                {
                    this.dbLog.Trace("备份站点", this.SiteObj.SiteBaseInfo.NAME, "成功");
                }
                UploadTrace.TaskBackuping(this.block);
                #endregion

                #region 判定用户是否取消任务
                if (UploadTrace.IsTaskCancel(this.block))
                {
                    this.dbLog.Trace("上传站点", this.SiteObj.SiteBaseInfo.NAME, "失败,用户取消");
                    return;
                }
                #endregion

                #region 步骤三:覆盖文件到所有任务服务器
                if (this.CoverSite())
                {
                    this.dbLog.Trace("覆盖站点", this.SiteObj.SiteBaseInfo.NAME, "成功");
                    this.dbLog.Trace("同步站点", this.SiteObj.SiteBaseInfo.NAME, "结束同步");
                    UploadTrace.TaskSuccess(this.block);
                    return;
                }
                else
                {
                    this.dbLog.Trace("覆盖站点", this.SiteObj.SiteBaseInfo.NAME, "失败,任务终止");
                }
                UploadTrace.TaskCovering(this.block);
                #endregion

                #region 步骤四:回滚文件到所有任务服务器
                if (this.RollBackSite())
                {
                    this.dbLog.Trace("覆盖回滚", this.SiteObj.SiteBaseInfo.NAME, "成功");
                }
                else
                {
                    this.dbLog.Trace("覆盖回滚", this.SiteObj.SiteBaseInfo.NAME, "失败,任务终止");
                }
                UploadTrace.TaskFailed(this.block);
                #endregion
            }
            catch (Exception ex)
            {
                this.dbLog.Trace("上传站点", this.SiteObj.SiteBaseInfo.NAME, "失败,任务终止。错误信息:" + ex.Message + ex.StackTrace);
                UploadTrace.TaskFailed(this.block);
            }
        }