Ejemplo n.º 1
0
        /// <summary>
        /// 签出编辑
        /// </summary>
        private bool Checkout(TFSHelper tfsHelper)
        {
            decimal progressAddValue = 80M / this._updateFiles.Count;

            //签出编辑
            foreach (var updateFile in this._updateFiles)
            {
                progressValue += progressAddValue;
                this.worker.ReportProgress((int)progressValue, "开始签出编辑文件" + updateFile.Name + ",请稍后.....");
                var directoryName = updateFile.DirectoryName.Replace(rootProductPath + "\\", "");
                if (directoryName.Contains(rootProductPath))
                {
                    directoryName = updateFile.DirectoryName.Replace(rootProductPath, "");
                    var fileName = Path.Combine(customizePath, directoryName, updateFile.Name);
                    tfsHelper.GetLatest(fileName, JoeyRecursionType.OneLevel);
                    tfsHelper.CheckOut(fileName);
                }
                else
                {
                    var fileName = Path.Combine(customizePath, directoryName, updateFile.Name);
                    //获取文件所在目录的最新版本
                    tfsHelper.GetLatest(fileName);
                    tfsHelper.CheckOut(fileName);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public override TaskStatu Job(TfsVariable tfsVariables, UserVariable <PartialUnitTestSetting> usrVariables)
        {
            var setting = usrVariables.Config;

            if (setting == null)
            {
                return(new TaskStatu("PUT01", "No setting found."));
            }

            var changedAll = TFSHelper.ChangedFiles();

            if (!changedAll.Any())
            {
                return(new TaskStatu("No code change found on TFS"));
            }

            var codes        = changedAll.Where(x => x.FilePath.EndsWith(".cs")).ToList();
            var codesChanged = codes.Where(x => x.State == SourceControlFileState.Changed).ToList();
            var codesAdded   = codes.Where(x => x.State == SourceControlFileState.Added).ToList();

            if (codesChanged.Count + codesAdded.Count < 1)
            {
                return(new TaskStatu("No code changes found to check for partial unit test"));
            }

            var      tmpFile   = codesChanged.Any() ? codesChanged[0] : codesAdded[0];
            Solution gSolution = GetSolutionInfo(tfsVariables, setting, tmpFile);

            if (gSolution == null)
            {
                return(new TaskStatu("PUT03", "No suitable solution found"));
            }

            var tmpMethodsforChanged = GetChangeforChangedFiles(codesChanged, tfsVariables, gSolution);

            if (tmpMethodsforChanged == null)
            {
                return(new TaskStatu("PUT04", "No suitable project document found for changed list"));
            }
            var tmpMethodsforAdded = GetChangeforChangedAdded(codesAdded, tfsVariables, gSolution);

            if (tmpMethodsforAdded == null)
            {
                return(new TaskStatu("PUT05", "No suitable project document found for added list"));
            }

            int totalMethod = tmpMethodsforAdded.MethodCount + tmpMethodsforChanged.MethodCount;

            WriteDetail(string.Format("{0} number of methods will be looked for unit test", totalMethod));
            var unitTesttoCheck = CheckforUnitTest(setting, gSolution, tfsVariables, tmpMethodsforChanged, tmpMethodsforAdded);

            if (unitTesttoCheck == null)
            {
                return(new TaskStatu("PUT06", "No unit test found for partial check"));
            }

            bool isAllSucc = RunUnitTests(tfsVariables, setting, unitTesttoCheck, usrVariables.WorkingPath);

            return(isAllSucc ? new TaskStatu("Partial Unit Test check successful") : new TaskStatu("PUT07", "Partial Unit Test  failed"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 复制更新文件并签出编辑
        /// </summary>
        private bool CopyUpdateFile(TFSHelper tfsHelper)
        {
            //复制文件
            List <FileInfo> removeFiles      = new List <FileInfo>();
            List <FileInfo> undoFiles        = new List <FileInfo>();
            decimal         progressAddValue = 10M / this._updateFiles.Count;

            foreach (var updateFile in this._updateFiles)
            {
                progressValue += progressAddValue;
                this.worker.ReportProgress((int)progressValue, "开始复制文件" + updateFile.Name + ",请稍后.....");
                var directoryName = updateFile.DirectoryName.Replace(rootProductPath + "\\", "");
                if (directoryName.Contains(rootProductPath))
                {
                    directoryName = updateFile.DirectoryName.Replace(rootProductPath, "");
                }
                var fileName = Path.Combine(customizePath, directoryName, updateFile.Name);

                if (File.Exists(fileName))
                {
                    FileInfo fi = new FileInfo(fileName);
                    //修改文件只读
                    if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        fi.Attributes = FileAttributes.Normal;
                    }
                    //如果相同文件没有修改过
                    if (MD5Helper.CompareFile(updateFile.FullName, fileName) && _addFiles.FirstOrDefault(n => n == updateFile) == null)
                    {
                        removeFiles.Add(updateFile);
                        //撤销签出编辑
                        undoFiles.Add(new FileInfo(fileName));
                        JoeyLog.Logging.WriteLog("撤销签出编辑文件:" + fileName);
                        continue;
                    }
                }
                try
                {
                    File.Copy(updateFile.FullName, fileName, true);
                    JoeyLog.Logging.WriteLog("复制编辑签出文件:" + fileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return(false);
                }
            }
            if (undoFiles.Count > 0)
            {
                tfsHelper.Undo(undoFiles);
                foreach (var item in removeFiles)
                {
                    this._updateFiles.Remove(item);
                }
            }
            this.worker.ReportProgress(100, "完成");
            return(true);
        }
Ejemplo n.º 4
0
        public void TfsHelperTest()
        {
            var dictTfs = DummyTfsVariable();
            var tfs     = new TfsVariable(dictTfs);

            TFSHelper.Initialize(tfs);
            var usrGroups = TFSHelper.GroupUserJoined();

            Assert.IsTrue(usrGroups.Count > 0);
        }
Ejemplo n.º 5
0
 private void CheckOutMainItems(string[] listOfEntityInfoPaths)
 {
     EntityHelper.envInfo = envInfo;
     foreach (var enPath in listOfEntityInfoPaths)
     {
         var allItems = EntityHelper.GetEntityFilesListByENFilePath(enPath);
         TFSHelper.CheckOutFile(envInfo.dte, allItems[EntityFileTypeEnum.EntityInfoEN].FullPath);
         TFSHelper.CheckOutFile(envInfo.dte, allItems[EntityFileTypeEnum.EntityObjT].FullPath);
         TFSHelper.CheckOutFile(envInfo.dte, allItems[EntityFileTypeEnum.EntityObjV].FullPath);
         TFSHelper.CheckOutFile(envInfo.dte, allItems[EntityFileTypeEnum.EntityObjTXml].FullPath);
         TFSHelper.CheckOutFile(envInfo.dte, allItems[EntityFileTypeEnum.EntityObjVXml].FullPath);
     }
 }
Ejemplo n.º 6
0
        private void DisplayAllChangedFiles(TfsVariable tfsVariables)
        {
            var files = TFSHelper.ChangedFiles();

            if (files.Any())
            {
                WriteDetail("Changed files are : ");
                foreach (var itm in files)
                {
                    WriteDetail(itm.State + " : " + itm.FilePath);
                }
            }
            else
            {
                WriteDetail("No changed files found");
            }
        }
Ejemplo n.º 7
0
        public static void Serialize <T>(object obj, ICollection <Type> types, FileInfo fileInfo, IServiceProvider serviceProvider)
        {
            Guard.ArgumentNotNull(obj, "obj");
            Guard.ArgumentNotNull(types, "types");
            Guard.ArgumentNotNull(fileInfo, "fileInfo");

            string text = Serialize <T>(obj, types);

            if (serviceProvider != null)
            {
                TFSHelper.CheckOutFile(serviceProvider, fileInfo.FullName);
                File.WriteAllText(fileInfo.FullName, text);
            }
            else
            {
                File.WriteAllText(fileInfo.FullName, text);
            }
        }
Ejemplo n.º 8
0
        public TFSProxy(CompositionContainer container, IMessageService messageService, TFSHelper tfsHelper)
            : base(Resources.ProxyName)
        {
            if (container == null) { throw new ArgumentNullException("container"); }
            if (messageService == null) { throw new ArgumentNullException("messageService"); }
            if (tfsHelper == null) { throw new ArgumentNullException("tfsHelper"); }

            this.container = container;
            this.messageService = messageService;
            this.tfsHelper = tfsHelper;

            this.testConnectionCommand = new DelegateCommand(TestConnectionCommandExcute, CanTestConnectionCommandExcute);

            this.tfsFieldsCache = new List<TFSField>();
            this.stateValues = new ObservableCollection<string>();

            this.CanQuery = false;
        }
Ejemplo n.º 9
0
        public override TaskStatu Job(TfsVariable tfsVariables, UserVariable <FileControlSetting> usrVariables)
        {
            var setting = usrVariables.Config;

            if (setting == null)
            {
                return(new TaskStatu("No setting found."));
            }

            var allFiles = TFSHelper.ChangedFiles();

            if (!allFiles.Any())
            {
                return(new TaskStatu("No changed file found."));
            }

            string adName    = TFSHelper.UserDomainName;
            var    usrGroups = TFSHelper.GroupUserJoined();

            foreach (var sourceData in allFiles)
            {
                var sourceFile = sourceData.FilePath;
                var rule       = setting.Files.FirstOrDefault(x => x.FileNames.Any(y => sourceFile.EndsWith(y)));

                if (rule == null)
                {
                    continue;
                }

                if (rule.AllowedUser.Any(x => x == adName))
                {
                    continue;
                }

                if (rule.AllowedGroup.Any(x => (usrGroups.Any(y => y.EndsWith(x)))))
                {
                    continue;
                }

                return(new TaskStatu("FC01", string.Format("[{0}] file is restirected for [{1}] user.", sourceFile, adName)));
            }

            return(new TaskStatu(string.Format("All changes controlled successfully. FileCount/TotalRule = {0}/{1}.", allFiles.Count, setting.Files.Count)));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This is where shell script trigger. A cocoon ;)
        /// </summary>
        /// <param name="dllName"></param>
        /// <param name="className"></param>
        /// <param name="methodName"></param>
        /// <param name="tfsVarRaw"></param>
        /// <param name="usrVarRaw"></param>
        /// <returns></returns>
        public ShellStatu Initializer(string dllName, string className, string methodName, Dictionary <string, string> tfsVarRaw, Dictionary <string, string> usrVarRaw)
        {
            Stopwatch watchGeneral = Stopwatch.StartNew();
            string    taskLongName = string.Empty;

            try
            {
                taskLongName = Path.GetFileNameWithoutExtension(dllName) + " -> " + className;
                var tfsVar = new TfsVariable(tfsVarRaw);
                var usrVar = new UserVariable <Tsetting>(this.GetType().Name, usrVarRaw);
                Logger.Set(usrVar.WorkingPath);

                var bsSetting = usrVar.Config;
                if (bsSetting == null)
                {
                    return(new ShellStatu(false, string.Format("{0}.{1} tasks setting could not deserialized.", className, methodName)));
                }

                TFSHelper.Initialize(tfsVar);

                Stopwatch watchTask = Stopwatch.StartNew();
                var       tmpResult = Job(tfsVar, usrVar);
                watchTask.Stop();

                if (intrDetailContainer.Any() && !tmpResult.Detail.Any())
                {
                    tmpResult.Detail = intrDetailContainer;
                }

                var rtnData = tmpResult == null ? new ShellStatu() : tmpResult.ToShellStatu(taskLongName);
                watchGeneral.Stop();
                rtnData.Msgs.Add(string.Format("*** FINISH > [{0}] task runned/total (ms) : {1}/{2}",
                                               className, watchTask.Elapsed.TotalMilliseconds, watchGeneral.Elapsed.TotalMilliseconds));

                rtnData.Msgs.Add("---------------------------------------");

                return(rtnData);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return(new ShellStatu(false, string.Format("!!! BaseTask.Initializer failed. TaskName = [{0}]. ExDetail = [{1}].", taskLongName, ex)));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 复制更新文件
        /// </summary>
        private void CopyUpdateFileAndCheckout()
        {
            //Tfs帮助类
            TFSHelper tfsHelper = new TFSHelper(Directory.GetParent(customizePath).FullName, customizeSlnFileName);

            //判断产品TFS是否全部签入
            if (tfsHelper.GetPendingChange().Count > 0)
            {
                _updateFiles = null;
                MessageBox.Show("二开有未签入的数据,不可以再次签入二开,请先签入二开!");
                return;
            }

            //先复制新的文件
            if (!CopyNewFile(tfsHelper))
            {
                return;
            }
            //签出编辑
            if (!Checkout(tfsHelper))
            {
                return;
            }
            //复制文件
            if (!CopyUpdateFile(tfsHelper))
            {
                return;
            }
            //判断是否有编辑签入文件
            if (this._updateFiles.Count == 0)
            {
                MessageBox.Show("没有要编辑签出的文件夹!");
                return;
            }
            MessageBox.Show("复制成功并签出编辑成功!");

            if (CustomizeFileIsTrue() && this._customizeFilePath.Count > 0)
            {
                MessageBox.Show("有二开文件,请点击“显示二开元数据”查看详情信息!");
            }
            JoeyLog.Logging.WriteLog("完成编辑签出");
        }
Ejemplo n.º 12
0
        private MethodUnitTestCollection GetChangeforChangedFiles(List <TFSFileState> changedFiles, TfsVariable tfsVariables, Solution solution)
        {
            var depo = new MethodUnitTestCollection();

            if (!changedFiles.Any())
            {
                return(depo);
            }

            foreach (var itmChanged in changedFiles)
            {
                var webPath       = itmChanged.FilePath.Substring(1).Replace("/", "\\");
                var serverVersion = TFSHelper.DownloadFile(webPath);
                serverVersion = string.IsNullOrEmpty(serverVersion) ? serverVersion : serverVersion.Replace("\r\n", "\n");
                var      localVersionFullPath = Path.Combine(tfsVariables.BuildSourceDirectory, webPath);
                var      report = GetFileChanges(serverVersion, localVersionFullPath);
                Document doc    = null;
                foreach (var tmp in solution.Projects)
                {
                    doc = tmp.Documents.FirstOrDefault(x => x.FilePath == localVersionFullPath);
                    if (doc != null)
                    {
                        break;
                    }
                }
                if (doc == null)
                {
                    WriteDetail(string.Format("(Changed) No project document found for : {0}", localVersionFullPath));
                    return(null);
                }

                var tmpMethods = GetChangedPublicMethods(doc, report);
                if (tmpMethods != null)
                {
                    depo.Add(doc, tmpMethods);
                }
            }

            return(depo);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 复制新的文件
        /// </summary>
        private bool CopyNewFile(TFSHelper tfsHelper)
        {
            _addFiles = new List <FileInfo>();
            //复制文件
            decimal progressAddValue = 10M / this._updateFiles.Count;

            foreach (var updateFile in this._updateFiles)
            {
                progressValue += progressAddValue;
                this.worker.ReportProgress((int)progressValue, "开始复制文件" + updateFile.Name + ",请稍后.....");
                var directoryName = updateFile.DirectoryName.Replace(rootProductPath + "\\", "");
                var fileName      = Path.Combine(customizePath, directoryName, updateFile.Name);

                if (!File.Exists(fileName))
                {
                    //生成新目录
                    string dir = Path.GetDirectoryName(fileName);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                }
                else
                {
                    continue;
                }
                try
                {
                    _addFiles.Add(updateFile);
                    JoeyLog.Logging.WriteLog("复制新的文件" + fileName);
                    File.Copy(updateFile.FullName, fileName, true);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 14
0
        private void ConfigureTreeView(string path, string customizeSlnFileName)
        {
            this.updateTriSatateTreeView.Nodes.Clear();

            try
            {
                //Tfs帮助类
                tfsHelper = new TFSHelper(Directory.GetParent(path).FullName, customizeSlnFileName);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }
            List <FileInfo> fileInfos = tfsHelper.GetPendingChange();

            if (fileInfos != null && fileInfos.Count > 0)
            {
                IEnumerable <IGrouping <string, FileInfo> > dictionarys = fileInfos.GroupBy(n => n.DirectoryName);

                foreach (var dictionary in dictionarys)
                {
                    TriStateTreeNode treeNode1 = new TriStateTreeNode();
                    treeNode1.Text            = dictionary.Key.Replace(path + "\\", "");
                    treeNode1.Text            = dictionary.Key.Replace(path, "");
                    treeNode1.CheckboxVisible = true;
                    treeNode1.Checked         = true;
                    treeNode1.IsContainer     = true;//文件夹
                    foreach (var metadataFile in dictionary)
                    {
                        TriStateTreeNode treeNode2 = new TriStateTreeNode(metadataFile.Name, 2, 2);
                        treeNode2.Checked = true;
                        treeNode2.Tag     = metadataFile;
                        treeNode1.Nodes.Add(treeNode2);
                    }
                    this.updateTriSatateTreeView.Nodes.Add(treeNode1);
                }
            }
        }
Ejemplo n.º 15
0
        void CheckInScripts()
        {
            List <CheckInModel> errorlist   = new List <CheckInModel>();
            List <CheckInModel> successlist = new List <CheckInModel>();

            OpResult = new List <LogText>();
            bool vsucess = true;

            successlist = StoredProcedures;

            var bVersion = cbVersion.Checked;
            var bSingle  = cbSP.Checked;

            try
            {
                if (_username.Length > 0 && _password.Length > 0)
                {
                    TFSAuthModel auth = new TFSAuthModel()
                    {
                        Username = _username, Password = _password
                    };

                    if (successlist.Count > 0)
                    {
                        if (bVersion || bSingle)
                        {
                            // get latest project files
                            if (bVersion)
                            {
                                var res = TFSHelper.GetLatest(_path_version_tfs, auth);
                                AddConsoleText(res);
                                if (res.IsError)
                                {
                                    OpResult.Add(new LogText()
                                    {
                                        IsError = true,
                                        Output  = "Operation failed - Error occured while updating version scripts."
                                    });
                                    vsucess = false;
                                    MessageBox.Show("Error occured while updating version scripts", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }

                            if (bSingle)
                            {
                                var res = TFSHelper.GetLatest(_path_sp_tfs, auth);
                                AddConsoleText(res);
                                if (res.IsError)
                                {
                                    OpResult.Add(new LogText()
                                    {
                                        IsError = true,
                                        Output  = "Operation failed - Error occured while updating Stored Procedures."
                                    });
                                    MessageBox.Show("Error occured while updating Stored Procedures", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }



                            AddManualConsoleTest("Getting latest scripts successful....");

                            // end getting latest

                            //create files if not exists - version
                            bool vcreated = false;
                            if (bVersion)
                            {
                                string path = _path_version_local + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                if (!File.Exists(path))
                                {
                                    FileHelper.CreateFile(path);
                                    vcreated = true;
                                }
                            }

                            //create files if not exists - single
                            if (bSingle)
                            {
                                foreach (var sp in successlist)
                                {
                                    string path = _path_sp_local + "\\" + sp.Name + ".sql";
                                    if (!File.Exists(path))
                                    {
                                        FileHelper.CreateFile(path);
                                        sp.fCreated = true;
                                    }
                                }
                            }

                            //checkout files for edit
                            if (bVersion)
                            {
                                if (!vcreated)
                                {
                                    string path = _path_version_tfs + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                    var    res  = TFSHelper.Checkout(path, auth);
                                    AddConsoleText(res);
                                    if (res != null && res.IsError)
                                    {
                                        OpResult.Add(new LogText()
                                        {
                                            IsError = true,
                                            Output  = "Version Script(" + FileHelper.GenerateDateFile(ScriptDate) + ") - Failed."
                                        });
                                        vsucess = false;
                                    }
                                }
                            }

                            if (bSingle)
                            {
                                foreach (var sp in successlist)
                                {
                                    string path = _path_sp_tfs + "\\" + sp.Name + ".sql";
                                    if (!sp.fCreated)
                                    {
                                        var res = TFSHelper.Checkout(path, auth);
                                        AddConsoleText(res);
                                        if (res.IsError)
                                        {
                                            sp.IsError = true;
                                            errorlist.Add(sp);
                                        }
                                    }
                                }

                                foreach (var ersp in errorlist)
                                {
                                    var sp = successlist.Where(x => x.ID == ersp.ID).SingleOrDefault();
                                    if (sp != null)
                                    {
                                        successlist.Remove(sp);
                                    }
                                }
                            }


                            //add new files to tfs
                            //version script
                            if (bVersion)
                            {
                                if (vcreated)
                                {
                                    var res = TFSHelper.AddFile(_path_version_local, FileHelper.GenerateDateFile(ScriptDate), auth);
                                    AddConsoleText(res);
                                }
                            }

                            if (bSingle)
                            {
                                foreach (var sp in successlist)
                                {
                                    string name = sp.Name + ".sql";
                                    if (sp.fCreated)
                                    {
                                        var res = TFSHelper.AddFile(_path_sp_local, name, auth);
                                        AddConsoleText(res);
                                    }
                                }
                            }


                            //update scripts text
                            if (bVersion)
                            {
                                if (vcreated)
                                {
                                    string path = _path_version_local + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                    FileHelper.UpdateFileText(path, new ScriptHelper().GenerateVersionScript(successlist.Select(x => x.Name).ToList()));
                                }
                                else
                                {
                                    string path    = _path_version_local + "\\" + FileHelper.GenerateDateFile(ScriptDate);
                                    string vscript = FileHelper.ReadFile(path);
                                    StoredProcedureBusiness spData = new StoredProcedureBusiness();
                                    foreach (var s in successlist)
                                    {
                                        string script = new ScriptHelper().GenerateIndividualScript(s.Name, spData.GetScript(null, s.Name).Trim(), true);
                                        vscript = ReplaceScript(vscript, script, s.Name);
                                    }
                                    FileHelper.UpdateFileText(path, vscript);
                                }
                            }

                            //update single scripts
                            if (bSingle)
                            {
                                StoredProcedureBusiness spData = new StoredProcedureBusiness();
                                foreach (var sp in successlist)
                                {
                                    string script = new ScriptHelper().GenerateIndividualScript(sp.Name, spData.GetScript(null, sp.Name).Trim(), false);
                                    string path   = _path_sp_local + "\\" + sp.Name + ".sql";
                                    FileHelper.UpdateFileText(path, script);
                                }
                            }


                            //checkin pending changes
                            string comment = "";
                            if (txtComment.Text.Trim().Length > 0)
                            {
                                comment = txtComment.Text.Trim();
                            }
                            else
                            {
                                comment = "Script Changes";
                            }
                            var checkinres = TFSHelper.CheckIn(comment, auth);
                            AddConsoleText(checkinres);
                            AddManualConsoleTest("Operation completed successfuly");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                GenerateLog(successlist, errorlist, vsucess, bVersion);
            }
        }
Ejemplo n.º 16
0
        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的整数
        }
Ejemplo n.º 17
0
 public TFSFcd(ILog logger)
 {
     _logger    = logger;
     _tfsHelper = new TFSHelper(logger);
 }
Ejemplo n.º 18
0
 public TFSHelperTest()
 {
     this.tfsHelper = new TFSHelper();
     this.tfsHelper.TryConnection(new Uri(TheCodePlexUri), TheUsername, ThePassword, out tpc);
 }
Ejemplo n.º 19
0
 public TFSHelperTest()
 {
     this.tfsHelper = new TFSHelper();
     this.tfsHelper.TryConnection(new Uri(TheCodePlexUri), TheUsername, ThePassword, out tpc);
 }
Ejemplo n.º 20
0
        /// <summary>
        /// 打开更新的文件目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RootFileBtn_Click(object sender, EventArgs e)
        {
            this._updateFiles = new List <FileInfo>();
            this.updateTriSatateTreeView.Nodes.Clear();
            string rootPath = this.pathTBx.Text;

            //获取修改当前日期
            _dt = DateTime.Parse(DateTime.Parse(this.updateDateTimePicker.Text).ToString("yyyy/MM/dd"));
            if (string.IsNullOrEmpty(this.pathTBx.Text))
            {
                //选择文件夹
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                folderBrowserDialog.SelectedPath = rootProductPath;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    //选择的文件夹
                    this.pathTBx.Text = folderBrowserDialog.SelectedPath;
                }
            }
            if (!File.Exists(rootPath + "\\Web.config"))
            {
                MessageBox.Show("请选择产品根目录!");
            }
            else
            {
                //产品TFS
                TFSHelper tfs = new TFSHelper(Directory.GetParent(rootPath).FullName, productSlnFileName);
                _updateFiles.AddRange(GetRootFileName(rootPath));
                _updateFiles.AddRange(GetMetadataFiles(rootPath));
                var pendingFiles = tfs.GetPendingChange();
                //判断产品TFS是否全部签入
                if (pendingFiles.Count > 0)
                {
                    _updateFiles = null;
                    foreach (var item in pendingFiles)
                    {
                        Logging.WriteLog("没有签入的产品文件:", item.FullName);
                    }
                    MessageBox.Show("产品有未签入的数据,不可以迁移二开!");
                    return;
                }
                if (isTip)
                {
                    _updateFiles = null;
                    MessageBox.Show("产品有未签入的元数据,请在建模平台签入后迁移二开!");
                    return;
                }

                _updateFiles.AddRange(GetBinFiles(rootPath));
                _updateFiles.AddRange(GetAppDataFiles(rootPath));
                //获取需要更新的文件夹信息
                foreach (var updateDirectory in _updateDirectorys)
                {
                    openFileName = Path.Combine(rootPath, updateDirectory);
                    _updateFiles.AddRange(GetUpdateFiles(openFileName));
                }


                IEnumerable <IGrouping <string, FileInfo> > dictionarys = _updateFiles.GroupBy(n => n.DirectoryName);
                if (_updateFiles != null && _updateFiles.Count > 0)
                {
                    foreach (var dictionary in dictionarys)
                    {
                        TriStateTreeNode treeNode1 = new TriStateTreeNode();
                        treeNode1.Text            = dictionary.Key.Replace(this.pathTBx.Text + "\\", "");
                        treeNode1.Text            = treeNode1.Text.Replace(this.pathTBx.Text.Replace("00_根目录", ""), "");
                        treeNode1.CheckboxVisible = true;
                        treeNode1.Checked         = true;
                        treeNode1.IsContainer     = true;//文件夹
                        var list = dictionary.OrderBy(n => n.Name);
                        foreach (var metadataFile in list)
                        {
                            TriStateTreeNode treeNode2 = new TriStateTreeNode(metadataFile.Name, 2, 2);
                            treeNode2.Checked = true;
                            treeNode2.Tag     = metadataFile;
                            treeNode1.Nodes.Add(treeNode2);
                        }
                        this.updateTriSatateTreeView.Nodes.Add(treeNode1);
                    }

                    if (this.isTrueCopyRadioBtn.Checked)
                    {
                        this._updateFiles = TriStateTreeNodeHelper.GetTreeNodeChecked(this.updateTriSatateTreeView.Nodes);
                        if (this._updateFiles == null)
                        {
                            MessageBox.Show("请选择产品修改的信息!");
                            return;
                        }
                        if (this._updateFiles.Count == 0)
                        {
                            MessageBox.Show("没有要复制编辑签出的文件!");
                            return;
                        }
                        progressValue = 0;
                        customizePath = this.customizePathCBX.Text;
                        this.worker.RunWorkerAsync();                    // 运行 backgroundWorker 组件
                        ProgressBar form = new ProgressBar(this.worker); // 显示进度条窗体
                        form.ShowDialog(this);
                    }
                }
            }
        }
Ejemplo n.º 21
0
 private void FillProperties()
 {
     TfsHelper = _kernel.Get <TFSHelper>();
 }