00001 /* ---------------------------------------------------------------------------- 00002 * Microsoft Corporation 00003 * ---------------------------------------------------------------------------- 00004 * Microsoft Project Server mpFx (mpFx) 00005 * ---------------------------------------------------------------------------- 00006 * Author: Colby Africa 00007 * ---------------------------------------------------------------------------- 00008 * License: http://code.msdn.microsoft.com/mpFx/Project/License.aspx 00009 * ---------------------------------------------------------------------------- 00010 */ 00011 00012 using System; 00013 using System.Collections; 00014 using System.Collections.Generic; 00015 using System.Collections.ObjectModel; 00016 using Mcs.Epm.MicrosoftProject.mpFx.CustomFieldsWebService; 00017 using Mcs.Epm.MicrosoftProject.mpFx.ResourcesWebService; 00018 using Microsoft.Office.Project.Server.Library; 00019 00020 namespace Mcs.Epm.MicrosoftProject.mpFx 00021 { 00022 /// <summary> 00023 /// A collection class for ResourceCustomFields 00024 /// </summary> 00025 public class ResourceCustomFieldsCollection : ICollection<ResourceCustomField> 00026 { 00027 #region Static Methods 00028 00029 /// <summary> 00030 /// Given a custom field definition and a resource custom field, attempt to get the value and type 00031 /// </summary> 00032 /// <param name="projectServer">ProjectServer object</param> 00033 /// <param name="customFieldDefinition">Custom field definition</param> 00034 /// <param name="customField">Resource custom field</param> 00035 /// <param name="value">Out value containing the custom field value if successfull</param> 00036 /// <param name="type">Out value containong the data type if successfull</param> 00037 /// <returns>True for success, false if not</returns> 00038 public static bool TryGetFieldValueInformation(ProjectServer projectServer, 00039 CustomFieldDataSet.CustomFieldsRow customFieldDefinition, 00040 ResourceDataSet.ResourceCustomFieldsRow customField, 00041 bool multiLanguage, 00042 out object value, 00043 out CustomFieldValueType type) 00044 { 00045 PSDataType dataType = (PSDataType) customField.FIELD_TYPE_ENUM; 00046 00047 type = CustomFieldValueType.None; 00048 value = null; 00049 00050 switch (dataType) 00051 { 00052 case PSDataType.STRING: 00053 if (customField.IsTEXT_VALUENull() == false) 00054 { 00055 value = customField.TEXT_VALUE; 00056 type = CustomFieldValueType.Text; 00057 } 00058 else if (customField.IsCODE_VALUENull() == false) 00059 { 00060 if (multiLanguage) 00061 { 00062 value = projectServer.LookupTables.MultiLangGetLookupTableTextValue(customFieldDefinition.MD_LOOKUP_TABLE_UID, customField.CODE_VALUE, 1033); 00063 } 00064 else 00065 { 00066 00067 } 00068 00069 type = CustomFieldValueType.Text; 00070 } 00071 break; 00072 case PSDataType.NUMBER: 00073 value = customField.NUM_VALUE.ToString(); 00074 type = CustomFieldValueType.Number; 00075 break; 00076 case PSDataType.DATE: 00077 value = customField.DATE_VALUE.ToUniversalTime().ToLongDateString(); 00078 type = CustomFieldValueType.Date; 00079 break; 00080 default: 00081 break; 00082 } 00083 00084 return type != CustomFieldValueType.None; 00085 } 00086 00087 #endregion 00088 00089 #region Instance Data 00090 00091 private Collection<ResourceCustomField> _ResourceCustomFieldsCollection; 00092 private readonly bool _IsReadOnly; 00093 00094 #endregion 00095 00096 #region Constructor 00097 00098 /// <summary> 00099 /// Create an instance of ResourceCustomFieldsCollection 00100 /// </summary> 00101 /// <param name="parent">EnterpriseResource Parent Object</param> 00102 internal ResourceCustomFieldsCollection(EnterpriseResource parent) 00103 { 00104 // Class cannot be created externally 00105 00106 if (parent == null) 00107 { 00108 throw new ArgumentNullException( /* TODO: Exception Message */); 00109 } 00110 00111 Parent = parent; 00112 00113 _IsReadOnly = true; 00114 00115 LoadResourceCustomFieldsCollection(); 00116 } 00117 00118 #endregion; 00119 00120 #region Internal Properties 00121 00122 /// <summary> 00123 /// Retrieve parent object 00124 /// </summary> 00125 internal EnterpriseResource Parent { get; private set; } 00126 00127 #endregion 00128 00129 #region Indexer 00130 00131 /// <summary> 00132 /// For a given field GUID, retrieve the ResourceCustomField 00133 /// </summary> 00134 /// <param name="fieldGuid">GUID of field to retrieve</param> 00135 /// <returns></returns> 00136 public ResourceCustomField this[Guid fieldGuid] 00137 { 00138 get 00139 { 00140 foreach (ResourceCustomField customField in _ResourceCustomFieldsCollection) 00141 { 00142 if (customField.PropertyGuid == fieldGuid) 00143 { 00144 return customField; 00145 } 00146 } 00147 00148 return null; 00149 } 00150 } 00151 00152 #endregion 00153 00154 #region Private Methods 00155 00156 /// <summary> 00157 /// Load custom fields defined for resources 00158 /// </summary> 00159 private void LoadResourceCustomFieldsCollection() 00160 { 00161 if (_ResourceCustomFieldsCollection == null) 00162 { 00163 _ResourceCustomFieldsCollection = new Collection<ResourceCustomField>(); 00164 } 00165 else 00166 { 00167 _ResourceCustomFieldsCollection.Clear(); 00168 } 00169 00170 List<Guid> loadedFields = new List<Guid>(); 00171 00172 foreach (ResourceDataSet.ResourceCustomFieldsRow customField in Parent.CustomFieldsDataSet.Rows) 00173 { 00174 if (!loadedFields.Contains(customField.MD_PROP_UID)) 00175 { 00176 ResourceCustomField field = new ResourceCustomField(this, 00177 customField.MD_PROP_UID, 00178 Parent.Parent.CustomFieldsDataSet.CustomFields.FindByMD_PROP_UID(customField.MD_PROP_UID).MD_PROP_NAME); 00179 _ResourceCustomFieldsCollection.Add(field); 00180 00181 loadedFields.Add(customField.MD_PROP_UID); 00182 } 00183 } 00184 } 00185 00186 #endregion 00187 00188 #region ICollection<ResourceCustomField> Members 00189 00190 ///<summary> 00191 ///Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"></see>. 00192 ///</summary> 00193 /// 00194 ///<param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param> 00195 ///<exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.</exception> 00196 void ICollection<ResourceCustomField>.Add(ResourceCustomField item) 00197 { 00198 _ResourceCustomFieldsCollection.Add(item); 00199 } 00200 00201 ///<summary> 00202 ///Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"></see>. 00203 ///</summary> 00204 /// 00205 ///<exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only. </exception> 00206 void ICollection<ResourceCustomField>.Clear() 00207 { 00208 _ResourceCustomFieldsCollection.Clear(); 00209 } 00210 00211 ///<summary> 00212 ///Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"></see> contains a specific value. 00213 ///</summary> 00214 /// 00215 ///<returns> 00216 ///true if item is found in the <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false. 00217 ///</returns> 00218 /// 00219 ///<param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param> 00220 bool ICollection<ResourceCustomField>.Contains(ResourceCustomField item) 00221 { 00222 return _ResourceCustomFieldsCollection.Contains(item); 00223 } 00224 00225 ///<summary> 00226 ///Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1"></see> to an <see cref="T:System.Array"></see>, starting at a particular <see cref="T:System.Array"></see> index. 00227 ///</summary> 00228 /// 00229 ///<param name="array">The one-dimensional <see cref="T:System.Array"></see> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1"></see>. The <see cref="T:System.Array"></see> must have zero-based indexing.</param> 00230 ///<param name="arrayIndex">The zero-based index in array at which copying begins.</param> 00231 ///<exception cref="T:System.ArgumentOutOfRangeException">arrayIndex is less than 0.</exception> 00232 ///<exception cref="T:System.ArgumentNullException">array is null.</exception> 00233 ///<exception cref="T:System.ArgumentException">array is multidimensional.-or-arrayIndex is equal to or greater than the length of array.-or-The number of elements in the source <see cref="T:System.Collections.Generic.ICollection`1"></see> is greater than the available space from arrayIndex to the end of the destination array.-or-Type T cannot be cast automatically to the type of the destination array.</exception> 00234 void ICollection<ResourceCustomField>.CopyTo(ResourceCustomField[] array, 00235 int arrayIndex) 00236 { 00237 _ResourceCustomFieldsCollection.CopyTo(array, arrayIndex); 00238 } 00239 00240 ///<summary> 00241 ///Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"></see>. 00242 ///</summary> 00243 /// 00244 ///<returns> 00245 ///true if item was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false. This method also returns false if item is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"></see>. 00246 ///</returns> 00247 /// 00248 ///<param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param> 00249 ///<exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.</exception> 00250 bool ICollection<ResourceCustomField>.Remove(ResourceCustomField item) 00251 { 00252 return _ResourceCustomFieldsCollection.Remove(item); 00253 } 00254 00255 ///<summary> 00256 ///Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"></see>. 00257 ///</summary> 00258 /// 00259 ///<returns> 00260 ///The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"></see>. 00261 ///</returns> 00262 /// 00263 int ICollection<ResourceCustomField>.Count 00264 { 00265 get { return _ResourceCustomFieldsCollection.Count; } 00266 } 00267 00268 ///<summary> 00269 ///Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only. 00270 ///</summary> 00271 /// 00272 ///<returns> 00273 ///true if the <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only; otherwise, false. 00274 ///</returns> 00275 /// 00276 bool ICollection<ResourceCustomField>.IsReadOnly 00277 { 00278 get { return _IsReadOnly; } 00279 } 00280 00281 ///<summary> 00282 ///Returns an enumerator that iterates through the collection. 00283 ///</summary> 00284 /// 00285 ///<returns> 00286 ///A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection. 00287 ///</returns> 00288 ///<filterpriority>1</filterpriority> 00289 IEnumerator<ResourceCustomField> IEnumerable<ResourceCustomField>.GetEnumerator() 00290 { 00291 return _ResourceCustomFieldsCollection.GetEnumerator(); 00292 } 00293 00294 ///<summary> 00295 ///Returns an enumerator that iterates through a collection. 00296 ///</summary> 00297 /// 00298 ///<returns> 00299 ///An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection. 00300 ///</returns> 00301 ///<filterpriority>2</filterpriority> 00302 IEnumerator IEnumerable.GetEnumerator() 00303 { 00304 return ((IEnumerable<ResourceCustomField>) this).GetEnumerator(); 00305 } 00306 00307 #endregion 00308 } 00309 } 00310 00311 /* ------------------------------------------------------------------------------------------------------- 00312 * Change Log 00313 * ------------------------------------------------------------------------------------------------------- 00314 * 2008-06-06: Colby Africa - Added header and footer 00315 * 2008-06-06: Colby Africa - Regionized members 00316 */
1.5.8