2010-04-07 27 views
0

我在類中實現了IAlertUpdateHandler接口,並用它來處理警報的創建和更新。代碼被解僱,但它通過一次又一次地調用自己進入無限循環。實施IAlertUpdateHandler接口時出現的問題

其實我想壓制電子郵件通知,所以我打電話a.Update(false);但這再次呼籲PreUpdatePostUpdate方法並沒有 StackOverFlowException :(

我試圖返回真/假由這兩種方法,但沒有

回答

0

根據documentation,你應該只是返回true或false,嘗試註釋掉Update調用,並返回true或false,如果你調用Update,你只需要進入遞歸循環和你的return語句將永遠不會被評估

+0

@Hirvox它說**,可用於防止更新或拋出SPException一個布爾值。* *我不想阻止更新,只是爲了禁止訂閱創建的電子郵件。 – TheVillageIdiot 2010-04-07 12:41:50

0

我知道這可能會有點遲,但我認爲無論如何要幫助下一個。

我發現一個解決方案/黑客這個問題。

我相信,當從UI創建警報時,系統會觸發一個SPAlert.update(),所以我想出的是做類似的事情,但忽略從UI調用的更新來做這些事情,我添加了一個自定義財產給SPAlert財產袋。

public bool PreUpdate(SPAlert a, SPWeb web, bool newAlert, string properties) 
{ 
    if (CHECK_IF_SUPPRESSING_EMAIL && !a.Properties.ContainsKey("CustomUpdate")) 
    { 
     //add a property to identify this update 
     a.Properties.Add("CustomUpdate", ""); //can be called anything :) 
     a.Update(false); 
     //return false to ignore the update sent by the UI 
     return false; 
    } 
    else 
    { 
     //no changes here proceed with custom behaviour 
     return true; 
    } 

} 

我已經測試過,似乎這樣的伎倆,希望這可以幫助別人:)