Example #1
0
 private void EnsureNotificationContactFilter()
 {
     if (_notificationContactFilter == null)
     {
         using (ConfigurationServiceAgent configurationAgent = new ConfigurationServiceAgent())
         {
             _notificationContactFilter = new AddressList(
                 configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnNotificationFilterList, false));
         }
     }
 }
Example #2
0
        private void ValidateContacts()
        {
            Logger.Verbose("Validating Windows Live contacts...");

            bool reconnect = false;

            using (ConfigurationServiceAgent configurationAgent = new ConfigurationServiceAgent())
            {
                AddressList contactAddresses = new AddressList(
                    configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnContactList, false));

                List <Contact> contactsToRemove = new List <Contact>();
                foreach (Contact contact in _messenger.ContactList.Allowed)
                {
                    if (!contactAddresses.Contains(contact.Account))
                    {
                        contactsToRemove.Add(contact);
                    }
                }
                foreach (Contact contact in contactsToRemove)
                {
                    if (contact.Guid != Guid.Empty)
                    {
                        contact.AppearOffline = true;
                        Logger.Write("Blocked contact: " + contact.Account);
                    }
                }

                foreach (string mailAddress in contactAddresses)
                {
                    Contact contact = FindContactInList(mailAddress);
                    if (contact == null ||
                        contact.Guid == Guid.Empty)
                    {
                        _messenger.ContactService.AddNewContact(mailAddress, "ARGUS TV is inviting you.");
                        Logger.Write("Invited contact: " + contact.Account);
                        reconnect = true;
                    }
                    else if (contact.AppearOffline)
                    {
                        contact.AppearOffline = false;
                        Logger.Write("Unblocked contact: " + contact.Account);
                        reconnect = true;
                    }
                }
            }

            if (reconnect)
            {
                Thread.Sleep(1000);
                DisconnectMessenger();
            }
        }
