TFS working with IBuildController in C# - c#

I want to trigger a build from C#
In the build I need to change the default BuildController. My code look like this:
IBuildRequest buildRequest = BuildDefinition.CreateBuildRequest();
if(changebuildcontroller)
{
buildRequest.DropLocation = #"\\zzz.Domain.com\yyy$\TFS\Drop";
buildRequest.BuildController = **???**;
}
...
var queuedBuild = buildServer.QueueBuild(buildRequest);
Questions:
I would like to know how to find a list of buildcontrollers.
Any advice about how to understand the TFS object model will be appreciated. I looked at MSDN articles like this, but I do not see how it should help me. I used Google to find implementations of other objects in the Microsoft.TeamFoundation.Build.Client namespace.

It helped looking at another assignment for a while :)
If anyone else run into the same problem Use the Ibuildserver object to get a list of IBuildController
buildServer = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));
IBuildController[] buildserverlist = buildServer.QueryBuildControllers();

Related

How to get recent build TFS programmatically?

Ok i am new to TFS. I want to get the recent build pro grammatically using c# code. i have seen other post about this, they did this way
var buildDefinitions = buildServer.QueryBuildDefinitions("Project_name").Where(bd=>bd.DateCreated.Date>=DateTime.Now.AddDays(-7).Date);
But I need to get an example of this image click here
As you know, the method returns IBuildDefinitions. And since you seem to be wanting to find them by name, you could do something like:
var buildDefinitions = buildServer
.QueryBuildDefinitions("Project_name")
.Where(bd => bd.Name == yourBuildName);

How can I get the CurrentSite object in Orchard?

What I'm trying to do, ultimately, is access the CacheSettingsPart so that I can programmatically add some ignored URLs to the output caching config.
The relevant admin controller already achieves this with:
var settings = Services.WorkContext.CurrentSite.As<CacheSettingsPart>();
settings.IgnoredUrls = model.IgnoredUrls;
I need something similar for my own method, but when I try and inject IOrchardServices, the WorkContext is null, meaning I don't have access to the CurrentSite.
I need suggestions of achieving this with an alternative approach or, ideally, a way of accessing the CurrentSite/CacheSettingsPart for me to amend the IgnoredUrls.
EDIT
var query = Services.ContentManager.Query<CacheSettingsPart>();
var cacheSettingsPart = query.List().First();
The above seems to be giving me what I need, I'll now test whether amending IgnoredUrls persists or not.
The WorkContext, as far as I can see, hasn't been created at the point of the Migration being run.
You could get the first SettingsPart as you suggest - it's probably not used for anything except the current site, though if you had multiple tenants, then I think you might run into trouble.
An alternative would be to inject ISiteService into your migrations class.
You can then do
var site = _siteService.GetSiteSettings();
var cacheSettings = site.As<CacheSettingsPart>();
var query = Services.ContentManager.Query<CacheSettingsPart>();
var cacheSettingsParts = query.Slice(1);
if(cacheSettingsParts.Any())
{
_signals.Trigger(CacheSettingsPart.CacheKey);
cacheSettingsParts.First().IgnoredUrls = "/dans-test";
}
The above works, but I appreciate it might not be the best approach so I'm open to other suggestions.

How to find in VSPackage which version control system a solution uses

