コード例 #1
0
        private void DefaultInterpreterRegistry_Changed(object sender, RegistryChangedEventArgs e)
        {
#if !DEV12_OR_LATER
            // Pre-VS 2013 has trouble obtaining services from the original
            // thread, so attempt to get back to the thread we started on.
            if (_serviceContext != null && Thread.CurrentThread != _serviceThread)
            {
                _serviceContext.Post(_ => DefaultInterpreterRegistry_Changed(sender, e), null);
                return;
            }
#endif
            try {
                LoadDefaultInterpreter();
            } catch (InvalidComObjectException) {
                // Race between VS closing and accessing the settings store.
            } catch (Exception ex) {
                try {
                    ActivityLog.LogError(
                        "Python Tools for Visual Studio",
                        string.Format("Exception updating default interpreter: {0}", ex)
                        );
                } catch (InvalidOperationException) {
                    // Can't get the activity log service either. This probably
                    // means we're being used from outside of VS, but also
                    // occurs during some unit tests. We want to debug this if
                    // possible, but generally avoid crashing.
                    Debug.Fail(ex.ToString());
                }
            }
        }
コード例 #2
0
 private static bool Exists(RegistryChangedEventArgs e)
 {
     using (var root = RegistryKey.OpenBaseKey(e.Hive, e.View))
         using (var key = root.OpenSubKey(e.Key)) {
             return(key != null);
         }
 }
コード例 #3
0
        public void RegistryWatcherDeleteRecursive()
        {
            string keyName = "RegistryWatcherDeleteRecursive";

            SetValue(keyName, "TestValue1", "ABC");
            SetValue(keyName, "TestValue2", "DEF");
            SetValue(keyName, "TestValue3", "GHI");
            SetValue(keyName + "\\TestKey1", "Value", 123);
            SetValue(keyName + "\\TestKey2", "Value", 456);

            using (var watcher = new RegistryWatcher())
            {
                RegistryChangedEventArgs args = null;
                var argsSet = new ManualResetEventSlim();

                var watch1 = AddWatch(watcher, keyName,
                                      e => { args = e; argsSet.Set(); },
                                      recursive: true);

                // Value is deleted
                DeleteValue(keyName, "TestValue2");
                Assert.IsTrue(argsSet.Wait(TIMEOUT));
                Assert.IsNotNull(args);
                Assert.AreEqual(GetKey(keyName), args.Key);
                argsSet.Reset();
                args = null;

                // Value in subkey is deleted
                DeleteValue(keyName + "\\TestKey1", "Value");
                Assert.IsTrue(argsSet.Wait(TIMEOUT));
                Assert.IsNotNull(args);
                Assert.AreEqual(GetKey(keyName), args.Key);
                argsSet.Reset();
                args = null;

                // Subkey is deleted
                DeleteKey(keyName + "\\TestKey1");
                Assert.IsTrue(argsSet.Wait(TIMEOUT));
                Assert.IsNotNull(args);
                Assert.AreEqual(GetKey(keyName), args.Key);
                argsSet.Reset();
                args = null;

                watcher.Remove(watch1);

                // Another value is deleted, but we don't get notified
                DeleteValue(keyName, "TestValue3");
                Assert.IsFalse(argsSet.Wait(TIMEOUT));
                Assert.IsNull(args);

                // Another key is deleted, but we don't get notified
                DeleteKey(keyName + "\\TestKey2");
                Assert.IsFalse(argsSet.Wait(TIMEOUT));
                Assert.IsNull(args);
            }
        }
コード例 #4
0
 private void Registry_PythonCorePath_Changed(object sender, RegistryChangedEventArgs e) {
     if (!Exists(e)) {
         // PythonCore key no longer exists, so go back to watching
         // Python.
         e.CancelWatcher = true;
         StartWatching(e.Hive, e.View);
     } else {
         DiscoverInterpreterFactories();
     }
 }
コード例 #5
0
 private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e)
 {
     if (RegistryWatcher.Instance.TryAdd(
             e.Hive, e.View, IronPythonCorePath, Registry_Changed,
             recursive: true, notifyValueChange: true, notifyKeyChange: true
             ) != null)
     {
         e.CancelWatcher = true;
         Registry_Changed(sender, e);
     }
 }
コード例 #6
0
 private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e)
 {
     using (var root = RegistryKey.OpenBaseKey(e.Hive, e.View))
         using (var key = root.OpenSubKey(IronPythonCorePath)) {
             if (key != null)
             {
                 RegistryWatcher.Instance.Add(e.Hive, e.View, IronPythonCorePath, Registry_Changed,
                                              recursive: true, notifyValueChange: true, notifyKeyChange: true);
                 e.CancelWatcher = true;
                 Registry_Changed(sender, e);
             }
         }
 }
