Beispiel #1
0
        public void FragmentWithIdentifier()
        {
            string     UriPattern       = "Simple/{id}/{foo}";
            string     MappedUriPattern = "Result.xaml?{foo}2=6#fragment{id}";
            UriMapping alias            = new UriMapping();

            alias.Uri       = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123/myVar?x=10", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary <string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase  = UriParsingHelper.InternalUriGetBaseValue(result);
            string fragment = UriParsingHelper.InternalUriGetFragment(result);

            Assert.AreEqual <string>("Result.xaml", uriBase);
            Assert.IsFalse(queryStringValues.ContainsKey("id"));
            Assert.IsFalse(queryStringValues.ContainsKey("foo"));
            Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10");
            Assert.IsTrue(queryStringValues.ContainsKey("myVar2") && queryStringValues["myVar2"] == "6");
            Assert.AreEqual("fragment123", fragment);
        }
Beispiel #2
0
        public void OnlyQueryStringInMappedUriTemplateThrows()
        {
            string UriPattern       = "Simple";
            string MappedUriPattern = "?Result=1";

            UriMapping alias = new UriMapping();

            alias.Uri       = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // This is expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
Beispiel #3
0
        public void UriCannotContainQueryString()
        {
            string UriPattern       = "Simple?var1={x}";
            string MappedUriPattern = "Result.xaml?id={x}";

            UriMapping alias = new UriMapping();

            alias.Uri       = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple?var1=10", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // This is expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
Beispiel #4
0
        public void FragmentInUriTemplateThrows()
        {
            string UriPattern       = "Simple/var1={x}#foo";
            string MappedUriPattern = "Result";

            UriMapping alias = new UriMapping();

            alias.Uri       = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/var1=10#foo", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // This is expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
Beispiel #5
0
        static void Main()
        {
            Program.SetupPermissions();

            SettingsHandlers.Register();
            SystemUsersHandlers.Register();
            SystemUserGroupsHandlers.Register();
            CommitHooks.Register();
            LauncherHooks.Register();


            // Mapping issue
            // https://github.com/Starcounter/Starcounter/issues/2902
            UriMapping.OntologyMap("/UserAdmin/admin/users/@w", "Simplified.Ring2.Person",

                                   (String fromSo) => {
                var user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID=?", fromSo).First;
                if (user != null)
                {
                    return(user.WhatIs.Key);
                }

                return(null);
            },
                                   (String fromSo) => {
                var user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.WhatIs.ObjectID=?", fromSo).First;

                if (user != null)
                {
                    return(user.Key);
                }
                return(null);
            }
                                   );
        }
Beispiel #6
0
        public void UriParameterUsedTwiceThrows()
        {
            string     UriPattern       = "Simple/{id}/{id}";
            string     MappedUriPattern = "Result/{id}";
            UriMapping alias            = new UriMapping();

            alias.Uri       = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123/123", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // Expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
        /// <summary>
        /// Initializes a new instance of ExtensionUriMapper.
        /// </summary>
        public ExtensionUriMapper()
        {
            _uriMappings = new Collection <UriMapping>();

            // 1) Neutral mapping to preserve full base URI.
            // i.e. /Perspective.Demo;component/View/ShapeDemo.xaml
            UriMapping m1 = CreateMapping(
                "/{assembly};component/View/{pageName}.xaml",
                "/{assembly};component/View/{pageName}.xaml");

            _uriMappings.Add(m1);

            // 2) Simple mapping mapping for arguments
            // i.e. /Perspective.Demo/ShapeDemo/Polygon/8
            UriMapping m2 = CreateMapping(
                "/{assembly}/{pageName}/{argKey}/{argValue}",
                "/{assembly};component/View/{pageName}.xaml?{argKey}={argValue}");

            _uriMappings.Add(m2);

            // 3) Simple mapping to load a page
            // i.e. /Perspective.Demo/ShapeDemo
            UriMapping m3 = CreateMapping(
                "/{assembly}/{pageName}",
                "/{assembly};component/View/{pageName}.xaml");

            _uriMappings.Add(m3);
        }
        private UriMapping CreateMapping(string uriString, string uriMappedString)
        {
            UriMapping mapping = new UriMapping();

            mapping.Uri       = new Uri(uriString, UriKind.Relative);
            mapping.MappedUri = new Uri(uriMappedString, UriKind.Relative);
            return(mapping);
        }
        private static void GlobalizedTestCore(Uri uri, Uri mappedUri, Uri inputUri, Uri expectedOutputUri)
        {
            UriMapping mapping = new UriMapping();
            mapping.Uri = uri;
            mapping.MappedUri = mappedUri;

            Uri outputUri = mapping.MapUri(inputUri);

            Assert.AreEqual(expectedOutputUri, outputUri);
        }
        public void EmptyUriMapping()
        {
            Uri emptyUri  = new Uri(String.Empty, UriKind.Relative);
            Uri mappedUri = new Uri("mapped", UriKind.Relative);

            UriMapping emptyUriToMappedUri = new UriMapping()
            {
                Uri       = new Uri(String.Empty, UriKind.Relative),
                MappedUri = mappedUri
            };

            UriMapping nullUriToMappedUri = new UriMapping()
            {
                Uri       = null,
                MappedUri = mappedUri
            };

            UriMapping otherMapping = new UriMapping()
            {
                Uri       = new Uri("abc", UriKind.Relative),
                MappedUri = new Uri("other mapped", UriKind.Relative)
            };


            // Should be the emptyUri when there's no UriMappings present
            this.UriMapper.UriMappings.Clear();
            Assert.AreEqual(emptyUri, this.UriMapper.MapUri(emptyUri), "did not map to emptyUri with no UriMappings present");

            // Should be the emptyUri when there's a UriMapping present that does not map from Uri=""
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(otherMapping);
            Assert.AreEqual(emptyUri, this.UriMapper.MapUri(emptyUri), "did not map to emptyUri with a UriMapping present where Uri!=\"\"");

            // Should be the MappedUri when there's a UriMapping present that maps from Uri=""
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(emptyUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=\"\"");

            // Should be the MappedUri when there's a UriMapping present that maps from Uri=null
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(nullUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=null");

            // Should be the MappedUri when there's multiple UriMappings present, one of which maps from Uri=""
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(otherMapping);
            this.UriMapper.UriMappings.Add(emptyUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=\"\" and multiple UriMappings");

            // Should be the MappedUri when there's multiple UriMappings present, one of which maps from Uri=null
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(otherMapping);
            this.UriMapper.UriMappings.Add(nullUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=null and multiple UriMappings");
        }
        public void EmptyUriMapping()
        {
            Uri emptyUri = new Uri(String.Empty, UriKind.Relative);
            Uri mappedUri = new Uri("mapped", UriKind.Relative);

            UriMapping emptyUriToMappedUri = new UriMapping()
                {
                    Uri = new Uri(String.Empty, UriKind.Relative),
                    MappedUri = mappedUri
                };

            UriMapping nullUriToMappedUri = new UriMapping()
                {
                    Uri = null,
                    MappedUri = mappedUri
                };

            UriMapping otherMapping = new UriMapping()
                {
                    Uri = new Uri("abc", UriKind.Relative),
                    MappedUri = new Uri("other mapped", UriKind.Relative)
                };


            // Should be the emptyUri when there's no UriMappings present
            this.UriMapper.UriMappings.Clear();
            Assert.AreEqual(emptyUri, this.UriMapper.MapUri(emptyUri), "did not map to emptyUri with no UriMappings present");

            // Should be the emptyUri when there's a UriMapping present that does not map from Uri=""
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(otherMapping);
            Assert.AreEqual(emptyUri, this.UriMapper.MapUri(emptyUri), "did not map to emptyUri with a UriMapping present where Uri!=\"\"");

            // Should be the MappedUri when there's a UriMapping present that maps from Uri=""
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(emptyUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=\"\"");

            // Should be the MappedUri when there's a UriMapping present that maps from Uri=null
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(nullUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=null");

            // Should be the MappedUri when there's multiple UriMappings present, one of which maps from Uri=""
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(otherMapping);
            this.UriMapper.UriMappings.Add(emptyUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=\"\" and multiple UriMappings");

            // Should be the MappedUri when there's multiple UriMappings present, one of which maps from Uri=null
            this.UriMapper.UriMappings.Clear();
            this.UriMapper.UriMappings.Add(otherMapping);
            this.UriMapper.UriMappings.Add(nullUriToMappedUri);
            Assert.AreEqual(mappedUri, this.UriMapper.MapUri(emptyUri), "did not map to mappedUri with UriMapping.Uri=null and multiple UriMappings");
        }
        public void NoUriTemplateDoesNotMatchNonNullInput()
        {
            string MappedUriPattern = "Result.xaml?id={x}";

            UriMapping alias = new UriMapping();
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple?var1=10", UriKind.Relative);

            Assert.IsNull(alias.MapUri(testUri));
        }
        public void NonMatchingFails()
        {
            string UriPattern = "Simple";
            string MappedUriPattern = "Result/123?x=10";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri(UriPattern + "/123", UriKind.Relative);

            Uri result = alias.MapUri(testUri); ;

            Assert.IsNull(result);
        }
        public void NonMatchingFails()
        {
            string UriPattern = "Simple";
            string MappedUriPattern = "Result/123?x=10";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri(UriPattern + "/123", UriKind.Relative);

            Uri result = alias.MapUri(testUri); ;

            Assert.IsNull(result);
        }
        public void SimpleMatch()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            Assert.AreEqual<string>("Result/123", result.OriginalString);
        }
        public void NoUriParametersIsPassthrough()
        {
            string UriPattern = "Simple";
            string MappedUriPattern = "Result/123?x=10";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri(UriPattern, UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            Assert.AreEqual<string>(MappedUriPattern, result.OriginalString);
        }
        public void NoUriParametersIsPassthrough()
        {
            string UriPattern = "Simple";
            string MappedUriPattern = "Result/123?x=10";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri(UriPattern, UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            Assert.AreEqual<string>(MappedUriPattern, result.OriginalString);
        }
        public void SimpleMatch()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            Assert.AreEqual<string>("Result/123", result.OriginalString);
        }
        public void NoUriTemplateReturnsMappedUriExactlyWithNullInput()
        {
            string MappedUriPattern = "Result.aspx?id={x}";

            UriMapping alias = new UriMapping();
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri1 = null;
            Uri testUri2 = new Uri(String.Empty, UriKind.Relative);

            Uri result1 = alias.MapUri(testUri1);
            Uri result2 = alias.MapUri(testUri2);

            Assert.AreEqual(MappedUriPattern, result1.OriginalString);
            Assert.AreEqual(MappedUriPattern, result2.OriginalString);
        }
Beispiel #20
0
        private static void Uri_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UriMapping mapping  = (UriMapping)d;
            Uri        newValue = (Uri)e.NewValue;

#if BRIDGE
            Regex r = new Regex("{[^}]*}");                          //this should be read as '{' followed by anything but '}', then '}'
#else
            Regex r = new Regex("{[^}]*}", RegexOptions.ECMAScript); //this should be read as '{' followed by anything but '}', then '}'
#endif
            mapping._groupNames = new List <string>();
            foreach (Match match in r.Matches(newValue.OriginalString))
            {
                mapping._groupNames.Add(match.Value);
            }
            mapping._regularExpressionToApplyOnUriToMap = r.Replace(newValue.OriginalString, "(.*)"); //whatever is needed to say "anything".
        }
Beispiel #21
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            var bingMapping = new UriMapping
            {
                Uri       = new Uri("/SearchExtras", UriKind.Relative),
                MappedUri = new Uri("/MainPage.xaml", UriKind.Relative)
            };

            var mapper = new UriMapper();

            mapper.UriMappings.Add(bingMapping);
            RootFrame.UriMapper = mapper;
        }
        public void QueryStringValueInMappedUriAndActualUriHasActualUriWin()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{id}?ShowDetails=true";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123?ShowDetails=false", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase = UriParsingHelper.InternalUriGetBaseValue(result);

            Assert.AreEqual<string>("Result/123", uriBase);
            Assert.IsFalse(queryStringValues.ContainsKey("id"));
            Assert.IsTrue(queryStringValues.ContainsKey("ShowDetails") && queryStringValues["ShowDetails"] == "false");
        }
        public void MappedUriParameterUsedTwiceValid()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{id}.xaml?id={id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123?x=10", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase = UriParsingHelper.InternalUriGetBaseValue(result);

            Assert.AreEqual<string>("Result/123.xaml", uriBase);
            Assert.IsTrue(queryStringValues.ContainsKey("id") && queryStringValues["id"] == "123");
            Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10");
        }
        public void SimpleMatchOriginalUriQueryStringPreserved()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123?x=10&id=456", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase = UriParsingHelper.InternalUriGetBaseValue(result);

            Assert.AreEqual<string>("Result/123", uriBase);
            Assert.AreEqual(2, queryStringValues.Count);
            Assert.IsTrue(queryStringValues.ContainsKey("id") && queryStringValues["id"] == "456");
            Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10");
        }
        private static UriMapper CreateOldAppMapping()
        {
            var mapping = new UriMapping {
                Uri = new Uri(ExampleNavigationPattern, UriKind.RelativeOrAbsolute), MappedUri = new Uri(OldAppNavigationPattern, UriKind.RelativeOrAbsolute)
            };
            var mapper = new UriMapper();

            mapper.UriMappings.Add(mapping);

            var examples = Module.ChartingPages.Where(x => x.Value is ExampleAppPage).Select(x => x.Value);

            foreach (var example in examples)
            {
                mapper.UriMappings.Add(new UriMapping
                {
                    Uri       = mapping.MapUri(new Uri(example.MappedUri, UriKind.RelativeOrAbsolute)),
                    MappedUri = new Uri(example.Uri, UriKind.RelativeOrAbsolute),
                });
            }

            return(mapper);
        }
Beispiel #26
0
        protected void RegisterMap()
        {
            UriMapping.Map("/chatter/app-name", "/sc/mapping/app-name");
            UriMapping.Map("/chatter/menu", "/sc/mapping/menu");

            UriMapping.OntologyMap("/chatter/partials/people/{?}", "simplified.ring2.person");

            #region Custom application ontology mapping
            UriMapping.OntologyMap("/chatter/partials/chatmessages/{?}", "simplified.ring6.chatmessage", (string objectId) => objectId, (string objectId) =>
            {
                var message = DbHelper.FromID(DbHelper.Base64DecodeObjectID(objectId)) as ChatMessage;
                return(message.IsDraft ? null : objectId);
            });
            UriMapping.OntologyMap("/chatter/partials/chatmessages-draft/{?}", "simplified.ring6.chatmessage", (string objectId) => objectId, (string objectId) =>
            {
                var chatMessage = (ChatMessage)DbHelper.FromID(DbHelper.Base64DecodeObjectID(objectId));
                return(chatMessage.IsDraft ? objectId : null);
            });

            UriMapping.OntologyMap("/chatter/partials/chatattachments/{?}", "simplified.ring6.chatattachment");
            UriMapping.OntologyMap("/chatter/partials/chatdraftannouncements/{?}", "simplified.ring6.chatdraftannouncement");
            UriMapping.OntologyMap("/chatter/partials/chatwarnings/{?}", "simplified.ring6.chatwarning");
            #endregion
        }
Beispiel #27
0
        static void Main()
        {
            Handle.GET("/KitchenSink/standalone", () => {
                Session session = Session.Current;

                if (session != null && session.Data != null)
                {
                    return(session.Data);
                }

                var standalone = new StandalonePage();

                if (session == null)
                {
                    session         = new Session(SessionOptions.PatchVersioning);
                    standalone.Html = "/KitchenSink/StandalonePage.html";
                }
                else
                {
                    standalone.Html = "/KitchenSink/LauncherWrapperPage.html";
                }

                var nav = new NavPage();
                standalone.CurrentPage = nav;

                standalone.Session = session;
                return(standalone);
            });

            Handle.GET("/KitchenSink", () => {
                return(Self.GET("/KitchenSink/text"));
            });

            Handle.GET("/KitchenSink/button", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is ButtonPage))
                {
                    var page = new ButtonPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/chart", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is ChartPage))
                {
                    var page = new ChartPage();

                    page.AddChartData("January", 4);
                    page.AddChartData("February", 7);
                    page.AddChartData("March", 9);
                    page.AddChartData("April", 12);
                    page.AddChartData("May", 15);
                    page.AddChartData("June", 19);

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/checkbox", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is CheckboxPage))
                {
                    var page = new CheckboxPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/datagrid", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is DatagridPage))
                {
                    var page = new DatagridPage();

                    DatagridPagePetsElementJson pet;
                    pet      = page.Pets.Add();
                    pet.Name = "Rocky";
                    pet.Kind = "Dog";

                    pet      = page.Pets.Add();
                    pet.Name = "Tigger";
                    pet.Kind = "Cat";

                    pet      = page.Pets.Add();
                    pet.Name = "Bella";
                    pet.Kind = "Rabbit";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/decimal", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is DecimalPage))
                {
                    var page   = new DecimalPage();
                    page.Price = 10;
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/dropdown", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is DropdownPage))
                {
                    var page = new DropdownPage();

                    DropdownPage.PetsElementJson pet;
                    pet       = page.Pets.Add();
                    pet.Label = "dogs";

                    pet       = page.Pets.Add();
                    pet.Label = "cats";

                    pet       = page.Pets.Add();
                    pet.Label = "rabbit";

                    page.SelectedPet = "dogs";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/html", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is HtmlPage))
                {
                    var page = new HtmlPage();
                    page.Bio = @"<h1>This is a markup text</h1>

You can put <strong>any</strong> <a href=""https://en.wikipedia.org/wiki/HTML"">HTML</a> in it.";
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/integer", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is IntegerPage))
                {
                    var page = new IntegerPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/Geo", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is MapPage))
                {
                    var page = new MapPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/markdown", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is MarkdownPage))
                {
                    var page = new MarkdownPage();
                    page.Bio = @"# This is a strucured text

It supports **markdown** *syntax*.";
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/radiolist", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is RadiolistPage))
                {
                    var page = new RadiolistPage();
                    MenuOptionsElement a;
                    a       = page.MenuOptions.Add();
                    a.Label = "Dogs";
                    a       = page.MenuOptions.Add();
                    a.Label = "Cats";
                    page.SelectOption(0);
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/multiselect", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is MultiselectPage))
                {
                    var page = new MultiselectPage()
                    {
                        Data = null
                    };
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/password", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is PasswordPage))
                {
                    var page = new PasswordPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/table", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is TablePage))
                {
                    var page = new TablePage();

                    TablePage.PetsElementJson pet;
                    pet      = page.Pets.Add();
                    pet.Name = "Rocky";
                    pet.Kind = "Dog";

                    pet      = page.Pets.Add();
                    pet.Name = "Tigger";
                    pet.Kind = "Cat";

                    pet      = page.Pets.Add();
                    pet.Name = "Bella";
                    pet.Kind = "Rabbit";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/text", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is TextPage))
                {
                    var page = new TextPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/textarea", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is TextareaPage))
                {
                    var page = new TextareaPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/radio", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is RadioPage))
                {
                    var page = new RadioPage();

                    RadioPage.PetsElementJson pet;
                    pet       = page.Pets.Add();
                    pet.Label = "dogs";

                    pet       = page.Pets.Add();
                    pet.Label = "cats";

                    pet       = page.Pets.Add();
                    pet.Label = "rabbit";

                    page.SelectedPet = "dogs";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/url", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is UrlPage))
                {
                    var page   = new UrlPage();
                    page.Url   = "/KitchenSink";
                    page.Label = "Go to home page";
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            //for a launcher
            Handle.GET("/KitchenSink/app-name", () => {
                return(new AppName());
            });

            Handle.GET("/KitchenSink/menu", () => {
                return(new Page()
                {
                    Html = "/KitchenSink/AppMenuPage.html"
                });
            });

            UriMapping.Map("/KitchenSink/menu", UriMapping.MappingUriPrefix + "/menu");
            UriMapping.Map("/KitchenSink/app-name", UriMapping.MappingUriPrefix + "/app-name");
        }
Beispiel #28
0
        static void Main()
        {
            Handle.GET("/ProcurementStats", () => {
                MasterPage master;

                if (Session.Current != null && Session.Current.Data != null)
                {
                    master = (MasterPage)Session.Current.Data;
                }
                else
                {
                    master = new MasterPage();

                    if (Session.Current != null)
                    {
                        master.Html    = "/ProcurementStats/viewmodels/LauncherWrapperPage.html";
                        master.Session = Session.Current;
                    }
                    else
                    {
                        master.Html    = "/ProcurementStats/viewmodels/MasterPage.html";
                        master.Session = new Session(SessionOptions.PatchVersioning);
                    }

                    master.RecentGraphs = new GraphsPage()
                    {
                        Html = "/ProcurementStats/viewmodels/GraphsPage.html"
                    };
                }

                ((GraphsPage)master.RecentGraphs).RefreshData();
                master.FocusedGraph = null;

                return(master);
            });

            Handle.GET("/ProcurementStats/NewGraph", () => {
                MasterPage master   = Self.GET <MasterPage>("/ProcurementStats");
                master.FocusedGraph = Db.Scope <GraphPage>(() => {
                    GraphPage page = new GraphPage()
                    {
                        Html = "/ProcurementStats/viewmodels/GraphPage.html",
                        Data = new Simplified.Ring6.ProcurementGraph()
                        {
                            DateTo = DateTime.Now.Date, DateFrom = DateTime.Now.AddMonths(-1).Date
                        }
                    };

                    page.Saved += (s, a) => {
                        ((GraphsPage)master.RecentGraphs).RefreshData();
                    };

                    page.Deleted += (s, a) => {
                        ((GraphsPage)master.RecentGraphs).RefreshData();
                    };

                    return(page);
                });
                return(master);
            });

            Handle.GET("/ProcurementStats/Details/{?}", (string Key) => {
                MasterPage master   = Self.GET <MasterPage>("/ProcurementStats");
                master.FocusedGraph = Db.Scope <GraphPage>(() => {
                    var page = new GraphPage()
                    {
                        Html = "/ProcurementStats/viewmodels/GraphPage.html",
                        Data = Db.SQL <Simplified.Ring6.ProcurementGraph>(@"SELECT i FROM Simplified.Ring6.ProcurementGraph i WHERE Key = ?", Key).First
                    };

                    page.Saved += (s, a) => {
                        ((GraphsPage)master.RecentGraphs).RefreshData();
                    };

                    page.Deleted += (s, a) => {
                        ((GraphsPage)master.RecentGraphs).RefreshData();
                    };
                    page.RequestGraph();

                    return(page);
                });
                return(master);
            });

            //Handle.GET("/ProcurementStats/Only/{?}", (string Key) => {
            //    GraphPage page = new GraphPage() {
            //        Html = "/ProcurementStats/viewmodels/GraphPage.html",
            //        Data = Db.SQL<Simplified.Ring6.ProcurementGraph>(@"SELECT i FROM Simplified.Ring6.ProcurementGraph i WHERE i.Key = ?", Key).First
            //    };

            //    return page;
            //});

            Handle.GET("/ProcurementStats/menu", () => {
                return(new Page()
                {
                    Html = "/ProcurementStats/viewmodels/AppMenuPage.html"
                });
            });

            Handle.GET("/ProcurementStats/app-name", () => {
                return(new AppName());
            });

            UriMapping.Map("/ProcurementStats/app-name", UriMapping.MappingUriPrefix + "/app-name");
            UriMapping.Map("/ProcurementStats/menu", UriMapping.MappingUriPrefix + "/menu");
        }
Beispiel #29
0
 public void Register()
 {
     UriMapping.Map("/Cashier/menu", UriMapping.MappingUriPrefix + "/menu");
     UriMapping.Map("/Cashier/app-name", UriMapping.MappingUriPrefix + "/app-name");
     //UriMapping.Map("/Cashier/search?query={?}", UriMapping.MappingUriPrefix + "/search?query={?}");
 }
        public static void Register()
        {
            // Workspace root (Launchpad)
            Handle.GET("/useradmin", () => {
                return(Self.GET("/useradmin/admin/users"));
            });

            Handle.GET("/useradmin/standalone", () => {
                Session session = Session.Current;

                if (session != null && session.Data != null)
                {
                    return(session.Data);
                }

                MasterPage masterPage = new MasterPage();

                if (session == null)
                {
                    session         = new Session(SessionOptions.PatchVersioning);
                    masterPage.Html = "/useradmin/viewmodels/launcher/StandalonePage.html";
                }
                else
                {
                    masterPage.Html = "/useradmin/viewmodels/launcher/LauncherWrapperPage.html";
                }

                masterPage.Session = session;
                return(masterPage);
            });


            Handle.GET("/useradmin/app-name", () => {
                return(new AppName());
            });

            // App name required for Launchpad
            Handle.GET("/useradmin/app-icon", () => {
                return(new Page()
                {
                    Html = "/UserAdmin/viewmodels/launcher/AppIconPage.html"
                });
            });

            // Menu
            Handle.GET("/useradmin/menu", () => {
                MasterPage master = GetMaster();

                master.Menu = new AdminMenu()
                {
                    Html = "/UserAdmin/viewmodels/launcher/AppMenuPage.html", IsAdministrator = MasterPage.IsAdmin()
                };
                return(master.Menu);
                //return new UserSessionPage() { Html = "/UserAdmin/viewmodels/launcher/AppMenuPage.html" };

                //return new Page() { Html = "/UserAdmin/viewmodels/launcher/AppMenuPage.html" };
                //UserSessionPage userSessionPage = new UserSessionPage();

                //var menuPage = new AdminMenu() {
                //    Html = "/UserAdmin/viewmodels/launcher/AppMenuPage.html",
                //    IsAdministrator = UserSessionPage.IsAdmin()
                //};

                //userSessionPage.Menu = menuPage;
                //userSessionPage.Session = Session.Current;

                //return menuPage;
            });

            // TODO:
            // Not sure where to put this.
            Handle.GET("/useradmin/search/{?}", (string query) => {
                var result  = new SearchResultPage();
                result.Html = "/UserAdmin/viewmodels/launcher/AppSearchPage.html";

                // If not authorized we don't return any results.
                if (!string.IsNullOrEmpty(query) && MasterPage.IsAdmin())
                {
                    result.Users  = Db.SQL <Simplified.Ring3.SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.Username LIKE ? FETCH ?", "%" + query + "%", 5);
                    result.Groups = Db.SQL <Simplified.Ring3.SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name LIKE ? FETCH ?", "%" + query + "%", 5);
                }

                return(result);
            });

            UriMapping.Map("/useradmin/menu", "/sc/mapping/menu");
            UriMapping.Map("/useradmin/app-name", "/sc/mapping/app-name");
            UriMapping.Map("/useradmin/app-icon", "/sc/mapping/app-icon");
            UriMapping.Map("/useradmin/search/@w", "/sc/mapping/search?query=@w");
        }
        public void MappedUriParameterNotInUriBecomesEmptyString()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{foo}/{id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123?x=10", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase = UriParsingHelper.InternalUriGetBaseValue(result);

            Assert.AreEqual<string>("Result//123", uriBase);
            Assert.IsFalse(queryStringValues.ContainsKey("id"));
            Assert.IsFalse(queryStringValues.ContainsKey("foo"));
            Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10");
        }
Beispiel #32
0
 private void RegisterMapperHandlers()
 {
     UriMapping.Map("/braintree/settings", UriMapping.MappingUriPrefix + "/settings");
     UriMapping.Map("/braintree/menu", UriMapping.MappingUriPrefix + "/menu");
     UriMapping.Map("/braintree/app-name", UriMapping.MappingUriPrefix + "/app-name");
 }
        public void QueryStringValueInMappedUriAndActualUriHasActualUriWin()
        {
            string UriPattern = "Simple/{id}";
            string MappedUriPattern = "Result/{id}?ShowDetails=true";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123?ShowDetails=false", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase = UriParsingHelper.InternalUriGetBaseValue(result);

            Assert.AreEqual<string>("Result/123", uriBase);
            Assert.IsFalse(queryStringValues.ContainsKey("id"));
            Assert.IsTrue(queryStringValues.ContainsKey("ShowDetails") && queryStringValues["ShowDetails"] == "false");
        }
        private static void GlobalizedTestCore(Uri uri, Uri mappedUri, Uri inputUri, Uri expectedOutputUri)
        {
            UriMapping mapping = new UriMapping();
            mapping.Uri = uri;
            mapping.MappedUri = mappedUri;

            Uri outputUri = mapping.MapUri(inputUri);

            Assert.AreEqual(expectedOutputUri, outputUri);
        }
        public void OnlyQueryStringInMappedUriTemplateThrows()
        {
            string UriPattern = "Simple";
            string MappedUriPattern = "?Result=1";

            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // This is expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
        public void FragmentWithIdentifier()
        {
            string UriPattern = "Simple/{id}/{foo}";
            string MappedUriPattern = "Result.xaml?{foo}2=6#fragment{id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123/myVar?x=10", UriKind.Relative);

            Uri result = alias.MapUri(testUri);

            Assert.IsNotNull(result);
            IDictionary<string, string> queryStringValues = UriParsingHelper.InternalUriParseQueryStringToDictionary(result, false /* decodeResults */);
            string uriBase = UriParsingHelper.InternalUriGetBaseValue(result);
            string fragment = UriParsingHelper.InternalUriGetFragment(result);

            Assert.AreEqual<string>("Result.xaml", uriBase);
            Assert.IsFalse(queryStringValues.ContainsKey("id"));
            Assert.IsFalse(queryStringValues.ContainsKey("foo"));
            Assert.IsTrue(queryStringValues.ContainsKey("x") && queryStringValues["x"] == "10");
            Assert.IsTrue(queryStringValues.ContainsKey("myVar2") && queryStringValues["myVar2"] == "6");
            Assert.AreEqual("fragment123", fragment);
        }
        public void FragmentInUriTemplateThrows()
        {
            string UriPattern = "Simple/var1={x}#foo";
            string MappedUriPattern = "Result";

            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/var1=10#foo", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // This is expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
        public void NoUriTemplateDoesNotMatchNonNullInput()
        {
            string MappedUriPattern = "Result.xaml?id={x}";

            UriMapping alias = new UriMapping();
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple?var1=10", UriKind.Relative);

            Assert.IsNull(alias.MapUri(testUri));
        }
        public void NoUriTemplateReturnsMappedUriExactlyWithNullInput()
        {
            string MappedUriPattern = "Result.aspx?id={x}";

            UriMapping alias = new UriMapping();
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri1 = null;
            Uri testUri2 = new Uri(String.Empty, UriKind.Relative);

            Uri result1 = alias.MapUri(testUri1);
            Uri result2 = alias.MapUri(testUri2);

            Assert.AreEqual(MappedUriPattern, result1.OriginalString);
            Assert.AreEqual(MappedUriPattern, result2.OriginalString);
        }
Beispiel #40
0
        static void Main()
        {
            Handle.GET("/Graph", () => {
                MasterPage master;

                if (Session.Current != null && Session.Current.Data != null)
                {
                    master = (MasterPage)Session.Current.Data;
                }
                else
                {
                    master = new MasterPage();

                    if (Session.Current != null)
                    {
                        master.Html    = "/Graph/viewmodels/LauncherWrapperPage.html";
                        master.Session = Session.Current;
                    }
                    else
                    {
                        master.Html    = "/Graph/viewmodels/MasterPage.html";
                        master.Session = new Session(SessionOptions.PatchVersioning);
                    }

                    master.RecentGraphs = new GraphsPage()
                    {
                        Html = "/Graph/viewmodels/GraphsPage.html"
                    };
                }

                ((GraphsPage)master.RecentGraphs).RefreshData();
                master.FocusedGraph = null;

                return(master);
            });

            //The bug! /Graph/Graphs/{?} returns Not found exception
            Handle.GET("/Graph/Details/{?}", (string Key) => {
                FillTestData();

                MasterPage master   = Self.GET <MasterPage>("/Graph");
                master.FocusedGraph = Self.GET <GraphPage>("/Graph/Only/" + Key);
                return(master);
            });

            Handle.GET("/Graph/Only/{?}", (string Key) => {
                GraphPage page = new GraphPage()
                {
                    Html = "/Graph/viewmodels/GraphPage.html",
                    Data = Db.SQL <Simplified.Ring6.Graph>(@"SELECT i FROM Simplified.Ring6.Graph i WHERE i.Key = ?", Key).First
                };

                return(page);
            });

            Handle.GET("/Graph/menu", () => {
                return(new Page()
                {
                    Html = "/Graph/viewmodels/AppMenuPage.html"
                });
            });

            Handle.GET("/Graph/app-name", () => {
                return(new AppName());
            });

            UriMapping.Map("/Graph/app-name", UriMapping.MappingUriPrefix + "/app-name");
            UriMapping.Map("/Graph/menu", UriMapping.MappingUriPrefix + "/menu");

            UriMapping.OntologyMap <Simplified.Ring6.Graph>("/Graph/Only/{?}");
        }
        public void UriParameterUsedTwiceThrows()
        {
            string UriPattern = "Simple/{id}/{id}";
            string MappedUriPattern = "Result/{id}";
            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple/123/123", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // Expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }
Beispiel #42
0
        static void Main()
        {
            var app = Application.Current;

            app.Use(new HtmlFromJsonProvider());
            app.Use(new PartialToStandaloneHtmlProvider());

            DummyData.Create();

            Handle.GET("/KitchenSink/master", () =>
            {
                Session session = Session.Current;
                if (session != null && session.Data != null)
                {
                    return(session.Data);
                }

                var master = new MasterPage();

                if (session == null)
                {
                    session = new Session(SessionOptions.PatchVersioning);
                }

                var nav            = new NavPage();
                master.CurrentPage = nav;

                master.Session = session;
                return(master);
            });

            Handle.GET("/KitchenSink/json", () => { return(new Json()); });

            Handle.GET("/KitchenSink/partial/mainpage", () => new MainPage());
            Handle.GET("/KitchenSink/mainpage", () => WrapPage <MainPage>("/KitchenSink/partial/mainpage"));

            Handle.GET("/KitchenSink", () => { return(Self.GET("/KitchenSink/mainpage")); });

            Handle.GET("/KitchenSink/partial/button", () => new ButtonPage());
            Handle.GET("/KitchenSink/button", () => WrapPage <ButtonPage>("/KitchenSink/partial/button"));

            Handle.GET("/KitchenSink/partial/breadcrumb",
                       () => { return(Db.Scope(() => { return new BreadcrumbPage(); })); });
            Handle.GET("/KitchenSink/breadcrumb", () => WrapPage <BreadcrumbPage>("/KitchenSink/partial/breadcrumb"));

            Handle.GET("/KitchenSink/partial/chart", () => new ChartPage());
            Handle.GET("/KitchenSink/chart", () => WrapPage <ChartPage>("/KitchenSink/partial/chart"));

            Handle.GET("/KitchenSink/partial/checkbox", () => new CheckboxPage());
            Handle.GET("/KitchenSink/checkbox", () => WrapPage <CheckboxPage>("/KitchenSink/partial/checkbox"));

            Handle.GET("/KitchenSink/partial/togglebutton", () => new ToggleButtonPage());
            Handle.GET("/KitchenSink/togglebutton",
                       () => WrapPage <ToggleButtonPage>("/KitchenSink/partial/togglebutton"));

            Handle.GET("/KitchenSink/partial/datagrid", () => new DatagridPage());
            Handle.GET("/KitchenSink/datagrid", () => WrapPage <DatagridPage>("/KitchenSink/partial/datagrid"));

            Handle.GET("/KitchenSink/partial/decimal", () => new DecimalPage());
            Handle.GET("/KitchenSink/decimal", () => WrapPage <DecimalPage>("/KitchenSink/partial/decimal"));

            Handle.GET("/KitchenSink/partial/dropdown", () => new DropdownPage());
            Handle.GET("/KitchenSink/dropdown", () => WrapPage <DropdownPage>("/KitchenSink/partial/dropdown"));

            Handle.GET("/KitchenSink/partial/html", () => new HtmlPage());
            Handle.GET("/KitchenSink/html", () => WrapPage <HtmlPage>("/KitchenSink/partial/html"));

            Handle.GET("/KitchenSink/partial/integer", () => new IntegerPage());
            Handle.GET("/KitchenSink/integer", () => WrapPage <IntegerPage>("/KitchenSink/partial/integer"));

            Handle.GET("/KitchenSink/partial/Geo", () =>
            {
                return(Db.Scope(() =>
                {
                    var geoPage = new GeoPage();
                    geoPage.Init();
                    return geoPage;
                }));
            });
            Handle.GET("/KitchenSink/Geo", () => WrapPage <GeoPage>("/KitchenSink/partial/Geo"));

            Handle.GET("/KitchenSink/partial/markdown", () => new MarkdownPage());
            Handle.GET("/KitchenSink/markdown", () => WrapPage <MarkdownPage>("/KitchenSink/partial/markdown"));

            Handle.GET("/KitchenSink/partial/nested", () => new NestedPartial
            {
                Data = new AnyData()
            });
            Handle.GET("/KitchenSink/nested", () => WrapPage <NestedPartial>("/KitchenSink/partial/nested"));

            Handle.GET("/KitchenSink/partial/radiolist", () => new RadiolistPage());
            Handle.GET("/KitchenSink/radiolist", () => WrapPage <RadiolistPage>("/KitchenSink/partial/radiolist"));

            Handle.GET("/KitchenSink/partial/multiselect", () => new MultiselectPage());
            Handle.GET("/KitchenSink/multiselect", () => WrapPage <MultiselectPage>("/KitchenSink/partial/multiselect"));

            Handle.GET("/KitchenSink/partial/password", () => new PasswordPage());
            Handle.GET("/KitchenSink/password", () => WrapPage <PasswordPage>("/KitchenSink/partial/password"));

            Handle.GET("/KitchenSink/partial/table", () => new TablePage());
            Handle.GET("/KitchenSink/table", () => WrapPage <TablePage>("/KitchenSink/partial/table"));

            Handle.GET("/KitchenSink/partial/text", () => new TextPage());
            Handle.GET("/KitchenSink/text", () => WrapPage <TextPage>("/KitchenSink/partial/text"));

            Handle.GET("/KitchenSink/partial/textarea", () => new TextareaPage());
            Handle.GET("/KitchenSink/textarea", () => WrapPage <TextareaPage>("/KitchenSink/partial/textarea"));

            Handle.GET("/KitchenSink/partial/radio", () => new RadioPage());
            Handle.GET("/KitchenSink/radio", () => WrapPage <RadioPage>("/KitchenSink/partial/radio"));

            Handle.GET("/KitchenSink/partial/Redirect", () => new RedirectPage());
            Handle.GET("/KitchenSink/Redirect", () => WrapPage <RedirectPage>("/KitchenSink/partial/Redirect"));

            Handle.GET("/KitchenSink/partial/Validation", () => new ValidationPage());
            Handle.GET("/KitchenSink/Validation", () => WrapPage <ValidationPage>("/KitchenSink/partial/Validation"));

            Handle.GET("/KitchenSink/Redirect/{?}", (string param) =>
            {
                var master            = WrapPage <RedirectPage>("/KitchenSink/partial/Redirect") as MasterPage;
                var nav               = master.CurrentPage as NavPage;
                var page              = nav.CurrentPage as RedirectPage;
                page.YourFavoriteFood = "You've got some tasty " + param;
                return(master);
            });

            Handle.GET("/KitchenSink/partial/url", () => new UrlPage());
            Handle.GET("/KitchenSink/url", () => WrapPage <UrlPage>("/KitchenSink/partial/url"));

            Handle.GET("/KitchenSink/partial/datepicker", () => new DatepickerPage());
            Handle.GET("/KitchenSink/datepicker", () => WrapPage <DatepickerPage>("/KitchenSink/partial/datepicker"));

            Handle.GET("/KitchenSink/partial/fileupload", () => new FileUploadPage());
            Handle.GET("/KitchenSink/fileupload", () => WrapPage <FileUploadPage>("/KitchenSink/partial/fileupload"));

            Handle.GET("/KitchenSink/partial/callback", () => new CallbackPage());
            Handle.GET("/KitchenSink/callback", () => WrapPage <CallbackPage>("/KitchenSink/partial/callback"));

            Handle.GET("/KitchenSink/partial/dialog", () => new DialogPage());
            Handle.GET("/KitchenSink/dialog", () => WrapPage <DialogPage>("/KitchenSink/partial/dialog"));

            Handle.GET("/KitchenSink/partial/progressbar", () => new ProgressBarPage());
            Handle.GET("/Kitchensink/progressbar", () => WrapPage <ProgressBarPage>("/KitchenSink/partial/progressbar"));

            Handle.GET("/KitchenSink/partial/lazyloading", () => new LazyLoadingPage());
            Handle.GET("/Kitchensink/lazyloading", () => WrapPage <LazyLoadingPage>("/KitchenSink/partial/lazyloading"));

            Handle.GET("/KitchenSink/partial/pagination", () => new PaginationPage());
            Handle.GET("/Kitchensink/pagination", () => WrapPage <PaginationPage>("/KitchenSink/partial/pagination"));

            Handle.GET("/KitchenSink/partial/flashmessage", () => new FlashMessagePage());
            Handle.GET("/Kitchensink/flashmessage", () => WrapPage <FlashMessagePage>("/KitchenSink/partial/flashmessage"));

            Handle.GET("/KitchenSink/partial/sortablelist", () => new SortableListPage());
            Handle.GET("/Kitchensink/sortablelist", () => WrapPage <SortableListPage>("/KitchenSink/partial/sortablelist"));

            Handle.GET("/KitchenSink/partial/cookie", (Request request) =>
            {
                string name     = "KitchenSink";
                CookiePage page = new CookiePage();
                Cookie cookie   = request.Cookies.Select(x => new Cookie(x)).FirstOrDefault(x => x.Name == name);

                if (cookie != null)
                {
                    page.RequestCookie = cookie.Value;
                }

                cookie = new Cookie()
                {
                    Name    = name,
                    Value   = string.Format("KitchenSinkCookie-{0}", DateTime.Now.ToString()),
                    Expires = DateTime.Now.AddDays(1)
                };

                Handle.AddOutgoingCookie(name, cookie.GetFullValueString());

                return(page);
            });
            Handle.GET("/KitchenSink/cookie", () => WrapPage <CookiePage>("/KitchenSink/partial/cookie"));

            HandleFile.GET("/KitchenSink/fileupload/upload", task =>
            {
                Session.ScheduleTask(task.SessionId, (s, id) =>
                {
                    MasterPage master = s.Data as MasterPage;

                    if (master == null)
                    {
                        return;
                    }

                    NavPage nav = master.CurrentPage as NavPage;

                    if (nav == null)
                    {
                        return;
                    }

                    FileUploadPage page = nav.CurrentPage as FileUploadPage;

                    if (page == null)
                    {
                        return;
                    }

                    var item = page.Tasks.FirstOrDefault(x => x.FileName == task.FileName);

                    if (task.State == HandleFile.UploadTaskState.Error)
                    {
                        if (item != null)
                        {
                            page.Tasks.Remove(item);
                        }
                    }
                    else if (task.State == HandleFile.UploadTaskState.Completed)
                    {
                        if (item != null)
                        {
                            page.Tasks.Remove(item);
                        }

                        var file = page.Files.FirstOrDefault(x => x.FileName == task.FileName);

                        if (file == null)
                        {
                            file = page.Files.Add();
                        }

                        file.FileName = task.FileName;
                        file.FileSize = task.FileSize;
                        file.FilePath = task.FilePath;
                    }
                    else
                    {
                        if (item == null)
                        {
                            item = page.Tasks.Add();
                        }

                        item.FileName = task.FileName;
                        item.FileSize = task.FileSize;
                        item.Progress = task.Progress;
                    }

                    s.CalculatePatchAndPushOnWebSocket();
                });
            });

            Handle.GET("/KitchenSink/partial/autocomplete", () => Db.Scope(() => new AutocompletePage()));
            Handle.GET("/KitchenSink/autocomplete", () => WrapPage <AutocompletePage>("/KitchenSink/partial/autocomplete"));

            //for a launcher
            Handle.GET("/KitchenSink/app-name", () => { return(new AppName()); });

            Handle.GET("/KitchenSink/menu", () => { return(new AppMenuPage()); });

            UriMapping.Map("/KitchenSink/menu", UriMapping.MappingUriPrefix + "/menu");
            UriMapping.Map("/KitchenSink/app-name", UriMapping.MappingUriPrefix + "/app-name");
        }
        public void UriCannotContainQueryString()
        {
            string UriPattern = "Simple?var1={x}";
            string MappedUriPattern = "Result.xaml?id={x}";

            UriMapping alias = new UriMapping();
            alias.Uri = new Uri(UriPattern, UriKind.Relative);
            alias.MappedUri = new Uri(MappedUriPattern, UriKind.Relative);

            Uri testUri = new Uri("Simple?var1=10", UriKind.Relative);

            try
            {
                Uri result = alias.MapUri(testUri);

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
                // This is expected
            }
            catch (Exception)
            {
                Assert.Fail("Exception other than InvalidOperationException thrown");
            }
        }