/// <summary> /// 上传文件,上传结束后不会退出Sftp服务器 /// </summary> /// <param name="config">Sftp参数</param> /// <returns></returns> public OperationReturn UploadFile1(SftpHelperConfig config) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { if (mSftp == null || !mSftp.Connected) { optReturn = LogOn(config); if (!optReturn.Result) { return(optReturn); } } if (mSftp == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("Sftp is null"); return(optReturn); } mSftp.RemoteFile = config.RemoteFile; mSftp.LocalFile = config.LocalFile; mSftp.Overwrite = true; mSftp.MakeDirectory(config.RemoteDirectory); mSftp.Upload(); return(optReturn); } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; return(optReturn); } }
private OperationReturn SendMessage(string msg) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { msg = string.Format("{0}\r\n", msg); byte[] data = Encoding.UTF8.GetBytes(msg); mSslStream.Write(data); mSslStream.Flush(); mLastActiveTime = DateTime.Now; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = string.Format("SendMessage fail.\t{0}", ex.Message); } return(optReturn); }
private void Application_Exit(object sender, ExitEventArgs e) { if (bIsUpgrageSuccess) { List <string> lstServices = App.lstServicesToStart; if (lstServices.Count > 0) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; for (int i = 0; i < lstServices.Count; i++) { optReturn = CommonFuncs.StartServiceByNmae(lstServices[i]); if (!optReturn.Result) { App.WriteLog("Start service " + lstServices[i] + " failed. " + optReturn.Message); } else { App.WriteLog("Start service " + lstServices[i] + " success. "); } } } } //删掉解压出来的文件 if (Directory.Exists(App.gStrUpdateFolderTempPath)) { try { Directory.Delete(gStrUpdateFolderTempPath, true); } catch (Exception ex) { App.WriteLog("Delete " + gStrUpdateFolderTempPath + " failed. " + ex.Message); } } }
private bool LoadFiles() { try { WebRequest webRequest; Service36011Client client; WebReturn webReturn; webRequest = new WebRequest(); webRequest.Session = CurrentApp.Session; webRequest.Code = (int)S3601Codes.OperationLoadFile; OperationReturn optReturn = XMLHelper.SeriallizeObject(SetQuestionInfo.questionParam); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return(false); } webRequest.ListData.Add(optReturn.Data.ToString()); client = new Service36011Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service36011")); //client = new Service36011Client(); webReturn = client.UmpTaskOperation(webRequest); client.Close(); if (!webReturn.Result) { ShowException(webReturn.Message); return(false); } if (string.IsNullOrWhiteSpace(webReturn.Data)) { return(false); } _mLoadPath = webReturn.Data; } catch (Exception ex) { ShowException(ex.Message); return(false); } return(true); }
private List <string> SaveQueryConditionItems(List <string> mListData, long QueryCode, long QueryItemCode) { List <string> mListQueryCondition = new List <string>(); int num = mListData.Count; for (int i = 0; i < num; i += 5) { QueryConditionItem queryItem = new QueryConditionItem(); queryItem.QueryConditionCode = QueryCode; queryItem.QueryItemCode = QueryItemCode; queryItem.Type = 1; queryItem.Sort = i; queryItem.Value1 = mListData[i]; if (i + 1 < num) { queryItem.Value2 = mListData[i + 1]; } if (i + 2 < num) { queryItem.Value3 = mListData[i + 2]; } if (i + 3 < num) { queryItem.Value4 = mListData[i + 3]; } if (i + 4 < num) { queryItem.Value5 = mListData[i + 4]; } OperationReturn optReturn = XMLHelper.SeriallizeObject <QueryConditionItem>(queryItem); if (!optReturn.Result) { ShowException(CurrentApp.GetLanguageInfo("", "Save Fail!")); return(new List <string>()); } mListQueryCondition.Add(optReturn.Data as string); } return(mListQueryCondition); }
private bool SaveScoreItemResult() { try { WebRequest webRequest = new WebRequest(); webRequest.Session = CurrentApp.Session; webRequest.Code = (int)S3102Codes.SaveScoreItemResult; webRequest.ListData.Add(ScoreSheetItem.ScoreSheetID.ToString()); webRequest.ListData.Add(ScoreSheetItem.ScoreResultID.ToString()); webRequest.ListData.Add(mListScoreItemResults.Count.ToString()); for (int i = 0; i < mListScoreItemResults.Count; i++) { OperationReturn optReturn = XMLHelper.SeriallizeObject(mListScoreItemResults[i]); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return(false); } webRequest.ListData.Add(optReturn.Data.ToString()); } Service31021Client client = new Service31021Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service31021")); WebReturn webReturn = client.DoOperation(webRequest); client.Close(); if (!webReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", webReturn.Code, webReturn.Message)); return(false); } return(true); } catch (Exception ex) { ShowException(ex.Message); return(false); } }
public static OperationReturn ExecuteStoredProcedure(string strConn, string procedureName, DbParameter[] parameters) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; int count = parameters.Length; SqlConnection sqlConnection = new SqlConnection(strConn); SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlConnection; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = procedureName; for (int i = 0; i < parameters.Length; i++) { sqlCmd.Parameters.Add(parameters[i]); } try { sqlConnection.Open(); sqlCmd.ExecuteNonQuery(); } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_DBACCESS_FAIL; optReturn.Message = ex.Message; } finally { if (sqlConnection.State == ConnectionState.Open) { sqlConnection.Close(); } sqlConnection.Dispose(); } return(optReturn); }
private void UploadFile() { try { string strAddress = "192.168.6.27"; //string strAddress = "192.168.5.31"; int port = 8081 - 3; if (mService03Helper != null) { mService03Helper.Close(); } mService03Helper = new Service03Helper(); mService03Helper.HostAddress = strAddress; mService03Helper.HostPort = port; RequestMessage request = new RequestMessage(); request.Command = (int)Service03Command.UploadFile; request.ListData.Add("123.txt"); request.ListData.Add("1"); request.ListData.Add("test.txt"); OperationReturn optReturn = mService03Helper.DoRequest(request); if (!optReturn.Result) { AppendMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } ReturnMessage ret = optReturn.Data as ReturnMessage; if (ret == null) { AppendMessage(string.Format("Fail.\tReturnMessage is null")); return; } AppendMessage(string.Format("End.")); } catch (Exception ex) { AppendMessage(ex.Message); } }
private void downftp() { string strAddress = "192.168.6.27"; //string strAddress = "192.168.6.75"; int port = 8081 - 3; if (mService03Helper != null) { mService03Helper.Close(); } mService03Helper = new Service03Helper(); mService03Helper.HostAddress = strAddress; mService03Helper.HostPort = port; RequestMessage request = new RequestMessage(); request.Command = (int)Service03Command.DownloadRecordFileNas; request.ListData.Add("192.168.6.27"); request.ListData.Add("21"); request.ListData.Add("ftpuser"); request.ListData.Add("123123"); request.ListData.Add("vox/111.wav"); request.ListData.Add("1505070200000000166"); OperationReturn optReturn = mService03Helper.DoRequest(request); if (!optReturn.Result) { AppendMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } ReturnMessage ret = optReturn.Data as ReturnMessage; if (ret == null) { AppendMessage(string.Format("Fail.\tReturnMessage is null")); return; } AppendMessage(string.Format("End.\t{0}", @"http://192.168.6.27:8081/MediaData/" + ret.Data)); }
private bool DeleteTest(TestInfoParam testInfoParam) { try { WebRequest webRequest = new WebRequest(); webRequest.Session = UMPApp.Session; webRequest.Code = (int)S3603Codes.OptDeleteTestInfo; Service36031Client client = new Service36031Client(WebHelper.CreateBasicHttpBinding(App.Session), WebHelper.CreateEndpointAddress(App.Session.AppServerInfo, "Service36031")); //var client = new Service36031Client(); OperationReturn optReturn = XMLHelper.SeriallizeObject(testInfoParam); if (!optReturn.Result) { UMPApp.ShowExceptionMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return(false); } webRequest.ListData.Add(optReturn.Data.ToString()); //Service36031Client client = new Service36031Client(); WebReturn webReturn = client.UmpTaskOperation(webRequest); client.Close(); if (!webReturn.Result) { UMPApp.ShowExceptionMessage(UMPApp.GetLanguageInfo("3603T00083", "Delete Failed")); return(false); } if (webReturn.Message == S3603Consts.HadUse)// 该查询条件被使用无法删除 { UMPApp.ShowInfoMessage(UMPApp.GetLanguageInfo("3603T00011", "Can't Delete")); return(false); } } catch (Exception ex) { UMPApp.ShowExceptionMessage(ex.Message); return(false); } return(true); }
private void SaveData224002(CVoiceServerBindStrategy cvsbs) { if (cvsbs == null) { return; } try { WebRequest webRequest = new WebRequest(); webRequest.Code = (int)S2400RequestCode.SaveData224002; OperationReturn optReturn = XMLHelper.SeriallizeObject(cvsbs); if (!optReturn.Result) { ShowException(string.Format("{0}\t{1}", "Field.", optReturn.Message)); return; } webRequest.Data = optReturn.Data.ToString(); webRequest.Session = CurrentApp.Session; //Service24011Client client = new Service24011Client(); Service24011Client client = new Service24011Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service24011")); WebReturn webReturn = client.DoOperation(webRequest); client.Close(); if (!webReturn.Result) { ShowException(string.Format("{0}\t{1}", "Field.", webReturn.Message)); return; } string strLog = string.Format("{0}{1}{2}", CurrentApp.Session.UserInfo.UserName, Utils.FormatOptLogString(string.Format("FO2403003")), cvsbs.CusFiled3); CurrentApp.WriteOperationLog("2403003", ConstValue.OPT_RESULT_SUCCESS, strLog); } catch (Exception ex) { string strLog = string.Format("{0}{1}{2}", CurrentApp.Session.UserInfo.UserName, Utils.FormatOptLogString(string.Format("FO2403003")), cvsbs.CusFiled3 + "," + ex.Message); CurrentApp.WriteOperationLog("2403003", ConstValue.OPT_RESULT_FAIL, strLog); ShowException(ex.Message); } }
private bool EnablePaperName() { try { var webRequest = new WebRequest { Session = CurrentApp.Session, Code = (int)S3602Codes.OptPaperSameName }; OperationReturn optReturn = XMLHelper.SeriallizeObject(_mCAddPaper); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return(false); } webRequest.ListData.Add(optReturn.Data.ToString()); var client = new Service36021Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service36021")); //client = new Service36021Client(); var webReturn = client.UmpTaskOperation(webRequest); client.Close(); if (!webReturn.Result) { ShowException(string.Format("{0}{1}", CurrentApp.GetLanguageInfo("3602T00076", "Failed to query the database!"), webReturn.Message)); return(false); } if (webReturn.Message == S3602Consts.PaperExist) { ShowInformation(CurrentApp.GetLanguageInfo("3602T00075", "Paper already exist")); return(false); } } catch (Exception ex) { ShowException(ex.Message); return(false); } return(true); }
/// <summary> /// 获得用户可操作权限 /// </summary> private void GetUserOpts(string strParent) { WebRequest webRequest = new WebRequest(); webRequest.Code = (int)RequestCode.WSGetUserOptList; webRequest.Session = App.Session; webRequest.ListData.Add(App.Session.UserID.ToString()); webRequest.ListData.Add("61"); webRequest.ListData.Add(strParent); Service11012Client client = new Service11012Client(WebHelper.CreateBasicHttpBinding(App.Session), WebHelper.CreateEndpointAddress(App.Session.AppServerInfo, "Service11012")); WebReturn webReturn = client.DoOperation(webRequest); App.MonitorHelper.AddWebReturn(webReturn); client.Close(); if (!webReturn.Result) { App.ShowExceptionMessage(string.Format("WSFail.\t{0}\t{1}", webReturn.Code, webReturn.Message)); return; } for (int i = 0; i < webReturn.ListData.Count; i++) { OperationReturn optReturn = XMLHelper.DeserializeObject <OperationInfo>(webReturn.ListData[i]); if (!optReturn.Result) { App.ShowExceptionMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } OperationInfo optInfo = optReturn.Data as OperationInfo; if (optInfo != null) { optInfo.Display = App.GetLanguageInfo(string.Format("FO{0}", optInfo.ID), optInfo.ID.ToString()); optInfo.Description = optInfo.Display; AllListDashBoard.Add(optInfo); GetUserOpts(optInfo.ID.ToString()); } } }
/// <summary> /// 获得数据库信息 /// </summary> /// <returns></returns> private OperationReturn GetDatabaseInfo() { OperationReturn optReturn = new OperationReturn(); optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; if (App.bIsUMPServer) { //UMP服务器 从programdata下读数据库参数 string strDBFileath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); DatabaseInfo dbInfo = null; optReturn = DatabaseXmlOperator.GetDBInfo(strDBFileath, ref dbInfo); } else if (App.bIsLoggingServer) { //voice服务器 从programdata\VoiceServer下读数据库参数 string strDBFileath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\VoiceServer"; DatabaseInfo dbInfo = null; optReturn = DatabaseXmlOperator.GetDBInfo(strDBFileath, ref dbInfo); } return(optReturn); }
private OperationReturn Connect() { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { if (mIsConnected) { optReturn.Message = string.Format("Already connected.\t{0}\t{1}", mHostAddress, mHostPort); return(optReturn); } mTcpClient = new TcpClient(mHostAddress, mHostPort); if (mTcpClient.Connected) { mSslStream = new SslStream(mTcpClient.GetStream(), false, (sender, cert, chain, errs) => true, null); mSslStream.AuthenticateAsClient(mHostAddress); mIsConnected = true; mLastActiveTime = DateTime.Now; OnDebug(string.Format("Server connected.\t{0}", mTcpClient.Client.RemoteEndPoint)); } else { optReturn.Result = false; optReturn.Code = Defines.RET_NOT_CONNECTED; optReturn.Message = string.Format("TcpClient Connect fail."); } } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
private void ShowRecordOperatorMessage(OperationReturn optReturn) { try { int code = optReturn.Code; switch (code) { case RecordOperator.RET_DOWNLOADSERVER_NOT_EXIST: ShowException(CurrentApp.GetMessageLanguageInfo("014", "Download server not exist.")); break; case RecordOperator.RET_DOWNLOAD_APPSERVER_FAIL: ShowException(CurrentApp.GetMessageLanguageInfo("035", "Download fail")); break; case RecordOperator.RET_GET_REAL_PASSWORD_FAIL: ShowException(CurrentApp.GetMessageLanguageInfo("043", "Get real password fail.")); break; case Service03Consts.DECRYPT_PASSWORD_ERROR: ShowException(CurrentApp.GetMessageLanguageInfo("048", "Decrypt password error")); break; case Defines.RET_TIMEOUT: ShowException(CurrentApp.GetLanguageInfo("3102N047", "Receive message timeout")); break; case RecordOperator.RET_NO_RECORDINFO: ShowException(string.Format("RecordInfo is null")); break; } } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// 创建申诉数量统计的sql语句 /// </summary> /// <param name="session"></param> /// <param name="lstParam"></param> /// lstParam[0] : 开始时间(yyyy-MM-dd hh:mm:ss格式) /// lstParam[1] : 结束时间(yyyy-MM-dd hh:mm:ss格式) /// lstParam[2] : TempID /// <returns></returns> public static OperationReturn CreateSql(SessionInfo session, List <string> lstParam) { OperationReturn optReturn = new OperationReturn(); try { string startTime = lstParam[0]; string EndTime = lstParam[1]; string strTempID = lstParam[2]; string strSql = string.Empty; string strToken = session.RentInfo.Token; switch (session.DBType) { case 2: strSql = string.Format("SELECT * FROM T_31_008_{0} where C006 between '{1}' and '{2}' and C014<>'0'", strToken, startTime, EndTime); break; case 3: strSql = string.Format("SELECT * FROM T_31_008_{0} where " + " C006 >= to_date('{1}','yyyy-mm-dd,hh24:mi:ss') " + "and C006 <= to_date('{2}','yyyy-mm-dd,hh24:mi:ss') and C014<>'0'", strToken, startTime, EndTime); break; } strSql += string.Format(" and C005 in (select C011 from T_00_901 where C001 = {0})", strTempID); optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; optReturn.Data = strSql; optReturn.Message = strSql; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
/// <summary> /// 获得流水号 /// </summary> /// <param name="session"></param> /// <param name="lstParams"></param> /// lstParams[0] : 模块编号 /// lstParams[1] : 模块内编号 /// <returns></returns> private static OperationReturn GetSerialID(SessionInfo session, List <string> lstParams) { OperationReturn optReturn = new OperationReturn(); Service11012Client client = null; try { WebRequest webRequest = new WebRequest(); webRequest.Session = session; webRequest.Code = (int)RequestCode.WSGetSerialID; webRequest.ListData.Add(lstParams[0]); webRequest.ListData.Add(lstParams[1]); webRequest.ListData.Add(DateTime.Now.ToString("yyyyMMddHHmmss")); client = new Service11012Client(WebHelper.CreateBasicHttpBinding(session), WebHelper.CreateEndpointAddress(session.AppServerInfo, "Service11012")); WebReturn webReturn = client.DoOperation(webRequest); optReturn.Data = webReturn.Data; optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; } catch (Exception ex) { optReturn.Result = false; //LogOperation.WriteLog("GetSerialID " + lstParams[1] + " failed: " + ex.Message); } finally { if (client != null) { if (client.State == System.ServiceModel.CommunicationState.Opened) { client.Close(); } } } return(optReturn); }
private void LoadInstallInfo() { try { string strPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), ConstValue.VCT_COMPANY_SHORTNAME, ConstValue.UMP_PRODUCTER_SHORTNAME); if (!Directory.Exists(strPath)) { Directory.CreateDirectory(strPath); } string strFile = Path.Combine(strPath, InstallInfo.FILE_NAME); if (!File.Exists(strFile)) { App.WriteLog("LoadInstallInfo", string.Format("InstallInfo file not exist.\t{0}", strFile)); return; } OperationReturn optReturn = XMLHelper.DeserializeFile <InstallInfo>(strFile); if (!optReturn.Result) { App.WriteLog("LoadInstallInfo", string.Format("InstallInfo file invalid.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } InstallInfo installInfo = optReturn.Data as InstallInfo; if (installInfo == null) { App.WriteLog("LoadInstallInfo", string.Format("InstallInfo is null")); return; } mInstallInfo = installInfo; } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// 获得用户可操作权限 /// </summary> private void GetUserOpts() { WebRequest webRequest = new WebRequest(); webRequest.Code = (int)RequestCode.WSGetUserOptList; webRequest.Session = CurrentApp.Session; webRequest.ListData.Add(CurrentApp.Session.UserID.ToString()); webRequest.ListData.Add("24"); webRequest.ListData.Add("2403"); Service11012Client client = new Service11012Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service11012")); WebReturn webReturn = client.DoOperation(webRequest); CurrentApp.MonitorHelper.AddWebReturn(webReturn); client.Close(); if (!webReturn.Result) { ShowException(string.Format("WSFail.\t{0}\t{1}", webReturn.Code, webReturn.Message)); return; } ListOperationsOnlyAdd.Clear(); AllListOperations.Clear(); for (int i = 0; i < webReturn.ListData.Count; i++) { OperationReturn optReturn = XMLHelper.DeserializeObject <OperationInfo>(webReturn.ListData[i]); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } OperationInfo optInfo = optReturn.Data as OperationInfo; if (optInfo != null) { AllListOperations.Add(optInfo); } } }
public virtual OperationReturn DoAppCommand(WebRequest webRequest) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { int code = webRequest.Code; switch (code) { case (int)RequestCode.CSModuleClose: Exit(); break; } } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
private void LoadConfig() { try { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SystemConfig.FILE_NAME); OperationReturn optReturn = XMLHelper.DeserializeFile <SystemConfig>(path); if (!optReturn.Result) { ShowException(string.Format("load system config fail. [{0}]{1}", optReturn.Code, optReturn.Message)); return; } SystemConfig config = optReturn.Data as SystemConfig; if (config == null) { ShowException(string.Format("system config is null.")); return; } mSystemConfig = config; } catch (Exception ex) { ShowException(string.Format("Load system config fail. \r\n{0}", ex.Message)); } }
/// <summary> /// 停止帮助器,在不用时调用以关闭Socket连接并清理资源 /// </summary> /// <returns></returns> public OperationReturn Stop() { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { if (mThreadCheck != null) { try { mThreadCheck.Abort(); mThreadCheck = null; } catch { } } if (mThreadReceive != null) { try { mThreadReceive.Abort(); mThreadReceive = null; } catch { } } Close(); } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
private void LoadUpdateConfig() { try { string strPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, UpdateConfig.FILE_NAME); if (!File.Exists(strPath)) { ShowException(string.Format("UpdateConfig file not exist.\t{0}", strPath)); return; } OperationReturn optReturn = XMLHelper.DeserializeFile <UpdateConfig>(strPath); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } var config = optReturn.Data as UpdateConfig; if (config == null) { ShowException(string.Format("UpdateConfig is null")); return; } mUpdateConfig = config; mDatabaseInfo = mUpdateConfig.DatabaseInfo; if (mDatabaseInfo != null) { mDatabaseInfo.RealPassword = mDatabaseInfo.Password; mDBConnectionString = mDatabaseInfo.GetConnectionString(); } mCurrentVersion = mListVersionsItems.FirstOrDefault(v => v.StrValue == mUpdateConfig.CurrentVersion); } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// 删掉离线消息 /// </summary> /// <param name="session"></param> /// <param name="lstParams"></param> /// lstParams[0] : /// <returns></returns> public static OperationReturn DelteOfflineMsg(SessionInfo session, List <string> lstParams) { OperationReturn optReturn = new OperationReturn(); try { string strToken = session.RentInfo.Token; string strSql = string.Empty; switch (session.DBType) { case 2: strSql = "delete from t_16_003_{0} where C000= {1}"; strSql = string.Format(strSql, strToken, lstParams[0]); optReturn = MssqlOperation.ExecuteSql(session.DBConnectionString, strSql); break; case 3: strSql = "delete from t_16_003_{0} where C000= {1}"; strSql = string.Format(strSql, strToken, lstParams[0]); optReturn = OracleOperation.ExecuteSql(session.DBConnectionString, strSql); break; } if (!optReturn.Result) { //LogOperation.WriteLog("Delete offline message error : " + optReturn.Message); return(optReturn); } } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; //LogOperation.WriteLog("Delete offline message exception : " + ex.Message); } return(optReturn); }
/// <summary> /// 下载MediaUtils文件夹中的文件,如果已经下载过(存在FileList.txt文件)则跳过 /// </summary> /// <param name="session"></param> /// <returns></returns> public static OperationReturn DownloadMediaUtils(SessionInfo session) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { //添加Path环境变量 optReturn = SetMeidaUtilsPath(); if (!optReturn.Result) { return(optReturn); } //下载到本应用程序域 optReturn = DownloadMediaUtilsDomain(session); if (!optReturn.Result) { return(optReturn); } //下载到公共临时目录 optReturn = DownloadMediaUtilsCommon(session); if (!optReturn.Result) { return(optReturn); } } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } return(optReturn); }
private void LoadSessionInfo() { try { string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), ConstValue.TEMP_DIR_UMP, AppName, ConstValue.TEMP_FILE_UMPSESSION); if (!File.Exists(path)) { WriteLog("AppLoad", string.Format("umpsession.xml not exist.\t{0}", path)); return; } OperationReturn optReturn = XMLHelper.DeserializeFile <SessionInfo>(path); if (!optReturn.Result) { WriteLog("AppLoad", string.Format("Load SessionInfo from xml file fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } SessionInfo session = optReturn.Data as SessionInfo; if (session == null) { WriteLog("AppLoad", string.Format("Load SessionInfo from xml file fail.\tSessionInfo is null")); return; } Session.SetSessionInfo(session); Session.IsMonitor = session.IsMonitor; WriteLog("AppLoad", string.Format("Load SessionInfo from xml file end.")); } catch (Exception ex) { WriteLog("AppLoad", string.Format("Load SessionInfo from xml file fail.\t{0}", ex.Message)); } }
private bool WriteTestInfo(TestInfoParam testInformation) { string strLog; try { var webRequest = new WebRequest { Session = CurrentApp.Session, Code = (int)S3603Codes.OptAddTestInfo }; OperationReturn optReturn = XMLHelper.SeriallizeObject(testInformation); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return(false); } webRequest.ListData.Add(optReturn.Data.ToString()); var client = new Service36031Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service36031")); //var client = new Service36031Client(); var webReturn = client.UmpTaskOperation(webRequest); client.Close(); CurrentApp.WriteLog(CurrentApp.GetLanguageInfo("3603T00006", "Create")); if (!webReturn.Result) { #region 写操作日志 strLog = string.Format("{0} {1} : {2}", Utils.FormatOptLogString("3603T00006"), Utils.FormatOptLogString("3603T00091"), webReturn.Message); CurrentApp.WriteOperationLog(S3603Consts.OPT_Add.ToString(), ConstValue.OPT_RESULT_FAIL, strLog); #endregion CurrentApp.WriteLog(webReturn.Message); ShowException(webReturn.Message); return(false); } #region 写操作日志 strLog = string.Format("{0} {1}", Utils.FormatOptLogString("3603T00006"), Utils.FormatOptLogString("3603T00092")); CurrentApp.WriteOperationLog(S3603Consts.OPT_Add.ToString(), ConstValue.OPT_RESULT_SUCCESS, strLog); #endregion CurrentApp.WriteLog(CurrentApp.GetLanguageInfo("3603T00092", "Create Success")); } catch (Exception ex) { #region 写操作日志 strLog = string.Format("{0} {1} : {2}", Utils.FormatOptLogString("3603T00006"), Utils.FormatOptLogString("3603T00091"), ex.Message); CurrentApp.WriteOperationLog(S3603Consts.OPT_Add.ToString(), ConstValue.OPT_RESULT_FAIL, strLog); #endregion CurrentApp.WriteLog(ex.Message); ShowException(ex.Message); return(false); } return(true); }
private OperationReturn SyncExtension(List <string> listParams) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { #region 解析参数 //ListParams //参考S000ACodes中的说明,此处从略 if (listParams == null || listParams.Count < 3) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Request param is null or count invalid"); return(optReturn); } string strUserID = listParams[0]; string strTenantOrgToken = listParams[1]; string strCount = listParams[2]; WriteOperationLog(string.Format("SyncExtension:\tUserID:{0};TenantOrgToken:{1};Count:{2}", strUserID, strTenantOrgToken, strCount)); #endregion #region 检查参数有效性 int tenantOrgToken; if (!int.TryParse(strTenantOrgToken, out tenantOrgToken) || tenantOrgToken <= 0) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Param TenantOrgToken invalid."); return(optReturn); } int intCount; if (!int.TryParse(strCount, out intCount) || intCount < 0) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Param Count invalid."); return(optReturn); } if (listParams.Count < intCount + 3) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Extension Count invalid."); return(optReturn); } #endregion #region 得到分机列表 List <ExtensionInfo> listExtensions = new List <ExtensionInfo>(); for (int i = 0; i < intCount; i++) { string strInfo = listParams[i + 3]; JsonObject jsonExt = null; try { jsonExt = new JsonObject(strInfo); } catch { } if (jsonExt != null) { ExtensionInfo info = new ExtensionInfo(); if (jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_EXTENSION] != null) { info.Extension = jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_EXTENSION].Value; } if (jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_CHANNELNAME] != null) { info.ChannelName = jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_CHANNELNAME].Value; } if (jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_SERVERIP] != null) { info.ServerIP = jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_SERVERIP].Value; } if (jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_CHANNELID] != null) { info.ChannelID = (int)jsonExt[S000AConsts.FIELD_NAME_EXTENSIONINFO_CHANNELID].Number; } listExtensions.Add(info); } } WriteOperationLog(string.Format("ListExtension:{0}", listExtensions.Count)); #endregion #region 获取数据库信息 optReturn = ReadDatabaseInfo(); if (!optReturn.Result) { return(optReturn); } DatabaseInfo dbInfo = optReturn.Data as DatabaseInfo; if (dbInfo == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("DatabaseInfo is null"); return(optReturn); } WriteOperationLog(string.Format("DatabaseInfo:{0}", dbInfo)); #endregion #region 根据TenantOrgToken获取数据库中分机信息列表 string strConn = dbInfo.GetConnectionString(); string strRentToken = "00000"; string strSql; int dbType = dbInfo.TypeID; DataSet objDataSet; int addNum = 0; int modifyNum = 0; List <string> listReturn = new List <string>(); #region 租户机构编号 string strOrgID = string.Format("10114010100000{0}", tenantOrgToken.ToString("00000")); long orgID = long.Parse(strOrgID); long orgAdminID = 0; #endregion #region 获取租户管理员编号 if (tenantOrgToken > 0) { switch (dbType) { case 2: strSql = string.Format("SELECT * FROM T_11_005_{0} WHERE C006 = {1} AND C027 = '1'", strRentToken, orgID); optReturn = MssqlOperation.GetDataSet(strConn, strSql); break; case 3: strSql = string.Format("SELECT * FROM T_11_005_{0} WHERE C006 = {1} AND C027 = '1'", strRentToken, orgID); optReturn = OracleOperation.GetDataSet(strConn, strSql); break; default: optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("DBType invalid"); return(optReturn); } if (!optReturn.Result) { return(optReturn); } objDataSet = optReturn.Data as DataSet; if (objDataSet == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("DataSet is null."); return(optReturn); } if (objDataSet.Tables[0].Rows.Count <= 0) { optReturn.Result = false; optReturn.Code = Defines.RET_NOT_EXIST; optReturn.Message = string.Format("TenantOrg admin not exist."); return(optReturn); } DataRow dr = objDataSet.Tables[0].Rows[0]; orgAdminID = Convert.ToInt64(dr["C001"]); } if (orgAdminID <= 0) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("TenantOrg admin invalid."); return(optReturn); } #endregion #region 首先获取该TenantOrgToken下的分机编号 List <ExtensionInfo> listExts = new List <ExtensionInfo>(); switch (dbType) { case 2: strSql = string.Format( "SELECT C001 FROM T_11_101_{0} WHERE C001 > 1040000000000000000 AND C001 < 1050000000000000000 AND C002 = 3 AND C011 = '{1}' ORDER BY C001, C002", strRentToken, tenantOrgToken); optReturn = MssqlOperation.GetDataSet(strConn, strSql); break; case 3: strSql = string.Format( "SELECT C001 FROM T_11_101_{0} WHERE C001 > 1040000000000000000 AND C001 < 1050000000000000000 AND C002 = 3 AND C011 = '{1}' ORDER BY C001, C002", strRentToken, tenantOrgToken); optReturn = OracleOperation.GetDataSet(strConn, strSql); break; default: optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("DBType invalid"); return(optReturn); } if (!optReturn.Result) { return(optReturn); } objDataSet = optReturn.Data as DataSet; if (objDataSet == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("DataSet is null"); return(optReturn); } for (int i = 0; i < objDataSet.Tables[0].Rows.Count; i++) { DataRow dr = objDataSet.Tables[0].Rows[i]; long id = Convert.ToInt64(dr["C001"]); ExtensionInfo info = new ExtensionInfo(); info.ObjID = id; listExts.Add(info); } #endregion IDbConnection objConn; IDbDataAdapter objAdapter; DbCommandBuilder objCmdBuilder; #region 遍历每个分机,获取分机的配置信息,然后更新分机信息 bool isModify; for (int i = 0; i < listExts.Count; i++) { ExtensionInfo extInfo = listExts[i]; long id = extInfo.ObjID; switch (dbType) { case 2: strSql = string.Format("SELECT * FROM T_11_101_{0} WHERE C001 = {1} ORDER BY C001, C002", strRentToken, id); objConn = MssqlOperation.GetConnection(strConn); objAdapter = MssqlOperation.GetDataAdapter(objConn, strSql); objCmdBuilder = MssqlOperation.GetCommandBuilder(objAdapter); break; case 3: strSql = string.Format("SELECT * FROM T_11_101_{0} WHERE C001 = {1} ORDER BY C001, C002", strRentToken, id); objConn = OracleOperation.GetConnection(strConn); objAdapter = OracleOperation.GetDataAdapter(objConn, strSql); objCmdBuilder = OracleOperation.GetCommandBuilder(objAdapter); break; default: optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("DBType invalid"); return(optReturn); } if (objConn == null || objAdapter == null || objCmdBuilder == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("Database object is null"); return(optReturn); } objCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges; objCmdBuilder.SetAllValues = false; try { objDataSet = new DataSet(); objAdapter.Fill(objDataSet); for (int j = 0; j < objDataSet.Tables[0].Rows.Count; j++) { DataRow dr = objDataSet.Tables[0].Rows[j]; #region 更新 isModify = false; int rowID = Convert.ToInt32(dr["C002"]); if (rowID == 1) { string strExt01017 = dr["C017"].ToString(); //01017代表分机名称(分机号+IP的形式) strExt01017 = DecryptFromDB(strExt01017); string[] arrInfos = strExt01017.Split(new[] { ConstValue.SPLITER_CHAR }, StringSplitOptions.None); if (arrInfos.Length > 0) { string strExt = arrInfos[0]; extInfo.Extension = strExt; } string strExt01018 = dr["C018"].ToString(); strExt01018 = DecryptFromDB(strExt01018); extInfo.ChannelName = strExt01018; } var temp = listExtensions.FirstOrDefault(e => e.Extension == extInfo.Extension); if (temp != null) { temp.ObjID = id; extInfo.ChannelName = temp.ChannelName; isModify = true; modifyNum++; } if (isModify) { string strExt01018 = extInfo.ChannelName; strExt01018 = EncryptToDB(strExt01018); if (rowID == 1) { dr["C012"] = "1"; dr["C013"] = "0"; dr["C014"] = "0"; dr["C015"] = "N"; dr["C018"] = strExt01018; } } #endregion } objAdapter.Update(objDataSet); objDataSet.AcceptChanges(); } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } objConn.Dispose(); } } #endregion #region 遍历每个分机,如果是需要新增的,增加分机信息 bool isAdd = false; for (int i = 0; i < listExtensions.Count; i++) { ExtensionInfo extInfo = listExtensions[i]; long id = extInfo.ObjID; if (id <= 0) { isAdd = isAdd || true; } } if (isAdd) { switch (dbType) { case 2: strSql = string.Format("SELECT * FROM T_11_101_{0} WHERE 1 = 2 ORDER BY C001, C002", strRentToken); objConn = MssqlOperation.GetConnection(strConn); objAdapter = MssqlOperation.GetDataAdapter(objConn, strSql); objCmdBuilder = MssqlOperation.GetCommandBuilder(objAdapter); break; case 3: strSql = string.Format("SELECT * FROM T_11_101_{0} WHERE 1 = 2 ORDER BY C001, C002", strRentToken); objConn = OracleOperation.GetConnection(strConn); objAdapter = OracleOperation.GetDataAdapter(objConn, strSql); objCmdBuilder = OracleOperation.GetCommandBuilder(objAdapter); break; default: optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("DBType invalid"); return(optReturn); } if (objConn == null || objAdapter == null || objCmdBuilder == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("Database object is null"); return(optReturn); } objCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges; objCmdBuilder.SetAllValues = false; try { objDataSet = new DataSet(); objAdapter.Fill(objDataSet); for (int i = 0; i < listExtensions.Count; i++) { ExtensionInfo extInfo = listExtensions[i]; long id = extInfo.ObjID; if (id <= 0) { #region 生成流水号 List <string> listSubParams = new List <string>(); listSubParams.Add("11"); listSubParams.Add("104"); listSubParams.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); optReturn = GetSerialID(listSubParams); if (!optReturn.Result) { return(optReturn); } id = Convert.ToInt64(optReturn.Data.ToString()); extInfo.ObjID = id; #endregion #region 新增 DataRow dr1 = objDataSet.Tables[0].NewRow(); dr1["C001"] = id; dr1["C002"] = 1; dr1["C011"] = orgID; dr1["C012"] = "1"; dr1["C013"] = "1"; dr1["C014"] = "0"; dr1["C015"] = "N"; dr1["C016"] = "05"; string str01017 = string.Format("{0}{1}{2}", extInfo.Extension, ConstValue.SPLITER_CHAR, extInfo.ServerIP); str01017 = EncryptToDB(str01017); dr1["C017"] = str01017; string str01018 = extInfo.ChannelName; str01018 = EncryptToDB(str01018); dr1["C018"] = str01018; DataRow dr2 = objDataSet.Tables[0].NewRow(); dr2["C001"] = id; dr2["C002"] = 2; DataRow dr3 = objDataSet.Tables[0].NewRow(); dr3["C001"] = id; dr3["C002"] = 3; dr3["C011"] = tenantOrgToken; objDataSet.Tables[0].Rows.Add(dr1); objDataSet.Tables[0].Rows.Add(dr2); objDataSet.Tables[0].Rows.Add(dr3); addNum++; #endregion #region 新增的分机要添加到系统管理员权限列表中 if (id > 0) { switch (dbType) { case 2: strSql = string.Format( "INSERT INTO T_11_201_{0} VALUES (0, 0, {1}, {2}, '2014/1/1', '2199/12/31')", strRentToken, ConstValue.USER_ADMIN, id); optReturn = MssqlOperation.ExecuteSql(strConn, strSql); break; case 3: strSql = string.Format( "INSERT INTO T_11_201_{0} VALUES (0, 0, {1}, {2}, TO_DATE('2014/1/1','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2199/12/31','YYYY-MM-DD HH24:MI:SS'))", strRentToken, ConstValue.USER_ADMIN, id); optReturn = OracleOperation.ExecuteSql(strConn, strSql); break; default: optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("DBType invalid"); return(optReturn); } if (!optReturn.Result) { return(optReturn); } } #endregion #region 新增的分机要添加到租户管理员的管理权限列表中 if (id > 0) { switch (dbType) { case 2: strSql = string.Format( "INSERT INTO T_11_201_{0} VALUES (0, 0, {1}, {2}, '2014/1/1', '2199/12/31')", strRentToken, orgAdminID, id); optReturn = MssqlOperation.ExecuteSql(strConn, strSql); break; case 3: strSql = string.Format( "INSERT INTO T_11_201_{0} VALUES (0, 0, {1}, {2}, TO_DATE('2014/1/1','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2199/12/31','YYYY-MM-DD HH24:MI:SS'))", strRentToken, orgAdminID, id); optReturn = OracleOperation.ExecuteSql(strConn, strSql); break; default: optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("DBType invalid"); return(optReturn); } if (!optReturn.Result) { return(optReturn); } } #endregion } } objAdapter.Update(objDataSet); objDataSet.AcceptChanges(); } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } objConn.Dispose(); } } #endregion listReturn.Add(addNum.ToString()); listReturn.Add(modifyNum.ToString()); optReturn.Data = listReturn; #endregion } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } return(optReturn); }
private void GetChildDirItems(ObjectItem parentItem) { try { string strAddress = string.Empty; if (string.IsNullOrEmpty(strAddress)) { ShowException(string.Format("Server address is empty")); return; } if (parentItem == null) { return; } var parentDir = parentItem.Data as DirInfo; if (parentDir == null) { return; } ServerRequestInfo requestInfo = new ServerRequestInfo(); requestInfo.ServerHost = strAddress; requestInfo.ServerPort = 8009; requestInfo.Command = (int)ServerRequestCommand.GetChildDirectoryList; requestInfo.ListData.Add(parentDir.Path); OperationReturn optReturn = XMLHelper.SeriallizeObject(requestInfo); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } WebRequest webRequest = new WebRequest(); webRequest.Session = CurrentApp.Session; webRequest.Code = (int)S1110Codes.GetServerInfo; webRequest.Data = optReturn.Data.ToString(); Service11102Client client = new Service11102Client( WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress( CurrentApp.Session.AppServerInfo, "Service11102")); WebReturn webReturn = null; if (MainPage != null) { MainPage.SetBusy(true, CurrentApp.GetMessageLanguageInfo("004", "Getting server directory information")); } mWorker = new BackgroundWorker(); mWorker.DoWork += (s, de) => { try { webReturn = client.DoOperation(webRequest); client.Close(); } catch (Exception ex) { ShowException(ex.Message); } }; mWorker.RunWorkerCompleted += (s, re) => { mWorker.Dispose(); if (MainPage != null) { MainPage.SetBusy(false, string.Empty); } if (!webReturn.Result) { ShowException(string.Format("WSFail.\t{0}\t{1}", webReturn.Code, webReturn.Message)); return; } if (webReturn.ListData == null) { ShowException(string.Format("ListData is null")); return; } parentItem.Children.Clear(); for (int i = 0; i < webReturn.ListData.Count; i++) { string info = webReturn.ListData[i]; string[] arrInfo = info.Split(new[] { ConstValue.SPLITER_CHAR }, StringSplitOptions.None); if (arrInfo.Length < 2) { continue; } DirInfo dirInfo = new DirInfo(); dirInfo.Name = arrInfo[0]; dirInfo.Path = arrInfo[1]; ObjectItem item = new ObjectItem(); item.Type = S1110Consts.OBJECTITEMTYPE_DIRINFO; item.Name = dirInfo.Name; item.Icon = string.Format("../Themes/Default/UMPS1110/Images/{0}", "folder.png"); item.Description = dirInfo.Path; item.Data = dirInfo; parentItem.AddChild(item); } if (mConfigObject != null) { switch (mConfigObject.ObjectType) { case S1110Consts.RESOURCE_VOICESERVER: case S1110Consts.RESOURCE_NTIDRVPATH: //GetChildFileItems(parentItem); break; } } parentItem.IsExpanded = true; }; mWorker.RunWorkerAsync(); } catch (Exception ex) { ShowException(ex.Message); } }
public static OperationReturn Operation(System.Drawing.Image image, OperationType type, OperationParams parameters) { System.Drawing.Image cropImage = null; System.Drawing.Image newImage = null; System.Drawing.Image zoomedImage = null; System.Drawing.Image overlayImage = null; System.Drawing.Image sonyOverlayImage = null; System.Drawing.Image thinkBottomLeftOverlayImage = null; System.Drawing.Image thinkTextBottomLeftOverlayImage = null; Graphics cropGraphic = null; Graphics newFullGraphic = null; Graphics zoomedGraphic = null; try { #region Convert any image with an indexed pixel format to JPG if (image.PixelFormat.Equals(PixelFormat.Format1bppIndexed) || image.PixelFormat.Equals(PixelFormat.Format4bppIndexed) || image.PixelFormat.Equals(PixelFormat.Format8bppIndexed) || image.PixelFormat.Equals(PixelFormat.Undefined) || image.PixelFormat.Equals(PixelFormat.DontCare) || image.PixelFormat.Equals(PixelFormat.Format16bppArgb1555) || image.PixelFormat.Equals(PixelFormat.Format16bppGrayScale)) { MemoryStream converterStream = new MemoryStream(); ImageCodecInfo jpgEncoder = ImageCodecInfo.GetImageEncoders()[1]; EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(2); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); encoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24L); image.Save(converterStream, jpgEncoder, encoderParams); image.Dispose(); image = null; image = System.Drawing.Image.FromStream(converterStream); } #endregion int CropWidth = 0; int CropHeight = 0; int CropX = 0; int CropY = 0; int ResizeWidth = 0; int ResizeHeight = 0; bool portrait = image.Height > image.Width; #region Work out crop / zoom image sizes from input data if (type == OperationType.Crop) { CropWidth = parameters.CropSize.Width; CropHeight = parameters.CropSize.Height; CropX = parameters.CropOffset.Width; CropY = parameters.CropOffset.Height; ResizeWidth = parameters.CropResize.Width; ResizeHeight = parameters.CropResize.Height; if (CropWidth > ResizeWidth || CropHeight > ResizeHeight) { double horizontalScale = (double)CropWidth / (double)ResizeWidth; double verticalScale = (double)CropHeight / (double)ResizeHeight; if (horizontalScale > verticalScale) { ResizeWidth = CropWidth; ResizeHeight = (int)Math.Ceiling(ResizeHeight * horizontalScale); } else { ResizeWidth = (int)Math.Ceiling(ResizeWidth * verticalScale); ResizeHeight = CropHeight; } } if (CropX + CropWidth > ResizeWidth) CropX = ResizeWidth - CropWidth; if (CropX < 0) CropX = 0; if (CropY + CropHeight > ResizeHeight) CropY = ResizeHeight - CropHeight; if (CropY < 0) CropY = 0; } else if (type == OperationType.MaxSide) { if (portrait) { if (parameters.AllowMaxSideToEnlarge || image.Height > parameters.MaxSide) { CropHeight = parameters.MaxSide; CropWidth = (int)Math.Floor(((double)parameters.MaxSide / (double)image.Height) * image.Width); } else { CropHeight = image.Height; CropWidth = image.Width; } } else { if (parameters.AllowMaxSideToEnlarge || image.Width > parameters.MaxSide) { CropWidth = parameters.MaxSide; CropHeight = (int)Math.Floor(((double)parameters.MaxSide / (double)image.Width) * image.Height); } else { CropHeight = image.Height; CropWidth = image.Width; } } ResizeWidth = CropWidth; ResizeHeight = CropHeight; CropX = 0; CropY = 0; } else { CropHeight = parameters.FixedSize.Height; CropWidth = parameters.FixedSize.Width; if (portrait) { ResizeWidth = CropWidth; ResizeHeight = (int)Math.Floor(((double)parameters.FixedSize.Width / (double)image.Width) * image.Height); } else { ResizeHeight = CropHeight; ResizeWidth = (int)Math.Floor(((double)parameters.FixedSize.Height / (double)image.Height) * image.Width); } CropX = (int)Math.Floor((ResizeWidth - CropWidth) / 2.0); CropY = (int)Math.Floor((ResizeHeight - CropHeight) / 2.0); } #endregion #region If we are within 2 pixels of the edge of the image, we have to do this nasty kludge to avoid a black halo if (CropX < 2 || CropY < 2 || (CropX + CropWidth > ResizeWidth - 2) || (CropY + CropHeight > ResizeHeight - 2)) { int size = (int)Math.Ceiling((((double)image.Width / (double)ResizeWidth) * 5)); newImage = new Bitmap(image.Width + (2 * size), image.Height + (2 * size), image.PixelFormat); newFullGraphic = Graphics.FromImage(newImage); newFullGraphic.CompositingMode = CompositingMode.SourceCopy; newFullGraphic.PixelOffsetMode = PixelOffsetMode.None; newFullGraphic.CompositingQuality = CompositingQuality.Default; newFullGraphic.SmoothingMode = SmoothingMode.None; newFullGraphic.InterpolationMode = InterpolationMode.NearestNeighbor; newFullGraphic.DrawImage(image, new Rectangle(size, size, image.Width, image.Height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);//Full image newFullGraphic.DrawImage(image, new Rectangle(0, size, size, image.Height), new Rectangle(0, 0, 1, image.Height), GraphicsUnit.Pixel);//left newFullGraphic.DrawImage(image, new Rectangle(image.Width + size, size, size, image.Height), new Rectangle(image.Width - 2, 0, 1, image.Height), GraphicsUnit.Pixel);//right newFullGraphic.DrawImage(image, new Rectangle(size, 0, image.Width, size), new Rectangle(0, 0, image.Width, 1), GraphicsUnit.Pixel);//top newFullGraphic.DrawImage(image, new Rectangle(size, image.Height + size, image.Width, size), new Rectangle(0, image.Height - 2, image.Width, 1), GraphicsUnit.Pixel);//bottom newFullGraphic.DrawImage(image, new Rectangle(0, 0, size, size), new Rectangle(0, 0, 1, 1), GraphicsUnit.Pixel);//top-left newFullGraphic.DrawImage(image, new Rectangle(image.Width + size, 0, size, size), new Rectangle(image.Width - 2, 0, 1, 1), GraphicsUnit.Pixel);//top-right newFullGraphic.DrawImage(image, new Rectangle(0, image.Height + size, size, size), new Rectangle(0, image.Height - 2, 1, 1), GraphicsUnit.Pixel);//bottom-left newFullGraphic.DrawImage(image, new Rectangle(image.Width + size, image.Height + size, size, size), new Rectangle(image.Width - 2, image.Height - 2, 1, 1), GraphicsUnit.Pixel);//bottom-right CropX += 5; CropY += 5; ResizeWidth += 10; ResizeHeight += 10; } else { newImage = image; } #endregion #region Resize... zoomedImage = new Bitmap(ResizeWidth, ResizeHeight, newImage.PixelFormat); zoomedGraphic = Graphics.FromImage(zoomedImage); ApplyGraphicQualityProperties(zoomedGraphic); Rectangle zoomedRectangle = new Rectangle(0, 0, ResizeWidth, ResizeHeight); zoomedGraphic.DrawImage(newImage, zoomedRectangle); #endregion #region Crop... Rectangle cropRectangle = new Rectangle(CropX, CropY, CropWidth, CropHeight); cropImage = new Bitmap(CropWidth, CropHeight, newImage.PixelFormat); cropGraphic = Graphics.FromImage(cropImage); ApplyGraphicQualityProperties(cropGraphic); Rectangle destRectangle = new Rectangle(0, 0, CropWidth, CropHeight); cropGraphic.DrawImage(zoomedImage, destRectangle, cropRectangle, GraphicsUnit.Pixel); #endregion #region Overlay... if ( parameters.Overlay.Equals(Overlays.DsiLogoBottomRight) //|| //parameters.Overlay.Equals(Overlays.DsiLogoBottomRightSonyBottomLeft) || //parameters.Overlay.Equals(Overlays.DsiLogoBottomRightSonyC902BottomLeft) || //parameters.Overlay.Equals(Overlays.DsiLogoBottomRightThinkBottomLeft) || //parameters.Overlay.Equals(Overlays.DsiLogoBottomRightThinkTextBottomLeft) ) { overlayImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Bobs.Overlay.new-logo-overlay.png")); Rectangle overlayRectangle = new Rectangle(0, 0, overlayImage.Width, overlayImage.Height); Rectangle destinationRectangle = new Rectangle(6, CropHeight - overlayImage.Height - 6, overlayImage.Width, overlayImage.Height); cropGraphic.DrawImage(overlayImage, destinationRectangle, overlayRectangle, GraphicsUnit.Pixel); //if (parameters.Overlay.Equals(Overlays.DsiLogoBottomRightSonyC902BottomLeft) && // (Vars.DevEnv || (DateTime.Now >= new DateTime(2008, 07, 01) && DateTime.Now < new DateTime(2008, 10, 01))) // ) //{ // string sonyOverlayFullFileName = Vars.MapPath("~/gfx/overlay-sonyc902.png"); // sonyOverlayImage = new Bitmap(sonyOverlayFullFileName); // Rectangle sonyOverlayRectangle = new Rectangle(0, 0, sonyOverlayImage.Width, sonyOverlayImage.Height); // Rectangle sonyDestinationRectangle = new Rectangle(5, CropHeight - sonyOverlayImage.Height - 5, sonyOverlayImage.Width, sonyOverlayImage.Height); // cropGraphic.DrawImage(sonyOverlayImage, sonyDestinationRectangle, sonyOverlayRectangle, GraphicsUnit.Pixel); //} //if (parameters.Overlay.Equals(Overlays.DsiLogoBottomRightSonyBottomLeft) && // (Vars.DevEnv || (DateTime.Now >= new DateTime(2006, 08, 01) && DateTime.Now < new DateTime(2006, 10, 01))) // ) //{ // string sonyOverlayFullFileName = Vars.MapPath("~/gfx/sony-overlay.png"); // sonyOverlayImage = new Bitmap(sonyOverlayFullFileName); // Rectangle sonyOverlayRectangle = new Rectangle(0, 0, sonyOverlayImage.Width, sonyOverlayImage.Height); // Rectangle sonyDestinationRectangle = new Rectangle(0, CropHeight - sonyOverlayImage.Height, sonyOverlayImage.Width, sonyOverlayImage.Height); // cropGraphic.DrawImage(sonyOverlayImage, sonyDestinationRectangle, sonyOverlayRectangle, GraphicsUnit.Pixel); //} //if (parameters.Overlay.Equals(Overlays.DsiLogoBottomRightThinkBottomLeft)) //{ // string extraOverlayFullFileName = Vars.MapPath("~/gfx/think-overlay.png"); // thinkBottomLeftOverlayImage = new Bitmap(extraOverlayFullFileName); // Rectangle extraOverlayRectangle = new Rectangle(0, 0, thinkBottomLeftOverlayImage.Width, thinkBottomLeftOverlayImage.Height); // Rectangle extraDestinationRectangle = new Rectangle(5, CropHeight - thinkBottomLeftOverlayImage.Height - 5, thinkBottomLeftOverlayImage.Width, thinkBottomLeftOverlayImage.Height); // cropGraphic.DrawImage(thinkBottomLeftOverlayImage, extraDestinationRectangle, extraOverlayRectangle, GraphicsUnit.Pixel); //} //if (parameters.Overlay.Equals(Overlays.DsiLogoBottomRightThinkTextBottomLeft)) //{ // string extraOverlayFullFileName = Vars.MapPath("~/gfx/thinktext-overlay.png"); // thinkTextBottomLeftOverlayImage = new Bitmap(extraOverlayFullFileName); // Rectangle extraOverlayRectangle = new Rectangle(0, 0, thinkTextBottomLeftOverlayImage.Width, thinkTextBottomLeftOverlayImage.Height); // Rectangle extraDestinationRectangle = new Rectangle(0, CropHeight - thinkTextBottomLeftOverlayImage.Height - 12, thinkTextBottomLeftOverlayImage.Width, thinkTextBottomLeftOverlayImage.Height); // cropGraphic.DrawImage(thinkTextBottomLeftOverlayImage, extraDestinationRectangle, extraOverlayRectangle, GraphicsUnit.Pixel); //} } else if (parameters.Overlay.Equals(Overlays.PlayButtonLarge) || parameters.Overlay.Equals(Overlays.PlayButtonSmall)) { if (parameters.Overlay.Equals(Overlays.PlayButtonLarge)) overlayImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Bobs.Overlay.video-button.png")); else overlayImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Bobs.Overlay.video-button-small.png")); Rectangle overlayRectangle = new Rectangle(0, 0, overlayImage.Width, overlayImage.Height); Rectangle destinationRectangle = new Rectangle((int)Math.Floor((CropWidth / 2.0) - (overlayImage.Width / 2.0)), (int)Math.Floor((CropHeight / 2.0) - (overlayImage.Height / 2.0)), overlayImage.Width, overlayImage.Height); cropGraphic.DrawImage(overlayImage, destinationRectangle, overlayRectangle, GraphicsUnit.Pixel); } #endregion if (parameters.FileName != null && parameters.FileName.Length > 0) SaveJPGWithCompressionSetting(cropImage, parameters.FileName, (long)85.0); OperationReturn operationReturn = new OperationReturn(); operationReturn.ImageSize = new Size(cropImage.Width, cropImage.Height); if (parameters.ReturnBytes) operationReturn.Bytes = SaveJPGWithCompressionSetting(cropImage, (long)85.0); return operationReturn; } finally { if (cropImage != null) cropImage.Dispose(); if (newImage != null) newImage.Dispose(); if (zoomedImage != null) zoomedImage.Dispose(); if (overlayImage != null) overlayImage.Dispose(); if (sonyOverlayImage != null) sonyOverlayImage.Dispose(); if (thinkBottomLeftOverlayImage != null) thinkBottomLeftOverlayImage.Dispose(); if (thinkTextBottomLeftOverlayImage != null) thinkTextBottomLeftOverlayImage.Dispose(); if (cropGraphic != null) cropGraphic.Dispose(); if (newFullGraphic != null) newFullGraphic.Dispose(); if (zoomedGraphic != null) zoomedGraphic.Dispose(); } }