コード例 #1
0
ファイル: TfsProject.cs プロジェクト: KilskyreMan/JiraToTfs
        public void EndImport()
        {
            var batchFile = "";
            if (newlyImported.Count > 0)
            {
                var progressNotifer = new ProgressNotifier(OnPercentComplete, (newlyImported.Count + 3));

                // Batch save WorkItems to TFS
                progressNotifer.UpdateProgress();
                var workItemStore = (WorkItemStore) tfs.GetService(typeof (WorkItemStore));

                var batch = new WorkItem[newlyImported.Count];
                newlyImported.Values.CopyTo(batch, 0);

                // Unfortunately once created we need to revisit & update TFS ticket state.
                // (Seemingly you cannot create a new TFS ticket with a status of "Closed", "In-progress" etc).
                foreach (var item in newlyImported)
                {
                    updateWorkItem(item.Key, item.Value);
                    progressNotifer.UpdateProgress();
                }
                progressNotifer.UpdateProgress();

                batchFile = generateBatchFile();
                Users.ReleaseImpersonations();
                progressNotifer.UpdateProgress();
            }

            if (tfsUsers.CanImpersonate == false || tfsUsers.FailedImpersonations.Count > 0)
            {
                if (importSummary.Warnings.Count > 0)
                {
                    importSummary.Warnings.Add(Environment.NewLine);
                }
                importSummary.Warnings.Add("Impersonation");
                importSummary.Warnings.Add("-------------");
            }

            if (tfsUsers.CanImpersonate == false)
            {
                importSummary.Warnings.Add(
                    "You don't have impersonation rights enabled. Hence all tickets were created under your name.");
            }
            else if (tfsUsers.FailedImpersonations.Count > 0)
            {
                importSummary.Warnings.Add(string.Format("TFS failed to impersonate the following {0} users.",
                    externalReferenceTag));
                foreach (var failedUser in tfsUsers.FailedImpersonations)
                {
                    importSummary.Warnings.Add(string.Format("* {0}", failedUser.DisplayName));
                }
            }

            if (tfsUsers.NoRightsToAdd.Count > 0)
            {
                if (importSummary.Warnings.Count > 0)
                {
                    importSummary.Warnings.Add(Environment.NewLine);
                }
                importSummary.Warnings.Add("User Rights");
                importSummary.Warnings.Add("-----------");
                importSummary.Warnings.Add(
                    string.Format("The following {0} users do not have rights to add tickets in {1}.",
                        externalReferenceTag, Target));
                importSummary.Warnings.Add(string.Format("Default ticket creator '{0}' used instead.",
                    tfsUsers.CurrentDefaultCreator));
                foreach (var failedUser in tfsUsers.NoRightsToAdd)
                {
                    importSummary.Warnings.Add(string.Format("* {0}", failedUser.DisplayName));
                }
            }

            importSummary.End = DateTime.Now;
            importSummary.Imported = newlyImported.Count;
            importSummary.PreviouslyImported = previouslyImported.Count;
            if (failedAttachments)
            {
                importSummary.Notes.Add(
                    "Default max. attachment size in TFS is 4MB. Contact your TFS Administrator to expand this limit if required.");
            }
            if (string.IsNullOrWhiteSpace(batchFile) == false)
            {
                importSummary.Notes.Add(string.Format("To undo import run the following batch file: '{0}'.", batchFile));
            }
        }
コード例 #2
0
        public void StartImport()
        {
            setCurrentAction("Preparing to import");
            FailedTickets = new List<IFailedTicket>();
            passedTickets = new List<Ticket>();
            var okToImport = ticketTarget.StartImport(ticketSource.Source);
            if (okToImport)
            {
                ticketSource.PreferHtml = ticketTarget.SupportsHtml;

                setCurrentAction(String.Format("Validating {0} tickets against {1}", ticketSource.Source, ticketTarget.Target));

                foreach (var sourceTicket in ticketSource.Tickets(ticketTarget.GetAvailableTicketTypes()))
                {
                    IFailedTicket failedTicket;
                    if (ticketTarget.CheckTicket(sourceTicket, out failedTicket))
                    {
                        passedTickets.Add(sourceTicket);
                    }
                    else
                    {
                        FailedTickets.Add(failedTicket);
                    }
                }

            if (FailedTickets.Count == 0)
            {
                setCurrentAction(String.Format("Creating {0} tickets", ticketTarget.Target));
                var progressNotifer = new ProgressNotifier(onPercentComplete, passedTickets.Count);
                foreach (var passedTicket in passedTickets)
                {
                    if (includeAttachments)
                    {
                        clearDownloadFolder();
                        ticketSource.DownloadAttachments(passedTicket, downloadFolder);
                    }
                    else
                    {
                        passedTicket.Attachments.Clear();
                    }
                    ticketTarget.AddTicket(passedTicket);
                    progressNotifer.UpdateProgress();
                }

                setCurrentAction(String.Format("Updating {0} tickets", ticketTarget.Target));
                ticketTarget.EndImport();

                if (includeAttachments)
                {
                    clearDownloadFolder();
                    Directory.Delete(downloadFolder);
                }

                setCurrentAction("Import complete.");
            }
        }
}
コード例 #3
0
ファイル: TfsProject.cs プロジェクト: KilskyreMan/JiraToTfs
        private void findPreviouslyImportedTickets()
        {
            previouslyImported = new Dictionary<string, WorkItem>();
            var workItemStore = (WorkItemStore) tfs.GetService(typeof (WorkItemStore));

            var query = string.Format("Select [ID] From WorkItems where [Team Project] = '{0}' AND [Hyperlink Count] > 0", project);
            var queryResults = workItemStore.Query(query);
            if (queryResults.Count > 0)
            {
                var externalRef = externalReferenceTag + " [";
                var progressNotifer = new ProgressNotifier(OnPercentComplete, queryResults.Count);
                foreach (WorkItem workItem in queryResults)
                {
                    var hyperLinks = workItem.Links.OfType<Hyperlink>();
                    foreach (var link in hyperLinks)
                    {
                        if (link.Comment.IndexOf(externalRef, StringComparison.Ordinal) == 0)
                        {
                            var toExtract = (link.Comment.Length - externalRef.Length) - 1;
                            var sourceId = link.Comment.Substring(externalRef.Length, toExtract);
                            onDetailedProcessing(string.Format("Retrieving previously imported tickets ({0}).", sourceId));
                            previouslyImported[sourceId] = workItem;
                            break;
                        }
                        progressNotifer.UpdateProgress();
                    }
                }
            }
        }