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, 2004 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;
49 private StringCollection events;
50 private bool initialCounts;
51 private int[] previousCounts;
52 private int[] actualCounts;
58 public IDatabase Database
60 get { return this.db; }
65 get { return this.localId; }
66 set { this.localId = value; }
71 get { return this.remoteId; }
72 set { this.remoteId = value; }
75 public StringCollection Events
79 if (this.events == null)
81 this.events = new StringCollection();
88 public bool HasChanges
92 if (this.actualCounts == null && this.previousCounts == null)
96 else if (this.actualCounts != null && this.previousCounts == null)
100 else if (this.actualCounts.Length != this.previousCounts.Length)
105 for (int i = 0; i < this.actualCounts.Length; i++)
107 if (this.actualCounts[i] != this.previousCounts[i])
117 public int[] PreviousCounts
119 get { return this.previousCounts; }
122 public int[] ActualCounts
124 get { return this.actualCounts; }
131 public RemoteEvent(IDatabase db) : this(db, 0, 0, null)
135 public RemoteEvent(IDatabase db, int localId, int remoteId, StringCollection events)
138 this.localId = localId;
139 this.remoteId = remoteId;
140 this.events = events;
147 public void QueueEvents()
151 this.db.QueueEvents(this);
155 public void CancelEvents()
159 this.db.CancelEvents(this);
164 public void ResetCounts()
166 this.initialCounts = false;
167 this.actualCounts = null;
168 this.previousCounts = null;
171 public void EventCounts(byte[] buffer)
174 Charset charset = this.db.Charset;
178 if (this.initialCounts)
180 this.previousCounts = this.actualCounts;
183 this.actualCounts = new int[this.events.Count];
185 while (pos < buffer.Length)
187 int length = buffer[pos++];
188 string eventName = charset.GetString(buffer, pos, length);
192 int index = this.events.IndexOf(eventName);
195 this.actualCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;
201 if (!this.initialCounts)
204 this.initialCounts = true;
208 if (this.EventCountsCallback != null)
210 this.EventCountsCallback();
216 public EventParameterBuffer ToEpb()
218 EventParameterBuffer epb = this.db.CreateEventParameterBuffer();
220 epb.Append(IscCodes.EPB_version1);
222 for (int i = 0; i < this.events.Count; i++)
224 if (this.actualCounts != null)
226 epb.Append(this.events[i], this.actualCounts[i] + 1);
230 epb.Append(this.events[i], 0);