Esempio n. 1
0
        /// <summary>
        /// 転送ファイルのチェック
        /// </summary>
        /// <param name="dirs"></param>
        private void TransferMain()
        {
            //バックアップ先list
            IList <BackupServer> BackupServer = BackupServerService.GetGroupBackupServerList(_backupgroupid);
            //バックアップ元
            MonitorServer MonitorServer = MonitorServerService.GetMonitorServerById(Int32.Parse(_monitorid));
            string        strSenderDir  = MonitorServer.monitorLocalPath + "\\";
            //バックアップ元のファイル変更list
            IList <MonitorServerFile> monitorServerFileForDelList    = MonitorServerFileService.GetMonitorServerFileDelList(_monitorid);
            IList <MonitorServerFile> monitorServerFileForTopDirList = MonitorServerFileService.GetMonitorServerFileTopDirList(_monitorid, strSenderDir.TrimEnd('\\'));
            string requestUrl = System.Configuration.ConfigurationManager.AppSettings["ssbapi"];
            string account    = System.Configuration.ConfigurationManager.AppSettings["ssbaccount"];
            string password   = System.Configuration.ConfigurationManager.AppSettings["ssbpassword"];

            foreach (BackupServer backup in BackupServer)
            {
                try
                {
                    SkeedFileTransfer filetransfer = new SkeedFileTransfer(requestUrl, account, password);
                    var jsonSession = filetransfer.connect(backup.backupServerIP);

                    if (jsonSession.ToString() != string.Empty && jsonSession.result == 0)
                    {
                        //批量传输
                        string strFileName    = "";
                        string fileId         = "";
                        string strDelFileName = "";
                        string fileDelId      = "";
                        foreach (MonitorServerFile file in monitorServerFileForDelList)
                        {
                            strDelFileName = strDelFileName + "&files=./" + file.monitorFilePath.Replace(strSenderDir, "");
                            fileDelId      = fileDelId + file.id + ",";
                        }
                        foreach (MonitorServerFile file in monitorServerFileForTopDirList)
                        {
                            strFileName = strFileName + "&files=" + file.monitorFilePath;
                            fileId      = fileId + file.id + ",";
                        }
                        if (strDelFileName != "")
                        {
                            //SSB Delete
                            DateTime startTime  = DateTime.Now;
                            dynamic  jsonResult = filetransfer.deleteFiles(jsonSession.session.sessionId, strSenderDir, backup.startFile, strDelFileName.TrimStart('&'));
                            DateTime endTime    = DateTime.Now;
                            TimeSpan timespan   = endTime - startTime;
                            if (jsonResult.ToString() != string.Empty && jsonResult.result == 0)
                            {
                                foreach (MonitorServerFile file in monitorServerFileForDelList)
                                {
                                    try
                                    {
                                        //更新传输flg
                                        MonitorServerFileService.UpdateTransferFlg(file.id, 1);
                                        //insert log and backupserverfile
                                        //InsertTransferInfo(file, backup, startTime, endTime, timespan, 1);
                                        //logger.Info("["+file.monitorFilePath + "] is deleted to [" + backup.backupServerIP + "] OK");
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Error(ex.Message);
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                try
                                {
                                    foreach (MonitorServerFile file in monitorServerFileForDelList)
                                    {
                                        //更新传输flg
                                        MonitorServerFileService.UpdateTransferFlg(file.id, 2);
                                        //insert log and backupserverfile
                                        //InsertTransferInfo(file, backup, startTime, endTime, timespan, 2);
                                        //logger.Info("[" + file.monitorFilePath + "] is deleted to [" + backup.backupServerIP + "] NG");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.Message);
                                    continue;
                                }
                            }
                        }
                        if (strFileName != "")
                        {
                            //SSB Upload
                            DateTime startTime  = DateTime.Now;
                            dynamic  jsonResult = filetransfer.transferFiles(jsonSession.session.sessionId, strSenderDir, strFileName);
                            DateTime endTime    = DateTime.Now;
                            TimeSpan timespan   = endTime - startTime;
                            if (jsonResult.ToString() != string.Empty && jsonResult.result == 0)
                            {
                                foreach (MonitorServerFile file in monitorServerFileForTopDirList)
                                {
                                    try
                                    {
                                        //更新传输flg
                                        MonitorServerFileService.UpdateTransferFlg(file.id, 1);
                                        //insert log and backupserverfile
                                        //InsertTransferInfo(file, backup, startTime, endTime, timespan, 1);
                                        //logger.Info("[" + file.monitorFilePath + "] is uploaded to [" + backup.backupServerIP + "] OK");
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Error(ex.Message);
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                foreach (MonitorServerFile file in monitorServerFileForTopDirList)
                                {
                                    try
                                    {
                                        //更新传输flg
                                        MonitorServerFileService.UpdateTransferFlg(file.id, 2);
                                        //insert log and backupserverfile
                                        //InsertTransferInfo(file, backup, startTime, endTime, timespan, 2);
                                        //logger.Info("[" + file.monitorFilePath + "] is uploaded to [" + backup.backupServerIP + "] NG");
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Error(ex.Message);
                                        continue;
                                    }
                                }
                            }
                        }
                        var jsonSession2 = filetransfer.disconnect(jsonSession.session.sessionId);
                    }
                    else
                    {
                        logger.Error("[" + backup.backupServerIP + "]は接続できません");
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    continue;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTansferFile(object sender, System.Timers.ElapsedEventArgs e)
        {
            m_timer.Enabled = false;
            //バックアップ先list
            IList <BackupServer> BackupServer = BackupServerService.GetGroupBackupServerList(backupgroupid);
            //バックアップ元
            MonitorServer MonitorServer = MonitorServerService.GetMonitorServerById(Int32.Parse(monitorid));
            string        strSenderDir  = MonitorServer.monitorLocalPath + "\\";
            //バックアップ元のファイル変更list
            IList <MonitorServerFile> monitorServerFileList = MonitorServerFileService.GetMonitorServerFileSSBPutList(monitorid, strSenderDir.TrimEnd('\\'));
            string requestUrl = System.Configuration.ConfigurationManager.AppSettings["ssbapi"];
            string account    = System.Configuration.ConfigurationManager.AppSettings["ssbaccount"];
            string password   = System.Configuration.ConfigurationManager.AppSettings["ssbpassword"];

            try
            {
                if (Directory.GetDirectories(strSenderDir).Length > 0 || Directory.GetFiles(strSenderDir).Length > 0)
                {
                    foreach (BackupServer backup in BackupServer)
                    {
                        try
                        {
                            SkeedFileTransfer filetransfer = new SkeedFileTransfer(requestUrl, account, password);
                            var jsonSession = filetransfer.connect(backup.backupServerIP);
                            //
                            if (monitorServerFileList.Count > 0)
                            {
                                // linq
                                var dirList = monitorServerFileList.ToList().Distinct(new DirectoryNameComparer());
                                // 転送情報
                                Hashtable transferInfo = new Hashtable();
                                if (dirList.Count() > 0)
                                {
                                    foreach (var dirname in dirList)
                                    {
                                        if (jsonSession.ToString() != string.Empty && jsonSession.result == 0)
                                        {
                                            dynamic jsonResult = filetransfer.doingTransferBatchesList();
                                            if (jsonResult.ToString() != string.Empty && jsonResult.result == 0)
                                            {
                                                try
                                                {
                                                    filetransfer.disconnect(jsonSession.session.sessionId);
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                                int taskeNum = Regex.Matches(jsonResult.ToString(), "taskId").Count;
                                                if (taskeNum <= SSBTaskMaxNum)
                                                {
                                                    //SSB Upload
                                                    DateTime startTime = DateTime.Now;
                                                    // 削除の場合
                                                    bool   transferresult;
                                                    string remotepath = RemotePathConvert(strSenderDir, dirname.monitorFileDirectory, backup.ssbpath);
                                                    transferresult = TransferDir(backup.backupServerIP, dirname.monitorFileDirectory, remotepath, minbpsset, maxbpsset, initbpsset);
                                                    DateTime       endTime        = DateTime.Now;
                                                    TimeSpan       timespan       = endTime - startTime;
                                                    TransferResult transferResult = new TransferResult();
                                                    if (transferresult)
                                                    {
                                                        transferResult.OKResult = true;
                                                        MonitorServerFileService.UpdateAllTransferFlg(dirname.monitorFileDirectory, 1);
                                                    }
                                                    else
                                                    {
                                                        transferResult.OKResult = false;
                                                        MonitorServerFileService.UpdateAllTransferFlg(dirname.monitorFileDirectory, 2);
                                                    }
                                                    transferResult.StartTime = startTime;
                                                    transferResult.EndTime   = endTime;
                                                    transferResult.TimeSpan  = timespan;
                                                    transferInfo.Add(dirname.monitorFileDirectory, transferResult);
                                                }
                                            }
                                        }
                                    }
                                    // ファイル更新
                                    foreach (MonitorServerFile file in monitorServerFileList)
                                    {
                                        try
                                        {
                                            TransferResult dirResult = transferInfo[file.monitorFileDirectory] as TransferResult;
                                            if (dirResult.OKResult)
                                            {
                                                MonitorServerFileService.UpdateTransferFlg(file.id, 1);
                                                //insert log and backupserverfile
                                                //InsertTransferInfo(file, backup, dirResult.StartTime, dirResult.EndTime, dirResult.TimeSpan, 1);
                                            }
                                            else
                                            {
                                                MonitorServerFileService.UpdateTransferFlg(file.id, 2);
                                                //insert log and backupserverfile
                                                //InsertTransferInfo(file, backup, dirResult.StartTime, dirResult.EndTime, dirResult.TimeSpan, 2);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex.Message);
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                            continue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            m_timer.Enabled = true;
        }