/
VEventCollection.cs
175 lines (154 loc) · 6.83 KB
/
VEventCollection.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//===============================================================================================================
// System : Personal Data Interchange Classes
// File : VEventCollection.cs
// Author : Eric Woodruff (Eric@EWoodruff.us)
// Updated : 11/06/2014
// Note : Copyright 2004-2014, Eric Woodruff, All rights reserved
// Compiler: Microsoft Visual C#
//
// This file contains a collection class for VEvent objects
//
// This code is published under the Microsoft Public License (Ms-PL). A copy of the license should be
// distributed with the code and can be found at the project website: https://github.com/EWSoftware/PDI.
// This notice, the author's name, and all copyright notices must remain intact in all applications,
// documentation, and source files.
//
// Date Who Comments
// ==============================================================================================================
// 03/28/2004 EFW Created the code
// 03/21/2007 EFW Converted to use a generic base class
//===============================================================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using EWSoftware.PDI.Binding;
using EWSoftware.PDI.Properties;
namespace EWSoftware.PDI.Objects
{
/// <summary>
/// A type-safe collection of <see cref="VEvent"/> objects
/// </summary>
/// <remarks>The class has a type-safe enumerator</remarks>
public class VEventCollection : ExtendedBindingList<VEvent>
{
#region Constructors
//=====================================================================
/// <summary>
/// Default constructor
/// </summary>
/// <overloads>There are two overloads for the constructor</overloads>
public VEventCollection()
{
}
/// <summary>
/// Construct the collection using a list of <see cref="VEvent"/> objects
/// </summary>
/// <param name="events">The <see cref="IList{T}"/> of events to add</param>
public VEventCollection(IList<VEvent> events) : base(events)
{
}
#endregion
#region Indexer
//=====================================================================
/// <summary>
/// Collection indexer
/// </summary>
/// <param name="uniqueId">The unique ID of the item to get or set. When retrieving an item, null is
/// returned if it does not exist in the collection.</param>
/// <exception cref="ArgumentException">This is thrown if an attempt is made to set an item using a
/// unique ID that does not exist in the collection.</exception>
public VEvent this[string uniqueId]
{
get
{
for(int idx = 0; idx < base.Count; idx++)
if(base[idx].UniqueId.Value == uniqueId)
return base[idx];
return null;
}
set
{
for(int idx = 0; idx < base.Count; idx++)
if(base[idx].UniqueId.Value == uniqueId)
{
base[idx] = value;
return;
}
throw new ArgumentException(LR.GetString("ExUIDNotFound"));
}
}
#endregion
#region Methods
//=====================================================================
/// <summary>
/// This can be used to ensure that all events in the collection have a unique ID assigned to them
/// </summary>
/// <param name="forceNew">If true, a new unique ID is assigned regardless of whether one already exists.
/// If false and the event already has a unique ID, it keeps the old one.</param>
public void AssignUniqueIds(bool forceNew)
{
foreach(VEvent e in this)
e.UniqueId.AssignNewId(forceNew);
base.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
/// <summary>
/// This is used to propagate a common version to all objects in the collection
/// </summary>
/// <param name="version">The version to use</param>
public void PropagateVersion(SpecificationVersions version)
{
foreach(PDIObject o in this)
o.Version = version;
base.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
/// <summary>
/// This is used to get a list of time zones used by all owned objects
/// </summary>
/// <param name="timeZoneIds">A <see cref="StringCollection"/> that will be used to store the list of
/// unique time zone IDs used by the calendar objects.</param>
public void TimeZonesUsed(StringCollection timeZoneIds)
{
foreach(VEvent e in this)
e.TimeZonesUsed(timeZoneIds);
}
/// <summary>
/// This is used to replace an old time zone ID with a new time zone ID in all properties of a calendar
/// object.
/// </summary>
/// <param name="oldId">The old ID being replaced</param>
/// <param name="newId">The new ID to use</param>
public void UpdateTimeZoneId(string oldId, string newId)
{
foreach(VEvent e in this)
e.UpdateTimeZoneId(oldId, newId);
base.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
/// <summary>
/// This is used to apply the selected time zone to all date/time objects in the component and convert
/// them to the new time zone.
/// </summary>
/// <param name="vTimeZone">A <see cref="VTimeZone"/> object that will be used for all date/time objects
/// in the component.</param>
/// <remarks>When applied, all date/time values in the object will be converted to the new time zone</remarks>
public void ApplyTimeZone(VTimeZone vTimeZone)
{
foreach(VEvent e in this)
e.ApplyTimeZone(vTimeZone);
base.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
/// <summary>
/// This is used to set the selected time zone in all date/time objects in the component without
/// modifying the date/time values.
/// </summary>
/// <param name="vTimeZone">A <see cref="VTimeZone"/> object that will be used for all date/time objects
/// in the component.</param>
/// <remarks>This method does not affect the date/time values</remarks>
public void SetTimeZone(VTimeZone vTimeZone)
{
foreach(VEvent e in this)
e.SetTimeZone(vTimeZone);
base.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
#endregion
}
}