00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Globalization;
00014 using System.Text.RegularExpressions;
00015 using System.Windows.Forms;
00016 using Mcs.Epm.MicrosoftProject.mpFx.ProjectsWebService;
00017 using Microsoft.Office.Project.Server.Library;
00018
00019 namespace Mcs.Epm.MicrosoftProject.mpFx
00020 {
00021
00022
00023
00024 public static class Utilities
00025 {
00026 private const string REGEX_URL_PATTERN = "(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?";
00027
00028 #region Public Static Methods
00029
00030
00031
00032
00033
00034
00035 public static string GetPropertyTypeDisplayName(object type)
00036 {
00037 return Enum.Parse(typeof (CustomField.Type), type.ToString()).ToString();
00038 }
00039
00040
00041
00042
00043
00044
00045 public static string GetEntityTypeDisplayName(object guid)
00046 {
00047 string uniqueID = guid.ToString().ToUpper(CultureInfo.InvariantCulture);
00048
00049 foreach (Entity entity in EntityCollection.Entities)
00050 {
00051 if (entity.UniqueId == uniqueID)
00052 {
00053 return entity.Name;
00054 }
00055 }
00056
00057 return string.Empty;
00058 }
00059
00060
00061
00062
00063
00064
00065 public static string GetEntityGuidStringFromName(string name)
00066 {
00067 name = name.ToUpper(CultureInfo.InvariantCulture);
00068
00069 foreach (Entity entity in EntityCollection.Entities)
00070 {
00071 if (entity.Name.ToUpper(CultureInfo.InvariantCulture) == name)
00072 {
00073 return entity.UniqueId;
00074 }
00075 }
00076
00077 return string.Empty;
00078 }
00079
00080
00081
00082
00083
00084
00085 public static bool IsValidUrl(string candidate)
00086 {
00087 if (string.IsNullOrEmpty(candidate))
00088 {
00089 return false;
00090 }
00091
00092 Regex urlRegex = new Regex(REGEX_URL_PATTERN);
00093 return urlRegex.IsMatch(candidate);
00094 }
00095
00096 #endregion
00097
00098 public static ProjectDataSet.ProjectRow P(ProjectDataSet projectDataSet)
00099 {
00100 return projectDataSet.Project[0];
00101 }
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110