后期事件处理程序创建自定义字段的报表数据服务中。
命名空间: 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包含项目的服务器的上下文信息。
备注
报表数据服务引发事件的自定义字段信息更新报告数据库时创建的报告的自定义字段。PSI 方法CreateCustomFields和CreateCustomFields2引发事件报告事件之前创建的自定义字段。这些事件可以是时间非常接近。
ReportingCustomFieldMetadataDataSet 提供了元数据所需的报告系统,如果将自定义字段信息传输到 rds.CustomFieldTypeUID 数据集成员的值还找在事件参数的属性 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