예제 #1
0
        /// <summary>
        /// Fires toggle loading.
        /// </summary>
        /// <param name="show"></param>
        public void FireOnLoading(bool isLoading)
        {
            // If is the same leave.
            if (isLoading == IsLoading)
            {
                return;
            }

            // Set the value
            IsLoading = isLoading;

            // Try to tell the host
            IContentPanelHost host = m_host;

            if (host != null)
            {
                host.OnLoadingChanged();
            }

            // When loading is done and we haven't before report it to the master
            if (!m_hasDeclaredLoaded && !IsLoading)
            {
                m_hasDeclaredLoaded = true;
                // Tell the manager that we are loaded.
                Task.Run(() =>
                {
                    ContentPanelMaster.Current.OnContentLoadComplete(Source.Id);
                });
            }
        }
예제 #2
0
        /// <summary>
        /// Fires show error
        /// </summary>
        /// <param name="show"></param>
        public void FireOnError(bool hasError, string errorText = null)
        {
            // Set the value
            HasError  = hasError;
            ErrorText = errorText;

            // Try to tell the host
            IContentPanelHost host = m_host;

            if (host != null)
            {
                host.OnErrorChanged();
            }

            // When loading is done report it to the master
            if (!m_hasDeclaredLoaded && HasError)
            {
                m_hasDeclaredLoaded = true;
                // Tell the manager that we are loaded.
                Task.Run(() =>
                {
                    ContentPanelMaster.Current.OnContentLoadComplete(Source.Id);
                });
            }
        }
예제 #3
0
        /// <summary>
        /// Fired when a new host has been added.
        /// </summary>
        /// <param name="host"></param>
        public void OnHostAdded(IContentPanelHost host)
        {
            m_host = host;
            Panel.OnHostAdded();

            // Also fire on visibility changed so the panel is in the correct state
            Panel.OnVisibilityChanged(host.IsVisible);
        }
예제 #4
0
        public async void UnRegisterForPanel(IContentPanelHost host, string panelId)
        {
            // Fist we need to see if there was a panel.
            IContentPanelBase removePanelBase = null;

            lock (m_currentPanelList)
            {
                // Make sure we have an entry.
                if (!m_currentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                ContentListElement element = m_currentPanelList[panelId];

                // Important! Make sure this host is the correct host for the panel!
                // This can happen if two hosts register for the same id, but the newer will
                // replace the older one. But we don't want the older to unregister and kill
                // the entry for the newer host.
                // The host can also be null if we are in the process of switching.
                if (element.Host == null || !element.Host.Id.Equals(host.Id))
                {
                    return;
                }

                removePanelBase = m_currentPanelList[panelId].PanelBase;
            }

            // If we got a panel back clear it out
            if (removePanelBase != null)
            {
                await FireOnRemovePanel(host, removePanelBase);
            }

            // Now actually clear the host
            lock (m_currentPanelList)
            {
                // Make sure we have an entry.
                if (!m_currentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                ContentListElement element = m_currentPanelList[panelId];
                element.Host = null;

                // If we the state isn't allowed delete this entry because
                // no one wants it.
                if (element.State == ContentState.NotAllowed)
                {
                    m_currentPanelList.Remove(panelId);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Fires ToggleFullscreen
        /// </summary>
        /// <param name="show"></param>
        public bool FireOnFullscreenChanged(bool goFullscreen)
        {
            // Try to tell the host
            IContentPanelHost host = m_host;

            if (host != null)
            {
                return(host.OnFullscreenChanged(goFullscreen));
            }
            return(false);
        }
예제 #6
0
        /// <summary>
        /// Removes content from the list of approved content. Anyone using that content will have it removed.
        /// </summary>
        /// <param name="id"></param>
        public async void RemoveAllowedContent(string id)
        {
            // First we need to see if it has a host and a panel.
            IContentPanelHost host      = null;
            IContentPanelBase panelBase = null;

            lock (_mCurrentPanelList)
            {
                // Make sure we have the element.
                if (!_mCurrentPanelList.ContainsKey(id))
                {
                    return;
                }

                // Get the element.
                var element = _mCurrentPanelList[id];

                // Get the host and panel if there are any.
                host      = element.Host;
                panelBase = element.PanelBase;

                // Null the panel and set the state to now allowed.
                element.PanelBase = null;
                element.State     = ContentState.NotAllowed;

                // If we don't have a host delete it.
                if (element.Host == null)
                {
                    _mCurrentPanelList.Remove(id);
                }

                // Ensure it isn't in our delay load list
                _mDelayLoadQueue.Remove(element.Source);
            }

            // Call on load complete in case this was the delay loaded
            // panels were waiting on this panel
            OnContentLoadComplete(id);

            // If we have a host remove the panel from them
            if (host != null && panelBase != null)
            {
                await FireOnRemovePanel(host, panelBase);
            }

            // If we have a panel destroy it
            if (panelBase != null)
            {
                await FireOnDestroyContent(panelBase);
            }
        }
 /// <summary>
 /// Fires OnPanelUnloaded on the UI thread.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="panel"></param>
 private async void FireOnPanelUnloaded(IContentPanelHost host)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
     {
         try
         {
             // Then tell the pane has been unloaded.
             host.OnPanelUnloaded();
         }
         catch (Exception e)
         {
             App.BaconMan.MessageMan.DebugDia("FireOnPanelUnloaded failed", e);
         }
     });
 }
 /// <summary>
 /// Fires OnContentPreloading on the UI thread.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="panel"></param>
 private async void FireOnContentPreloading(IContentPanelHost host)
 {
     // Do this on a high pri so the loading indicator will show up ASAP.
     await global::Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         try
         {
             // Then tell the content has begun loading.
             host.OnContentPreloading();
         }
         catch (Exception e)
         {
             App.BaconMan.MessageMan.DebugDia("FireOnContentPreloading failed", e);
         }
     });
 }
        /// <summary>
        /// Fires OnPanelAvailable on the UI thread.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="panel"></param>
        private async void FireOnPanelAvailable(IContentPanelHost host, IContentPanelBase panelBase)
        {
            await global::Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                try
                {
                    // First tell the post it has a host
                    panelBase.OnHostAdded(host);

                    // Then tell the host it has a panel.
                    host.OnPanelAvailable(panelBase);
                }
                catch (Exception e)
                {
                    App.BaconMan.MessageMan.DebugDia("FireOnPanelAvailable failed", e);
                }
            });
        }
