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);
            }
        }
Esempio n. 2
0
        public async Task PrintOrdersToPdf(Stream stream, IList <Order> orders, string languageId = "", string vendorId = "")
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

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

            _generatePdf.SetConvertOptions(new ConvertOptions()
            {
                PageSize    = Wkhtmltopdf.NetCore.Options.Size.A4,
                PageMargins = new Wkhtmltopdf.NetCore.Options.Margins()
                {
                    Bottom = 10, Left = 10, Right = 10, Top = 10
                },
                FooterHtml = CommonPath.WebMapPath(_orderFooter)
            });

            var html = await _viewRenderService.RenderToStringAsync <(IList <Order>, string)>(_orderTemaplate, new (orders, vendorId));

            var pdfBytes = _generatePdf.GetPDF(html);

            stream.Write(pdfBytes);
        }
        /// <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);
        }
        /// <summary>
        /// 选择游戏exe文件
        /// </summary>
        private void SelectGameDir(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog
            {
                Title    = "选择游戏exe文件",
                FileName = CommonPath.GamePlatform == "WeGame"
                    ? "dontstarve_rail"
                    : "dontstarve_steam", //默认文件名
                DefaultExt = ".exe",      // 默认文件扩展名
                Filter     = CommonPath.GamePlatform == "WeGame"
                    ? "饥荒游戏exe文件(*.exe)|dontstarve_rail.exe"
                    : "饥荒游戏exe文件(*.exe)|dontstarve_steam.exe",
                FilterIndex      = 1,
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() == true)
            {
                var fileName = openFileDialog.FileName;
                if (string.IsNullOrEmpty(fileName) || !fileName.Contains("dontstarve_"))
                {
                    MessageBox.Show("文件选择错误,请选择正确文件");
                    return;
                }
                CommonPath.ClientFilePath = fileName;
                GameDirSelectTextBox.Text = fileName;
                CommonPath.WriteClientPath(fileName, CommonPath.GamePlatform);
                // 检查通用设置
                CheckCommonSetting(true);
            }
        }
 /// <summary>
 /// 初始化服务器
 /// </summary>
 /// <param name="whenCreateWorld">是否为创建新世界时调用</param>
 public void InitServer(bool whenCreateWorld = false)
 {
     // 设置游戏平台
     CommonPath.SetGamePlatform();
     // 设置游戏平台SelectBox选择
     GamePlatformSelectBox.TextIndex = CommonPath.GetGamePlatform();
     // 设置SaveSlot面板按钮
     SetSaveSlotRadioButton();
     // 汉化
     _Hanization = JsonHelper.ReadHanization();
     // 控制台
     CreateConsoleClassificationButton();
     #region 仅创建世界时
     // [创建世界]设定文件路径
     if (whenCreateWorld)
     {
         _dediFilePath = new DediFilePath(SaveSlot);
     }
     // [创建世界]从modoverrides.lua读取mod设置
     if (!string.IsNullOrEmpty(CommonPath.ServerModsDirPath) && whenCreateWorld)
     {
         SetModSet();
     }
     #endregion
 }
