Exemplo n.º 1
0
 public void ExitModelContext(NavigationContext oldContext, NavigationContext newContext)
 {
     _messageQueue.Shutdown();
     if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
     {
         if (newDllsDownloaded)
         {
             Log.Info("Reloading SiteUtil Dlls at runtime.");
             DownloadManager.Instance.StopAll();
             // now reload the appdomain
             OnlineVideoSettings.Reload();
             TranslationLoader.SetTranslationsToSingleton();
             GC.Collect();
             GC.WaitForFullGCComplete();
         }
         if (newDataSaved || newDllsDownloaded)
         {
             SystemMessage msg = new SystemMessage(OnlineVideosMessaging.MessageType.SitesUpdated);
             msg.MessageData[OnlineVideosMessaging.UPDATE_RESULT] = newDllsDownloaded ? new bool?(true) : new bool?();
             ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, msg);
         }
     }
     newDataSaved      = false;
     newDllsDownloaded = false;
 }
 void OnlineVideosMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
 {
     if (message.ChannelName == OnlineVideosMessaging.CHANNEL)
     {
         OnlineVideosMessaging.MessageType messageType = (OnlineVideosMessaging.MessageType)message.MessageType;
         switch (messageType)
         {
         case OnlineVideosMessaging.MessageType.SitesUpdated:
             bool?updateResult = (bool?)message.MessageData[OnlineVideosMessaging.UPDATE_RESULT];
             if (updateResult != false)
             {
                 if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
                 {
                     if (updateResult == true)
                     {
                         Log.Info("Reloading SiteUtil Dlls at runtime.");
                         DownloadManager.Instance.StopAll();
                         // now reload the appdomain
                         OnlineVideoSettings.Reload();
                         TranslationLoader.SetTranslationsToSingleton();
                         GC.Collect();
                         GC.WaitForFullGCComplete();
                     }
                 }
                 OnlineVideoSettings.Instance.BuildSiteUtilsList();
                 RebuildSitesList();
             }
             else
             {
                 // called when entering OnlineVideos first time (after sites have been updated)
                 if (!OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
                 {
                     // show the busy indicator, because loading site dlls takes some seconds
                     ServiceRegistration.Get <ISuperLayerManager>().ShowBusyScreen();
                     try
                     {
                         OnlineVideoSettings.Instance.BuildSiteUtilsList();
                         RebuildSitesList();
                     }
                     catch (Exception ex)
                     {
                         Log.Error(ex);
                     }
                     finally
                     {
                         ServiceRegistration.Get <ISuperLayerManager>().HideBusyScreen();
                     }
                 }
             }
             break;
         }
     }
 }
Exemplo n.º 3
0
        internal static void ReloadDownloadedDlls()
        {
            Log.Instance.Info("Reloading SiteUtil Dlls at runtime.");
            bool stopPlayback = (MediaPortal.Player.g_Player.Player != null && MediaPortal.Player.g_Player.Player.GetType().Assembly == typeof(GUISiteUpdater).Assembly);
            bool stopDownload = DownloadManager.Instance.Count > 0;

            if (stopDownload || stopPlayback)
            {
                GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                if (dlg != null)
                {
                    dlg.Reset();
                    dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                    dlg.SetLine(1, Translation.Instance.NewDllDownloaded);
                    int i = 1;
                    if (stopDownload)
                    {
                        dlg.SetLine(i++, Translation.Instance.DownloadsWillBeAborted);
                    }
                    if (stopPlayback)
                    {
                        dlg.SetLine(i++, Translation.Instance.PlaybackWillBeStopped);
                    }
                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                }
            }
            // stop playback if an OnlineVideos video is playing
            if (stopPlayback)
            {
                MediaPortal.Player.g_Player.Stop();
            }
            // stop downloads
            DownloadManager.Instance.StopAll();
            // reset the GuiOnlineVideos instance and stop the LatestVideos Thread
            GUIOnlineVideos ovGuiInstance = (GUIOnlineVideos)GUIWindowManager.GetWindow(GUIOnlineVideos.WindowId);

            if (ovGuiInstance != null)
            {
                ovGuiInstance.ResetToFirstView();
                ovGuiInstance.LatestVideosManager.Stop();
            }
            // now reload the appdomain
            OnlineVideoSettings.Reload();
            TranslationLoader.SetTranslationsToSingleton();
            OnlineVideoSettings.Instance.BuildSiteUtilsList();
            GC.Collect();
            GC.WaitForFullGCComplete();
            // restart the LatestVideos thread
            ovGuiInstance.LatestVideosManager.Start();
        }
Exemplo n.º 4
0
 void VisibilityChanged(object sender, EventArgs e)
 {
     ImageDownloader.StopDownload = true;
     if (Visibility == System.Windows.Visibility.Hidden)
     {
         if (changedXml)
         {
             (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.ItemsSource = null;
             if (newDlls)
             {
                 OnlineVideoSettings.Reload();
                 TranslationLoader.SetTranslationsToSingleton();
                 GC.Collect();
                 GC.WaitForFullGCComplete();
                 newDlls = false;
             }
             OnlineVideoSettings.Instance.BuildSiteUtilsList();
             (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.ItemsSource = ViewModels.SiteList.GetSitesView(App.Current.MainWindow as OnlineVideosMainWindow);
             changedXml = false;
         }
         (App.Current.MainWindow as OnlineVideosMainWindow).SelectAndFocusItem(rememberedIndex);
     }
     else if (Visibility == System.Windows.Visibility.Visible)
     {
         // deselect any site on the main view but remember the index
         rememberedIndex = (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.SelectedIndex;
         (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.SelectedIndex = -1;
         var sitesView = ViewModels.GlobalSiteList.GetSitesView(App.Current.MainWindow as OnlineVideosMainWindow);
         lvSites.ItemsSource = sitesView;
         ImageDownloader.GetImages <ViewModels.GlobalSite>(sitesView.SourceCollection as IList <ViewModels.GlobalSite>);
         GridViewSort.ApplySort(lvSites.Items, "LastUpdated", lvSites, FindColumnHeader(lvSites, "LastUpdated"), ListSortDirection.Descending);
         // focus the first item when this list becomes visible /use dispatcher to let WPF create the items first)
         Dispatcher.BeginInvoke((Action)(() =>
         {
             var itemToFocus = lvSites.ItemContainerGenerator.ContainerFromIndex(0) as ListViewItem;
             if (itemToFocus != null)
             {
                 itemToFocus.Focus();
             }
         }), DispatcherPriority.Loaded);
     }
 }
        private static void PeriodicSitesUpdate()
        {
            // don't run when any of the OV workflow models are currently active
            var workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            if (workflowManager.IsModelContainedInNavigationStack(Guids.WorkFlowModelOV) ||
                workflowManager.IsModelContainedInNavigationStack(Guids.WorkFlowModelSiteManagement) ||
                workflowManager.IsModelContainedInNavigationStack(Guids.WorkFlowModelSiteUpdate))
            {
                return;
            }

            var settingsManager = ServiceRegistration.Get <ISettingsManager>();
            var ovMP2Settings   = settingsManager.Load <Configuration.Settings>();

            // if the current version is compatible and automatic update is enabled and due, run it now
            if (Sites.Updater.VersionCompatible &&
                ovMP2Settings.AutomaticUpdate &&
                ovMP2Settings.LastAutomaticUpdate.AddHours(ovMP2Settings.AutomaticUpdateInterval) < DateTime.Now)
            {
                var updateResult = Sites.Updater.UpdateSites();
                ovMP2Settings.LastAutomaticUpdate = DateTime.Now;
                settingsManager.Save(ovMP2Settings);

                if (updateResult == true)
                {
                    Log.Info("Reloading SiteUtil Dlls at runtime.");
                    DownloadManager.Instance.StopAll();
                    OnlineVideoSettings.Reload();
                    TranslationLoader.SetTranslationsToSingleton();
                    GC.Collect();
                    GC.WaitForFullGCComplete();
                }
                if (updateResult != false)
                {
                    OnlineVideoSettings.Instance.BuildSiteUtilsList();
                    ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, new SystemMessage(OnlineVideosMessaging.MessageType.RebuildSites));
                }
            }
        }
 public void ExitModelContext(NavigationContext oldContext, NavigationContext newContext)
 {
     _messageQueue.Shutdown();
     if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
     {
         if (newDllsDownloaded)
         {
             Log.Info("Reloading SiteUtil Dlls at runtime.");
             DownloadManager.Instance.StopAll();
             OnlineVideoSettings.Reload();
             TranslationLoader.SetTranslationsToSingleton();
             GC.Collect();
             GC.WaitForFullGCComplete();
         }
         if (newDataSaved || newDllsDownloaded)
         {
             OnlineVideoSettings.Instance.BuildSiteUtilsList();
             ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, new SystemMessage(OnlineVideosMessaging.MessageType.RebuildSites));
         }
     }
     newDataSaved      = false;
     newDllsDownloaded = false;
 }