Example #1
0
        public void AsyncStateChange_UserThread()
        {
            SilverlightHost host     = Application.Current.Host;
            bool            complete = false;
            bool            status   = false;
            int             tid      = Thread.CurrentThread.ManagedThreadId;
            Thread          t        = new Thread(() => {
                try {
                    Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, tid, "ManagedThreadId");
                    Assert.Throws <UnauthorizedAccessException> (delegate {
                        host.NavigationStateChanged += host_NavigationStateChanged;
                    }, "add_NavigationStateChanged");
                    Assert.Throws <UnauthorizedAccessException> (delegate {
                        Assert.IsNotNull(host.NavigationState, "get");
                    }, "get_NavigationState");
                    Assert.Throws <UnauthorizedAccessException> (delegate {
                        host.NavigationState = "user thread";
                    }, "set_NavigationState");
                    host.NavigationStateChanged -= host_NavigationStateChanged;
                    status = true;
                }
                finally {
                    complete = true;
                    Assert.IsTrue(status, "Success");
                }
            });

            t.Start();
            EnqueueConditional(() => complete);
            EnqueueTestComplete();
        }
Example #2
0
        public void AsyncStateChange_Dispatch()
        {
            SilverlightHost host     = Application.Current.Host;
            bool            complete = false;
            bool            status   = false;
            int             tid      = Thread.CurrentThread.ManagedThreadId;

            Application.Current.RootVisual.Dispatcher.BeginInvoke(() => {
                try {
                    Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, tid, "ManagedThreadId");
                    host.NavigationStateChanged += host_NavigationStateChanged;
                    host.NavigationState         = "dispatch";             // set
                    Assert.AreEqual("dispatch", host.NavigationState, "get");
                    host.NavigationStateChanged -= host_NavigationStateChanged;
                    status = true;
                }
                finally {
                    complete             = true;
                    host.NavigationState = String.Empty;
                    Assert.IsTrue(status, "Success");
                }
            });
            EnqueueConditional(() => complete);
            EnqueueTestComplete();
        }
Example #3
0
        public void NavigationState()
        {
            SilverlightHost host = Application.Current.Host;

            Assert.Throws <ArgumentNullException> (delegate {
                host.NavigationState = null;
            }, "null");
        }
        public VideoWindowView()
        {
            InitializeComponent();

            SilverlightHost currentHost = Application.Current.Host;

            //The XamHtmlViewer works with Windowless set to false.
            if (!currentHost.Settings.Windowless)
            {
                ExpanderDetails.Visibility = Visibility.Collapsed;
            }
        }
Example #5
0
        public void InitParams()
        {
            SilverlightHost host = Application.Current.Host;

            // what's added at Application.Startup is available later (see App.xaml.cs)
            Assert.IsTrue(host.InitParams.ContainsKey("Moon-y-Test"), "Application_Startup");
            int n = host.InitParams.Count;

            host.InitParams.Add("a", "b");              // not read-only
            // a single copy is kept
            Assert.AreEqual(n + 1, Application.Current.Host.InitParams.Count, "Count");
            host.InitParams.Remove("a");
            Assert.AreEqual(n, Application.Current.Host.InitParams.Count, "Count-2");
        }
Example #6
0
        void Check(SilverlightHost host)
        {
            Assert.AreEqual(Colors.White, host.Background, "Background");
            Assert.IsNotNull(host.Content, "Content");
            Assert.IsTrue(host.IsLoaded, "IsLoaded");
            Assert.AreEqual(String.Empty, host.NavigationState, "NavigationState");
            Assert.IsNotNull(host.Settings, "Settings");
            // ensure this works with 'moon-unit#.xap'
            string ba = host.Source.AbsoluteUri;

            Assert.IsTrue(ba.EndsWith(".xap"), "Source (.xap)");
            int last_slash = ba.LastIndexOf('/');

            Assert.IsTrue(ba.Substring(last_slash, ba.Length - last_slash - 5) == "/moon-unit", "Source: " + ba);
        }
