Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Last active August 22, 2017 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/0fce80d8d70d18efa895dd902d8ee25f to your computer and use it in GitHub Desktop.
Save JogoShugh/0fce80d8d70d18efa895dd902d8ee25f to your computer and use it in GitHub Desktop.
VersionOne Code Structure WIP
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.Build();
IServices services = new Services(connector);
Oid projectId = services.GetOid("Scope:1012");
IAssetType storyType = services.Meta.GetAssetType("Story");
Asset newStory = services.New(storyType, projectId);
IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name");
newStory.SetAttributeValue(nameAttribute, "My New Story");
services.Save(newStory);
Console.WriteLine(newStory.Oid.Token);
Console.WriteLine(newStory.GetAttribute(storyType.GetAttributeDefinition("Scope")).Value);
Console.WriteLine(newStory.GetAttribute(nameAttribute).Value);
var connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
var newStory = connector.Create("Story", new {
Scope = "Scope:1012"
Name = "My New Story"
});
Console.WriteLine(newStory.OidToken);
Console.WriteLine(newStory.Scope);
Console.WriteLine(newStory.Name);
V1Connector connector = V1Connector
.WithInstanceUrl(instanceUrl)
.WithUserAgentHeader("Examples", "0.1")
.WithAccessToken(accessToken)
.Build();
IServices services = new Services(connector);
IAssetType storyType = services.Meta.GetAssetType("Story");
Query query = new Query(storyType);
IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name");
IAttributeDefinition numberAttribute = storyType.GetAttributeDefinition("Number");
query.Selection.Add(nameAttribute);
query.Selection.Add(numberAttribute);
FilterTerm term = new FilterTerm(numberAttribute);
term.Equal("S-01001");
query.Filter = term;
QueryResult result = services.Retrieve(query);
foreach (Asset story in result.Assets)
{
Console.WriteLine(story.Oid.Token);
Console.WriteLine(story.GetAttribute(nameAttribute).Value);
Console.WriteLine(story.GetAttribute(numberAttribute).Value);
}
var assets = V1Connector
.WithInstanceUrl(instanceUrl)
.WithUserAgentHeader("Examples", "0.1")
.WithAccessToken(accessToken)
.Query("Story")
.Where("Number", "S-01001")
.Select("Name", "Number")
.Retrieve();
foreach (dynamic story in assets)
{
WriteLine(story.OidToken);
WriteLine(story.Name);
WriteLine(story.Number);
}
const string scopeOid = "Scope:1015";
var v1 = V1Connector
.WithInstanceUrl(instanceUrl)
.WithUserAgentHeader("Examples", "0.1")
.WithAccessToken(accessToken);
dynamic scope = v1
.Query(scopeOid)
.Select("Workitems:Story")
.RetrieveFirst();
WriteLine($"Story count: {scope["Workitems:Story"].Count}");
foreach (var story in scope["Workitems:Story"])
{
WriteLine(story);
}
var assets = V1Connector
.WithInstanceUrl(instanceUrl)
.WithUserAgentHeader("Examples", "0.1")
.WithAccessToken(accessToken)
.Query("Scope")
.Select("Name", "Description", "Status", "Members", "Workitems:Defect")
.Retrieve();
foreach (dynamic scope in assets)
{
WriteLine(scope.OidToken);
WriteLine(scope.Description);
WriteLine(scope.Status);
WriteLine($"Members count: {scope.Members.Count}");
foreach (dynamic member in scope.Members)
{
WriteLine(member);
}
WriteLine($"Defects count: {scope["Workitems:Defect"].Count}");
foreach (dynamic defect in scope["Workitems:Defect"])
{
WriteLine(defect);
}
WriteLine("---");
}
var connector = V1Connector
.WithInstanceUrl(instanceUrl)
.WithUserAgentHeader("Examples", "0.1")
.WithAccessToken(accessToken);
var storyOid = "Story:12345";
dynamic retrievedStory = connector.Query(storyOid).Select("Name").RetrieveFirst();
WriteLine($"{retrievedStory.OidToken} original name: {retrievedStory.Name}");
retrievedStory.Name = $"{retrievedStory.Name} - Name updated";
connector.Update(retrievedStory);
dynamic updatedStory = v1.Query(retrievedStory.OidToken).Select("Name").RetrieveFirst();
WriteLine($"{updatedStory.OidToken} updated name: {updatedStory.Name}");
var connector = V1Connector
.WithInstanceUrl(BaseUrl)
.WithUserAgentHeader("Sample", "0.0.0")
.WithUsernameAndPassword(UserName, Password);
var services = new Services(connector);
var StoryAssetType = MetaModel.GetAssetType("Story");
var StoryNameAttribute = MetaModel.GetAttributeDefinition("Story.Name");
var StoryReferenceAttribute = MetaModel.GetAttributeDefinition("Story.Reference");
var StoryNumberAttribute = MetaModel.GetAttributeDefinition("Story.Number");
var StoryStatusAttribute = MetaModel.GetAttributeDefinition("Story.Status");
var StoryPriorityAttribute = MetaModel.GetAttributeDefinition("Story.Priority");
var StoryScopeAttribute = MetaModel.GetAttributeDefinition("Story.Scope");
var StoryOwnersAttriute = MetaModel.GetAttributeDefinition("Story.Owners");
var StoryDescriptionAttribute = MetaModel.GetAttributeDefinition("Story.Description");
var StorySprintAttribute = MetaModel.GetAttributeDefinition("Story.Timebox");
var StoryEpicAttribute = MetaModel.GetAttributeDefinition("Story.Super");
var StoryStateAttribute = MetaModel.GetAttributeDefinition("Story.AssetState");
var StoryProjectAttribute = MetaModel.GetAttributeDefinition("Story.Project");
Query AssetQuery = new Query(StoryAssetType);
AssetQuery.Selection.Add(StoryNameAttribute);
AssetQuery.Selection.Add(StoryReferenceAttribute);
AssetQuery.Selection.Add(StoryNumberAttribute);
AssetQuery.Selection.Add(StoryStatusAttribute);
AssetQuery.Selection.Add(StoryPriorityAttribute);
AssetQuery.Selection.Add(StoryScopeAttribute);
AssetQuery.Selection.Add(StoryOwnersAttriute);
AssetQuery.Selection.Add(StoryDescriptionAttribute);
AssetQuery.Selection.Add(StorySprintAttribute);
AssetQuery.Selection.Add(StoryEpicAttribute);
AssetQuery.Selection.Add(StoryStateAttribute);
AssetQuery.Selection.Add(StoryProjectAttribute);
FilterTerm Filter = new FilterTerm(StoryReferenceAttribute);
Filter.Equal(reference);
AssetQuery.Filter = Filter;
var queryResult = services.Retrieve(AssetQuery);
var reference = "Some reference value...";
var queryResult = V1Connector
.WithInstanceUrl(instanceUrl)
.WithUserAgentHeader("Sample", "0.0.0")
.WithUsernameAndPassword(userName, password)
.Query("Story")
.Select("Name", "Reference", "Number", "Status",
"Priority", "Scope", "Owners", "Description",
"Timebox", "Super", "AssetState")
.Where("Reference", reference)
.Retrieve();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment