Esempio n. 1
0
        public int Checkin(IPendingChange[] changes, string comment, string author, ICheckinNote checkinNote, IEnumerable <IWorkItemCheckinInfo> workItemChanges,
                           TfsPolicyOverrideInfo policyOverrideInfo, bool overrideGatedCheckIn)
        {
            var checkinParameters = new WorkspaceCheckInParameters(_bridge.Unwrap <PendingChange>(changes), comment)
            {
                CheckinNotes         = _bridge.Unwrap <CheckinNote>(checkinNote),
                AssociatedWorkItems  = _bridge.Unwrap <WorkItemCheckinInfo>(workItemChanges),
                PolicyOverride       = ToTfs(policyOverrideInfo),
                OverrideGatedCheckIn = overrideGatedCheckIn
            };

            if (author != null)
            {
                checkinParameters.Author = author;
            }

            try
            {
                return(_workspace.CheckIn(checkinParameters));
            }
            catch (GatedCheckinException gatedException)
            {
                throw new GitTfsGatedCheckinException(gatedException.ShelvesetName, gatedException.AffectedBuildDefinitions, gatedException.CheckInTicket);
            }
        }
        internal static void UpdateReferences(List <string> solutionFiles, string newVersion, Workspace workspace)
        {
            List <ItemSpec> itemSpecs = new List <ItemSpec>();

            ProjectFileUpdater pfu = new ProjectFileUpdater(solutionFiles, newVersion);

            pfu.ExtractCandidateFiles();
            pfu.FindFilesWithFrameworkReferences();

            ConfigFileUpdater cfu = new ConfigFileUpdater(pfu.ProjectFiles, newVersion);

            cfu.ExtractCandidateFiles();
            cfu.FindFilesWithFrameworkReferences();

            List <ReferenceUpdaterBase> rub = new List <ReferenceUpdaterBase>()
            {
                pfu, cfu
            };

            Parallel.ForEach(rub, ru =>
            {
                ru.UpdateReferences(workspace, itemSpecs);
            });

            if (itemSpecs.Count > 0)
            {
                string checkinComment           = String.Format("Changed Framework references to {0}", newVersion);
                WorkspaceCheckInParameters wcip = new WorkspaceCheckInParameters(itemSpecs.ToArray(), checkinComment);
                workspace.CheckIn(wcip);
            }
        }
        private void UpdateVersionBackToTFS(Workspace currentWorkspace, string versionFileLocation, string versionFileName, Version newVersion, String localVersionPath)
        {
            File.WriteAllText(localVersionPath, newVersion.ToString());

            WorkspaceCheckInParameters parameters = new WorkspaceCheckInParameters(new[] { new ItemSpec(versionFileLocation + versionFileName, RecursionType.None) }, "***NO_CI*** - Updating Version");

            currentWorkspace.CheckIn(parameters);
        }
        public void Commit(string checkinComment, string commentOverRidePolicy)
        {
            // Finally check-in, don't trigger a Continuous Integration build and override gated check-in.
            var wip = new WorkspaceCheckInParameters(this.tmpWs.GetPendingChanges(), "***NO_CI***" + checkinComment)
            {
                // Enable the override of gated check-in when the server supports gated check-ins.
                OverrideGatedCheckIn = ((CheckInOptions2)this.vcserver.SupportedFeatures & CheckInOptions2.OverrideGatedCheckIn) == CheckInOptions2.OverrideGatedCheckIn,
                PolicyOverride = new PolicyOverrideInfo(commentOverRidePolicy, null)
            };

            this.tmpWs.CheckIn(wip);
        }
Esempio n. 5
0
        public int Checkin(IPendingChange[] changes, string comment, ICheckinNote checkinNote, IEnumerable<IWorkItemCheckinInfo> workItemChanges,
                           TfsPolicyOverrideInfo policyOverrideInfo, bool overrideGatedCheckIn)
        {
            var checkinParameters = new WorkspaceCheckInParameters(_bridge.Unwrap<PendingChange>(changes), comment)
            {
                CheckinNotes = _bridge.Unwrap<CheckinNote>(checkinNote),
                AssociatedWorkItems = _bridge.Unwrap<WorkItemCheckinInfo>(workItemChanges),
                PolicyOverride = ToTfs(policyOverrideInfo),
                OverrideGatedCheckIn = overrideGatedCheckIn
            };

            return _workspace.CheckIn(checkinParameters);
        }
