private static ItemsFilterData GetFilter(GetCountParameters parameters)
        {
            ItemsFilterData filter;
            if (parameters.OrganizationalItemId.EndsWith("-1")) // is Publication
            {
                filter = new RepositoryItemsFilterData();
            }
            else // is Folder or Structure Group
            {
                filter = new OrganizationalItemItemsFilterData();
            }

            filter.Recursive = true;

            List<ItemType> itemTypesList = new List<ItemType>();
            if (parameters.CountFolders) { itemTypesList.Add(ItemType.Folder); }
            if (parameters.CountComponents) { itemTypesList.Add(ItemType.Component); }
            if (parameters.CountSchemas) { itemTypesList.Add(ItemType.Schema); }
            if (parameters.CountComponentTemplates) { itemTypesList.Add(ItemType.ComponentTemplate); }
            if (parameters.CountPageTemplates) { itemTypesList.Add(ItemType.PageTemplate); }
            if (parameters.CountTemplateBuildingBlocks) { itemTypesList.Add(ItemType.TemplateBuildingBlock); }
            if (parameters.CountStructureGroups) { itemTypesList.Add(ItemType.StructureGroup); }
            if (parameters.CountPages) { itemTypesList.Add(ItemType.Page); }
            if (parameters.CountCategories) { itemTypesList.Add(ItemType.Category); }
            if (parameters.CountKeywords) { itemTypesList.Add(ItemType.Keyword); }

            filter.ItemTypes = itemTypesList.ToArray();
            return filter;
        }
示例#2
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);
        }
示例#3
0
        public string GetMultimediaComponentByPubID(string tcmuri)
        {
            string xmlOrJson = "xml";

            try
            {
                coreService = CoreServiceFactory.GetCoreServiceContext(new Uri(ConfigurationManager.AppSettings["CoreServiceURL"].ToString()), new NetworkCredential(ConfigurationManager.AppSettings["UserName"].ToString(), ConfigurationManager.AppSettings["Password"].ToString(), ConfigurationManager.AppSettings["Domain"].ToString()));
                string output = string.Empty;

                var filter = new RepositoryItemsFilterData();
                filter.ItemTypes      = new ItemType[] { ItemType.Component };
                filter.ComponentTypes = new ComponentType[] { ComponentType.Multimedia };

                filter.Recursive = true;
                var listXml = coreService.Client.GetListXml("tcm:" + tcmuri, filter);
                if (xmlOrJson.ToString().ToLower() == "json")
                {
                    output = JsonConvert.SerializeObject(listXml);
                }
                else
                {
                    output = listXml.ToString();
                }

                return(output);
            }


            catch (Exception ex)
            {
                return(ex.Message.ToString());
            }
        }
示例#4
0
        public IEnumerable <TemplateData> FindTemplatesForPublication(string publicationId, bool pageTemplatesOnly = false)
        {
            log.Info("Called FindSchemasForPublication with publicationId " + publicationId);
            RepositoryItemsFilterData filterData = new RepositoryItemsFilterData();

            filterData.ItemTypes = pageTemplatesOnly ? new[] { ItemType.PageTemplate } : new[] { ItemType.PageTemplate, ItemType.ComponentTemplate };
            filterData.Recursive = true;
            XElement resultXml = Client.GetListXml(publicationId, filterData);

            return(GetConvertibleTemplates(resultXml));
        }
示例#5
0
        /// <summary>
        /// Sets up the template filter
        /// </summary>
        /// <param>none</param>
        /// <returns></returns>
        private static RepositoryItemsFilterData SetTemplateFilterCriterias()
        {
            RepositoryItemsFilterData templateFilter = new RepositoryItemsFilterData();
            List <ItemType>           types          = new List <ItemType>();

            types.Add(ItemType.Page);
            templateFilter.Recursive   = true;
            templateFilter.BaseColumns = ListBaseColumns.Extended;
            templateFilter.ItemTypes   = types.ToArray();
            return(templateFilter);
        }
