-/*\r
- * Firebird ADO.NET Data provider for .NET and Mono \r
- * \r
- * The contents of this file are subject to the Initial \r
- * Developer's Public License Version 1.0 (the "License"); \r
- * you may not use this file except in compliance with the \r
- * License. You may obtain a copy of the License at \r
- * http://www.firebirdsql.org/index.php?op=doc&id=idpl\r
- *\r
- * Software distributed under the License is distributed on \r
- * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either \r
- * express or implied. See the License for the specific \r
- * language governing rights and limitations under the License.\r
- * \r
- * Copyright (c) 2002, 2005 Carlos Guzman Alvarez\r
- * All Rights Reserved.\r
- */\r
-\r
-using System;\r
-using System.Collections.Specialized;\r
-\r
-namespace FirebirdSql.Data.Common\r
-{\r
- #region Delegates\r
-\r
- internal delegate void EventCountsCallback();\r
-\r
- #endregion\r
-\r
- internal class RemoteEvent\r
- {\r
- #region Callbacks\r
-\r
- public EventCountsCallback EventCountsCallback\r
- {\r
- get { return this.eventCountsCallback; }\r
- set { this.eventCountsCallback = value; }\r
- }\r
-\r
- #endregion\r
-\r
- #region Fields\r
-\r
- private EventCountsCallback eventCountsCallback;\r
- private StringCollection events;\r
- private IDatabase db;\r
- private int localId;\r
- private int remoteId;\r
- private bool initialCounts;\r
- private int[] previousCounts;\r
- private int[] actualCounts;\r
-\r
- #endregion\r
-\r
- #region Properties\r
-\r
- public IDatabase Database\r
- {\r
- get { return this.db; }\r
- }\r
-\r
- public int LocalId\r
- {\r
- get { return this.localId; }\r
- set { this.localId = value; }\r
- }\r
-\r
- public int RemoteId\r
- {\r
- get { return this.remoteId; }\r
- set { this.remoteId = value; }\r
- }\r
-\r
- public StringCollection Events\r
- {\r
- get\r
- {\r
- if (this.events == null)\r
- {\r
- this.events = new StringCollection();\r
- }\r
-\r
- return this.events;\r
- }\r
- }\r
-\r
- public bool HasChanges\r
- {\r
- get\r
- {\r
- if (this.actualCounts == null && this.previousCounts == null)\r
- {\r
- return false;\r
- }\r
- else if (this.actualCounts != null && this.previousCounts == null)\r
- {\r
- return true;\r
- }\r
- else if (this.actualCounts.Length != this.previousCounts.Length)\r
- {\r
- return true;\r
- }\r
-\r
- for (int i = 0; i < this.actualCounts.Length; i++)\r
- {\r
- if (this.actualCounts[i] != this.previousCounts[i])\r
- {\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
- }\r
- }\r
-\r
- public int[] PreviousCounts\r
- {\r
- get { return this.previousCounts; }\r
- }\r
-\r
- public int[] ActualCounts\r
- {\r
- get { return this.actualCounts; }\r
- }\r
-\r
- #endregion\r
-\r
- #region Constructors\r
-\r
- public RemoteEvent(IDatabase db) : this(db, 0, 0, null)\r
- {\r
- }\r
-\r
- public RemoteEvent(IDatabase db, int localId, int remoteId, StringCollection events)\r
- {\r
- this.db = db;\r
- this.localId = localId;\r
- this.remoteId = remoteId;\r
- this.events = events;\r
- }\r
-\r
- #endregion\r
-\r
- #region Methods\r
-\r
- public void QueueEvents()\r
- {\r
- lock (this.db)\r
- {\r
- this.db.QueueEvents(this);\r
- }\r
- }\r
-\r
- public void CancelEvents()\r
- {\r
- lock (this.db)\r
- {\r
- this.db.CancelEvents(this);\r
- this.ResetCounts();\r
- }\r
- }\r
-\r
- public void ResetCounts()\r
- {\r
- this.initialCounts = false;\r
- this.actualCounts = null;\r
- this.previousCounts = null;\r
- }\r
-\r
- public void EventCounts(byte[] buffer)\r
- {\r
- int pos = 1;\r
- Charset charset = this.db.Charset;\r
-\r
- if (buffer != null)\r
- {\r
- if (this.initialCounts)\r
- {\r
- this.previousCounts = this.actualCounts;\r
- }\r
-\r
- this.actualCounts = new int[this.events.Count];\r
-\r
- while (pos < buffer.Length)\r
- {\r
- int length = buffer[pos++];\r
- string eventName = charset.GetString(buffer, pos, length);\r
-\r
- pos += length;\r
-\r
- int index = this.events.IndexOf(eventName);\r
- if (index != -1)\r
- {\r
- this.actualCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;\r
- }\r
-\r
- pos += 4;\r
- }\r
-\r
- if (!this.initialCounts)\r
- {\r
- this.QueueEvents();\r
- this.initialCounts = true;\r
- }\r
- else\r
- {\r
- if (this.EventCountsCallback != null)\r
- {\r
- this.EventCountsCallback();\r
- }\r
- }\r
- }\r
- }\r
-\r
- public EventParameterBuffer ToEpb()\r
- {\r
- EventParameterBuffer epb = this.db.CreateEventParameterBuffer();\r
-\r
- epb.Append(IscCodes.EPB_version1);\r
-\r
- for (int i = 0; i < this.events.Count; i++)\r
- {\r
- if (this.actualCounts != null)\r
- {\r
- epb.Append(this.events[i], this.actualCounts[i] + 1);\r
- }\r
- else\r
- {\r
- epb.Append(this.events[i], 0);\r
- }\r
- }\r
-\r
- return epb;\r
- }\r
-\r
- #endregion\r
- }\r
-}\r
+/*
+ * Firebird ADO.NET Data provider for .NET and Mono
+ *
+ * The contents of this file are subject to the Initial
+ * Developer's Public License Version 1.0 (the "License");
+ * you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ * http://www.firebirdsql.org/index.php?op=doc&id=idpl
+ *
+ * Software distributed under the License is distributed on
+ * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the License for the specific
+ * language governing rights and limitations under the License.
+ *
+ * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
+ * All Rights Reserved.
+ */
+
+using System;
+using System.Collections.Specialized;
+
+namespace FirebirdSql.Data.Common
+{
+ #region Delegates
+
+ internal delegate void EventCountsCallback();
+
+ #endregion
+
+ internal class RemoteEvent
+ {
+ #region Callbacks
+
+ public EventCountsCallback EventCountsCallback
+ {
+ get { return this.eventCountsCallback; }
+ set { this.eventCountsCallback = value; }
+ }
+
+ #endregion
+
+ #region Fields
+
+ private EventCountsCallback eventCountsCallback;
+ private StringCollection events;
+ private IDatabase db;
+ private int localId;
+ private int remoteId;
+ private bool initialCounts;
+ private int[] previousCounts;
+ private int[] actualCounts;
+
+ #endregion
+
+ #region Properties
+
+ public IDatabase Database
+ {
+ get { return this.db; }
+ }
+
+ public int LocalId
+ {
+ get { return this.localId; }
+ set { this.localId = value; }
+ }
+
+ public int RemoteId
+ {
+ get { return this.remoteId; }
+ set { this.remoteId = value; }
+ }
+
+ public StringCollection Events
+ {
+ get
+ {
+ if (this.events == null)
+ {
+ this.events = new StringCollection();
+ }
+
+ return this.events;
+ }
+ }
+
+ public bool HasChanges
+ {
+ get
+ {
+ if (this.actualCounts == null && this.previousCounts == null)
+ {
+ return false;
+ }
+ else if (this.actualCounts != null && this.previousCounts == null)
+ {
+ return true;
+ }
+ else if (this.actualCounts.Length != this.previousCounts.Length)
+ {
+ return true;
+ }
+
+ for (int i = 0; i < this.actualCounts.Length; i++)
+ {
+ if (this.actualCounts[i] != this.previousCounts[i])
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ public int[] PreviousCounts
+ {
+ get { return this.previousCounts; }
+ }
+
+ public int[] ActualCounts
+ {
+ get { return this.actualCounts; }
+ }
+
+ #endregion
+
+ #region Constructors
+
+ public RemoteEvent(IDatabase db) : this(db, 0, 0, null)
+ {
+ }
+
+ public RemoteEvent(IDatabase db, int localId, int remoteId, StringCollection events)
+ {
+ this.db = db;
+ this.localId = localId;
+ this.remoteId = remoteId;
+ this.events = events;
+ }
+
+ #endregion
+
+ #region Methods
+
+ public void QueueEvents()
+ {
+ lock (this.db)
+ {
+ this.db.QueueEvents(this);
+ }
+ }
+
+ public void CancelEvents()
+ {
+ lock (this.db)
+ {
+ this.db.CancelEvents(this);
+ this.ResetCounts();
+ }
+ }
+
+ public void ResetCounts()
+ {
+ this.initialCounts = false;
+ this.actualCounts = null;
+ this.previousCounts = null;
+ }
+
+ public void EventCounts(byte[] buffer)
+ {
+ int pos = 1;
+ Charset charset = this.db.Charset;
+
+ if (buffer != null)
+ {
+ if (this.initialCounts)
+ {
+ this.previousCounts = this.actualCounts;
+ }
+
+ this.actualCounts = new int[this.events.Count];
+
+ while (pos < buffer.Length)
+ {
+ int length = buffer[pos++];
+ string eventName = charset.GetString(buffer, pos, length);
+
+ pos += length;
+
+ int index = this.events.IndexOf(eventName);
+ if (index != -1)
+ {
+ this.actualCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;
+ }
+
+ pos += 4;
+ }
+
+ if (!this.initialCounts)
+ {
+ this.QueueEvents();
+ this.initialCounts = true;
+ }
+ else
+ {
+ if (this.EventCountsCallback != null)
+ {
+ this.EventCountsCallback();
+ }
+ }
+ }
+ }
+
+ public EventParameterBuffer ToEpb()
+ {
+ EventParameterBuffer epb = this.db.CreateEventParameterBuffer();
+
+ epb.Append(IscCodes.EPB_version1);
+
+ for (int i = 0; i < this.events.Count; i++)
+ {
+ if (this.actualCounts != null)
+ {
+ epb.Append(this.events[i], this.actualCounts[i] + 1);
+ }
+ else
+ {
+ epb.Append(this.events[i], 0);
+ }
+ }
+
+ return epb;
+ }
+
+ #endregion
+ }
+}