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);
        }
 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);
 }
Esempio n. 3
0
        /// <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);
            }
        }
Esempio n. 5
0
 public IdentifiableObjectData Save(IdentifiableObjectData deltaData, ReadOptions readBackOptions)
 {
     return(_client.Save(deltaData, readBackOptions));
 }
        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);
        }