tfs build 2010 add custom editor
i add a custom editor for our custom process parameter but and add the
assembly to "version control path to custom assemblies" and when i edit
the build definition the editor not show, why?
when i add the assembly into The Visual Studio probing path it work
but i don't want to copy menualy the assembly to all cllints that use this
build and so i want to use the assembly from the source control but then
it don't work
i need i sulotion
my editor code:
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.IO;
using System.Management;
using System.Windows.Forms;
namespace SVBuild
{
public class FolderBrowserEditor : UITypeEditor
{
public override UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{
if (context != null)
return UITypeEditorEditStyle.Modal;
return UITypeEditorEditStyle.None;
}
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
FolderBrowserDialog fd;
string path = "";
string realPath = "";
if (context == null || provider == null || context.Instance == null)
return base.EditValue(provider, value);
fd = new FolderBrowserDialog();
fd.ShowNewFolderButton = true;
fd.Description = "Select Folder";
fd.RootFolder = Environment.SpecialFolder.MyComputer;
if (fd.ShowDialog() == DialogResult.OK)
{
path = fd.SelectedPath;
realPath = ResolveToUNC(path);
}
return realPath;
}
#region ResolveToUNC
/// <summary>Resolves the given path to a full UNC path, or full local
drive path.</summary>
/// <param name="pPath"></param>
/// <returns></returns>
private string ResolveToUNC(string pPath)
{
if (pPath.StartsWith(@"\\")) { return pPath; }
string root = ResolveToRootUNC(pPath);
if (pPath.StartsWith(root))
{
return pPath; // Local drive, no resolving occurred
}
else
{
return pPath.Replace(GetDriveLetter(pPath), root);
}
}
/// <summary>Resolves the given path to a root UNC path, or root local
drive path.</summary>
/// <param name="pPath"></param>
/// <returns>\\server\share OR C:\</returns>
private string ResolveToRootUNC(string pPath)
{
ManagementObject mo = new ManagementObject();
if (pPath.StartsWith(@"\\")) { return
Directory.GetDirectoryRoot(pPath); }
// Get just the drive letter for WMI call
string driveletter = GetDriveLetter(pPath);
mo.Path = new
ManagementPath(string.Format("Win32_LogicalDisk='{0}'",
driveletter));
// Get the data we need
uint DriveType = Convert.ToUInt32(mo["DriveType"]);
string NetworkRoot = Convert.ToString(mo["ProviderName"]);
mo = null;
// Return the root UNC path if network drive, otherwise return the
root path to the local drive
if (DriveType == 4)
{
return NetworkRoot;
}
else
{
return driveletter + Path.DirectorySeparatorChar;
}
}
/// <summary>Checks if the given path is on a network drive.</summary>
/// <param name="pPath"></param>
/// <returns></returns>
private bool isNetworkDrive(string pPath)
{
ManagementObject mo = new ManagementObject();
if (pPath.StartsWith(@"\\")) { return true; }
// Get just the drive letter for WMI call
string driveletter = GetDriveLetter(pPath);
mo.Path = new
ManagementPath(string.Format("Win32_LogicalDisk='{0}'",
driveletter));
// Get the data we need
uint DriveType = Convert.ToUInt32(mo["DriveType"]);
mo = null;
return DriveType == 4;
}
/// <summary>Given a path will extract just the drive letter with
volume separator.</summary>
/// <param name="pPath"></param>
/// <returns>C:</returns>
private string GetDriveLetter(string pPath)
{
if (pPath.StartsWith(@"\\")) { throw new ArgumentException("A UNC
path was passed to GetDriveLetter"); }
return
Directory.GetDirectoryRoot(pPath).Replace(Path.DirectorySeparatorChar.ToString(),
"");
}
No comments:
Post a Comment