Exemplo n.º 1
0
        private async Task <int> EvaluateAsync(string luaScriptFilePath, RequiresLimitFeatureContext context, CancellationToken cancellation = default)
        {
            var luaScriptFile = _virtualFileProvider.GetFileInfo(luaScriptFilePath);

            using var luaScriptFileStream = luaScriptFile.CreateReadStream();
            var fileBytes = await luaScriptFileStream.GetAllBytesAsync(cancellation);

            var luaSha1 = fileBytes.Sha1();

            if (!await _server.ScriptExistsAsync(luaSha1))
            {
                var luaScript = Encoding.UTF8.GetString(fileBytes);
                luaSha1 = await _server.ScriptLoadAsync(luaScript);
            }

            var keys = new RedisKey[1] {
                NormalizeKey(context)
            };
            var values = new RedisValue[] { context.GetEffectTicks() };
            var result = await _redis.ScriptEvaluateAsync(luaSha1, keys, values);

            if (result.Type == ResultType.Error)
            {
                throw new AbpException($"脚本执行错误:{result}");
            }
            return((int)result);
        }
        protected virtual async Task <ILocalizedTemplateContentReader> CreateInternalAsync(
            TemplateDefinition templateDefinition)
        {
            var virtualPath = templateDefinition.GetVirtualFilePathOrNull();

            if (virtualPath == null)
            {
                return(NullLocalizedTemplateContentReader.Instance);
            }

            var fileInfo = _virtualFileProvider.GetFileInfo(virtualPath);

            if (!fileInfo.Exists)
            {
                throw new AbpException("Could not find a file/folder at the location: " + virtualPath);
            }

            if (fileInfo.IsDirectory)
            {
                var folderReader = new VirtualFolderLocalizedTemplateContentReader();
                await folderReader.ReadContentsAsync(_virtualFileProvider, virtualPath);

                return(folderReader);
            }
            else //File
            {
                var singleFileReader = new FileInfoLocalizedTemplateContentReader();
                await singleFileReader.ReadContentsAsync(fileInfo);

                return(singleFileReader);
            }
        }
Exemplo n.º 3
0
        public string GenerateByTemplateName(string templateDirectory, string templateName, object model, out TemplateContext context)
        {
            string path         = Path.Combine(templateDirectory, templateName).NormalizePath();
            var    templateFile = _virtualFileProvider.GetFileInfo(path);
            var    templateText = templateFile.ReadAsString();

            return(GenerateByTemplateText(templateText, model, out context));
        }
        public async Task <IActionResult> ReadFile()
        {
            var fileInfo = _virtualFileProvider.GetFileInfo("/FooModule/MyResources/Localization/en.json");

            //string fileString = await fileInfo.ReadAsStringAsync();

            var fileBytes = await fileInfo.ReadBytesAsync();

            return(File(fileBytes, MimeTypes.Application.Json));
        }
Exemplo n.º 5
0
        public string GetOrNull(string cultureName)
        {
            var file = _virtualFileProvider.GetFileInfo(_virtualPath);

            if (file == null || !file.Exists || file.IsDirectory)
            {
                return(null);
            }

            return(file.ReadAsString());
        }
Exemplo n.º 6
0
        private void Initial()
        {
            var providers = Enum.GetValues(typeof(DbProviderType)).Cast <DbProviderType>();

            foreach (var provider in providers)
            {
                var sqlTable = _virtualFileProvider
                               .GetFileInfo($"/iBestRead/Abp/DbSchemaReader/Sql/{provider.ToString()}.Table.sql");
                if (!sqlTable.Exists)
                {
                    continue;
                }

                var sqlTableContent = sqlTable.ReadAsString();

                var sqlColumn = _virtualFileProvider
                                .GetFileInfo($"/iBestRead/Abp/DbSchemaReader/Sql/{provider.ToString()}.Column.sql");
                var sqlColumnContent = sqlColumn.ReadAsString();

                _dictionarySql.TryAdd(provider, new QuerySql(sqlTableContent, sqlColumnContent));
            }
        }
Exemplo n.º 7
0
        public void Test()
        {
            var file = _virtualFileProvider
                       .GetFileInfo("/MyResources/Hello.txt");

            if (file.Exists)
            {
                var fileContent = file.ReadAsString();
                Console.WriteLine(fileContent);
            }
            else
            {
                Console.WriteLine("文件不存在");
            }
        }
        public async Task ReadContentsAsync(
            IVirtualFileProvider virtualFileProvider,
            string virtualPath)
        {
            _dictionary = new Dictionary <string, string> ();

            var directoryInfo = virtualFileProvider.GetFileInfo(virtualPath);

            if (!directoryInfo.IsDirectory)
            {
                throw new RocketException("Given virtual path is not a folder: " + virtualPath);
            }

            foreach (var file in virtualFileProvider.GetDirectoryContents(virtualPath))
            {
                if (file.IsDirectory)
                {
                    continue;
                }

                _dictionary.Add(file.Name.RemovePostFix(".tpl"), await file.ReadAsStringAsync());
            }
        }
        private string GetFileContent()
        {
            var viewFileInfo = _virtualFileProvider.GetFileInfo(ViewPath);

            return(viewFileInfo.ReadAsString());
        }
Exemplo n.º 10
0
 public string Load(TemplateContext context, SourceSpan callerSpan, string templatePath)
 {
     return(_virtualFileProvider.GetFileInfo(templatePath).ReadAsString());
 }