Example #1
0
 public WorkItemLinkCollectionWrapper(WorkItemLinkCollection workItemLinkCollection, IRuntimeContext context)
 {
     this.logger = context.Logger;
     this.workItemLinkCollection = workItemLinkCollection;
     this.store   = context.WorkItemRepository;
     this.context = context;
 }
Example #2
0
        public static int getChildEffort(WorkItem wi, WorkItemStore workItemStore)
        {
            WorkItemLinkCollection linkWorkItem = wi.WorkItemLinks;
            int           comEffort             = 0;
            StringBuilder childId = new StringBuilder();

            foreach (WorkItemLink wil in linkWorkItem)
            {
                if (wil.LinkTypeEnd.Name.Equals("Child"))
                {
                    WorkItem childWI = workItemStore.GetWorkItem(wil.TargetId);
                    childId = childId.Append((childWI.Id).ToString()).Append("*");
                    if ("Task".Equals(childWI.Type.Name))
                    {
                        int      childRevs = childWI.Revision;
                        Revision childRev  = childWI.Revisions[childRevs - 1];
                        comEffort = comEffort + Convert.ToInt32(childRev.Fields["Completed work"].Value);
                    }
                    else
                    {
                        comEffort = comEffort + getChildEffort(childWI, workItemStore);
                    }
                }
            }
            return(comEffort);
        }