示例#6
0
        /// <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());
        }
示例#7
0
        public IEnumerable <SchemaData> FindSchemasForPublication(string publicationId)
        {
            log.Info("Called FindSchemasForPublication with publicationId " + publicationId);
            RepositoryItemsFilterData filterData = new RepositoryItemsFilterData();

            filterData.ItemTypes = new[] { ItemType.Schema };
            filterData.Recursive = true;
            XElement           resultXml          = Client.GetListXml(publicationId, filterData);
            IList <SchemaData> convertibleSchemas = GetConvertibleSchemas(resultXml);

            return(convertibleSchemas);
        }
示例#8
0
        //http://codedweapon.com/2012/12/getting-using-and-used-items-with-core-services/
        private static List GetListOfType(string publicationTcmId, Tridion.ContentManager.CoreService.Client.ItemType searchForType)
        {
            RepositoryItemsFilterData filter = new RepositoryItemsFilterData
            {
                ItemTypes = new[] { searchForType },
                Recursive = true
            };

            IEnumerable <XNode> searchResult = core.GetListXml(publicationTcmId, filter).Nodes();
            var list = new List(searchResult);

            return(list);
        }
        //http://codedweapon.com/2012/12/getting-using-and-used-items-with-core-services/
        private static List GetListOfType(string publicationTcmId, Tridion.ContentManager.CoreService.Client.ItemType searchForType)
        {
            RepositoryItemsFilterData filter = new RepositoryItemsFilterData
            {
                ItemTypes = new[] { searchForType },
                Recursive = true
            };

            IEnumerable<XNode> searchResult = core.GetListXml(publicationTcmId, filter).Nodes();
            var list = new List(searchResult);

            return list;
        }
示例#10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _coreServiceEndpoint  = new EndpointAddress(WebConfigurationManager.AppSettings["EndpointAddress"]);
            _vocabulariesAppId    = WebConfigurationManager.AppSettings["VocabulariesAppId"];
            _typeOfAppId          = WebConfigurationManager.AppSettings["TypeOfAppId"];
            _schemaPublicationUri = WebConfigurationManager.AppSettings["SchemaPublicationUri"];

            if (!IsPostBack)
            {
                var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint);
                client.Impersonate(HttpContext.Current.User.Identity.Name);

                // load vocabularies appdata
                ApplicationData appData = client.ReadApplicationData(null, _vocabulariesAppId);
                if (appData != null)
                {
                    AppData.Text = Encoding.Unicode.GetString(appData.Data);
                }
                else
                {
                    // load default xml
                    AppData.Text = "<vocabularies>\n  <vocabulary prefix=\"s\" name=\"http://schema.org\"/>\n</vocabularies>";
                }

                // load schemas
                var filter = new RepositoryItemsFilterData {
                    ItemTypes = new[] { ItemType.Schema }, Recursive = true
                };
                var schemas = client.GetList(_schemaPublicationUri, filter);
                foreach (var schema in schemas)
                {
                    SchemaList.Items.Add(new ListItem(schema.Title, schema.Id));
                }

                // load appdata for first schema in the list
                appData = client.ReadApplicationData(schemas[0].Id, _typeOfAppId);
                if (appData != null)
                {
                    TypeOf.Text = Encoding.Unicode.GetString(appData.Data);
                }

                Close(client);
            }
        }
