Beispiel #1
0
        // This method is called by the ProcessDispatcher upon a notification for this AppDomain.
        internal void InvalidateCommandID(SqlNotification sqlNotification)
        {
            long scopeID = SqlClientEventSource.Log.TryNotificationScopeEnterEvent("<sc.SqlDependencyPerAppDomainDispatcher.InvalidateCommandID|DEP> {0}, commandHash: '{1}'", ObjectID, sqlNotification.Key);

            try
            {
                List <SqlDependency> dependencyList = null;

                lock (this)
                {
                    dependencyList = LookupCommandEntryWithRemove(sqlNotification.Key);

                    if (null != dependencyList)
                    {
                        SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlDependencyPerAppDomainDispatcher.InvalidateCommandID|DEP> commandHash found in hashtable.");
                        foreach (SqlDependency dependency in dependencyList)
                        {
                            // Ensure we remove from process static app domain hash for dependency initiated invalidates.
                            LookupDependencyEntryWithRemove(dependency.Id);

                            // Completely remove Dependency from commandToDependenciesHash.
                            RemoveDependencyFromCommandToDependenciesHash(dependency);
                        }
                    }
                    else
                    {
                        SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlDependencyPerAppDomainDispatcher.InvalidateCommandID|DEP> commandHash NOT found in hashtable.");
                    }
                }

                if (null != dependencyList)
                {
                    // After removal from hashtables, invalidate.
                    foreach (SqlDependency dependency in dependencyList)
                    {
                        SqlClientEventSource.Log.TryNotificationTraceEvent("<sc.SqlDependencyPerAppDomainDispatcher.InvalidateCommandID|DEP> Dependency found in commandHash dependency ArrayList - calling invalidate.");
                        try
                        {
                            dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source);
                        }
                        catch (Exception e)
                        {
                            // Since we are looping over dependencies, do not allow one Invalidate
                            // that results in a throw prevent us from invalidating all dependencies
                            // related to this server.
                            if (!ADP.IsCatchableExceptionType(e))
                            {
                                throw;
                            }
                            ADP.TraceExceptionWithoutRethrow(e);
                        }
                    }
                }
            }
            finally
            {
                SqlClientEventSource.Log.TryNotificationScopeLeaveEvent(scopeID);
            }
        }
        // This method is called when a connection goes down or other unknown error occurs in the ProcessDispatcher.
        internal void InvalidateServer(string server, SqlNotification sqlNotification)
        {
            IntPtr hscp;

            Bid.NotificationsScopeEnter(out hscp, "<sc.SqlDependencyPerAppDomainDispatcher.Invalidate|DEP> %d#, server: '%ls'", ObjectID, server);
            try
            {
                List <SqlDependency> dependencies = new List <SqlDependency>();

                lock (this)
                { // Copy inside of lock, but invalidate outside of lock.
                    foreach (KeyValuePair <string, SqlDependency> entry in _dependencyIdToDependencyHash)
                    {
                        SqlDependency dependency = entry.Value;
                        if (dependency.ContainsServer(server))
                        {
                            dependencies.Add(dependency);
                        }
                    }

                    foreach (SqlDependency dependency in dependencies)
                    { // Iterate over resulting list removing from our hashes.
                        // Ensure we remove from process static app domain hash for dependency initiated invalidates.
                        LookupDependencyEntryWithRemove(dependency.Id);

                        // Completely remove Dependency from commandToDependenciesHash.
                        RemoveDependencyFromCommandToDependenciesHash(dependency);
                    }
                }

                foreach (SqlDependency dependency in dependencies)
                { // Iterate and invalidate.
                    try
                    {
                        dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source);
                    }
                    catch (Exception e)
                    {
                        // Since we are looping over dependencies, do not allow one Invalidate
                        // that results in a throw prevent us from invalidating all dependencies
                        // related to this server.
                        if (!ADP.IsCatchableExceptionType(e))
                        {
                            throw;
                        }
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                }
            }
            finally
            {
                Bid.ScopeLeave(ref hscp);
            }
        }
Beispiel #3
0
        // This method is called by the ProcessDispatcher upon a notification for this AppDomain.
        internal void InvalidateCommandID(SqlNotification sqlNotification)
        {
            List <SqlDependency> dependencyList = null;

            lock (_instanceLock)
            {
                dependencyList = LookupCommandEntryWithRemove(sqlNotification.Key);

                if (null != dependencyList)
                {
                    foreach (SqlDependency dependency in dependencyList)
                    {
                        // Ensure we remove from process static app domain hash for dependency initiated invalidates.
                        LookupDependencyEntryWithRemove(dependency.Id);

                        // Completely remove Dependency from commandToDependenciesHash.
                        RemoveDependencyFromCommandToDependenciesHash(dependency);
                    }
                }
            }

            if (null != dependencyList)
            {
                // After removal from hashtables, invalidate.
                foreach (SqlDependency dependency in dependencyList)
                {
                    try
                    {
                        dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source);
                    }
                    catch (Exception e)
                    {
                        // Since we are looping over dependencies, do not allow one Invalidate
                        // that results in a throw prevent us from invalidating all dependencies
                        // related to this server.
                        if (!ADP.IsCatchableExceptionType(e))
                        {
                            throw;
                        }
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                }
            }
        }