예제 #10
0
        /// <summary>
        /// Fires FireOnPanelStolen on the UI thread.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="panel"></param>
        private async Task FireOnRemovePanel(IContentPanelHost host, IContentPanelBase panelBase)
        {
            await global::Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                try
                {
                    // Tell the panel the host is gone
                    panelBase.OnHostRemoved();

                    // And remove the panel.
                    host.OnRemovePanel(panelBase);
                }
                catch (Exception e)
                {
                    App.BaconMan.MessageMan.DebugDia("FireOnRemovePanel failed", e);
                }
            });
        }
예제 #11
0
        /// <summary>
        /// Fires FireOnPanelStolen on the UI thread.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="panel"></param>
        private async Task FireOnRemovePanel(IContentPanelHost host, IContentPanelBase panelBase)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                try
                {
                    // Tell the panel the host is gone
                    panelBase.OnHostRemoved();

                    // And remove the panel.
                    host.OnRemovePanel(panelBase);
                }
                catch (Exception e)
                {
                    App.BaconMan.MessageMan.DebugDia("FireOnRemovePanel failed", e);
                    TelemetryManager.ReportUnexpectedEvent(this, "FireOnRemovePanelFailed", e);
                }
            });
        }
예제 #12
0
        public async void UnRegisterForPanel(IContentPanelHost host, string panelId)
        {
            // Fist we need to see if there was a panel.
            IContentPanelBase removePanelBase = null;
            lock (m_currentPanelList)
            {
                // Make sure we have an entry.
                if (!m_currentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                ContentListElement element = m_currentPanelList[panelId];

                // Important! Make sure this host is the correct host for the panel!
                // This can happen if two hosts register for the same id, but the newer will
                // replace the older one. But we don't want the older to unregister and kill
                // the entry for the newer host.
                // The host can also be null if we are in the process of switching.
                if (element.Host == null || !element.Host.Id.Equals(host.Id))
                {
                    // Try to find the panel in our back stack.
                    IContentPanelHost removeStackHost = null;
                    foreach (IContentPanelHost stackHost in element.PastHosts)
                    {
                        if(stackHost.Id.Equals(host.Id))
                        {
                            removeStackHost = stackHost;
                            break;
                        }
                    }

                    // If found remove it, if it is in this stack it isn't registered anywhere.
                    if(removeStackHost != null)
                    {
                        element.PastHosts.Remove(removeStackHost);
                    }
                    else
                    {
                        // This is odd, report it.
                        App.BaconMan.MessageMan.DebugDia("panel removed that wasn't active or in the panel stack");
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                    }

                    // Get out of here.
                    return;
                }

                removePanelBase = m_currentPanelList[panelId].PanelBase;
            }

            // If we got a panel back clear it out
            if (removePanelBase != null)
            {
                await FireOnRemovePanel(host, removePanelBase);
            }

            IContentPanelHost restoreHost = null;

            // Now actually clear the host
            lock (m_currentPanelList)
            {
                // Make sure we have an entry.
                if (!m_currentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                // Remove the current host.
                ContentListElement element = m_currentPanelList[panelId];
                element.Host = null;

                // If we have a past host restore it.
                if(element.PastHosts.Count > 0)
                {
                    // Get the host
                    restoreHost = element.PastHosts[0];
                    element.PastHosts.RemoveAt(0);
                }

                // If we the state isn't allowed and we don't have a host to restore
                // delete this entry because no one wants it.
                if(element.State == ContentState.NotAllowed && restoreHost == null)
                {
                    m_currentPanelList.Remove(panelId);
                }
            }

            // If we have a panel to restore call register on it.
            if(restoreHost != null)
            {
                RegisterForPanel(restoreHost, panelId);
            }            
        }
예제 #13
0
        /// <summary>
        /// Called by hosts when they want to get a panel
        /// </summary>
        /// <param name="panelId"></param>
        public async void RegisterForPanel(IContentPanelHost host, string panelId)
        {
            // Indicates if we should fire content loading.
            IContentPanelHost fireContentLoadingHost = null;

            // Used to fire the on panel available event.
            IContentPanelBase returnPanelBase = null;

            // Used to hold a past host if there is one.
            IContentPanelHost pastHost = null;

            // Used to hold the host we will tell is unloaded.
            IContentPanelHost fireUnloadedHost = null;

            // Check to see if the panel exists
            lock (m_currentPanelList)
            {
                // We already have it
                if(m_currentPanelList.ContainsKey(panelId))
                {
                    ContentListElement element = m_currentPanelList[panelId];

                    if(element.Host == null)
                    {
                        // We don't have a host, add ourselves.
                        element.Host = host;
                        if(element.State == ContentState.Created)
                        {
                            // If the control is already created fire the on control available right now.
                            returnPanelBase = element.PanelBase;
                        }
                        else if(element.State == ContentState.PendingCreation)
                        {
                            // If the content is being created tell the panel that.
                            fireContentLoadingHost = element.Host;
                        }
                        else if(element.State == ContentState.Unloaded)
                        {
                            fireUnloadedHost = element.Host;
                        }
                    }
                    else
                    {
                        // Grab the host and null it so we can tell it that it has been removed
                        // and nothing will go to it. 
                        pastHost = element.Host;
                        element.Host = null;

                        // We want to add it to the panel list so we can restore it if the current host leaves.
                        element.PastHosts.Insert(0, pastHost);

                        // If the control is already created remove it from the old host.
                        if (element.State == ContentState.Created)
                        {
                            // If the control is already created fire the on control available right now.
                            returnPanelBase = element.PanelBase;
                        }
                    }
                }
                else
                {
                    // We don't have it, make an entry so when we get it
                    // we will be called back if one is created.
                    ContentListElement element = new ContentListElement()
                    {
                        Host = host,
                        State = ContentState.NotAllowed
                    };
                    m_currentPanelList.Add(panelId, element);
                }
            }

            // If we have a past host we are transferring.
            if(pastHost != null)
            {
                // If we have a panel already we need to remove it.
                if(returnPanelBase != null)
                {
                    await FireOnRemovePanel(pastHost, returnPanelBase);
                }

                // Now that the old host is gone, register again.
                RegisterForPanel(host, panelId);
                return;
            }

            // Out of lock, fire the event if we have a panel
            if(returnPanelBase != null)
            {
                FireOnPanelAvailable(host, returnPanelBase);
            }

            // Or if we have content loading.
            if(fireContentLoadingHost != null)
            {
                FireOnContentPreloading(fireContentLoadingHost);
            }

            // Or if we have unloaded content.
            if (fireUnloadedHost != null)
            {
                FireOnPanelUnloaded(fireUnloadedHost);
            }
        }
예제 #14
0
 /// <summary>
 /// Fires OnPanelUnloaded on the UI thread.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="panel"></param>
 private async void FireOnPanelUnloaded(IContentPanelHost host)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
     {
         try
         {
             // Then tell the pane has been unloaded.
             host.OnPanelUnloaded();
         }
         catch (Exception e)
         {
             App.BaconMan.MessageMan.DebugDia("FireOnPanelUnloaded failed", e);
             App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "FireOnPanelUnloadedFailed", e);
         }
     });
 }
