Permalink
Browse files

Changed how fields are parsed for issues

  • Loading branch information...
1 parent 064aed2 commit 031380507399bcf45818c42eeacd20954a2a5484 @hhariri hhariri committed Oct 22, 2011
@@ -50,10 +50,10 @@ public class YTSRP9 :AuthenticatedYouTrackConnectionForIssue
public class YTSRP15: AuthenticatedYouTrackConnectionForIssue
{
- Because of = () => { issue = issueManagement.GetIssue("SB-2"); };
+ Because of = () => { issue = issueManagement.GetIssue("SB-12"); };
It should_contain_assignee = () => { issue.Assignee.ShouldEqual("hhariri"); };
static Issue issue;
- }
+ }
}
@@ -28,7 +28,10 @@
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#endregion
+
+using System.Collections.Generic;
using System.ComponentModel;
+using JsonFx.Json;
namespace YouTrackSharp.Issues
{
@@ -46,5 +49,16 @@ public class Issue
public string Subsystem { get; set; }
public string Description { get; set; }
public string State { get; set; }
+ public int Votes { get; set; }
+ // TODO: not supported
+ //public IEnumerable<Link> Links {get;set;}
+ }
+
+ public class Link
+ {
+ public string Type { get; set; }
+ public string Role { get; set; }
+ [JsonName("$")]
+ public string Value { get; set; }
}
}
@@ -66,9 +66,10 @@ public Issue GetIssue(string issueId)
{
var response = _connection.Get<SingleIssueWrapper>(String.Format("issue/{0}", issueId));
- var issue = TypeDescriptor.GetConverter(typeof (Issue)).ConvertFrom(response.field) as Issue;
+
+ response.field.Add(new Field() { name = "Id", value = response.id });
- issue.Id = response.id;
+ var issue = TypeDescriptor.GetConverter(typeof (Issue)).ConvertFrom(response.field) as Issue;
return issue;
}
@@ -29,6 +29,8 @@
// =============================================================
#endregion
using System;
+using System.Collections;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
@@ -39,41 +41,49 @@ public class IssueTypeConverter : TypeConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
- if (value.GetType() == typeof (Field[]))
+ if (value.GetType() == typeof (List<Field>))
{
- return ConvertFromFields((Field[]) value);
+ var hashValues = CreateHashOfFields((List<Field>) value);
+
+ return ConvertFromFields(hashValues);
}
throw new InvalidCastException("Cannot convert from type: " + value.GetType());
}
+ Hashtable CreateHashOfFields(List<Field> value)
+ {
+
+ var hashTable = new Hashtable(value.Count, StringComparer.InvariantCultureIgnoreCase);
+ foreach (var field in value)
+ {
+ hashTable.Add(field.name, field.value);
+ }
+ return hashTable;
+ }
- Issue ConvertFromFields(Field[] source)
+
+ Issue ConvertFromFields(Hashtable fields)
{
var issue = new Issue();
PropertyInfo[] properties = typeof (Issue).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo property in properties)
{
- property.SetValue(issue, GetValueByName(property.Name, source), null);
+ property.SetValue(issue, Convert.ChangeType(fields[property.Name], property.PropertyType), null);
+ if (String.Compare(property.Name, "Links", true) == 0)
+ {
+ }
}
return issue;
}
- static string GetValueByName(string fieldName, Field[] fields)
+ void ProcessLinkValues(PropertyInfo property, string source)
{
- for (int i = 0; i < fields.Length - 1; i++)
- {
- Field field = fields[i];
-
- if (String.Compare(field.name, fieldName, true) == 0)
- {
- return field.value.ToString();
- }
- }
- return String.Empty;
+
}
+
}
}
@@ -28,12 +28,16 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// =============================================================
#endregion
+
+using System.Collections;
+using System.Collections.Generic;
+
namespace YouTrackSharp.Issues
{
public class SingleIssueWrapper
{
public string id { get; set; }
- public Field[] field { get; set; }
+ public List<Field> field { get; set; }
}
Binary file not shown.
View
@@ -0,0 +1,16 @@
+{"@id":"SB-12","field":[{"@name":"Priority","value":"Normal"},{"@name":"Type","value":"Bug"},{"@name":"State","value":"Submitted"},{"@name":"Assignee","value":"hhariri"},{"@name":"Subsystem","value":"No subsystem"},
+
+
+{"@name":"links","value":[{"@type":"Relates","@role":"relates to","$":"SB-10"},{"@type":"Relates","@role":"relates to","$":"SB-8"}]},
+
+
+
+
+
+
+
+
+
+
+
+{"@name":"projectShortName","value":"SB"},{"@name":"numberInProject","value":"12"},{"@name":"summary","value":"issues with links"},{"@name":"description","value":"gdfgdffgdf"},{"@name":"created","value":"1319221283203"},{"@name":"updated","value":"1319221283203"},{"@name":"updaterName","value":"root"},{"@name":"reporterName","value":"root"},{"@name":"commentsCount","value":"0"},{"@name":"votes","value":"0"}]}
View
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><issue id="SB-12"><field name="Priority"><value>Normal</value></field><field name="Type"><value>Bug</value></field><field name="State"><value>Submitted</value></field><field name="Assignee"><value>hhariri</value></field><field name="Subsystem"><value>No subsystem</value></field><field name="links"><value type="Relates" role="relates to">SB-10</value><value type="Relates" role="relates to">SB-8</value></field><field name="projectShortName"><value>SB</value></field><field name="numberInProject"><value>12</value></field><field name="summary"><value>issues with links</value></field><field name="description"><value>gdfgdffgdf</value></field><field name="created"><value>1319221283203</value></field><field name="updated"><value>1319221283203</value></field><field name="updaterName"><value>root</value></field><field name="reporterName"><value>root</value></field><field name="commentsCount"><value>0</value></field><field name="votes"><value>0</value></field></issue>

0 comments on commit 0313805

Please sign in to comment.