blob: e78e0a19539b9f2f034bd67af3c8b61288dc12ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.Integration.Observables
{
public partial class Job
{
public event EventHandler LengthChanged;
protected override void RaisePropertyChanged(string propName)
{
base.RaisePropertyChanged(propName);
if (propName == nameof(Segments))
{
if (Segments != null)
{
Segments.CollectionChanged -= Segments_CollectionChanged;
Segments.CollectionChanged += Segments_CollectionChanged;
OnLengthChanged();
}
}
if (propName == nameof(InterSegmentLength) || propName == nameof(EnableInterSegment))
{
OnLengthChanged();
}
}
private void Segments_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
foreach (var segment in Segments)
{
segment.PropertyChanged += Segment_PropertyChanged;
}
OnLengthChanged();
}
private void Segment_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Segment.Length))
{
OnLengthChanged();
}
}
protected virtual void OnLengthChanged()
{
RaisePropertyChanged(nameof(Length));
LengthChanged?.Invoke(this, new EventArgs());
}
[NotMapped]
public double Length
{
get { return Segments.Sum(x => x.Length) + (EnableInterSegment ? (InterSegmentLength * (Segments.Count > 0 ? Segments.Count - 1 : Segments.Count)) : 0); }
}
}
}
|