Example #7
0
        public void IsVersionSupported()
        {
            SilverlightHost host = new SilverlightHost();

            Assert.Throws(delegate { host.IsVersionSupported(null); }, typeof(NullReferenceException), "IsVersionSupported(null)");

            Assert.IsFalse(host.IsVersionSupported(String.Empty), "Empty");
            Assert.IsFalse(host.IsVersionSupported("1"), "1");
            Assert.IsFalse(host.IsVersionSupported("1."), "1.");
            Assert.IsTrue(host.IsVersionSupported("1.0"), "1.0");
            Assert.IsFalse(host.IsVersionSupported("1.0."), "1.0.");
            Assert.IsTrue(host.IsVersionSupported("1.0.0"), "1.0.0");
            Assert.IsFalse(host.IsVersionSupported("1.0.0."), "1.0.0.");
            Assert.IsTrue(host.IsVersionSupported("1.0.0.0"), "1.0.0.0");
            Assert.IsFalse(host.IsVersionSupported("1.0.0.0."), "1.0.0.0.");
            Assert.IsFalse(host.IsVersionSupported("1.0.0.0.0"), "1.0.0.0.0");
        }
Example #8
0
        public void StateChange()
        {
            SilverlightHost host = Application.Current.Host;

            Assert.AreEqual(String.Empty, host.NavigationState, "NavigationState-original");
            Assert.AreEqual(String.Empty, HtmlPage.Window.CurrentBookmark, "CurrentBookmark-original");
            // Empty by default - but some other (previous) test may have already changed it to '#'
            Assert.IsTrue(IsFragmentEmptyOrSharp(HtmlPage.Document.DocumentUri.Fragment), "Fragment-original");

            int n = 0;

            host.NavigationStateChanged += delegate(object sender, NavigationStateChangedEventArgs e) {
                Assert.AreSame(host, sender, "sender");
                Assert.AreEqual(n == 0 ? "a" : String.Empty, e.NewNavigationState, "NewNavigationState");
                Assert.AreEqual(n == 0 ? String.Empty : "a", e.PreviousNavigationState, "PreviousNavigationState");
                n++;
            };

            host.NavigationState = host.NavigationState;
            Assert.AreEqual(n, 0, "same state");
            Assert.AreEqual(String.Empty, HtmlPage.Window.CurrentBookmark, "CurrentBookmark-same");
            // resetting NavigationState to same (even empty) value introduced a '#' for fragment
            Assert.IsTrue(IsFragmentEmptyOrSharp(HtmlPage.Document.DocumentUri.Fragment), "Fragment-same");

            host.NavigationState = "a";
            Assert.AreEqual(n, 1, "different state");
            Assert.AreEqual("a", HtmlPage.Window.CurrentBookmark, "CurrentBookmark-a");
            Assert.AreEqual("#a", HtmlPage.Document.DocumentUri.Fragment, "Fragment-a");

            host.NavigationState = String.Empty;
            Assert.AreEqual(n, 2, "back to original");
            Assert.AreEqual(String.Empty, HtmlPage.Window.CurrentBookmark, "CurrentBookmark-b");
            Assert.IsTrue(IsFragmentEmptyOrSharp(HtmlPage.Document.DocumentUri.Fragment), "Fragment-b");

            // using CurrentBookmark will change NavigationState but won't fire the event
            HtmlPage.Window.CurrentBookmark = "a";
            Assert.AreEqual(n, 2, "different state using CurrentBookmark");
            Assert.AreEqual("a", host.NavigationState, "Document-a2");
            Assert.AreEqual("#a", HtmlPage.Document.DocumentUri.Fragment, "Fragment-a2");

            HtmlPage.Window.CurrentBookmark = String.Empty;
            Assert.AreEqual(n, 2, "back to original using CurrentBookmark");
            Assert.AreEqual(String.Empty, host.NavigationState, "Document-b2");
            Assert.IsTrue(IsFragmentEmptyOrSharp(HtmlPage.Document.DocumentUri.Fragment), "Fragment-b2");
        }
