现在的位置: 首页 > 综合 > 正文

为TFS中指定组中的项目添加和删除指定权限C#代码实现

2013年08月05日 ⁄ 综合 ⁄ 共 4904字 ⁄ 字号 评论关闭
        /// <summary>
        /// 为指定组添加指定权限
        /// </summary>
        /// <param name="PermissionsName">权限名称</param>
        /// <param name="GroupName">组名称</param>
        /// <param name="ProjectName">组所属的项目</param>
        /// <returns></returns>
        public static string AddPowerForGroup(string PermissionsName, string GroupName, string ProjectName, string CollectionURI)
        {
            StringBuilder sp = new StringBuilder();
            sp.Append("/a+ Project FrameworkGlobalSecurity #PermissionsName "+'"'+"n:[#ProjectName]\\#GroupName"+'"'+" ALLOW /collection:#CollectionURI");
            sp.Replace("#PermissionsName", PermissionsName);
            sp.Replace("#GroupName", GroupName);
            sp.Replace("#ProjectName", ProjectName);
            sp.Replace("#CollectionURI", CollectionURI);
            return sp.ToString();
        }

    /// <summary>
        /// 为指定组移出指定权限
        /// </summary>
        /// <param name="PermissionsName">权限名称</param>
        /// <param name="GroupName">组名称</param>
        /// <param name="ProjectName" >所属的团队项目的名称,例如:surekamspm3</param>
        /// <returns></returns>
        public static string MovePowerForGroup(string PermissionsName, string GroupName, string ProjectName, string CollectionURI)
        {
            StringBuilder sp = new StringBuilder();
            sp.Append("/a- Server FrameworkGlobalSecurity #PermissionsName "+'"'+"n:[#ProjectName]\\#GroupName"+'"'+" ALLOW /collection:#CollectionURI");
            sp.Replace("#PermissionsName", PermissionsName);
            sp.Replace("#GroupName", GroupName);
            sp.Replace("#ProjectName", ProjectName);
            sp.Replace("#CollectionURI", CollectionURI);
            return sp.ToString();
        }

       /// <summary>
        /// 调用tfssecurity为指定组授予指定的权限
        /// </summary>
        /// <param name="PermissionsName">权限名称</param>
        /// <param name="GroupName">组名称</param>
        /// <returns></returns>
        public static string ExcuteAddPowerForGroup(string PermissionsName, string GroupName, string ProjectName, string CollectionURI)
        {
            Process p = new Process();
            string cmdStr = AddPowerForGroup(PermissionsName, GroupName,ProjectName, CollectionURI);
            p.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\TFSSecurity.exe";

            //执行命令及参数
            p.StartInfo.Arguments = cmdStr;
            p.StartInfo.UseShellExecute = false; //关闭Shell的使用
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;//设置不显示窗口
            p.Start();//启动进程

            string standardOutput = p.StandardOutput.ReadToEnd();
            string ErrorOutput = p.StandardError.ReadToEnd();
            string message = standardOutput + "#" + ErrorOutput;
            return message;
        }

        /// <summary>
        /// 为指定的组删除指定的权限
        /// </summary>
        /// <param name="PermissionsName">权限名称</param>
        /// <param name="GroupName">组名称</param>
        /// <returns></returns>
        public static string ExcuteMovePowerForGroup(string PermissionsName, string GroupName, string ProjectName, string CollectionURI)
        {
            Process p = new Process();
            string cmdStr = MovePowerForGroup(PermissionsName, GroupName, ProjectName, CollectionURI);
            p.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\TFSSecurity.exe";

            //执行命令及参数
            p.StartInfo.Arguments = cmdStr;
            p.StartInfo.UseShellExecute = false; //关闭Shell的使用
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;//设置不显示窗口
            p.Start();//启动进程

            string standardOutput = p.StandardOutput.ReadToEnd();
            string ErrorOutput = p.StandardError.ReadToEnd();
            string message = standardOutput + "#" + ErrorOutput;
            return message;
        }

        /// <summary>
        /// 执行获取项目集下所有项目的权限组(项目组)的命令
        /// </summary>
        /// <param name="collectionUrl">项目URL,例如;http://10.2.11.35:8080/tfs/SureKAMSPM3 </param>
        /// <returns>返回正确输出流 + "#" + 错误输出流</returns>
        public static string ExcuteGetAuthortyGroup(string collectionUrl)
        {
            Process p = new Process();
            string cmdStr = ProduceCMD.GetAuthorityGroup(collectionUrl);
            p.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\TFSSecurity.exe";

            //执行命令及参数
            p.StartInfo.Arguments = cmdStr;
            p.StartInfo.UseShellExecute = false; //关闭Shell的使用
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;//设置不显示窗口
            p.Start();//启动进程

            string standardOutput = p.StandardOutput.ReadToEnd();
            string ErrorOutput = p.StandardError.ReadToEnd();
            string message = standardOutput + "#" + ErrorOutput;
            return message;
        }

抱歉!评论已关闭.