Esempio n. 6
0
        public async Task PrintPackagingSlipsToPdf(Stream stream, IList <Shipment> shipments, string languageId = "")
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

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

            var lang = await _languageService.GetLanguageById(languageId);

            if (lang == null)
            {
                throw new ArgumentException(string.Format("Cannot load language. ID={0}", languageId));
            }

            _generatePdf.SetConvertOptions(new ConvertOptions()
            {
                PageSize    = Wkhtmltopdf.NetCore.Options.Size.A4,
                PageMargins = new Wkhtmltopdf.NetCore.Options.Margins()
                {
                    Bottom = 10, Left = 10, Right = 10, Top = 10
                },
                FooterHtml = CommonPath.WebMapPath(_shipmentFooter)
            });

            var html = await _viewRenderService.RenderToStringAsync <IList <Shipment> >(_shipmentsTemaplate, shipments);

            var pdfBytes = _generatePdf.GetPDF(html);

            stream.Write(pdfBytes);
        }
        /// <summary>
        /// 选择服务器文件
        /// </summary>
        private void SelectDediDir(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog
            {
                Title            = "选择服务器exe文件",
                FileName         = "dontstarve_dedicated_server_nullrenderer", //默认文件名
                DefaultExt       = ".exe",                                     // 默认文件扩展名
                Filter           = "饥荒服务器exe文件(*.exe)|dontstarve_dedicated_server_nullrenderer.exe",
                FilterIndex      = 1,
                RestoreDirectory = true
            };

            if (openFileDialog.ShowDialog() == true)
            {
                var fileName = openFileDialog.FileName;
                if (string.IsNullOrEmpty(fileName) || !fileName.Contains("dontstarve_dedicated_server_nullrenderer"))
                {
                    MessageBox.Show("文件选择错误,请选择正确文件");
                    return;
                }
                // 判断是否选择了客户端目录下的的服务器程序
                if (!fileName.Contains("Don't Starve Together Dedicated Server") && !fileName.Contains("饥荒联机版专用服务器"))
                {
                    if (MessageBox.Show("似乎选择了客户端目录的程序,请确认!如果确定没有问题仍然保存点击“是”(判断出错的情况一般只出现在WeGame版)!", "似乎选错了呢...", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }
                CommonPath.ServerFilePath = fileName;
                DediDirSelectTextBox.Text = fileName;
                CommonPath.WriteServerPath(fileName, CommonPath.GamePlatform);
                // 检查通用设置
                CheckCommonSetting(true);
            }
        }
Esempio n. 8
0
        private IPath GetModuleHistoryPath(string moduleName)
        {
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(_moduleInstallationPath.PhysicalPath, moduleName), VirtualPath = Kooboo.Web.Url.UrlUtility.Combine(_moduleInstallationPath.VirtualPath, moduleName)
            };

            Kooboo.IO.IOUtility.EnsureDirectoryExists(path.PhysicalPath);
            return(path);
        }
Esempio n. 9
0
        public IPath GetModuleDataPath(Site site)
        {
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(site.PhysicalPath, "Modules", ModuleName),
                VirtualPath  = UrlUtility.Combine(site.VirtualPath, "Modules", ModuleName)
            };

            return(path);
        }
        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. 11
0
        public IPath GetModuleDataPath()
        {
            var baseDir = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <IBaseDir>();
            var path    = new CommonPath()
            {
                PhysicalPath = Path.Combine(baseDir.Cms_DataPhysicalPath, "Modules", ModuleName),
                VirtualPath  = UrlUtility.Combine(baseDir.Cms_DataVirtualPath, "Modules", ModuleName)
            };

            return(path);
        }
Esempio n. 12
0
        public virtual void PrepareFlagsModel(LanguageModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            model.FlagFileNames = Directory
                                  .EnumerateFiles(CommonPath.WebMapPath("/assets/images/flags/"), "*.png", SearchOption.TopDirectoryOnly)
                                  .Select(Path.GetFileName)
                                  .ToList();
        }
Esempio n. 13
0
        public static IPath GetModuleSharedFilePath(this ModulePath modulePath, params string[] extraPaths)
        {
            var baseDir       = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <IBaseDir>();
            var physicalPaths = new[] { baseDir.Cms_DataPhysicalPath, ModuleDataFolderName, modulePath.ModuleName };
            var virtualPaths  = new[] { baseDir.Cms_DataVirtualPath, ModuleDataFolderName, modulePath.ModuleName };

            if (extraPaths != null && extraPaths.Length > 0)
            {
                physicalPaths = physicalPaths.Concat(extraPaths).ToArray();
                virtualPaths  = virtualPaths.Concat(extraPaths).ToArray();
            }
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(physicalPaths),
                VirtualPath  = UrlUtility.Combine(virtualPaths)
            };

            return(path);
        }
Esempio n. 14
0
        public async Task <string> PrintOrderToPdf(Order order, string languageId, string vendorId = "")
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var fileName = string.Format("order_{0}_{1}.pdf", order.OrderGuid, CommonHelper.GenerateRandomDigitCode(4));
            var filePath = Path.Combine(CommonPath.WebMapPath("assets/files/exportimport"), fileName);

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                var orders = new List <Order>
                {
                    order
                };
                await PrintOrdersToPdf(fileStream, orders, languageId, vendorId);
            }
            return(filePath);
        }
