<commit_before>﻿using Microsoft.TeamFoundation.Client;
using NullGuard;
using System;
using System.ComponentModel;
using System.Diagnostics;

namespace GitHub.VisualStudio.Base
{
    public abstract class TeamExplorerBase : IDisposable, INotifyPropertyChanged
    {
        bool subscribed = false;
        bool disposed = false;

        IServiceProvider serviceProvider;
        protected IServiceProvider ServiceProvider
        {
            get { return serviceProvider; }
            set
            {
                if (serviceProvider != null)
                    UnsubscribeContextChanges();
                serviceProvider = value;
                if (serviceProvider != null)
                    SubscribeContextChanges();
            }
        }

        protected ITeamFoundationContext CurrentContext
        {
            get
            {
                var manager = GetService<ITeamFoundationContextManager>();
                if (manager != null)
                    return manager.CurrentContext;
                return null;
            }
        }

        void SubscribeContextChanges()
        {
            Debug.Assert(serviceProvider != null, "ServiceProvider must be set before subscribing to context changes");
            if (serviceProvider == null || subscribed)
                return;

            var manager = GetService<ITeamFoundationContextManager>();
            if (manager != null)
            {
                manager.ContextChanged += ContextChanged;
                subscribed = true;
            }
        }

        void UnsubscribeContextChanges()
        {
            Debug.Assert(serviceProvider != null, "ServiceProvider must be set before subscribing to context changes");
            if (serviceProvider == null || !subscribed)
                return;

            var manager = GetService<ITeamFoundationContextManager>();
            if (manager != null)
            {
                manager.ContextChanged -= ContextChanged;
                subscribed = false;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        ~TeamExplorerBase()
        {
            Dispose(false);
        }

        protected virtual void Dispose(bool disposing)<commit_msg>Thread guard<commit_after>﻿using Microsoft.TeamFoundation.Client;
using NullGuard;
using System;
using System.ComponentModel;
using System.Diagnostics;

namespace GitHub.VisualStudio.Base
{
    public abstract class TeamExplorerBase : IDisposable, INotifyPropertyChanged
    {
        bool subscribed = false;
        bool disposed = false;

        IServiceProvider serviceProvider;
        protected IServiceProvider ServiceProvider
        {
            get { return serviceProvider; }
            set
            {
                if (serviceProvider != null)
                    UnsubscribeContextChanges();
                serviceProvider = value;
                if (serviceProvider != null)
                    SubscribeContextChanges();
            }
        }

        protected ITeamFoundationContext CurrentContext
        {
            get
            {
                var manager = GetService<ITeamFoundationContextManager>();
                if (manager != null)
                    return manager.CurrentContext;
                return null;
            }
        }

        void SubscribeContextChanges()
        {
            Debug.Assert(serviceProvider != null, "ServiceProvider must be set before subscribing to context changes");
            if (serviceProvider == null || subscribed)
                return;

            var manager = GetService<ITeamFoundationContextManager>();
            if (manager != null)
            {
                manager.ContextChanged += ContextChanged;
                subscribed = true;
            }
        }

        void UnsubscribeContextChanges()
        {
            Debug.Assert(serviceProvider != null, "ServiceProvider must be set before subscribing to context changes");
            if (serviceProvider == null || !subscribed)
                return;

            var manager = GetService<ITeamFoundationContextManager>();
            if (manager != null)
            {
                manager.ContextChanged -= ContextChanged;
                subscribed = false;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        ~TeamExplorerBase()
        {
            Dispose(false);
        }

        protected virtual void Dispose(bool disposing)
{'fraction_non_alphanumeric': 0.06864635557269572, 'fraction_numerical': 0.0, 'mean_word_length': 1.6464285714285714, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6195229', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1098, 'n_words': 281}