Ejemplo n.º 1
0
        /// <summary>
        /// Solves the TSP.
        /// </summary>
        /// <param name="problem"></param>
        /// <returns></returns>
        protected override IRoute DoSolve(IProblem problem)
        {
            // initialize.
            List <int> solution = new List <int>();

            for (int idx = 0; idx < problem.Size; idx++)
            { // add each customer again.
                solution.Add(idx);
            }

            // keep on looping until all the permutations
            // have been considered.
            PermutationEnumerable <int> enumerator = new PermutationEnumerable <int>(
                solution.ToArray());

            int[]  best       = null;
            double bestWeight = double.MaxValue;

            foreach (int[] permutation in enumerator)
            {
                double weight = RouteExtensions.CalculateWeight(permutation, problem.First == problem.Last, problem);
                if (weight < bestWeight)
                { // the best weight has improved.
                    bestWeight = weight;
                    best       = permutation;
                }
            }
            return(new SimpleAsymmetricRoute(best.ToList <int>(), true));
        }
Ejemplo n.º 2
0
        private ContentRegistration AnalyzeView(HttpContextBase httpContext, VirtualFile file, string controllerName, Type modelType)
        {
            if (modelType == null || !typeof(ContentItem).IsAssignableFrom(modelType) || modelType.IsAbstract)
            {
                return(null);
            }

            var model = Activator.CreateInstance(modelType) as ContentItem;

            var  rd     = new RouteData();
            bool isPage = model.IsPage;

            RouteExtensions.ApplyCurrentPath(rd, controllerName, Path.GetFileNameWithoutExtension(file.Name), new PathData(isPage ? model : new StubItem(), isPage ? null : model));

            var cctx = new ControllerContext(httpContext, rd, new StubController());

            var result = isPage
                ? viewEnginesProvider.Get().FindView(cctx, file.VirtualPath, null)
                : viewEnginesProvider.Get().FindPartialView(cctx, file.VirtualPath);


            if (result.View == null)
            {
                return(null);
            }

            return(RenderViewForRegistration(file, modelType, cctx, result));
        }
Ejemplo n.º 3
0
        private RouteData GetRouteData()
        {
            var routeData = new RouteData();

            RouteExtensions.ApplyCurrentItem(routeData, "webforms", "index", webContext.CurrentPath.CurrentPage, webContext.CurrentPath.CurrentItem);
            return(routeData);
        }
Ejemplo n.º 4
0
        private RouteData GetRouteData()
        {
            var routeData = new RouteData();

            RouteExtensions.ApplyCurrentPath(routeData, "WebForms", "Index", webContext.CurrentPath);
            return(routeData);
        }
Ejemplo n.º 5
0
        public static void InitTheme(this ControllerContext context)
        {
            var page = context.RequestContext.CurrentPage <ContentItem>()
                       ?? RouteExtensions.ResolveService <IUrlParser>(context.RouteData).Parse(context.HttpContext.Request["returnUrl"])
                       ?? context.RequestContext.StartPage();

            InitTheme(context, page);
        }
Ejemplo n.º 6
0
        public override void RegisterArea(AreaRegistrationContext context)
        {
            BeforeRegisterArea(context);

            RouteExtensions.MapRouteEx(context, SchwabenCode.Samples.ASPMVC5_Google2WayAuthentication.Routing.RouteNames.AccountArea.Account_Login, "Account/Login", new { Controller = "Account", Action = "Login" }, null, new [] { "SchwabenCode.Samples.ASPMVC5_Google2WayAuthentication.Areas.Account.Controllers" }, "Account", forceTrailingSlash: false);

            RouteExtensions.MapRouteEx(context, SchwabenCode.Samples.ASPMVC5_Google2WayAuthentication.Routing.RouteNames.AccountArea.Account, "Account", new { Controller = "Account", Action = "Index" }, null, new [] { "SchwabenCode.Samples.ASPMVC5_Google2WayAuthentication.Areas.Account.Controllers" }, "Account", forceTrailingSlash: false);


            AfterRegisterArea(context);
        }
        public void ObfuscateUrlQueryDefault_ReturnsNotObfuscatedWhenQueryIsEmpty()
        {
            //Arrange
            Uri data = new Uri("https://localhost:550/users/account");

            // Act
            var obfuscated = RouteExtensions.ObfuscateUrlQuery(data, RouteExtensions.ObfuscatedReturnUrlMetadata);

            //Assert
            Assert.Equal(data.ToString(), obfuscated.ToString());
        }
        public void ObfuscateUrlQuery_ReturnsObfuscatedUriWhenObfuscated(string input, string expected)
        {
            //Arrange
            Uri data = new Uri(input);

            // Act
            var obfuscated = RouteExtensions.ObfuscateUrlQuery(data, RouteExtensions.ObfuscatedReturnUrlMetadata);

            //Assert
            Assert.Equal(expected, obfuscated.ToString());
        }