示例#11
0
        public string GetComponentTemplateByPubID(string tcmuri)
        {
            string xmljson = "xml";

            try
            {
                coreService = CoreServiceFactory.GetCoreServiceContext(new Uri(ConfigurationManager.AppSettings["CoreServiceURL"].ToString()), new NetworkCredential(ConfigurationManager.AppSettings["UserName"].ToString(), ConfigurationManager.AppSettings["Password"].ToString(), ConfigurationManager.AppSettings["Domain"].ToString()));

                var filter = new RepositoryItemsFilterData();
                filter.ItemTypes = new[] { ItemType.ComponentTemplate, };
                filter.Recursive = true;
                var listXml = coreService.Client.GetListXml("tcm:" + tcmuri, filter);
                return(xmljson.ToLower() == "json" ? JsonConvert.SerializeObject(listXml) : listXml.ToString());
            }
            catch (Exception ex)
            {
                return(ex.Message.ToString());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _coreServiceEndpoint = new EndpointAddress(WebConfigurationManager.AppSettings["EndpointAddress"]);
            _vocabulariesAppId = WebConfigurationManager.AppSettings["VocabulariesAppId"];
            _typeOfAppId = WebConfigurationManager.AppSettings["TypeOfAppId"];
            _schemaPublicationUri = WebConfigurationManager.AppSettings["SchemaPublicationUri"];

            if (!IsPostBack)
            {
                var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint);
                client.Impersonate(HttpContext.Current.User.Identity.Name);

                // load vocabularies appdata
                ApplicationData appData = client.ReadApplicationData(null, _vocabulariesAppId);
                if (appData != null)
                {
                    AppData.Text = Encoding.Unicode.GetString(appData.Data);
                }
                else
                {
                    // load default xml
                    AppData.Text = "<vocabularies>\n  <vocabulary prefix=\"s\" name=\"http://schema.org\"/>\n</vocabularies>";
                }

                // load schemas
                var filter = new RepositoryItemsFilterData { ItemTypes = new[] { ItemType.Schema }, Recursive = true };
                var schemas = client.GetList(_schemaPublicationUri, filter);
                foreach (var schema in schemas)
                {
                    SchemaList.Items.Add(new ListItem(schema.Title, schema.Id));
                }

                // load appdata for first schema in the list
                appData = client.ReadApplicationData(schemas[0].Id, _typeOfAppId);
                if (appData != null)
                {
                    TypeOf.Text = Encoding.Unicode.GetString(appData.Data);
                }

                Close(client);
            }
        }
        /// <summary>
        /// GetFilter - Creates a ItemFilter which is used to obtain a list of publishable items.
        /// </summary>
        /// <param name="parameters">PagePublisherParameters</param>
        /// <returns>ItemsFilterData object</returns>
        private ItemsFilterData GetFilter(PagePublisherParameters parameters)
        {
            ItemsFilterData filter = null;

            if (parameters.LocationId.EndsWith("-1")) // is Publication
            {
                filter = new RepositoryItemsFilterData();
            }
            else // is Folder or Structure Group
            {
                filter = new OrganizationalItemItemsFilterData();
            }

            filter.Recursive = parameters.Recursive;
            List <ItemType> itemTypesList = new List <ItemType>();

            itemTypesList.Add(ItemType.Page);
            filter.ItemTypes = itemTypesList.ToArray();
            return(filter);
        }
        public string[] GetSchemaIds()
        {
            string tcmUri = ConfigurationManager.AppSettings[Constants.START_TCMURI];
            SubjectRelatedListFilterData filter = new RepositoryItemsFilterData
            {
                ItemTypes = new[] {
                    ItemType.Schema
                },
                SchemaPurposes = new[] {
                    SchemaPurpose.Component,
                    SchemaPurpose.Embedded,
                    SchemaPurpose.Multimedia
                },
                Recursive = true
            };

            string[] result = Client.GetList(tcmUri, filter).Select(x => x.Id).ToArray();
            Console.WriteLine("Found {0} Schemas", result.Length);

            return result;
        }