예제 #15
0
 /// <summary>
 /// Fires OnContentPreloading on the UI thread.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="panel"></param>
 private async void FireOnContentPreloading(IContentPanelHost host)
 {
     // Do this on a high pri so the loading indicator will show up ASAP.
     await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         try
         {
             // Then tell the content has begun loading.
             host.OnContentPreloading();
         }
         catch (Exception e)
         {
             App.BaconMan.MessageMan.DebugDia("FireOnContentPreloading failed", e);
             App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "FireOnContentPreloadingFailed", e);
         }
     });
 }
예제 #16
0
        /// <summary>
        /// If the content is allowed it will be unloaded. It will remain in this state until
        /// a panel that wasn't it becomes visible.
        /// </summary>
        public async void UnloadContent(string sourceId)
        {
            string            idToCallLoadCompleteOn = null;
            IContentPanelHost hostToTakeFrom         = null;
            IContentPanelBase panelToDestory         = null;

            // Lock the list.
            lock (_mCurrentPanelList)
            {
                // Make sure we have the id
                if (!_mCurrentPanelList.ContainsKey(sourceId))
                {
                    return;
                }

                // Get the element.
                var element = _mCurrentPanelList[sourceId];

                // Make sure we have something to do here.
                if (element.State == ContentState.NotAllowed || element.State == ContentState.Unloaded)
                {
                    return;
                }

                if (element.State == ContentState.PendingCreation)
                {
                    // The object is either being created or delay loaded. If we set the status to
                    // unloaded this will kill the object when created.
                    element.State = ContentState.Unloaded;

                    // Make sure it isn't in the delay load list
                    _mDelayLoadQueue.Remove(element.Source);

                    // Grab the id so we can call load complete on the id.
                    // This will ensure if this is the post we are waiting on
                    // the delay load will move on.
                    idToCallLoadCompleteOn = element.Source.Id;
                }
                else
                {
                    // We are created, grab the panel
                    panelToDestory    = element.PanelBase;
                    element.PanelBase = null;

                    // Set our state to unloaded.
                    element.State = ContentState.Unloaded;

                    // If we have a host we need to remove it from the host. It is safe to steal
                    // the panel and host from the list because this panel will not be reset into
                    // the UI until it is created again (which won't be this panel)
                    if (element.Host != null)
                    {
                        hostToTakeFrom = element.Host;
                    }
                }
            }

            // If we have an id call on load complete. This will cause delay load
            // to move on if this was the elemet it was waiting on.
            if (idToCallLoadCompleteOn != null)
            {
                OnContentLoadComplete(idToCallLoadCompleteOn);
            }

            // If we have a source and a panel, take it from the host.
            if (hostToTakeFrom != null && panelToDestory != null)
            {
                await FireOnRemovePanel(hostToTakeFrom, panelToDestory);

                // #todo tell the host it was unloaded so they can put up UI.
            }

            // If we have a panel destroy it.
            if (panelToDestory != null)
            {
                await FireOnDestroyContent(panelToDestory);
            }
        }