コード例 #7
0
        public void RegistryWatcher100Keys()
        {
            string keyName = "RegistryWatcher100Keys";

            for (int i = 0; i < 100; ++i)
            {
                SetValue(string.Format("{0}\\Key{1}", keyName, i), "Value", "ABC");
            }

            using (var watcher = new RegistryWatcher())
            {
                RegistryChangedEventArgs[] args = new RegistryChangedEventArgs[100];
                var argsSet = args.Select(_ => new ManualResetEventSlim()).ToArray();
                global::System.Object[] tokens = new object[100];

                for (int i = 0; i < 100; ++i)
                {
                    tokens[i] = AddWatch(watcher, string.Format("{0}\\Key{1}", keyName, i),
                                         new ArgSetter(args, argsSet, i).Raised);
                }

                // Change the first value
                SetValue(keyName + "\\Key0", "Value", "DEF");
                Assert.IsTrue(argsSet[0].Wait(TIMEOUT));
                Assert.IsNotNull(args[0]);
                Assert.AreEqual(GetKey(keyName + "\\Key0"), args[0].Key);
                argsSet[0].Reset();
                args[0] = null;

                // Change the last value
                SetValue(keyName + "\\Key99", "Value", "DEF");
                Assert.IsTrue(argsSet[99].Wait(TIMEOUT));
                Assert.IsNotNull(args[99]);
                Assert.AreEqual(GetKey(keyName + "\\Key99"), args[99].Key);
                argsSet[99].Reset();
                args[99] = null;

                watcher.Remove(tokens[0]);
                watcher.Remove(tokens[99]);

                // Change the first value
                SetValue(keyName + "\\Key0", "Value", "GHI");
                Assert.IsFalse(argsSet[0].Wait(TIMEOUT));
                Assert.IsNull(args[0]);

                // Change the last value
                SetValue(keyName + "\\Key99", "Value", "GHI");
                Assert.IsFalse(argsSet[99].Wait(TIMEOUT));
                Assert.IsNull(args[99]);
            }
        }
コード例 #8
0
        public void RegistryWatcherUpdateRecursive()
        {
            string keyName = "RegistryWatcherUpdateRecursive";

            SetValue(keyName, "TestValue", "ABC");
            SetValue(keyName + "\\TestKey", "Value", 123);

            using (var watcher = new RegistryWatcher())
            {
                RegistryChangedEventArgs args = null;
                var argsSet = new ManualResetEventSlim();

                var watch1 = AddWatch(watcher, keyName,
                                      e => { args = e; argsSet.Set(); },
                                      recursive: true);

                // Value is set, but does not actually change
                SetValue(keyName, "TestValue", "ABC");
                Assert.IsFalse(argsSet.Wait(TIMEOUT));
                Assert.IsNull(args);

                // Value is changed
                SetValue(keyName, "TestValue", "DEF");
                Assert.IsTrue(argsSet.Wait(TIMEOUT));
                Assert.IsNotNull(args);
                Assert.AreEqual(GetKey(keyName), args.Key);
                argsSet.Reset();
                args = null;

                // Value in subkey is changed
                SetValue(keyName + "\\TestKey", "Value", 456);
                Assert.IsTrue(argsSet.Wait(TIMEOUT));
                Assert.IsNotNull(args);
                Assert.AreEqual(GetKey(keyName), args.Key);
                argsSet.Reset();
                args = null;

                watcher.Remove(watch1);

                // Value is changed back, but we don't get notified
                SetValue(keyName, "TestValue", "ABC");
                Assert.IsFalse(argsSet.Wait(TIMEOUT));
                Assert.IsNull(args);

                // Value in subkey is changed back, but we don't notice
                SetValue(keyName + "\\TestKey", "Value", 123);
                Assert.IsFalse(argsSet.Wait(TIMEOUT));
                Assert.IsNull(args);
            }
        }
コード例 #9
0
 private void Registry_PythonCorePath_Changed(object sender, RegistryChangedEventArgs e)
 {
     if (!Exists(e))
     {
         // PythonCore key no longer exists, so go back to watching
         // Python.
         e.CancelWatcher = true;
         StartWatching(e.Hive, e.View);
     }
     else
     {
         DiscoverInterpreterFactories();
     }
 }
コード例 #10
0
 private void Registry_PythonPath_Changed(object sender, RegistryChangedEventArgs e)
 {
     if (!Exists(e))
     {
         // Python key no longer exists, so go back to watching
         // Software.
         e.CancelWatcher = true;
         _registryTags.Remove(e.Tag);
         _registryTags.Add(StartWatching(e.Hive, e.View));
     }
     else
     {
         DiscoverInterpreterFactories();
     }
 }