Esempio n. 15
0
        /// <summary>
        /// GetModuleLocalFilePath是得到Module在某个站点下的ModuleData,也就是:Bsc_Data\Sites\{SiteName}\ModuleData
        /// 需要ModulePath.Site信息。
        /// </summary>
        /// <param name="modulePath"></param>
        /// <param name="extraPaths"></param>
        /// <returns></returns>
        public static IPath GetModuleLocalFilePath(this ModulePath modulePath, params string[] extraPaths)
        {
            if (modulePath.Site == null)
            {
                throw new Exception("该站点为空, can not get the local file path");
            }
            var physicalPaths = new[] { modulePath.Site.PhysicalPath, ModuleDataFolderName, modulePath.ModuleName };
            var virtualPaths = new[] { modulePath.Site.VirtualPath, ModuleDataFolderName, modulePath.ModuleName };
            if (extraPaths != null && extraPaths.Length > 0)
            {
                physicalPaths = physicalPaths.Concat(extraPaths).ToArray();
                virtualPaths = virtualPaths.Concat(extraPaths).ToArray();
            }
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(physicalPaths),
                VirtualPath = UrlUtility.Combine(virtualPaths)
            };

            return path;
        }
Esempio n. 16
0
        /// <summary>
        /// Get the site related module file path. Each website has its seperated local file path for every module
        /// </summary>
        /// <param name="extraPaths"></param>
        /// <returns></returns>
        public IPath GetModuleLocalFilePath(params string[] extraPaths)
        {
            if (_site == null)
            {
                throw new ArgumentNullException("site");
            }
            var physicalPaths = new[] { _site.PhysicalPath, "Modules", _moduleName };
            var virtualPaths = new[] { _site.VirtualPath, "Modules", _moduleName };
            if (extraPaths != null && extraPaths.Length > 0)
            {
                physicalPaths = physicalPaths.Concat(extraPaths).ToArray();
                virtualPaths = virtualPaths.Concat(extraPaths).ToArray();
            }
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(physicalPaths),
                VirtualPath = UrlUtility.Combine(virtualPaths)
            };

            return path;
        }
 /// <summary>
 /// 设置"路径"
 /// </summary>
 private void SetCommonPath()
 {
     // 读取游戏平台
     CommonPath.SetGamePlatform();
     #region 读取客户端路径、服务器路径和ClusterToken
     // 客户端路径
     GameDirSelectTextBox.Text = "";
     CommonPath.ClientFilePath = CommonPath.ReadClientPath(CommonPath.GamePlatform);
     if (!string.IsNullOrEmpty(CommonPath.ClientFilePath) && File.Exists(CommonPath.ClientFilePath))
     {
         GameDirSelectTextBox.Text = CommonPath.ClientFilePath;
     }
     else
     {
         CommonPath.ClientFilePath = "";
     }
     // 服务器路径
     DediDirSelectTextBox.Text = "";
     CommonPath.ServerFilePath = CommonPath.ReadServerPath(CommonPath.GamePlatform);
     if (!string.IsNullOrEmpty(CommonPath.ServerFilePath) && File.Exists(CommonPath.ServerFilePath))
     {
         DediDirSelectTextBox.Text = CommonPath.ServerFilePath;
     }
     else
     {
         CommonPath.ServerFilePath = "";
     }
     // ClusterToken
     DediSettingClusterTokenTextBox.Text = "";
     CommonPath.ClusterToken             = CommonPath.ReadClusterTokenPath(CommonPath.GamePlatform);
     if (!string.IsNullOrEmpty(CommonPath.ClusterToken))
     {
         DediSettingClusterTokenTextBox.Text = CommonPath.ClusterToken;
     }
     else
     {
         CommonPath.ClusterToken = "";
     }
     #endregion
 }
