Beispiel #1
0
        public int CheckInFile(string filePath)
        {
            if (File.Exists(filePath))
            {
                using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(this.tfsServerUrl))
                {
                    var service   = tfs.GetService <VersionControlServer>();
                    var workspace = service.GetWorkspace(filePath);

                    var conflicts = workspace.QueryConflicts(new string[] { filePath }, true);
                    if (conflicts.Any())
                    {
                        var resolvedConflicts = new Conflict[conflicts.Length];
                        foreach (Conflict conflict in conflicts)
                        {
                            workspace.ResolveConflict(conflict, out resolvedConflicts);
                        }

                        if (resolvedConflicts.Any(resolvedConflict => !resolvedConflict.IsResolved))
                        {
                            throw new Exception(
                                      "Local copy of file saved but conflicts encountered during checkin - Merge and check in manually");
                        }
                    }

                    var pendingChanges = workspace.GetPendingChanges(filePath);
                    if (pendingChanges.Count() == 1)
                    {
                        return(workspace.CheckIn(pendingChanges, "loc file checked in from localization tool"));
                    }
                }

                throw new Exception("No pending changes - please check out file in first step");
            }

            return(-1);
        }