예제 #17
0
 /// <summary>
 /// Fired when the host is removed.
 /// </summary>
 public void OnHostRemoved()
 {
     m_host = null;
 }
예제 #18
0
        public async void UnRegisterForPanel(IContentPanelHost host, string panelId)
        {
            // Fist we need to see if there was a panel.
            IContentPanelBase removePanelBase = null;

            lock (_mCurrentPanelList)
            {
                // Make sure we have an entry.
                if (!_mCurrentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                var element = _mCurrentPanelList[panelId];

                // Important! Make sure this host is the correct host for the panel!
                // This can happen if two hosts register for the same id, but the newer will
                // replace the older one. But we don't want the older to unregister and kill
                // the entry for the newer host.
                // The host can also be null if we are in the process of switching.
                if (element.Host == null || !element.Host.Id.Equals(host.Id))
                {
                    // Try to find the panel in our back stack.
                    IContentPanelHost removeStackHost = null;
                    foreach (var stackHost in element.PastHosts)
                    {
                        if (stackHost.Id.Equals(host.Id))
                        {
                            removeStackHost = stackHost;
                            break;
                        }
                    }

                    // If found remove it, if it is in this stack it isn't registered anywhere.
                    if (removeStackHost != null)
                    {
                        element.PastHosts.Remove(removeStackHost);
                    }
                    else
                    {
                        // This is odd, report it.
                        App.BaconMan.MessageMan.DebugDia("panel removed that wasn't active or in the panel stack");
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                    }

                    // Get out of here.
                    return;
                }

                removePanelBase = _mCurrentPanelList[panelId].PanelBase;
            }

            // If we got a panel back clear it out
            if (removePanelBase != null)
            {
                await FireOnRemovePanel(host, removePanelBase);
            }

            IContentPanelHost restoreHost = null;

            // Now actually clear the host
            lock (_mCurrentPanelList)
            {
                // Make sure we have an entry.
                if (!_mCurrentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                // Remove the current host.
                var element = _mCurrentPanelList[panelId];
                element.Host = null;

                // If we have a past host restore it.
                if (element.PastHosts.Count > 0)
                {
                    // Get the host
                    restoreHost = element.PastHosts[0];
                    element.PastHosts.RemoveAt(0);
                }

                // If we the state isn't allowed and we don't have a host to restore
                // delete this entry because no one wants it.
                if (element.State == ContentState.NotAllowed && restoreHost == null)
                {
                    _mCurrentPanelList.Remove(panelId);
                }
            }

            // If we have a panel to restore call register on it.
            if (restoreHost != null)
            {
                RegisterForPanel(restoreHost, panelId);
            }
        }
예제 #19
0
        /// <summary>
        /// Called by hosts when they want to get a panel
        /// </summary>
        /// <param name="panelId"></param>
        public async void RegisterForPanel(IContentPanelHost host, string panelId)
        {
            // Indicates if we should fire content loading.
            IContentPanelHost fireContentLoadingHost = null;

            // Used to fire the on panel available event.
            IContentPanelBase returnPanelBase = null;

            // Used to hold a past host if there is one.
            IContentPanelHost pastHost = null;

            // Used to hold the host we will tell is unloaded.
            IContentPanelHost fireUnloadedHost = null;

            // Check to see if the panel exists
            lock (_mCurrentPanelList)
            {
                // We already have it
                if (_mCurrentPanelList.ContainsKey(panelId))
                {
                    var element = _mCurrentPanelList[panelId];

                    if (element.Host == null)
                    {
                        // We don't have a host, add ourselves.
                        element.Host = host;
                        if (element.State == ContentState.Created)
                        {
                            // If the control is already created fire the on control available right now.
                            returnPanelBase = element.PanelBase;
                        }
                        else if (element.State == ContentState.PendingCreation)
                        {
                            // If the content is being created tell the panel that.
                            fireContentLoadingHost = element.Host;
                        }
                        else if (element.State == ContentState.Unloaded)
                        {
                            fireUnloadedHost = element.Host;
                        }
                    }
                    else
                    {
                        // Grab the host and null it so we can tell it that it has been removed
                        // and nothing will go to it.
                        pastHost     = element.Host;
                        element.Host = null;

                        // We want to add it to the panel list so we can restore it if the current host leaves.
                        element.PastHosts.Insert(0, pastHost);

                        // If the control is already created remove it from the old host.
                        if (element.State == ContentState.Created)
                        {
                            // If the control is already created fire the on control available right now.
                            returnPanelBase = element.PanelBase;
                        }
                    }
                }
                else
                {
                    // We don't have it, make an entry so when we get it
                    // we will be called back if one is created.
                    var element = new ContentListElement
                    {
                        Host  = host,
                        State = ContentState.NotAllowed
                    };
                    _mCurrentPanelList.Add(panelId, element);
                }
            }

            // If we have a past host we are transferring.
            if (pastHost != null)
            {
                // If we have a panel already we need to remove it.
                if (returnPanelBase != null)
                {
                    await FireOnRemovePanel(pastHost, returnPanelBase);
                }

                // Now that the old host is gone, register again.
                RegisterForPanel(host, panelId);
                return;
            }

            // Out of lock, fire the event if we have a panel
            if (returnPanelBase != null)
            {
                FireOnPanelAvailable(host, returnPanelBase);
            }

            // Or if we have content loading.
            if (fireContentLoadingHost != null)
            {
                FireOnContentPreloading(fireContentLoadingHost);
            }

            // Or if we have unloaded content.
            if (fireUnloadedHost != null)
            {
                FireOnPanelUnloaded(fireUnloadedHost);
            }
        }
예제 #20
0
        /// <summary>
        /// This will actually do the loading of content. This starts the load but
        /// the load isn't actually done until the app fires the loading function above.
        /// </summary>
        /// <param name="source"></param>
        private void BeginLoadContent(ContentPanelSource source, bool isVisible)
        {
            // Next make the control, spin this off to keep the UI thread going.
            Task.Run(async() =>
            {
                // Create a new base and panel.
                var panelBase   = new ContentPanelBase();
                var panelLoaded = await panelBase.CreateContentPanel(source, CanLoadLaregePanel(isVisible));

                var destoryPanel = true;
                IContentPanelHost hostToGivePanel      = null;
                IContentPanelHost hostToInformUnlaoded = null;

                // Update the list with the control
                lock (_mCurrentPanelList)
                {
                    // Make sure it is still there.
                    if (_mCurrentPanelList.ContainsKey(source.Id))
                    {
                        var element = _mCurrentPanelList[source.Id];

                        // Make sure we still have a good state.
                        if (element.State == ContentState.PendingCreation)
                        {
                            // Make sure the panel loaded
                            if (panelLoaded)
                            {
                                // Set the panel and state, if we have a host grab it.
                                destoryPanel      = false;
                                element.PanelBase = panelBase;
                                element.State     = ContentState.Created;
                                hostToGivePanel   = element.Host;
                            }
                            else
                            {
                                // If we didn't load it was probably due to low memory.
                                // Set our state to unloaded and tell the host.
                                element.State        = ContentState.Unloaded;
                                hostToInformUnlaoded = element.Host;
                                destoryPanel         = true;
                            }
                        }
                    }
                }

                // If the entry is now gone or whatever, destroy the post.
                if (destoryPanel)
                {
                    await FireOnDestroyContent(panelBase);
                }
                else
                {
                    // If we have a host inform them the panel is now ready.
                    if (hostToGivePanel != null)
                    {
                        FireOnPanelAvailable(hostToGivePanel, panelBase);
                    }
                }

                // If we have a host to tell that we unloaded the panel tell them.
                if (hostToInformUnlaoded != null)
                {
                    FireOnPanelUnloaded(hostToInformUnlaoded);
                }
            });
        }
예제 #21
0
 /// <summary>
 /// Fired when the host is removed.
 /// </summary>
 public void OnHostRemoved()
 {
     m_host = null;
 }
예제 #22
0
        /// <summary>
        /// Fired when a new host has been added.
        /// </summary>
        /// <param name="host"></param>
        public void OnHostAdded(IContentPanelHost host)
        {
            m_host = host;
            Panel.OnHostAdded();

            // Also fire on visibility changed so the panel is in the correct state
            Panel.OnVisibilityChanged(host.IsVisible);
        }
예제 #23
0
        /// <summary>
        /// Fires OnPanelAvailable on the UI thread.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="panel"></param>
        private async void FireOnPanelAvailable(IContentPanelHost host, IContentPanelBase panelBase)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                try
                {
                    // First tell the post it has a host
                    panelBase.OnHostAdded(host);

                    // Then tell the host it has a panel.
                    host.OnPanelAvailable(panelBase);
                }
                catch (Exception e)
                {
                    App.BaconMan.MessageMan.DebugDia("FireOnPanelAvailable failed", e);
                    App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "FireOnPanelAvailableFailed", e);
                }
            });
        }
