/// <summary> /// Get a list of PublicationTargetData objects that represent Tridion publication targets, using the CoreService /// </summary> /// <param name="targetTypes">A list of TargetType URI's</param> /// <returns>a list of PublicationTargetData objects that represent Tridion publication targets</returns> public List<PublicationTargetData> GetPublicationTargetsFromTargetTypes(List<string> targetTypes) { List<PublicationTargetData> publicationTargets = new List<PublicationTargetData>(); PublicationTargetsFilterData targetFilter = new PublicationTargetsFilterData(); XElement publicationTargetList = this.Client.GetSystemWideListXml(targetFilter); foreach (XElement pubTargetNode in publicationTargetList.Elements(ToolsConfiguration.TridionCmNamespace + "Item")) { ReadOptions options = new ReadOptions(); options.LoadFlags = LoadFlags.Expanded; PublicationTargetData pubTarget = (PublicationTargetData)this.Client.Read(pubTargetNode.Attribute("ID").Value, options); foreach (LinkToTargetTypeData link in pubTarget.TargetTypes) { if (targetTypes.Contains(link.IdRef)) { publicationTargets.Add(pubTarget); } } } return publicationTargets; }
internal void CreatePublicationTarget(XElement site, WebsiteHelper.TargetLanguage language) { string targetName = site.Element("Name").Value; string targetTypeId = TcmUri.UriNull; string url = string.Empty; if (language == WebsiteHelper.TargetLanguage.Aspnet || language == WebsiteHelper.TargetLanguage.REL) { url = "http://localhost:" + site.Element("Port").Value + "/httpupload.aspx"; } else if (language == WebsiteHelper.TargetLanguage.Jsp) { url = "http://localhost:" + site.Element("Port").Value + "/" + site.Element("ContextRoot").Value + "/httpupload"; } TargetTypesFilterData filter = new TargetTypesFilterData(); //filter.ForRepository.IdRef = Configuration.WebsitePublicationId; foreach (XElement node in _client.GetSystemWideListXml(filter).Nodes()) { if (node.Attribute("Title").Value.Equals(targetName)) { targetTypeId = node.Attribute("ID").Value; break; } } if (targetTypeId.Equals(TcmUri.UriNull)) { TargetTypeData targetType = (TargetTypeData)_client.GetDefaultData(ItemType.TargetType, null); targetType.Title = targetName; targetType.Description = targetName; targetType = (TargetTypeData)_client.Save(targetType, _readOptions); targetTypeId = targetType.Id; } PublicationTargetsFilterData pFilter = new PublicationTargetsFilterData(); string pTargetId = TcmUri.UriNull; foreach (XElement node in _client.GetSystemWideListXml(pFilter).Nodes()) { if (node.Attribute("Title").Value.Equals(targetName)) { pTargetId = node.Attribute("ID").Value; break; } } if (pTargetId.Equals(TcmUri.UriNull)) { PublicationTargetData pt = (PublicationTargetData)_client.GetDefaultData(ItemType.PublicationTarget, null); pt.Title = targetName; pt.Description = targetName; pt.Publications = new[] { new LinkToPublicationData { IdRef = Configuration.WebsitePublicationId } }; pt.TargetTypes = new[] { new LinkToTargetTypeData { IdRef = targetTypeId } }; SchemaData protocolSchema = (SchemaData)_client.Read("/webdav//HTTPS.xsd", _readOptions); //_client.GetSystemWideListXml() TargetDestinationData destination = new TargetDestinationData { ProtocolSchema = new LinkToSchemaData { IdRef = protocolSchema.Id }, Title = targetName, ProtocolData = "<HTTPS xmlns=\"" + protocolSchema.NamespaceUri + "\"><UserName>notused</UserName><Password>notused</Password><URL>" + url + "</URL></HTTPS>" }; pt.Destinations = new[] { destination }; if (language == WebsiteHelper.TargetLanguage.Aspnet) { pt.TargetLanguage = "ASP.NET"; } else { pt.TargetLanguage = "JSP"; } _client.Save(pt, null); } }
/// <summary> /// Get a list of ListItem objects that represent Tridion PublicationTargets using the CoreService /// </summary> /// <returns>a list of ListItem objects that represent Tridion PublicationTargets</returns> public List<ListItem> GetPublicationTargets() { List<ListItem> items = new List<ListItem>(); PublicationTargetsFilterData filter = new PublicationTargetsFilterData(); XElement xml = this.Client.GetSystemWideListXml(filter); items.AddRange(xml.Elements(ToolsConfiguration.TridionCmNamespace + "Item") .Select(t => new ListItem() { Value = t.Attribute("ID").Value, Text = t.Attribute("Title").Value }) .ToList()); return items; }