OracleDependency OnChange事件反复触发

时间:2015-01-02 09:27:38

标签: asp.net asp.net-mvc oracle signalr sqldependency

在页面加载时,我调用了 OracleDependency 对象。它在第一次加载页面时非常适用。

表示如果与查询关联的表发生更改(某些联接表存在),则 OracleDependency OnChange 事件触发一次。这是完美的。

但是当我再次刷新页面并且在相同的表中完成的某些更改比 OracleDependency OnChange 事件触发两次时。如果刷新3次而不是 onchange 那么会激发三次。当它发射不止一个时我面临一些问题。

我经历过类似问题的解决方案,但没有运气。

代码:致电On change:

    private DataTable CaseListNotification(Int64 appId, Int64 personId, string value, ref int refOpenCases, ref int refMyCases, ref int refPriorityCases, ref int refEta, string isClosedShow, string isOnholdShow)
    {
        OracleDependency oracleDependency = null;

        //oracleConnection.Open();
        OracleCommand oracleCommand = null;
        OracleConnection oracleConnection = null;
        OracleParameter appIdParamIn = null;
        OracleParameter personIdParamIn = null;
        OracleParameter casesCursorParamOut = null;
        OracleParameter openCasesParam = null;
        OracleParameter myCasesParam = null;
        OracleParameter highPriorityCasesParam = null;
        OracleParameter etaCasesParam = null;
        OracleParameter isShowClosedParam = null;
        OracleParameter isShowOnHoldParam = null;

        DataTable dataTable = new DataTable();
        try
        {

            oracleConnection = Connection.GetGeneralConnection();
            oracleCommand = new OracleCommand("Data.get_data_list", oracleConnection);
            oracleCommand.CommandType = CommandType.StoredProcedure;


            appIdParamIn = new OracleParameter("p_app_id", OracleDbType.Int32, ParameterDirection.Input);
            oracleCommand.Parameters.Add(appIdParamIn).Value = appId;
            personIdParamIn = new OracleParameter("p_pe_id", OracleDbType.Int32, ParameterDirection.Input);
            oracleCommand.Parameters.Add(personIdParamIn).Value = personId;
            isShowClosedParam = new OracleParameter("p_isShow_Closed", OracleDbType.Varchar2, 1, null, ParameterDirection.Input);
            oracleCommand.Parameters.Add(isShowClosedParam).Value = isClosedShow;
            isShowOnHoldParam = new OracleParameter("p_isShow_OnHold", OracleDbType.Varchar2, 1, null, ParameterDirection.Input);
            oracleCommand.Parameters.Add(isShowOnHoldParam).Value = isOnholdShow;

            openCasesParam = CommonFunction.CreateInt32OracleParam("o_open_cases", oracleCommand, null, ParameterDirection.Output);
            myCasesParam = CommonFunction.CreateInt32OracleParam("o_my_cases", oracleCommand, null, ParameterDirection.Output);
            highPriorityCasesParam = CommonFunction.CreateInt32OracleParam("o_high_priority", oracleCommand, null, ParameterDirection.Output);
            etaCasesParam = CommonFunction.CreateInt32OracleParam("o_eta", oracleCommand, null, ParameterDirection.Output);

            casesCursorParamOut = new OracleParameter("o_case_list", OracleDbType.RefCursor);
            casesCursorParamOut.Direction = ParameterDirection.Output;
            oracleCommand.Parameters.Add(casesCursorParamOut);
            if (value == "notification")
            {
                oracleCommand.Notification = null;

                oracleDependency = new OracleDependency(oracleCommand);
                oracleDependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
                oracleCommand.Notification.IsNotifiedOnce = false;
                oracleCommand.AddRowid = true;
            }
            OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(oracleCommand);
            oracleDataAdapter.Fill(dataTable);


            if (openCasesParam.Value != null)
                refOpenCases = Convert.ToInt32(((Oracle.DataAccess.Types.OracleDecimal)(openCasesParam.Value)).Value);
            if (myCasesParam.Value != null)
                refMyCases = Convert.ToInt32(((Oracle.DataAccess.Types.OracleDecimal)(myCasesParam.Value)).Value);
            if (highPriorityCasesParam.Value != null)
                refPriorityCases = Convert.ToInt32(((Oracle.DataAccess.Types.OracleDecimal)(highPriorityCasesParam.Value)).Value);
            if (etaCasesParam.Value != null)
                refEta = Convert.ToInt32(((Oracle.DataAccess.Types.OracleDecimal)(etaCasesParam.Value)).Value);
            Connection.ReleseGeneralConnection(oracleConnection);
            return dataTable;
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

OnChange方法:

private void dependency_OnChange(object sender, OracleNotificationEventArgs e)
{
    OracleDependency dependency = sender as OracleDependency;

    //  NOTE: the following code uses the normal .Net capitalization methods, though
    //      the forum software seems to change it to lowercase letters
    dependency.OnChange -= new OnChangeEventHandler(dependency_OnChange);

    new GetRecordsHub().ShowRecords();

}

程序:

PROCEDURE get_data_list(p_app_id in t_id,
                    p_pe_id in t_id,
                    p_isShow_Closed in t_name,
                    p_isShow_OnHold in t_name,
                    o_open_cases out t_id,
                    o_my_cases out t_id,
                    o_high_priority out t_id,
                    o_eta out t_id,
                    o_case_list out sys_refcursor) IS  C_FUN CONSTANT t_name :='get_data_list'; 

BEGIN
   OPEN o_case_list for 
  SELECT    distinct    ca.ca_id,   ca.ca_number as CaseNumber,   
  cud.cud_name AS Customer,    lod.lde_name AS Location,   
  ca.ca_summary AS Subject,   pe.pe_first_name ||' ' || pe.pe_last_name AS Owner,   
  te.txt_display_text AS Type,   ca.ca_created_date AS CreatedDate,   
  ca.ca_created_date AS CreatedDateForNotification,   
  ca.ca_updated_date AS UpdatedDate,   ca.ca_updated_date AS 
  UpdatedDateForNotification,   dr.pe_first_name ||' ' || dr.pe_last_name AS 
  Driver,    ops.pe_first_name ||' ' || ops.pe_last_name AS OpsManager,   
  tepr.txt_display_text AS Priority,   tere.txt_display_text AS CaseReason,   
    (select count(caco_id) from wb_case_comments where CACO_CA_ID = ca.ca_id) 
      as CmmentCounts,  
    (SELECT caco_comments FROM wb_case_comments 
       WHERE caco_id=(select max(caco_id)
                       from wb_case_comments 
                        where CACO_CA_ID = ca.ca_id and 
                        caco_app_id = p_app_id)
     )   as LatestComments
     FROM    wb_cases ca, cu_customers cud,cu_locations lo,
     cu_location_dsls lod,cu_persons pe,cu_persons dr,cu_persons ops,
     di_texts te,di_texts tepr,di_texts tere   
     where ca.ca_app_id = cud.cud_app_id AND 
     ca.ca_cu_id = cud.cud_cu_id and 
      cud.cud_is_active = 1   AND ca.ca_lo_id = lo.lo_id(+) 
     AND lo.lo_id = lod.lde_lo_id(+)   AND 
     ca.ca_pe_id_owner = pe.pe_id(+)   AND 
     ca.ca_pe_id_driver = dr.pe_id(+)   AND 
     ca.ca_pe_id_opsmanager = ops.pe_id(+)   AND 
     ca.ca_iv_code_status = te.txt_code(+)   AND 
     ca.ca_iv_code_severity = tepr.txt_code(+)   AND 
     ca.ca_iv_code_reason = tere.txt_code(+)   and 
     ca.ca_app_id = p_app_id    and lo.lo_app_id = p_app_id
     and lod.lde_app_id = p_app_id    and pe.pe_app_id = p_app_id
     and dr.pe_app_id = p_app_id    and te.txt_app_id = p_app_id 
     and tepr.txt_app_id = p_app_id     and tere.txt_app_id = p_app_id
     order by ca.ca_id desc;

请帮忙。

0 个答案:

没有答案