I am trying to consume Core Services through the Event System. The Event System is a Class library as expected.
I added the content nodes from Tridion.ContentManager.CoreService.Client.dll.config
to app.config. No matter which endpoint I am try to use I always get an error such as the following (which happens when trying to initialize SessionAwareCoreServiceClient
):
Could not find endpoint element with name "" and contract
I would like to note I am using Core Services through a console application without any issues. Are there any other ways to consume Core Services through the Event System (class library type) or is something else causing this error?
Well, as you advised I was started to use TOM.NET API for this purpose but can't figure out why code below doesn't work. Trying to change component metadata date fields...
public class Events:TcmExtension
{
public Events()
{
ImplementedEvents();
}
private void ImplementedEvents()
{
//Here should be subscription for used events
EventSystem.Subscribe<Component, CheckInEventArgs>(OnComponentCheckedPre, EventPhases.Initiated);
EventSystem.Subscribe<Component, PublishEventArgs>(ComponentPublished, EventPhases.Processed);
EventSystem.Subscribe<StructureGroup, PublishEventArgs>(StructureGroupPublished, EventPhases.Processed);
}
/// <summary>
/// Edit news metadata DateTime values and remove checked button for modify component metadata from content in case if editor checked in this box
/// </summary>
/// <param name="component"></param>
/// <param name="arg"></param>
/// <param name="phase"></param>
public void OnComponentCheckedPre(Component component, CheckInEventArgs arg, EventPhases phase)
{
if (component.Schema.Title.ToLower().Equals("ks News Private") || component.Schema.Title.ToLower().Equals("ks News Business"))
{
EditNewsComponent(component);
}
}
private void EditNewsComponent(Component component)
{
try
{
ItemFields componentContentItemFields = new ItemFields(component.Content, component.Schema);
ItemFields componentMetadataItemFields = new ItemFields(component.Metadata, component.MetadataSchema);
WriteEventLog("comp metadata xml elements before :" + componentMetadataItemFields.ToXml().InnerXml );
if (componentMetadataItemFields.Contains("Created"))
{
DateField createdMetaField = (DateField)componentMetadataItemFields["Created"];
if (createdMetaField.Value == DateTime.MinValue)
{
createdMetaField.Value = component.RevisionDate;
}
}
if(componentMetadataItemFields.Contains("Modified"))
{
DateField modifiedMetaField = (DateField)componentMetadataItemFields["Modified"];
if (modifiedMetaField.Value == DateTime.MinValue)
{
modifiedMetaField.Value = DateTime.Now;
}
}
if (componentContentItemFields.Contains("SettModified"))
{
DateField modifiedMetaField = (DateField)componentMetadataItemFields["Modified"];
modifiedMetaField.Value = DateTime.Now;
}
if (componentMetadataItemFields.Contains("ValidTo"))
{
DateField validToMetaField = (DateField)componentMetadataItemFields["ValidTo"];
if (validToMetaField.Value == DateTime.MinValue)
{
validToMetaField.Value = DateTime.Now.AddYears(100);
}
}
WriteEventLog("metadata item fields value after checking :" + componentMetadataItemFields.ToXml().InnerXml);
((TextField)componentContentItemFields["Ingress"]).Value = "ingress test event system";
component.Content = componentContentItemFields.ToXml();
// component.Content.InnerXml = componentContentItemFields.ToXml().InnerXml;
WriteEventLog("component content after to xml: " + component.Content.InnerXml);
component.Metadata= componentMetadataItemFields.ToXml();
WriteEventLog("component metadata xml: " + component.Metadata.InnerXml);
//Changes visible in log files. Not in Tridion
}
catch (Exception ex)
{
WriteEventLog("Unable to edit FIKS component " + component.Id + ". Error:" + ex.Message);
}
}
I have seen the changes in logs but not in Tridion component. Other events triggered and worked as intended. Old event system uninstall as suggested. Network Service is only one impersonate user visible through SDL Tridion Management console application.