public OperationReturn DownloadFileToAppServer() { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { if (Session == null) { optReturn.Result = false; optReturn.Code = RET_NO_SESSION; optReturn.Message = string.Format("SessionInfo is null"); return(optReturn); } if (mRecordInfo == null) { optReturn.Result = false; optReturn.Code = RET_NO_RECORDINFO; optReturn.Message = string.Format("RecordInfo is null"); return(optReturn); } string strServerAddress = mRecordInfo.VoiceIP; #region 获取下载服务器列表 List <DownloadServerItem> listServerItems = new List <DownloadServerItem>(); if (ListDownloadParams != null) { var downloadParams = ListDownloadParams.Where(d => d.VoiceAddress == strServerAddress || d.VoiceAddress == string.Empty).OrderBy(d => d.ID).ToList(); for (int i = 0; i < downloadParams.Count; i++) { var downloadParam = downloadParams[i]; if (!downloadParam.IsEnabled) { continue; } var item = new DownloadServerItem(); item.Type = 1; item.Info = downloadParam; listServerItems.Add(item); } } if (ListSftpServers != null) { var sftps = ListSftpServers.Where(s => s.HostAddress == strServerAddress).OrderBy(s => s.ObjID).ToList(); for (int i = 0; i < sftps.Count; i++) { var sftp = sftps[i]; var item = new DownloadServerItem(); item.Type = 0; item.Info = sftp; listServerItems.Add(item); } } if (listServerItems.Count <= 0) { optReturn.Result = false; optReturn.Code = RET_DOWNLOADSERVER_NOT_EXIST; optReturn.Message = string.Format("Download server not exist.\t{0}", strServerAddress); return(optReturn); } if (Service03Helper == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("Service03Helper is null"); return(optReturn); } #endregion #region 载文件 RequestMessage request; ReturnMessage retMessage; bool isDownloaded = false; //遍历可用的下载服务器尝试下载文件 for (int i = 0; i < listServerItems.Count; i++) { var item = listServerItems[i]; var type = item.Type; request = new RequestMessage(); if (type == 0) { //Sftp方式 var sftpServer = item.Info as SftpServerInfo; if (sftpServer == null) { continue; } string strPartInfo = string.Empty; PartitionTableInfo partInfo = Session.ListPartitionTables.FirstOrDefault( p => p.TableName == ConstValue.TABLE_NAME_RECORD && p.PartType == TablePartType.DatetimeRange); if (partInfo != null) { DateTime startTime = mRecordInfo.StartRecordTime; strPartInfo = string.Format("{0}{1}", startTime.ToString("yy"), startTime.ToString("MM")); } OnDebug("DownloadAppServer", string.Format("Downloading by sftp.\t{0}:{1}\t{2}", sftpServer.HostAddress, sftpServer.HostPort, mRecordInfo.SerialID)); request.Command = (int)Service03Command.DownloadRecordFile; request.ListData.Add(sftpServer.HostAddress); request.ListData.Add(sftpServer.HostPort.ToString()); request.ListData.Add(string.Format("{0}|{1}", Session.UserID, Session.RentInfo.Token)); request.ListData.Add(Session.UserInfo.Password); request.ListData.Add(mRecordInfo.RowID.ToString()); request.ListData.Add(mRecordInfo.SerialID.ToString()); request.ListData.Add(strPartInfo); //MediaType为0,认为是.wav文件 int mediaType = mRecordInfo.MediaType; if (mediaType == 0) { mediaType = 1; } request.ListData.Add(mediaType.ToString()); } else if (type == 1) { //NAS方式 var downloadParam = item.Info as DownloadParamInfo; if (downloadParam == null) { continue; } optReturn = GetRecordPath(downloadParam); if (!optReturn.Result) { return(optReturn); } string path = optReturn.Data.ToString(); if (string.IsNullOrEmpty(path)) { OnDebug("DownloadAppServer", string.Format("Record path is empty")); continue; } if (!string.IsNullOrEmpty(downloadParam.RootDir)) { path = string.Format("/{0}{1}", downloadParam.RootDir, path); } path = string.Format("{0}{1}.{2}", path, mRecordInfo.RecordReference, mRecordInfo.MediaType == 2 ? "vls" : "wav"); OnDebug("DownloadAppServer", string.Format("Downloading by nas.\t{0}:{1}\t{2}\t{3}", downloadParam.Address, downloadParam.Port, path, mRecordInfo.SerialID)); string serialID = mRecordInfo.SerialID.ToString(); request.Command = (int)Service03Command.DownloadRecordFileNas; request.ListData.Add(downloadParam.Address); request.ListData.Add(downloadParam.Port.ToString()); request.ListData.Add(downloadParam.UserName); request.ListData.Add(downloadParam.Password); request.ListData.Add(path); request.ListData.Add(serialID); int mediaType = mRecordInfo.MediaType; if (mediaType == 2) { mediaType = 2; } else { mediaType = 1; } request.ListData.Add(mediaType.ToString()); } else { OnDebug("DownloadAppServer", string.Format("Method invalid.\t{0}", type)); continue; } optReturn = Service03Helper.DoRequest(request); if (!optReturn.Result) { OnDebug("DownloadAppServer", string.Format("Download by {0} fail.\t{1}\t{2}", type, optReturn.Code, optReturn.Message)); continue; } retMessage = optReturn.Data as ReturnMessage; if (retMessage == null) { OnDebug("DownloadAppServer", string.Format("RetMessage is null")); continue; } if (!retMessage.Result) { OnDebug("DownloadAppServer", string.Format("Fail.\t{0}\t{1}", retMessage.Code, retMessage.Message)); continue; } OnDebug("DownloadAppServer", string.Format("Download by {0} end.\t{1}", type, mRecordInfo.SerialID)); isDownloaded = true; optReturn.Data = retMessage.Data; break; } if (!isDownloaded) { optReturn.Result = false; optReturn.Code = RET_DOWNLOAD_APPSERVER_FAIL; optReturn.Message = string.Format("Download file to AppServer fail. Reference log for detail information"); return(optReturn); } #endregion } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } return(optReturn); }
protected override void InitSessionInfo() { base.InitSessionInfo(); if (Session == null) { return; } //分表之类的参数 Session.ListPartitionTables.Clear(); PartitionTableInfo partInfo = new PartitionTableInfo(); partInfo.TableName = ConstValue.TABLE_NAME_RECORD; partInfo.PartType = TablePartType.DatetimeRange; partInfo.Other1 = ConstValue.TABLE_FIELD_NAME_RECORD_STARTRECORDTIME; Session.ListPartitionTables.Add(partInfo); //partInfo = new PartitionTableInfo(); //partInfo.TableName = ConstValue.TABLE_NAME_OPTLOG; //partInfo.PartType = TablePartType.DatetimeRange; //partInfo.Other1 = ConstValue.TABLE_FIELD_NAME_OPTLOG_OPERATETIME; //Session.ListPartitionTables.Add(partInfo); AppServerInfo serverInfo = new AppServerInfo(); serverInfo.Protocol = "http"; serverInfo.Address = "192.168.6.7"; serverInfo.Port = 8081; serverInfo.SupportHttps = false; Session.AppServerInfo = serverInfo; //AppServerInfo serverInfo = new AppServerInfo(); //serverInfo.Protocol = "https"; //serverInfo.Address = "192.168.6.86"; //serverInfo.Port = 8082; //serverInfo.SupportHttps = true; //Session.AppServerInfo = serverInfo; //DatabaseInfo dbInfo = new DatabaseInfo(); //dbInfo.TypeID = 3; //dbInfo.TypeName = "ORCL"; //dbInfo.Host = "192.168.4.182"; //dbInfo.Port = 1521; //dbInfo.DBName = "PFOrcl"; //dbInfo.LoginName = "PFDEV"; //dbInfo.Password = "******"; //Session.DatabaseInfo = dbInfo; //Session.DBType = dbInfo.TypeID; //Session.DBConnectionString = dbInfo.GetConnectionString(); //DatabaseInfo dbInfo = new DatabaseInfo(); //dbInfo.TypeID = 2; //dbInfo.TypeName = "MSSQL"; //dbInfo.Host = "192.168.4.182"; //dbInfo.Port = 1433; //dbInfo.DBName = "UMPDataDB0922"; //dbInfo.LoginName = "PFDEV"; //dbInfo.Password = "******"; //Session.DatabaseInfo = dbInfo; //Session.DBType = dbInfo.TypeID; //Session.DBConnectionString = dbInfo.GetConnectionString(); DatabaseInfo dbInfo = new DatabaseInfo(); dbInfo.TypeID = 2; dbInfo.TypeName = "MSSQL"; dbInfo.Host = "192.168.4.182"; dbInfo.Port = 1433; dbInfo.DBName = "UMPDataDB1225"; dbInfo.LoginName = "sa"; dbInfo.Password = "******"; Session.DatabaseInfo = dbInfo; Session.DBType = dbInfo.TypeID; Session.DBConnectionString = dbInfo.GetConnectionString(); //DatabaseInfo dbInfo = new DatabaseInfo(); //dbInfo.TypeID = 2; //dbInfo.TypeName = "MSSQL"; //dbInfo.Host = "192.168.4.182"; //dbInfo.Port = 1433; //dbInfo.DBName = "UMPDataDBYoung0805"; //dbInfo.LoginName = "PFDEV"; //dbInfo.Password = "******"; //Session.DatabaseInfo = dbInfo; //Session.DBType = dbInfo.TypeID; //Session.DBConnectionString = dbInfo.GetConnectionString(); }