List of Publication Targets using Tridion Core Service? - tridion

How would I get a list of Publication Targets with the Tridion Core Service? I see this code sample to get the Target Info, but cannot find a way to get the list from the Core Service. Maybe it is part of the Publication object?
var pubtarget = (PublicationTargetData)client.Read("tcm:0-21-65537", readoption);
Also, if there is a way to get this via the Anguilla JavaScript client it would also be cool.

var filter = new PublicationTargetsFilterData();
var pubTargets = ClientAdmin.GetSystemWideList(filter);
var pubTargetsXml = ClientAdmin.GetSystemWideListXml(filter);
You can set additional filter properties on filter object

user978511 already answered how to do it using the Core Service, so let me just answer how you can do it using Anguilla:
var system = $models.getItem($const.TCMROOT);
var list = system.getListPublicationTargets();
From then on, it's a normal list -- so you'll want to check isLoaded() and call load() if it returns false (hooking into the "load"/"loadfailed" events for the callback).
The Publication Targets are available either as XML through the getXml() method or as an array through the getItems() method (which returns an array of model items -- so again, you can check isLoaded() on those, etc.)

Related

How do I use multiple schema GenerationProviders

We are using Json.Net Schema and require multiple generation providers.
However when we specify more than one generation provider it seems that only the last one in the list is used.
Here is an example where only ObjectNotNullableGenerationProvider is used and StringEnumGeneration is ignored.
Any example of example of multiple providers or help on why this is not working would be appreciated.
Example:
var generator = new JSchemaGenerator
{
SchemaReferenceHandling = SchemaReferenceHandling.None,
DefaultRequired = Required.Default,
};
generator.GenerationProviders.Add(new StringEnumGenerationProvider());
generator.GenerationProviders.Add(new ObjectNotNullableGenerationProvider());
var jsonSchema = generator.Generate(typeof(SchemaTest));
The GetSchema method on JSchemaGenerationProvider returns a new schema. Only the first matching schema generation provider is called and its schema is used.
What you could do is take the source code from StringEnumGenerationProvider (available here) and have you own version that either inherits from ObjectNotNullableGenerationProvider or reuses its logic internally.

Fetch a component by its tcm id using the core services

I need to fetch a component based on its tcm id using the core services. Please help me which function of core service I can use along with some sample code if possible as well.
Thanks in advance!!
Check the section in the documentation, which you can find here
A basic sample (out of my head, untested ;) ):
ComponentData component = (ComponentData)client.Read(yourComponentId, new ReadOptions());
string title = component.Title;
XElement content = XElement.Parse(component.Content);
The Read method will get you an IdentifiableObjectData object, which you can cast to the needed type if you're sure about what you're supposed to be getting back.
The ReadOptions object will instruct the CoreService how to load the item, for instance, with all Keyword URI's loaded as well using LoadFlags.KeywordXlinks

Caliburn.micro calling navigationService.UriFor on dynamic type

I'm trying to allow some navigation in Caliburn.Micro in a bit of a dynamic way (viewModels won't be known at design time).
This code obviously works
navigationService.UriFor<DatabasesViewModel>().Navigate();
However, with what I'm trying to do, I won't know the view model ahead of time. Instead I'll only have the Type of the view model.
I've been trying to use reflection to get the generic method, but I'm to able to get the UriFor method via GetMethod or GetMethods. Any ideas how this can be accomplished.
Your problem is not directly related to Caliburn.Micro but how to call generic methods with reflection in C#.
There are already quite a few and very good questions about this on SO:
How do I use reflection to call a generic method?
However your case is a little bit special because the UriFor<T> method defined as an extension method by Caliburn in the NavigationExtensions class
So you need some extra steps and start from the NavigationExtensions type before you can call Navigate:
//Create the UriFor Method for your ViewModelType
var navigationExtension = typeof(NavigationExtensions);
var uriFor = navigationExtension.GetMethod("UriFor");
var genericUriFor = uriFor.MakeGenericMethod(yourViewModelType);
//Invoke UriFor: an instance of UriBuilder<T> is returned
var uriBuilder = genericUriFor.Invoke(null, new[] {navigationService});
//Create and Navigate on the returned uriBuilder
var navigateMethod = uriBuilder.GetType().GetMethod("Navigate");
navigateMethod.Invoke(uriBuilder, null);

How to get the user who initiated a publish action in a SDL Tridion C# TBB

From a C# TBB used by a Modular Page Template in SDL Tridion 2011, is it possible to access the User object who initiated the Publishing action?
Looking at the TOM.NET 6 Programmers Reference Guide, it seems that the property I need is the Creator property of the PublicationTransaction object, but I can’t find a way to access that from a C# TBB, I don’t see an obvious way to get the current PublicationTransaction from the engine or package objects, and I can only find a way to get a list of PublicationTransaction objects using the PublishEngine object.
Any advice would be greatly appreciated.
Have a look at these two blog posts from Mihai Cadariu:
How to look up the current Publish Transaction (based on a trick from Chris Summers)
Create a new Publish Transaction based on an existing one
With those two you should be able to find what you need.
The basic function you need in your TBB is this:
public PublishTransaction GetPublishTransaction(Engine engine)
{
String binaryPath = engine.PublishingContext.PublishInstruction.
RenderInstruction.BinaryStoragePath;
Regex tcmRegex = new Regex(#"tcm_\d+-\d+-66560");
Match match = tcmRegex.Match(binaryPath);
if (match.Success)
{
String transactionId = match.Value.Replace('_', ':');
TcmUri transactionUri = new TcmUri(transactionId);
return new PublishTransaction(transactionUri, engine.GetSession());
}
return null;
}
It might also be worth noting that the property engine.PublishingContext.PublishInstruction.RenderInstruction.BinaryStoragePath will return something different when rendering the coder in PreviewMode or from the Template Builder compared to when the code is running in the Publisher. To see the PublishTransaction URI in the BinaryStoragePath, you must attach your Visual Studio TBB Debug Project to the TcmPublisher.exe process in order for there to actually be a PublishTransaction object present, otherwise the BinaryStoragePath will just contain a generic path like ../preview.

how do I use ClassifiedItemsFilterData for folders in Tridion 2011 CoreService?

I'm rewriting a .NET backend application so that it uses the Tridion 2011 CoreService.
There's one part where it will get a folder in Tridion that uses a particular keyword.
In the current setup, this is done by calling the method 'GetListClassifiedItems' on the keyword itself, but how am I suppose to do this using the CoreService?
There is a ClassifiedItemsFilterData available in the CoreService API, but how do I use it?
I've tried this piece of code:
ClassifiedItemsFilterData filter = new ClassifiedItemsFilterData()
{
ItemTypes = new ItemType[] { ItemType.Folder }
};
XElement list = client.GetListXml("tcm:113-363331-1024", filter);
but it will only return the keyword itself, with URI tcm:113-363331-1024, and not the folders that have been classified with it.
If I add the component ItemType to the filter too, I will get all components that have been classified with this keywordk, but still not that folder.
How do I get the folder too?
When I run a similar test, I do get both Folders and Components in my result
var filter = new ClassifiedItemsFilterData();
filter.ItemTypes = new ItemType[] {ItemType.Folder};
var transactions = client.GetListXml("tcm:1-134-1024", filter);
Console.WriteLine(transactions.ToString());
I added a Keyword field to a Metadata Schema and associate that with the Folder. Is that the same way you did it?
When I remove the item types filter from the code above, I get all Components and Folders classified against that Keyword, but I do not get the Keyword itself. These are all exactly how I'd expect a ClassifiedItemsFilterData to work, so we really should focus on what is different in your scenario.

Resources