How to create a Structure Group in SDL Tridion 2011 using core services? - tridion

I want to create a Structure Group in Tridion 2011 using core services
Any idea?

This is the code:
var structureGroup = ClientAdmin.GetDefaultData(ItemType.StructureGroup, "tcm:0-2-1");
structureGroup.Title = "SG";
structureGroup.Directiry = structureGroup.Title.Replace(" ", ""),
structureGroup = (StructureGroupData) ClientAdmin.Create(structureGroup, new ReadOptions());
I don't think that any explanations are needed here, if you want to know more - check StructureGroupData class in CoreService API docs

The code above doesn't seem to be an standard Core Services API. Check this one.
CoreServiceClient channel = new CoreServiceClient("basicHttp_2011");
string organizationalItemId = "tcm:6-3-4";
StructureGroupData sg = new StructureGroupData();
sg.Id = "tcm:0-0-0";
sg.Title = "NewSG";
sg.LocationInfo = new LocationInfo() { OrganizationalItem = new LinkToOrganizationalItemData() { IdRef = organizationalItemId } };
sg.Directory = "NewSG";
sg = (StructureGroupData)channel.Save(sg, new ReadOptions());
You might note there that the Directory property cannot contain blank spaces. That is because it is validated by a regular expression. You can change it in the file cm_xml_usr.xsd located at [TRIDION_HOME]\bin.

Related

Azure Resource Manager DNS: Sample code to create a DNS record

I'm currently trying to move out from using old Microsoft.Azure.Management.Dns package to the new Azure.ResourceManager.Dns.
However I've been having issues in our code that creates Dns records such as an Arecord.
I've tried to go through the official documentation https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.dns.dnsarecordcollection.createorupdate?view=azure-dotnet
But the classes that represent an Arecord are either read only or private so I have no idea how to update this simple lines:
RecordSet set = DnsManagementClient.client.RecordSets.Get(resourceGroupName, zone, recordSetName, RecordType.A);
set.ARecords = set.ARecords ?? new List<ARecord>();
set.ARecords.Add(new ARecord(ipAddress));
DnsManagementClient.client.RecordSets.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, zone, recordSetName, RecordType.A, set, ifNoneMatch: "*");
Currently documentation only talks about Zones, can an example be added to the official documentation on how to add or update a DNS record (A,CNAME,etc..)
https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/dns/Azure.ResourceManager.Dns
I'm expecting a method to create an A record that let's you specify an IP address, and currently all the classes that potentially can be used to do that are either read-only or internal.
DnsARecordData has an internal list of Arecords, DnsARecordData.DnsARecords is where we can invoke the Add method to create the record. The reason DnsARecordData doesn't have a setter method is due to the .Net framework design guideline..
An example of how to create an A record using Azure.Resourcemanager.Dns can be found here:
// Create or update A record
string myARecordName = "myrecord";
DnsARecordData dnsARecordData = new() {TtlInSeconds = (long)TimeSpan.FromHours(1).TotalSeconds};
dnsARecordData.DnsARecords.Add(new DnsARecordInfo { IPv4Address = IPAddress.Parse("127.0.0.1") });
DnsARecordCollection dnsARecordCollection1 = dnsZoneResource.GetDnsARecords();
dnsARecordCollection1.CreateOrUpdate(WaitUntil.Completed, myARecordName, dnsARecordData);
// Create or update CName pointing to A record
string myCnameName = "mycname";
DnsCnameRecordData dnsCnameRecordData = new() { Cname = $"{myARecordName}.{DnsZone}", TtlInSeconds = (long)TimeSpan.FromMinutes(10).TotalSeconds, };
DnsCnameRecordCollection cnameRecordCollection = dnsZoneResource.GetDnsCnameRecords();
cnameRecordCollection.CreateOrUpdate(WaitUntil.Completed, myCnameName, dnsCnameRecordData);
I tried in my environment and got below results:
You can create A record set using Azure.ResourceManager.Dns package. The version of NuGet package is beta-1.
NuGet Package:
Azure.ResourceManager.Dns 1.0.0 beta-1
Code:
using Azure;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Dns;
using Azure.ResourceManager.Resources;
using System.Net;
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "rg-name";
ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
string dnsZoneName = "dns name";
DnsZoneCollection dnsZoneCollection = resourceGroup.GetDnsZones();
DnsZoneData data1 = new DnsZoneData("Global")
{
};
ArmOperation<DnsZoneResource> lro = await dnsZoneCollection.CreateOrUpdateAsync(WaitUntil.Completed, dnsZoneName, data1);
DnsZoneResource dnsZone = lro.Value;
RecordSetACollection recordSetACollection = dnsZone.GetRecordSetAs();
string name = "cname1";
var parm = new ARecordSetData();
parm.TTL =600;
parm.ARecords = new List<ARecord>();
parm.ARecords.Add(new ARecord("1.2.3.4"));
ArmOperation<RecordSetAResource> recordSetAResource = recordSetACollection.CreateOrUpdate(WaitUntil.Completed, name,parm);
RecordSetAResource recordSetAs = recordSetAResource.Value;
Console:
Portal:
For more reference:
azure-sdk-for-net/Sample2_ManagingRecordSetPtrs.md at dvbb-mgmt-track2-dns-2 ยท dvbb/azure-sdk-for-net (github.com)

Get List of Localized Items

