TFS 2012 API Set TeamSettings Programmatically - c#

Is it possible to set the TeamSettings Programmatically?
var teamConfig = _tfs.GetService<TeamSettingsConfigurationService>();
var css = _tfs.GetService<ICommonStructureService4>();
var configs = teamConfig.GetTeamConfigurationsForUser(new[] { _selectedTeamProject.Uri });
var team = configs.Where(c => c.TeamName == "Demo").FirstOrDefault() as TeamConfiguration;
The above code gives me the Team Configuration for the team Demo. Look at the TeamSettings, it contains the property BacklogIterationPath, CurrentIterationPath, IterationPaths. How can these be set programmatically?

I think I have solved it myself.
// Set up default team sprint date and time
var teamConfig = _tfs.GetService<TeamSettingsConfigurationService>();
var css = _tfs.GetService<ICommonStructureService4>();
string rootNodePath = string.Format("\\{0}\\Iteration\\Release 1\\Sprint 1", _selectedTeamProject.Name);
var pathRoot = css.GetNodeFromPath(rootNodePath);
css.SetIterationDates(pathRoot.Uri, DateTime.Now.AddDays(-5), DateTime.Now.AddDays(7));
var configs = teamConfig.GetTeamConfigurationsForUser(new[] { _selectedTeamProject.Uri });
var team = configs.Where(c => c.TeamName == "Demo").FirstOrDefault();
var ts = team.TeamSettings;
ts.BacklogIterationPath = string.Format(#"{0}\Release 1", _selectedTeamProject.Name);
ts.IterationPaths = new string[] { string.Format(#"{0}\Release 1\Sprint 1", _selectedTeamProject.Name), string.Format(#"{0}\Release 1\Sprint 2", _selectedTeamProject.Name) };
var tfv = new TeamFieldValue();
tfv.IncludeChildren = true;
tfv.Value = _selectedTeamProject.Name;
ts.TeamFieldValues = new []{tfv};
teamConfig.SetTeamSettings(team.TeamId, ts);
This sets up,
1. Iteration Start and Finish Date for an Iteration
2. Backlog Iteration Path for the team Demo
3. Sets up Iteration Paths for the team Demo
4. Sets up the default Area Path for the team Demo
HTH
Cheers, Tarun

Related

How do I add a metric name to MetricOrderBy when using Google.Analytics.Data.V1Beta?

I am writing come code in c# with Visual Studio 2022 to fetch Google G4 analytics data and cannot get one piece to work correctly. It is the part where a create an "OrderBy" list for the "RunReportRequest". I have defined 3 lists for each of dimensions, metrics & orderby
List<Dimension> Dlist = new();
List<Metric> Mlist = new();
List<OrderBy> Olist = new();
when I add items to the Dlist and MList using the following it works fine.
Dlist.Add(new Dimension { Name = "country" });
Mlist.Add(new Metric { Name = "activeUsers" });
when I try to add the OrderBy it fails.
OrderBy orderBy = new OrderBy();
orderBy.Metric.MetricName = "activeUsers";
orderBy.Desc = true;
Olist.Add(orderBy);
Although the program compiles and runs but stops at the line
orderBy.Metric.MetricName = "activeUsers";
with the error message
'Object reference not set to an instance of an object.'
I also tried another way
Olist.Add(new OrderBy { Metric = "activeUsers", Desc = true });
but this indicates an error
Cannot implicitly convert type "string" to "Google.Analytics.Data.V1Beta.OrderBy.Types.MetricOrderBy"
the code that creates the report request is as follows
var G4request2 = new RunReportRequest
{
Property = "properties/" + Grequest.PropertyId,
Dimensions = { Dlist },
Metrics = { Mlist },
DateRanges = { new DateRange { StartDate = Grequest.StartDate, EndDate = Grequest.EndDate } },
OrderBys = { Olist }
};
If I do not include the Olist and don't use the OrderBys = { Olist} line in the RunReportRequest the program works and the Google Date is retrieved (just not sorted in the order I want though).
Can anyone help me with a suggestion how to fix the issue with the OrderBy part please?
Try using orderbys in the following manner:
RunReportRequest request = new RunReportRequest
{
Property = "properties/" + propertyId,
Dimensions = { new Dimension { Name = Dimensions },},
Metrics = { new Metric { Name = Matrix }, },
DateRanges = { new DateRange { StartDate = strStartDate, EndDate = strEndDate }, },
OrderBys = {new OrderBy {Dimension = new OrderBy.Types.DimensionOrderBy() { DimensionName = "date" }, Desc = false}, }
};
This gives the response sorted by date in ascending order.

How to set Backlog Iteration and Team/Area connection programmatically?

So far I can programmatically create a new Team and a new Area, but when I navigate to the TFS 2015 "Work" tab I see this error:
TF400509: No backlog iteration path was specified. You must select an iteration path.
So if I manually choose one iteration then I get:
TF400512: You have not selected any areas for your team. You must select at least one area before you can use features such as the product backlog, the task board or tiles.
Here's my code:
tpc.Authenticate();
// Create New Area
ICommonStructureService css = tpc.GetService<ICommonStructureService>();
string rootNodePath = string.Format("\\Onboarding\\Area");
var pathRoot = css.GetNodeFromPath(rootNodePath);
var newAreaPath = css.CreateNode("Area 51", pathRoot.Uri);
// Create new Team with Same Name
TfsTeamService tts = tpc.GetService<TfsTeamService>();
string newteamname = "Area 51";
string teamdescription = "Area 51 Team Description";
IDictionary<string, object> prop = new Dictionary<string, object>
{
{"Area", "Area 51"},
{"Iteration", "\\Onboarding\\Iteration\\Onboarding" }
};
tts.CreateTeam(onboardingProject.Uri.ToString(), newteamname, teamdescription, prop);
TfsTeamService teamService = tpc.GetService<TfsTeamService>();
ProjectInfo projectInfo = css.GetProjectFromName("Onboarding");
var allTeams = teamService.QueryTeams(projectInfo.Uri);
So the question again?
At what point can you set the Backlog Iteration for the new Area, and how/where do you select the new Area for the new Team?
You can add following codes to set the backlog iteration path:
TeamSettingsConfigurationService tscs = tpc.GetService<TeamSettingsConfigurationService>();
IEnumerable<TeamFoundationTeam> teams = tts.QueryTeams(projectInfo.Uri);
TeamFoundationTeam team = teams.Where(a => a.Name == "Area 51").FirstOrDefault();
var teamconfigs = tscs.GetTeamConfigurations(new[] { team.Identity.TeamFoundationId });
TeamConfiguration tconfig = teamconfigs.FirstOrDefault();
Console.WriteLine(tconfig.TeamName);
TeamSettings ts = tconfig.TeamSettings;
ts.IterationPaths = new string[] { string.Format("\\Onboarding\\Iteration 1") };
ts.BacklogIterationPath = string.Format("\\Onboarding\\Iteration 1");
TeamFieldValue tfv = new TeamFieldValue();
tfv.IncludeChildren = true;
tfv.Value = projectInfo.Name + "\\Area 51";
ts.TeamFieldValues = new TeamFieldValue[] { tfv};
tscs.SetTeamSettings(tconfig.TeamId,ts);
What you are looking for is TeamSettings Class, you can check case TFS 2012 API Set TeamSettings Programmatically of how to Set TeamSettings Programmatically:
// Set up default team sprint date and time
var teamConfig = _tfs.GetService<TeamSettingsConfigurationService>();
var css = _tfs.GetService<ICommonStructureService4>();
string rootNodePath = string.Format("\\{0}\\Iteration\\Release 1\\Sprint 1", _selectedTeamProject.Name);
var pathRoot = css.GetNodeFromPath(rootNodePath);
css.SetIterationDates(pathRoot.Uri, DateTime.Now.AddDays(-5), DateTime.Now.AddDays(7));
var configs = teamConfig.GetTeamConfigurationsForUser(new[] { _selectedTeamProject.Uri });
var team = configs.Where(c => c.TeamName == "Demo").FirstOrDefault();
var ts = team.TeamSettings;
ts.BacklogIterationPath = string.Format(#"{0}\Release 1", _selectedTeamProject.Name);
ts.IterationPaths = new string[] { string.Format(#"{0}\Release 1\Sprint 1", _selectedTeamProject.Name), string.Format(#"{0}\Release 1\Sprint 2", _selectedTeamProject.Name) };
var tfv = new TeamFieldValue();
tfv.IncludeChildren = true;
tfv.Value = _selectedTeamProject.Name;
ts.TeamFieldValues = new []{tfv};
teamConfig.SetTeamSettings(team.TeamId, ts);
Useful blog: http://blogs.microsoft.co.il/shair/2012/05/23/tfs-api-part-46-vs11-team-settings/

AWS - How to change the cloudwatchclient config service version in AWSSDK for .NET

I am trying to get CPU percentage of a particular amazon EC2 instance using CloudWatch
I am facing this error when executing the code (see below)
The requested version (2010-08-01) of service AmazonEC2 does not exist"
I could not change the ServiceVersion in AmazonCloudWatchClient because it has Read Only property
The default set is 2010-08-01
I need to change the ServiceVersion to 2014-10-01
Please find the configuration below
And the config in text here
var client = new AmazonCloudWatchClient(clientkey,secretkey,new AmazonCloudWatchConfig{ServiceURL="url"})
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
var request = new GetMetricStatisticsRequest
{
Dimensions = new List<Dimension>() { dimension },
EndTime = DateTime.Today,
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
// Get statistics by day.
Period = (int)TimeSpan.FromDays(1).TotalSeconds,
// Get statistics for the past month.
StartTime = DateTime.Today.Subtract(TimeSpan.FromDays(30)),
Statistics = new List<string>() { "Minimum" },
Unit = StandardUnit.Percent
};
var response = client.GetMetricStatistics(request);
if (response.Datapoints.Count > 0)
{
foreach (var point in response.Datapoints)
{
Console.WriteLine(point.Timestamp.ToShortDateString() +
" " + point.Minimum + "%");
}
}
why do you think you'd need to change the date ?
The property has indeed no setter (see code) so you'll not be able to defined a config with such property.
I understand you dont want to reveal your information but what do you have under
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
The Name should be InstanceName and if you use you instance id as you indicate in the Value it should be InstanceId something like
var dimension = new Dimension
{
Name = "InstanceId"
Value = "i-54cfb999"
};

How to set value in "AssignedTo" field in TFS programatically while creating a UserStory?

Code:
// To create a User Story
var collectionUri = new Uri(txtTFS.Text);
var tpc = new TfsTeamProjectCollection(collectionUri);
var workItemStore = tpc.GetService<WorkItemStore>();
var teamProject = workItemStore.Projects[txtSelectedProject.Text];
var typeWorkItem = ConfigurationManager.AppSettings["WorkItemType"];
var workItemType = teamProject.WorkItemTypes[typeWorkItem];
var userStory = new WorkItem(workItemType)
{
Title = "Test Title",
Description = "Test Description",
IterationPath = "xx\\yy\\zz",
AreaPath = "xxx\\yyy\\zzz",
State = "New",
// "AssignedTo" field not populated here...
};
// Save the new user story.
userStory.Save();
How to set value in "AssignedTo" field in TFS programatically while creating a UserStory?
Only the fields that are on every work item type have their own property on the WorkItem class.
You should use the WorkItem.Fields property to access any field that are not properties.
userStory.Fields["System.AssignedTo"].Value = "JJJ";
You cannot really use properties with indexers inside object intialiser syntax so you will have to have then on a new line before .Save();

ebay GetOrders API using OutputSelector and SortOrder - .Net SDK

I am using ebay .Net SDK. Everything is working fine except following requirements:
Using of OutputSelector to boost performance
Unable to use SortingOrder, while showing records.
Total income/amount sold for specified time range i.e. Total amount across all calls of the pagination without looping through pages and aggregating it manually.
Here is the code which I am using:
var apicall = new GetOrdersCall(context);
//apicall.ApiRequest.OutputSelector = new StringCollection(new String[] { "Order.OrderID", "Order.Total" });
apicall.ApiRequest.Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
};
var fltr = new TimeFilter(Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"), Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"));
var statusCodeType = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]);
var orders = apicall.GetOrders(fltr, TradingRoleCodeType.Seller, statusCodeType);
Please assist me how to use these 3 functionality as well.
After much efforts I got the way for it:
var request = new GetOrdersRequestType
{
//OutputSelector = new StringCollection {"OrderID","Total"},
CreateTimeFrom = Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"),
CreateTimeTo = Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"),
OrderStatus = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]),
OrderRole = TradingRoleCodeType.Seller,
Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
}
};
var apicall = new GetOrdersCall(context)
{
ApiRequest = request,
OutputSelector =
new string[]
{
"OrderID", "Total", "PaidTime", "eBayPaymentStatus",
"PaymentMethod", "Title", "PageNumber", "PaginationResult.TotalNumberOfPages"
}
};
apicall.Execute();
var orders = apicall.ApiResponse.OrderArray;

Categories

Resources