public GeneralChannelViewModel(string name, IChatState chatState)
            : base(chatState)
        {
            try
            {
                Model = ChatModel.CurrentChannels.FirstOrDefault(chan => chan.Id == name)
                        ?? ChatModel.AllChannels.First(chan => chan.Id == name);
                Model.ThrowIfNull("this.Model");

                var safeName = StringExtensions.EscapeSpaces(name);

                Container.RegisterType <object, GeneralChannelView>(safeName, new InjectionConstructor(this));

                isDisplayingChat = ShouldDisplayChat;

                ChannelManagementViewModel = new ChannelManagementViewModel(Events, (GeneralChannelModel)Model);

                // instance our management vm
                Model.Messages.CollectionChanged += OnMessagesChanged;
                Model.Ads.CollectionChanged      += OnAdsChanged;
                Model.PropertyChanged            += OnModelPropertyChanged;

                SearchSettings = new GenericSearchSettingsModel();
                GenderSettings = new GenderSettingsModel();

                messageManager =
                    new FilteredMessageCollection(
                        isDisplayingChat
                            ? Model.Messages
                            : Model.Ads,
                        MeetsFilter,
                        ConstantFilter,
                        IsDisplayingAds);

                GenderSettings.Updated += (s, e) => OnPropertyChanged("GenderSettings");

                SearchSettings.Updated += (s, e) => OnPropertyChanged("SearchSettings");

                messageFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownMessage       = false;
                    messageFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                };

                adFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownAd       = false;
                    adFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                    OnPropertyChanged("CannotPost");
                    OnPropertyChanged("ShouldShowAutoPost");
                    if (autoPostAds)
                    {
                        SendAutoAd();
                    }
                    else
                    {
                        autoPostCount = 0;
                    }
                };

                updateTimer.Elapsed += (s, e) =>
                {
                    if (!Model.IsSelected)
                    {
                        return;
                    }

                    if (CannotPost)
                    {
                        OnPropertyChanged("TimeLeft");
                        OnPropertyChanged("AutoTimeLeft");
                    }

                    OnPropertyChanged("StatusString");
                };

                ChannelManagementViewModel.PropertyChanged += (s, e) => OnPropertyChanged("ChannelManagementViewModel");

                updateTimer.Enabled = true;

                var newSettings = SettingsService.GetChannelSettings(
                    ChatModel.CurrentCharacter.Name, Model.Title, Model.Id, Model.Type);
                Model.Settings = newSettings;

                ChannelSettings.Updated += (s, e) =>
                {
                    OnPropertyChanged("ChannelSettings");
                    OnPropertyChanged("HasNotifyTerms");
                    if (!ChannelSettings.IsChangingSettings)
                    {
                        SettingsService.UpdateSettingsFile(
                            ChannelSettings, ChatModel.CurrentCharacter.Name, Model.Title, Model.Id);
                    }
                };

                PropertyChanged += OnPropertyChanged;

                updateSearch = DeferredAction.Create(() => messageManager.IsFiltering = isSearching);

                Events.GetEvent <NewUpdateEvent>().Subscribe(UpdateChat);

                LoggingSection = "general chan vm";

                if (!string.IsNullOrWhiteSpace(ChannelSettings.LastMessage))
                {
                    Message = ChannelSettings.LastMessage;
                    ChannelSettings.LastMessage = null;
                }
                SearchSettings.ShowOffline = true;

                Application.Current.Dispatcher.Invoke(
                    () => Application.Current.MainWindow.Deactivated += SetLastMessageMark);
            }
            catch (Exception ex)
            {
                ex.Source = "General Channel ViewModel, init";
                Exceptions.HandleException(ex);
            }
        }
