internal void CreateOrIgnoreRootStructureGroup(string rootStructureGroupTitle, string publicationId)
        {
            PublicationData publication = (PublicationData)_client.Read(publicationId, _readOptions);

            if (publication.RootStructureGroup.IdRef == TcmUri.UriNull)
            {
                StructureGroupData structureGroup =
                    //(StructureGroupData)_client.GetDefaultData(ItemType.StructureGroup, publicationId, _readOptions);
                    (StructureGroupData)_client.GetDefaultData(ItemType.StructureGroup, publicationId);
                structureGroup.Title = rootStructureGroupTitle;
                _client.Save(structureGroup, null);
            }
        }
        //public List<Page> GetNewsletterPages()
        //{
        //    List<Page> result = new List<Page>();
        //    StructureGroup sg = (StructureGroup)_session.GetObject(Constants.NewsletterStructureGroupUrl);
        //    OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(_session) { ItemTypes = new[] { ItemType.Page } };

        //    foreach (Page page in sg.GetItems(filter))
        //    {
        //        result.Add(page);
        //    }
        //    return result;
        //}

        public List <Article> GetArticlesForDate(DateTime date)
        {
            List <Article> result   = new List <Article>();
            string         folderId = GetFolderForDate(date);
            OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData {
                ItemTypes = new[] { ItemType.Component }
            };

            foreach (XElement node in _client.GetListXml(folderId, filter).Nodes())
            {
                result.Add(new Article((ComponentData)_client.Read(node.Attribute("ID").Value, _readOptions), _client));
            }

            return(result);
        }
        /// <summary>
        /// Get publishing targets for any given publication
        /// </summary>
        /// <param name="publicationID"></param>
        /// <returns></returns>
        public static Dictionary <string, List <string> > GetPublishingTargets(List <string> publicationIDs)
        {
            cs_client = CoreServiceProvider.CreateCoreService();
            Dictionary <string, List <string> > resultTargets = new Dictionary <string, List <string> >();
            var pubTargets = cs_client.GetSystemWideList(new PublicationTargetsFilterData());

            foreach (var publicationID in publicationIDs)
            {
                foreach (PublicationTargetData pubTargetdata in pubTargets)
                {
                    List <string>           targetIds    = new List <string>();
                    PublicationTargetData   target       = (PublicationTargetData)cs_client.Read(pubTargetdata.Id, new ReadOptions());
                    LinkToPublicationData[] pubDataItems = target.Publications;
                    foreach (LinkToPublicationData publicationData in pubDataItems)
                    {
                        if (publicationData.IdRef == publicationID)
                        {
                            if (resultTargets.ContainsKey(publicationData.Title))
                            {
                                resultTargets[publicationData.Title].Add(pubTargetdata.Id);
                            }

                            else
                            {
                                targetIds.Add(pubTargetdata.Id);
                                resultTargets.Add(publicationData.Title, targetIds);
                            }
                        }
                    }
                }
            }

            return(resultTargets);
        }
        /// <summary>
        /// Create bundle from given schema
        /// </summary>
        /// <param name="schemaID"></param>
        /// <param name="folderId"></param>
        /// <returns></returns>
        public static VirtualFolderData CreateBundle(string schemaID, string folderId)
        {
            cs_client = CoreServiceProvider.CreateCoreService();
            SchemaData bundleSchema = (SchemaData)cs_client.Read(schemaID, new ReadOptions());

            SchemaData virtualFolderTypeSchema =
                cs_client.GetVirtualFolderTypeSchema(@"http://www.sdltridion.com/ContentManager/Bundle");

            VirtualFolderData bundle = new VirtualFolderData()
            {
                Id             = "tcm:0-0-0",
                Title          = "Test Bundle Title",
                Description    = "Test Bundle Description",
                MetadataSchema = new LinkToSchemaData()
                {
                    IdRef = bundleSchema.Id
                },
                TypeSchema = new LinkToSchemaData()
                {
                    IdRef = virtualFolderTypeSchema.Id
                },
                LocationInfo = new LocationInfo()
                {
                    OrganizationalItem = new LinkToOrganizationalItemData()
                    {
                        IdRef = folderId
                    }
                }
            };

            bundle = (VirtualFolderData)cs_client.Create(bundle, new ReadOptions());
            return(bundle);
        }