Example #3
0
        internal static WorkItemLinkCollectionWrapper GetInstance()
        {
            WorkItemLinkCollection real = default(WorkItemLinkCollection);

            RealInstanceFactory(ref real);
            var instance = (WorkItemLinkCollectionWrapper)WorkItemLinkCollectionWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
Example #4
0
        public static List <WorkItem> getWorkItemChild(WorkItemStore workItemStore, WorkItem wi)
        {
            List <WorkItem>        linkedItem = new List <WorkItem>();
            WorkItemLinkCollection links      = wi.WorkItemLinks;

            foreach (WorkItemLink wil in links)
            {
                //search for the correct link
                if (wil.LinkTypeEnd.Name.Equals("Child"))
                {
                    WorkItem childItem = workItemStore.GetWorkItem(wil.TargetId);
                    linkedItem.Add(childItem);
                }
            }
            return(linkedItem);
        }
        private static void WriteWorkItemLinks(XmlWriter xmlWriter, WorkItemLinkCollection workItemLinks)
        {
            xmlWriter.WriteStartElement("WorkItemLinks");

            foreach (WorkItemLink workItemLink in workItemLinks)
            {
                xmlWriter.WriteStartElement("WorkItemLink");

                xmlWriter.WriteAttributeString("LinkTypeEndName", workItemLink.LinkTypeEnd.Name);
                xmlWriter.WriteAttributeString("TargetId", workItemLink.TargetId.ToString());

                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }
Example #6
0
        private static void WriteWorkItemLinks(XmlWriter xmlWriter, WorkItemLinkCollection workItemLinks)
        {
            xmlWriter.WriteStartElement("WorkItemLinks");

            foreach (WorkItemLink workItemLink in workItemLinks)
            {
                xmlWriter.WriteStartElement("WorkItemLink");

                xmlWriter.WriteAttributeString("LinkTypeEndName", workItemLink.LinkTypeEnd.Name);
                xmlWriter.WriteAttributeString("TargetId", workItemLink.TargetId.ToString());

                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }
Example #7
0
        /* Set links between workitems */
        private void CreateLinks(List <WorkItem> workItemCollection, WorkItemStore sourceStore)
        {
            List <int>         linkedWorkItemList       = new List <int>();
            WorkItemCollection targetWorkItemCollection = GetWorkItemCollection();

            foreach (WorkItem workItem in workItemCollection)
            {
                WorkItemLinkCollection links = workItem.WorkItemLinks;
                if (links.Count > 0)
                {
                    int      newWorkItemID = (int)itemMap[workItem.Id];
                    WorkItem newWorkItem   = store.GetWorkItem(newWorkItemID);

                    foreach (WorkItemLink link in links)
                    {
                        try
                        {
                            WorkItem targetItem = sourceStore.GetWorkItem(link.TargetId);
                            if (itemMap.ContainsKey(link.TargetId) && targetItem != null)
                            {
                                int targetWorkItemID = 0;
                                if (itemMap.ContainsKey(link.TargetId))
                                {
                                    targetWorkItemID = (int)itemMap[link.TargetId];
                                }

                                //if the link is not already created(check if target id is not in list)
                                if (!linkedWorkItemList.Contains(link.TargetId))
                                {
                                    try
                                    {
                                        WorkItemLinkTypeEnd linkTypeEnd = store.WorkItemLinkTypes.LinkTypeEnds[link.LinkTypeEnd.Name];
                                        newWorkItem.Links.Add(new RelatedLink(linkTypeEnd, targetWorkItemID));

                                        ArrayList array = newWorkItem.Validate();
                                        if (array.Count == 0)
                                        {
                                            newWorkItem.Save();
                                        }
                                        else
                                        {
                                            logger.Info("WorkItem Validation failed at link setup for work item: " + workItem.Id);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        logger.Info(String.Format("Error occured when crearting link for work item: {0} target item: {1}", workItem.Id, link.TargetId));
                                    }
                                }
                            }
                            else
                            {
                                logger.Info("Link is not created for work item: " + workItem.Id + " - target item: " + link.TargetId + " does not exist");
                            }
                        }
                        catch (Exception)
                        {
                            logger.Info("Link is not created for work item: " + workItem.Id + " - target item: " + link.TargetId + " is not in Source TFS or you do not have permission to access");
                        }
                    }
                    //add the work item to list if the links are processed
                    linkedWorkItemList.Add(workItem.Id);
                }
            }
        }
Example #8
0
        static partial void RealInstanceFactory(ref WorkItemLink real, string callerName)
        {
            WorkItemLinkCollection collection = WorkItemLinkCollectionWrapper_UnitTests.GetRealInstance();

            real = collection[0];
        }
 public WorkItemLinkCollectionWrapper(WorkItemLinkCollection workItemLinkCollection, IWorkItemRepository store, ILogEvents logger)
 {
     this.logger = logger;
     this.workItemLinkCollection = workItemLinkCollection;
     this.store = store;
 }
 public WorkItemLinkCollectionWrapper(WorkItemLinkCollection workItemLinkCollection, IRuntimeContext context)
     : this(context)
 {
     this.workItemLinkCollection = workItemLinkCollection.Cast <WorkItemLink>();
 }
Example #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("123!");
            System.Console.Write("Input FileName: ");
            fileName = Console.ReadLine();

            //read excel file-------------------------------
            Console.WriteLine("Reading File...");
            string path = Environment.CurrentDirectory + "\\";

            path = path + fileName + ".xlsx";
            string          strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + ";" + "Extended Properties='Excel 12.0 Macro;HDR=YES;IMEX=1'";
            OleDbConnection conn    = new OleDbConnection(strConn);

            conn.Open();
            string           strExcel  = "";
            OleDbDataAdapter myCommand = null;
            DataTable        ds        = null;

            strExcel  = "select Id from [sheet1$]";
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            ds        = new DataTable();
            myCommand.Fill(ds);
            conn.Close();

            //创建文件
            //StreamWriter sw = File.AppendText(System.Environment.CurrentDirectory + "\\AnalysisResult.csv");
            FileStream fs = new FileStream(Environment.CurrentDirectory + "\\" + fileName + "_Child.csv", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);

            fs.SetLength(0);
            StreamWriter sw = new StreamWriter(fs);

            //服务器连接,相关对象的获取
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tfs.slb.com/tfs/SLB1/"));

            //版本控制
            version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer;
            WorkItemStore workItemStore = tpc.GetService <WorkItemStore>();

            // get child---------------------------
            sw.WriteLine(" ID,Description,total completed effort,Children");
            foreach (DataRow dr in ds.Rows)
            {
                if (dr[0] != DBNull.Value)
                {
                    WorkItem wi = workItemStore.GetWorkItem(Convert.ToInt32(dr[0]));
                    Console.WriteLine("Id: " + wi.Id);
                    string description = wi.Description;
                    description = description.Replace(",", ".");
                    int           comEffort = 0;
                    StringBuilder childId   = new StringBuilder();
                    if ("Task".Equals(wi.Type.Name))
                    {
                        int      wiRevs = wi.Revision;
                        Revision wiRev  = wi.Revisions[wiRevs - 1];
                        childId   = childId.Append("");
                        comEffort = comEffort + Convert.ToInt32(wiRev.Fields["Completed work"].Value);
                    }
                    else
                    {
                        WorkItemLinkCollection linkWorkItem = wi.WorkItemLinks;
                        foreach (WorkItemLink wil in linkWorkItem)
                        {
                            if (wil.LinkTypeEnd.Name.Equals("Child"))
                            {
                                WorkItem childWI   = workItemStore.GetWorkItem(wil.TargetId);
                                int      childRevs = childWI.Revision;
                                Revision childRev  = childWI.Revisions[childRevs - 1];
                                childId = childId.Append((childWI.Id).ToString()).Append(",");
                                if ("Task".Equals(childWI.Type.Name))
                                {
                                    comEffort = comEffort + Convert.ToInt32(childRev.Fields["Completed work"].Value);
                                }
                                else
                                {
                                    comEffort = comEffort + getChildEffort(childWI, workItemStore);
                                }
                            }
                        }
                    }
                    sw.WriteLine("" + wi.Id + ',' + description + ',' + comEffort + ',' + childId);
                }
            }
            Console.WriteLine("***********************try end**********************");
            sw.Close();
            fs.Close();
            Thread.Sleep(5000);
        }
Example #12
0
 static partial void RealInstanceFactory(ref WorkItemLinkCollection real, string callerName)
 {
     real = GetRealInstance();
 }
 public WorkItemLinkCollectionWrapper(WorkItemLinkCollection workItemLinkCollection, IWorkItemRepository store, ILogEvents logger)
 {
     this.logger = logger;
     this.workItemLinkCollection = workItemLinkCollection;
     this.store = store;
 }
Example #14
0
 static partial void RealInstanceFactory(ref WorkItemLinkCollection real, [CallerMemberName] string callerName        = "");