public NewUserReturnData CreateUser(String userName) { SessionAwareCoreServiceClient coreService = Client.GetCoreService(); try { #if TRIDION2013 UserData userData = (UserData)coreService.GetDefaultData(ItemType.User, null, new ReadOptions()); #else UserData userData = (UserData)coreService.GetDefaultData(ItemType.User, null); #endif userData.Title = userName; userData.Description = userName; userData = (UserData)coreService.Create(userData, new ReadOptions()); _newUserReturnData = new NewUserReturnData(); _newUserReturnData.UserDescription = userData.Description; _newUserReturnData.UserName = userData.Title; _newUserReturnData.UserID = userData.Id; _newUserReturnData.ErrorMessage = null; } catch (Exception e) { _newUserReturnData = new NewUserReturnData(); _newUserReturnData.UserDescription = "Creation Failed"; _newUserReturnData.UserName = userName; _newUserReturnData.UserID = null; _newUserReturnData.ErrorMessage = e.Message; } return(_newUserReturnData); }
internal string GetPublication(string publicationTitle, params string[] parentIds) { // Console.WriteLine("Getting Publication " + publicationTitle); Stopwatch watch = new Stopwatch(); watch.Start(); string publicationId = TcmUri.UriNull; PublicationsFilterData publicationsFilter = new PublicationsFilterData(); foreach (XElement pub in _client.GetSystemWideListXml(publicationsFilter).Nodes()) { if (!pub.Attribute("Title").Value.Equals(publicationTitle)) { continue; } publicationId = pub.Attribute("ID").Value; Console.WriteLine("Found publication with ID " + publicationId); break; } if (publicationId.Equals(TcmUri.UriNull) && CreateIfNewItem) { // New Publication PublicationData newPublication = //(PublicationData)_client.GetDefaultData(ItemType.Publication, null, _readOptions); (PublicationData)_client.GetDefaultData(ItemType.Publication, null); newPublication.Title = publicationTitle; newPublication.Key = publicationTitle; if (parentIds.Length > 0) { List <LinkToRepositoryData> parents = new List <LinkToRepositoryData>(); foreach (string parentId in parentIds) { LinkToRepositoryData linkToParent = new LinkToRepositoryData { IdRef = parentId }; parents.Add(linkToParent); } newPublication.Parents = parents.ToArray(); } newPublication = (PublicationData)_client.Save(newPublication, _readOptions); publicationId = newPublication.Id; Console.WriteLine("Created publication with ID " + publicationId); } watch.Stop(); Console.WriteLine("GetPublication finished in " + watch.ElapsedMilliseconds + " milliseconds."); return(publicationId); }
/// <summary> /// Create Keywirds in a given category /// </summary> /// <param name="model">CategoryModel</param> /// <param name="CategoryId">tcm:xx-yy-zz</param> /// <returns></returns> public static string CreateKeywordsInCategory(CategoryModel model, string CategoryId) { var result = "true"; cs_client = CoreServiceProvider.CreateCoreService(); try { // open the category that is already created in Tridion CategoryData category = (CategoryData)cs_client.Read(CategoryId, null); var xmlCategoryKeywords = cs_client.GetListXml(CategoryId, new KeywordsFilterData()); var keywordAny = xmlCategoryKeywords.Elements() .Where(element => element.Attribute("Key").Value == model.Key) .Select(element => element.Attribute("ID").Value) .Select(id => (KeywordData)cs_client.Read(id, null)).FirstOrDefault(); if (keywordAny == null) { // create a new keyword KeywordData keyword = (KeywordData)cs_client.GetDefaultData(Tridion.ContentManager.CoreService.Client.ItemType.Keyword, category.Id, new ReadOptions()); // set the id to 0 to notify Tridion that it is new keyword.Id = "tcm:0-0-0"; keyword.Title = model.Title; keyword.Key = model.Key; keyword.Description = model.Description; keyword.IsAbstract = false; // create the keyword cs_client.Create(keyword, null); cs_client.Close(); } } catch (Exception ex) { result = "Error: " + ex.Message; } finally { cs_client.Close(); } return(result); }
public IdentifiableObjectData GetDefaultData(ItemType itemType, string containerId, ReadOptions readOptions) { return(_client.GetDefaultData(itemType, containerId, readOptions)); }
public string GetFolderForDate(DateTime date) { Stopwatch watch = new Stopwatch(); watch.Start(); //Console.WriteLine("Searching folder for date " + date.ToString("yyyy-MM-dd")); //Folder start = (Folder)_session.GetObject(Constants.ArticleLocationUrl); OrganizationalItemItemsFilterData folders = new OrganizationalItemItemsFilterData { ItemTypes = new[] { ItemType.Folder } }; string year = null; string month = null; string day = null; string yearName = date.Year.ToString(CultureInfo.InvariantCulture); string monthName; if (date.Month < 10) { monthName = "0" + date.Month; } else { monthName = date.Month.ToString(CultureInfo.InvariantCulture); } monthName += " " + date.ToString("MMMM"); string dayName; if (date.Day < 10) { dayName = "0" + date.Day; } else { dayName = date.Day.ToString(CultureInfo.InvariantCulture); } foreach (XElement folderElement in _client.GetListXml(Constants.ArticleLocationUrl, folders).Nodes()) //start.GetListItems(folders)) { if (folderElement.Attribute("Title").Value.Equals(yearName)) { year = folderElement.Attribute("ID").Value; break; } } if (year == null) { FolderData f = (FolderData)_client.GetDefaultData(ItemType.Folder, Constants.ArticleLocationUrl); f.Title = yearName; f = (FolderData)_client.Save(f, _readOptions); year = f.Id; } foreach (XElement monthFolder in _client.GetListXml(year, folders).Nodes())//year.GetListItems(folders)) { if (monthFolder.Attribute("Title").Value.Equals(monthName)) { month = monthFolder.Attribute("ID").Value; break; } } if (month == null) { FolderData f = (FolderData)_client.GetDefaultData(ItemType.Folder, year); f.Title = monthName; f = (FolderData)_client.Save(f, _readOptions); month = f.Id; } foreach (XElement dayFolder in _client.GetListXml(month, folders).Nodes())//month.GetListItems(folders)) { if (dayFolder.Attribute("Title").Value.Equals(dayName)) { day = dayFolder.Attribute("ID").Value; break; } } if (day == null) { FolderData f = (FolderData)_client.GetDefaultData(ItemType.Folder, month); f.Title = dayName; f = (FolderData)_client.Save(f, _readOptions); day = f.Id; } watch.Stop(); //Console.WriteLine("Returning folder " + day + " in " + watch.ElapsedMilliseconds + " milliseconds"); return(day); }