Beispiel #5
0
        protected override void Notify(UserData userData, WorkItemData[] workItemData, XElement applicationData)
        {
            var emailaddress = applicationData.Element("EmailAddress").Value;
            var xml          = GetWorkflowDataXml(userData, workItemData, applicationData);

            if (xslt == null)
            {
                using (var client = new SessionAwareCoreServiceClient("wsHttp_2011")) //TODO: Refactor
                {
                    client.Impersonate(userData.Title);
                    var xsltBody =
                        client.Read(ConfigurationManager.AppSettings.Get("EmailNotifier.TcmIdXslt"), new ReadOptions())
                        as TemplateBuildingBlockData;
                    xslt = xsltBody.Content;
                }
            }

            var myXslTrans = new XslCompiledTransform();

            myXslTrans.Load(new XmlTextReader(new StringReader(xslt)));
            using (var sr = new StringWriter())
            {
                myXslTrans.Transform(xml.CreateNavigator(), null, sr);

                //Read mailFrom from mail-settings in App.Config
                var config       = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var mailSettings = config.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;

                SendMail(emailaddress, mailSettings.Smtp.Network.UserName, "Tridion Community Email notifier", sr.ToString());
            }
        }
 protected ContentItem(TcmUri itemId, SessionAwareCoreServiceClient client)
 {
     ReadOptions    = new ReadOptions();
     Client         = client;
     Content        = (ComponentData)client.Read(itemId, ReadOptions);
     ContentManager = new ContentManager(Client);
 }
Beispiel #7
0
        public List <string> GenerateInfoForAllSchema()
        {
            List <string> allSchema = new List <string>();

            TcmUri uri = new TcmUri(bbFolderURI);

            SessionAwareCoreServiceClient client = GetCoreServiceClient();

            RepositoryItemsFilterData filter = new RepositoryItemsFilterData();


            filter.ItemTypes   = new[] { Tridion.ContentManager.CoreService.Client.ItemType.Schema };
            filter.Recursive   = true;
            filter.BaseColumns = Tridion.ContentManager.CoreService.Client.ListBaseColumns.Id;

            IdentifiableObjectData[] schemas = client.GetList(bbFolderURI, filter);

            foreach (SchemaData schema in schemas)
            {
                SchemaData sch = (SchemaData)client.Read(schema.Id, null);
                ParseSchema(sch);
                allSchema.Add(formattedSchemaInfo);
            }

            return(allSchema);
        }
 protected ContentItem(TcmUri itemId, SessionAwareCoreServiceClient client)
 {
     ReadOptions = new ReadOptions();
     Client = client;
     Content = (ComponentData) client.Read(itemId, ReadOptions);
     ContentManager = new ContentManager(Client);
 }
