Esempio n. 1
0
        protected virtual CountryResponse GetInformation(string ipAddress)
        {
            if (String.IsNullOrEmpty(ipAddress))
            {
                return(null);
            }

            try
            {
                //This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com
                var databasePath = CommonPath.MapPath("App_Data/GeoLite2-Country.mmdb");
                var reader       = new DatabaseReader(databasePath);
                var response     = reader.Country(ipAddress);
                return(response);
                //more info: http://maxmind.github.io/GeoIP2-dotnet/
                //more info: https://github.com/maxmind/GeoIP2-dotnet
            }
            catch (GeoIP2Exception)
            {
                return(null);
            }
            catch (Exception exc)
            {
                _logger.Warning("Cannot load MaxMind record", exc);
                return(null);
            }
        }
        /// <summary>
        /// Get a list of available collactions
        /// </summary>
        /// <returns>Available collations mongodb</returns>
        public virtual IList <InstallationCollation> GetAvailableCollations()
        {
            if (_availableCollation != null)
            {
                return(_availableCollation);
            }

            _availableCollation = new List <InstallationCollation>();
            var filePath    = CommonPath.MapPath("App_Data/Resources/supportedcollation.xml");
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(File.OpenRead(filePath));

            var collation = xmlDocument.SelectNodes(@"//Collations/Collation");

            foreach (XmlNode resNode in collation)
            {
                var resNameAttribute = resNode.Attributes["Name"];
                var resValueNode     = resNode.SelectSingleNode("Value");

                var resourceName  = resNameAttribute.Value.Trim();
                var resourceValue = resValueNode.InnerText.Trim();

                _availableCollation.Add(new InstallationCollation()
                {
                    Name  = resourceName,
                    Value = resourceValue,
                });
            }

            return(_availableCollation);
        }
        protected virtual async Task InstallLocaleResources()
        {
            //'English' language
            var language = _languageRepository.Table.Single(l => l.Name == "English");

            //save resources
            var filePath           = CommonPath.MapPath("App_Data/Resources/DefaultLanguage.xml");
            var localesXml         = File.ReadAllText(filePath);
            var translationService = _serviceProvider.GetRequiredService <ITranslationService>();
            await translationService.ImportResourcesFromXmlInstall(language, localesXml);
        }
