<commit_before>﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using TCC.Annotations;
using TCC.Data;
using TCC.Data.Skills;

namespace TCC.Controls.Skills
{
    public class SkillControlBase : UserControl, INotifyPropertyChanged
    {
        #region INPC
        public event PropertyChangedEventHandler PropertyChanged;
        [NotifyPropertyChangedInvocator]
        protected virtual void NPC([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
        protected Cooldown Context;
        protected Arc MainArcRef;
        protected Arc PreArcRef;
        protected FrameworkElement ResetArcRef;
        private readonly DoubleAnimation _arcAnimation;

        private bool _isRunning;
        public bool IsRunning
        {
            get => _isRunning;
            set
            {
                if (_isRunning == value) return;
                _isRunning = value;
                NPC();
            }
        }
        public string SecondsText => Context == null ? "0" : Utils.TimeFormatter(Convert.ToUInt32(Context.Seconds > uint.MaxValue ? 0 : Context.Seconds));

        public SkillControlBase()
        {
            _arcAnimation = new DoubleAnimation(359.9, 0, TimeSpan.FromMilliseconds(1));
            Loaded += OnLoaded;
            Unloaded += OnUnloaded;
        }
        protected virtual void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this) || DataContext == null) return;
            Context = (Cooldown)DataContext;
            OnSecondsUpdated();
            if (!Context.IsAvailable)
            {
                OnCooldownStarted(Context.Mode);
            }
            Context.Ended += OnCooldownEnded;
            Context.Started += OnCooldownStarted;
            Context.SecondsUpdated += OnSecondsUpdated;
        }<commit_msg>fix crash if DataContext has been disposed<commit_after>﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using TCC.Annotations;
using TCC.Data;
using TCC.Data.Skills;

namespace TCC.Controls.Skills
{
    public class SkillControlBase : UserControl, INotifyPropertyChanged
    {
        #region INPC
        public event PropertyChangedEventHandler PropertyChanged;
        [NotifyPropertyChangedInvocator]
        protected virtual void NPC([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
        protected Cooldown Context;
        protected Arc MainArcRef;
        protected Arc PreArcRef;
        protected FrameworkElement ResetArcRef;
        private readonly DoubleAnimation _arcAnimation;

        private bool _isRunning;
        public bool IsRunning
        {
            get => _isRunning;
            set
            {
                if (_isRunning == value) return;
                _isRunning = value;
                NPC();
            }
        }
        public string SecondsText => Context == null ? "0" : Utils.TimeFormatter(Convert.ToUInt32(Context.Seconds > uint.MaxValue ? 0 : Context.Seconds));

        public SkillControlBase()
        {
            _arcAnimation = new DoubleAnimation(359.9, 0, TimeSpan.FromMilliseconds(1));
            Loaded += OnLoaded;
            Unloaded += OnUnloaded;
        }
        protected virtual void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this) || !(DataContext is Cooldown)) return;
            Context = (Cooldown)DataContext;
            OnSecondsUpdated();
            if (!Context.IsAvailable)
            {
                OnCooldownStarted(Context.Mode);
            }
            Context.Ended += OnCooldownEnded;
            Context.Started += OnCooldownStarted;
            Context.SecondsUpdated += OnSecondsUpdated;
        }
{'fraction_non_alphanumeric': 0.0765379113018598, 'fraction_numerical': 0.004768717215069146, 'mean_word_length': 2.2294072363356428, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3007335', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1040, 'n_words': 247}