為TFS中指定組中的項目添加和刪除指定許可權C#代碼實現

來源:互聯網
上載者:User
        /// <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" >所屬的Team 專案的名稱,例如: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;
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.