Ejemplo n.º 1
0
        protected void OnChange(object sender, SqlNotificationEventArgs args)
        {
            try
            {
                if (args.Info == SqlNotificationInfo.Invalid &&
                    args.Source == SqlNotificationSource.Statement &&
                    args.Type == SqlNotificationType.Subscribe)
                {
                    throw new InvalidOperationException("Invalid query for SqlDependency")
                          {
                              Data = { { "query", query.PlainSql() } }
                          }
                }
                ;

                if (args.Info == SqlNotificationInfo.PreviousFire)
                {
                    throw new InvalidOperationException("The same transaction that loaded the data is invalidating it! Table: {0} SubTables: {1} ".
                                                        FormatWith(Table, subTables?.Select(e => e.Table).ToString(",")))
                          {
                              Data = { { "query", query.PlainSql() } }
                          }
                }
                ;

                if (CacheLogic.LogWriter != null)
                {
                    CacheLogic.LogWriter.WriteLine("Change {0}".FormatWith(GetType().TypeName()));
                }

                Reset();

                Interlocked.Increment(ref invalidations);

                controller.OnChange(this, args);
            }
            catch (Exception e)
            {
                e.LogException();
            }
        }