示例#1
0
            internal static void RegisterCallback(Interop.DataControl.SafeDataControlHandle handle, string providerId)
            {
                ResultType ret;

                Interop.DataControl.SqlResponseCallbacks          sqlCallbacks;
                Interop.DataControl.SqlBulkInsertResponseCallback sqlBulkCallbacks;
                Interop.DataControl.MapResponseCallbacks          mapCallbacks;
                Interop.DataControl.MapBulkAddResponseCallback    mapBulkCallbacks;
                bool sqlRegistered = false;
                bool mapRegistered = false;

                if (_reqProviderList.ContainsKey(providerId))
                {
                    _reqProviderList[providerId]++;
                    Log.Error(LogTag, "The data control is already set");
                    return;
                }

                sqlCallbacks.Insert = new Interop.DataControl.SqlInsertResponseCallback(InsertResponse);
                sqlCallbacks.Select = new Interop.DataControl.SqlSelectResponseCallback(SelectResponse);
                sqlCallbacks.Update = new Interop.DataControl.SqlUpdateResponseCallback(UpdateResponse);
                sqlCallbacks.Delete = new Interop.DataControl.SqlDeleteResponseCallback(DeleteResponse);
                ret = Interop.DataControl.RegisterSqlResponseCallback(handle, ref sqlCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the sql callback function is failed : " + ret);
                }
                else
                {
                    _sqlResponseCallbacks.Add(providerId, sqlCallbacks);
                    sqlRegistered = true;
                }

                sqlBulkCallbacks = new Interop.DataControl.SqlBulkInsertResponseCallback(BulkInsertResponse);
                ret = Interop.DataControl.RegisterSqlBulkResponseCallback(handle, sqlBulkCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the sql bulk callback function is failed : " + ret);
                }
                else
                {
                    _sqlBulkResponseCallback.Add(providerId, sqlBulkCallbacks);
                }

                mapCallbacks.Add    = new Interop.DataControl.MapAddResponseCallback(MapAddResponse);
                mapCallbacks.Set    = new Interop.DataControl.MapSetResponseCallback(MapSetResponse);
                mapCallbacks.Get    = new Interop.DataControl.MapGetResponseCallback(MapGetResponse);
                mapCallbacks.Remove = new Interop.DataControl.MapRemoveResponseCallback(MapRemoveResponse);
                ret = Interop.DataControl.RegisterMapResponse(handle, ref mapCallbacks, IntPtr.Zero);

                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the map callback function is failed : " + ret);
                }
                else
                {
                    _mapResponseCallbacks.Add(providerId, mapCallbacks);
                    mapRegistered = true;
                }

                mapBulkCallbacks = new Interop.DataControl.MapBulkAddResponseCallback(MapBulkAddResponse);
                ret = Interop.DataControl.RegisterMapBulkResponseCallback(handle, mapBulkCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the map bulk callback function is failed : " + ret);
                }
                else
                {
                    _mapBulkResponseCallback.Add(providerId, mapBulkCallbacks);
                }

                if (!mapRegistered && !sqlRegistered)
                {
                    ErrorFactory.ThrowException(ret, true, "Registering the response callback function is failed");
                }

                _reqProviderList.Add(providerId, 1);
            }