internal void Start(DataContextCallback callback, SchemaChangeTestMode schemaTestMode)
            {
                ThreadStart start = null;
                bool        flag  = false;

                lock (this._locker)
                {
                    this._lastUsed = DateTime.UtcNow;
                    if (callback != null)
                    {
                        this._oneOffSubscribers = (DataContextCallback)Delegate.Combine(this._oneOffSubscribers, callback);
                    }
                    if (!(this._busy && (schemaTestMode != SchemaChangeTestMode.ForceRefresh)))
                    {
                        this._busy   = flag = true;
                        this._error  = null;
                        this._status = "Connecting";
                    }
                    if (flag)
                    {
                        if (start == null)
                        {
                            start = () => this.GetDCInfo(schemaTestMode);
                        }
                        Thread thread = new Thread(start)
                        {
                            IsBackground = true,
                            Name         = "DataContext Refresh",
                            Priority     = ThreadPriority.BelowNormal
                        };
                        this._worker = thread;
                        this._worker.Start();
                    }
                }
            }
 public void Dispose()
 {
     if (!this._isDisposed)
     {
         this._isDisposed = true;
         if (this._runner != null)
         {
             if (this._subscription != null)
             {
                 this._runner.DataContextChanged -= this._subscription;
             }
             this._subscription = null;
             lock (_runners)
             {
                 this._runner.LastUsed = DateTime.UtcNow;
                 this._runner.RefCount--;
                 if (this._runner.RefCount < 0)
                 {
                     this._runner.RefCount = 0;
                 }
             }
             this._runner = null;
         }
     }
 }
 private DataContextManager(LINQPad.Repository r, DataContextCallback subscription)
 {
     this.Repository    = r;
     this._subscription = subscription;
     lock (_runners)
     {
         if (_runners.TryGetValue(r, out this._runner))
         {
             this._runner.RefCount++;
         }
         else
         {
             _runners[this.Repository] = this._runner = new Runner(this.Repository);
         }
     }
     if (this._subscription != null)
     {
         this._runner.DataContextChanged += this._subscription;
     }
 }
        public static void GetDataContextInfo(LINQPad.Repository r, DataContextCallback callback, SchemaChangeTestMode schemaTestMode)
        {
            DataContextManager  manager   = new DataContextManager(r, null);
            DataContextCallback callback2 = delegate(DataContextInfo info) {
                manager.Dispose();
                if (callback != null)
                {
                    callback(info);
                }
            };

            if (!((callback != null) || manager.HasOtherSubscribers))
            {
                manager.Dispose();
            }
            else
            {
                manager.GetDataContextInfo(callback2, schemaTestMode);
            }
        }
 private DataContextManager(LINQPad.Repository r, DataContextCallback subscription)
 {
     this.Repository = r;
     this._subscription = subscription;
     lock (_runners)
     {
         if (_runners.TryGetValue(r, out this._runner))
         {
             this._runner.RefCount++;
         }
         else
         {
             _runners[this.Repository] = this._runner = new Runner(this.Repository);
         }
     }
     if (this._subscription != null)
     {
         this._runner.DataContextChanged += this._subscription;
     }
 }
            private void GetDCInfo(SchemaChangeTestMode schemaTestMode)
            {
                Exception exception;
                bool      flag = true;

                try
                {
                    object obj2;
                    try
                    {
                        bool flag2;
                        if (this._disposed)
                        {
                            return;
                        }
                        if (!((flag2 = (this._schema == null) || (schemaTestMode == SchemaChangeTestMode.ForceRefresh)) || (schemaTestMode == SchemaChangeTestMode.None)))
                        {
                            bool?nullable = this.HasSchemaChanged();
                            flag2 = nullable.HasValue ? nullable.GetValueOrDefault() : (schemaTestMode == SchemaChangeTestMode.TestAndFailPositive);
                        }
                        if (flag2)
                        {
                            this.UpdateSchema();
                        }
                        else
                        {
                            flag = false;
                        }
                        if (this._lastSchemaChange == new DateTime())
                        {
                            this.HasSchemaChanged();
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        if (!(!this._repository.DriverLoader.IsInternalAuthor || IsUserError(exception)))
                        {
                            Program.ProcessException(exception);
                        }
                        else
                        {
                            Log.Write(exception, "Error opening DataContext");
                        }
                        lock ((obj2 = this._locker))
                        {
                            if (this._worker == Thread.CurrentThread)
                            {
                                this._error = (exception is AccessViolationException) ? "An AccessViolationException was thrown when trying to open the connection." : exception.Message;
                                this._repository.IsAutoGenAssemblyAvailable = false;
                                this._repository.AutoGenAssemblyFailed      = true;
                            }
                        }
                    }
                    Delegate[]      invocationList = null;
                    Delegate[]      delegateArray2 = null;
                    DataContextInfo dCInfo         = null;
                    lock ((obj2 = this._locker))
                    {
                        if (this._worker != Thread.CurrentThread)
                        {
                            return;
                        }
                        this._status = "";
                        this._busy   = false;
                        dCInfo       = this.GetDCInfo();
                        if (flag && (this._changeSubscribers != null))
                        {
                            invocationList = this._changeSubscribers.GetInvocationList();
                            foreach (DataContextCallback callback in this._changeSubscribers.GetInvocationList())
                            {
                                if (this._oneOffSubscribers == null)
                                {
                                    break;
                                }
                                this._oneOffSubscribers = (DataContextCallback)Delegate.Remove(this._oneOffSubscribers, callback);
                            }
                        }
                        if (this._oneOffSubscribers != null)
                        {
                            delegateArray2 = this._oneOffSubscribers.GetInvocationList();
                        }
                        this._oneOffSubscribers = null;
                    }
                    if (invocationList != null)
                    {
                        foreach (DataContextCallback callback2 in invocationList)
                        {
                            callback2(dCInfo);
                        }
                    }
                    if (delegateArray2 != null)
                    {
                        foreach (DataContextCallback callback2 in delegateArray2)
                        {
                            callback2(dCInfo);
                        }
                    }
                    if (dCInfo.Error != null)
                    {
                        DataContextManager._globalErrorHandlers(dCInfo);
                    }
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    Program.ProcessException(exception);
                }
            }
 public void Dispose()
 {
     this._disposed          = true;
     this._changeSubscribers = (DataContextCallback)(this._oneOffSubscribers = null);
 }
 public static DataContextManager SubscribeToDataContextChanges(LINQPad.Repository r, DataContextCallback subscription)
 {
     return(new DataContextManager(r, subscription));
 }
 public static void SubscribeToAllErrors(DataContextCallback callback)
 {
     _globalErrorHandlers = (DataContextCallback)Delegate.Combine(_globalErrorHandlers, callback);
 }
 public static void GetDataContextInfo(LINQPad.Repository r, DataContextCallback callback, SchemaChangeTestMode schemaTestMode)
 {
     DataContextManager manager = new DataContextManager(r, null);
     DataContextCallback callback2 = delegate (DataContextInfo info) {
         manager.Dispose();
         if (callback != null)
         {
             callback(info);
         }
     };
     if (!((callback != null) || manager.HasOtherSubscribers))
     {
         manager.Dispose();
     }
     else
     {
         manager.GetDataContextInfo(callback2, schemaTestMode);
     }
 }
 public void Dispose()
 {
     if (!this._isDisposed)
     {
         this._isDisposed = true;
         if (this._runner != null)
         {
             if (this._subscription != null)
             {
                 this._runner.DataContextChanged -= this._subscription;
             }
             this._subscription = null;
             lock (_runners)
             {
                 this._runner.LastUsed = DateTime.UtcNow;
                 this._runner.RefCount--;
                 if (this._runner.RefCount < 0)
                 {
                     this._runner.RefCount = 0;
                 }
             }
             this._runner = null;
         }
     }
 }
 internal void Start(DataContextCallback callback, SchemaChangeTestMode schemaTestMode)
 {
     ThreadStart start = null;
     bool flag = false;
     lock (this._locker)
     {
         this._lastUsed = DateTime.UtcNow;
         if (callback != null)
         {
             this._oneOffSubscribers = (DataContextCallback) Delegate.Combine(this._oneOffSubscribers, callback);
         }
         if (!(this._busy && (schemaTestMode != SchemaChangeTestMode.ForceRefresh)))
         {
             this._busy = flag = true;
             this._error = null;
             this._status = "Connecting";
         }
         if (flag)
         {
             if (start == null)
             {
                 start = () => this.GetDCInfo(schemaTestMode);
             }
             Thread thread = new Thread(start) {
                 IsBackground = true,
                 Name = "DataContext Refresh",
                 Priority = ThreadPriority.BelowNormal
             };
             this._worker = thread;
             this._worker.Start();
         }
     }
 }
 private void GetDCInfo(SchemaChangeTestMode schemaTestMode)
 {
     Exception exception;
     bool flag = true;
     try
     {
         object obj2;
         try
         {
             bool flag2;
             if (this._disposed)
             {
                 return;
             }
             if (!((flag2 = (this._schema == null) || (schemaTestMode == SchemaChangeTestMode.ForceRefresh)) || (schemaTestMode == SchemaChangeTestMode.None)))
             {
                 bool? nullable = this.HasSchemaChanged();
                 flag2 = nullable.HasValue ? nullable.GetValueOrDefault() : (schemaTestMode == SchemaChangeTestMode.TestAndFailPositive);
             }
             if (flag2)
             {
                 this.UpdateSchema();
             }
             else
             {
                 flag = false;
             }
             if (this._lastSchemaChange == new DateTime())
             {
                 this.HasSchemaChanged();
             }
         }
         catch (Exception exception1)
         {
             exception = exception1;
             if (!(!this._repository.DriverLoader.IsInternalAuthor || IsUserError(exception)))
             {
                 Program.ProcessException(exception);
             }
             else
             {
                 Log.Write(exception, "Error opening DataContext");
             }
             lock ((obj2 = this._locker))
             {
                 if (this._worker == Thread.CurrentThread)
                 {
                     this._error = (exception is AccessViolationException) ? "An AccessViolationException was thrown when trying to open the connection." : exception.Message;
                     this._repository.IsAutoGenAssemblyAvailable = false;
                     this._repository.AutoGenAssemblyFailed = true;
                 }
             }
         }
         Delegate[] invocationList = null;
         Delegate[] delegateArray2 = null;
         DataContextInfo dCInfo = null;
         lock ((obj2 = this._locker))
         {
             if (this._worker != Thread.CurrentThread)
             {
                 return;
             }
             this._status = "";
             this._busy = false;
             dCInfo = this.GetDCInfo();
             if (flag && (this._changeSubscribers != null))
             {
                 invocationList = this._changeSubscribers.GetInvocationList();
                 foreach (DataContextCallback callback in this._changeSubscribers.GetInvocationList())
                 {
                     if (this._oneOffSubscribers == null)
                     {
                         break;
                     }
                     this._oneOffSubscribers = (DataContextCallback) Delegate.Remove(this._oneOffSubscribers, callback);
                 }
             }
             if (this._oneOffSubscribers != null)
             {
                 delegateArray2 = this._oneOffSubscribers.GetInvocationList();
             }
             this._oneOffSubscribers = null;
         }
         if (invocationList != null)
         {
             foreach (DataContextCallback callback2 in invocationList)
             {
                 callback2(dCInfo);
             }
         }
         if (delegateArray2 != null)
         {
             foreach (DataContextCallback callback2 in delegateArray2)
             {
                 callback2(dCInfo);
             }
         }
         if (dCInfo.Error != null)
         {
             DataContextManager._globalErrorHandlers(dCInfo);
         }
     }
     catch (Exception exception2)
     {
         exception = exception2;
         Program.ProcessException(exception);
     }
 }
 public void Dispose()
 {
     this._disposed = true;
     this._changeSubscribers = (DataContextCallback) (this._oneOffSubscribers = null);
 }
 public static DataContextManager SubscribeToDataContextChanges(LINQPad.Repository r, DataContextCallback subscription)
 {
     return new DataContextManager(r, subscription);
 }
 public static void SubscribeToAllErrors(DataContextCallback callback)
 {
     _globalErrorHandlers = (DataContextCallback) Delegate.Combine(_globalErrorHandlers, callback);
 }
 private void GetDataContextInfo(DataContextCallback callback, SchemaChangeTestMode schemaTestMode)
 {
     this._runner.Start(callback, schemaTestMode);
 }
 private void GetDataContextInfo(DataContextCallback callback, SchemaChangeTestMode schemaTestMode)
 {
     this._runner.Start(callback, schemaTestMode);
 }