I need to get the list of localized items of a publication programatically using coreservice in tridion. Could any one suggest me.
I would use the GetListXml method and specify a BluePrintChainFilterData filter object.
var subjectId = "[TCM Uri of your item]";
var filter = new BluePrintChainFilterData
{
Direction = BluePrintChainDirection.Down
};
var subjectBluePrintChainList = coreServiceClient.GetListXml(subjectId, filter);
You then still need to verify the localized items from the received list.
This wasn't in my original answer, and probably isn't complete because I don't take into account namespaces, but the following would work to select the localized (not shared) items.
var localizedItems = subjectBluePrintChainList.Elements("Item")
.Where(element => "false".Equals(element.Attribute("IsShared").Value, StringComparison.OrdinalIgnoreCase));
The only way I know is to use search functionality:
var searchQuery = new SearchQueryData();
searchQuery.BlueprintStatus = SearchBlueprintStatus.Localized;
searchQuery.FromRepository = new LinkToRepositoryData{IdRef = "tcm:0-5-1"};
var resultXml = ClientAdmin.GetSearchResultsXml(searchQuery);
var result = ClientAdmin.GetSearchResults(searchQuery);

Creation of Schema using Core Service in SDL Tridion 2011 SP1

I am creating Schema using Core Service in SDL Tridion 2011 SP1. In the creation of the Schema I have used the custom namespace URI for the Schema. Generally when we create a Schema through Tridion CME directly, we will get a namespace URI generated automatically starting with uuid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I have used this code to create a Schema:
Tridion.ContentManager.CoreService.Client.SchemaData schemas = new SchemaData
{
Title = "coreservicesschema3",
Description = "coreservicesschema",
Id = "tcm:0-0-0",
LocationInfo = new LocationInfo
{
OrganizationalItem =
new LinkToOrganizationalItemData { IdRef = "tcm:7-18-2" }
},
RootElementName = "Content",
NamespaceUri = "customnamespaceuri",
Xsd = xsd.ToString(SaveOptions.None)
};
schemas = (SchemaData)client.Create(schemas, new ReadOptions());
Response.Write("<BR>" +"new schema id"+ schemas.Id);
Response.Write("<BR>" + "new schema Name" + schemas.Title);
//schema created
Can anyone indicate how to create a Schema with default namespace URI?
Thank you
The minimal code you need in order to create a Schema with Core Service is the following:
using (var client = new SessionAwareCoreServiceClient(netTcpBinding, remoteAddress))
{
SchemaData schemaData = client.GetDefaultData(ItemType.Schema, folderId) as SchemaData;
schemaData.Description = "description";
schemaData = client.Save(schemaData, readOptions) as SchemaData;
schemaData = client.CheckIn(schemaData.Id, readOptions) as SchemaData;
Console.WriteLine("Schema: " + schemaData.LocationInfo.WebDavUrl);
}
The Schema will be created with the default namespace. In the case of this example, it will also not contain any fields, but that's not what you were asking for.

ASP.NET C# Filter Data from Soap Service

I have a Soap service that I added to my .NET project via Service Reference.
problemReporting.soapClient s = new problemReporting.soapClient();
problemReporting.NullRequest nr = new NullRequest();
problemReporting.ProblemDescription[] getDescList = s.getProblemDescriptionList(nr);
if (!IsPostBack)
{
rbProblemList.DataSource = getDescList;
rbProblemList.DataTextField = "description";
rbProblemList.DataValueField = "code";
rbProblemList.DataBind();
}
This returns a DropDownList of 23 items. (This list could grow in the future.) The service is returning an array of objects, where each object contains Category, Code, and Description.
How can I create a separate method that will return ONLY the 4 categories that exists in this array? I am unable to find any examples of how to create a method that will filter the data from a soap service.
Thank you in advance for any assistance.
This is basically the same code from another question you asked:
ASP.NET C# Filter DropDownList based on specific Category of Items from Soap Service
problemReporting.soapClient s = new problemReporting.soapClient();
problemReporting.NullRequest nr = new NullRequest();
problemReporting.ProblemDescription[] getDescList = s.getProblemDescriptionList(nr);
List<string> categories = new List<string>();
categories.Add("Category1");
categories.Add("Category2");
categories.Add("Category3");
var filteredResults = FilterCategories(categories, getDescList);
if (!IsPostBack)
{
rbProblemList.DataSource = filteredResults;
rbProblemList.DataTextField = "description";
rbProblemList.DataValueField = "code";
rbProblemList.DataBind();
}
public ProblemDescription[] FilterCategories(List<string> categories, ProblemDescription[] data )
{
var cats = from desc in data
where categories.Contains(desc.category)
select desc;
return cats;
}

How to publish an item in Sitecore 5.3 using the API

Using Sitecore 5.3, what API calls would be necessary to publish a given item? If there are multiple publication targets configured, how would you specify which target to publish to?
My code is actually for Sitecore 6 but we used almost the same code when we ran 5.3
Needlessly to say maybe but in the code we publish from Master to Web and we only publish items under the node /sitecore/content/home/projects/ongoing
DateTime publishDate = DateTime.Now;
var master = Sitecore.Configuration.Factory.GetDatabase("master");
var targetDB = Sitecore.Configuration.Factory.GetDatabase("web");
var pubOpts = new Sitecore.Publishing.PublishOptions(master, targetDB, Sitecore.Publishing.PublishMode.Full, Sitecore.Data.Managers.LanguageManager.GetLanguage("sv", master), publishDate);
pubOpts.Deep = true;
string idstr = master.Items["/sitecore/content/Home/Projects/Ongoing"].ID.ToString();
var id = new ID(idstr);
pubOpts.RootItem = master.Items[id];
var pub = new Sitecore.Publishing.Publisher(pubOpts);
Sitecore.Jobs.Job pubJob = pub.PublishAsync();
pubJob.Start();
You can find the code for Sitecore 5.3 on the sdn.

Resources