檔案的下載動作是透過 ItemType:Vault 來運行。
檔案 ItemType:File 與 ItemType:Vault 是透過 ItemType:Locate 關聯。
因此,當使用者有下載檔案動作時,便會觸發 ItemType:Vault 和 ItemType:Locate 的 [Get] 動作。故我們可以藉由在 ItemType:Locate 的 Server Method : OnAfterGet,實作檔案下載記錄。透過 source_id 取得包含檔案名稱等檔案資訊、透過呼叫 Innovator.getUserID() 取得下載人的資料。
Aras.Server.Security.Identity plmIdentity = Aras.Server.Security.Identity.GetByName("Aras PLM");
bool permissionWasSet = Aras.Server.Security.Permissions.GrantIdentity(plmIdentity);
Innovator inno = this.getInnovator();
try {
string sqlCommandText = string.Format(
@"INSERT INTO file_get_records(username,filename)
SELECT [USER].KEYED_NAME,[FILE].[FILENAME]
FROM [USER],[FILE]
WHERE [USER].ID='{0}' AND [FILE].ID='{1}'", inno.getUserID(), this.getProperty("source_id"));
inno.applySQL(sqlCommandText);
}
finally {
if (permissionWasSet) {
Aras.Server.Security.Permissions.RevokeIdentity(plmIdentity);
}
}
return this;