Example #3
0
        protected override void Run()
        {
            Logger.Write(_threadName + " thread started.");

            _wakeUpEvent = new AutoResetEvent(false);
            try
            {
                Logger.Write("Starting service.");

                _messenger.ConnectionEstablished              += NameserverProcessor_ConnectionEstablished;
                _messenger.ConnectingException                += NameserverProcessor_ConnectingException;
                _messenger.Nameserver.ExceptionOccurred       += Nameserver_ExceptionOccurred;
                _messenger.Nameserver.AuthenticationError     += Nameserver_AuthenticationError;
                _messenger.Nameserver.ServerErrorReceived     += Nameserver_ServerErrorReceived;
                _messenger.Nameserver.SignedIn                += Nameserver_SignedIn;
                _messenger.MessageManager.TextMessageReceived += MessageManager_TextMessageReceived;
                _messenger.Nameserver.ContactOnline           += Nameserver_ContactOnline;
                _messenger.Nameserver.ContactOffline          += Nameserver_ContactOffline;

                _nextPersonalMessageRefreshTime = DateTime.Now.AddSeconds(5);
                _nextAlertsCheckTime            = DateTime.Now.AddSeconds(_checkAlertsIntervalSeconds);
                do
                {
                    try
                    {
                        EnsureArgusTVConnection();
                        if (ServiceChannelFactories.IsInitialized)
                        {
                            EnsureEventsListenerService();

                            if (_messenger.Connected)
                            {
                                if (_messenger.Nameserver.IsSignedIn)
                                {
                                    if (_refreshMessageAndStatus)
                                    {
                                        RefreshBotPersonalMessage();
                                        _refreshMessageAndStatus = false;
                                    }

                                    // If needed, make sure our contact list is up-to-date.
                                    if (!_contactsValidated)
                                    {
                                        ValidateContacts();
                                        _contactsValidated = true;
                                    }

                                    if (DateTime.Now >= _nextPersonalMessageRefreshTime)
                                    {
                                        _nextPersonalMessageRefreshTime = DateTime.MaxValue;
                                        RefreshBotPersonalMessage();
                                    }

                                    if (_messenger.Owner.Name != "ARGUS TV")
                                    {
                                        _messenger.Owner.Name = "ARGUS TV";
                                    }

                                    if (DateTime.Now >= _nextAlertsCheckTime)
                                    {
                                        HandleAlerts();
                                        _nextAlertsCheckTime = DateTime.Now.AddSeconds(_checkAlertsIntervalSeconds);
                                    }
                                }
                                else
                                {
                                    //Logger.Verbose("Connected to Windows Live, but not signed in yet...");
                                }
                            }
                            else
                            {
                                using (ConfigurationServiceAgent configurationAgent = new ConfigurationServiceAgent())
                                {
                                    _messenger.Credentials.Account =
                                        configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnAccount, false);
                                    _messenger.Credentials.Password =
                                        configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnPassword, false);
                                    if (!String.IsNullOrEmpty(_messenger.Credentials.Account))
                                    {
                                        Logger.Info("Connecting to Windows Live as '{0}'...", _messenger.Credentials.Account);
                                        _messenger.Connect();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.ToString());
                        if (_messenger.Connected)
                        {
                            DisconnectMessenger();
                        }
                    }
                } while (0 != WaitHandle.WaitAny(new WaitHandle[] { this.StopThreadEvent, _wakeUpEvent }, 1000, false));

                StopEventsListenerService();
                if (_messenger.Connected)
                {
                    DisconnectMessenger();
                }

                Logger.Write("Service ended.");
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                using (ServiceController controller = new ServiceController("ArgusTVMessenger"))
                {
                    try { controller.Stop(); }
                    catch { }
                }
            }
            finally
            {
                _wakeUpEvent.Close();
                _wakeUpEvent = null;
            }

            Logger.Write(_threadName + " thread ended.");
        }
Example #4
0
        private void ValidateContacts()
        {
            Logger.Verbose("Validating Windows Live contacts...");

            bool reconnect = false;

            using (ConfigurationServiceAgent configurationAgent = new ConfigurationServiceAgent())
            {
                AddressList contactAddresses = new AddressList(
                    configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnContactList, false));

                List<Contact> contactsToRemove = new List<Contact>();
                foreach (Contact contact in _messenger.ContactList.Allowed)
                {
                    if (!contactAddresses.Contains(contact.Account))
                    {
                        contactsToRemove.Add(contact);
                    }
                }
                foreach (Contact contact in contactsToRemove)
                {
                    if (contact.Guid != Guid.Empty)
                    {
                        contact.AppearOffline = true;
                        Logger.Write("Blocked contact: " + contact.Account);
                    }
                }

                foreach (string mailAddress in contactAddresses)
                {
                    Contact contact = FindContactInList(mailAddress);
                    if (contact == null
                        || contact.Guid == Guid.Empty)
                    {
                        _messenger.ContactService.AddNewContact(mailAddress, "ARGUS TV is inviting you.");
                        Logger.Write("Invited contact: " + contact.Account);
                        reconnect = true;
                    }
                    else if (contact.AppearOffline)
                    {
                        contact.AppearOffline = false;
                        Logger.Write("Unblocked contact: " + contact.Account);
                        reconnect = true;
                    }
                }
            }

            if (reconnect)
            {
                Thread.Sleep(1000);
                DisconnectMessenger();
            }
        }
Example #5
0
 private void EnsureNotificationContactFilter()
 {
     if (_notificationContactFilter == null)
     {
         using (ConfigurationServiceAgent configurationAgent = new ConfigurationServiceAgent())
         {
             _notificationContactFilter = new AddressList(
                 configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnNotificationFilterList, false));
         }
     }
 }
