Changes<TAdd, TUpdate>#

The edits to one record kind: records to add, partial updates, and ids to remove. Every SchedulingChanges starts with an empty instance for each record kind. Edits go into its lists.

Property of SchedulingChanges Type
Tasks Changes<TaskData, TaskUpdate>
Links Changes<LinkAdd, LinkUpdate>
Resources Changes<ResourceData, ResourceUpdate>
Assignments Changes<AssignmentData, AssignmentUpdate>

Declaration#

namespace Plen;

public sealed class Changes<TAdd, TUpdate> : IDeepCloneable<Changes<TAdd, TUpdate>>
    where TAdd : IDeepCloneable<TAdd>
    where TUpdate : IDeepCloneable<TUpdate>
Type parameter Description
TAdd The full record to add: TaskData, LinkAdd, ResourceData or AssignmentData.
TUpdate The partial update record: TaskUpdate, LinkUpdate, ResourceUpdate or AssignmentUpdate.

Both type arguments implement IDeepCloneable<T>, so DeepClone() can copy every record in the lists.

Constructors#

Changes()#

public Changes()

Creates an instance with all three lists empty.

Properties#

Property Type Default Description
Add List<TAdd> empty Records to add. The id of each record must not exist yet. A LinkAdd or AssignmentData without an id gets a generated one.
Update List<TUpdate> empty Partial updates. Each record names an existing id. Its Patch<T> fields keep, clear or set each value.
Remove List<Id> empty Ids of existing records to remove.
public List<TAdd> Add { get; set; }
public List<TUpdate> Update { get; set; }
public List<Id> Remove { get; set; }

Each entry is one operation. In ApplyReport, an operation's path is its group, its list and its index: tasks.add[0], links.remove[1], assignments.update[2]. An unknown id in Update or Remove, or an id in Add that already exists, rejects that operation. Removing a record also removes the records that depend on it, and the report's Effects lists them. For the order in which the lists run, see SchedulingChanges.

Methods#

DeepClone#

public Changes<TAdd, TUpdate> DeepClone()

Returns a copy with new lists. Each record in Add and Update is deep-copied. Remove holds the same Id values, which are immutable.

ToString#

public override string ToString()

Returns a readable rendering of Add, Update and Remove, for logging.

Example#

Add, update and remove tasks in one change set:

using Plen;

var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var data = new ProjectData
{
    Tasks =
    [
        new TaskData(1) { StartDate = monday, Duration = 2.0 },
        new TaskData(2) { StartDate = monday, Duration = 1.0 },
    ],
};

var project = new Project();
var solved = project.Solve(data, new SolveOptions());

var changes = new SchedulingChanges { BaselineId = solved.BaselineId };
changes.Tasks.Add.Add(new TaskData(3) { StartDate = monday, Duration = 4.0 });
changes.Tasks.Update.Add(new TaskUpdate(1) { Duration = 3.0 });
changes.Tasks.Remove.Add(2);

var report = project.Apply(changes);
foreach (var applied in report.Applied)
{
    Console.WriteLine(applied.Path); // tasks.remove[0], tasks.add[0], tasks.update[0]
}