Beispiel #9
0
        public string GetPathOfSelectedItem(string tcm)
        {
            string path = string.Empty;

            // Create a new, null Core Service Client
            SessionAwareCoreServiceClient client = null;

            try
            {
                // Creates a new core service client
                client = new SessionAwareCoreServiceClient("netTcp_2013");
                // Gets the current user so we can impersonate them for our client
                string username = GetUserName();
                client.Impersonate(username);

                if (String.Equals(tcm, "tcm:0") || String.Equals(tcm, "0"))
                {
                    // If it's tcm:0, we're dealing with the root element in the CMS's tree. In that case, simply
                    // do nothing to return an empty path, indicating to search through the entire tree.
                }
                else
                {
                    var item = client.Read("tcm:" + tcm, new ReadOptions());

                    if (item is RepositoryLocalObjectData)
                    {
                        path = ((RepositoryLocalObjectData)item).LocationInfo.Path + "\\" + item.Title;
                    }
                    else if (item is PublicationData)
                    {
                        // If the selection is not the root element and not a RepositoryLocalObjectData,
                        // then it's a publication.
                        path = "\\" + ((PublicationData)item).Title;
                    }
                    else
                    {
                        // Do nothing - allow empty path to be return; handle any additional cases here, if they arise.
                    }
                }

                // Explicitly abort to ensure there are no memory leaks.
                client.Abort();
            }
            catch (Exception ex)
            {
                // Proper way of ensuring that the client gets closed.
                if (client != null)
                {
                    client.Abort();
                }

                // We are rethrowing the original exception and just letting webapi handle it.
                throw ex;
            }

            return(path);
        }
        /// <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());
        }
        /// <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);
        }
        /// <summary>
        /// Gets list of CT's along with the associated schema & view
        /// </summary>
        /// <param>none</param>
        /// <returns></returns>
        public static string GetTemplatesInPublication(string pubID)
        {
            //note: this runs for about 1 minute
            StringBuilder sb = new StringBuilder();
            string        meta = string.Empty, ct = string.Empty, schema = string.Empty;

            byte[]       data = null;
            MemoryStream stm  = null;;
            XDocument    doc  = null;

            try
            {
                cs_client = CoreServiceProvider.CreateCoreService();

                // get the Id of the publication to import into
                RepositoryItemsFilterData templateFilter = SetTemplateFilterCriterias();
                XElement templates = cs_client.GetListXml(pubID, templateFilter);;

                foreach (XElement template in templates.Descendants())
                {
                    ComponentTemplateData t = (ComponentTemplateData)cs_client.Read(CheckAttributeValueOrEmpty(template, "ID"), null);

                    if (t.Metadata != "")
                    {
                        ct   = t.Title;
                        data = Encoding.ASCII.GetBytes(t.Metadata);
                        stm  = new MemoryStream(data, 0, data.Length);
                        doc  = XDocument.Load(stm);
                        meta = doc.Root.Value;

                        if (t.RelatedSchemas.Count() > 0)
                        {
                            schema = t.RelatedSchemas[0].Title;
                        }
                        else
                        {
                            schema = "No Schema Found";
                        }

                        sb.AppendLine(ct + "|" + schema + "|" + meta);
                    }
                }
            }
            catch (Exception ex)
            {
                // throw ex;
            }
            finally
            {
                cs_client.Close();
            }

            return(sb.ToString());
        }
Beispiel #13
0
        private void Localize(SessionAwareCoreServiceClient tridionClient, string objectID)
        {
            /* this is just the basic code */


            RepositoryLocalObjectData item = (RepositoryLocalObjectData)tridionClient.Read(objectID, new ReadOptions());

            // if object is localized already, return
            if ((bool)item.BluePrintInfo.IsLocalized)
            {
                return;
            }
            tridionClient.Localize(objectID, new ReadOptions());
        }
Beispiel #14
0
        public SocialPageData Execute(string pageUri)
        {
            SessionAwareCoreServiceClient client = null;
            SocialPageData socialPageData        = new SocialPageData();

            try
            {
                client = Client.GetCoreService();

                string liveTargetUri = Configuration.GetConfigString("livetargeturi");
                string liveUrl       = Configuration.GetConfigString("liveurl");

                PageData            pageData = (PageData)client.Read(pageUri, new ReadOptions());
                PublishLocationInfo pubInfo  = (PublishLocationInfo)pageData.LocationInfo;

                socialPageData.Title       = pageData.Title;
                socialPageData.Uri         = pageUri;
                socialPageData.Url         = liveUrl + pubInfo.PublishLocationUrl;
                socialPageData.IsPublished = client.IsPublished(pageUri, liveTargetUri, true);
                socialPageData.UseShortUrl = bool.Parse(Configuration.GetConfigString("shorturl"));

                string shortUrl = string.Empty;

                if (socialPageData.UseShortUrl)
                {
                    ApplicationData appData = client.ReadApplicationData(pageUri, SHORT_URL_APP_ID);

                    if (appData != null)
                    {
                        Byte[] data = appData.Data;
                        shortUrl = Encoding.Unicode.GetString(data);
                    }

                    if (shortUrl.Equals(string.Empty))
                    {
                        Bitly  service = new Bitly(socialPageData.Url);
                        string shorter = service.ShortenUrl(service.UrlToShorten, service.BitlyLogin, service.BitlyAPIKey);
                        shortUrl = Bitly.ParseXmlResponse(shorter, false);

                        Byte[] byteData = Encoding.Unicode.GetBytes(shortUrl);
                        appData = new ApplicationData
                        {
                            ApplicationId = SHORT_URL_APP_ID,
                            Data          = byteData,
                            TypeId        = shortUrl.GetType().ToString()
                        };

                        client.SaveApplicationData(pageUri, new[] { appData });
                    }
                }

                socialPageData.ShortUrl = shortUrl;
            }
            catch (Exception ex)
            {
                socialPageData.HasError  = true;
                socialPageData.ErrorInfo = ex;
            }
            finally
            {
                if (client != null)
                {
                    if (client.State == CommunicationState.Faulted)
                    {
                        client.Abort();
                    }
                    else
                    {
                        client.Close();
                    }
                }
            }

            return(socialPageData);
        }
