예제 #1
0
파일: Program.cs 프로젝트: a764578566/Joey
        static void Main(string[] args)
        {
            string sln =
                File.ReadAllText(
                    "E:\\mysoft\\tfs_new\\10.5.10.70\\星河二开项目\\总部星河\\明源云ERPv1.0SP5星河孵化\\源代码\\分支1\\材料供应链二开整体解决方案.sln");

            string regex = @"SccTeamFoundationServer = (.+)\r";

            var math2 = Regex.Matches(sln, regex, RegexOptions.IgnoreCase);

            ////连接TFS
            string tpcURL = "http://10.5.10.70:8080/tfs";

            //登录服务器
            TfsConfigurationServer tfs = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(tpcURL),
                                                                                              new UICredentialsProvider());

            //登录服务前,如果没有登录过会弹出提示框登录,登录过会直接跳过
            tfs.EnsureAuthenticated();

            #region 隐藏
            ////获取tfs服务器上所有项目
            //CatalogNode configurationServerNode = tfs.CatalogNode;

            //ReadOnlyCollection<CatalogNode> tpcNodes = configurationServerNode.QueryChildren(
            //      new Guid[] { CatalogResourceTypes.ProjectCollection },
            //      false,
            //      CatalogQueryOptions.None);

            //List<TfsTeamProjectCollection> lst = new List<TfsTeamProjectCollection>();

            ////遍历每一个TeamProjectCollection 节点
            //foreach (CatalogNode tpcNode in tpcNodes)
            //{
            //    //获取 当前 team project collection 名称.
            //    String displayName = tpcNode.Resource.DisplayName;

            //    // 获得 当前 team project collection 描述.
            //    String description = tpcNode.Resource.Description;

            //    //获取当前 team project collection 的描述.
            //    ServiceDefinition tpcServiceDefinition = tpcNode.Resource.ServiceReferences["Location"];
            //    ILocationService configLocationService = tfs.GetService<ILocationService>();
            //    Uri tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));

            //    // 真正的连接到team project collection
            //    TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri);
            //    lst.Add(tpc);
            //}
            #endregion

            //获取tfs权限
            TeamFoundationIdentity tfi;
            tfs.GetAuthenticatedIdentity(out tfi);

            //登录服务器指定tfs项目
            TfsTeamProjectCollection pjc     = new TfsTeamProjectCollection(new Uri(tpcURL + "/szzb"), tfi.Descriptor);
            VersionControlServer     version = pjc.GetService <VersionControlServer>();

            //获取文件夹目录 ItemSet
            //ItemSet its = version.GetItems("$/", RecursionType.OneLevel);

            //获取工作区
            Workspace[] wss = version.QueryWorkspaces(Environment.MachineName, version.AuthenticatedUser, Environment.MachineName);//查询工作区

            Workspace ws = wss.FirstOrDefault();

            #region 获取最新版本信息
            ItemSet itemSet = version.GetItems("$\\总部星河\\明源云ERPv1.0SP5星河孵化\\源代码\\分支1\\00-ERP站点\\Clgyl\\OrderMng\\M02210303", RecursionType.Full);

            //string filename =
            //    @"E:\mysoft\tfs_new\10.5.10.70\星河二开项目\总部星河\明源云ERPv1.0SP5星河孵化\源代码\分支1\00-ERP站点\Clgyl\OrderMng\M02210303\ApplyEdit.js";

            //foreach (var item in itemSet.Items)
            //{
            //    if (item.ItemType == ItemType.File)
            //    {
            //        if (Path.GetFileName(item.ServerItem) == Path.GetFileName(filename))
            //        {
            //            item.DownloadFile(filename);
            //        }
            //    }
            //}
            #endregion

            #region TFS获取最新版本

            TFSHelper tfsHelper = new TFSHelper("E:\\mysoft\\tfs_new\\10.5.10.70\\星河二开项目\\总部星河\\明源云ERPv1.0SP5星河孵化\\源代码\\分支1", "材料供应链二开整体解决方案.sln");

            ItemSet its = version.GetItems("$/总部星河/明源云ERPv1.0SP5星河孵化/源代码/分支1/00-ERP站点/Clgyl/OrderMng/M02210303", RecursionType.Full);

            tfsHelper.GetLatest("E:\\mysoft\\tfs_new\\10.5.10.70\\星河二开项目\\总部星河\\明源云ERPv1.0SP5星河孵化\\源代码\\分支1\\00-ERP站点\\Clgyl\\OrderMng\\M02210303\\ApplyMng.js");

            #endregion

            //添加Item
            //int pend = ws.PendAdd(localPath);

            //删除Item
            //int pend = ws.PendDelete(localPath);

            //编辑
            //int pend = wss.FirstOrDefault().PendEdit();

            //签入
            //ItemSpec[] itemSpecs = new ItemSpec[1];
            //itemSpecs[0] = new ItemSpec(localDir, RecursionType.Full);
            //WorkspaceCheckInParameters wscip = new WorkspaceCheckInParameters(itemSpecs, "注释内容");
            //int changeSetId = ws.CheckIn(wscip);//如果签入失败changeSetId==-1;反之,返回变更集,大于0的整数
        }
