在编程时经常会遇到一些错误,例如,http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.workitemtracking.client.fieldstatus.aspx 上面所列出的错误,简单的通过描述无法确认真的问题所在,那么你就需要查看server内部是如何实现的。 names
在编程时经常会遇到一些错误,例如,http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.workitemtracking.client.fieldstatus.aspx 上面所列出的错误,简单的通过描述无法确认真的问题所在,那么你就需要查看server内部是如何实现的。namespace Microsoft.TeamFoundation.WorkItemTracking.Client { using Microsoft.TeamFoundation; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Common; using Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore; using Microsoft.TeamFoundation.WorkItemTracking.Proxy; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using System.Xml; public sealed class WorkItem : IRevisionInternal { internal const int c_revisionHistory = -4; internal const int c_revisionLatest = -3; internal const int c_revisionNull = -1; internal const int c_revisionUpdate = -2; private DateTime? m_asof; private AttachmentCollection m_attachments; private int m_dataVersion; private bool ? m_dirty; private FieldCollection m_fields; private WorkItemFieldData m_fieldsData; private int m_id; private int m_index; private bool m_IsUpdating; private LinkCollection m_links; private WorkItemLinkData m_linksData; private WorkItemCollection m_list; private int m_metadataVersion; private OpenState m_openState; private Microsoft.TeamFoundation.WorkItemTracking.Client.Project m_project; private bool ? m_readonly; private RevisionCollection m_revisions; private WorkItemStore m_store; private int m_tempId; private WorkItemType m_type; private WorkItemLinkCollection m_wlinks; private WorkItemLinkCollection m_wlinksHistory; private static int [] s_areaDependentFieldIds = new int [] { -12, -42, -43, -44, -45, -46, -47, -48, -49 }; internal static int [] s_internallyCalculatedFieldIds = new int [] { -7, -12, -42, -43, -44, -45, -46, -47, -48, -49, -105, -50, -51, -52, -53, -54, -55, -56 }; private static int [] s_iterationDependentFieldIds = new int [] { -50, -51, -52, -53, -54, -55, -56 }; private static int s_tempId = 0; public event WorkItemFieldChangeEventHandler FieldChanged; public WorkItem(WorkItemType type) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, WorkItemType type)" ); if (type == null ) { throw new ArgumentNullException( "type" ); } this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); this .m_store = type.Store; this .m_id = 0; this .m_tempId = Interlocked.Decrement( ref s_tempId); this .m_openState = OpenState.New; this .m_readonly = false ; this .InitNew(type); this .ApplyRules(); this .m_dirty = true ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal WorkItem(WorkItemCollection list, int index) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; this .m_store = list.Store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); this .m_id = list.GetId(index); this .m_tempId = this .m_id; this .m_list = list; this .m_index = index; this .m_openState = OpenState.Queried; if (!list.Query.IsBatchReadMode) { this .m_asof = new DateTime?(list.Query.AsOfUTC); } } internal WorkItem(WorkItemStore store, int id) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, int id)" ); if (store == null ) { throw new ArgumentNullException( "store" ); } if (id { throw new ArgumentOutOfRangeException( "id" ); } this .m_store = store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); this .m_id = id; this .m_tempId = id; this .LoadWorkItem(id, 0, null ); this .ApplyRules(); Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal WorkItem(WorkItemStore store, System.Uri uri) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, Uri uri)" ); if (store == null ) { throw new ArgumentNullException( "store" ); } this .m_store = store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); if (! this .IsValidUri(uri)) { throw new ArgumentException( "uri" ); } ArtifactId artifact = this .GetArtifact(uri); this .m_id = Convert.ToInt32(artifact.ToolSpecificId, CultureInfo.InvariantCulture); this .m_tempId = this .m_id; this .LoadWorkItem( this .m_id, 0, null ); this .ApplyRules(); Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal WorkItem(WorkItemStore store, int id, DateTime at) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, int id, DateTime at)" ); if (store == null ) { throw new ArgumentNullException( "store" ); } if (id { throw new ArgumentOutOfRangeException( "id" ); } DateTime time = store.ConvertToUniversalTime(at); if ((time new DateTime(0x76c, 1, 1)) || (time >= DateTime.MaxValue)) { throw new ArgumentOutOfRangeException( "at" ); } this .m_store = store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); this .m_id = id; this .m_tempId = id; this .LoadWorkItem(id, 0, new DateTime?(time)); this .ApplyRules(); Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal WorkItem(WorkItemStore store, int id, int revision) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, int id, int revision)" ); if (store == null ) { throw new ArgumentNullException( "store" ); } if (id { throw new ArgumentOutOfRangeException( "id" ); } if (revision { throw new ArgumentOutOfRangeException( "revision" ); } this .m_store = store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); this .m_id = id; this .m_tempId = id; this .LoadWorkItem(id, revision, null ); this .ApplyRules(); Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal WorkItem(WorkItemStore store, System.Uri uri, DateTime at) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, Uri uri, DateTime at)" ); if (store == null ) { throw new ArgumentNullException( "store" ); } DateTime time = store.ConvertToUniversalTime(at); if ((time new DateTime(0x76c, 1, 1)) || (time >= DateTime.MaxValue)) { throw new ArgumentOutOfRangeException( "at" ); } this .m_store = store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); if (! this .IsValidUri(uri)) { throw new ArgumentException( "uri" ); } ArtifactId artifact = this .GetArtifact(uri); this .m_id = Convert.ToInt32(artifact.ToolSpecificId, CultureInfo.InvariantCulture); this .m_tempId = this .m_id; this .LoadWorkItem( this .m_id, 0, new DateTime?(time)); this .ApplyRules(); Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal WorkItem(WorkItemStore store, System.Uri uri, int revision) { this .m_dirty = false ; this .m_readonly = null ; this .m_asof = null ; Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewBegin); TeamFoundationTrace.Verbose( "Entering WorkItem(WorkItemStore store, Uri uri, int revision)" ); if (store == null ) { throw new ArgumentNullException( "store" ); } if (revision { throw new ArgumentOutOfRangeException( "revision" ); } this .m_store = store; this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); if (! this .IsValidUri(uri)) { throw new ArgumentException( "uri" ); } ArtifactId artifact = this .GetArtifact(uri); this .m_id = Convert.ToInt32(artifact.ToolSpecificId, CultureInfo.InvariantCulture); this .m_tempId = this .m_id; this .LoadWorkItem( this .m_id, revision, null ); this .ApplyRules(); Microsoft.TeamFoundation.Common.Marker.Process(Microsoft.TeamFoundation.Common.Mark.OMWorkItemNewEnd); } internal void ApplyFieldChange( int fieldId, object value) { BrieCallBack bc = new BrieCallBack( this ); WorkItemFieldData.FieldUpdate update = new WorkItemFieldData.FieldUpdate(); update.Value = value; update.Flags = 0; bc.FieldUpdates.Add(fieldId, update); this .ApplyFieldChange(fieldId, bc, 2); bc.FieldUpdates.Remove(fieldId); this .FieldData.SetFieldValues(bc.FieldUpdates); this .Store.PsDatastore.BrieAccessCheck(bc, 1, fieldId); this .FieldData.SetFieldStates(bc.FieldStates); } private void ApplyFieldChange( int fieldId, BrieCallBack bc, int recursive) { if (fieldId != 0) { this .Store.PsDatastore.BrieInvalidateFields(bc, fieldId); bc.SetFieldUpdateFlags(WorkItemFieldData.FieldFlags.SetByDefaultRule); this .Store.PsDatastore.BrieAccessCheck(bc, 0x80, fieldId); bc.SetFieldUpdateFlags(0); this .Store.PsDatastore.BrieAccessCheck(bc, 0x40, fieldId); } Dictionary int , bool = "" > dictionary = bc.ResetChanges(); if (recursive > 0) { foreach ( int num in dictionary.Keys) { this .ApplyFieldChange(num, bc, recursive - 1); } } } internal void ApplyRules() { this .ApplyRules( true ); } internal void ApplyRules( bool fSetChangedBy) { this .FieldData.ResetChangedFields(); BrieCallBack callback = new BrieCallBack( this ); callback.SetFieldUpdateFlags(WorkItemFieldData.FieldFlags.SetByDefaultRule); this .Store.PsDatastore.BrieAccessCheck(callback, 0x80, 0); callback.SetFieldUpdateFlags(0); this .Store.PsDatastore.BrieAccessCheck(callback, 0x20, 0); this .ApplyFieldChange(0, callback, 2); this .FieldData.SetFieldValues(callback.FieldUpdates); this .Store.PsDatastore.BrieAccessCheck(callback, 1, 0); this .FieldData.SetAllFieldStates(callback.FieldStates); if (fSetChangedBy) { int id = 9; string userDisplayName = this .m_store.UserDisplayName; if ( this .FieldData.SetUpdateFieldValue(id, userDisplayName, WorkItemFieldData.FieldFlags.SetByRule)) { this .ApplyFieldChange(id, userDisplayName); } } this .FieldData.FireEvents(); } private object CalculateAuthorizedAsField( int revision) { object fieldValue = this .GetFieldValue(-6, revision); if (fieldValue is int ) { return this .m_store.GetPersonNameById(( int ) fieldValue); } return fieldValue; } internal void CalculateFieldLists( int fieldId) { BrieCallBack callback = new BrieCallBack( this ); this .Store.PsDatastore.BrieAccessCheck(callback, 0x17, fieldId); this .FieldData.SetFieldStates(callback.FieldStates); } private object CalculateNodeNameField( int fname, int fid, int revision) { object fieldValue = this .GetFieldValue(fid, revision); if (fieldValue is int ) { return this .m_store.TreeIdToNodeName(( int ) fieldValue); } return fieldValue; } private object CalculateTreeLevelField( int flevel, int flevel1, int fid, int revision) { object fieldValue = this .GetFieldValue(fid, revision); if (fieldValue is int ) { return this .m_store.TreeIdToNodeLevel(( int ) fieldValue, (flevel1 - flevel) + 1); } return fieldValue; } private object CalculateTreePathField( int fpath, int fid, int revision) { object fieldValue = this .GetFieldValue(fid, revision); if (fieldValue is int ) { return this .m_store.TreeIdToPath(( int ) fieldValue); } return fieldValue; } private void CheckType() { WorkItemType type = this .Type; } private void CheckUpdateCachedData() { bool flag = false ; if ( this .m_store.MetadataVersion != this .m_metadataVersion) { flag = true ; } int metadataVersion = this .m_store.MetadataVersion; if ( this .m_project == null ) { object fieldValue = this .GetFieldValue(-2, -2); if (fieldValue != null ) { this .m_project = this .m_store.TreeIdToProject(( int ) fieldValue); } } else if (flag) { this .m_project = this .m_store.Projects.GetById( this .m_project.Id); this .m_type = null ; } if (( this .m_type == null ) && ( this .m_project != null )) { string str = ( string ) this .GetFieldValue(0x19, -2); if (! string .IsNullOrEmpty(str) && this .m_project.WorkItemTypes.Contains(str)) { this .m_type = this .m_project.WorkItemTypes[str]; } } this .m_metadataVersion = metadataVersion; } public void Close() { if (! this .IsNew) { this .m_fieldsData = new WorkItemFieldData( this ); this .m_linksData = new WorkItemLinkData( this ); this .m_revisions = null ; this .m_attachments = null ; this .m_links = null ; this .m_wlinks = null ; this .m_wlinksHistory = null ; this .m_fields = null ; if ( this .m_list != null ) { this .m_openState = OpenState.Queried; } else { this .m_openState = OpenState.Undefined; } } } internal void ConvertFieldValueToExternal( ref object value, System.Type type) { if ((value == null ) && (type == typeof ( string ))) { value = string .Empty; } else if (value is DateTime) { value = this .Store.ConvertToLocalTime((DateTime) value); } } internal WorkItemFieldData.FieldFlags ConvertFieldValueToInternal( ref object value, System.Type type) { if (value == null ) { return 0; } try { object obj2 = value; if (value.GetType() != type) { if ((type == typeof (Guid)) && (value is string )) { obj2 = new Guid(( string ) value); } 查看更多关于workitemtrackingsourcecode的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did96240