Exemplo n.º 1
0
        /// <summary>
        /// Cleans up the COM object references.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> if this was called from the
        /// <see cref="IDisposable"/> interface.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                _owner             = null;
                _unmappedEventKeys = null;

                if (null != _events)
                {
                    _events.Dispose();
                    _events = null;
                }
            }

            if (null != _connectionPoint)
            {
                if (0 != _connectionCookie)
                {
                    _connectionPoint.Unadvise(_connectionCookie);
                    _connectionCookie = 0;
                }

                while (Marshal.ReleaseComObject(_connectionPoint) > 0)
                {
                    ;
                }
                _connectionPoint = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cleans up the COM object references.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> if this was called from the
        /// <see cref="IDisposable"/> interface.
        /// </param>
        private void Dispose(bool disposing)
        {
            lock (this)
            {
                if (null != _eventSink)
                {
                    _eventSink.Dispose();
                    _eventSink = null;
                }

                if (null != _connectionPoint)
                {
                    while (Marshal.ReleaseComObject(_connectionPoint) > 0)
                    {
                        ;
                    }
                    _connectionPoint = null;
                }

                if (null != _connectionPointContainer)
                {
                    while (Marshal.ReleaseComObject(_connectionPointContainer) > 0)
                    {
                        ;
                    }
                    _connectionPointContainer = null;
                }
            }
        }
Exemplo n.º 3
0
		/// <summary>
		/// Cleans up the COM object references.
		/// </summary>
		/// <param name="disposing">
		/// <see langword="true"/> if this was called from the
		/// <see cref="IDisposable"/> interface.
		/// </param>
		protected virtual void Dispose(bool disposing)
		{
			if (disposing)
			{
				_owner = null;
				_unmappedEventKeys = null;
				
				if (null != _events)
				{
					_events.Dispose();
					_events = null;
				}
			}
			
			if (null != _connectionPoint)
			{
				if (0 != _connectionCookie)
				{
					_connectionPoint.Unadvise(_connectionCookie);
					_connectionCookie = 0;
				}
				
				while( Marshal.ReleaseComObject(_connectionPoint) > 0 );
				_connectionPoint = null;
			}
		}
Exemplo n.º 4
0
 // Disconnect from ActiveX event source
 void Disconnect()
 {
     System.Threading.Monitor.Enter(this);
     try {
         if (EventSinkHelper != null)
         {
             ConnectionPoint.Unadvise(EventSinkHelper.Cookie);
         }
         ConnectionPoint = null;
         EventSinkHelper = null;
     } catch { }
     System.Threading.Monitor.Exit(this);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Connects this event sink to a COM object.
        /// </summary>
        /// <param name="connectionPoint">
        /// The connection point to connect to.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="connectionPoint"/> is <see langword="null"/>.
        /// </exception>
        internal void Connect(UCOMIConnectionPoint connectionPoint)
        {
            if (null == connectionPoint)
            {
                throw new ArgumentNullException("connectionPoint");
            }

            if (0 == _connectionCookie)
            {
                int connectionCookie;
                connectionPoint.Advise(this, out connectionCookie);
                _connectionCookie = connectionCookie;
                _connectionPoint  = connectionPoint;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize the event sink.
        /// </summary>
        private void Initialize()
        {
            if (null == _connectionPointContainer)
            {
                throw new ObjectDisposedException("ComEventProvider");
            }

            UCOMIConnectionPoint connectionPoint;
            Guid pointGuid = _connectionPointGuid;

            _connectionPointContainer.FindConnectionPoint(ref pointGuid, out connectionPoint);
            _connectionPoint = connectionPoint;

            _eventSink = (ComEventSink)Activator.CreateInstance(_eventSinkType);
            _eventSink.Connect(_connectionPoint);
            _eventSink.Owner = _owner;
        }
Exemplo n.º 7
0
        // Method called when the connection is put back into the pool while it is manually
        // enlisted in a distributed transaction.  We must create an outcome event and let the
        // connection wait until the distributed transaction has finished.  Once it does, we then
        // put it back into the general population of the pool.
        private void PutConnectionManualEnlisted(SqlInternalConnection con)
        {
            ITransaction transaction = con.ManualEnlistedTransaction;

            con.ResetCachedTransaction(); // Null out con internal transaction reference
            con.InPool = true;            // Mark as in pool so it will not be reclaimed by CheckForDeadConnections

            // Create IConnectionPoint object - from ITransaction
            UCOMIConnectionPoint point = (UCOMIConnectionPoint)transaction;

            // Create outcome event - passing pool, connection, and the IConnectionPoint object
            TransactionOutcomeEvents outcomeEvent = new TransactionOutcomeEvents(this, con, point);

            Int32 cookie = 0;

            point.Advise(outcomeEvent, out cookie); // Register for callbacks, obtain cookie

            outcomeEvent.SetCookie(cookie);         // Set the cookie on the event
        }
Exemplo n.º 8
0
        private void ReturnToPool()
        {
            if (_signaled)
            {
                if (null != _connection && null != _pool)
                {
                    _pool.PutNewConnection(_connection);
                    _pool       = null;
                    _connection = null;
                }

                if (0 != _cookie && null != _point)
                {
                    _point.Unadvise(_cookie);
                    _point  = null;
                    _cookie = 0;
                }
            }
        }
Exemplo n.º 9
0
            private void ReturnToPool()
            {
                if (_signaled)
                {
                    if (null != _pooledObject && null != _pool)
                    {
                        _pool.PutNewObject(_pooledObject);
                        _pool         = null;
                        _pooledObject = null;
                    }

                    if (0 != _cookie && null != _point)
                    {
                        _point.Unadvise(_cookie);
                        _point  = null;
                        _cookie = 0;
                    }
                }
            }
Exemplo n.º 10
0
        /// <summary>
        /// Disconnects this event sink from a COM object.
        /// </summary>
        internal void Disconnect()
        {
            if (null != _connectionPoint)
            {
                if (0 != _connectionCookie)
                {
                    _connectionPoint.Unadvise(_connectionCookie);
                    _connectionCookie = 0;
                }

                while (Marshal.ReleaseComObject(_connectionPoint) > 0)
                {
                    ;
                }
                _connectionPoint = null;
            }

            _owner = null;
        }
Exemplo n.º 11
0
            private bool _signaled;                    // Bool in case signal occurs before Cookie is set.

            public TransactionOutcomeEvents(DBObjectPool pool, DBPooledObject pooledObject, UCOMIConnectionPoint point)
            {
                _pool         = pool;
                _pooledObject = pooledObject;
                _point        = point;
            }
Exemplo n.º 12
0
        public void Disconnect()
        {
            if( ! (shutdowncpoint == null) )
            {
            if( shutdowncookie != 0 )
                {
                shutdowncpoint.Unadvise( shutdowncookie );
                shutdowncookie = 0;
                }
            int	rc = Marshal.ReleaseComObject( shutdowncpoint );
            shutdowncpoint = null;
            }

            cpointcontainer = null;
            ifBrowse		= null;
            ifItmProps		= null;
            ifCommon		= null;
            ifServer		= null;
            if( ! (OPCserverObj == null) )
            {
            int rc = Marshal.ReleaseComObject( OPCserverObj );
            OPCserverObj = null;
            }
        }
Exemplo n.º 13
0
        public void Remove( bool bForce )
        {
            if( ! (callbackcpoint == null) )
            {
            if( callbackcookie != 0 )
                {
                callbackcpoint.Unadvise( callbackcookie );
                callbackcookie = 0;
                }
            int	rc = Marshal.ReleaseComObject( callbackcpoint );
            callbackcpoint = null;
            }

            cpointcontainer	= null;
            ifItems		= null;
            ifSync		= null;
            ifAsync		= null;

            if( ! (ifMgt == null) )
            {
            int	rc = Marshal.ReleaseComObject( ifMgt );
            ifMgt = null;
            }

            if( ! (ifServer == null) )
            {
            if( ! state.Public )
                ifServer.RemoveGroup( state.HandleServer, bForce );
            ifServer	= null;
            }

            state.HandleServer = 0;
        }
Exemplo n.º 14
0
 // Disconnect from ActiveX event source
 void Disconnect()
 {
   System.Threading.Monitor.Enter(this);
   try {
     if (EventSinkHelper != null)
       ConnectionPoint.Unadvise(EventSinkHelper.Cookie);
     ConnectionPoint = null;
     EventSinkHelper = null;
   } catch { }
   System.Threading.Monitor.Exit(this);
 }
Exemplo n.º 15
0
        public string ExecuteSqlServerPackage(int iBuyerCompanyID, string strFromDate, string strToDate, string strType)
        {
            string strMessage = "";

            UCOMIConnectionPointContainer CnnctPtCont = null;
            UCOMIConnectionPoint          CnnctPt     = null;
            PackageEventsSink             PES         = null;

            int iCookie = 0;

            try
            {
                package     = new Package2Class();
                CnnctPtCont = (UCOMIConnectionPointContainer)package;
                PES         = new PackageEventsSink();
                Guid guid = new Guid("10020605-EB1C-11CF-AE6E-00AA004A34D5");

                CnnctPtCont.FindConnectionPoint(ref guid, out CnnctPt);
                CnnctPt.Advise(PES, out iCookie);
                object pVarPersistStgOfHost = null;

                package.LoadFromSQLServer(serverName, serverUsername, serverPassword, DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, null,
                                          null, null, packageName, ref pVarPersistStgOfHost);

                foreach (GlobalVariable global in package.GlobalVariables)
                {
                    try
                    {
                        if (global.Name.Equals("BuyerCompanyID"))
                        {
                            package.GlobalVariables.Remove(global.Name);
                        }

                        if (global.Name.Equals("FromDate"))
                        {
                            package.GlobalVariables.Remove(global.Name);
                        }

                        if (global.Name.Equals("ToDate"))
                        {
                            package.GlobalVariables.Remove(global.Name);
                        }
                    }
                    catch (Exception ex) { strMessage = strMessage + ex.Message + Environment.NewLine; }
                }

                //Read all the global variables that are of type string
                package.GlobalVariables.AddGlobalVariable("BuyerCompanyID", iBuyerCompanyID);
                package.GlobalVariables.AddGlobalVariable("FromDate", strFromDate);
                package.GlobalVariables.AddGlobalVariable("ToDate", strToDate);
                package.Execute();
                package.UnInitialize();
                package = null;
                CnnctPt.Unadvise(iCookie); //a connection that is created by IConnectionPoint.Advise must be closed by calling IConnectionPoint.Unadvise to avoid a memory leak

                strMessage = strMessage + "CSV Files generated successfully through DTS package." + Environment.NewLine;
            }
            catch (System.Runtime.InteropServices.COMException ex) { strMessage = strMessage + ex.Message + Environment.NewLine; package.UnInitialize(); package = null; CnnctPt.Unadvise(iCookie); }
            catch (Exception ex) { strMessage = strMessage + ex.Message + Environment.NewLine; package.UnInitialize(); package = null; CnnctPt.Unadvise(iCookie); }

            return(strMessage);
        }
Exemplo n.º 16
0
		/// <summary>
		/// Initialize the event sink.
		/// </summary>
		private void Initialize()
		{
			if (null == _connectionPointContainer)
				throw new ObjectDisposedException("ComEventProvider");
			
			UCOMIConnectionPoint connectionPoint;
			Guid pointGuid = _connectionPointGuid;
			_connectionPointContainer.FindConnectionPoint(ref pointGuid, out connectionPoint);
			_connectionPoint = connectionPoint;
			
			_eventSink = (ComEventSink)Activator.CreateInstance(_eventSinkType);
			_eventSink.Connect(_connectionPoint);
			_eventSink.Owner = _owner;
		}
Exemplo n.º 17
0
        private bool _signaled;                  // Bool in case signal occurs before Cookie is set.

        public TransactionOutcomeEvents(ConnectionPool pool, SqlInternalConnection connection, UCOMIConnectionPoint point)
        {
            _pool       = pool;
            _connection = connection;
            _point      = point;
        }
Exemplo n.º 18
0
 public ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException)
 {
     Exception exception = null;
     if (source is UCOMIConnectionPointContainer)
     {
         UCOMIConnectionPointContainer container = (UCOMIConnectionPointContainer) source;
         try
         {
             Guid gUID = eventInterface.GUID;
             container.FindConnectionPoint(ref gUID, out this.connectionPoint);
         }
         catch (Exception)
         {
             this.connectionPoint = null;
         }
         if (this.connectionPoint == null)
         {
             exception = new ArgumentException("The source object does not expose the " + eventInterface.Name + " event inteface");
             goto Label_00C1;
         }
         if (!eventInterface.IsInstanceOfType(sink))
         {
             exception = new InvalidCastException("The sink object does not implement the eventInterface");
             goto Label_00C1;
         }
         try
         {
             this.connectionPoint.Advise(sink, out this.cookie);
             goto Label_00C1;
         }
         catch
         {
             this.cookie = 0;
             this.connectionPoint = null;
             exception = new Exception("IConnectionPoint::Advise failed for event interface '" + eventInterface.Name + "'");
             goto Label_00C1;
         }
     }
     exception = new InvalidCastException("The source object does not expost IConnectionPointContainer");
     Label_00C1:
     if (!throwException || ((this.connectionPoint != null) && (this.cookie != 0)))
     {
         return;
     }
     if (exception == null)
     {
         throw new ArgumentException("Could not create connection point for event interface '" + eventInterface.Name + "'");
     }
     throw exception;
 }
Exemplo n.º 19
0
		/// <summary>
		/// Cleans up the COM object references.
		/// </summary>
		/// <param name="disposing">
		/// <see langword="true"/> if this was called from the
		/// <see cref="IDisposable"/> interface.
		/// </param>
		private void Dispose(bool disposing)
		{
			lock(this)
			{
				if (null != _eventSink)
				{
					_eventSink.Dispose();
					_eventSink = null;
				}
				
				if (null != _connectionPoint)
				{
					while( Marshal.ReleaseComObject(_connectionPoint) > 0 );
					_connectionPoint = null;
				}
				
				if (null != _connectionPointContainer)
				{
					while( Marshal.ReleaseComObject(_connectionPointContainer) > 0 );
					_connectionPointContainer = null;
				}
			}
		}
Exemplo n.º 20
0
        public void PutObject(DBPooledObject obj, object owningObject)
        {
            if (obj == null)
            {
                throw ADP.ArgumentNull("obj");
            }

            obj.PrePush(owningObject);

            if (_state != State.ShuttingDown)
            {
                bool isInTransaction = obj.Deactivate();

                if (obj.CanBePooled())
                {
#if USEORAMTS
                    ITransaction transaction = obj.ManualEnlistedTransaction;

                    if (null != transaction)
                    {
                        // When the object is put back into the pool while it is manually
                        // enlisted in a distributed transaction, we must create an outcome
                        // event and let the object wait until the distributed transaction
                        // has finished.  Once it does, the TransactionOutcomeEvents class
                        // can put it back into the general population of the pool.

                        UCOMIConnectionPoint point = (UCOMIConnectionPoint)transaction;

                        TransactionOutcomeEvents outcomeEvent = new TransactionOutcomeEvents(this, obj, point);

                        Int32 cookie = 0;
                        point.Advise(outcomeEvent, out cookie); // Register for callbacks, obtain cookie
                        outcomeEvent.SetCookie(cookie);         // Set the cookie on the event

#if ALLOWTRACING
                        ADP.TraceObjectPoolActivity("WaitForOutcomeEvnt", obj);
#endif //ALLOWTRACING
                        return;
                    }
#endif //USEORAMTS
                    // Try shoving it in the tx context first.  If that succeeds,
                    // we're done.
                    if (isInTransaction && TryPutResourceInContext(obj))
                    {
                        return;
                    }

                    // If the above failed, we just shove it into our current collection
                    PutNewObject(obj);
                }
                else
                {
                    DestroyObject(obj);
                    // Make sure we're at quota by posting a callback to the threadpool.
                    ThreadPool.QueueUserWorkItem(new WaitCallback(PoolCreateRequest));
                }
            }
            else
            {
                // If we're shutting down, we destroy the object.
                DestroyObject(obj);
            }
        }
Exemplo n.º 21
0
		/// <summary>
		/// Connects this event sink to a COM object.
		/// </summary>
		/// <param name="connectionPoint">
		/// The connection point to connect to.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="connectionPoint"/> is <see langword="null"/>.
		/// </exception>
		internal void Connect(UCOMIConnectionPoint connectionPoint)
		{
			if (null == connectionPoint) throw new ArgumentNullException("connectionPoint");
			
			if (0 == _connectionCookie)
			{
				int connectionCookie;
				connectionPoint.Advise(this, out connectionCookie);
				_connectionCookie = connectionCookie;
				_connectionPoint = connectionPoint;
			}
		}
Exemplo n.º 22
0
 public void Disconnect()
 {
     if ((this.connectionPoint != null) && (this.cookie != 0))
     {
         try
         {
             this.connectionPoint.Unadvise(this.cookie);
             this.cookie = 0;
             this.connectionPoint = null;
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.Message);
         }
     }
 }
Exemplo n.º 23
0
		/// <summary>
		/// Disconnects this event sink from a COM object.
		/// </summary>
		internal void Disconnect()
		{
			if (null != _connectionPoint)
			{
				if (0 != _connectionCookie)
				{
					_connectionPoint.Unadvise(_connectionCookie);
					_connectionCookie = 0;
				}
				
				while( Marshal.ReleaseComObject(_connectionPoint) > 0 );
				_connectionPoint = null;
			}
			
			_owner = null;
		}