コード例 #11
0
        private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e)
        {
            Registry_PythonPath_Changed(sender, e);
            if (e.CancelWatcher)
            {
                // Python key no longer exists, we're still watching Software
                return;
            }

            if (RegistryWatcher.Instance.TryAdd(
                    e.Hive, e.View, PythonPath, Registry_PythonPath_Changed,
                    recursive: true, notifyValueChange: true, notifyKeyChange: true
                    ) != null)
            {
                // Python exists, we no longer need to watch Software
                e.CancelWatcher = true;
            }
        }
コード例 #12
0
 private void Registry_PythonPath_Changed(object sender, RegistryChangedEventArgs e) {
     if (Exists(e)) {
         if (RegistryWatcher.Instance.TryAdd(
             e.Hive, e.View, PythonCorePath, Registry_PythonCorePath_Changed,
             recursive: true, notifyValueChange: true, notifyKeyChange: true
         ) != null) {
             // PythonCore key now exists, so start watching it,
             // discover any interpreters, and cancel this watcher.
             e.CancelWatcher = true;
             DiscoverInterpreterFactories();
         }
     } else {
         // Python key no longer exists, so go back to watching
         // Software.
         e.CancelWatcher = true;
         StartWatching(e.Hive, e.View);
     }
 }
コード例 #13
0
 private void Registry_Changed(object sender, RegistryChangedEventArgs e)
 {
     if (!Exists(e))
     {
         // IronPython key no longer exists, so go back to watching
         // Software.
         RegistryWatcher.Instance.Add(RegistryHive.LocalMachine, RegistryView.Registry32, "Software",
                                      Registry_Software_Changed,
                                      recursive: false, notifyValueChange: false, notifyKeyChange: true);
         e.CancelWatcher = true;
     }
     else
     {
         DiscoverInterpreterFactories();
         if (_interpreter != null)
         {
             e.CancelWatcher = true;
         }
     }
 }
コード例 #14
0
        private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e)
        {
            Registry_PythonPath_Changed(sender, e);
            if (e.CancelWatcher)
            {
                // PythonCore key also exists and is now being watched, so just
                // return.
                return;
            }

            if (RegistryWatcher.Instance.TryAdd(
                    e.Hive, e.View, PythonPath, Registry_PythonPath_Changed,
                    recursive: false, notifyValueChange: false, notifyKeyChange: true
                    ) != null)
            {
                // Python exists, but not PythonCore, so watch Python until
                // PythonCore is created.
                e.CancelWatcher = true;
            }
        }
コード例 #15
0
 private void DefaultInterpreterRegistry_Changed(object sender, RegistryChangedEventArgs e)
 {
     try {
         LoadDefaultInterpreter();
     } catch (InvalidComObjectException) {
         // Race between VS closing and accessing the settings store.
     } catch (Exception ex) {
         try {
             //ActivityLog.LogError(
             //    "Python Tools for Visual Studio",
             //    string.Format("Exception updating default interpreter: {0}", ex)
             //);
         } catch (InvalidOperationException) {
             // Can't get the activity log service either. This probably
             // means we're being used from outside of VS, but also
             // occurs during some unit tests. We want to debug this if
             // possible, but generally avoid crashing.
             Debug.Fail(ex.ToString());
         }
     }
 }
 private void Registry_PythonPath_Changed(object sender, RegistryChangedEventArgs e)
 {
     using (var root = RegistryKey.OpenBaseKey(e.Hive, e.View))
         using (var key = root.OpenSubKey(PythonCorePath)) {
             if (key != null)
             {
                 // PythonCore key now exists, so start watching it and also
                 // discover any interpreters.
                 RegistryWatcher.Instance.Add(e.Hive, e.View, PythonCorePath, Registry_PythonCorePath_Changed,
                                              recursive: true, notifyValueChange: true, notifyKeyChange: true);
                 e.CancelWatcher = true;
                 DiscoverInterpreterFactories();
             }
             else if (!Exists(e))
             {
                 // Python key no longer exists, so go back to watching
                 // Software.
                 e.CancelWatcher = true;
                 StartWatching(e.Hive, e.View);
             }
         }
 }
        private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e)
        {
            Registry_PythonPath_Changed(sender, e);
            if (e.CancelWatcher)
            {
                // PythonCore key also exists and is now being watched, so just
                // return.
                return;
            }

            using (var root = RegistryKey.OpenBaseKey(e.Hive, e.View))
                using (var key = root.OpenSubKey(PythonPath)) {
                    if (key != null)
                    {
                        // Python exists, but not PythonCore, so watch Python until
                        // PythonCore is created.
                        RegistryWatcher.Instance.Add(e.Hive, e.View, PythonPath, Registry_PythonPath_Changed,
                                                     recursive: false, notifyValueChange: false, notifyKeyChange: true);
                        e.CancelWatcher = true;
                    }
                }
        }
