Exemple #1
0
 void IStartupTask.Start()
 {
     _eventBroker.Subscribe <WebsiteCreated>(x => _webSiteIds.Add(x.SystemId));
     _eventBroker.Subscribe <WebsiteDeleted>(x => _webSiteIds.Remove(x.SystemId));
     foreach (var webSite in _websiteService.GetAll())
     {
         _webSiteIds.Add(webSite.SystemId);
     }
 }
        public ActionResult Create()
        {
            var viewModel = new BindingViewModel();

            viewModel.Websites               = WebsiteService.GetAll().ToList();
            viewModel.SelectableServers      = ServerService.GetAll().ToList();
            viewModel.SelectableEnvironments = EnvironmentService.GetAll().ToList();

            return(View(viewModel));
        }
        public ActionResult Index(int?page)
        {
            var viewModel = new WebsiteListViewModel();

            var  pageNumber = (page ?? 1) - 1;
            long totalCount;
            IEnumerable <IWebsite> websites = WebsiteService.GetAll(pageNumber, PageSize, out totalCount);

            viewModel.Websites = new StaticPagedList <IWebsite>(websites, pageNumber + 1, PageSize, (int)totalCount);
            return(View(viewModel));
        }
 public ActionResult Edit(long?id, int?page)
 {
     if (id.HasValue)
     {
         var viewModel = AutoMapper.Mapper.Map <IBinding, BindingViewModel>(BindingService.GetById(id.Value));
         viewModel.Websites               = WebsiteService.GetAll().ToList();
         viewModel.SelectableServers      = ServerService.GetAll().ToList();
         viewModel.SelectableEnvironments = EnvironmentService.GetAll().ToList();
         return(View(viewModel));
     }
     return(RedirectToAction("Create"));
 }
        public PageByFieldTemplateCache(
            FieldTemplateService fieldTemplateService,
            DataService dataService,
            EventBroker eventBroker,
            MemoryCacheService memoryCacheService,
            AuthorizationService authorizationService,
            PageService pageService,
            IServiceProvider serviceProvider,
            RouteRequestLookupInfoAccessor routeRequestLookupInfoAccessor,
            WebsiteService websiteService,
            ChannelService channelService)
        {
            var fieldType = ActivatorUtilities.CreateInstance <T>(serviceProvider);

            _fieldTemplateService = fieldTemplateService;
            _dataService          = dataService;
            _memoryCacheService   = memoryCacheService;
            _authorizationService = authorizationService;
            _pageService          = pageService;
            _fieldTemplateName    = fieldType.Name;
            _channelService       = channelService;

            _cacheKey = GetType().FullName + ":" + _fieldTemplateName;

            eventBroker.Subscribe <FieldTemplateCreated>(_ => RemoveCacheForWebsites());
            eventBroker.Subscribe <FieldTemplateDeleted>(_ => RemoveCacheForWebsites());
            eventBroker.Subscribe <DraftPageCreated>(_ => RemoveCacheForWebsites());
            eventBroker.Subscribe <PageCreated>(_ => RemoveCacheForWebsites());
            eventBroker.Subscribe <PageDeleted>(_ => RemoveCacheForWebsites());
            eventBroker.Subscribe <PageUpdated>(x =>
            {
                if (x.OriginalFieldTemplateSystemId != null)
                {
                    RemoveCacheForWebsites();
                }
            });
            _routeRequestLookupInfoAccessor = routeRequestLookupInfoAccessor;

            void RemoveCacheForWebsites()
            {
                foreach (var website in websiteService.GetAll())
                {
                    _memoryCacheService.Remove(_cacheKey + website.SystemId);
                }
            }
        }
Exemple #6
0
        public override void CreateWebsiteTexts(IWebsiteTextSource textSource)
        {
            try
            {
                using (_solution.SystemToken.Use("WebsiteTextSetup.CreateWebsiteStrings"))
                {
                    var allWebsites = _websiteService.GetAll();

                    foreach (var ws in allWebsites)
                    {
                        var website = ws.MakeWritableClone();


                        foreach (var text in textSource.GetTexts())
                        {
                            try
                            {
                                if (text == null)
                                {
                                    throw new Exception("Text is null");
                                }
                                if (text.Id == null)
                                {
                                    throw new Exception("Text.Id cannot be null");
                                }

                                // If the text should be generated on specific websites only and current site is not among those then skip
                                if (text.WebsiteIds.Any() && !text.WebsiteIds.Any(w => website.SystemId.Equals(w)))
                                {
                                    continue;
                                }

                                var serverTextKey = GetTextKey(textSource.Prefix, text.Id, false);
                                var clientTextKey = GetTextKey(textSource.Prefix, text.Id, true);

                                // If they dont exist here its a first time insert, so then insert all cultures
                                var serverTextKeyInitialInsert = !website.Texts.Keys.Contains(serverTextKey);
                                var clientTextKeyInitialInsert = !website.Texts.Keys.Contains(clientTextKey);

                                foreach (var textValue in text.Name)
                                {
                                    // If the string should be avaliable on the server, in other words generated as defined only
                                    if (text.ServerAvailable)
                                    {
                                        AddOrUpdateValue(textSource, website, textValue, serverTextKey, serverTextKeyInitialInsert);
                                    }

                                    // If the string shold be avaliable on client, create another string with js.-prefix
                                    // this makes the string avaliable in clientscript from window.__litium.translation
                                    // See https://docs.litium.com/documentation/litium-accelerators/develop/architecture/accelerator-mvc
                                    if (text.ClientAvailable)
                                    {
                                        AddOrUpdateValue(textSource, website, textValue, clientTextKey, clientTextKeyInitialInsert);
                                    }
                                }
                            }
                            catch (Exception exception)
                            {
                                _logger.LogError($"Error creating website text '{text?.Id}'", exception);
                            }
                        }

                        _websiteService.Update(website);
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.LogError("Error creating website texts", exception);
            }
        }