Ejemplo n.º 1
0
 private static void AddOrUpdateValue(IWebsiteTextSource textSource, Website website, KeyValuePair <string, string> textValue, string textKey, bool initialInsert)
 {
     if (initialInsert || textSource.UpdateExistingTexts)
     {
         website.Texts.AddOrUpdateValue(textKey, textValue.Key, textValue.Value);
     }
 }
Ejemplo n.º 2
0
 public override void DeleteMissingWebsiteTexts(IWebsiteTextSource textSource)
 {
     try
     {
         using (_solution.SystemToken.Use("WebsiteTextSetup.DeleteMissingWebsiteStrings"))
         {
             var allWebsites = _websiteService.GetAll();
             foreach (var ws in allWebsites)
             {
                 var website = ws.MakeWritableClone();
                 DeleteRemovedWebsiteTexts(textSource.Prefix, website, textSource.GetTexts());
                 _websiteService.Update(website);
             }
         }
     }
     catch (Exception exception)
     {
         _logger.LogError("Error deleting website texts", exception);
     }
 }
Ejemplo n.º 3
0
 public WebsiteTextSetup(WebsiteTextService websiteTextService, IWebsiteTextSource websiteTextSource)
 {
     _websiteTextService = websiteTextService;
     _websiteTextSource  = websiteTextSource;
 }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
 public abstract void DeleteMissingWebsiteTexts(IWebsiteTextSource textSource);
Ejemplo n.º 6
0
 public abstract void CreateWebsiteTexts(IWebsiteTextSource textSource);