Beispiel #15
0
        public void CheckInItem(string id, Label label)
        {
            if (label != null)
            {
                _label = label;
            }

            string tridionInstallPath = Environment.GetEnvironmentVariable("TRIDION_CM_HOME") + @"web\WebUI\Editors\AdminCheckIn\Config\";
            string filename           = "admincheckincm.config";

            string scheduleFile = System.IO.Path.Combine(tridionInstallPath, filename);

            _eventLog.WriteEntry("PATH : " + scheduleFile, EventLogEntryType.Information);
            XmlDocument doc = new XmlDocument();

            _eventLog.WriteEntry("Test");
            doc.Load(scheduleFile);
            //CultureInfo provider = CultureInfo.InvariantCulture;
            if (doc == null)
            {
                _eventLog.WriteEntry("doc is null");
            }
            _eventLog.WriteEntry("After Test");
            // has trouble accessing by selectSingleNode.
            XmlNodeList adminList         = doc.GetElementsByTagName("checkInAdminUsername");
            XmlNodeList adminPasswordList = doc.GetElementsByTagName("checkInAdminPassword");
            XmlNode     adminusername     = null;
            XmlNode     adminpassword     = null;

            if (adminList != null && adminList.Count > 0 && adminPasswordList != null && adminPasswordList.Count > 0)
            {
                adminusername = adminList[0];
                adminpassword = adminPasswordList[0];
            }
            if (adminusername == null || adminpassword == null)
            {
                label.Text = "The admin username or password is empty.  Please ensure you specified the username and password in the admincheckincm.config";
            }
            _eventLog.WriteEntry("Username: "******"PW: " + adminpassword.InnerText, EventLogEntryType.Information);
            String userName = adminusername.InnerText;
            String password = adminpassword.InnerText;

            var credentials = CredentialCache.DefaultNetworkCredentials;

            if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
            {
                credentials = new NetworkCredential(userName, password);
            }
            _client.ChannelFactory.Credentials.Windows.ClientCredential = credentials;
            try
            {
                VersionedItemData obj = _client.Read(id, new ReadOptions()) as VersionedItemData;

                if (obj is ComponentData || obj is PageData)
                {
                    BluePrintInfo   blueprintInfo = null;
                    FullVersionInfo info          = null;
                    if (obj is ComponentData)
                    {
                        ComponentData comp = obj as ComponentData;
                        info          = comp.VersionInfo as FullVersionInfo;
                        blueprintInfo = comp.BluePrintInfo as BluePrintInfo;
                    }
                    if (obj is PageData)
                    {
                        PageData page = obj as PageData;
                        info          = page.VersionInfo as FullVersionInfo;
                        blueprintInfo = page.BluePrintInfo;
                    }
                    if (info.LockType != LockType.CheckedOut)
                    {
                        _label.Text = "Item is Not Checked Out";
                        return;
                    }
                    if (blueprintInfo.IsLocalized == false && blueprintInfo.IsShared == true)
                    {
                        _label.Text = "Item is Shared Item. Please Checkin from the Owning Publication";
                        return;
                    }
                }
                if (obj is ComponentData || obj is PageData)
                {
                    _label.Text = "Checking in item";
                    this._client.CheckInCompleted += new EventHandler <CheckInCompletedEventArgs>(TridionCheckIn.CheckInCallback);
                    this._client.CheckInAsync(id, new ReadOptions());
                    _eventLog.WriteEntry("Checking in item", EventLogEntryType.Information);
                }
                else
                {
                    _label.Text = "Can not check in. Item is not Component or Page!";
                    return;
                }
            }
            catch (Exception e)
            {
                _label.Text = "Username and Password provided is invalid";
                _eventLog.WriteEntry(e.Message, EventLogEntryType.Error);
            }
        }
        static void Main(string[] args)
        {
            //args[0] = "tcm:11-403-8";
            if (!args.Any())
            {
                Log("Please pass the Schema Tcm Uri as a parameter.");
                return;
            }
            string schemaUri = args[0];
            if (!TcmUri.IsValid(schemaUri))
            {
                Log("The specified URI of " + schemaUri + " is not a valid URI, please pass the schema Tcm Uri as a parameter.");
                return;
            }

            SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2013");
            if (!client.IsExistingObject(schemaUri))
            {
                Log("Could not find item with URI " + schemaUri + " in Tridion. Please pass the Schema Tcm Uri as a parameter.");
                return;
            }
            ReadOptions readOptions = new ReadOptions();
            UsingItemsFilterData whereUsedFilter = new UsingItemsFilterData { ItemTypes = new[] { ItemType.Component } };
            SchemaData schema = (SchemaData)client.Read(schemaUri, readOptions);
            SchemaFieldsData schemaFieldsData = client.ReadSchemaFields(schema.Id, true, readOptions);
            bool hasMeta = schemaFieldsData.MetadataFields.Any();
            string newNamespace = schema.NamespaceUri;

            if (schema.Purpose == SchemaPurpose.Metadata)
            {
                List<IdentifiableObjectData> items = new List<IdentifiableObjectData>();
                UsingItemsFilterData anyItem = new UsingItemsFilterData();
                foreach (XElement node in client.GetListXml(schema.Id, anyItem).Nodes())
                {
                    string uri = node.Attribute("ID").Value;
                    items.Add(client.Read(uri, readOptions));
                }
                Log("Found " + items.Count + " items using schema...");

                foreach (var item in items)
                {
                    if (item is PublicationData)
                    {
                        PublicationData pub = (PublicationData)item;
                        string meta = pub.Metadata;
                        XmlDocument xml = new XmlDocument();
                        xml.LoadXml(meta);
                        string oldnamespace = xml.DocumentElement.NamespaceURI;
                        if (oldnamespace != newNamespace)
                        {
                            Log("Replacing namespace for publication " + pub.Id + " (" + pub.Title + ") - Current Namespace: " + oldnamespace);
                            string metadata = meta.Replace(oldnamespace, newNamespace);
                            pub.Metadata = metadata;
                            client.Update(pub, readOptions);
                        }
                    }
                    else if (item is RepositoryLocalObjectData)
                    {
                        RepositoryLocalObjectData data = (RepositoryLocalObjectData)item;
                        string meta = data.Metadata;
                        XmlDocument xml = new XmlDocument();
                        xml.LoadXml(meta);
                        string oldnamespace = xml.DocumentElement.NamespaceURI;
                        if (oldnamespace != newNamespace)
                        {
                            Log("Replacing namespace for item " + data.Id + " (" + data.Title + ") - Current Namespace: " + oldnamespace);
                            string metadata = meta.Replace(oldnamespace, newNamespace);
                            data.Metadata = metadata;
                            client.Update(data, readOptions);
                        }

                    }
                }

                return;
            }

            List<ComponentData> components = new List<ComponentData>();
            foreach (XElement node in client.GetListXml(schema.Id, whereUsedFilter).Nodes())
            {
                string uri = node.Attribute("ID").Value;
                components.Add((ComponentData)client.Read(uri, readOptions));
            }
            Log("Found " + components.Count + " components.");

            Log("Current schema namespace set to " + newNamespace + ", checking for components with incorrect namespace.");
            int count = 0;
            foreach (var component in components)
            {
                if (schema.Purpose == SchemaPurpose.Multimedia)
                {
                    Log("Changing Multimedia Component");
                    string meta = component.Metadata;
                    XmlDocument metaXml = new XmlDocument();
                    metaXml.LoadXml(meta);
                    string metaOldnamespace = metaXml.DocumentElement.NamespaceURI;
                    if (metaOldnamespace != newNamespace)
                    {
                        Log("Replacing namespace for item " + component.Id + " (" + component.Title + ") - Current Namespace: " + metaOldnamespace);
                        string metadata = meta.Replace(metaOldnamespace, newNamespace);
                        component.Metadata = metadata;
                        client.Update(component, readOptions);
                    }
                    count++;
                    Log(components.Count - count + " components remaining...");

                    continue;
                }

                string content = component.Content;

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(content);

                string oldnamespace = xml.DocumentElement.NamespaceURI;

                if (oldnamespace != newNamespace)
                {
                    Log("Replacing namespace for component " + component.Id + " (" + component.Title + ") - Current Namespace: " + oldnamespace);
                    content = content.Replace(oldnamespace, newNamespace);
                    try
                    {
                        ComponentData editableComponent = component;
                        editableComponent.Content = content;
                        if (hasMeta)
                        {
                            string metadata = editableComponent.Metadata.Replace(oldnamespace, newNamespace);

                            // Fix for new meta
                            if (string.IsNullOrEmpty(metadata))
                            {
                                metadata = string.Format("<Metadata xmlns=\"{0}\" />", newNamespace);
                                Log("Component had no metadata, but schema specifies it has. Adding empty metadata node");
                            }
                            editableComponent.Metadata = metadata;
                        }

                        if (!hasMeta && !(string.IsNullOrEmpty(editableComponent.Metadata)))
                        {
                            editableComponent.Metadata = string.Empty;
                        }

                        client.Update(editableComponent, readOptions);

                    }
                    catch (Exception ex)
                    {
                        Log("Error occurred trying to update component: " + component.Id + Environment.NewLine + ex);

                    }

                }
                count++;
                Log(components.Count - count + " components remaining...");
            }
        }