Example #6
0
        protected override void Run()
        {
            Logger.Write(_threadName + " thread started.");

            _wakeUpEvent = new AutoResetEvent(false);
            try
            {
                Logger.Write("Starting service.");

                _messenger.ConnectionEstablished += NameserverProcessor_ConnectionEstablished;
                _messenger.ConnectingException += NameserverProcessor_ConnectingException;
                _messenger.Nameserver.ExceptionOccurred += Nameserver_ExceptionOccurred;
                _messenger.Nameserver.AuthenticationError += Nameserver_AuthenticationError;
                _messenger.Nameserver.ServerErrorReceived += Nameserver_ServerErrorReceived;
                _messenger.Nameserver.SignedIn += Nameserver_SignedIn;
                _messenger.MessageManager.TextMessageReceived += MessageManager_TextMessageReceived;
                _messenger.Nameserver.ContactOnline += Nameserver_ContactOnline;
                _messenger.Nameserver.ContactOffline += Nameserver_ContactOffline;

                _nextPersonalMessageRefreshTime = DateTime.Now.AddSeconds(5);
                _nextAlertsCheckTime = DateTime.Now.AddSeconds(_checkAlertsIntervalSeconds);
                do
                {
                    try
                    {
                        EnsureArgusTVConnection();
                        if (ServiceChannelFactories.IsInitialized)
                        {
                            EnsureEventsListenerService();

                            if (_messenger.Connected)
                            {
                                if (_messenger.Nameserver.IsSignedIn)
                                {
                                    if (_refreshMessageAndStatus)
                                    {
                                        RefreshBotPersonalMessage();
                                        _refreshMessageAndStatus = false;
                                    }

                                    // If needed, make sure our contact list is up-to-date.
                                    if (!_contactsValidated)
                                    {
                                        ValidateContacts();
                                        _contactsValidated = true;
                                    }

                                    if (DateTime.Now >= _nextPersonalMessageRefreshTime)
                                    {
                                        _nextPersonalMessageRefreshTime = DateTime.MaxValue;
                                        RefreshBotPersonalMessage();
                                    }

                                    if (_messenger.Owner.Name != "ARGUS TV")
                                    {
                                        _messenger.Owner.Name = "ARGUS TV";
                                    }

                                    if (DateTime.Now >= _nextAlertsCheckTime)
                                    {
                                        HandleAlerts();
                                        _nextAlertsCheckTime = DateTime.Now.AddSeconds(_checkAlertsIntervalSeconds);
                                    }
                                }
                                else
                                {
                                    //Logger.Verbose("Connected to Windows Live, but not signed in yet...");
                                }
                            }
                            else
                            {
                                using (ConfigurationServiceAgent configurationAgent = new ConfigurationServiceAgent())
                                {
                                    _messenger.Credentials.Account =
                                        configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnAccount, false);
                                    _messenger.Credentials.Password =
                                        configurationAgent.GetStringValue(ConfigurationModule.Messenger, ConfigurationKey.Messenger.MsnPassword, false);
                                    if (!String.IsNullOrEmpty(_messenger.Credentials.Account))
                                    {
                                        Logger.Info("Connecting to Windows Live as '{0}'...", _messenger.Credentials.Account);
                                        _messenger.Connect();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.ToString());
                        if (_messenger.Connected)
                        {
                            DisconnectMessenger();
                        }
                    }
                } while (0 != WaitHandle.WaitAny(new WaitHandle[] { this.StopThreadEvent, _wakeUpEvent }, 1000, false));

                StopEventsListenerService();
                if (_messenger.Connected)
                {
                    DisconnectMessenger();
                }

                Logger.Write("Service ended.");
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                using (ServiceController controller = new ServiceController("ArgusTVMessenger"))
                {
                    try { controller.Stop(); }
                    catch { }
                }
            }
            finally
            {
                _wakeUpEvent.Close();
                _wakeUpEvent = null;
            }

            Logger.Write(_threadName + " thread ended.");
        }
Example #7
0
        private void LoadSettings()
        {
            Log.Debug("ServerSettingsBase: LoadSettings()");
            bool?_autoCreateThumbs         = ConfigurationServiceAgent.GetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.CreateVideoThumbnails, true);
            bool?_metaDataForRecs          = ConfigurationServiceAgent.GetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.AlwaysCreateMetadataFiles, true);
            bool?_swapTunerPriority        = ConfigurationServiceAgent.GetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.SwapRecorderTunerPriorityForRecordings, true);
            bool?_autoCombineConsecutive   = ConfigurationServiceAgent.GetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.AutoCombineConsecutiveRecordings, true);
            bool?_combineConsecutive       = ConfigurationServiceAgent.GetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.CombineConsecutiveRecordings, true);
            bool?_combineOnlyOnSameChannel = ConfigurationServiceAgent.GetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.CombineRecordingsOnlyOnSameChannel, true);

            int?_preRecord        = ConfigurationServiceAgent.GetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.PreRecordsSeconds, true);
            int?_postRecord       = ConfigurationServiceAgent.GetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.PostRecordsSeconds, true);
            int?_keepUntilValue   = ConfigurationServiceAgent.GetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.DefaultKeepUntilValue, true);
            int?_freeDiskSpace    = ConfigurationServiceAgent.GetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.FreeDiskSpaceInMB, true);
            int?_minFreeDiskSpace = ConfigurationServiceAgent.GetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.MinimumFreeDiskSpaceInMB, true);

            string _keepUntilMode = ConfigurationServiceAgent.GetStringValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.DefaultKeepUntilMode, true);
            string _guideSource   = ConfigurationServiceAgent.GetStringValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.PreferredGuideSource, true);

            if (_autoCreateThumbs.HasValue)
            {
                _autoCreateThumbsButton.Selected = _autoCreateThumbs.Value;
            }
            if (_metaDataForRecs.HasValue)
            {
                _metaDataForRecsButton.Selected = _metaDataForRecs.Value;
            }
            if (_keepUntilValue.HasValue)
            {
                _currentKeepUntilValue = _keepUntilValue.Value;
            }
            if (_keepUntilMode != string.Empty)
            {
                _currentKeepUntilMode = GetKeepUntilModeFromString(_keepUntilMode);
            }
            if (_guideSource != string.Empty)
            {
                _currentGuideSource = GetGuideSourceFromString(_guideSource);
            }

            _autoCreateThumbsButton.IsEnabled     = _autoCreateThumbs.HasValue;
            _metaDataForRecsButton.IsEnabled      = _metaDataForRecs.HasValue;
            _preRecordButton.IsEnabled            = _preRecord.HasValue;
            _postRecordButton.IsEnabled           = _postRecord.HasValue;
            _keepUntilValueButton.IsEnabled       = _keepUntilValue.HasValue;
            _freeDiskSpaceSpinButton.IsEnabled    = _freeDiskSpace.HasValue;
            _minFreeDiskSpaceSpinButton.IsEnabled = _minFreeDiskSpace.HasValue;

            if (_preRecord.HasValue)
            {
                int  prerec           = _preRecord.Value / 60;
                bool valueFoundInList = false;

                for (int i = 0; i <= 60; i++)
                {
                    _preRecordButton.AddSpinLabel(i.ToString(), 0);
                    if (i == prerec)
                    {
                        valueFoundInList = true;
                    }
                }

                if (valueFoundInList)
                {
                    _preRecordButton.SpinValue = prerec;
                }
                else
                {
                    _preRecordButton.AddSpinLabel(prerec.ToString(), 0);
                    _preRecordButton.SpinValue = _preRecordButton.SpinMaxValue() - 1;
                }
            }
            if (_postRecord.HasValue)
            {
                int  postrec          = _postRecord.Value / 60;
                bool valueFoundInList = false;

                for (int i = 0; i <= 60; i++)
                {
                    _postRecordButton.AddSpinLabel(i.ToString(), 0);
                    if (i == postrec)
                    {
                        valueFoundInList = true;
                    }
                }

                if (valueFoundInList)
                {
                    _postRecordButton.SpinValue = postrec;
                }
                else
                {
                    _postRecordButton.AddSpinLabel(postrec.ToString(), 0);
                    _postRecordButton.SpinValue = _postRecordButton.SpinMaxValue() - 1;
                }
            }
            if (_freeDiskSpace.HasValue)
            {
                int  freespace        = _freeDiskSpace.Value / 1000;
                bool valueFoundInList = false;

                for (int i = 1; i < 1000; i++)
                {
                    _freeDiskSpaceSpinButton.AddSpinLabel(i.ToString(), 0);
                    if (i == freespace)
                    {
                        valueFoundInList = true;
                    }
                }

                if (valueFoundInList)
                {
                    _freeDiskSpaceSpinButton.SpinValue = freespace - 1;
                }
                else
                {
                    _freeDiskSpaceSpinButton.AddSpinLabel(freespace.ToString(), 0);
                    _freeDiskSpaceSpinButton.SpinValue = _freeDiskSpaceSpinButton.SpinMaxValue() - 1;
                }
            }
            if (_minFreeDiskSpace.HasValue)
            {
                int  freespace        = _minFreeDiskSpace.Value / 1000;
                bool valueFoundInList = false;

                for (int i = 1; i <= 1000; i++)
                {
                    _minFreeDiskSpaceSpinButton.AddSpinLabel(i.ToString(), 0);
                    if (i == freespace)
                    {
                        valueFoundInList = true;
                    }
                }

                if (valueFoundInList)
                {
                    _minFreeDiskSpaceSpinButton.SpinValue = freespace - 1;
                }
                else
                {
                    _minFreeDiskSpaceSpinButton.AddSpinLabel(freespace.ToString(), 0);
                    _minFreeDiskSpaceSpinButton.SpinValue = _minFreeDiskSpaceSpinButton.SpinMaxValue() - 1;
                }
            }
        }