Example #9
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            UpdateOOB(); //TODO: run this from background thread, seems to take some time //CALLING THIS FIRST, SINCE THE REST OF THE CODE COULD THROW AN EXCEPTION WHICH WOULD BLOCK UPDATES (AND ALSO TO MAKE USE OF THE TIME TO SET UP THE APP, SINCE UPDATING OCCURS IN THE BACKGROUND)

            LocalizeUI();

            silverlightHost = Application.Current.Host;
            settings        = silverlightHost.Settings;
            content         = silverlightHost.Content;

            if (!IsRunningOutOfBrowser)
            {
                queryString = HtmlPage.Document.QueryString;
            }

            //// Read/write properties of the Settings object.
            //settings.EnableFrameRateCounter = true;
            //settings.EnableRedrawRegions = true;
            //settings.MaxFrameRate = 60;

            //// Read-only properties of the Settings object.
            //bool windowless = settings.Windowless;
            //bool htmlAccessEnabled = settings.EnableHTMLAccess;

            //// The read/write IsFullScreen property of the Content object.
            //// See also the Content.FullScreenChanged event.
            //bool isFullScreen = content.IsFullScreen;

            FloatingWindowHost host = new FloatingWindowHost(); //don't use FloatingWindowHostZUI here

            host.CloseWindowsOnApplicationExit = true;          //only using for the parent of the toplevel ActivityWindow, else multiple closing warning dialogs can show up
            host.BorderThickness = new Thickness(0);            //removing border of outer FloatingWindowHost container so that activityWindow will take up all space of the Silverlight control

            ActivityWindow activityWindow = CreateActivityWindow(host);

            if (IsRunningOutOfBrowser) //Must not set this for in-browser apps, else warning that this will be ignored will be shown at runtime

            {
                App.Current.MainWindow.Closing += (s, ev) => //due to a bug in Silverlight, this has to be attached BEFORE setting the App's RootVisual
                {
                    if (activityWindow.View.WarnOnClosing)
                    {
                        if (MessageBox.Show(ClipFlairStudioStrings.MsgExit + " " + ProductName + ClipFlairStudioStrings.MsgQuestionMark, ClipFlairStudioStrings.MsgConfirmation, MessageBoxButton.OKCancel) != MessageBoxResult.OK)
                        {
                            ev.Cancel = true;
                            return;
                        }
                        else //proceed with app closing
                        {
                            activityWindow.View.WarnOnClosing = false; //disable warning before proceeding with close (not really needed, since the ActivityWindow checks if it's TopLevel or not)
                        }
                    }
                    activityWindow.Container.DisableChildrenWarnOnClosing();
                    activityWindow.Close();
                }
            }
            ;


            host.Rendered += (s, ev) =>
                                               //content.Resized += (s, ev) => //if we use this, should use as a method so that we can remove it after 1st call
            {
                host.IsToolbarVisible = false; //hide outer container's toolbar, only want to show the one of the ActivityContainer that the ActivityWindow hosts
                activityWindow.Width  = host.ActualWidth;
                activityWindow.Height = host.ActualHeight;

                if (!IsRunningOutOfBrowser)
                {
                    HtmlPage.RegisterScriptableObject("activityWindow", activityWindow); //NOTE: must do this only after setting RootVisual (obviously for Rendered to be called this will have occured)

                    if (queryString.ContainsKey(PARAMETER_ICONBAR))
                    {
                        activityWindow.ActivityView.IconbarVisible = true;
                    }
                    //if (queryString.ContainsKey(PARAMETER_LOCKICONBAR))
                    //  activityWindow.ActivityView.IconbarAutoHide = false;
                    if (queryString.ContainsKey(PARAMETER_NOTOOLBAR))
                    {
                        activityWindow.ActivityView.ToolbarVisible = false;
                    }
                }

                if (!ParseUrlParameters(activityWindow)) //ParseUrlParameters returns false if IsRunningOutOfBrowser is true
                {
                    activityWindow.ShowStartDialog();
                }
            };

            //host.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentUICulture.Name); //don't do this, will use "," for decimal points in some cultures, which could cause problems with fractional times etc. //TODO: test if this is indeed a problem with the data binding in CaptionsGrid control
            RootVisual = host;

            //MessageBox.Show("ClipFlair loaded"); //uncomment this to test the loading indicator
        }
Example #10
0
        public void Current()
        {
            SilverlightHost host = Application.Current.Host;

            Check(host);
        }
Example #11
0
        public void New()
        {
            SilverlightHost host = new SilverlightHost();

            Check(host);
        }