[英]CRM 2013 - Plugin Execution (Post Operation) What happens and when?
我有一個系統配置實體,在其中存儲Web服務的憑據。 我需要加密密碼字段(new_SharePointServicePassword),並且我希望我的插件進行加密。
因此,我創建了一個新的程序集,並注冊了以下事件。
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "new_systemconfiguration", new Action<LocalPluginContext>(ExecutePostSystemConfigurationCreate)));
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "new_systemconfiguration", new Action<LocalPluginContext>(ExecutePostSystemConfigurationCreate)));
我的插件代碼如下。
string plainTextPassword = SystemConfiguration.new_SharePointServicePassword;
string encryptedPassword;
this.TracingService.Trace("Generating Keys");
Encryption encryption = new Encryption(localContext.PluginExecutionContext.OrganizationId.ToString());
this.TracingService.Trace("Generating Keys - Completed");
if (!string.IsNullOrEmpty(plainTextPassword))
{
this.TracingService.Trace("Encrypting password");
encryptedPassword = encryption.Encrypt(plainTextPassword);
this.TracingService.Trace("Encrypting password - Completed");
SystemConfiguration.new_SharePointServicePassword = encryptedPassword;
localContext.OrganizationService.Update(SystemConfiguration);
}
針對插件注冊的步驟適用於創建和更新消息的后期操作。 更新消息在new_SharePointServicePassword屬性上進行過濾。
問題
localContext.OrganizationService.Update(SystemConfiguration);
需要? 是因為我的插件在更改提交到數據庫后執行? 我建議您在Pre Operation
上運行插件。 因為當您通過UI輸入密碼時,它將首先保存未加密的密碼。 用戶將必須刷新才能看到加密。 另外,如果您在密碼字段上啟用了審核。 它將在審核日志中顯示未加密的密碼。 在“ Pre Operation
您不需要執行以下Pre Operation
:
localContext.OrganizationService.Update(SystemConfiguration);
確保在代碼中將40
替換為20
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.