I'm new to extending Visual Studio and I'm trying to find way to find which source control system is used by current solution.
I created VsPackage project and I am able to obtain reference to solution via IVsSolution and to hook up to solution events via IVsSolutionEvents.
Inside OnAfterSolutionOpen (or possibly some other if there's an alternative) I would like to act differently basing on whether the solution uses TFS or Git or something else. How can I obtain this information?
I plan to support as many Visual Studio versions as possible, but if it isn't possible I would like to support at least VS2012 and higher.
Ok, after several hours of digging I've found a solution to this. Thanks to the article of Mark Rendle and the source code for his NoGit extension I've found, that the list of registered source control plugins is located in registry: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\SourceControlProviders (in case of VS 2013).
So now, we can have both plugin guid, and the name of the provider. This sample code can fetch those values:
var key = #"Software\Microsoft\VisualStudio\" + "12.0" + #"_Config\SourceControlProviders";
var subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(key);
var providerNames = subkey.GetSubKeyNames().Dump();
var dict = new Dictionary<Guid, String>();
foreach (var provGuidString in subkey.GetSubKeyNames())
{
var provName = (string)subkey.OpenSubKey(provGuidString).GetValue("");
dict.Add(Guid.Parse(provGuidString), provName);
}
Now, there are two ways I've found to obtain guid of currently active provider.
important update: Apparently the second way of obtaining currently active plugin does not work as expected. I strongly advise using first solution.
This is the way that bases on the extension mentioned earlier:
var getProvider = GetService(typeof(IVsRegisterScciProvider)) as IVsGetScciProviderInterface;
Guid pGuid;
getProvider.GetSourceControlProviderID(out pGuid);
Or we can just go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\CurrentSourceControlProvider and get the default value of this key:
var key2 = #"Software\Microsoft\VisualStudio\12.0\CurrentSourceControlProvider";
var guidString = (string)Microsoft.Win32.Registry.CurrentUser.OpenSubKey(key2).GetValue("");
var currentGuid = Guid.Parse(guidString);
Now we just take var activeProviderName = dict[currentGuid]; and that's all.

C# code completion with NRefactory 5

I just found out about NRefactory 5 and I would guess, that it is the most suitable solution for my current problem. At the moment I'm developing a little C# scripting application for which I would like to provide code completion. Until recently I've done this using the "Roslyn" project from Microsoft. But as the latest update of this project requires .Net Framework 4.5 I can't use this any more as I would like the app to run under Win XP as well. So I have to switch to another technology here.
My problem is not the compilation stuff. This can be done, with some more effort, by .Net CodeDomProvider as well. The problem ist the code completion stuff. As far as I know, NRefactory 5 provides everything that is required to provide code completion (parser, type system etc.) but I just can't figure out how to use it. I took a look at SharpDevelop source code but they don't use NRefactory 5 for code completion there, they only use it as decompiler. As I couldn't find an example on how to use it for code completion in the net as well I thought that I might find some help here.
The situation is as follows. I have one single file containing the script code. Actually it is not even a file but a string which I get from the editor control (by the way: I'm using AvalonEdit for this. Great editor!) and some assemblies that needs to get referenced. So, no solution files, no project files etc. just one string of source code and the assemblies.
I've taken a look at the Demo that comes with NRefactory 5 and the article on code project and got up with something like this:
var unresolvedTypeSystem = syntaxTree.ToTypeSystem();
IProjectContent pc = new CSharpProjectContent();
// Add parsed files to the type system
pc = pc.AddOrUpdateFiles(unresolvedTypeSystem);
// Add referenced assemblies:
pc = pc.AddAssemblyReferences(new CecilLoader().LoadAssemblyFile(
System.Reflection.Assembly.GetAssembly(typeof(Object)).Location));
My problem is that I have no clue on how to go on. I'm not even sure if it is the right approach to accomplish my goal. How to use the CSharpCompletionEngine? What else is required? etc. You see there are many things that are very unclear at the moment and I hope you can bring some light into this.
Thank you all very much in advance!
I've just compiled and example project that does C# code completion with AvalonEdit and NRefactory.
It can be found on Github here.
Take a look at method ICSharpCode.NRefactory.CSharp.CodeCompletion.CreateEngine. You need to create an instance of CSharpCompletionEngine and pass in the correct document and the resolvers. I managed to get it working for CTRL+Space compltition scenario. However I am having troubles with references to types that are in other namespaces. It looks like CSharpTypeResolveContext does not take into account the using namespace statements - If I resolve the references with CSharpAstResolver, they are resolved OK, but I am unable to correctly use this resolver in code completition scenario...
UPDATE #1:
I've just managed to get the working by obtaining resolver from unresolved fail.
Here is the snippet:
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
var resolver3 = unresolvedFile.GetResolver(cmp, loc); // get the resolver from unresolvedFile
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
Update #2:
Here is the complete method. It references classes from unit test projects, sou you would need to reference/copy them into your project:
public static IEnumerable<ICompletionData> DoCodeComplete(string editorText, int offset) // not the best way to put in the whole string every time
{
var doc = new ReadOnlyDocument(editorText);
var location = doc.GetLocation(offset);
string parsedText = editorText; // TODO: Why there are different values in test cases?
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
IProjectContent pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value};
pctx = pctx.AddAssemblyReferences(refs);
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var resolver3 = unresolvedFile.GetResolver(cmp, location);
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono();
var data = engine.GetCompletionData(offset, controlSpace: false);
return data;
}
}
Hope it helps,
Matra
NRefactory 5 is being used in SharpDevelop 5. The source code for SharpDevelop 5 is currently available in the newNR branch on github. I would take a look at the CSharpCompletionBinding class which has code to display a completion list window using information from NRefactory's CSharpCompletionEngine.

Question about Microsoft robotics developer studio sample code

If anyone has come across the the Arcos sample code in the MRDS can you please let me know what the following code fragment does in the ArcosDrive.cs file. I am more interested in the lines "arcos.Update update = new arcos.Update(raw);" and "_arcosPort.Post(update);".
Thanks.
void VelocityHandler(Velocity velocity)
{
arcos.RawType raw = new arcos.RawType();
raw.Command = "Vel";
raw.Integer = (short)velocity.Body.Velocity;
raw.Flags = arcos.RawFlags.Integer;
arcos.Update update = new arcos.Update(raw);
_arcosPort.Post(update);
Activate(Arbiter.Choice(update.ResponsePort,
delegate(DefaultUpdateResponseType response)
{
velocity.ResponsePort.Post(DefaultSubmitResponseType.Instance);
},
delegate(Fault fault)
{
velocity.ResponsePort.Post(fault);
})
);
}
After taking a deep breath and careful thinking :P I managed to figure it out.
Seems that a PostUnknownType is like an automatic type casting whereby the type that is posted is recognized automatically without having to define multiple post types.
In the case of RawType, a RawType post eventually triggers a call to RawCommandHandler defined in the ArcosState class.
Hope someone finds this useful.

Categories

Resources