博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
fineui实时监控(增、删、改)+CDC+长连接(一)
阅读量:6734 次
发布时间:2019-06-25

本文共 27437 字,大约阅读时间需要 91 分钟。

hot3.png

一:前台页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestRealStoping.aspx.cs"    Inherits="WebApp.StopGenerat.TestRealStoping" %><%--实时停发电综合管理--%>    实时停发电综合管理                
<%--
市电来电
信息错误
--%>

二:CDC语句

USE [DMS]GO/****** Object:  StoredProcedure [dbo].[RealCDC]    Script Date: 08/06/2014 15:23:22 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO---监控ConfirmBK_StopGenerat表的变化ALTER PROCEDURE [dbo].[RealCDC]    @BeginTime datetime,--开始时间    @BeginLSN varbinary(10),--开始LSN边界    @ToLSN varbinary(10) output--返回值ASBEGIN--结束 LSN边界select @ToLSN = sys.fn_cdc_map_time_to_lsn('largest less than or equal',getdate())--首次 if ISNULL(@BeginTime,'')<>''   begin    --最小开始LSN边界   通过@BeginTime算出赋值给@BeginLSN   --declare @fromLSN varbinary(10)=sys.fn_cdc_map_time_to_lsn   -- ('smallest greater than or equal',@BeginTime)        select  @BeginLSN=sys.fn_cdc_map_time_to_lsn('smallest greater than or equal',@BeginTime)       end            else    begin         select  @BeginLSN=sys.fn_cdc_increment_lsn(@BeginLSN)       end      --返回三个select, 删除,新增,修改    --返回一个输出变量@ToLSN    --cdc对应--when 1 then 'DELETE'--when 2 then 'INSERT'--when 3 then 'Before Update'--when 4 then 'After Update'     --最终状态--净变更  --删除---对应操作为更新- 发电结束(从页面删除)select --  __$operation as operation--,[ID]  ,[LSCCode] from cdc.fn_cdc_get_net_changes_dbo_ConfirmBK_StopGenerat(@BeginLSN,@ToLSN,'all with mask') as K where__$operation=4 and  StatusType=3 and sys.fn_cdc_is_bit_set(  sys.fn_cdc_get_column_ordinal('dbo_ConfirmBK_StopGenerat','StatusType'),K.__$update_mask)=1order by ID asc----------不要用*代替列名,因为是CDC,不是表---新增select --  __$operation as operation--, [ID]      ,[LSCCode]      ,[Sucode]      ,[AreaID]      ,[SuType]      ,[AlarmId]      ,[AlarmNo]      ,[StatusType]      ,[StationStatus]      ,[OneDayTimes]      ,[StopPowerTime]      ,[Under47VTime]      ,[RemainTime]      ,[IsBlackouts]      ,[PrevEndTime]      ,[DispachNum]      ,[DoorcardTime]      ,[IsGenerator]      ,[BeginGenerator]      ,[RecoveryTime]      ,[EndOfJobStyle]      ,[EndOfJobTime]      ,[DischargeTime]      ,[BatteryVLower]      ,[InType]      ,[InSubType]      ,[StopDur]      ,[GeneratorDur]      ,[RedundancyDur]      ,[CreateStyle]      ,[LSCName]      ,[SuName]      ,[AreaName]      ,[ParentID]      ,[SuSubType]      ,[SuLevel]      ,[SuAhValue]      ,[BatteryContain]      ,[StationCommStatus]      ,[BatteryVVal]      ,[BatteryStatus]      ,[OilStatus]      ,[OillastBeginTime]      ,[OillastStopTime]      ,[OillastStopReason]      ,[CurStopDur]      ,[CurGeneratorDur]      ,[SumOilGeneratorDur]      ,[OilBeginCount]      ,[LastSMPSOutAAvg]      ,[Flashing]      ,[IsFake]      ,[IsTimely]      ,[IsPremature]      ,[IsSuperShort]      ,[IsMidWayReturn]      ,[IsTakeback]      ,[IsOilLongStop]      ,[BatteryBad]      ,[BatteryOneBad]      ,[BatteryUnderLine]      ,[ReplaceOil]      ,[Timestamp]      ,[CollectTime]      ,[CreateTime]      ,[UpdateTime]      ,[Reserve]      ,[Reserve1]      ,[Reserve2]      ,[Reserve3],       CASE   StatusType       WHEN 1 THEN '停电中'       WHEN 2 THEN '发电中'       WHEN 3 THEN '来电--结束发电'       ELSE '' END       as       StatusTypeTxt,       CASE   StationStatus       WHEN 1 THEN '停电'       WHEN 2 THEN '油机发电'       WHEN 3 THEN '退服'       WHEN 4 THEN '来电'       ELSE '' END       as       StationStatusTxt,  CASE   IsBlackouts       WHEN 0 THEN '否'       WHEN 1 THEN '大面积停电'       ELSE '' END       as       IsBlackoutsTxt,   CASE isnull(DispachNum,'')       WHEN '' THEN '无'       ELSE '已派单' END       as       DispachNumTxt,  CASE isnull(DoorcardTime,'')       WHEN '' THEN '无'       ELSE '已开门' END       as       DoorcardTimeTxt,       CASE   IsGenerator       WHEN 0 THEN '否'       WHEN 1 THEN '已发电'       ELSE '' END       as       IsGeneratorTxt,  CASE   ReplaceOil        WHEN 0 THEN '否'       WHEN 1 THEN '是'       ELSE '' END       as       ReplaceOilTxt,    LTRIM(floor(      (CASE WHEN  ISNULL(RecoveryTime,-1)<>-1      THEN  datediff(minute,RecoveryTime,GETDATE())+ ISNULL(StopDur,0)  ELSE      datediff(minute,StopPowerTime,GETDATE()) end)/60))  +':'+      LTRIM( (CASE WHEN  ISNULL(RecoveryTime,-1)<>-1      THEN  datediff(minute,RecoveryTime,GETDATE())+ISNULL(StopDur,0)  ELSE      datediff(minute,StopPowerTime,GETDATE()) end)%60)      as    StopDurTxt,            CASE WHEN  IsGenerator=1      THEN      CASE WHEN  StationStatus=2       then       LTRIM(floor(      ( CASE WHEN  ISNULL(RecoveryTime,-1)<>-1      THEN  datediff(minute,OillastBeginTime,GETDATE())+ISNULL(GeneratorDur,0)      ELSE    datediff(minute,BeginGenerator,GETDATE()) end) /60))      +':'+      LTRIM( ( CASE WHEN  ISNULL(RecoveryTime,-1)<>-1   THEN      datediff(minute,OillastBeginTime,GETDATE())+ISNULL(GeneratorDur,0)    ELSE      datediff(minute,BeginGenerator,GETDATE())   end )%60)       ELSE       LTRIM(floor(       ( ISNULL(GeneratorDur,0) /60)))       +':'+       LTRIM( floor(( ISNULL(GeneratorDur,0)%60)))       end       ELSE '0' end      as      GeneratorDurTxt,  LTRIM(floor( StopDur/60))  +':'+  LTRIM(StopDur %60) as    TotalStopDurTxt,      LTRIM(floor( GeneratorDur/60))  +':'+  LTRIM(GeneratorDur %60) as    TotalGeneratorDurTxt,        LTRIM(floor( DischargeTime/60))  +':'+  LTRIM(DischargeTime %60) as    DischargeTimeTxt,         LTRIM(floor(RemainTime/60))  +':'+  LTRIM(RemainTime %60) as RemainTimeTxt,            CASE CreateStyle       WHEN 1 THEN '系统自动判断停电'       WHEN 2 THEN '人工判断停电'       ELSE '' END       as       CreateStyleTxt,     CASE EndOfJobStyle       WHEN 1 THEN '自动来电'       WHEN 2 THEN '手动来电'       WHEN 3 THEN '油机最后一次停止超过1小时(自动结束)'       WHEN 4 THEN '错误'       ELSE '' END       as       EndOfJobStyleTxt,   CASE   BatteryOneBad       WHEN 0 THEN '否'       WHEN 1 THEN '是'       ELSE '' END       as       BatteryOneBadTxt,  CASE   BatteryBad       WHEN 0 THEN '否'       WHEN 1 THEN '是'       ELSE '' END       as       BatteryBadTxt,   CASE   BatteryUnderLine       WHEN 0 THEN '否'       WHEN 1 THEN '是'       ELSE '' END       as       BatteryUnderLineTxt,     CASE   IsTakeback       WHEN 0 THEN '否'       WHEN 1 THEN '曾退服'       ELSE '' END       as       IsTakebackTxt,    CASE StationCommStatus       WHEN 1 THEN '正常'       WHEN 2 THEN '异常'       ELSE '' END       as       StationCommStatusTxt,   CASE BatteryStatus      WHEN 1 THEN '浮充'      WHEN 2 THEN '停电'      WHEN 3 THEN '充电'      WHEN 4 THEN '放电'      ELSE '未监控' END      as      BatteryStatusTxt,     CASE OilStatus      WHEN 1 THEN '油机发电'      WHEN 2 THEN '油机停止'      WHEN 3 THEN '未监控'      ELSE '' END      as      OilStatusTxt, CASE  Flashing      WHEN 0 THEN '否'      WHEN 1 THEN '闪断'      ELSE '' END      as      FlashingTxt,CASE  IsFake      WHEN 0 THEN '否'      WHEN 1 THEN '假发电'      ELSE '' END      as      IsFakeTxt, CASE  IsTimely      WHEN 0 THEN '否'      WHEN 1 THEN '发电及时'      ELSE '' END      as      IsTimelyTxt, CASE  IsPremature      WHEN 0 THEN '否'      WHEN 1 THEN '过早发电'      ELSE '' END      as      IsPrematureTxt,CASE  IsSuperShort      WHEN 0 THEN '否'      WHEN 1 THEN '超短发电'      ELSE '' END      as      IsSuperShortTxt,  CASE  IsMidWayReturn      WHEN 0 THEN '否'      WHEN 1 THEN '中途返回'      ELSE '' END      as      IsMidWayReturnTxt, CASE  IsOilLongStop      WHEN 0 THEN '否'      WHEN 1 THEN '油机超长停止'      ELSE '' END      as      IsOilLongStopTxt,  CASE WHEN ISNULL(OillastBeginTime,-1)<>-1 and ISNULL(OillastStopTime,-1)<>-1  AND (OillastBeginTime
-1 THEN datediff(minute,RecoveryTime,GETDATE())+ ISNULL(StopDur,0) ELSE datediff(minute,StopPowerTime,GETDATE()) end)/60)) +':'+ LTRIM( (CASE WHEN ISNULL(RecoveryTime,-1)<>-1 THEN datediff(minute,RecoveryTime,GETDATE())+ISNULL(StopDur,0) ELSE datediff(minute,StopPowerTime,GETDATE()) end)%60) as StopDurTxt, CASE WHEN IsGenerator=1 THEN CASE WHEN StationStatus=2 then LTRIM(floor( ( CASE WHEN ISNULL(RecoveryTime,-1)<>-1 THEN datediff(minute,OillastBeginTime,GETDATE())+ISNULL(GeneratorDur,0) ELSE datediff(minute,BeginGenerator,GETDATE()) end) /60)) +':'+ LTRIM( ( CASE WHEN ISNULL(RecoveryTime,-1)<>-1 THEN datediff(minute,OillastBeginTime,GETDATE())+ISNULL(GeneratorDur,0) ELSE datediff(minute,BeginGenerator,GETDATE()) end )%60) ELSE LTRIM(floor( ( ISNULL(GeneratorDur,0) /60))) +':'+ LTRIM( floor(( ISNULL(GeneratorDur,0)%60))) end ELSE '0' end as GeneratorDurTxt, LTRIM(floor( StopDur/60)) +':'+ LTRIM(StopDur %60) as TotalStopDurTxt, LTRIM(floor( GeneratorDur/60)) +':'+ LTRIM(GeneratorDur %60) as TotalGeneratorDurTxt, LTRIM(floor( DischargeTime/60)) +':'+ LTRIM(DischargeTime %60) as DischargeTimeTxt, LTRIM(floor(RemainTime/60)) +':'+ LTRIM(RemainTime %60) as RemainTimeTxt, CASE CreateStyle WHEN 1 THEN '系统自动判断停电' WHEN 2 THEN '人工判断停电' ELSE '' END as CreateStyleTxt, CASE EndOfJobStyle WHEN 1 THEN '自动来电' WHEN 2 THEN '手动来电' WHEN 3 THEN '油机最后一次停止超过1小时(自动结束)' WHEN 4 THEN '错误' ELSE '' END as EndOfJobStyleTxt, CASE BatteryOneBad WHEN 0 THEN '否' WHEN 1 THEN '是' ELSE '' END as BatteryOneBadTxt, CASE BatteryBad WHEN 0 THEN '否' WHEN 1 THEN '是' ELSE '' END as BatteryBadTxt, CASE BatteryUnderLine WHEN 0 THEN '否' WHEN 1 THEN '是' ELSE '' END as BatteryUnderLineTxt, CASE IsTakeback WHEN 0 THEN '否' WHEN 1 THEN '曾退服' ELSE '' END as IsTakebackTxt, CASE StationCommStatus WHEN 1 THEN '正常' WHEN 2 THEN '异常' ELSE '' END as StationCommStatusTxt, CASE BatteryStatus WHEN 1 THEN '浮充' WHEN 2 THEN '停电' WHEN 3 THEN '充电' WHEN 4 THEN '放电' ELSE '未监控' END as BatteryStatusTxt, CASE OilStatus WHEN 1 THEN '油机发电' WHEN 2 THEN '油机停止' WHEN 3 THEN '未监控' ELSE '' END as OilStatusTxt, CASE Flashing WHEN 0 THEN '否' WHEN 1 THEN '闪断' ELSE '' END as FlashingTxt,CASE IsFake WHEN 0 THEN '否' WHEN 1 THEN '假发电' ELSE '' END as IsFakeTxt, CASE IsTimely WHEN 0 THEN '否' WHEN 1 THEN '发电及时' ELSE '' END as IsTimelyTxt, CASE IsPremature WHEN 0 THEN '否' WHEN 1 THEN '过早发电' ELSE '' END as IsPrematureTxt,CASE IsSuperShort WHEN 0 THEN '否' WHEN 1 THEN '超短发电' ELSE '' END as IsSuperShortTxt, CASE IsMidWayReturn WHEN 0 THEN '否' WHEN 1 THEN '中途返回' ELSE '' END as IsMidWayReturnTxt, CASE IsOilLongStop WHEN 0 THEN '否' WHEN 1 THEN '油机超长停止' ELSE '' END as IsOilLongStopTxt, CASE WHEN ISNULL(OillastBeginTime,-1)<>-1 and ISNULL(OillastStopTime,-1)<>-1 AND (OillastBeginTime
3 and sys.fn_cdc_is_bit_set( sys.fn_cdc_get_column_ordinal('dbo_ConfirmBK_StopGenerat','StatusType'),K.__$update_mask)=1 order by ID asc---返回输出 return @ToLSNEND

三:长连接前台核心

//循环post        function Keepline() {            var array = new RequestArray();            $.post("comet_broadcast.asyn", array.ToJson(),  function (data) {      var loadrowdata = false;      if (parent.parent.getActiveTabUrl().indexOf("RealStoping") > -1) {          loadrowdata = true;      }      if (loadrowdata) {          if (data.ResultStatus == 1 && data.ResultData != null) {              //数值与时间 累加更新              var fdtime = new Date();              var txtcurdatetimeflash = fdtime.getFullYear() + "-" + (fdtime.getMonth() + 1) + "-" + fdtime.getDate() + ":" + fdtime.getHours() + ":" + fdtime.getMinutes() + ":" + fdtime.getSeconds();              Ext.getCmp(PrevTimeTag).setValue(txtcurdatetimeflash);              X.ajaxLoadingMask.show(); //遮罩              if (data.ResultData.DeleteDT != null && data.ResultData.DeleteDT.length > 0) {                  //得到当前页面是否被显示                  if (loadrowdata) {                      DeleteData(data.ResultData.DeleteDT); //删除                    }                  intPrevDelete = (data.ResultData.DeleteDT.length) * 1;              }              if (data.ResultData.AddDT != null && data.ResultData.AddDT.length > 0) {                  if (loadrowdata) {                      AddData(data.ResultData.AddDT); //新增                  }                  intPrevAdd = (data.ResultData.AddDT.length) * 1;              }              if (data.ResultData.UpdateDT != null && data.ResultData.UpdateDT.length > 0) {                  if (loadrowdata) {                      UpdateData(data.ResultData.UpdateDT); //替换                  }                  intPrevUpdate = (data.ResultData.UpdateDT.length) * 1;              }              X.ajaxLoadingMask.hide(); //遮罩              try {                  //数值与时间 累加更新                  intSumAdd = intSumAdd + intPrevAdd;                  intSumDelete = intSumDelete + intPrevDelete;                  intSumUpdate = intSumUpdate + intPrevUpdate;                  Ext.getCmp(TxtPrevAdd).setValue(intPrevAdd)                  Ext.getCmp(TxtPrevDelete).setValue(intPrevDelete)                  Ext.getCmp(TxtPrevUpdate).setValue(intPrevUpdate)                  Ext.getCmp(TxtSumAdd).setValue(intSumAdd)                  Ext.getCmp(TxtSumDelete).setValue(intSumDelete)                  Ext.getCmp(TxtSumUpdate).setValue(intSumUpdate)              }              catch (e) {                  //e.message                  //e.description                  //e.number                  //throw new erroe();              }          }      }      Keepline();  }, "json");

四:连接统一回发组件

4.1进入ashx

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web;using System.Web.SessionState;namespace ServerPushHttpHandler{    //1.主要做接收操作    ///     /// 异步处理程序    ///     public class ServerPushHandler : IHttpAsyncHandler, IReadOnlySessionState     {        //进程开始异步调用        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)         {            return new ServerPushManager(context, new ServerPushResult(context, cb, extraData)).ExecAction();        }        //进程结束        public void EndProcessRequest(IAsyncResult result)         {        }        #region  防止IIS报错        //不使用线程池        public bool IsReusable         {            get { return false; }        }        //同步时的处理方法        public void ProcessRequest(HttpContext context)         {            throw new NotImplementedException();        }        #endregion    }}

4.2进入分析

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web;namespace ServerPushHttpHandler{    public class ServerPushManager    {        //2.主要用来做请求处理        #region 全局变量        HttpContext m_Context;        //推送结果        ServerPushResult _IAsyncResult;        //请求参数对象        RequestModel rm = new RequestModel();        #endregion        #region 构造函数        ///         /// 构造方法        ///         public ServerPushManager(HttpContext context, ServerPushResult _IAsyncResult)        {            this.m_Context = context;            this._IAsyncResult = _IAsyncResult;        }        #endregion        ///         /// 根据Action判断执行方法        ///         /// 
public ServerPushResult ExecAction() { try { //角色--没有权限,直接返回-1 if (m_Context.Session["roleid"] != null && !string.IsNullOrEmpty(m_Context.Session["roleid"].ToString())) { rm.RoleId = int.Parse(m_Context.Session["roleid"].ToString()); } else { //没有权限,直接返回-1 ResponseResultModel ResponseResult = new ResponseResultModel(); ResponseResult.ResultStatus = -1; ResponseResult.ResultDetails = StatusCodeMsg.GetMsg(403); _IAsyncResult.Result = ResponseResult.ResultString(); ; _IAsyncResult.Send(); BLL.NLog.Current.Info("实时监控请求处理--没有角色权限"); } //用户 rm.UserName = m_Context.User.Identity.Name; //类型 if (!string.IsNullOrEmpty(m_Context.Request["Type"])) { rm.Type = int.Parse(m_Context.Request["Type"]); } //请求时间戳 rm.InTimeStamp = DateTime.Now.ToString(); BLL.NLog.Current.Info("实时监控请求处理--用户:" + rm.UserName + "类型" + rm.Type + "请求时间戳:" + rm.InTimeStamp); } catch (Exception ex) { //参数错误 ResponseResultModel ResponseResult = new ResponseResultModel(); ResponseResult.ResultStatus = -1; ResponseResult.ResultDetails = StatusCodeMsg.GetMsg(400); _IAsyncResult.Result = ResponseResult.ResultString(); ; _IAsyncResult.Send(); BLL.NLog.Current.Info("实时监控请求处理--"+ex.Message + Environment.NewLine + ex.StackTrace); } RealMonitor(); 参数选择--操作 //switch (rm.Type) //{ // case 0://实时监控Column // RealMonitor(); // break; // //其他扩展OtherParamter // default: // break; //} return _IAsyncResult; } /// /// 实时监控 /// ///
切割参数,存储进入实时监控List(CommonObj.Current.SPDict)中
private void RealMonitor() { //Column if (!string.IsNullOrEmpty(m_Context.Request["Column"])) { rm.Column = m_Context.Request["Column"]; } //LSCCode if (!string.IsNullOrEmpty(m_Context.Request["LSCCode"])) { rm.LSCCode = m_Context.Request["LSCCode"]; } //请求包装 _IAsyncResult.rm = rm; BLL.NLog.Current.Info("实时监控请求处理--用户:" + rm.UserName + "列:" + rm.Column + "LSCCode:" + rm.LSCCode ); lock (CommonObj.Current.RealDict) { if (!CommonObj.Current.RealDict.ContainsKey(rm.UserName)) CommonObj.Current.RealDict.Add(rm.UserName, _IAsyncResult); else //登录时虽然保存了当前用户的连接,但是登录完后异步向客户端推送了数据,此时这个客户端连接已经失效,那么在connect时相当于才是此客户端与服务器端真正的连接,需要重新更新ServerPushResult的值 CommonObj.Current.RealDict[rm.UserName] = _IAsyncResult; } } }}

4.3回发

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Timers;using System.Data.SqlClient;using System.Data;using System.Configuration;using DBUtility;using Newtonsoft.Json;namespace ServerPushHttpHandler{    //静态实时分发器      //检测当前数据,存入数据缓存中,LSN用作为标志。    public class StaticDistribution   {       //分发器。 主要用于时间扫描,集成在启动时asmx类,创建类,执行类启动方法,退出时,停止方法。       //方法自动根据检测请求是否大于0决定是否执行数据库操作。如果不执行操作,则操作完成       static System.Timers.Timer timer = new System.Timers.Timer();       //开始时间,每次start时设置       private System.DateTime beginTime = new DateTime();       //上一次的EndLSN,下一次的BeginLSN       private Byte[] LSNBytes = new Byte[10];       //首次       private bool isbeing = true;       public StaticDistribution()       {           int RealTimeRefresh=int.Parse(ConfigurationManager.AppSettings["RealTimeRefresh"]);           //30秒扫描一次CDC数据           timer.Interval = RealTimeRefresh;           timer.AutoReset = true;                }       public void start()        {           beginTime = DateTime.Now;           timer.Enabled = true;           timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);           timer.Start();       }       public void end()        {           beginTime = DateTime.MinValue;           isbeing = true;           timer.Enabled = false;           timer.Stop();           timer.Dispose();       }        void  timer_Elapsed(object sender, ElapsedEventArgs e)        {            //有请求时执行            if (CommonObj.Current.RealDict.Count > 0)            {                DataSet ds = new DataSet();                try                {                    //select cdc 得到3个变动                    if (isbeing)                    {                        isbeing = false;                        LSNBytes = new Byte[10];                        SqlParameter[] parameters = {					new SqlParameter("@BeginTime", SqlDbType.DateTime),                    new SqlParameter("@BeginLSN", SqlDbType.VarBinary,10),                    new SqlParameter("@ToLSN", SqlDbType.VarBinary,10)					};                        parameters[0].Value = beginTime;                        parameters[1].Value = DBNull.Value;                        parameters[2].Direction = ParameterDirection.Output;                        parameters[2].Value = LSNBytes;                        BLL.NLog.Current.Info("实时监控分发器读取存储过程开始时间无LSN!" );                        ds = DBUtility.DbHelperSQL.RunProcedure("RealCDC", parameters);//存储过程                        LSNBytes = (Byte[])parameters[2].Value;                        BLL.NLog.Current.Info("实时监控分发器读取存储过程开始时间结束LSN值为:" + HEX.byteToHexStr(LSNBytes));                    }                    else                    {                        SqlParameter[] parameters2 = {					new SqlParameter("@BeginTime", SqlDbType.DateTime),                    new SqlParameter("@BeginLSN", SqlDbType.VarBinary,10),                    new SqlParameter("@ToLSN", SqlDbType.VarBinary,10)					};                        parameters2[0].Value = DBNull.Value;//进入存储过程不同的选择                        parameters2[1].Value = LSNBytes;                        parameters2[2].Direction = ParameterDirection.Output;                                  parameters2[2].Value = LSNBytes;                       BLL.NLog.Current.Info("实时监控分发器读取存储过程开始LSN值为:" + HEX.byteToHexStr(LSNBytes));                       ds = DBUtility.DbHelperSQL.RunProcedure("RealCDC", parameters2);//存储过程                       LSNBytes = (Byte[])parameters2[2].Value;                       BLL.NLog.Current.Info("实时监控分发器读取存储过程结束LSN值为:" + HEX.byteToHexStr(LSNBytes));                    }                }catch(Exception ex1)                {                    BLL.NLog.Current.Info("实时监控分发器读取存储过程失败!"+ex1.Message + Environment.NewLine + ex1.StackTrace);                }                if (ds.Tables.Count == 3)                 {                     DataTable deleteTB=ds.Tables[0];                     DataTable addTB=ds.Tables[1];                     DataTable updateTB=ds.Tables[2];                    lock (CommonObj.Current.RealDict)                    {                        for (int i = 0; i < CommonObj.Current.RealDict.Count; i++)                        {                            ServerPushResult sr = (ServerPushResult)CommonObj.Current.RealDict.ElementAt(i).Value;                            ResponseResultModel srm = new ResponseResultModel();                            try                            {                                                               RealModel realModel=new RealModel();                                srm.ResultStatus=1;                                   realModel.InTimeStamp=sr.rm.InTimeStamp;                                realModel.OutLSN = System.Text.Encoding.Default.GetString(LSNBytes);                                                               //抽取其对应的数据,构造JSON并返回                                //1.请求解包rm                                //2.抽取数据 lsccode 与 Column列                               //要求LSCCODE权限                                if(!String.IsNullOrEmpty(sr.rm.LSCCode))                                {                                    //单独查询LSCCODE                                    if (deleteTB.Rows.Count > 0)                                    {                                        DataRow[] deleterows = deleteTB.Select("LSCCode in (" + sr.rm.LSCCode + ")");                                        realModel.DeleteDT = deleteTB.Clone();                                        for (int j = 0; j < deleterows.Length; j++)                                        {                                            realModel.DeleteDT.ImportRow((DataRow)deleterows[j]);                                        }                                    }                                    if (addTB.Rows.Count > 0)                                    {                                        DataRow[] addrows = addTB.Select("LSCCode in (" + sr.rm.LSCCode + ")");                                        realModel.AddDT = addTB.Clone();                                        for (int j = 0; j < addrows.Length; j++)                                        {                                            realModel.AddDT.ImportRow((DataRow)addrows[j]);                                        }                                    }                                    if (updateTB.Rows.Count > 0)                                    {                                        DataRow[] updaterows = updateTB.Select("LSCCode in (" + sr.rm.LSCCode + ")");                                        realModel.UpdateDT = updateTB.Clone();                                        for (int j = 0; j < updaterows.Length; j++)                                        {                                            realModel.UpdateDT.ImportRow((DataRow)updaterows[j]);                                        }                                    }                                }                                else                                {                                    //查询全部                                    realModel.DeleteDT = deleteTB;                                    realModel.AddDT = addTB;                                    realModel.UpdateDT = updateTB;                                }                                //从datatable中得到定义列                                //3.构造结果ResponseResultModel                                srm.ResultData=realModel;                                sr.Result=srm.ResultString();                                //4.发送                                sr.Send();                                BLL.NLog.Current.Info("实时监控请求处理--发送成功:" + sr.rm.UserName + "请求时间戳:" + sr.rm.InTimeStamp + "回复时间:" + DateTime.Now);                            }                            catch(Exception ex2)                            {                                srm.ResultStatus = -1;                                sr.Result =srm.ResultString();                                sr.Send();                                BLL.NLog.Current.Info("实时监控请求处理--发送异常处理:" + sr.rm.UserName  +ex2.Message + Environment.NewLine + ex2.StackTrace);                            }                        }                       //清空全部                       CommonObj.Current.RealDict.Clear();                    }                }            }            else { isbeing = true; }        }    }}

转载于:https://my.oschina.net/mahaisong/blog/300566

你可能感兴趣的文章
centos启动tomcat无法访问
查看>>
免费馅饼~-~ (hdu 1176
查看>>
wordpress插件汉化包,和使用教程
查看>>
一个使用反射实现的实体类插入数据库工具(java,mysql)
查看>>
激活pycharm
查看>>
Codeforces Round #554 Div.2 C - Neko does Maths
查看>>
解析Http请求调用高德地图的api(货车路径规划)
查看>>
使用静态路由的优点
查看>>
Idea在不关闭project的情况下进行Import Project
查看>>
Advice for students of machine learning
查看>>
ArrayList源码解析-扩容
查看>>
第二周助教总结
查看>>
php封装练习
查看>>
[ Android 五种数据存储方式之三 ] —— SQLite存储数据
查看>>
Android studio 英文——中文 翻译插件
查看>>
jmeter知识总结(一)
查看>>
asp.net三层框架的简单理解
查看>>
入职培训笔记记录--day2(1、变量 2、生命周期与作用域 3、类型转换 4、运算符)...
查看>>
Python基本数据类型
查看>>
SqlServer分页
查看>>