예제 #24
0
        /// <summary>
        /// When fired the source given should fall back to a web
        /// browser instead of a complex control.
        /// </summary>
        public async void FallbackToWebrowser(ContentPanelSource source)
        {
            IContentPanelHost hostToReport = null;
            IContentPanelBase panelToKill  = null;

            // Fire on load complete so if someone else was waiting on us they will
            // move on.
            OnContentLoadComplete(source.Id);

            // Lock
            lock (_mCurrentPanelList)
            {
                // Make sure we have it.
                if (_mCurrentPanelList.ContainsKey(source.Id))
                {
                    // Grab the panel to kill and the host to tell.
                    var element = _mCurrentPanelList[source.Id];
                    hostToReport = element.Host;
                    panelToKill  = element.PanelBase;

                    // Null the post and update our state
                    element.PanelBase = null;
                    element.State     = ContentState.Unloaded;
                }
                else
                {
                    return;
                }
            }

            // Remove the panel
            if (hostToReport != null && panelToKill != null)
            {
                await FireOnRemovePanel(hostToReport, panelToKill);
            }

            // Kill the panel
            if (panelToKill != null)
            {
                await FireOnDestroyContent(panelToKill);

                panelToKill = null;
            }

            ContentPanelSource sourceToCreate = null;
            var isVisible = false;

            // Now lock again
            lock (_mCurrentPanelList)
            {
                // Make sure we still have it.
                if (_mCurrentPanelList.ContainsKey(source.Id))
                {
                    var element = _mCurrentPanelList[source.Id];
                    if (element.State == ContentState.Unloaded)
                    {
                        // Grab the element again and set the new state.
                        isVisible = element.IsVisible;
                        element.Source.ForceWeb = true;
                        sourceToCreate          = element.Source;
                        element.State           = ContentState.PendingCreation;
                    }
                    else
                    {
                        // if we are not in the same state get out of here.
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            if (sourceToCreate != null)
            {
                BeginLoadContent(sourceToCreate, isVisible);
            }
        }
예제 #25
0
        /// <summary>
        /// Fires FireOnPanelStolen on the UI thread.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="panel"></param>
        private async Task FireOnRemovePanel(IContentPanelHost host, IContentPanelBase panelBase)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                try
                {
                    // Tell the panel the host is gone
                    panelBase.OnHostRemoved();

                    // And remove the panel.
                    host.OnRemovePanel(panelBase);
                }
                catch (Exception e)
                {
                    App.BaconMan.MessageMan.DebugDia("FireOnRemovePanel failed", e);
                    App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "FireOnRemovePanelFailed", e);
                }
            });
        }
