Exemplo n.º 1
0
        public void CallbackShouldBeCalledOnceAnyWatchedSettingChanged()
        {
            Settings.Default.Feature_CleanupAllCode      = false;
            Settings.Default.Feature_CleanupOpenCode     = false;
            Settings.Default.Feature_CleanupSelectedCode = true;
            var monitor = new SettingsMonitor <Settings>(Settings.Default);

            bool[] values        = null;
            int    callbackTimes = 0;

            monitor.Watch <bool>(new[] {
                nameof(Settings.Default.Feature_CleanupAllCode),
                nameof(Settings.Default.Feature_CleanupOpenCode),
                nameof(Settings.Default.Feature_CleanupSelectedCode)
            }, v =>
            {
                values = v;
                callbackTimes++;
            });

            Settings.Default.Feature_CleanupSelectedCode = false;
            Settings.Default.Save();

            Assert.AreEqual(/*Initial Call Times*/ 1 + 1, callbackTimes);
            Assert.IsTrue(values.All(v => v == false));
        }
Exemplo n.º 2
0
        public void AllCallbacksShouldBeCalledOnceSettingChanged()
        {
            Settings.Default.Feature_CleanupAllCode = false;
            var monitor = new SettingsMonitor <Settings>(Settings.Default);

            bool?value1 = null, value2 = null;
            int  callbackTimes1 = 0, callbackTimes2 = 0;

            monitor.Watch(s => s.Feature_CleanupAllCode, v =>
            {
                value1 = v;
                callbackTimes1++;
            });
            monitor.Watch(s => s.Feature_CleanupAllCode, v =>
            {
                value2 = v;
                callbackTimes2++;
            });

            Settings.Default.Feature_CleanupAllCode = true;
            Settings.Default.Save();

            Assert.AreEqual(/*Initial Call Times*/ 1 + 1, callbackTimes1);
            Assert.AreEqual(/*Initial Call Times*/ 1 + 1, callbackTimes2);
            Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value1);
            Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value2);
        }
Exemplo n.º 3
0
        public async Task AllCallbacksShouldBeCalledOnceSettingChanged()
        {
            Settings.Default.Feature_CleanupAllCode = false;
            var monitor = new SettingsMonitor <Settings>(Settings.Default, null);

            bool?value1 = null, value2 = null;
            int  callbackTimes1 = 0, callbackTimes2 = 0;
            await monitor.WatchAsync(s => s.Feature_CleanupAllCode, v =>
            {
                value1 = v;
                callbackTimes1++;

                return(Task.CompletedTask);
            });

            await monitor.WatchAsync(s => s.Feature_CleanupAllCode, v =>
            {
                value2 = v;
                callbackTimes2++;

                return(Task.CompletedTask);
            });

            Settings.Default.Feature_CleanupAllCode = true;
            Settings.Default.Save();

            Assert.AreEqual(/*Initial Call Times*/ 1 + 1, callbackTimes1);
            Assert.AreEqual(/*Initial Call Times*/ 1 + 1, callbackTimes2);
            Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value1);
            Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value2);
        }
Exemplo n.º 4
0
        public void CallbackShouldBeCalledAtOnce()
        {
            var monitor = new SettingsMonitor <Settings>(Settings.Default);

            int callbackTimes = 0;

            monitor.Watch(s => s.Feature_CleanupAllCode, _ => callbackTimes++);

            Assert.AreEqual(/*Initial Call Times*/ 1, callbackTimes);
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so
        /// this is the place where you can put all the initialization code that rely on services
        /// provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">
        /// A cancellation token to monitor for initialization cancellation, which can occur when VS
        /// is shutting down.
        /// </param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>
        /// A task representing the async work of package initialization, or an already completed
        /// task if there is none. Do not return null from this method.
        /// </returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            SettingsMonitor = new SettingsMonitor <Settings>(Settings.Default, JoinableTaskFactory);

            await RegisterCommandsAsync();
            await RegisterEventListenersAsync();
        }
Exemplo n.º 6
0
        public async Task CallbackShouldBeCalledAtOnce()
        {
            var monitor = new SettingsMonitor <Settings>(Settings.Default, null);

            int callbackTimes = 0;
            await monitor.WatchAsync(s => s.Feature_CleanupAllCode, _ =>
            {
                callbackTimes++;

                return(Task.CompletedTask);
            });

            Assert.AreEqual(/*Initial Call Times*/ 1, callbackTimes);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Default constructor of the package. Inside this method you can place any initialization
        /// code that does not require any Visual Studio service because at this point the package
        /// object is created but not sited yet inside Visual Studio environment. The place to do
        /// all the other initialization is the Initialize method.
        /// </summary>
        public CodeMaidPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this));

            if (Application.Current != null)
            {
                Application.Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
            }

            // If an existing user settings file cannot be found, perform a one-time settings upgrade.
            if (!File.Exists(SettingsContextHelper.GetUserSettingsPath()))
            {
                Settings.Default.Upgrade();
                Settings.Default.Save();
            }

            SettingsMonitor = new SettingsMonitor <Settings>(Settings.Default);
        }
Exemplo n.º 8
0
        public void CallbackShouldNotBeCalledIfSettingNotChanged()
        {
            Settings.Default.Feature_CleanupAllCode = false;
            var monitor = new SettingsMonitor <Settings>(Settings.Default);

            bool?value         = null;
            int  callbackTimes = 0;

            monitor.Watch(s => s.Feature_CleanupAllCode, v =>
            {
                value = v;
                callbackTimes++;
            });

            Settings.Default.Feature_CleanupAllCode = false;
            Settings.Default.Save();

            Assert.AreEqual(/*Initial Call Times*/ 1 + 0, callbackTimes);
            Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value);
        }
Exemplo n.º 9
0
        public async Task CallbackShouldNotBeCalledIfSettingNotChanged()
        {
            Settings.Default.Feature_CleanupAllCode = false;
            var monitor = new SettingsMonitor <Settings>(Settings.Default, null);

            bool?value         = null;
            int  callbackTimes = 0;
            await monitor.WatchAsync(s => s.Feature_CleanupAllCode, v =>
            {
                value = v;
                callbackTimes++;

                return(Task.CompletedTask);
            });

            Settings.Default.Feature_CleanupAllCode = false;
            Settings.Default.Save();

            Assert.AreEqual(/*Initial Call Times*/ 1 + 0, callbackTimes);
            Assert.AreEqual(Settings.Default.Feature_CleanupAllCode, value);
        }