Esempio n. 4
0
        public static void Load(ApplicationPartManager applicationPartManager, AppConfig config)
        {
            if (applicationPartManager == null)
            {
                throw new ArgumentNullException(nameof(applicationPartManager));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (!config.UseRoslynScripts)
            {
                return;
            }

            var referencedScripts = new List <ResultCompiler>();

            var roslynFolder = new DirectoryInfo(CommonPath.MapPath(ScriptPath));

            _shadowCopyScriptPath = new DirectoryInfo(CommonPath.MapPath(ShadowCopyScriptPath));
            Directory.CreateDirectory(_shadowCopyScriptPath.FullName);

            //clear bin files
            var binFiles = _shadowCopyScriptPath.GetFiles("*", SearchOption.AllDirectories);

            foreach (var f in binFiles)
            {
                try
                {
                    //ignore index.htm
                    var fileName = Path.GetFileName(f.FullName);
                    if (fileName.Equals("index.htm", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    File.Delete(f.FullName);
                }
                catch (Exception exc)
                {
                    Debug.WriteLine("Error deleting file " + f.Name + ". Exception: " + exc);
                }
            }

            try
            {
                var ctxFiles = roslynFolder.GetFiles("*.csx", SearchOption.TopDirectoryOnly);
                foreach (var file in ctxFiles)
                {
                    var csxcript = new ResultCompiler
                    {
                        OriginalFile = file.FullName
                    };

                    string ctxCode            = File.ReadAllText(file.FullName);
                    var    sourceFileResolver = new SourceFileResolver(ImmutableArray <string> .Empty, AppContext.BaseDirectory);
                    var    opts        = ScriptOptions.Default.WithSourceResolver(sourceFileResolver);
                    var    script      = CSharpScript.Create(ctxCode, opts);
                    var    compilation = script.GetCompilation();
                    using (var ms = new MemoryStream())
                    {
                        var compilationResult = compilation.Emit(ms);

                        if (compilationResult.Success)
                        {
                            ms.Seek(0, SeekOrigin.Begin);
                            var shadowFileName = Path.Combine(_shadowCopyScriptPath.FullName, file.Name + "-" + Guid.NewGuid().ToString("D") + ".dll");
                            File.WriteAllBytes(shadowFileName, ms.ToArray());
                            Assembly shadowCopiedAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(shadowFileName);
                            csxcript.DLLAssemblyFile    = shadowFileName;
                            csxcript.ReferencedAssembly = shadowCopiedAssembly;
                            csxcript.IsCompiled         = true;
                            applicationPartManager.ApplicationParts.Add(new AssemblyPart(shadowCopiedAssembly));
                        }
                        else
                        {
                            foreach (var diagnostic in compilationResult.Diagnostics)
                            {
                                csxcript.ErrorInfo.Add(diagnostic.ToString());
                            }
                        }
                    }
                    referencedScripts.Add(csxcript);
                }
                ReferencedScripts = referencedScripts;
            }
            catch (Exception ex)
            {
                var msg = string.Format("Roslyn '{0}'", ex.Message);

                var fail = new Exception(msg, ex);
                throw fail;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Install plugin
        /// </summary>
        public override async Task Install()
        {
            //pictures
            var sampleImagesPath = CommonPath.MapPath("Plugins/Widgets.Slider/Assets/slider/sample-images/");
            var byte1            = File.ReadAllBytes(sampleImagesPath + "banner1.png");
            var byte2            = File.ReadAllBytes(sampleImagesPath + "banner2.png");

            var pictureSlider1 = new PictureSlider()
            {
                DisplayOrder = 0,
                Link         = "",
                Name         = "Sample slider 1",
                FullWidth    = true,
                Published    = true,
                Description  = "<div class=\"row slideRow justify-content-start\"><div class=\"col-lg-6 d-flex flex-column justify-content-center align-items-center\"><div><div class=\"animate-top animate__animated animate__backInDown\" >exclusive - modern - elegant</div><div class=\"animate-center-title animate__animated animate__backInLeft animate__delay-05s\">Smart watches</div><div class=\"animate-center-content animate__animated animate__backInLeft animate__delay-1s\">Go to collection and see more...</div><a href=\"/smartwatches\" class=\"animate-bottom btn btn-info animate__animated animate__backInUp animate__delay-15s\"> SHOP NOW </a></div></div></div>"
            };

            var pic1 = await _pictureService.InsertPicture(byte1, "image/png", "banner_1", reference : Grand.Domain.Common.Reference.Widget, objectId : pictureSlider1.Id, validateBinary : false);

            pictureSlider1.PictureId = pic1.Id;
            await _pictureSliderRepository.InsertAsync(pictureSlider1);


            var pictureSlider2 = new PictureSlider()
            {
                DisplayOrder = 1,
                Link         = "https://grandnode.com",
                Name         = "Sample slider 2",
                FullWidth    = true,
                Published    = true,
                Description  = "<div class=\"row slideRow\"><div class=\"col-md-6 offset-md-6 col-12 offset-0 d-flex flex-column justify-content-center align-items-start px-0 pr-md-3\"><div class=\"slide-title text-dark animate__animated animate__fadeInRight animate__delay-05s\"><h2 class=\"mt-0\">Redmi Note 9</h2></div><div class=\"slide-content animate__animated animate__fadeInRight animate__delay-1s\"><p class=\"mb-0\"><span>Equipped with a high-performance octa-core processor <br/> with a maximum clock frequency of 2.0 GHz.</span></p></div><div class=\"slide-price animate__animated animate__fadeInRight animate__delay-15s d-inline-flex align-items-center justify-content-start w-100 mt-2\"><p class=\"actual\">$249.00</p><p class=\"old-price\">$399.00</p></div><div class=\"slide-button animate__animated animate__fadeInRight animate__delay-2s mt-3\"><a class=\"btn btn-outline-info\" href=\"/redmi-note-9\">BUY REDMI NOTE 9</a></div></div></div>",
            };
            var pic2 = await _pictureService.InsertPicture(byte2, "image/png", "banner_2", reference : Grand.Domain.Common.Reference.Widget, objectId : pictureSlider2.Id, validateBinary : false);

            pictureSlider2.PictureId = pic2.Id;

            await _pictureSliderRepository.InsertAsync(pictureSlider2);

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.FriendlyName", "Widget Slider");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Added", "Slider added");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Addnew", "Add new slider");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.AvailableStores", "Available stores");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.AvailableStores.Hint", "Select stores for which the slider will be shown.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Backtolist", "Back to list");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Category", "Category");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Category.Hint", "Select the category where slider should appear.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Category.Required", "Category is required");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Description", "Description");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Description.Hint", "Enter the description of the slider");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.DisplayOrder", "Display Order");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.DisplayOrder.Hint", "The slider display order. 1 represents the first item in the list.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Edit", "Edit slider");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Edited", "Slider edited");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.Displayorder", "Display Order");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.Link", "Link");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.ObjectType", "Slider type");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.Picture", "Picture");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.Published", "Published");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.Title", "Title");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.FullWidth", "Full width");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.FullWidth.hint", "Full width");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Info", "Info");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.LimitedToStores", "Limited to stores");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.LimitedToStores.Hint", "Determines whether the slider is available only at certain stores.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Link", "URL");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Link.Hint", "Enter URL. Leave empty if you don't want this picture to be clickable.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Manage", "Manage Bootstrap Slider");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Collection", "Collection");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Collection.Hint", "Select the collection where slider should appear.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Collection.Required", "Collection is required");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Name", "Name");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Name.Hint", "Enter the name of the slider");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Name.Required", "Name is required");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Picture", "Picture");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Picture.Required", "Picture is required");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Published", "Published");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Published.Hint", "Specify it should be visible or not");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.SliderType", "Slider type");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.SliderType.Hint", "Choose the slider type. Home page, category or collection page.");

            await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Stores", "Stores");


            await base.Install();
        }
        /// <summary>
        /// Get a list of available languages
        /// </summary>
        /// <returns>Available installation languages</returns>
        public virtual IList <InstallationLanguage> GetAvailableLanguages()
        {
            if (_availableLanguages != null)
            {
                return(_availableLanguages);
            }

            _availableLanguages = new List <InstallationLanguage>();
            foreach (var filePath in Directory.EnumerateFiles(CommonPath.MapPath("App_Data/Resources/Installation/"), "*.xml"))
            {
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(File.OpenRead(filePath));

                var languageCode = "";
                var r            = new Regex(Regex.Escape("installation.") + "(.*?)" + Regex.Escape(".xml"));
                var matches      = r.Matches(Path.GetFileName(filePath));
                foreach (Match match in matches)
                {
                    languageCode = match.Groups[1].Value;
                }

                var languageNode = xmlDocument.SelectSingleNode(@"//Language");

                if (languageNode == null || languageNode.Attributes == null)
                {
                    continue;
                }

                //get language friendly name
                var languageName = languageNode.Attributes["Name"].InnerText.Trim();

                //is default
                var isDefaultAttribute = languageNode.Attributes["IsDefault"];
                var isDefault          = isDefaultAttribute != null && Convert.ToBoolean(isDefaultAttribute.InnerText.Trim());

                //is default
                var isRightToLeftAttribute = languageNode.Attributes["IsRightToLeft"];
                var isRightToLeft          = isRightToLeftAttribute != null && Convert.ToBoolean(isRightToLeftAttribute.InnerText.Trim());

                //create language
                var language = new InstallationLanguage
                {
                    Code          = languageCode,
                    Name          = languageName,
                    IsDefault     = isDefault,
                    IsRightToLeft = isRightToLeft,
                };

                //load resources
                var resources = xmlDocument.SelectNodes(@"//Language/LocaleResource");
                if (resources == null)
                {
                    continue;
                }
                foreach (XmlNode resNode in resources)
                {
                    if (resNode.Attributes == null)
                    {
                        continue;
                    }

                    var resNameAttribute = resNode.Attributes["Name"];
                    var resValueNode     = resNode.SelectSingleNode("Value");

                    if (resNameAttribute == null)
                    {
                        continue;
                    }
                    var resourceName = resNameAttribute.Value.Trim();
                    if (string.IsNullOrEmpty(resourceName))
                    {
                        continue;
                    }

                    if (resValueNode == null)
                    {
                        continue;
                    }
                    var resourceValue = resValueNode.InnerText.Trim();

                    language.Resources.Add(new InstallationLocaleResource
                    {
                        Name  = resourceName,
                        Value = resourceValue
                    });
                }

                _availableLanguages.Add(language);
                _availableLanguages = _availableLanguages.OrderBy(l => l.Name).ToList();
            }
            return(_availableLanguages);
        }