public static bool bluePrintInfo(CoreServiceClient client) { client.ClientCredentials.Windows.ClientCredential.Domain = ConfigurationSettings.AppSettings["Domain"]; client.ClientCredentials.Windows.ClientCredential.UserName = ConfigurationSettings.AppSettings["User"]; client.ClientCredentials.Windows.ClientCredential.Password = ConfigurationSettings.AppSettings["PWD"]; UsingItemsFilterData usingItemsFilterData = new UsingItemsFilterData { ItemTypes = new[] { ItemType.PublicationTarget, ItemType.Publication, ItemType.Component, ItemType.Page, ItemType.Keyword } , IncludeLocalCopies = true, BaseColumns = ListBaseColumns.Extended, }; PublicationsFilterData filter = new PublicationsFilterData { BaseColumns = ListBaseColumns.IdAndTitle }; XElement publications = client.GetSystemWideListXml(filter); XElement elist = client.GetListXml("tcm:3-1973", usingItemsFilterData); List <Result> lstRS = new List <Result>(); IEnumerable <XElement> usingXML1 = (from el in elist.Elements() //where (string)el.Attribute("IsPublished").Value == "true" select el); return(true); }
/// <summary> /// Gets the where used count. /// </summary> /// <param name="client">The client.</param> /// <param name="tcmId">The TCM identifier.</param> /// <returns/> private int WhereUsedCount(string tcmId) { UsingItemsFilterData usingItemsFilterData1 = new UsingItemsFilterData(); usingItemsFilterData1.BaseColumns = ListBaseColumns.Id; usingItemsFilterData1.IncludeLocalCopies = true; usingItemsFilterData1.IncludedVersions = VersionCondition.OnlyLatestVersions; UsingItemsFilterData usingItemsFilterData2 = usingItemsFilterData1; return(this.Client.GetList(tcmId, usingItemsFilterData2).Length); }
/// <summary> /// Gets using items of source item. All revisions discovered /// </summary> /// <param name="client">Tridion client object.</param> /// <param name="tcmItem">Item TCM id.</param> /// <param name="current">if set to <c>true</c> [current].</param> /// <param name="itemTypes">The item types.</param> /// <returns></returns> public static List <string> GetUsingItems(IAlchemyCoreServiceClient client, string tcmItem, bool current = false, ItemType[] itemTypes = null) { UsingItemsFilterData filter = new UsingItemsFilterData(); filter.IncludedVersions = current ? VersionCondition.OnlyLatestVersions : VersionCondition.AllVersions; filter.BaseColumns = ListBaseColumns.Id; if (itemTypes != null) { filter.ItemTypes = itemTypes; } List <string> items = client.GetListXml(tcmItem, filter).ToList().Select(x => x.TcmId).ToList(); return(items); }
public string GetLocalizedCount(string uri = "") { uri = "tcm:" + uri; UsingItemsFilterData filter = new UsingItemsFilterData(); filter.IncludeLocalCopies = true; var children = Client.GetListXml(uri, filter); int count = 0; foreach (XElement item in children.Elements()) { count++; } return count.ToString(); }
public string GetLocalizedCount(string uri = "") { uri = "tcm:" + uri; UsingItemsFilterData filter = new UsingItemsFilterData(); filter.IncludeLocalCopies = true; var children = Client.GetListXml(uri, filter); int count = 0; foreach (XElement item in children.Elements()) { count++; } return(count.ToString()); }
public string Unlocalize(string uri = "") { uri = "tcm:" + uri; UsingItemsFilterData filter = new UsingItemsFilterData(); filter.IncludeLocalCopies = true; var children = Client.GetListXml(uri, filter); int count = 0; foreach (XElement item in children.Elements()) { Client.UnLocalize(item.Attribute("ID").Value, new ReadOptions()); count++; } return count.ToString() + " Items Unlocalized"; }
/// <summary> /// Gets a list of all component templates used by this schema /// </summary> /// <param name="schemaId">The schema ID</param> /// <returns><![CDATA[An IEnumerabe<XNode> list of component templates]]></returns> private IEnumerable <XNode> GetUsingComponentTemplates(ComponentData component) { SchemaData componentSchema = GetComponentSchema(component.Schema.IdRef); LogMessage("The component's schema ID is " + componentSchema.Id); UsingItemsFilterData usingFilter = new UsingItemsFilterData(); usingFilter.ItemTypes = new[] { ItemType.ComponentTemplate }; usingFilter.IncludedVersions = VersionCondition.OnlyLatestVersions; //LinkToRepositoryData contextRepository = new LinkToRepositoryData() //{ // IdRef = TestContext.Properties["TemplatePublicationId"].ToString() //}; //usingFilter.InRepository = contextRepository; return(Client.GetListXml(componentSchema.Id, usingFilter).Nodes()); }
public string Unlocalize(string uri = "") { uri = "tcm:" + uri; UsingItemsFilterData filter = new UsingItemsFilterData(); filter.IncludeLocalCopies = true; var children = Client.GetListXml(uri, filter); int count = 0; foreach (XElement item in children.Elements()) { Client.UnLocalize(item.Attribute("ID").Value, new ReadOptions()); count++; } return(count.ToString() + " Items Unlocalized"); }
private static void GetRelatedPages(string componentUri, int level) { //Only collect pages that have publishdate before 15 april 2015 DateTime dt = new DateTime(2015, 4, 15); UsingItemsFilterData filter = new UsingItemsFilterData { ItemTypes = new[] { Tridion.ContentManager.CoreService.Client.ItemType.Component, Tridion.ContentManager.CoreService.Client.ItemType.Page }, IncludedVersions = VersionCondition.OnlyLatestVersions }; foreach (System.Xml.Linq.XElement node in core.GetListXml(componentUri, filter).Nodes()) { string nodeId = node.Attribute("ID").Value; string path = node.Attribute("Path").Value; int type = int.Parse(node.Attribute("Type").Value); if (type == 64) { //Is a page if (!pages.Keys.Contains(nodeId)) { //Get publish info of last publish action var pubInfo = core.GetListPublishInfo(nodeId).LastOrDefault(); if (pubInfo != null && pubInfo.PublishedAt < dt) { var page = core.Read(nodeId, readOpts) as PageData; var locInfo = ((PublishLocationInfo)page.LocationInfo); string url = locInfo.PublishLocationUrl; pages.Add(nodeId, url); //publish var liveTarget = new[] { "tcm:0-141-65538" }; //core.Publish(new[] { nodeId }, new PublishInstructionData { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = true }, RenderInstruction = new RenderInstructionData() }, liveTarget, PublishPriority.Low, null); } //ignore when page is never been published } } else if (level < 3) { GetRelatedPages(nodeId, level + 1); } } }
public static List <Lead> getLeadList(ICoreServiceFrameworkContext coreService) { SchemaFieldsData schemaFieldData = coreService.Client.ReadSchemaFields(ConfigurationManager.AppSettings["SchemaID"].ToString(), true, new ReadOptions()); UsingItemsFilterData f = new UsingItemsFilterData { ItemTypes = new[] { ItemType.Component } }; IdentifiableObjectData[] items = coreService.Client.GetList(ConfigurationManager.AppSettings["SchemaID"].ToString(), f); List <Lead> newLeadList = new List <Lead>(); XmlDocument Xdoc = new XmlDocument(); foreach (var item in items) { Lead _lead = new Lead(); ComponentData component = (ComponentData)coreService.Client.Read(item.Id, new ReadOptions()); Xdoc.LoadXml(component.Content); _lead = DataTransformation.Deserialize <Lead>(Xdoc); newLeadList.Add(_lead); //Do something } return(newLeadList); }
public void AddSchemas(IEnumerable <SchemaData> schemas) { currentViewModel = null; List <SchemaData> convertibleSchemas = new List <SchemaData>(); convertibleSchemas.AddRange(schemas); int nrTries = 0; while (convertibleSchemas.Count > 0 && nrTries++ < MaxTries) { _log.DebugFormat("trying to convert {0} schemas to viewmodel definitions, starting parsing round #{1}", convertibleSchemas.Count, nrTries); List <SchemaData> extraSchemas = new List <SchemaData>(); foreach (var schema in convertibleSchemas) { _log.Debug("starting converting schema " + schema.Title); ConvertSchema(schema); } convertibleSchemas = convertibleSchemas.Where(a => ViewModels.Any(b => b.TcmUri == a.Id && b.HasUnresolvedProperties)).ToList(); if (extraSchemas.Count > 0) { _log.DebugFormat("adding {0} extra schemas (found during property parsing)", extraSchemas.Count); convertibleSchemas.AddRange(extraSchemas); } _log.DebugFormat("after parsing round #{0} there are still {1} schemas to be converted", nrTries, convertibleSchemas.Count); } // after adding all schemas, we need to tell the ViewRegistry to add all component templates linked to the current set of schemas // this will trigger the ModelRegistry to create merged models in case a CT is linked to multiple schemas UsingItemsFilterData filter = new UsingItemsFilterData() { ItemTypes = new[] { ItemType.ComponentTemplate } }; foreach (var schema in convertibleSchemas.Where(s => s.Purpose == SchemaPurpose.Component)) { var associatedCTs = Client.GetList(schema.Id, filter).Cast <ComponentTemplateData>(); associatedCTs?.Select(s => ViewRegistry.GetViewModelDefinition(s.Id)); // we don't care about the return value but we want this } }
public static IList <T> GetAllUsages <T>(this IdentifiableObjectData item, Expression <Func <T, bool> > filterPredicate = null, UsingItemsFilterData filter = null) where T : IdentifiableObjectData { Logger.Debug("Loading usages of {0} for {1}", typeof(T).Name, item.Title); string filename = string.Format("{0} - {1} - {2}.txt", item.GetType().Name, typeof(T).Name, item.Title); var subFolder = "Usages"; var items = FileCache.LoadFromFile <IList <T> >(filename, subFolder); if (items == null) { if (filter == null) { filter = new UsingItemsFilterData { ItemTypes = new[] { ItemTypeResolver.GetItemType(typeof(T)) }, IncludedVersions = VersionCondition.OnlyLatestAndCheckedOutVersions, IncludeLocalCopies = false, BaseColumns = ListBaseColumns.Extended }; } items = TridionCoreServiceFactory.GetList <T>(item.Id, filter); Logger.Debug("Found {0} {1} for {2}", items.Count, typeof(T).Name, item.Title); FileCache.SaveToFile(filename, items, subFolder); } else { Logger.Debug("Loading usages of {0} for {1} from cache", typeof(T).Name, item.Title); } if (filterPredicate != null) { items = items.AsQueryable().Where(filterPredicate).ToList(); } return(items); }
public static bool listComponent(CoreServiceClient client, string path) { try { client.ClientCredentials.Windows.ClientCredential.Domain = ConfigurationSettings.AppSettings["Domain"]; client.ClientCredentials.Windows.ClientCredential.UserName = ConfigurationSettings.AppSettings["User"]; client.ClientCredentials.Windows.ClientCredential.Password = ConfigurationSettings.AppSettings["PWD"];// XElement elist = client.GetListXml(ConfigurationSettings.AppSettings["FolderTCM_ID"].ToString(), new OrganizationalItemItemsFilterData { ItemTypes = new[] { ItemType.Component }, Recursive = true, BaseColumns = ListBaseColumns.Default }); List <Result> lstRS = new List <Result>(); System.Data.DataTable dt = new System.Data.DataTable(); Stopwatch watch = new Stopwatch(); TimeSpan timeSpan = new TimeSpan(); watch.Start(); IEnumerable <XElement> elist1 = (from el in elist.Elements() //where (string)el.Attribute("IsPublished").Value == "true" select el); foreach (var x in elist1.ToArray()) { Result rs = new Result(); try { UsingItemsFilterData usingItemsFilterData = new UsingItemsFilterData { ItemTypes = new[] { ItemType.PublicationTarget, ItemType.Publication, ItemType.Component, ItemType.Page, ItemType.Keyword } , IncludeLocalCopies = true }; XElement usingXML = client.GetListXml(x.FirstAttribute.Value, usingItemsFilterData); #region Comment //BluePrintChainFilterData filter = new BluePrintChainFilterData(); //filter.Direction = BluePrintChainDirection.Down; //XElement result = client.GetListXml(x.FirstAttribute.Value, filter); //IEnumerable<XElement> result1 = (from el in result.Elements() // //where (string)el.Attribute("IsPublished").Value == "true" // select el); //StringBuilder sbBlueChain = new StringBuilder(); //StringBuilder sbLocal = new StringBuilder(); //foreach (var z in result1.ToArray()) //{ // sbBlueChain.Append(z.FirstAttribute.Value + " ; "); // if (z.Attribute("FromPub") != null) // { // sbLocal.Append(z.Attribute("FromPub").Value + " ; "); // } //} //rs.Blueprint_Chain_TCM_ID = sbBlueChain.ToString(); // rs.LocalCopy = sbLocal.ToString(); #endregion IEnumerable <XElement> usingXML1 = (from el in usingXML.Elements() select el); StringBuilder sbComponent = new StringBuilder(); StringBuilder sbKeyword = new StringBuilder(); StringBuilder sbPage = new StringBuilder(); StringBuilder sbPublicationNameWL = new StringBuilder(); StringBuilder sbPublicationNameWOL = new StringBuilder(); if (usingXML1.ToArray().Count() < 2 && usingXML1.ToArray().Count() != 0) { rs.TCM_ID = x.FirstAttribute.Value; rs.Title = x.Attribute("Title").Value; foreach (var y in usingXML1.ToArray()) { if (y.Attribute("Type").Value == "16" && y.Attribute("CommentToken") != null) { sbComponent.Append(y.FirstAttribute.Value + " ; "); sbPublicationNameWL.Append(y.Attribute("Publication").Value + " ; "); } if (y.Attribute("Type").Value == "16" && y.Attribute("CommentToken") == null) { sbComponent.Append(y.FirstAttribute.Value + " ; "); sbPublicationNameWOL.Append(y.Attribute("Publication").Value + " ; "); #region Demote //Demote Logic //string strPubID = string.Empty; //strPubID = lookUpPublication(y.Attribute("Publication").Value); //OperationInstruction instruction = new OperationInstruction { Mode = OperationMode.FailOnError }; //OperationResultDataOfRepositoryLocalObjectData result = client.Promote(x.FirstAttribute.Value, strPubID, instruction, new ReadOptions()); //if (result.ValidationWarnings.Length > 0) //{ // Console.WriteLine("Validation warnings:"); // foreach (ValidationWarningData warning in result.ValidationWarnings) // { // Console.WriteLine("\tMessage:{0} | Source:{1} | Location:{2}", // warning.Message, warning.Source, warning.Location); // } //} #endregion } //if (y.Attribute("Type").Value == "64") //{ // sbPage.Append(y.FirstAttribute.Value + " ; "); // sbPublicationNameWL.Append(y.Attribute("Publication").Value + " ; "); //} } rs.Using_Component_Tcm_ID = (string.IsNullOrEmpty(sbComponent.ToString())) ? "NA" : sbComponent.ToString(); rs.using_Page_tcm_id = (string.IsNullOrEmpty(sbPage.ToString())) ? "NA" : sbPage.ToString(); // rs.using_keyword_tcm_id = (string.IsNullOrEmpty(sbKeyword.ToString())) ? "NA" : sbKeyword.ToString(); rs.Using_Publication_name_With_Local = (string.IsNullOrEmpty(sbPublicationNameWL.ToString())) ? "NA" : sbPublicationNameWL.ToString(); rs.Using_Publication_name_Without_Local = (string.IsNullOrEmpty(sbPublicationNameWOL.ToString())) ? "NA" : sbPublicationNameWOL.ToString(); if (rs.TCM_ID != null) { lstRS.Add(rs); rs = null; } } } catch (Exception ex) { ExcelUtility.WriteLog(ex, "elist1"); rs = null; } timeSpan = TimeSpan.FromSeconds(Convert.ToInt32(watch.Elapsed.TotalSeconds)); Console.Write(timeSpan.ToString("c")); Console.Write('\r'); } lstRS = lstRS.AsEnumerable().ToList(); dt = ToDataTable(lstRS); dt.TableName = "REPORT"; ExcelUtility.WriteDataTableToExcel(dt, @"Report.xlsx"); Console.WriteLine("Total Records Are " + lstRS.Count() + System.Environment.NewLine); Console.WriteLine("Total Time Taken " + timeSpan.Hours + ":" + timeSpan.Minutes + ":" + timeSpan.Seconds + ":" + timeSpan.Milliseconds); //var x= elist.Descendants().Count(); return(true); } catch (Exception ex) { ExcelUtility.WriteLog(ex, "MainFunction"); return(false); } }
public static int GetAllUsageCount <T>(this IdentifiableObjectData item, Expression <Func <T, bool> > filterPredicate = null, UsingItemsFilterData filter = null) where T : IdentifiableObjectData { return(item.GetAllUsages <T>(filterPredicate: filterPredicate).Count); }
private static List<string> GetUsingItems(string tcmItem) { UsingItemsFilterData filter = new UsingItemsFilterData(); filter.IncludedVersions = VersionCondition.AllVersions; filter.BaseColumns = ListBaseColumns.Id; List<string> items = Client.GetListXml(tcmItem, filter).ToList().Select(x => x.TcmId).ToList(); return items; }
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..."); } }
//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> GetArticlesForSource(Source source) { List<Article> result = new List<Article>(); UsingItemsFilterData filter = new UsingItemsFilterData { ItemTypes = new[] { ItemType.Component } }; foreach (var xNode in _client.GetListXml(source.Id, filter).Nodes()) { var node = (XElement) xNode; result.Add(new Article((ComponentData)_client.Read(node.Attribute("ID").Value, _readOptions), _client)); } return result; }
public string GetPageIdForArticle(Article article) { UsingItemsFilterData filter = new UsingItemsFilterData { ItemTypes = new[] { ItemType.Page } }; foreach (var xNode in _client.GetListXml(article.Id, filter).Nodes()) { var node = (XElement) xNode; return node.Attribute("ID").Value; } return null; }
public override void Process(ServiceProcess process, object arguments) { PagePublisherParameters parameters = (PagePublisherParameters)arguments; process.SetCompletePercentage(0); process.SetStatus("Initializing"); using (var coreService = Client.GetCoreService()) { _pagePublisherData = new PagePublisherData(); string[] pageIds; if (parameters.LocationId.EndsWith("-1") || parameters.LocationId.EndsWith("-4")) // Publication or Structure Group { // get a list of the items from the core service ItemsFilterData filter = GetFilter(parameters); XElement listXml = coreService.GetListXml(parameters.LocationId, filter); // Get the page id's that will be published pageIds = GetPageIds(listXml); } else // Component { var readOptions = new ReadOptions(); // Get the current component var componentData = (ComponentData)coreService.Read(parameters.LocationId, readOptions); // Get the initial set of using items var filter = new UsingItemsFilterData { BaseColumns = ListBaseColumns.Default, IncludedVersions = VersionCondition.OnlyLatestAndCheckedOutVersions, IncludeLocalCopies = true, ItemTypes = new[] { ItemType.Component, ItemType.Page } }; var usingItemsXml = coreService.GetListXml(parameters.LocationId, filter); var pageIdsList = GetPageIds(usingItemsXml).ToList(); var level = 1; // We set the depth limit to 10, just so that we will never get an infinite loop in case // component 1 is included within a component 2 that is included within component 1. int depthLimit = 10; var componentIdsList = GetComponentIds(usingItemsXml).ToList(); var targets = componentIdsList.Distinct(StringComparer.InvariantCultureIgnoreCase); while (level <= depthLimit && targets.Count() > 0) { var nextTargets = new HashSet<string>(); foreach (var targetId in targets) { usingItemsXml = coreService.GetListXml(targetId, filter); pageIdsList.AddRange(GetPageIds(usingItemsXml)); foreach (var e in usingItemsXml.Elements()) { nextTargets.Add(e.Attribute("ID").Value); } } targets = nextTargets.ToList(); level++; } pageIds = pageIdsList.ToArray(); } int batchSize = 5; int currentBatch = 0; // Publish pages try { double ratio = pageIds.Count() /batchSize; double percentage = 100/ratio; double currperc = 0; while (currentBatch * batchSize < pageIds.Count()) { string[] nextBatch = pageIds.Skip(currentBatch * batchSize) .Take(batchSize).ToArray(); coreService.Publish(nextBatch, GetPublishInstructionData(parameters), parameters.TargetUri, parameters.Priority, new ReadOptions()); currentBatch++; currperc += percentage; if (currperc >= 1) { process.IncrementCompletePercentage(); currperc = 0; } } _pagePublisherData.SuccessMessage = string.Format("{0} Pages published successfully", pageIds.Length.ToString()); } catch (Exception ex) { //process.Complete(string.Format("Failed to publish, reason: {0}", ex.Message)); _pagePublisherData.FailedMessage = string.Format("Page publishing failed, reason {0}", ex.Message); } process.Complete("done"); } }
public bool IsArticleInPage(Article article) { UsingItemsFilterData filter = new UsingItemsFilterData { ItemTypes = new[] { ItemType.Page } }; return _client.GetListXml(article.Id, filter).Nodes().Any(); }