Esempio n. 2
0
        public GeneralChannelViewModel(
            string name, IUnityContainer contain, IRegionManager regman, IEventAggregator events, IChatModel cm,
            ICharacterManager manager)
            : base(contain, regman, events, cm, manager)
        {
            try
            {
                Model = ChatModel.CurrentChannels.FirstOrDefault(chan => chan.Id == name)
                        ?? ChatModel.AllChannels.First(chan => chan.Id == name);
                Model.ThrowIfNull("this.Model");

                var safeName = HelperConverter.EscapeSpaces(name);

                Container.RegisterType<object, GeneralChannelView>(safeName, new InjectionConstructor(this));

                isDisplayingChat = ShouldDisplayChat;

                ChannelManagementViewModel = new ChannelManagementViewModel(Events, Model as GeneralChannelModel);

                // instance our management vm
                Model.Messages.CollectionChanged += OnMessagesChanged;
                Model.Ads.CollectionChanged += OnAdsChanged;
                Model.PropertyChanged += OnModelPropertyChanged;

                searchSettings = new GenericSearchSettingsModel();
                genderSettings = new GenderSettingsModel();

                messageManager =
                    new FilteredMessageCollection(
                        isDisplayingChat
                            ? Model.Messages
                            : Model.Ads,
                        MeetsFilter,
                        ConstantFilter,
                        IsDisplayingAds);

                genderSettings.Updated += (s, e) => OnPropertyChanged("GenderSettings");

                SearchSettings.Updated += (s, e) => OnPropertyChanged("SearchSettings");

                messageFlood.Elapsed += (s, e) =>
                    {
                        isInCoolDownMessage = false;
                        messageFlood.Enabled = false;
                        OnPropertyChanged("CanPost");
                    };

                adFlood.Elapsed += (s, e) =>
                    {
                        isInCoolDownAd = false;
                        adFlood.Enabled = false;
                        OnPropertyChanged("CanPost");
                        OnPropertyChanged("CannotPost");
                        OnPropertyChanged("ShouldShowAutoPost");
                        if (autoPostAds)
                            SendAutoAd();
                    };

                update.Elapsed += (s, e) =>
                    {
                        if (!Model.IsSelected)
                            return;

                        if (CannotPost)
                            OnPropertyChanged("TimeLeft");

                        OnPropertyChanged("StatusString");
                    };

                ChannelManagementViewModel.PropertyChanged += (s, e) => OnPropertyChanged("ChannelManagementViewModel");

                update.Enabled = true;

                var newSettings = SettingsService.GetChannelSettings(
                    cm.CurrentCharacter.Name, Model.Title, Model.Id, Model.Type);
                Model.Settings = newSettings;

                ChannelSettings.Updated += (s, e) =>
                    {
                        OnPropertyChanged("ChannelSettings");
                        OnPropertyChanged("HasNotifyTerms");
                        if (!ChannelSettings.IsChangingSettings)
                        {
                            SettingsService.UpdateSettingsFile(
                                ChannelSettings, cm.CurrentCharacter.Name, Model.Title, Model.Id);
                        }
                    };

                PropertyChanged += OnPropertyChanged;

                Events.GetEvent<NewUpdateEvent>().Subscribe(UpdateChat);
            }
            catch (Exception ex)
            {
                ex.Source = "General Channel ViewModel, init";
                Exceptions.HandleException(ex);
            }
        }
        public GeneralChannelViewModel(string name, IChatState chatState)
            : base(chatState)
        {
            try
            {
                Model = ChatModel.CurrentChannels.FirstOrDefault(chan => chan.Id == name)
                        ?? ChatModel.AllChannels.First(chan => chan.Id == name);
                Model.ThrowIfNull("this.Model");

                var safeName = StringExtensions.EscapeSpaces(name);

                Container.RegisterType<object, GeneralChannelView>(safeName, new InjectionConstructor(this));

                isDisplayingChat = ShouldDisplayChat;

                ChannelManagementViewModel = new ChannelManagementViewModel(Events, (GeneralChannelModel) Model);

                // instance our management vm
                Model.Messages.CollectionChanged += OnMessagesChanged;
                Model.Ads.CollectionChanged += OnAdsChanged;
                Model.PropertyChanged += OnModelPropertyChanged;

                SearchSettings = new GenericSearchSettingsModel();
                GenderSettings = new GenderSettingsModel();

                messageManager =
                    new FilteredMessageCollection(
                        isDisplayingChat
                            ? Model.Messages
                            : Model.Ads,
                        MeetsFilter,
                        ConstantFilter,
                        IsDisplayingAds);

                GenderSettings.Updated += (s, e) => OnPropertyChanged("GenderSettings");

                SearchSettings.Updated += (s, e) => OnPropertyChanged("SearchSettings");

                messageFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownMessage = false;
                    messageFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                };

                adFloodTimer.Elapsed += (s, e) =>
                {
                    isInCoolDownAd = false;
                    adFloodTimer.Enabled = false;
                    OnPropertyChanged("CanPost");
                    OnPropertyChanged("CannotPost");
                    OnPropertyChanged("ShouldShowAutoPost");
                    if (autoPostAds)
                        SendAutoAd();
                    else
                        autoPostCount = 0;
                };

                updateTimer.Elapsed += (s, e) =>
                {
                    if (!Model.IsSelected)
                        return;

                    if (CannotPost)
                    {
                        OnPropertyChanged("TimeLeft");
                        OnPropertyChanged("AutoTimeLeft");
                    }

                    OnPropertyChanged("StatusString");
                };

                ChannelManagementViewModel.PropertyChanged += (s, e) => OnPropertyChanged("ChannelManagementViewModel");

                updateTimer.Enabled = true;

                var newSettings = SettingsService.GetChannelSettings(
                    ChatModel.CurrentCharacter.Name, Model.Title, Model.Id, Model.Type);
                Model.Settings = newSettings;

                ChannelSettings.Updated += (s, e) =>
                {
                    OnPropertyChanged("ChannelSettings");
                    OnPropertyChanged("HasNotifyTerms");
                    if (!ChannelSettings.IsChangingSettings)
                    {
                        SettingsService.UpdateSettingsFile(
                            ChannelSettings, ChatModel.CurrentCharacter.Name, Model.Title, Model.Id);
                    }
                };

                PropertyChanged += OnPropertyChanged;

                updateSearch = DeferredAction.Create(() => messageManager.IsFiltering = isSearching);

                Events.GetEvent<NewUpdateEvent>().Subscribe(UpdateChat);

                LoggingSection = "general chan vm";

                if (!string.IsNullOrWhiteSpace(ChannelSettings.LastMessage))
                {
                    Message = ChannelSettings.LastMessage;
                    ChannelSettings.LastMessage = null;
                }
                SearchSettings.ShowOffline = true;

                Application.Current.Dispatcher.Invoke(
                    () => Application.Current.MainWindow.Deactivated += SetLastMessageMark);
            }
            catch (Exception ex)
            {
                ex.Source = "General Channel ViewModel, init";
                Exceptions.HandleException(ex);
            }
        }