public string AddToPage(string sg, Article article) { Stopwatch watch = new Stopwatch(); watch.Start(); string foldername; if (article.Date.Month < 10) { foldername = "0" + article.Date.Month; } else { foldername = article.Date.Month.ToString(CultureInfo.InvariantCulture); } foldername += " " + article.Date.ToString("MMMM"); PageData page = (PageData)_client.Read(GetPage(sg, foldername), _readOptions); //if (!page.IsEditable.GetValueOrDefault()) //{ // page = (PageData)_client.CheckOut(page.Id, true, _readOptions); //} List <ComponentPresentationData> componentPresentations = page.ComponentPresentations.ToList(); string articleId = GetUriInBlueprintContext(article.Id, ResolveUrl(Constants.WebSitePublication)); string ctId = GetUriInBlueprintContext(ResolveUrl(Constants.ArticleComponentTemplateUrl), ResolveUrl(Constants.WebSitePublication)); ComponentPresentationData cp = new ComponentPresentationData(); if (articleId != null && articleId != TcmUri.UriNull) { cp.Component = new LinkToComponentData { IdRef = articleId }; cp.ComponentTemplate = new LinkToComponentTemplateData { IdRef = ctId }; componentPresentations.Add(cp); page.ComponentPresentations = componentPresentations.ToArray(); } page = (PageData)_client.Update(page, _readOptions); // Looks like it's still checked out at the end of this... if (page.IsEditable.HasValue && page.IsEditable == true) { _client.CheckIn(GetVersionlessUri(page.Id), null); } watch.Stop(); Console.WriteLine("Added component presentation in " + watch.ElapsedMilliseconds + " milliseconds"); return(page.Id); }
internal string GetSchema(string schemaTitle, string parentFolderId, string xsd = null, SchemaPurpose purpose = SchemaPurpose.UnknownByClient, string rootElementName = "Content") { Stopwatch watch = new Stopwatch(); watch.Start(); Console.WriteLine("Creating schema " + schemaTitle); string schemaId = TcmUri.UriNull; OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData { ItemTypes = new[] { ItemType .Schema } }; foreach (XElement node in _client.GetListXml(parentFolderId, filter).Nodes()) { if (!node.Attribute("Title").Value.Equals(schemaTitle)) { continue; } schemaId = node.Attribute("ID").Value; } if (schemaId.Equals(TcmUri.UriNull) && xsd != null && CreateIfNewItem && purpose != SchemaPurpose.UnknownByClient) { SchemaData schema = (SchemaData)_client.GetDefaultData(ItemType.Schema, parentFolderId); schema.Title = schemaTitle; schema.Description = schemaTitle; schema.Purpose = purpose; schema.RootElementName = rootElementName; schema.Xsd = xsd; schema = (SchemaData)_client.Save(schema, _readOptions); schema = (SchemaData)_client.CheckIn(schema.Id, _readOptions); schemaId = schema.Id; } watch.Stop(); Console.WriteLine("Returning Schema ID " + schemaId + " (" + watch.ElapsedMilliseconds + " milliseconds)"); return(schemaId); }
public void Save(bool checkOutIfNeeded = false) { if (checkOutIfNeeded) { if (!Content.IsEditable.GetValueOrDefault()) { Client.CheckOut(Content.Id, true, null); } } Content.Content = _fields.ToString(); Content = (ComponentData)Client.Save(Content, ReadOptions); Client.CheckIn(Content.Id, null); }
/// <summary> /// /// </summary> /// <param name="folderID"></param> /// <param name="recursive"></param> /// <param name="srcSchemaID"></param> /// <param name="destSchemaID"></param> public static string UpdateSchemaForComponent(string folderID, bool recursive, string srcSchemaID, string destSchemaID, bool isMultiMediaComp) { cs_client = CoreServiceProvider.CreateCoreService(); StringBuilder sb = new StringBuilder(); FolderData folder = cs_client.Read(folderID, null) as FolderData; SchemaData schema = cs_client.Read(destSchemaID, null) as SchemaData; XNamespace ns = schema.NamespaceUri; XElement items = cs_client.GetListXml(folder.Id, SetComponenetFilterCriterias(isMultiMediaComp)); List <ComponentData> failedItems = new List <ComponentData>(); foreach (XElement item in items.Elements()) { ComponentData component = cs_client.Read(item.Attribute("ID").Value, null) as ComponentData; if (!component.Schema.IdRef.Equals(srcSchemaID)) { // If the component is not of the schmea that we want to change from, do nothing... return(""); } if (component.Schema.IdRef.Equals(schema.Id)) { // If the component already has this schema, don't do anything. return(""); } component = cs_client.TryCheckOut(component.Id, new ReadOptions()) as ComponentData; if (component.IsEditable.Value) { component.Schema.IdRef = destSchemaID; component.Metadata = new XElement(ns + "Metadata").ToString(); cs_client.Save(component, null); cs_client.CheckIn(component.Id, null); } else { sb.AppendLine("Schema Can not be updated for: " + component.Id); sb.AppendLine(""); } } return(sb.ToString()); }
public void Save(bool checkOutIfNeeded = false) { if (checkOutIfNeeded) { if (!Content.IsEditable.GetValueOrDefault()) { Client.CheckOut(Content.Id, true, null); } } if (string.IsNullOrEmpty(Content.Title)) { Content.Title = "No title specified!"; } // Item titles cannot contain backslashes :) if (Content.Title.Contains("\\")) { Content.Title = Content.Title.Replace("\\", "/"); } Content.Content = _fields.ToString(); TcmUri contentId = new TcmUri(Content.Id); if (!contentId.IsVersionless) { contentId = new TcmUri(contentId.ItemId, contentId.ItemType, contentId.PublicationId); Content.Id = contentId.ToString(); } try { Content = (ComponentData)Client.Save(Content, ReadOptions); Client.CheckIn(Content.Id, null); } catch (Exception ex) { Console.WriteLine("Ooops, something went wrong saving component " + Content.Title); Console.WriteLine(ex.Message); } }
public VersionedItemData CheckIn(string id, ReadOptions readBackOptions) { return(_client.CheckIn(id, readBackOptions)); }