Esempio n. 18
0
        public static IPath GetModuleLocalFilePath(this ModulePath modulePath, params string[] extraPaths)
        {
            if (modulePath.Site == null)
            {
                throw new Exception("The site is null, can not get the local file path".Localize());
            }
            var physicalPaths = new[] { modulePath.Site.PhysicalPath, ModuleDataFolderName, modulePath.ModuleName };
            var virtualPaths  = new[] { modulePath.Site.VirtualPath, ModuleDataFolderName, modulePath.ModuleName };

            if (extraPaths != null && extraPaths.Length > 0)
            {
                physicalPaths = physicalPaths.Concat(extraPaths).ToArray();
                virtualPaths  = virtualPaths.Concat(extraPaths).ToArray();
            }
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(physicalPaths),
                VirtualPath  = UrlUtility.Combine(virtualPaths)
            };

            return(path);
        }
Esempio n. 19
0
        /// <summary>
        /// Get the site related module file path. Each website has its seperated local file path for every module
        /// </summary>
        /// <param name="extraPaths"></param>
        /// <returns></returns>
        public IPath GetModuleLocalFilePath(params string[] extraPaths)
        {
            if (_site == null)
            {
                throw new ArgumentNullException("site");
            }
            var physicalPaths = new[] { _site.PhysicalPath, "Modules", _moduleName };
            var virtualPaths  = new[] { _site.VirtualPath, "Modules", _moduleName };

            if (extraPaths != null && extraPaths.Length > 0)
            {
                physicalPaths = physicalPaths.Concat(extraPaths).ToArray();
                virtualPaths  = virtualPaths.Concat(extraPaths).ToArray();
            }
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(physicalPaths),
                VirtualPath  = UrlUtility.Combine(virtualPaths)
            };

            return(path);
        }
Esempio n. 20
0
        /// <summary>
        /// GetModuleSharedFilePath 是得到它共享的数据存放目录,与站点无关的,也就是:Cms_Data\ModuleData
        /// </summary>
        /// <param name="modulePath"></param>
        /// <param name="extraPaths"></param>
        /// <returns></returns>
        public static IPath GetModuleSharedFilePath(this ModulePath modulePath, params string[] extraPaths)
        {
            var baseDir = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve<IBaseDir>();
            var physicalPaths = new[] { baseDir.Cms_DataPhysicalPath, ModuleDataFolderName, modulePath.ModuleName };
            var virtualPaths = new[] { baseDir.Cms_DataVirtualPath, ModuleDataFolderName, modulePath.ModuleName };
            if (extraPaths != null && extraPaths.Length > 0)
            {
                physicalPaths = physicalPaths.Concat(extraPaths).ToArray();
                virtualPaths = virtualPaths.Concat(extraPaths).ToArray();
            }
            var path = new CommonPath()
            {
                PhysicalPath = Path.Combine(physicalPaths),
                VirtualPath = UrlUtility.Combine(virtualPaths)
            };

            return path;
        }
Esempio n. 21
0
 public IPath GetModuleDataPath(Site site)
 {
     if (site == null)
     {
         return GetModuleDataPath();
     }
     var path = new CommonPath()
     {
         PhysicalPath = Path.Combine(site.PhysicalPath, "Modules", ModuleName),
         VirtualPath = UrlUtility.Combine(site.VirtualPath, "Modules", ModuleName)
     };
     return path;
 }
Esempio n. 22
0
 public IPath GetModuleDataPath()
 {
     var baseDir = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve<IBaseDir>();
     var path = new CommonPath()
     {
         PhysicalPath = Path.Combine(baseDir.Cms_DataPhysicalPath, "Modules", ModuleName),
         VirtualPath = UrlUtility.Combine(baseDir.Cms_DataVirtualPath, "Modules", ModuleName)
     };
     return path;
 }
Esempio n. 23
0
 private IPath GetModuleHistoryPath(string moduleName)
 {
     var path = new CommonPath() { PhysicalPath = Path.Combine(_moduleInstallationPath.PhysicalPath, moduleName), VirtualPath = Kooboo.Web.Url.UrlUtility.Combine(_moduleInstallationPath.VirtualPath, moduleName) };
     Kooboo.IO.IOUtility.EnsureDirectoryExists(path.PhysicalPath);
     return path;
 }
Esempio n. 24
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;
            }
        }
        /// <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);
        }
Esempio n. 26
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();
        }