示例#15
0
        /// <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());
        }
        /// <summary>
        /// GetFilter - Creates a ItemFilter which is used to obtain a list of publishable items.
        /// </summary>
        /// <param name="parameters">PagePublisherParameters</param>
        /// <returns>ItemsFilterData object</returns>
        private ItemsFilterData GetFilter(PagePublisherParameters parameters)
        {
            ItemsFilterData filter = null;
            if (parameters.LocationId.EndsWith("-1")) // is Publication
            {
                filter = new RepositoryItemsFilterData();
            }
            else // is Folder or Structure Group
            {
                filter = new OrganizationalItemItemsFilterData();
            }

            filter.Recursive = parameters.Recursive;
            List<ItemType> itemTypesList = new List<ItemType>();
            itemTypesList.Add(ItemType.Page);
            filter.ItemTypes = itemTypesList.ToArray();
            return filter;
        }
        public override void Process(ServiceProcess process, object arguments)
        {
            _duplicateData = new List<DuplicateBinariesData>();
            fileNames = new Dictionary<string, string>();
            DuplicateBinariesParameters parameters = (DuplicateBinariesParameters)arguments;
            
            //_duplicateBinariesData = new DuplicateBinariesData();
            //_duplicateBinariesData.PublicationId = parameters.PublicationId;
            
            process.SetCompletePercentage(10);
            process.SetStatus("working");

            using (var coreService = Client.GetCoreService())
            {
                try
                {
                    process.SetCompletePercentage(15);
                    process.SetStatus("Creating publication filter");

                    // Create a filter to only fetch multimedia components from the publication
                    RepositoryItemsFilterData filter = new RepositoryItemsFilterData();
                    filter.ItemTypes = new[] { ItemType.Component };
                    filter.ComponentTypes = new[] { ComponentType.Multimedia };
                    XElement mmComponentsListXml = coreService.GetListXml(parameters.PublicationId, filter);
			        XNamespace tcm = "http://www.tridion.com/ContentManager/5.0";

                    double progressIncrement = mmComponentsListXml.Value.Length == 0 ? 0 : 80 / mmComponentsListXml.Value.Length; //nasty progress calculation
                    int i = 1;

                    // keep a list of all the file names from the items in the publication
                    // the if a file already exists in the filenames, it is considered a 'duplicate file name'
                    foreach(XElement itemElem in mmComponentsListXml.Descendants(tcm + "Item"))
                    {
                        string itemId = itemElem.Attribute("ID").Value;
                        string binaryFileName = GetFileNameFromComponent(coreService, itemId);
                        
                        fileNames.Add(itemId, binaryFileName);

                        int progressPercentage = (int)(20 + i * progressIncrement); // some more nasty progress calculation
                        process.SetCompletePercentage(progressPercentage);
                        i++;
                    }

                    var duplicateValues = fileNames.ToLookup(a => a.Value).
                        Where(b => b.Count() > 1);

                    // todo - refactor this below item to select the id's and values from the file
                    // name list

                    foreach (var group in duplicateValues)
                    {
                        foreach (KeyValuePair<string, string> kvp in group)
                        {
                            _duplicateData.Add(new DuplicateBinariesData
                            {
                                ItemTcmId = kvp.Key,
                                ItemFileName = kvp.Value,
                            });
                        }
                    }

                    process.Complete("Done");
                }
                catch (Exception ex)
                {
                    // TODO: Update the GUI that there has been error - solution below is temporary
                    process.Failed = true;
                    process.Complete(string.Format("Failure finding duplicate items reason: {0}", ex.Message));
                    return;
                    
                }

            }


        }
