Esempio n. 1
0
        static void StartServices()
        {
            ServiceLocator.Start = (IServiceLocator loc) =>
            {
                var profiler     = new NullProfiler();
                var localizer    = new NullLocalizer();
                var host         = new BackgroundApplicationHost(profiler);
                var dbContext    = new SqlDbContext(profiler, host, localizer);
                var logger       = new BackgroundLogger(dbContext);
                var workflow     = new WorkflowEngine(host, dbContext, null);
                var emailService = new EmailService(logger);
                var messaging    = new MessageProcessor(host, dbContext, emailService, logger);

                loc.RegisterService <IProfiler>(profiler);
                loc.RegisterService <ILocalizer>(localizer);
                loc.RegisterService <IDbContext>(dbContext);
                loc.RegisterService <ILogger>(logger);
                loc.RegisterService <IApplicationHost>(host);
                loc.RegisterService <IWorkflowEngine>(workflow);
                loc.RegisterService <IMessaging>(messaging);
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (_currentService == null)
                {
                    _currentService = new ServiceLocator();
                }
                return(_currentService);
            };
        }
Esempio n. 2
0
        public static LocalizedString AdaptiveCapture(string caption, string extension)
        {
            var result = NullLocalizer.Instance("{0}{1} {2}{3}",
                                                caption,
                                                new HtmlString("<span class=\"hidden-xs\">"),
                                                extension,
                                                new HtmlString("</span>"));

            return(result);
        }
Esempio n. 3
0
        public static void Start()
        {
            if (ServiceLocator.Start != null)
            {
                return;
            }

            ServiceLocator.Start = (IServiceLocator service) =>
            {
                var profiler = new NullProfiler();
                var host     = new TestApplicationHost(profiler)
                {
                    HostingPath = Path.GetFullPath("../../../../Web/A2v10.Web.Site")
                };

                var localizer      = new NullLocalizer();
                var dbContext      = new SqlDbContext(profiler, host, localizer);
                var messaging      = new NullMessaging();
                var workflowEngine = new WorkflowEngine(host, dbContext, messaging);
                var renderer       = new XamlRenderer(profiler, host);
                var scripter       = new VueDataScripter(host, localizer);

                service.RegisterService <IDbContext>(dbContext);
                service.RegisterService <IWorkflowEngine>(workflowEngine);
                service.RegisterService <IApplicationHost>(host);
                service.RegisterService <IProfiler>(profiler);
                service.RegisterService <IRenderer>(renderer);
                service.RegisterService <ILocalizer>(localizer);
                service.RegisterService <IDataScripter>(scripter);
                service.RegisterService <IMessaging>(messaging);
                _currentService = service;
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (_currentService == null)
                {
                    new ServiceLocator();
                }
                return(_currentService);
            };
        }
        public void StringsShouldPassThrough()
        {
            var result = NullLocalizer.Instance("hello world");

            Assert.Equal(result.ToString(), "hello world");
        }
        public void StringsShouldNotFormatWithoutAnyArguments()
        {
            var result = NullLocalizer.Instance("hello {0} world");

            Assert.Equal(result.ToString(), "hello {0} world");
        }
        public void StringsShouldFormatIfArgumentsArePassedIn()
        {
            var result = NullLocalizer.Instance("hello {0} world", "!");

            Assert.Equal(result.ToString(), "hello ! world");
        }
Esempio n. 7
0
        public IHttpActionResult Posts(int blogId, [FromUri] PagerParameters pagerParameters)
        {
            Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            var blogPart = _blogService.Get(blogId, VersionOptions.Published).As <BlogPart>();

            if (blogPart == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (!_services.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, blogPart, NullLocalizer.Instance("Cannot view content")))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var posts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize).Select(bp => new BlogPost
            {
                Id           = bp.Id,
                Title        = bp.Title,
                CreatedBy    = bp.Creator.UserName,
                PublishedUtc = bp.PublishedUtc
            }).ToList();

            return(Ok(posts));
        }
Esempio n. 8
0
        public IHttpActionResult Get(int blogId)
        {
            var blogPart = _blogService.Get(blogId, VersionOptions.Published).As <BlogPart>();

            if (blogPart == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (!_services.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, blogPart, NullLocalizer.Instance("Cannot view content")))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var blog = new Blog
            {
                Id          = blogPart.Id,
                Title       = blogPart.Name,
                Description = blogPart.Description,
                PostCount   = blogPart.PostCount
            };

            return(Ok(blog));
        }