Esempio n. 6
0
        public int Checkin(IPendingChange[] changes, string comment, ICheckinNote checkinNote, IEnumerable <IWorkItemCheckinInfo> workItemChanges,
                           TfsPolicyOverrideInfo policyOverrideInfo, bool overrideGatedCheckIn)
        {
            var checkinParameters = new WorkspaceCheckInParameters(_bridge.Unwrap <PendingChange>(changes), comment)
            {
                CheckinNotes         = _bridge.Unwrap <CheckinNote>(checkinNote),
                AssociatedWorkItems  = _bridge.Unwrap <WorkItemCheckinInfo>(workItemChanges),
                PolicyOverride       = ToTfs(policyOverrideInfo),
                OverrideGatedCheckIn = overrideGatedCheckIn
            };

            return(_workspace.CheckIn(checkinParameters));
        }
Esempio n. 7
0
        private bool CheckIn(string Path, RecursionType RecursionLevel, string Comment)
        {
            bool result = false;

            //CommonHelper.WriteMessage(string.Format("Get All LocalWorkspaceInfos."));

            WorkspaceInfo[] wsis = Workstation.Current.GetAllLocalWorkspaceInfo();

            foreach (WorkspaceInfo wsi in wsis)
            {
                //Ensure that all this processing is for the current server.
                if (!wsi.ServerUri.DnsSafeHost.ToLower().Equals(collectionUrl.ToLower().Replace("http://", "").Split('/')[0]))
                {
                    continue;
                }

                Workspace ws = GetWorkspace(wsi);

                var pendingChanges = ws.GetPendingChangesEnumerable(Path, (RecursionType)RecursionLevel);

                WorkspaceCheckInParameters checkinParamenters = new WorkspaceCheckInParameters(pendingChanges, Comment);

                //if (RecursionLevel == 0)
                //{
                //    CommonHelper.WriteMessage(string.Format("Check-in {0}.", Path));
                //}
                //else
                //{
                //    CommonHelper.WriteMessage(string.Format("Check-in {0} with recursion level {1}.", Path, (RecursionType)RecursionLevel));
                //}

                ws.CheckIn(checkinParamenters);

                //if (RecursionLevel == 0)
                //{
                //    CommonHelper.WriteMessage(string.Format("Checked-in {0}.", Path));
                //}
                //else
                //{
                //    CommonHelper.WriteMessage(string.Format("Checked-in {0}  with recursion level {1}.", Path, (RecursionType)RecursionLevel));
                //}

                result = true;
                break;
            }



            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// 签入二开
        /// </summary>
        /// <param name="checkInFileInfos">签入的文件信息</param>
        /// <param name="checkInRemark">签入说明</param>
        /// <returns></returns>
        public bool CheckIn(List <FileInfo> checkInFileInfos, string checkInRemark)
        {
            ItemSpec[] itemSpecs = new ItemSpec[checkInFileInfos.Count];
            for (int i = 0; i < checkInFileInfos.Count; i++)
            {
                itemSpecs[i] = new ItemSpec(checkInFileInfos[i].FullName, RecursionType.Full);
            }
            WorkspaceCheckInParameters wscip = new WorkspaceCheckInParameters(itemSpecs, "产品迁移二开工具:" + checkInRemark);

            try
            {
                int changeSetId = ws.CheckIn(wscip);//签入。
                if (changeSetId != -1)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Performs a check-in of the specified item.
        /// </summary>
        /// <param name="item">The path of the file to check in.</param>
        /// <param name="comment">Check-in comment.</param>
        /// <param name="checkinNotes">Check-in notes.</param>
        /// <param name="recursive">Recurse to the last child.</param>
        /// <returns>The result of the evaluation.</returns>
        public static CheckinEvaluationResult CheckIn(string item, string comment = null, CheckinNote checkinNotes = null, bool recursive = false, bool overridePolicyFailures = true)
        {
            var checkinChanges = Workspace.GetPendingChangesEnumerable(item, recursive ? RecursionType.Full : RecursionType.None);

            if (PendingChange.IsIEnumerableEmpty(checkinChanges))
            {
                throw new InvalidOperationException("There are no pending changes!");
            }

            var checkinOptions   = CheckinEvaluationOptions.Notes | CheckinEvaluationOptions.Policies;
            var checkedWorkItems = new WorkItemCheckinInfo[0];

            var result = Workspace.EvaluateCheckin2(checkinOptions, null, checkinChanges, comment, checkinNotes, checkedWorkItems);

            if (result.Conflicts.Length > 0 || result.NoteFailures.Length > 0 || result.PolicyEvaluationException != null ||
                (result.PolicyFailures.Length > 0 && !overridePolicyFailures))
            {
                return(result);
            }

            PolicyOverrideInfo policyOverrideInfo = null;

            if (result.PolicyFailures.Length > 0)
            {
                policyOverrideInfo = new PolicyOverrideInfo("PolicyFailures override!", result.PolicyFailures);
            }

            var checkInParameters = new WorkspaceCheckInParameters(checkinChanges, comment);

            checkInParameters.CheckinNotes        = checkinNotes;
            checkInParameters.AssociatedWorkItems = checkedWorkItems;
            checkInParameters.PolicyOverride      = policyOverrideInfo;
            Workspace.CheckIn(checkInParameters);

            return(result);
        }
Esempio n. 10
0
        public void Save(string filename, XmlDocument xml)
        {
            // Using temporary directory for the workspace mapping
            var dir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

            string serverPath   = filename.Substring(0, filename.LastIndexOf(@"/"));
            string fileNamePart = filename.Replace(serverPath + @"/", string.Empty);

            if (!dir.Exists)
            {
                dir.Create();
            }

            try
            {
                // Query for workspaces and delete if found.
                string username = null;

                if (tpCollection.Credentials is System.Net.NetworkCredential)
                {
                    System.Net.NetworkCredential nw = tpCollection.Credentials as System.Net.NetworkCredential;
                    if (nw.UserName != string.Empty)
                    {
                        username = nw.Domain + @"\" + nw.UserName;
                    }
                }

                if (username == null)
                {
                    username = Environment.UserName;
                }

                var ws = scSrv.QueryWorkspaces("temp", username, Environment.MachineName).FirstOrDefault();
                if (ws != null)
                {
                    ws.Delete();
                }

                // Create the workspace with a mapping to the temporary folder.
                ws = scSrv.CreateWorkspace("temp", username, string.Empty, new WorkingFolder[] { new WorkingFolder(serverPath, dir.FullName) });
                ws.Get(new GetRequest(filename, RecursionType.None, VersionSpec.Latest), GetOptions.None);

                // Create a file and add it as a pending change.
                var      file = Path.Combine(dir.FullName, fileNamePart);
                FileInfo fi   = new FileInfo(file);
                if (fi.Exists)
                {
                    fi.Attributes = FileAttributes.Normal;
                    xml.Save(file);
                    ws.PendEdit(file);
                }
                else
                {
                    xml.Save(file);
                    ws.PendAdd(file);
                }

                // Finally check-in, don't trigger a Continuous Integration build and override gated check-in.
                var wip = new WorkspaceCheckInParameters(ws.GetPendingChanges(), "***NO_CI***")
                {
                    // Enable the override of gated check-in when the server supports gated check-ins.
                    OverrideGatedCheckIn =
                        ((CheckInOptions2)scSrv.SupportedFeatures & CheckInOptions2.OverrideGatedCheckIn) ==
                        CheckInOptions2.OverrideGatedCheckIn,
                    PolicyOverride = new PolicyOverrideInfo("Check-in from IterationnManaager.", null)
                };

                ws.CheckIn(wip);
            }
            finally
            {
                if (dir.Exists)
                {
                    dir.Attributes = FileAttributes.Normal;
                    dir.Delete(true);
                }
            }
        }