/
IEvent.cs
147 lines (122 loc) · 3.17 KB
/
IEvent.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Runtime.Serialization;
namespace FarleyFile
{
public interface IEvent : IBaseMessage {}
[DataContract]
public class Identity : IComparable
{
[DataMember(Order = 1)]
public Guid Id { get; protected set; }
[DataMember(Order = 2)]
public int Tag { get; protected set; }
public bool IsEmpty
{
get { return Id == Guid.Empty; }
}
public static readonly Identity Empty = new Identity();
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
var identity = obj as Identity;
if (ReferenceEquals(identity, null))
{
return false;
}
return identity.Id.Equals(Id) && identity.Tag == Tag;
}
public override int GetHashCode()
{
unchecked
{
return (Id.GetHashCode()*397) ^ Tag;
}
}
public int CompareTo(object obj)
{
var id = obj as Identity;
if (id == null)
{
throw new ArgumentException("These types are not comparable");
}
if (Tag != id.Tag)
return Tag.CompareTo(id.Tag);
return Id.CompareTo(id.Id);
}
public static implicit operator Guid(Identity id)
{
return id.Id;
}
public override string ToString()
{
return string.Format("{0}({1})-{2}", GetType().Name.Replace("Id", ""), Tag, Id);
}
public static bool operator ==(Identity a, Identity b)
{
if (ReferenceEquals(a, null))
return ReferenceEquals(b, null);
return a.Equals(b);
}
public static bool operator !=(Identity a, Identity b)
{
if (ReferenceEquals(a, null))
return !ReferenceEquals(b, null);
return !a.Equals(b);
}
}
[DataContract]
public sealed class NoteId : Identity
{
public const int TagId = 1;
public NoteId(Guid id)
{
Tag = TagId;
Id = id;
}
NoteId() {}
}
[DataContract]
public sealed class StoryId : Identity
{
public const int TagId = 2;
public StoryId(Guid id)
{
Id = id;
Tag = TagId;
}
StoryId() {}
}
[DataContract]
public sealed class ActivityId : Identity
{
public const int TagId = 3;
public ActivityId(Guid id)
{
Tag = TagId;
Id = id;
}
ActivityId() {}
}
[DataContract]
public sealed class TaskId : Identity
{
public const int TagId = 4;
public TaskId(Guid id)
{
Tag = TagId;
Id = id;
}
TaskId() {}
}
[DataContract]
public sealed class TagId : Identity
{
public const int TagIdValue = 7;
public TagId(Guid id)
{
Tag = TagIdValue;
Id = id;
}
TagId() { }
}
}