Exemplo n.º 1
0
        public void Setup()
        {
            cruiseRequestMock         = new DynamicMock(typeof(ICruiseRequest));
            requestMock               = new DynamicMock(typeof(IRequest));
            linkFactoryMock           = new DynamicMock(typeof(ILinkFactory));
            velocityViewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
            farmServiceMock           = new DynamicMock(typeof(IFarmService));

            viewBuilder = new TopControlsViewBuilder(
                (ICruiseRequest)cruiseRequestMock.MockInstance,
                (ILinkFactory)linkFactoryMock.MockInstance,
                (IVelocityViewGenerator)velocityViewGeneratorMock.MockInstance,
                (IFarmService)farmServiceMock.MockInstance,
                null, null);

            serverSpecifier         = new DefaultServerSpecifier("myServer");
            projectSpecifier        = new DefaultProjectSpecifier(serverSpecifier, "myProject");
            buildSpecifier          = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
            expectedVelocityContext = new Hashtable();
            response = new HtmlFragmentResponse("foo");
            link1    = new GeneralAbsoluteLink("1");
            link2    = new GeneralAbsoluteLink("2");
            link3    = new GeneralAbsoluteLink("3");
            link4    = new GeneralAbsoluteLink("4");
        }
        public IResponse Execute(IRequest request)
        {
            Hashtable velocityContext         = new Hashtable();
            IResponse decoratedActionResponse = decoratedAction.Execute(request);

            if (decoratedActionResponse is HtmlFragmentResponse)
            {
                velocityContext["breadcrumbs"]      = (TopControlsViewBuilder.Execute()).ResponseFragment;
                velocityContext["sidebar"]          = (SideBarViewBuilder.Execute(cruiseRequest)).ResponseFragment;
                velocityContext["mainContent"]      = ((HtmlFragmentResponse)decoratedActionResponse).ResponseFragment;
                velocityContext["dashboardversion"] = versionProvider.GetVersion();
                if (request.ApplicationPath == "/")
                {
                    velocityContext["applicationPath"] = string.Empty;
                }
                else
                {
                    velocityContext["applicationPath"] = request.ApplicationPath;
                }
                velocityContext["renderedAt"] = DateUtil.FormatDate(DateTime.Now);
                velocityContext["loginView"]  = LoginViewBuilder.Execute().ResponseFragment;

                // set to no refresh if refresh interval lower than 5 seconds
                Int32 refreshIntervalInSeconds = Int32.MaxValue;
                if (request.RefreshInterval >= 5)
                {
                    refreshIntervalInSeconds = request.RefreshInterval;
                }

                velocityContext["refreshinterval"] = refreshIntervalInSeconds;

                string headerSuffix = string.Empty;
                if (!string.IsNullOrEmpty(loginViewBuilder.BuildServerName))
                {
                    headerSuffix = LoginViewBuilder.BuildServerName;
                }
                if (!string.IsNullOrEmpty(LoginViewBuilder.ProjectName))
                {
                    headerSuffix = string.Concat(headerSuffix, " - ", loginViewBuilder.ProjectName);
                }

                velocityContext["headersuffix"] = headerSuffix;

                GeneratejQueryLinks(velocityContext);

                return(velocityViewGenerator.GenerateView(TEMPLATE_NAME, velocityContext));
            }
            else
            {
                return(decoratedActionResponse);
            }
        }
Exemplo n.º 3
0
 private ConditionalGetFingerprint CalculateLocalFingerprint(IRequest request)
 {
     return(fingerprintFactory.BuildFromFileNames(TEMPLATE_NAME)
            .Combine(TopControlsViewBuilder.GetFingerprint(request))
            .Combine(SideBarViewBuilder.GetFingerprint(request)));
 }