2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
20 using System.Collections.Specialized;
22 namespace FirebirdSql.Data.Common
26 internal delegate void EventCountsCallback();
30 internal class RemoteEvent
34 public EventCountsCallback EventCountsCallback
36 get { return this.eventCountsCallback; }
37 set { this.eventCountsCallback = value; }
44 private EventCountsCallback eventCountsCallback;
45 private StringCollection events;
49 private bool initialCounts;
50 private int[] previousCounts;
51 private int[] actualCounts;
57 public IDatabase Database
59 get { return this.db; }
64 get { return this.localId; }
65 set { this.localId = value; }
70 get { return this.remoteId; }
71 set { this.remoteId = value; }
74 public StringCollection Events
78 if (this.events == null)
80 this.events = new StringCollection();
87 public bool HasChanges
91 if (this.actualCounts == null && this.previousCounts == null)
95 else if (this.actualCounts != null && this.previousCounts == null)
99 else if (this.actualCounts.Length != this.previousCounts.Length)
104 for (int i = 0; i < this.actualCounts.Length; i++)
106 if (this.actualCounts[i] != this.previousCounts[i])
116 public int[] PreviousCounts
118 get { return this.previousCounts; }
121 public int[] ActualCounts
123 get { return this.actualCounts; }
130 public RemoteEvent(IDatabase db) : this(db, 0, 0, null)
134 public RemoteEvent(IDatabase db, int localId, int remoteId, StringCollection events)
137 this.localId = localId;
138 this.remoteId = remoteId;
139 this.events = events;
146 public void QueueEvents()
150 this.db.QueueEvents(this);
154 public void CancelEvents()
158 this.db.CancelEvents(this);
163 public void ResetCounts()
165 this.initialCounts = false;
166 this.actualCounts = null;
167 this.previousCounts = null;
170 public void EventCounts(byte[] buffer)
173 Charset charset = this.db.Charset;
177 if (this.initialCounts)
179 this.previousCounts = this.actualCounts;
182 this.actualCounts = new int[this.events.Count];
184 while (pos < buffer.Length)
186 int length = buffer[pos++];
187 string eventName = charset.GetString(buffer, pos, length);
191 int index = this.events.IndexOf(eventName);
194 this.actualCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;
200 if (!this.initialCounts)
203 this.initialCounts = true;
207 if (this.EventCountsCallback != null)
209 this.EventCountsCallback();
215 public EventParameterBuffer ToEpb()
217 EventParameterBuffer epb = this.db.CreateEventParameterBuffer();
219 epb.Append(IscCodes.EPB_version1);
221 for (int i = 0; i < this.events.Count; i++)
223 if (this.actualCounts != null)
225 epb.Append(this.events[i], this.actualCounts[i] + 1);
229 epb.Append(this.events[i], 0);