示例#1
0
 /// <summary>
 /// Get workitem details default field
 /// </summary>
 /// <param name="id">
 /// workitem id.
 /// </param>
 /// <returns>
 /// field Name
 /// </returns>
 public string GetDefaultDetailsFieldName(int id)
 {
     try
     {
         if (id > 0)
         {
             string fieldType;
             var    workItem = ItemsStore.GetWorkItem(id);
             using (var stringReader = new StringReader(workItem.DisplayForm))
             {
                 using (var reader = XmlReader.Create(stringReader))
                 {
                     reader.ReadToFollowing("TabGroup");
                     reader.ReadToFollowing("Control");
                     fieldType = reader.GetAttribute("FieldName");
                 }
             }
             return
                 (workItem.Fields.Cast <Field>()
                  .Where(f => f.FieldDefinition.ReferenceName == fieldType)
                  .Select(f => f.Name)
                  .FirstOrDefault() ?? string.Empty);
         }
         return(string.Empty);
     }
     catch (DeniedOrNotExistException e)
     {
         return(null);
     }
 }
示例#2
0
        /// <summary>
        /// The add details for work item.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="fieldName">
        /// The field name.
        /// </param>
        /// <param name="ms">
        /// The memory stream.
        /// </param>
        public void AddDetailsForWorkItem(int id, string fieldName, MemoryStream ms)
        {
            WorkItem workItem = ItemsStore.GetWorkItem(id);

            string temp = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + @"\image.png";

            File.WriteAllBytes(temp, ms.ToArray());

            var attach      = new Attachment(temp);
            var attachIndex = workItem.Attachments.Add(attach);

            workItem.Save();
            Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == fieldName);

            if (itemField != null)
            {
                switch (tfsVersion)
                {
                case TfsVersion.Tfs2011:
                    itemField.Value += string.Format(@"<img src='{0}' />", workItem.Attachments[attachIndex].Uri);
                    break;

                case TfsVersion.Tfs2010:
                    itemField.Value += string.Format("\r({0} : {1})\r", ResourceHelper.GetResourceString("SEE_ATTACHEMENTS"), workItem.Attachments[attachIndex].Name);
                    break;
                }
            }

            workItem.Save();
        }
示例#3
0
        /// <summary>
        /// The add history to work item.
        /// </summary>
        /// <param name="workItemId">
        /// The work item id.
        /// </param>
        /// <param name="historyText">
        /// The history text.
        /// </param>
        public void AddHistoryToWorkItem(int workItemId, string historyText)
        {
            WorkItem workItem = ItemsStore.GetWorkItem(workItemId);

            workItem.History = historyText;
            workItem.Save();
        }
示例#4
0
 /// <summary>
 /// Initializes the results with specified items and result.
 /// </summary>
 /// <param name="items">The items produced by the target.</param>
 /// <param name="result">The overall result for the target.</param>
 internal TargetResult(TaskItem[] items, WorkUnitResult result)
 {
     ErrorUtilities.VerifyThrowArgumentNull(items, "items");
     ErrorUtilities.VerifyThrowArgumentNull(result, "result");
     _itemsStore = new ItemsStore(items);
     _result     = result;
 }
示例#5
0
 /// <summary>
 /// Initializes the results with specified items and result.
 /// </summary>
 /// <param name="items">The items produced by the target.</param>
 /// <param name="result">The overall result for the target.</param>
 internal TargetResult(TaskItem[] items, WorkUnitResult result)
 {
     ErrorUtilities.VerifyThrowArgumentNull(items, "items");
     ErrorUtilities.VerifyThrowArgumentNull(result, "result");
     _itemsStore = new ItemsStore(items);
     _result = result;
 }
