ReportingEventReceiver.OnCustomFieldCreated 方法
在建立自訂欄位的報告資料服務後置事件處理常式。
命名空間: Microsoft.Office.Project.Server.Events
組件: Microsoft.Office.Project.Server.Events.Receivers (在 Microsoft.Office.Project.Server.Events.Receivers.dll 中)
語法
'宣告
Public Overridable Sub OnCustomFieldCreated ( _
contextInfo As PSContextInfo, _
e As ReportingPostCustomFieldCreatedEventArgs _
)
'用途
Dim instance As ReportingEventReceiver
Dim contextInfo As PSContextInfo
Dim e As ReportingPostCustomFieldCreatedEventArgs
instance.OnCustomFieldCreated(contextInfo, _
e)
public virtual void OnCustomFieldCreated(
PSContextInfo contextInfo,
ReportingPostCustomFieldCreatedEventArgs e
)
參數
contextInfo
類型:Microsoft.Office.Project.Server.Library.PSContextInfo包含 Project Server 內容資訊。
備註
報告資料服務會建立的自訂欄位資訊更新報表資料庫時的事件之報表自訂欄位。PSI 方法CreateCustomFields和CreateCustomFields2引發自訂欄位建立報表事件之前的事件。這些事件可以是非常關閉的時間。
ReportingCustomFieldMetadataDataSet 提供時傳送到 RDS 的自訂欄位資訊報告系統所需的中繼資料CustomFieldTypeUID dataset 成員的值也可找到的事件引數屬性 e.CustomFieldTypeGUID。
下列兩個實體之名稱包含單字"輸入"不過這些值不與類型相關聯的自訂欄位 (成本、 日期、 工期、 旗標、 數字或文字),而是 GUID (自訂欄位) 的類型。
如需報表資料庫的 RDS 事件的詳細資訊,請參閱 < RDB 事件。
範例
以下是建立自訂欄位後置事件處理常式的範例。範例OnCustomFieldCreated方法從事件參數擷取資訊,並將它寫入至 XML 檔案。
using System;
using System.Data;
using System.IO;
using System.Text;
using Microsoft.Office.Project.Server.Events;
using PSLib = Microsoft.Office.Project.Server.Library;
using PSSchema = Microsoft.Office.Project.Server.Schema;
namespace Microsoft.SDK.Project.Samples.ReportingEvents
{
public class TestCustomFieldCreated : ReportingEventReceiver
{
// Change the output directory for your computer.
private const string OUTPUT_FILES = @"C:\Project\Samples\Output\";
private static string outFilePath;
public override void OnCustomFieldCreated(PSLib.PSContextInfo
contextInfo, ReportingPostCustomFieldCreatedEventArgs e)
{
// Record the time of the event.
DateTime eventRaised = DateTime.Now;
// Create the location for the output file.
outFilePath = OUTPUT_FILES + "ReportingCustomFieldCreatedTestOutput.txt";
// Write event argument information to the output file.
string eventData = "\r\n\r\nCustom Field Created post-event handler: " + eventRaised.ToString();
eventData += "\r\nPWA site Guid: " + contextInfo.SiteGuid.ToString();
eventData += "\r\nUser name: " + contextInfo.UserName;
eventData += "\r\nUser Guid: " + contextInfo.UserGuid;
eventData += "\r\nCustom field type GUID: " + e.CustomFieldTypeGuid.ToString();
// Include the reporting metadata for the custom field.
PSSchema.ReportingCustomFieldMetadataDataSet projectDs = e.CustomFieldMetadataDataSet;
projectDs.WriteXml(outFilePath);
using (StreamWriter outputData = new StreamWriter(outFilePath, true))
{
outputData.WriteLine();
outputData.WriteLine(eventData);
outputData.Close();
}
}
}
}
下列範例會列出 ReportingCustomFieldCreatedTestOutput.txt 檔寫入的應用程式的內容。
注意事項 |
---|
在範例中的自訂欄位資訊是特定的Project Web App執行個體中所定義的自訂欄位。 |
<?xml version="1.0" standalone="yes"?>
<ReportingCustomFieldMetadataDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/ReportingCustomFieldMetadataDataSet/">
<CustomFieldMetadata>
<CustomFieldTypeUID>1e1dfb97-b4fc-4d8a-aaa8-b1ad079a2013</CustomFieldTypeUID>
<ParentEntityTypeGuid>cecfe271-6660-4abe-97ed-208d3c71fc18</ParentEntityTypeGuid>
<CustomFieldName>Test Project Text CF - has LUT</CustomFieldName>
<CustomFieldType>21</CustomFieldType>
<LookupTableUID>cdff825e-8951-4ac7-ad0e-ba28a009dd1d</LookupTableUID>
<IsMultiValueEnabled>false</IsMultiValueEnabled>
<HasWeights>false</HasWeights>
<AssignmentRollDown>false</AssignmentRollDown>
<CreatedDate>2011-03-28T18:45:31.827-07:00</CreatedDate>
<ModificationDate>2011-03-28T18:45:31.827-07:00</ModificationDate>
</CustomFieldMetadata>
</ReportingCustomFieldMetadataDataSet>
Custom Field Created post-event handler: 3/28/2011 6:45:40 PM
PWA site GUID: 9f110f4a-3632-42d3-a1e5-21f9c43360c3
User name: DOMAIN\UserName
User GUID: 2e0fdcc1-85fc-4bde-9593-78a2789c66af
Custom field type GUID: 1e1dfb97-b4fc-4d8a-aaa8-b1ad079a2013