sections in the article
About this extension setting
A commonly asked question about customization is about an extension setting for ignoring entity update events for certain fields. This article explains how to implement and configure the FIELDS_TO_IGNORE extension setting which can be used for ignoring entity update events for certain fields.
Source code
Below is the source code for implementing the FIELDS_TO_IGNORE extension setting in an entity listener extension. Feel free to modify this code to your liking, this entity listener is bare-bones and only focuses on the EntityUpdated method for highlighting the extension setting functionality. Typically your entity listener will contain more logic.
using inRiver.Remoting.Extension.Interface;
using System.Collections.Generic;
using System.Linq;
using inRiver.Remoting.Extension;
using inRiver.Remoting.Objects;
using inRiver.Remoting.Log;
namespace MyEntityListener01
{
public class MyEntityListener : IEntityListener
{
/* In the inRiverContext you will find the authenticated Remoting API, settings, logging, etc...*/
public inRiverContext Context { get; set; }
/* Define your default settings for the Extension here, <key> , <defaultValue> */
public Dictionary<string, string> DefaultSettings => new Dictionary<string, string>();
/* Initialize variables */
public string fieldsToIgnoreString = string.Empty;
public string[] fieldsToIgnoreArray = new string[0];
public void EntityUpdated(int entityId, string[] fields)
{
/* Retrieve inputted values for Fields_To_Ignore setting */
fieldsToIgnoreString = Context.Settings["FIELDS_TO_IGNORE"];
/* Check to see if the Fields_To_Ignore extension setting is used */
if (string.IsNullOrEmpty(fieldsToIgnoreString))
{
/* Fields_To_Ignore is not used, no field update events will be ignored
* Insert Logic Here */
}
else
{
/* Store the ignored fields into an array so they can be compared with the updated fields */
string[] fieldsToIgnoreArray = fieldsToIgnoreString.Split(',').Select(sValue => sValue.Trim()).ToArray();
/* Check to see if the changes on the updated fields are ignored or accepted. */
foreach (string field in fields)
{
if (fieldsToIgnoreArray.Contains(field))
{
/* Ignore, Skip, Do Nothing, ect...
* Insert Logic Here */
Context.Log(LogLevel.Information, $"The field update for " + field + " on entity with id " + entityId + " was ignored.");
}
else
{
/* Make Another Update, Send Update, Take Action, ect...
* Insert Logic Here */
Context.Log(LogLevel.Information, $"The field update for " + field + " on entity with id " + entityId + " was accepted.");
}
}
}
}
public void EntityCommentAdded(int entityId, int commentId) { }
public void EntityCreated(int entityId) { }
public void EntityDeleted(Entity deletedEntity) { }
public void EntityFieldSetUpdated(int entityId, string fieldSetId) { }
public void EntityLocked(int entityId) { }
public void EntitySpecificationFieldAdded(int entityId, string fieldName) { }
public void EntitySpecificationFieldUpdated(int entityId, string fieldName) { }
public void EntityUnlocked(int entityId) { }
public string Test()
{
/* Check to see if the Fields_To_Ignore extension setting is used */
if (string.IsNullOrEmpty(fieldsToIgnoreString))
{
return "*Test* fields to ignore setting is not use or configured.";
}
else
{
return "*Test* you should see your fields to ignore string here: " + fieldsToIgnoreString;
}
}
}
}
Configuring the fields to ignore extension setting
In the extension settings section for your Entity Listener, you can add a new extension setting with the following Key: FIELDS_TO_IGNORE
The value portion of this setting will contain the FieldTypeId for the field updates that you wish to ignore. If you are entering multiple FieldTypeId(s) they must be comma-separated.
Note: Each time this extension setting is updated, make sure to click Reload Service Settings to make sure that the new values are loaded.
Now that you have the extension setting configured, the entity listener will check if a field update event should be ignored. Details can be found in the server logs.
Further reading
Event driven Extensions (Listeners)
Server extensions vs ChannelListeners
Comments
0 comments
Please sign in to leave a comment.