示例#18
0
        public override void Process(ServiceProcess process, object arguments)
        {
            _duplicateData = new List <DuplicateBinariesData>();
            fileNames      = new Dictionary <string, string>();
            DuplicateBinariesParameters parameters = (DuplicateBinariesParameters)arguments;

            //_duplicateBinariesData = new DuplicateBinariesData();
            //_duplicateBinariesData.PublicationId = parameters.PublicationId;

            process.SetCompletePercentage(10);
            process.SetStatus("working");

            using (var coreService = Client.GetCoreService())
            {
                try
                {
                    process.SetCompletePercentage(15);
                    process.SetStatus("Creating publication filter");

                    // Create a filter to only fetch multimedia components from the publication
                    RepositoryItemsFilterData filter = new RepositoryItemsFilterData();
                    filter.ItemTypes      = new[] { ItemType.Component };
                    filter.ComponentTypes = new[] { ComponentType.Multimedia };
                    XElement   mmComponentsListXml = coreService.GetListXml(parameters.PublicationId, filter);
                    XNamespace tcm = "http://www.tridion.com/ContentManager/5.0";

                    double progressIncrement = mmComponentsListXml.Value.Length == 0 ? 0 : 80 / mmComponentsListXml.Value.Length; //nasty progress calculation
                    int    i = 1;

                    // keep a list of all the file names from the items in the publication
                    // the if a file already exists in the filenames, it is considered a 'duplicate file name'
                    foreach (XElement itemElem in mmComponentsListXml.Descendants(tcm + "Item"))
                    {
                        string itemId         = itemElem.Attribute("ID").Value;
                        string binaryFileName = GetFileNameFromComponent(coreService, itemId);

                        fileNames.Add(itemId, binaryFileName);

                        int progressPercentage = (int)(20 + i * progressIncrement); // some more nasty progress calculation
                        process.SetCompletePercentage(progressPercentage);
                        i++;
                    }

                    var duplicateValues = fileNames.ToLookup(a => a.Value).
                                          Where(b => b.Count() > 1);

                    // todo - refactor this below item to select the id's and values from the file
                    // name list

                    foreach (var group in duplicateValues)
                    {
                        foreach (KeyValuePair <string, string> kvp in group)
                        {
                            _duplicateData.Add(new DuplicateBinariesData
                            {
                                ItemTcmId    = kvp.Key,
                                ItemFileName = kvp.Value,
                            });
                        }
                    }

                    process.Complete("Done");
                }
                catch (Exception ex)
                {
                    // TODO: Update the GUI that there has been error - solution below is temporary
                    process.Failed = true;
                    process.Complete(string.Format("Failure finding duplicate items reason: {0}", ex.Message));
                    return;
                }
            }
        }
示例#19
0
        /// <summary>
        /// Create an ItemsFilter for the given Organizational Item type by either instantiating a
        /// RepositoryItemsFilterData (for Publication) or OrganizationalItemItemsFilterData (for Folder or SG).
        /// Populates the ItemTypes property with only the types that were requested to improve performance.
        /// </summary>
        private static ItemsFilterData GetFilter(CountItemsParameters parameters)
        {
            ItemsFilterData filter;

            if (parameters.OrgItemUri.EndsWith("-1"))             // is Publication
            {
                filter = new RepositoryItemsFilterData();
            }
            else             // is Folder or Structure Group
            {
                filter = new OrganizationalItemItemsFilterData();
            }

            filter.Recursive = true;

            List <ItemType> itemTypesList = new List <ItemType>();

            if (parameters.CountFolders)
            {
                itemTypesList.Add(ItemType.Folder);
            }
            if (parameters.CountComponents)
            {
                itemTypesList.Add(ItemType.Component);
            }
            if (parameters.CountSchemas)
            {
                itemTypesList.Add(ItemType.Schema);
            }
            if (parameters.CountComponentTemplates)
            {
                itemTypesList.Add(ItemType.ComponentTemplate);
            }
            if (parameters.CountPageTemplates)
            {
                itemTypesList.Add(ItemType.PageTemplate);
            }
            if (parameters.CountTemplateBuildingBlocks)
            {
                itemTypesList.Add(ItemType.TemplateBuildingBlock);
            }
            if (parameters.CountStructureGroups)
            {
                itemTypesList.Add(ItemType.StructureGroup);
            }
            if (parameters.CountPages)
            {
                itemTypesList.Add(ItemType.Page);
            }
            if (parameters.CountCategories)
            {
                itemTypesList.Add(ItemType.Category);
            }
            if (parameters.CountKeywords)
            {
                itemTypesList.Add(ItemType.Keyword);
            }

            filter.ItemTypes = itemTypesList.ToArray();

            return(filter);
        }