예제 #26
0
        public async void UnRegisterForPanel(IContentPanelHost host, string panelId)
        {
            // Fist we need to see if there was a panel.
            IContentPanelBase removePanelBase = null;
            lock (m_currentPanelList)
            {
                // Make sure we have an entry.
                if (!m_currentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                ContentListElement element = m_currentPanelList[panelId];

                // Important! Make sure this host is the correct host for the panel!
                // This can happen if two hosts register for the same id, but the newer will
                // replace the older one. But we don't want the older to unregister and kill
                // the entry for the newer host.
                // The host can also be null if we are in the process of switching.
                if (element.Host == null || !element.Host.Id.Equals(host.Id))
                {
                    return;
                }

                removePanelBase = m_currentPanelList[panelId].PanelBase;
            }

            // If we got a panel back clear it out
            if (removePanelBase != null)
            {
                await FireOnRemovePanel(host, removePanelBase);
            }

            // Now actually clear the host
            lock (m_currentPanelList)
            {
                // Make sure we have an entry.
                if (!m_currentPanelList.ContainsKey(panelId))
                {
                    return;
                }

                ContentListElement element = m_currentPanelList[panelId];
                element.Host = null;

                // If we the state isn't allowed delete this entry because
                // no one wants it.
                if(element.State == ContentState.NotAllowed)
                {
                    m_currentPanelList.Remove(panelId);
                }
            }
        }