public void AddReversedFieldToPackageTest() { var templateId = "/webdav/04%20Web/Building%20Blocks/System/Templates/Test/TestCT-ReversedString.tctcmp"; var itemId = "/webdav/04%20Web/Building%20Blocks/Test/PerSchema/Dummy/GeneratedTestData_1.xml"; var client = new SessionAwareCoreServiceClient("wsHttp_2013"); client.ClientCredentials.Windows.ClientCredential.Domain = ConfigurationManager.AppSettings.Get("domain"); client.ClientCredentials.Windows.ClientCredential.Password = ConfigurationManager.AppSettings.Get("password"); client.ClientCredentials.Windows.ClientCredential.UserName = ConfigurationManager.AppSettings.Get("username"); var publishInstruction = new PublishInstructionData { RenderInstruction = new RenderInstructionData { RenderMode = RenderMode.PreviewDynamic }, ResolveInstruction = new ResolveInstructionData { StructureResolveOption = StructureResolveOption.OnlyItems } }; try { client.RenderItem(itemId, templateId, publishInstruction, ConfigurationManager.AppSettings.Get("publicationTargetId")); } catch (Exception ex) { Assert.Fail("Rendering {0} with {1} failed: {2}", templateId, itemId, ex.Message); } }
/// <summary> /// GetPublishInfoData - Creates a PublishInfoData which is used to obtain a list of publishable items. /// </summary> /// <param name="parameters">PagePublisherParameters</param> /// <returns>GetPublishInfoData object</returns> private PublishInstructionData GetPublishInstructionData(PagePublisherParameters parameters) { ResolveInstructionData resolveInstruction = new ResolveInstructionData(); resolveInstruction.IncludeChildPublications = parameters.PublishChildren; resolveInstruction.IncludeComponentLinks = parameters.IncludeComponentLinks ? true : false; resolveInstruction.StructureResolveOption = parameters.IncludeStructureGroups ? StructureResolveOption.ItemsAndStructure : StructureResolveOption.OnlyItems; resolveInstruction.IncludeWorkflow = parameters.IncludeWorkflow ? true : false; resolveInstruction.Purpose = parameters.Republish ? ResolvePurpose.RePublish : ResolvePurpose.Publish; RenderInstructionData renderInstruction = new RenderInstructionData(); renderInstruction.RenderMode = RenderMode.Publish; PublishInstructionData instruction = new PublishInstructionData(); instruction.RollbackOnFailure = true; instruction.MaximumNumberOfRenderFailures = 1; instruction.ResolveInstruction = resolveInstruction; instruction.RenderInstruction = renderInstruction; if (!string.IsNullOrEmpty(parameters.SchedulePublish)) { instruction.StartAt = DateTime.Parse(parameters.SchedulePublish); } return(instruction); }
/// <summary> /// This method is used to Publish Item to Preview environment /// </summary> protected override void Execute() { PublishInstructionData publishInstractionData = new PublishInstructionData(); publishInstractionData.RenderInstruction = new RenderInstructionData(); publishInstractionData.ResolveInstruction = new ResolveInstructionData(); publishInstractionData.ResolveInstruction.IncludeWorkflow = true; publishInstractionData.ResolveInstruction.IncludeChildPublications = false; List <string> itemToPublish = new List <string>(); String[] targets = Utility.GetPublishingTarget("Preview Publication Target"); String[] PublishTo = Utility.GetPublishingTo(); int length = PublishTo.Length; Logger.Write(string.Format("length: {0}", length), "Workflow", LoggingCategory.General, TraceEventType.Information); ActivityInstanceData activityInstance = ActivityInstance; foreach (WorkItemData wid in activityInstance.WorkItems) { if (length != 0 && PublishTo[0].ToString() != "All") { for (int counter = 0; counter < length; counter++) { string comp = wid.Subject.IdRef; int index = comp.IndexOf('-'); string sub1 = comp.Substring(index, comp.Length - index); comp = @"tcm:" + PublishTo[counter].ToString() + sub1; Logger.Write(string.Format("component ID : {0}", comp), "Workflow", LoggingCategory.General, TraceEventType.Information); itemToPublish.Add(comp); } } else { publishInstractionData.ResolveInstruction.IncludeChildPublications = true; itemToPublish.Add(wid.Subject.IdRef); } } PublishTransactionData[] publishTransactionData = CoreServiceClient.Publish(itemToPublish.ToArray <String>(), publishInstractionData, targets, PublishPriority.High, null); if (ProcessInstance.Variables.ContainsKey("PublishTransaction")) { ProcessInstance.Variables["PublishTransaction"] = publishTransactionData[0].Id; } else { ProcessInstance.Variables.Add("PublishTransaction", publishTransactionData[0].Id); } CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData { Message = "Publish to Preview Queued: Finished Activity" }, null); Logger.Write(string.Format("Message: {0}", "Publish to Preview Queued: Finished Activity"), "Workflow", LoggingCategory.General, TraceEventType.Information); }
protected override void Execute() { PublishInstructionData publishInstruction = new PublishInstructionData(); publishInstruction.ResolveInstruction = new ResolveInstructionData(); publishInstruction.RenderInstruction = new RenderInstructionData(); //Needed for publishing workflow revision/version publishInstruction.ResolveInstruction.IncludeWorkflow = true; TrusteeData lastPerformer = GetFirstManualActivityPerformer(); ActivityInstanceData activityInstance = ActivityInstance; Logger.Write(string.Format("lastPerformer: {0}", lastPerformer.Title), "Workflow", LoggingCategory.General, TraceEventType.Information); if (Utility.IsMailSendOptionTrue(activityInstance.Title)) { Logger.Write(string.Format("Mail Send Option: {0}", "True"), "Workflow", LoggingCategory.General, TraceEventType.Information); try { SmtpClient client = Utility.SMTPClientConfiguration(); MailMessage mail = Utility.WorkflowMailMessageConfiguration(ActivityInstance.Title.ToString(), null, lastPerformer.Title); client.Send(mail); Logger.Write(string.Format("Mail : {0}", mail.Body.ToString()), "Workflow", LoggingCategory.General, TraceEventType.Information); Logger.Write(string.Format("ActivityInstance.Title : {0}", "Mail Sent"), "Workflow", LoggingCategory.General, TraceEventType.Information); } catch (Exception ex) { Logger.Write(string.Format("ActivityInstance.Title : {0}", ex.Message.ToString()), "Workflow", LoggingCategory.General, TraceEventType.Information); } } if (Utility.IsPublishedToPreviewTrue()) { // Retrieving the Publication Target and Publish Transaction if (ProcessInstance.Variables.ContainsKey("PublishTransaction")) { string publishTransactionId = ProcessInstance.Variables["PublishTransaction"]; // Undo Publish Transaction CoreServiceClient.UndoPublishTransaction(publishTransactionId, QueueMessagePriority.Normal, null); } } // Finish the Activity ActivityFinishData finishData = new ActivityFinishData() { Message = "The Item " + activityInstance.WorkItems.FirstOrDefault().ToString() + " has been rejected and reassigned to " + lastPerformer.Title, NextAssignee = new LinkToTrusteeData() { IdRef = lastPerformer.Id } }; CoreServiceClient.FinishActivity(activityInstance.Id, finishData, null); }
/// <summary> /// Publishes the page. /// </summary> /// <param name="tcm">The TCM.</param> /// <param name="page">The page.</param> /// <param name="publishPriority">The publish priority.</param> /// <param name="publishTargets">The publish targets.</param> /// <returns></returns> /// <exception cref="System.ArgumentException"> /// Could not find page: + tcm or Skipped publishing, no suitable publish targets available for publication: + pubId /// </exception> /// <exception cref="System.Exception">Skipped publishing, no suitable publish targets configured.</exception> private string PublishPage(string tcm, PageData page, string publishPriority, string publishTargets) { if (page == null) { throw new ArgumentException("Could not find page: " + tcm); } string pubId = page.LocationInfo.ContextRepository.IdRef; List <string> listPublishTargetNames = publishTargets.ToLowerInvariant().Split(',').Select(p => p.Trim()).ToList(); List <KeyValuePair <string, string> > targets = this.TargetTypesForPublication(pubId); if (targets == null) { throw new ArgumentException("Skipped publishing, no suitable publish targets available for publication: " + pubId); } var items = targets.Where(x => listPublishTargetNames.Contains(x.Value)).ToList(); if (items.Any()) { List <string> listPublishTargetIds = new List <string>(); foreach (var item in items) { listPublishTargetIds.Add(item.Key); } PublishInstructionData instruction = new PublishInstructionData { ResolveInstruction = new ResolveInstructionData { IncludeChildPublications = false }, RenderInstruction = new RenderInstructionData() }; this.Client.Publish( new[] { tcm }, instruction, listPublishTargetIds.ToArray(), this.GetPublishPriority(publishPriority), null); } else { throw new Exception("Skipped publishing, no suitable publish targets configured."); } string targetsPublished = string.Join(", ", items.Select(x => x.Value)); return(string.Format("Page '{0}' is published to: {1}", page.Title, targetsPublished)); }
public void Publish(string[] itemIds, string targetId) { RenderInstructionData renderInstruction = new RenderInstructionData(); ResolveInstructionData resolveInstruction = new ResolveInstructionData(); PublishInstructionData publishInstruction = new PublishInstructionData { DeployAt = DateTime.Now, MaximumNumberOfRenderFailures = 0, RenderInstruction = renderInstruction, ResolveInstruction = resolveInstruction, StartAt = DateTime.Now }; _client.PublishAsync(itemIds, publishInstruction, new[] { targetId }, PublishPriority.Normal, null); }
private void AssertItemRendersWithoutException(IdentifiableObjectData item, IdentifiableObjectData template) { string testPublicationId = TestContext.Properties["TestPublicationId"].ToString(); string localisedItemId = Client.GetTcmUri(item.Id, testPublicationId, null); string localisedTemplateId = Client.GetTcmUri(template.Id, testPublicationId, null); // We check if the template exists at this publication level as the schema where used query // might give us templates that might only exist elsewhere in the blueprint if (Client.IsExistingObject(localisedTemplateId) && !this.renderedTemplates.Contains(localisedTemplateId)) { try { this.renderedTemplates.Add(localisedTemplateId); RenderedItemData renderedItem = new RenderedItemData(); RenderInstructionData renderInstruction = new RenderInstructionData(); renderInstruction.RenderMode = RenderMode.PreviewStatic; PublishInstructionData previewInstruction = new PublishInstructionData(); ResolveInstructionData resolveInstruction = new ResolveInstructionData(); previewInstruction.RenderInstruction = renderInstruction; previewInstruction.ResolveInstruction = resolveInstruction; stopwatch.Restart(); renderedItem = Client.RenderItem(localisedItemId, localisedTemplateId, previewInstruction, "tcm:0-1-65537"); long timeToRender = stopwatch.ElapsedMilliseconds; if (renderedItem.Content != null) { string renderedContent = System.Text.Encoding.Default.GetString(renderedItem.Content); this.LogMessage(String.Format("Rendering with template \"{0}\" ({1}) succeeded and took {2} milliseconds.", template.Title, localisedTemplateId, timeToRender)); Assert.IsNotNull(renderedContent); } else { this.LogMessage(String.Format("ALERT: Rendering with template \"{0}\" ({1}) resulted in null content and took {2} milliseconds.", template.Title, localisedTemplateId, timeToRender)); } } catch (System.ServiceModel.FaultException ex) { string failMessage = String.Format("TEST FAILED! Failed when rendering item {0} ({1}) with template {2} ({3}) {4}. Exception: {5}", item.Id, item.Title, template.Id, template.Title, Environment.NewLine + Environment.NewLine, ex.Message); this.LogMessage(failMessage); Assert.Fail(failMessage); } } }
private string RenderItem(string itemId, string templateId) { try { this.OpenSession(); ResolveInstructionData resolveInstruction = new ResolveInstructionData() { IncludeWorkflow = true, IncludeComponentLinks = false, IncludeChildPublications = false, Purpose = ResolvePurpose.Publish, StructureResolveOption = StructureResolveOption.OnlyItems }; RenderInstructionData renderInstruction = new RenderInstructionData() { RenderMode = RenderMode.PreviewDynamic }; PublishInstructionData publishInstruction = new PublishInstructionData() { MaximumNumberOfRenderFailures = 0, ResolveInstruction = resolveInstruction, RenderInstruction = renderInstruction, StartAt = DateTime.UtcNow, DeployAt = DateTime.MinValue }; RenderedItemData result = session.RenderItem(itemId, templateId, publishInstruction, TcmUri.UriNull.ToString()); if (result.Content != null && result.Content.Length > 0) { string contents = System.Text.Encoding.UTF8.GetString(result.Content); return(contents); } } catch (Exception ex) { return(null); } finally { this.CloseSession(); } return(""); }
public static void Publish(string targetTcmId, string targets, ICoreServiceFrameworkContext coreService) { var pubData = new PublishInstructionData { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = false }, RenderInstruction = new RenderInstructionData() }; //get the component info var component = coreService.Client.Read(targetTcmId, null) as ComponentData; var componentId = component.Id; //strip out the version number if it contains onercmd if (component.Id.Contains("v")) { componentId = component.Id.Substring(0, component.Id.LastIndexOf('-')); } //publish to the target supplied into this method on low priority try { string[] pubid = ConfigurationManager.AppSettings["PublicationID"].ToString().Split(','); string[] pubtargets = targets.ToString().Split(','); foreach (var item in pubid) { string componentIdTcm = componentId.Substring(componentId.IndexOf("tcm:"), componentId.IndexOf("-")); string publicationid = "tcm:" + item; foreach (var target in pubtargets) { coreService.Client.Publish(new[] { componentId.Replace(componentIdTcm, publicationid) }, pubData, new[] { target.ToString() }, PublishPriority.High, null); } } } catch (Exception ex) { } }
protected override void Execute() { PublishInstructionData publishInstruction = new PublishInstructionData(); publishInstruction.ResolveInstruction = new ResolveInstructionData(); publishInstruction.RenderInstruction = new RenderInstructionData(); //Needed for publishing workflow revision/version publishInstruction.ResolveInstruction.IncludeWorkflow = true; ActivityInstanceData activityInstance = ActivityInstance; IList <String> itemsToPublishList = new List <String>(); //Staging publication target URI String[] targets = Utility.GetPublishingTarget("Preview Publication Target"); foreach (WorkItemData wid in activityInstance.WorkItems) { int value = Convert.ToInt32(Enum.Parse(typeof(ItemType), "VirtualFolder")); if (wid.Subject.IdRef.EndsWith(value.ToString())) { itemsToPublishList.Add(wid.Subject.IdRef); } } //PublishTransactionData requires reference to System.ServiceModel PublishTransactionData[] publishTransactions = CoreServiceClient.Publish(itemsToPublishList.ToArray <String>(), publishInstruction, targets, PublishPriority.Normal, null); //Store the publish transaction id so that we can undo if needed! if (ProcessInstance.Variables.ContainsKey("PublishTransaction")) { ProcessInstance.Variables["PublishTransaction"] = publishTransactions[0].Id; } else { ProcessInstance.Variables.Add("PublishTransaction", publishTransactions[0].Id); } CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData { Message = "Publish to Staging Queued: Finished Activity" }, null); }
public static void Publish(this IdentifiableObjectData objectData, string[] purpose, PublishPriority prio = PublishPriority.Low, DateTime?StartAt = null) { var pubInst = new PublishInstructionData() { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = false, Purpose = ResolvePurpose.Publish, StructureResolveOption = StructureResolveOption.OnlyItems }, RenderInstruction = new RenderInstructionData(), MaximumNumberOfRenderFailures = 100, RollbackOnFailure = false }; if (StartAt.HasValue) { pubInst.StartAt = StartAt; } Wrapper.Instance.Publish(new string[] { objectData.Id.ToString() }, pubInst, purpose, PublishPriority.Low, new ReadOptions()); }
public string PublishItems(PublishUnPublishInfoData IDs) { try { var pubInstruction = new PublishInstructionData() { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = false }, RenderInstruction = new RenderInstructionData() }; PublishTransactionData[] result = null; var tfilter = new TargetTypesFilterData(); var allPublicationTargets = Client.GetSystemWideList(tfilter); if (allPublicationTargets == null) { throw new ArgumentNullException(nameof(allPublicationTargets)); } foreach (var pubdata in IDs.IDs) { var target = allPublicationTargets.Where(x => x.Title == pubdata.Target).Select(x => x.Id).ToList(); if (target.Any()) { result = Client.Publish(new[] { pubdata.Id }, pubInstruction, new[] { target[0] }, PublishPriority.Normal, null); if (result == null) { throw new ArgumentNullException(nameof(result)); } } } return("Item send to Publish"); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
//TODO: //public static SessionAwareCoreServiceClient CreateCoreServiceClient(bool isSessionAware = false) //{ // if (!isSessionAware) // bool.TryParse(ConfigurationManager.AppSettings["isSessionAware"], out isSessionAware); // return CreateCoreServiceSession(isSessionAware).CoreServiceSessionAwareClient; //} public static PublishTransactionData[] Publish(string [] itemIds, string[] targets, PublishInstructionData publishInstruction = null, PublishPriority priority = PublishPriority.Normal, ReadOptions readOptions = null) { PublishTransactionData[] obj = null; CreateCoreServiceClient().Using(client => { try { if (readOptions == null) { readOptions = new ReadOptions { LoadFlags = LoadFlags.Expanded } } ;; if (publishInstruction == null) { publishInstruction = new PublishInstructionData { } } ;; if (readOptions == null) { readOptions = new ReadOptions { LoadFlags = LoadFlags.Expanded } } ; obj = client.Publish(itemIds, publishInstruction, targets, priority, readOptions); } catch (Exception e) { obj = null; } }); return(obj); }
public ActionResult PublishAll(PublishViewModel model) { model.ServerErrorMessage = string.Empty; string targetTcmIdToPublish = "tcm:0-2-65538"; ReadOptions ro = new ReadOptions { LoadFlags = LoadFlags.None }; try { model.ComponentsList = (List <Component>)Session["ComponentsListPublish"]; PublishInstructionData instruction = new PublishInstructionData { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = false }, RenderInstruction = new RenderInstructionData() }; Client.Publish(model.ComponentsList.Select(x => x.Id).ToArray(), instruction, new[] { targetTcmIdToPublish }, PublishPriority.Normal, ro); model.IsSuccess = true; model.IsPublishCompleted = true; } catch (Exception ex) { log.Error("PublishAll - Post Method Error", ex); } this.SetModel <PublishViewModel>(model); return(Redirect("/Home/Publish?success=true")); }
public PublishTransactionData[] Publish(string[] ids, PublishInstructionData publishInstruction, string[] targets, PublishPriority?priority, ReadOptions readOptions) { return(_client.Publish(ids, publishInstruction, targets, priority, readOptions)); }
public static PublishTransactionData PublishItem <T>(this T item, string[] targets, PublishInstructionData publishInstruction = null, PublishPriority priority = PublishPriority.Normal, ReadOptions readOptions = null) where T : RepositoryLocalObjectData { if (item == null) { throw new ArgumentNullException(); } if (targets == null || !targets.Any()) { throw new ArgumentNullException(); } return(PublishItems(new string[] { item.Id }, targets, publishInstruction, priority, readOptions).FirstOrDefault()); }
/// <summary> /// GetPublishInfoData - Creates a PublishInfoData which is used to obtain a list of publishable items. /// </summary> /// <param name="parameters">PagePublisherParameters</param> /// <returns>GetPublishInfoData object</returns> private PublishInstructionData GetPublishInstructionData(PagePublisherParameters parameters) { ResolveInstructionData resolveInstruction = new ResolveInstructionData(); resolveInstruction.IncludeChildPublications = parameters.PublishChildren; resolveInstruction.IncludeComponentLinks = parameters.IncludeComponentLinks ? true : false; resolveInstruction.StructureResolveOption = parameters.IncludeStructureGroups ? StructureResolveOption.ItemsAndStructure : StructureResolveOption.OnlyItems; resolveInstruction.IncludeWorkflow = parameters.IncludeWorkflow ? true : false; resolveInstruction.Purpose = parameters.Republish ? ResolvePurpose.RePublish : ResolvePurpose.Publish; RenderInstructionData renderInstruction = new RenderInstructionData(); renderInstruction.RenderMode = RenderMode.PreviewDynamic; PublishInstructionData instruction = new PublishInstructionData(); instruction.RollbackOnFailure = true; instruction.MaximumNumberOfRenderFailures = 1; instruction.ResolveInstruction = resolveInstruction; instruction.RenderInstruction = renderInstruction; return instruction; }
public PublishTransactionData[] Publish(string[] itemUris, PublishInstructionData publishInstructionData, string[] destinationTargetUris, PublishPriority publishPriority, ReadOptions readOptions) { return(_client.Publish(itemUris, publishInstructionData, destinationTargetUris, publishPriority, readOptions)); }
/// <summary> /// GetPublishInfoData - Creates a PublishInfoData which is used to obtain a list of publishable items. /// </summary> /// <param name="parameters">PagePublisherParameters</param> /// <returns>GetPublishInfoData object</returns> private PublishInstructionData GetPublishInstructionData(PagePublisherParameters parameters) { ResolveInstructionData resolveInstruction = new ResolveInstructionData(); resolveInstruction.IncludeChildPublications = parameters.PublishChildren; resolveInstruction.IncludeComponentLinks = parameters.IncludeComponentLinks ? true : false; resolveInstruction.StructureResolveOption = parameters.IncludeStructureGroups ? StructureResolveOption.ItemsAndStructure : StructureResolveOption.OnlyItems; resolveInstruction.IncludeWorkflow = parameters.IncludeWorkflow ? true : false; resolveInstruction.Purpose = parameters.Republish ? ResolvePurpose.RePublish : ResolvePurpose.Publish; RenderInstructionData renderInstruction = new RenderInstructionData(); renderInstruction.RenderMode = RenderMode.Publish; PublishInstructionData instruction = new PublishInstructionData(); instruction.RollbackOnFailure = true; instruction.MaximumNumberOfRenderFailures = 1; instruction.ResolveInstruction = resolveInstruction; instruction.RenderInstruction = renderInstruction; if (!string.IsNullOrEmpty(parameters.SchedulePublish)) { instruction.StartAt = DateTime.Parse(parameters.SchedulePublish); } return instruction; }
public static PublishTransactionData[] PublishItems <T>(this T items, string[] targets, PublishInstructionData publishInstruction = null, PublishPriority priority = PublishPriority.Normal, ReadOptions readOptions = null) where T : IEnumerable <RepositoryLocalObjectData> { if (items == null || !items.Any()) { throw new ArgumentNullException(); } if (targets == null || !targets.Any()) { throw new ArgumentNullException(); } return(PublishItems(items.Select(x => x.Id).ToArray(), targets, publishInstruction, priority, readOptions)); }
public RenderedItemData RenderItem(string itemId, string templateId) { PublishInstructionData publishInstruction = new PublishInstructionData(); publishInstruction.RenderInstruction = new RenderInstructionData(); publishInstruction.ResolveInstruction = new ResolveInstructionData(); publishInstruction.RenderInstruction.RenderMode = RenderMode.PreviewDynamic; return this.Client.RenderItem(itemId, templateId, publishInstruction, null); }
public void Publish(string[] ids, PublishInstructionData instruction, string[] targets, PublishPriority priority) { this.Client.Publish(ids, instruction, targets, priority, new ReadOptions()); }
public static PublishTransactionData[] PublishItems(this string[] items, string[] targets, PublishInstructionData publishInstruction = null, PublishPriority priority = PublishPriority.Normal, ReadOptions readOptions = null) { if (items == null || !items.Any()) { throw new ArgumentNullException(); } if (targets == null || !targets.Any()) { throw new ArgumentNullException(); } return(TridionCoreServiceFactory.Publish(items, targets, publishInstruction, priority, readOptions)); }