示例#6
0
        /// <summary>
        /// Cache the items.
        /// </summary>
        internal void CacheItems(int configId, string targetName)
        {
            lock (_result)
            {
                if (_itemsStore == null)
                {
                    // Already cached.
                    return;
                }

                if (_itemsStore.ItemsCount == 0)
                {
                    // Nothing to cache.
                    return;
                }

                INodePacketTranslator translator = GetResultsCacheTranslator(configId, targetName, TranslationDirection.WriteToStream);

                // If the translator is null, it means these results were cached once before.  Since target results are immutable once they
                // have been created, there is no point in writing them again.
                if (translator != null)
                {
                    try
                    {
                        translator.Translate(ref _itemsStore, ItemsStore.FactoryForDeserialization);
                        _itemsStore = null;
                        _cacheInfo  = new CacheInfo(configId, targetName);
                    }
                    finally
                    {
                        translator.Writer.BaseStream.Close();
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// The add details for work item.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="fieldName">
        /// The field name.
        /// </param>
        /// <param name="bitmapSource">
        /// The bitmap source.
        /// </param>
        public void AddDetailsForWorkItem(int id, string fieldName, BitmapSource bitmapSource)
        {
            WorkItem workItem = ItemsStore.GetWorkItem(id);

            string temp = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + @"\image.png";

            using (var ms = new MemoryStream())
            {
                BitmapEncoder enc = new BmpBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create(bitmapSource));
                enc.Save(ms);
                File.WriteAllBytes(temp, ms.ToArray());
            }

            var attach = new Attachment(temp);

            workItem.Attachments.Add(attach);
            Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == fieldName);

            if (itemField != null)
            {
                itemField.Value += string.Format(@"<img src='{0}' />", attach.Uri);
            }

            workItem.Save();
        }
示例#8
0
 /// <summary>
 /// The get work item.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <returns>
 /// The <see cref="WorkItem"/>.
 /// </returns>
 public WorkItem GetWorkItem(int id)
 {
     try
     {
         return(ItemsStore.GetWorkItem(id));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
示例#9
0
        public List <string> GetWorkItemHistory(int workItemId)
        {
            var      log      = new List <string>();
            WorkItem workItem = ItemsStore.GetWorkItem(workItemId);

            foreach (Revision revision in workItem.Revisions)
            {
                log.AddRange(from Field field in workItem.Fields where revision.Fields[field.Name].Value != null where !string.IsNullOrEmpty(revision.Fields[field.Name].Value.ToString()) select field.Name + ": " + revision.Fields[field.Name].Value);
                log.Add("-------------------------------------");
            }
            return(log);
        }
示例#10
0
        /// <summary>
        /// Is step
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public bool IsStep(int id, string fieldName)
        {
            WorkItem workItem = ItemsStore.GetWorkItem(id);

            Field fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Steps");

            if (fieldSteps == null)
            {
                fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Шаги");
            }

            if (fieldSteps != null && fieldName == fieldSteps.Name)
            {
                return(true);
            }

            return(false);
        }
示例#11
0
        /// <summary>
        /// Replace details for work item
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fieldName"></param>
        /// <param name="data"></param>
        public void ReplaceDetailsForWorkItem(int id, string fieldName, string data)
        {
            WorkItem workItem = ItemsStore.GetWorkItem(id);

            Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name.Equals(fieldName, StringComparison.InvariantCultureIgnoreCase));

            if (fieldName.Equals("system.title", StringComparison.InvariantCultureIgnoreCase))
            {
                itemField = workItem.Fields["System.Title"];
            }

            if (itemField != null)
            {
                itemField.Value  = null;
                itemField.Value += data;
                workItem.Save();
            }
        }
示例#12
0
        /// <summary>
        /// The get html fields by item id.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List <string> GetHtmlFieldsByItemId(int id)
        {
            try
            {
                WorkItem workItem = ItemsStore.GetWorkItem(id);
                switch (tfsVersion)
                {
                case TfsVersion.Tfs2011:
                    return
                        (workItem.Fields.Cast <Field>()
                         .Where(f => f.FieldDefinition.FieldType == FieldType.Html)
                         .Select(f => f.Name)
                         .ToList());

                case TfsVersion.Tfs2010:
                {
                    return
                        (workItem.Fields.Cast <Field>()
                         .Where(
                             f =>
                             f.FieldDefinition.FieldType == FieldType.Html &&
                             f.FieldDefinition.Name != SalmaConstants.TFS.LOCAL_DATA_SOURCE ||
                             (f.FieldDefinition.FieldType == FieldType.PlainText &&
                              f.FieldDefinition.Name !=
                              SalmaConstants.TFS.PROJECT_SERVER_SYNC_ASSIGMENT_DATA) &&
                             f.FieldDefinition.Name != SalmaConstants.TFS.LOCAL_DATA_SOURCE)
                         .Select(f => f.Name)
                         .ToList());
                }
                }

                return(null);
            }
            catch (DeniedOrNotExistException e)
            {
                return(null);
            }
            catch (ArgumentOutOfRangeException e)
            {
                return(null);
            }
        }
示例#13
0
        /// <summary>
        /// Add step
        /// </summary>
        /// <param name="id"></param>
        /// <param name="text"></param>
        public void AddStep(int id, string text)
        {
            WorkItem workItem = ItemsStore.GetWorkItem(id);

            var popup = new StepActionsResult();

            popup.action.Text = text;
            popup.Create(null, Icons.AddDetails);

            ITestManagementService testService = collection.GetService <ITestManagementService>();
            var project  = testService.GetTeamProject(workItem.Project.Name);
            var testCase = project.TestCases.Find(workItem.Id);
            var step     = testCase.CreateTestStep();

            if (!popup.IsCanceled)
            {
                switch (tfsVersion)
                {
                case TfsVersion.Tfs2011:

                    step.Title          = "<div><p><span>" + popup.action.Text + "</span></p></div>";
                    step.ExpectedResult = "<div><p><span>" + popup.expectedResult.Text + "</span></p></div>";

                    break;

                case TfsVersion.Tfs2010:

                    step.Title          = popup.action.Text;
                    step.ExpectedResult = popup.expectedResult.Text;

                    break;
                }

                //testCase.Actions.Clear();
                testCase.Actions.Add(step);
                testCase.Save();
                workItem.Save();
            }
        }
示例#14
0
 /// <summary>
 /// The execute query.
 /// </summary>
 /// <param name="query">
 /// The query.
 /// </param>
 /// <returns>
 /// The <see cref="WorkItemCollection"/>.
 /// </returns>
 public WorkItemCollection ExecuteQuery(string query)
 {
     return(ItemsStore.Query(query));
 }
示例#15
0
        /// <summary>
        /// The add details for work item.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="fieldName">
        /// The field name.
        /// </param>
        /// <param name="dataObject">
        /// The data Object.
        /// </param>
        public void AddDetailsForWorkItem(int id, string fieldName, IDataObject dataObject, out bool comment)
        {
            //var html = dataObject.GetData(DataFormats.Html).ToString();
            string html = ClipboardHelper.Instanse.CopyFromClipboard();

            WorkItem workItem       = ItemsStore.GetWorkItem(id);
            string   attachmentName = string.Empty;

            html = html.CleanHeader();
            IDictionary <string, string> links = html.GetLinks();

            foreach (var link in links)
            {
                if (File.Exists(link.Value) &&
                    !(new FileInfo(link.Value).Extension == ".thmx" || new FileInfo(link.Value).Extension == ".xml" ||
                      new FileInfo(link.Value).Extension == ".mso"))
                {
                    var attach = new Attachment(link.Value);
                    if (tfsVersion == TfsVersion.Tfs2010)
                    {
                        var attachIndex = workItem.Attachments.Add(attach);
                        workItem.Save();
                        attachmentName += string.Format("Name={0} Id={1},", workItem.Attachments[attachIndex].Name, workItem.Attachments[attachIndex].Id);
                        string uri = attach.Uri.ToString();
                        html = html.Replace(link.Key, uri);
                    }
                    else
                    {
                        workItem.Attachments.Add(attach);
                        workItem.Save();
                        string uri = attach.Uri.ToString();
                        html = html.Replace(link.Key, uri);
                    }
                }
                else
                {
                    html = html.Replace(link.Key, string.Empty);
                }
            }

            Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == fieldName);
            //Field fieldSteps = workItem.Fields.Cast<Field>().FirstOrDefault(f => f.Id == 10265);
            Field fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Steps");
            var   fields     = workItem.Fields;

            if (fieldSteps == null)
            {
                fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Шаги");
                //fieldSteps = workItem.Fields.Cast<Field>().FirstOrDefault(f => f.Id == 10032);
            }
            comment = false;
            if (itemField != null)
            {
                if (fieldSteps != null && fieldName == fieldSteps.Name)
                {
                    AddStep(dataObject, workItem, out comment, true);
                }
                else
                {
                    if (tfsVersion == TfsVersion.Tfs2010)
                    {
                        if (itemField.FieldDefinition.FieldType == FieldType.Html)
                        {
                            itemField.Value += html.ClearComments();
                        }
                        else
                        {
                            string temp = Regex.Replace(dataObject.GetData(DataFormats.Text).ToString(), @"\s+", " ");
                            itemField.Value += "\r" + temp;
                            if (attachmentName != string.Empty)
                            {
                                itemField.Value += string.Format("\r({0}: {1})", Resources.SeeAttachments_Text, attachmentName.TrimEnd(','));
                            }
                        }
                    }
                    else
                    {
                        itemField.Value += html.ClearComments();
                    }
                    workItem.Save();
                    comment = true;
                }
            }
        }
示例#16
0
        public bool GetWorkItemFieldHistory(int workItemId, string FieldName, DateTime Date) //Check if Text was changed in WI revisions, comparing comment data created with WI Changed Date
        {
            WorkItem workItem         = ItemsStore.GetWorkItem(workItemId);
            bool     historyIsChanged = false;

            if (FieldName != String.Empty && FieldName != "Title")
            {
                var AllRevisions = from r in workItem.Revisions.OfType <Revision>()
                                   where ((CompareDate(Date, DateTime.Parse(r.Fields["System.ChangedDate"].Value.ToString())) >= 1) && (r.Fields[FieldName].IsChangedInRevision == true))
                                   group r by r.Fields[FieldName].IsChangedInRevision
                                   into g

                                   select new
                {
                    IsChangedInRevision = g.Key,
                    Count = g.Count(),
                };
                int rev = AllRevisions.Count();
                if (rev > 0)
                {
                    return(historyIsChanged = true);
                }
            }

            if (FieldName == "Title")
            {
                foreach (Revision revision in workItem.Revisions)
                {
                    if (revision.Index > 0)
                    {
                        if (revision.Fields["System.Title"].IsChangedInRevision)
                        {
                            DateTime revisionTime =
                                DateTime.Parse(revision.Fields["System.ChangedDate"].Value.ToString());
                            var comparedDate = revisionTime.Subtract(Date);
                            if (comparedDate.Minutes >= 1)
                            {
                                return(historyIsChanged = true);
                            }
                        }
                    }
                }
            }

            //var AllRevisions = from r in workItem.Revisions.OfType<Revision>()
            //    where (DateTime.Parse(r.Fields["Changed Date"].Value.ToString()) > Date)
            //                   && (r.Fields["Title"].IsChangedInRevision == true)
            //    group r by r.Fields["Title"].IsChangedInRevision
            //    into g

            //    select new
            //    {
            //        IsChangedInRevision = g.Key,
            //        Count = g.Count(),
            //    };

            //int rev = AllRevisions.Count();
            //if (rev > 0)
            //{
            //    return historyIsChanged = true;
            //}
            return(historyIsChanged = false);
        }
示例#17
0
        /// <summary>
        /// Cache the items.
        /// </summary>
        internal void CacheItems(int configId, string targetName)
        {
            lock (_result)
            {
                if (_itemsStore == null)
                {
                    // Already cached.
                    return;
                }

                if (_itemsStore.ItemsCount == 0)
                {
                    // Nothing to cache.
                    return;
                }

                INodePacketTranslator translator = GetResultsCacheTranslator(configId, targetName, TranslationDirection.WriteToStream);

                // If the translator is null, it means these results were cached once before.  Since target results are immutable once they
                // have been created, there is no point in writing them again.
                if (translator != null)
                {
                    try
                    {
                        translator.Translate(ref _itemsStore, ItemsStore.FactoryForDeserialization);
                        _itemsStore = null;
                        _cacheInfo = new CacheInfo(configId, targetName);
                    }
                    finally
                    {
                        translator.Writer.BaseStream.Close();
                    }
                }
            }
        }