本文整理汇总了C#中NLogEx.LoggerEx.Error方法的典型用法代码示例。如果您正苦于以下问题:C# NLogEx.LoggerEx.Error方法的具体用法?C# NLogEx.LoggerEx.Error怎么用?C# NLogEx.LoggerEx.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLogEx.LoggerEx
的用法示例。
在下文中一共展示了NLogEx.LoggerEx.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ESDK_RTP_Init
/// <summary>
/// 初始化rtp模块
/// </summary>
public void ESDK_RTP_Init()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: RtpAdapter.ESDK_RTP_Init().");
try
{
int iRet = 0;
if (!isInited)
{
iRet = SdkRtpInterface.ESDK_RTP_Init();
logEx.Trace("Enter: RtpAdapter.ESDK_RTP_Init(). This is first init!");
}
if (iRet != 0)
{
logEx.Error("RtpAdapter.ESDK_RTP_Init ,error:{0}", iRet);
isInited = false;
}
else
{
logEx.Trace("Enter: RtpAdapter.ESDK_RTP_Init().Success");
isInited = true;
}
logEx.Trace("Enter: RtpAdapter.ESDK_RTP_Init(). inited is {0}!", isInited);
}
catch (System.Exception ex)
{
logEx.Error("RtpAdapter.ESDK_RTP_Init ,Exception:{0}", ex.ToString());
isInited = false;
}
}
示例2: AssignMonitorChannel
/// <summary>
/// 分配监控通道
/// </summary>
public SmcErr AssignMonitorChannel(List<ChannelInfo> ChannelInfoList)
{
SmcErr err = new CgwError();
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
err = CheckSession();
if (err.IsSuccess())
{
if (ChannelInfoList != null)
{
err = MonitorChannelBll.Instance().AssignMonitorChannel(ChannelInfoList);
}
else
{
err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELLIST_NULL);
}
}
if (err.IsSuccess())
{
logEx.Trace("AssignMonitorChannel Successful");
}
else
{
logEx.Error("AssignMonitorChannel failed,ErrNo :{0}", err.ErrNo);
}
return err;
}
示例3: ESDK_RTP_CloseChannel
/// <summary>
/// 关闭通道
/// </summary>
/// <param name="uiChannel"></param>
public void ESDK_RTP_CloseChannel(uint uiChannel)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: RtpAdapter.ESDK_RTP_CloseChannel().");
try
{
int iRet = SdkRtpInterface.ESDK_RTP_CloseChannel(uiChannel);
if (iRet != 0)
{
logEx.Error("RtpAdapter.ESDK_RTP_CloseChannel ,error:{0}", iRet);
}
}
catch (System.Exception ex)
{
logEx.Error("RtpAdapter.ESDK_RTP_CloseChannel ,Exception:{0}", ex.ToString());
}
}
示例4: LoadMonitorTimer_Elapsed
/// <summary>
/// 线程加载监控平台
/// </summary>
private static void LoadMonitorTimer_Elapsed()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
System.Threading.Thread.Sleep(CgwConst.Thread_Sleep_Time);
SmcErr smcErr = new SmcErr();
try
{
smcErr = MonitorManageService.Instance().Load();
if (false == smcErr.IsSuccess())
{
logEx.Error("MonitorManageService Start failed! Errno :{0}", smcErr.ErrNo);
NLog.LogManager.Flush();
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
}
catch (Exception ex)
{
logEx.Fatal(ex, "MonitorManageService LoadMonitor Failed!");
NLog.LogManager.Flush();
}
}
示例5: GetAllCamerasMethod
/// <summary>
/// 获取摄像头列表及分组信息
/// </summary>
private void GetAllCamerasMethod()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: TiandyVideoMonitor.GetAllCamerasTimer().");
try
{
//调用天地伟业http接口获取天地伟业设备管理树列表
List<Resource> resourceTree = this.httpClient.GetResourceTree();
if (resourceTree == null)
{
logEx.Error("GetResourceTree failed.");
ClearCamera();
isRefreshSucess = false;
return;
}
//调用天地伟业http接口获取自定义设备树列表
List<Resource> customTree = this.httpClient.GetCustomTree();
if (customTree == null)
{
logEx.Error("GetCustomTree failed.");
ClearCamera();
isRefreshSucess = false;
return;
}
Dictionary<string, TiandyCamera> tiandyCameraDictionaryTemp = new Dictionary<string, TiandyCamera>();
Dictionary<string, Host> hostDictionaryTemp = new Dictionary<string, Host>();
Dictionary<string, MediaServer> mediaServerDictionaryTemp = new Dictionary<string, MediaServer>();
//递归处理,将摄像头、主机、流媒体服务器遍历出来
RecursionCamera(resourceTree, tiandyCameraDictionaryTemp, hostDictionaryTemp, mediaServerDictionaryTemp);
Dictionary<string, CameraGroup> groupDicTemp = new Dictionary<string, CameraGroup>();
Dictionary<string, NodeRelation> nodeRelationDicTemp = new Dictionary<string, NodeRelation>();
List<NodeRelation> nodeRelationListTemp = new List<NodeRelation>();
//递归处理,获取组,摄像头、分组关系
RecursionCameraGroup(customTree, null, groupDicTemp, nodeRelationDicTemp, nodeRelationListTemp);
//对于未分组的摄像头,父节点设置为空
foreach (KeyValuePair<string, TiandyCamera> tiandyCameraKeyValue in tiandyCameraDictionaryTemp)
{
if (!nodeRelationDicTemp.ContainsKey(tiandyCameraKeyValue.Key))
{
NodeRelation nodeRelation = new NodeRelation(tiandyCameraKeyValue.Key,
new List<string>(),
CgwMonitorManage.Common.NodeType.CAMERA);
nodeRelationListTemp.Add(nodeRelation);
}
}
DateTime dtStart = DateTime.Now;
DateTime dtNow = new DateTime();
while (!isGetDevicesFinish)
{
dtNow = DateTime.Now;
if ((dtNow - dtStart).TotalSeconds > refreshDeviceListOverTime)
{
isRefreshSucess = false;
return;
}
Thread.Sleep(1);
continue;
}
if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
this.tiandyCameraDictionary = tiandyCameraDictionaryTemp;
this.hostDictionary = hostDictionaryTemp;
this.mediaServerDictionary = mediaServerDictionaryTemp;
this.groupDic = groupDicTemp;
this.nodeRelationList = nodeRelationListTemp;
isRefreshSucess = true;
}
catch (Exception ex)
{
isRefreshSucess = false;
logEx.Error("Recursion camera failed.Execption message:{0}", ex.Message);
}
finally
{
this.cameraOperateLock.ExitWriteLock();
}
}
}
catch (System.Exception ex)
{
isRefreshSucess = false;
//.........这里部分代码省略.........
示例6: StopControlPtz
/// <summary>
/// 停止云台控制,摄像头控制
/// </summary>
/// <param name="cameraNo">摄像头编号</param>
/// <param name="ptzCommand">命令类型</param>
/// <returns></returns>
public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommand)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: TiandyVideoMonitor.StopControlPtz({0}).", cameraNo);
SmcErr err = new CgwError();
int handel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
if (this.handelOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
{
handel = this.cameraVideoHandeDic[cameraNo];
}
else
{
logEx.Warn("The camera was not Preview.Don't need to end the control.Camera No:{0}.", cameraNo);
}
}
finally
{
this.handelOperateLock.ExitReadLock();
}
}
if (handel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
{
Client_PTZ_Command client_ptz_command = new Client_PTZ_Command();
client_ptz_command.start = false;
//将ptz命令转换成天地伟业的命令
string name = Enum.GetName(typeof(PtzCommandType), ptzCommand);
if (Enum.IsDefined(typeof(TiandyPtzCommandType), name))
{
TiandyPtzCommandType tiandyPtzCommandType = (TiandyPtzCommandType)Enum.Parse(typeof(TiandyPtzCommandType), name);
client_ptz_command.cmd = (int)tiandyPtzCommandType;
}
else
{
err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
logEx.Error("The tiandy monitor is not support the command.ptzCommand:{0}.", ptzCommand);
return err;
}
bool result = this.sdkClient.ControlPtz(handel, client_ptz_command);
if (result)
{
logEx.Info("Stop control camera ptz success.Camera No:{0}.", cameraNo);
}
else
{
err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
logEx.Error("Stop control camera ptz failed.Camera No:{0}.", cameraNo);
}
}
else
{
err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
logEx.Error("Handel is not found. Stop control camera ptz failed. Camera No:{0}.", cameraNo);
return err;
}
return err;
}
示例7: Load
/// <summary>
/// 初始化天地伟业监控平台
/// </summary>
/// <param name="monitorConfigElement">监控平台配置节点</param>
/// <returns></returns>
public SmcErr Load(XmlElement monitorConfigElement)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: TiandyVideoMonitor.Load().");
SmcErr err = new CgwError();
string userLevel = "";
//解析xml节点,获取所需参数
try
{
#region Tiandy视频监控平台(Easy7)连接信息
this.monitorId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.ID_TAG);
userLevel = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PTZCONTROLLEVEL_TAG);
string httpUser = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_USER_TAG);
string httpPassword = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_PASSWORD_TAG);
string httpUrl = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_URL_TAG);
string mediaServerId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.MEDIASERVER_SERVERID_TAG);
#endregion
this.httpClient = new TiandyHttpClient(httpUrl, httpUser, httpPassword);
//使用线程轮询加载监控平台
Thread loaderThread = new Thread(LoaderThread);
loaderThread.Start(mediaServerId);
}
catch (Exception e)
{
err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
logEx.Error("Load Tiandy monitor failed.Execption message:{0}.", e.Message);
return err;
}
this.sdkClient = new TiandySdkClient();
//如果控制级别配置错误,只记录错误日志,不向外报错
try
{
this.sdkClient.PtzControlLevel = int.Parse(userLevel);
}
catch (Exception e)
{
logEx.Error("Ptz Control Level is invalid.Execption message:{0}.", e.Message);
this.sdkClient.PtzControlLevel = CgwConst.PTZ_CONTROL_LEVEL;
}
logEx.Info("Load video monitor success.Monitor id:{0}.", this.monitorId);
return err;
}
示例8: TiandyRealDataCallbackFunc
/// <summary>
/// 码流回调处理,用于中转
/// </summary>
/// <param name="playfd">预览句柄</param>
/// <param name="datatype">视频流类型</param>
/// <param name="buf">码流</param>
/// <param name="size">码流大小</param>
/// <param name="usr">用户标识数据</param>
private void TiandyRealDataCallbackFunc(int playfd, int datatype, byte[] buf, uint size, int usr)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
string cameraNo = null;
try
{
StreamType streamType = StreamType.VIDEO_H264;
//判断码流类型,因为码流回调访问频频非常高,不单独抽成一个方法,减少方法访问开销
//对于支持的码流类型,用break退出switch,对于不支持的码流类型直接舍弃,用return返回
switch (datatype)
{
case (int)TiandyStreamType.STREAM_TYPE_VIDEO_FRAME_I:
streamType = StreamType.VIDEO_H264;
break;
case (int)TiandyStreamType.STREAM_TYPE_VIDEO_FRAME_P:
streamType = StreamType.VIDEO_H264;
break;
case (int)TiandyStreamType.STREAM_TYPE_VIDEO_FRAME_B:
streamType = StreamType.VIDEO_H264;
break;
//音频只接收G711A和G711U,其他舍弃
case (int)TiandyStreamType.STREAM_TYPE_AUDIO_G711A:
streamType = StreamType.AUDIO_G711A;
break;
case (int)TiandyStreamType.STREAM_TYPE_AUDIO_G711U:
streamType = StreamType.AUDIO_G711U;
break;
default:
//不支持的类型直接舍弃,返回
//logEx.Warn("This stream type is not support. Chuck the data.StreamType:{0};Camera no:{1}", datatype, cameraNo);
return;
}
if (this.handelOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
if (!this.videoHandleCameraDic.ContainsKey(playfd))
{
logEx.Error("The video data handle is not found.Handle:{0}", playfd);
return;
}
cameraNo = this.videoHandleCameraDic[playfd];
if (string.IsNullOrEmpty(cameraNo))
{
return;
}
}
finally
{
this.handelOperateLock.ExitReadLock();
}
}
if (streamType == StreamType.AUDIO_G711A || streamType == StreamType.AUDIO_G711U)
{
//如果是音频流,需要判断mic的状态,开启时才发送音频流
if (this.micOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
if (this.cameraMicStatusDic.ContainsKey(cameraNo))
{
//如果mic为非开启状态,则不发送音频码流,
if (!this.cameraMicStatusDic[cameraNo])
{
//logEx.Warn("This data is audio,but the mic is off.Chuck the data.Camera no:{0}", cameraNo);
return;
}
}
else
{
//默认为关闭状态,因此如果cameraMicStatusDic不包含该摄像头,则认为处于关闭状态,舍弃音频码流
//logEx.Warn("This data is audio,but the mic is off.Chuck the data.Camera no:{0}", cameraNo);
return;
}
}
finally
{
this.micOperateLock.ExitReadLock();
}
}
}
MediaData mediaData = new MediaData();
mediaData.Data = buf;
mediaData.DataType = MediaDataType.FRAME_DATA;
mediaData.StreamType = streamType;
//.........这里部分代码省略.........
示例9: RecursionCamera
/// <summary>
/// 递归天地伟业返回的设备树,获取所有通道(一个通道对应一个摄像头)、主机、流媒体(中间件)服务器
/// </summary>
/// <param name="resourceTree">天地伟业返回的设备树</param>
/// <param name="tiandyCameraDictionary">摄像头键值对,key为摄像头编号</param>
/// <param name="hostDictionary">主机键值对,key为主机编号</param>
/// <param name="mediaServerDictionary">流媒体(中间件)服务键值对,key为编号</param>
private void RecursionCamera(List<Resource> resourceTree, Dictionary<string, TiandyCamera> tiandyCameraDictionary, Dictionary<string, Host> hostDictionary, Dictionary<string, MediaServer> mediaServerDictionary)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
if (resourceTree == null)
{
logEx.Error("Recursion camera failed.ResourceTree is null.");
return;
}
if (tiandyCameraDictionary == null)
{
tiandyCameraDictionary = new Dictionary<string, TiandyCamera>();
}
if (hostDictionary == null)
{
hostDictionary = new Dictionary<string, Host>();
}
if (mediaServerDictionary == null)
{
mediaServerDictionary = new Dictionary<string, MediaServer>();
}
foreach (Resource resource in resourceTree)
{
//TypeId为5时,表示该节点为通道,对应一个摄像头
if (((int)NodeType.CAMERA).ToString().Equals(resource.TypeId))
{
TiandyCamera camera = new TiandyCamera(resource.Id, resource.Caption);
camera.Channel = resource.Ch;
//摄像头的父节点为主机
camera.HostNo = resource.ParentId;
tiandyCameraDictionary.Add(camera.No, camera);
//如果是摄像头节点,不需要递归
continue;
}
else if (((int)NodeType.HOST).ToString().Equals(resource.TypeId))
{
//将主机加入缓存,主机的父节点为流媒体(中间件)服务器
Host host = new Host(
resource.Id,
resource.Username,
resource.Pwd,
resource.ParentId);
hostDictionary.Add(host.No, host);
}
else if (((int)NodeType.MEDIASERVER).ToString().Equals(resource.TypeId))
{
//将流媒体(中间件)服务器加入缓存
MediaServer mediaServer = new MediaServer(
resource.Id,
resource.Ip,
resource.Port,
resource.Username,
resource.Pwd);
mediaServerDictionary.Add(mediaServer.No, mediaServer);
}
//递归处理
RecursionCamera(resource.items, tiandyCameraDictionary, hostDictionary, mediaServerDictionary);
}
}
示例10: GetAllCamerasMethod
/// <summary>
/// 获取摄像头列表及分组信息
/// </summary>
private void GetAllCamerasMethod()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: IvsVideoMonitor.GetAllCamerasMethod().");
try
{
//1、获取系统中所有的域
List<IvsDomainRoute> ivsDomainRouteList;
logEx.Trace("Call ivsSdkClient.GetDomainRoute().");
int result = this.ivsSdkClient.GetDomainRoute(out ivsDomainRouteList);
if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
{
logEx.Info("GetDomainRoute success.List count:{0}", ivsDomainRouteList.Count);
}
else
{
logEx.Error("GetDomainRoute failed.Ivs sdk error code:{0}", result);
ClearCamera();
isRefreshSucess = false;
return;
}
List<Camera> cameraListTemp = new List<Camera>();
List<CameraGroup> groupListTemp = new List<CameraGroup>();
List<NodeRelation> nodeRelationListTemp = new List<NodeRelation>();
Dictionary<string, NodeRelation> nodeRelationDicTemp = new Dictionary<string, NodeRelation>();
foreach (IvsDomainRoute route in ivsDomainRouteList)
{
//加上此判断条件的话,子域将不会作查目录处理,不合理,故注释掉
//if (route.ParentDomain != "")
//{
// continue;
//}
Dictionary<string, IvsCameraGroup> ivsCameraGroupDic;
logEx.Trace("Call ivsSdkClient.GetDeviceGroupList({0},{1},out groupCount, out ivsCameraGroupDic).",
route.DomainCode,
CgwConst.IVS_SDK_ROOTGROUP_TAG);
result = this.ivsSdkClient.GetDeviceGroupList(route.DomainCode,
CgwConst.IVS_SDK_ROOTGROUP_TAG,
out ivsCameraGroupDic);
if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
{
logEx.Info("GetDeviceGroupList success.Current group count:{0}", ivsCameraGroupDic.Count);
}
else
{
logEx.Error("GetDeviceGroupList failed.Ivs sdk error code:{0}", result);
ClearCamera();
isRefreshSucess = false;
return;
}
//域也当做分组使用
string encodeDomainNo = CgwConst.IVS_SDK_ROOTGROUP_TAG + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + route.DomainCode;
CameraGroup domainGroup = new CameraGroup(encodeDomainNo, route.DomainName);
groupListTemp.Add(domainGroup);
List<string> pathDomainList = new List<string>();
RecursionGroupPath(route.DomainCode, ivsDomainRouteList,ref pathDomainList);
NodeRelation nodeDomainRelation = new NodeRelation(encodeDomainNo, pathDomainList, CgwMonitorManage.Common.NodeType.GROUP);
nodeRelationDicTemp.Add(encodeDomainNo, nodeDomainRelation);
foreach (KeyValuePair<string, IvsCameraGroup> ivsCameraGroupKeyValue in ivsCameraGroupDic)
{
IvsCameraGroup group = ivsCameraGroupKeyValue.Value;
string encodeGroupNo = group.GroupNo + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + group.DomainCode;
//添加组信息
CameraGroup cameraGroup = new CameraGroup(encodeGroupNo, group.GroupName);
groupListTemp.Add(cameraGroup);
List<string> pathList = new List<string>();
RecursionPath(group.GroupNo, ivsCameraGroupDic, ref pathList);
NodeRelation nodeRelation = new NodeRelation(encodeGroupNo, pathList, CgwMonitorManage.Common.NodeType.GROUP);
nodeRelationDicTemp.Add(encodeGroupNo, nodeRelation);
}
}
//添加所有组节点
nodeRelationListTemp.AddRange(nodeRelationDicTemp.Values);
List<IvsCamera> ivsCameraPageList = new List<IvsCamera>();
int cameraCount = 0;
logEx.Trace("Call ivsSdkClient.GetDeviceList");
//查询第一页记录,同时获取摄像头个数
result = this.ivsSdkClient.GetDeviceList(CgwConst.PAGE_FIRST_INDEX, CgwConst.PAGE_LAST_INDEX, out cameraCount, out ivsCameraPageList);
List<IvsCamera> ivsCameraLeaveList = new List<IvsCamera>();
//如果总记录大于一页的总记录数
if (cameraCount > CgwConst.PAGE_LAST_INDEX)
{
//.........这里部分代码省略.........
示例11: Run
/// <summary>
/// 运行管道
/// </summary>
public void Run()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
Thread th = new Thread(new ThreadStart(() =>
{
try
{
pipedStream.WaitForConnection();
haveConnect = true;
}
catch
{
logEx.Error("Run failed");
}
}));
th.Start();
}
示例12: GetResourceTree
/// <summary>
/// 获取设备树
/// </summary>
/// <param name="requestUrl"></param>
/// <returns>成功返回对象列表,失败返回null</returns>
private List<Resource> GetResourceTree(String requestUrl)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
List<Resource> resources = null;
//调用HTTP接口获取json字符串
string resourceString = CallHttpInterface(requestUrl);
if (!string.IsNullOrEmpty(resourceString))
{
resources = JsonUtil.ParseResource(resourceString);
if (resources == null)
{
logEx.Error("Call function GetResourceTree() failed.");
}
else
{
logEx.Info("Call function GetResourceTree() success.");
}
}
else
{
//如果字符串为空,说明调用不成功
resources = null;
logEx.Error("Call function GetResourceTree() failed.");
}
return resources;
}
示例13: CallHttpInterface
/// <summary>
/// 调用天地伟业http接口
/// </summary>
/// <param name="requestUrl"></param>
/// <returns>成功返回json字符串,失败返回null</returns>
private string CallHttpInterface(string requestUrl)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: TiandyHttpClient.CallHttpInterface().");
Stream stream = null;
string result = null;
try
{
//调用http接口
WebClient webClient = new WebClient();
stream = webClient.OpenRead(requestUrl);
StreamReader streamReader = new StreamReader(stream);
//调用HTTP接口返回json字符串
result = streamReader.ReadToEnd();
}
catch (Exception e)
{
result = null;
logEx.Error("Call http function failed.Exception message:{0}.", e.Message);
}
finally
{
//记录日志,待日志模块合入后补充日志信息
if (stream != null)
{
stream.Close();
}
}
return result;
}
示例14: Login
/// <summary>
/// 登陆http服务接口
/// </summary>
/// <returns>成功返回登录信息对象,失败返回null</returns>
public LoginInfo Login()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: TiandyHttpClient.Login().");
LoginInfo loginInfo = null;
//设置访问天地伟业登陆接口的uri
string requestUrl = string.Format(
"{0}/LogIn.jsp?UserName={1}&Password={2}&LoginType=1",
this.serverUrl,
this.user,
this.pwd);
//日志不能记密码,单独处理
string logString = string.Format(
"{0}/LogIn.jsp?UserName={1}&Password=******&LoginType=1",
this.serverUrl,
this.user);
//调用HTTP接口获取json字符串
string loginInfoString = CallHttpInterface(requestUrl);
if (!string.IsNullOrEmpty(loginInfoString))
{
loginInfo = JsonUtil.ParseLoginInfo(loginInfoString);
if (loginInfo == null)
{
logEx.Error("Login to http server failed.Url:{0}", logString);
//返回失败设置错误码
}
logEx.Info("Login to http server success.Url:{0}", logString);
}
else
{
//如果字符串为空,说明调用不成功
logEx.Error("Login to http server failed.Url:{0}", logString);
loginInfo = null;
}
return loginInfo;
}
示例15: Connect
/// <summary>
/// 连接融合网关
/// </summary>
/// <param name="password">连接字符串</param>
/// <returns></returns>
public SmcErr Connect(string password)
{
SmcErr err = new CgwError();
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
if (false == string.IsNullOrEmpty(password))
{
//获取后台密码字符串
string s = CommonFunction.GetAppSetting("PassWord");
//进行SHA256加密
string newPassword = CommonFunction.SHA256Encrypt(s);
//保存当前会话
if (newPassword == password)
{
//获取SessionManage中Session个数
if (SessionManage.Instance().GetSessionsCount() == 0)
{
Guid sessionGuid = Guid.NewGuid();
//保存至CGW的session管理中
CGWSession CgwSession = new CGWSession(sessionGuid, OperationContext.Current.SessionId);
logEx.Trace("Connect Successful,Current.SessionId is : ", OperationContext.Current.SessionId);
}
else
{
err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
logEx.Warn("Session Count is Top Of Max number !");
}
}
else
{
err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_INCORRECT);
logEx.Error("Connect Password is Incorrect !");
}
}
else
{
err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_NULL);
logEx.Error("Connect Password is null !");
}
return err;
}