CanHandlePost() static public method

Called by the host when it queries if we can handle a post.
static public CanHandlePost ( ContentPanelSource source ) : bool
source ContentPanelSource
return bool
コード例 #1
0
        public static Type GetControlType(ContentPanelSource source, object callingClass = null)
        {
            try
            {
                if (GifImageContentPanel.CanHandlePost(source))
                {
                    return(typeof(GifImageContentPanel));
                }
                if (RedditVideoContentPanel.CanHandlePost(source))
                {
                    return(typeof(RedditVideoContentPanel));
                }
                if (YoutubeContentPanel.CanHandlePost(source))
                {
                    return(typeof(YoutubeContentPanel));
                }
                if (BasicImageContentPanel.CanHandlePost(source))
                {
                    return(typeof(BasicImageContentPanel));
                }
                if (MarkdownContentPanel.CanHandlePost(source))
                {
                    return(typeof(MarkdownContentPanel));
                }
                if (RedditContentPanel.CanHandlePost(source))
                {
                    return(typeof(RedditContentPanel));
                }
                if (CommentSpoilerContentPanel.CanHandlePost(source))
                {
                    return(typeof(CommentSpoilerContentPanel));
                }
                if (WindowsAppContentPanel.CanHandlePost(source))
                {
                    return(typeof(WindowsAppContentPanel));
                }
            }
            catch (Exception e)
            {
                // If we fail here we will fall back to the web browser.
                App.BaconMan.MessageMan.DebugDia("Failed to query can handle post", e);
                TelemetryManager.ReportUnexpectedEvent(callingClass, "FailedToQueryCanHandlePost", e);
            }

            return(typeof(WebPageContentPanel));
        }
コード例 #2
0
        public async Task <bool> CreateContentPanel(ContentPanelSource source, bool canLoadLargePanels)
        {
            // Indicates if the panel was loaded.
            bool loadedPanel = true;

            // Capture the source
            Source = source;

            // We default to web page
            Type controlType = typeof(WebPageContentPanel);

            // If we are not forcing web find the control type.
            if (!source.ForceWeb)
            {
                // Try to figure out the type.
                try
                {
                    if (GifImageContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(GifImageContentPanel);
                    }
                    else if (YoutubeContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(YoutubeContentPanel);
                    }
                    else if (BasicImageContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(BasicImageContentPanel);
                    }
                    else if (MarkdownContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(MarkdownContentPanel);
                    }
                    else if (RedditContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(RedditContentPanel);
                    }
                    else if (CommentSpoilerContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(CommentSpoilerContentPanel);
                    }
                    else if (WindowsAppContentPanel.CanHandlePost(source))
                    {
                        controlType = typeof(WindowsAppContentPanel);
                    }
                    else
                    {
                        // This is a web browser

                        // If we are blocking large panels don't allow the
                        // browser.
                        if (!canLoadLargePanels)
                        {
                            loadedPanel = false;
                        }
                    }
                }
                catch (Exception e)
                {
                    // If we fail here we will fall back to the web browser.
                    App.BaconMan.MessageMan.DebugDia("Failed to query can handle post", e);
                    App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "FailedToQueryCanHandlePost", e);
                }
            }

            // Check if we should still load.
            if (loadedPanel)
            {
                // Make the control on the UI thread.
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    try
                    {
                        // Create the panel
                        Panel = (IContentPanel)Activator.CreateInstance(controlType, this);

                        // Fire OnPrepareContent
                        Panel.OnPrepareContent();
                    }
                    catch (Exception e)
                    {
                        loadedPanel = false;
                        HasError    = true;
                        App.BaconMan.MessageMan.DebugDia("failed to create content control", e);
                        App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "FailedToCreateContentPanel", e);
                    }
                });
            }

            // Indicate that we have loaded.
            return(loadedPanel);
        }