public void Setup()
        {
            cruiseRequestWrapperMock    = new DynamicMock(typeof(ICruiseRequest));
            buildNameRetrieverMock      = new DynamicMock(typeof(IBuildNameRetriever));
            recentBuildsViewBuilderMock = new DynamicMock(typeof(IRecentBuildsViewBuilder));
            pluginLinkCalculatorMock    = new DynamicMock(typeof(IPluginLinkCalculator));
            velocityViewGeneratorMock   = new DynamicMock(typeof(IVelocityViewGenerator));
            linkFactoryMock             = new DynamicMock(typeof(ILinkFactory));
            linkListFactoryMock         = new DynamicMock(typeof(ILinkListFactory));
            farmServiceMock             = new DynamicMock(typeof(IFarmService));


            sideBarViewBuilder = new SideBarViewBuilder(
                (ICruiseRequest)cruiseRequestWrapperMock.MockInstance,
                (IBuildNameRetriever)buildNameRetrieverMock.MockInstance,
                (IRecentBuildsViewBuilder)recentBuildsViewBuilderMock.MockInstance,
                (IPluginLinkCalculator)pluginLinkCalculatorMock.MockInstance,
                (IVelocityViewGenerator)velocityViewGeneratorMock.MockInstance,
                (ILinkFactory)linkFactoryMock.MockInstance,
                (ILinkListFactory)linkListFactoryMock.MockInstance,
                (IFarmService)farmServiceMock.MockInstance,
                null);

            velocityResponse = new HtmlFragmentResponse("velocity view");
            velocityContext  = new Hashtable();
            links            = new IAbsoluteLink[] { new GeneralAbsoluteLink("link") };
            serverLinks      = new IAbsoluteLink[] { new GeneralAbsoluteLink("link") };
            serverSpecifiers = new IServerSpecifier[] { new DefaultServerSpecifier("test") };
        }
        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);
            }
        }
Esempio n. 3
0
 private ConditionalGetFingerprint CalculateLocalFingerprint(IRequest request)
 {
     return(fingerprintFactory.BuildFromFileNames(TEMPLATE_NAME)
            .Combine(TopControlsViewBuilder.GetFingerprint(request))
            .Combine(SideBarViewBuilder.GetFingerprint(request)));
 }