VAF.Extensions.Community icon indicating copy to clipboard operation
VAF.Extensions.Community copied to clipboard

Pre-populating a Schedule can result in incorrect entries

Open CraigHawker opened this issue 3 years ago • 2 comments

Use the following configuration class structure:

[DataContract]
public class Configuration
	: ConfigurationBase
{
        [DataMember]
        [RecurringOperationConfiguration(VaultApplication.QueueId, "TaskTypeB")]
        public Schedule Schedule { get; set; } = new Schedule()
        {
            Enabled = true,
            Triggers = new List<Trigger>
                {
                    new DayOfMonthTrigger()
                    {
                        TriggerDays = new List<int> { 1 },
                        TriggerTimes = new List<TimeSpan>{ new TimeSpan(1, 0, 0) }
                    }
                }
        };
    }
}

When the application starts, the processor is scheduled for 1am on the first of the next month. This can be seen on the dashboard. Good.

Go into the configuration editor and set up a trigger for 2am on the second of the next month. When saved, note that both the original trigger and the new one are shown as valid in the dashboard. There is no way to remove the one that was created initially.

This seems to be related to this issue whereby Newtonsoft appends the list items rather than replacing them.

As we cannot control the deserialization directly (it is done outside of this library), we probably need a custom JsonConverter to handle this.

CraigHawker avatar Dec 02 '22 12:12 CraigHawker

Note: this issue only happens if the Schedule class is used directly. Using a Frequency instead is fine, as that already has a JsonConverter in place to control the deserialization.

CraigHawker avatar Dec 02 '22 12:12 CraigHawker

There should be a number of unit tests added around this to check that any changes do not adversely affect the overall deserialization process.

CraigHawker avatar Dec 02 '22 12:12 CraigHawker