예제 #2
0
        /// <summary>
        /// Load projects from certain user
        /// </summary>
        /// <param name="username">The name of the user which Shelvesets should be fetched</param>
        /// <returns>State if fetching Projects was succesfull</returns>
        public FetchState FetchProjects(string username = "")
        {
            if (m_TfsConfigurationServer == null)
            {
                return(FetchState.UserNotLoggedIn);
            }
            var configurationServerNode = m_TfsConfigurationServer.CatalogNode;

            if (configurationServerNode == null)
            {
                return(FetchState.NoProject);
            }
            IReadOnlyCollection <CatalogNode> tfsTeamProjectNodes = configurationServerNode.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false,
                CatalogQueryOptions.None);


            foreach (CatalogNode projectNode in tfsTeamProjectNodes)
            {
                var tfsTeamProjectCollection = m_TfsConfigurationServer.GetTeamProjectCollection(
                    new Guid(projectNode.Resource.Properties[s_TeamConfigServerIdProperty]));
                m_VersionControl = tfsTeamProjectCollection.GetService <VersionControlServer>();
                PendingSet[] allSets;

                // at start up or context change use authenticated user and on search the given username
                if (string.IsNullOrEmpty(username))
                {
                    TeamFoundationIdentity identity;

                    m_TfsConfigurationServer.GetAuthenticatedIdentity(out identity);
                    allSets = m_VersionControl.QueryShelvedChanges(
                        null,
                        identity.DisplayName);
                    username = identity.DisplayName;
                }
                else
                {
                    try
                    {
                        allSets = m_VersionControl.QueryShelvedChanges(
                            null,
                            username);
                    }
                    catch (Microsoft.TeamFoundation.VersionControl.Client.IdentityNotFoundException)
                    {
                        return(FetchState.UserNotFound);
                        //nothing to do here
                        //m_VersionControl.QueryShelvedChanges throws an exception if the given username is not valid
                    }
                }

                IList <PendingSetWrapper> wrapper = new List <PendingSetWrapper>();

                //get Shelveset from PendingSet.
                //need the CreatedDate from the Shelveset to order the PndingSets
                foreach (PendingSet set in allSets)
                {
                    Shelveset[] shelvesets = m_VersionControl.QueryShelvesets(set.Name, username);
                    wrapper.Add(new PendingSetWrapper(set, shelvesets[0].CreationDate));
                }
                var orderedWrapper = wrapper.OrderByDescending(d => d.CreationDate.Date);

                Project = new ProjectData(projectNode.Resource.DisplayName, orderedWrapper.ToArray());
            }

            OnSetUsername(username);
            OnChanged(Project);

            return(FetchState.Successful);
        }