Ejemplo n.º 9
0
        private static HtmlHelper CreateHtmlHelper(ContentItem item, TextWriter writer)
        {
            var httpContext = new HttpContextWrapper(HttpContext.Current);
            var routeData   = new RouteData();

            RouteExtensions.ApplyCurrentItem(routeData, "webforms", "index", item.ClosestPage(), item);
            return(new HtmlHelper(
                       new ViewContext(
                           new ControllerContext()
            {
                HttpContext = httpContext, RequestContext = new RequestContext(httpContext, routeData), RouteData = routeData
            },
                           new WebFormView(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath),
                           new ViewDataDictionary(),
                           new TempDataDictionary(),
                           writer),
                       new ViewPage(),
                       RouteTable.Routes));
        }
Ejemplo n.º 10
0
        private HtmlHelper BuildHtmlHelper()
        {
            var ctx = new HttpContextWrapper(Context);
            var rd  = new RouteData();

            var currentPage = (Page is IItemContainer) ? (Page as IItemContainer).CurrentItem : N2.Context.CurrentPage;

            RouteExtensions.ApplyCurrentPath(rd, "WebForms", "Index", new PathData(currentPage, currentPage));
            rd.DataTokens[ContentRoute.ContentEngineKey] = N2.Context.Current;

            var rqctx   = new RequestContext(ctx, rd);
            var ctrlctx = new ControllerContext {
                HttpContext = ctx, RequestContext = rqctx, RouteData = rqctx.RouteData
            };
            var wfv = new WebFormView(ctrlctx, Request.CurrentExecutionFilePath);

            var vctx = new ViewContext(ctrlctx, wfv, new ViewDataDictionary(), new TempDataDictionary(), Response.Output)
            {
                RouteData = rd
            };

            return(new HtmlHelper <ContentItem>(vctx, new ViewPage()));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Call this method on application start.
 /// </summary>
 public static void Register(RouteCollection routeCollection)
 {
     RouteExtensions.MapRouteEx(routeCollection, SchwabenCode.Samples.ASPMVC5_Google2WayAuthentication.Routing.RouteNames.Home, "", new { Controller = "Home", Action = "Index" }, null, new [] { "SchwabenCode.Samples.ASPMVC5_Google2WayAuthentication.Controllers" }, forceTrailingSlash: false);
 }
Ejemplo n.º 12
0
 /// <summary>Resolves the current <see cref="IEngine"/> using information stored in context or falling back to the singleton instance.</summary>
 public static IEngine ContentEngine(this HtmlHelper html)
 {
     return(RouteExtensions.GetEngine(html.ViewContext.RouteData)
            ?? N2.Context.Current);
 }
Ejemplo n.º 13
0
 public static T[] ResolveServices <T>(this HtmlHelper helper) where T : class
 {
     return(RouteExtensions.ResolveServices <T>(helper.ViewContext.RouteData));
 }
Ejemplo n.º 14
0
 public void ObfuscateUrlQueryDefault_ThrowWhenMetadataIsNull()
 {
     //Act + Assert
     Assert.Throws <ArgumentNullException>(() => RouteExtensions.ObfuscateUrlQuery(new Uri("https://localhost:550/users/account"), null));
 }
Ejemplo n.º 15
0
 public void ObfuscateUrlQueryDefault_ThrowWhenUriNull()
 {
     //Act + Assert
     Assert.Throws <ArgumentNullException>(() => RouteExtensions.ObfuscateUrlQuery(null, RouteExtensions.ObfuscatedReturnUrlMetadata));
 }