コード例 #18
0
 private void Registry_PythonPath_Changed(object sender, RegistryChangedEventArgs e)
 {
     if (Exists(e))
     {
         if (RegistryWatcher.Instance.TryAdd(
                 e.Hive, e.View, PythonCorePath, Registry_PythonCorePath_Changed,
                 recursive: true, notifyValueChange: true, notifyKeyChange: true
                 ) != null)
         {
             // PythonCore key now exists, so start watching it,
             // discover any interpreters, and cancel this watcher.
             e.CancelWatcher = true;
             DiscoverInterpreterFactories();
         }
     }
     else
     {
         // Python key no longer exists, so go back to watching
         // Software.
         e.CancelWatcher = true;
         StartWatching(e.Hive, e.View);
     }
 }
コード例 #19
0
        private void DefaultInterpreterRegistry_Changed(object sender, RegistryChangedEventArgs e) {
#if !DEV12_OR_LATER
            // Pre-VS 2013 has trouble obtaining services from the original
            // thread, so attempt to get back to the thread we started on.
            if (_serviceContext != null && Thread.CurrentThread != _serviceThread) {
                _serviceContext.Post(_ => DefaultInterpreterRegistry_Changed(sender, e), null);
                return;
            }
#endif
            try {
                LoadDefaultInterpreter();
            } catch (InvalidComObjectException) {
                // Race between VS closing and accessing the settings store.
            } catch (Exception ex) {
                try {
                    ActivityLog.LogError(
                        "Python Tools for Visual Studio",
                        string.Format("Exception updating default interpreter: {0}", ex)
                    );
                } catch (InvalidOperationException) {
                    // Can't get the activity log service either. This probably
                    // means we're being used from outside of VS, but also
                    // occurs during some unit tests. We want to debug this if
                    // possible, but generally avoid crashing.
                    Debug.Fail(ex.ToString());
                }
            }
        }
コード例 #20
0
 private void ChangedActivePowerScheme(object sender, RegistryChangedEventArgs e)
 {
     UpdateIcon();
 }
コード例 #21
0
 private static bool Exists(RegistryChangedEventArgs e) {
     using (var root = RegistryKey.OpenBaseKey(e.Hive, e.View))
     using (var key = root.OpenSubKey(e.Key)) {
         return key != null;
     }
 }
コード例 #22
0
        private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e) {
            Registry_PythonPath_Changed(sender, e);
            if (e.CancelWatcher) {
                // PythonCore key also exists and is now being watched, so just
                // return.
                return;
            }

            if (RegistryWatcher.Instance.TryAdd(
                e.Hive, e.View, PythonPath, Registry_PythonPath_Changed,
                recursive: false, notifyValueChange: false, notifyKeyChange: true
            ) != null) {
                // Python exists, but not PythonCore, so watch Python until
                // PythonCore is created.
                e.CancelWatcher = true;
            }
        }
コード例 #23
0
 public void Raised(RegistryChangedEventArgs e)
 {
     Args[Index] = e;
     ArgsSet[Index].Set();
 }
コード例 #24
0
        private void Registry_Software_Changed(object sender, RegistryChangedEventArgs e) {
            Registry_PythonPath_Changed(sender, e);
            if (e.CancelWatcher) {
                // Python key no longer exists, we're still watching Software
                return;
            }

            if (RegistryWatcher.Instance.TryAdd(
                e.Hive, e.View, PythonPath, Registry_PythonPath_Changed,
                recursive: true, notifyValueChange: true, notifyKeyChange: true
            ) != null) {
                // Python exists, we no longer need to watch Software
                e.CancelWatcher = true;
            }
        }
コード例 #25
0
 private void DefaultInterpreterRegistry_Changed(object sender, RegistryChangedEventArgs e) {
     try {
         LoadDefaultInterpreter();
     } catch (InvalidComObjectException) {
         // Race between VS closing and accessing the settings store.
     } catch (Exception ex) {
         try {
             //ActivityLog.LogError(
             //    "Python Tools for Visual Studio",
             //    string.Format("Exception updating default interpreter: {0}", ex)
             //);
         } catch (InvalidOperationException) {
             // Can't get the activity log service either. This probably
             // means we're being used from outside of VS, but also
             // occurs during some unit tests. We want to debug this if
             // possible, but generally avoid crashing.
             Debug.Fail(ex.ToString());
         }
     }
 }