Beispiel #17
0
        private string GetFileNameFromComponent(SessionAwareCoreServiceClient client, string componentId)
        {
            ComponentData compData = (ComponentData)client.Read(componentId, new ReadOptions());

            return(compData.BinaryContent.Filename);
        }
        /// <summary>
        /// Gets list of CT's along with the associated schema & view
        /// </summary>
        /// <param>none</param>
        /// <returns></returns>
        public static string GetAllItemsInPublication(string pubID)
        {
            RepositoryItemsFilterData filter = SetPageFilterCriterias();
            StringBuilder             sb     = new StringBuilder();

            cs_client = CoreServiceProvider.CreateCoreService();
            try
            {
                IdentifiableObjectData[] pages = cs_client.GetList(pubID, filter);

                foreach (IdentifiableObjectData iod in pages)
                {
                    PageData pageData = cs_client.Read(iod.Id, new ReadOptions()) as PageData;

                    sb.AppendLine("Page: " + pageData.LocationInfo.Path);
                    sb.AppendLine("PT: " + pageData.PageTemplate.Title);
                    sb.AppendLine("PM: " + pageData.MetadataSchema.Title);

                    foreach (ComponentPresentationData cpd in pageData.ComponentPresentations)
                    {
                        sb.AppendLine("");
                        sb.AppendLine("CP: " + cpd.Component.Title);

                        ComponentData cp = (ComponentData)cs_client.Read(cpd.Component.IdRef, new ReadOptions());
                        sb.AppendLine("CS: " + cp.Schema.Title);

                        sb.AppendLine("CT: " + cpd.ComponentTemplate.Title);
                        ComponentTemplateData ct = (ComponentTemplateData)cs_client.Read(cpd.ComponentTemplate.IdRef, new ReadOptions());
                        sb.AppendLine("CM: " + ct.MetadataSchema.Title);

                        // load the schema
                        var schemaFields = cs_client.ReadSchemaFields(cp.Schema.IdRef, true, new ReadOptions());

                        // build a  Fields object from it
                        var fields = Fields.ForContentOf(schemaFields, cp);

                        // let's first quickly list all values of all fields
                        foreach (var field in fields)
                        {
                            if (field.GetType() == typeof(EmbeddedSchemaFieldDefinitionData))
                            {
                            }
                            if (field.GetType() == typeof(ComponentLinkFieldDefinitionData))
                            {
                            }
                            if (field.GetType() == typeof(EmbeddedSchemaFieldDefinitionData))
                            {
                            }
                        }
                    }

                    //blank line for readability
                    sb.AppendLine("");
                    sb.AppendLine("");
                }
            }
            catch (Exception ex)
            {
                // throw ex;
            }
            finally
            {
                cs_client.Close();
            }

            return(sb.ToString());
        }
Beispiel #19
0
 public IdentifiableObjectData Read(string id, ReadOptions readOptions)
 {
     return(_client.Read(id, readOptions));
 }
 private string GetFileNameFromComponent(SessionAwareCoreServiceClient client, string componentId)
 {
     ComponentData compData = (ComponentData)client.Read(componentId, new ReadOptions());
     return compData.BinaryContent.Filename;
 }