I have a Visual Studio extension that we use internally for a project and one of the things it needs to be able to do is post tickets to VSTS. Previously we were using onsite TFS and making a connection to post tickets was as simple as:
var vssCreds = new VssCredentials(true);
projectCollection = new TfsTeamProjectCollection(url, vssCreds);
workItems = projectCollection.GetService<WorkItemStore>();
project = workItems.Projects["My Project"];
defaultType = project.WorkItemTypes["Bug"];
//...
var newItem = new WorkItem(defaultType)
{
Title = title
};
newItem.Fields["Assigned To"].Value = assignTo;
newItem.Fields["Repro Steps"].Value = repoSteps;
var validationResult = newItem.Validate();
newItem.Save();
And this worked fine. But after upgrading to VSTS I'm having a hard time getting the credentials part to work. I changed this line:
projectCollection = new TfsTeamProjectCollection(url, vssCreds);
To this:
projectCollection = new TfsTeamProjectCollection(url, new VssClientCredentials());
And this worked fine for me. But when I share it with other people on my team it didn't work at first and then started working a little later. I am guessing that interacting with VSTS caused their credentials to be loaded so that it then worked. But I have at least one person who just seems to be completely unable to make it work.
So what's the correct way to get it to use the VSTS credentials (that should already exist in VS)?
I see this overload for VssClientCredentials (https://msdn.microsoft.com/en-us/library/dn228355(v=vs.120).aspx):
public VssClientCredentials(
IVssCredentialPrompt credentialPrompt
)
Which I suspect might be useful, but I can't seem to find out if there's a built in implementation of IVssCredentialPrompt somewhere or, if not, how to implement it.
Remove the related key from
Computer\HKEY_CURRENT_USER\Software\Microsoft\VSCommon\14.0\ClientServices\TokenStorage\VisualStudio\VssApp, then authentication again.
You also can specify other Kind (vssApp by default) and Namespace (VisualStudio by default) by using this code:
var c = new VssClientCredentials();
c.Storage = new VssClientCredentialStorage(storageKind: "VssApp2", storageNamespace: "VisualStudio");
projectCollection = new TfsTeamProjectCollection(url, c);
For reasons that are entirely unclear and from this answer to an entirely different question: https://stackoverflow.com/a/40256731/1250301
It seems that spawning a new thread causes a login prompt to appear if needed and fix all the problems. So if I do this:
Task.Run(() =>
{
var url = new Uri(_tfsUrl);
var cred = new VssClientCredentials();
projectCollection = new TfsTeamProjectCollection(url, cred);
workItems = projectCollection.GetService<WorkItemStore>();
}).Wait();
project = workItems.Projects["Job Posting Data"];
defaultType = project.WorkItemTypes["Bug"];
taskType = project.WorkItemTypes["Task"];
Then it works. I have no idea why it works, or why this is necessary (at first I thought maybe it was a problem with not being in the UI thread so I'd tried Application.Current.Dispatcher.Invoke which did not work) but it seems to have fixed the problem.
Related
I'm having trouble creating a new ContentVersion - Right now I have created a new entry with this code.
var newItem = await client.DeviceAppManagement.MobileApps.Request().AddAsync(new Win32LobApp {});
But I can't find the method to create a new ContentVersion. I know the URL, but not the method to call.
The URL to call is this
POST: https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{0}/microsoft.graph.win32LobApp/contentVersions
So far I have tried to clone the github project (https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet) to see how it works, but without luck. And right now, I just don't know where to look.
Any help would be appreciated
Okay, I solved it by doing it like this
ManagedMobileLobAppRequestBuilder builder = new ManagedMobileLobAppRequestBuilder($"{client.BaseUrl}/deviceAppManagement/mobileApps/{newItem.Id}/{newItem.ODataType.Substring(1)}", client);
var result = await builder.ContentVersions.Request().AddAsync(new MobileAppContent());
Not sure if this is the correct way of doing it, but it works!
An alternative solution with a little less string concatenation:
var lobType = createAppResult.ODataType.Substring(1);
var baseUrl = client.DeviceAppManagement.MobileApps[appId].AppendSegmentToRequestUrl(lobType)
var lobRequestBuilder = new ManagedMobileLobAppRequestBuilder(baseUrl, client);
I downloaded via nuget the package Orc.SystemInfo (Orc.SystemInfo). I managed to display some SystemInfoElements as a list. However no name is provided (name in List is null). I think there is a problem with the LanguageService. I already googled for this problem but I was unable to find a solution.
Here is my code so far (Linq-Pad)
void Main()
{
var service = new Orc.SystemInfo.WindowsManagementInformationService();
var dotnet = new Orc.SystemInfo.DotNetFrameworkService();
var db = new Orc.SystemInfo.DbProvidersService();
ILanguageService lang = new Catel.Services.LanguageService();
var info = new Orc.SystemInfo.SystemInfoService(service, dotnet, lang, db);
var infoList = info.GetSystemInfo();
infoList.Dump();
}
Thank you for your help!
You can simply resolve the ISystemInfo service using the ServiceLocator and all should be taken care of for you.
I am using REST API C# to develop a tool. I would like to get project info based on owner name.
Does anyone have some sample code on how it should works?
Below is my code but it's not working.
Request ProjRequest = new Request("Projects");
ProjRequest.Workspace = "/workspace/xxx";
ProjRequest.Fetch = new List<string>()
{"Name"};
ProjRequest.Query = new Query("Owner.UserName", Query.Operator.Equals, "user name");
ProjResult result = restApi.Query(ProjRequest);
That looks pretty close. I think you just need to change the type to be singular:
Request ProjRequest = new Request("Project");
If that is still not working, inspect the Errors collection on the response and see what's wrong...
i am new with MongoDB, and i can't find GridFS.
Where can i get GridFS to store files now ?
I can get it this way:
mongoClient = new MongoClient(Settings.Default.MongoDB);
var server = mongoClient.GetServer();
MongoDatabase = server.GetDatabase(Settings.Default.DatabaseName);
MongoDatabase.GridFS...
but GetServer() method is obsolete.
if I get database as here:
MongoDatabase2 = mongoClient.GetDatabase(Settings.Default.DatabaseName);
MongoDatabase2.GridFS... not working
Then i receive IMongoDatabase instead MongoDatabase, and i didnt have GridFS.
Heureka!! Got it! Give me the Nobel prize! :)
var grid = new MongoGridFS(new MongoServer(new MongoServerSettings {Server = new MongoServerAddress(host, port)}), databaseName, new MongoGridFSSettings());
grid.Upload(file.InputStream, file.FileName, new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
});
I have the same problem. I did find something I thought would solve my problem, the class MongoGridFS. My problem now is that it takes a MongoServer, as it's first arg and times out when I give it a new instance or complains about a connectionstring not found.
var grid = new MongoGridFS(new MongoServer(new MongoServerSettings { Server = new MongoServerAddress(Settings.Default.WizdooMongoConnectionString) }), Settings.Default.WizdooMongoDatabaseName, new MongoGridFSSettings());
grid.Upload(file.InputStream, file.FileName, new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
});
//Yealds: The settings property 'ConnectionString' was not found.
I suppose I need to give it a connectionstring, but I've been able to do CRUD fine in MongoDB without it. So weird for this service to require it all of a sudden. Maybe you can make it work for you though. I'm going to look in to it more when I have time... should work with correct config. If you get it to work pls give me a hint! Good luck! :)
I'm trying to create a new Website using the nuget package Microsoft.WindowsAzure.Management.WebSites (Version 3.0.0)
This tutorial has been helpful (even though its Java):
http://azure.microsoft.com/fi-fi/documentation/articles/java-create-azure-website-using-java-sdk/
except it suggests to use the WebSpaceNames.WestUSWebSpace constant.
var hostingPlanParams = new WebHostingPlanCreateParameters
{
Name = this.webhostingPlanName,
NumberOfWorkers = 1,
SKU = SkuOptions.Free,
WorkerSize = WorkerSizeOptions.Small
};
var result = new WebSiteManagementClient(this.Credentials)
.WebHostingPlans
.CreateAsync(WebSpaceNames.WestUSWebSpace, hostingPlanParams, CancellationToken.None)
.Result
This will result in an exception: NotFound: Cannot find WebSpace with name westuswebspace.
I actually want to create a custom WebSpace.
Except I can't find any method for it. See MSDN
So the only way I can make this work is using an existing WebSpace, that had created through the manage.windowsazure.com site. Which defeats the whole purpose of automating this.
The only Create[...] Method on IWebSpaceOperations is CreatePublishingUserAsync which I have tried running this as well but it results in an exception This operation is not supported for subscriptions that have co-admins. Which is pretty annoying in itself, doesn't make much sense to me, but is not really the core of my question.
I resolved this by using the prerelease package: PM> Install-Package Microsoft.Azure.Management.WebSites -Pre
Which works perfectly well. Except that it's only a pre-release of cause
// Create Web Hosting Plan
var hostingPlanParams = new WebHostingPlanCreateOrUpdateParameters
{
WebHostingPlan = new WebHostingPlan()
{
Name = "WebHostingPlanName",
Location = "Australia Southeast",
Properties = new WebHostingPlanProperties
{
NumberOfWorkers = 1,
Sku = SkuOptions.Standard,
WorkerSize = WorkerSizeOptions.Small
}
},
};
var result = this.ManagementContext.WebSiteManagementClient.WebHostingPlans.CreateOrUpdateAsync(
"ResourceGroupName",
"WebHostingPlanName",
CancellationToken.None).Result;
// Create Website
var websiteParams = new WebSiteCreateOrUpdateParameters
{
WebSite = new WebSiteBase
{
Location = "Australia Southeast",
Name = "WebSiteName",
Properties = new WebSiteBaseProperties
{
ServerFarm = "WebHostingPlanName"
}
}
};
var siteResult = this.ManagementContext.WebSiteManagementClient.WebSites.CreateOrUpdateAsync(
"ResourceGroupName",
"WebSiteName",
null,
websiteParams,
CancellationToken.None).Result;
If you want to use deployment slots you have to take this under consideration:
https://github.com/Azure/azure-sdk-for-net/issues/1088