public override async Task <WebResponse> Get(WebRequest request) { if (request.QueryParameter.ContainsKey("key")) { IFileInfo mhfFile = FileProvider.GetFileInfo("MHFUP_00.DAT"); WebResponse response = new WebResponse(); response.StatusCode = 200; response.Header.Add("content-type", "application/octet-stream"); response.Header.Add("content-disposition", "inline; filename=\"MHFUP_00.DAT\""); response.Header.Add("connection", "close"); await response.WriteAsync(mhfFile); return(response); } if (request.QueryParameter.ContainsKey("chk")) { WebResponse response = new WebResponse(); response.StatusCode = 200; response.Header.Add("content-type", "application/octet-stream"); response.Header.Add("connection", "close"); await response.WriteAsync("[mhf Check Message:0]"); return(response); } return(await WebResponse.NotFound()); }
private void InitializeMetadataSettings() { IFileInfo fileInfo = FileProvider.GetFileInfo(METADATA_CATALOG_NAME); if (!fileInfo.Exists) { Directory.CreateDirectory(fileInfo.PhysicalPath); } string json = "{}"; fileInfo = FileProvider.GetFileInfo($"{METADATA_CATALOG_NAME}/{METADATA_SETTINGS_FILE_NAME}"); if (fileInfo.Exists) { using (StreamReader reader = new StreamReader(fileInfo.PhysicalPath, Encoding.UTF8)) { json = reader.ReadToEnd(); } MetadataSettings = JsonSerializer.Deserialize <MetadataSettings>(json); } else { SaveMetadataSettings(); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddScoped <DashboardConfigurator>((IServiceProvider serviceProvider) => { DashboardConfigurator configurator = new DashboardConfigurator(); // Create and configure a dashboard storage. DashboardFileStorage dashboardFileStorage = new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath); configurator.SetDashboardStorage(dashboardFileStorage); // Create and configure a data source storage. DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); SqlDataSourceConfigurator.ConfigureDataSource(dataSourceStorage); ExcelDataSourceConfigurator.ConfigureDataSource(configurator, dataSourceStorage, FileProvider); ObjectDataSourceConfigurator.ConfigureDataSource(configurator, dataSourceStorage); EFDataSourceConfigurator.ConfigureDataSource(dataSourceStorage); JsonDataSourceConfigurator.ConfigureDataSource(configurator, dataSourceStorage, FileProvider); ExtractDataSourceConfigurator.ConfigureDataSource(configurator, dataSourceStorage, FileProvider); OlapDataSourceConfigurator.ConfigureDataSource(configurator, dataSourceStorage); XpoDataSourceConfigurator.ConfigureDataSource(dataSourceStorage); configurator.SetDataSourceStorage(dataSourceStorage); // Uncomment the next line to allow users to create new data sources based on predefined connection strings. // configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); return(configurator); }); services.AddDevExpressControls(); }
public override async Task <OriginalData?> GetAsync(string source, ICachedImage?existingCachedImage) { IFileInfo fileInfo = FileProvider.GetFileInfo(source); if (fileInfo.Exists == false) { throw new Exception("file not found: " + source); } string etag = (fileInfo.Length ^ fileInfo.LastModified.UtcTicks).ToString(); if (existingCachedImage != null) { if (existingCachedImage.Metadata.Cache.ETag == etag) { return(null); } } MemoryStream mem = new MemoryStream((int)fileInfo.Length); using (Stream stream = fileInfo.CreateReadStream()) { await stream.CopyToAsync(mem); } string mimeType = MimeTypeHelper.GetMimeTypeByExtension(fileInfo.Name); return(new OriginalData(mimeType, mem.ToArray(), new CacheSettings() { ETag = etag })); }
/// <summary> /// Open file and get new reader. /// </summary> /// <returns></returns> /// <exception cref="FileNotFoundException">if ThrowIfNotFound and not found</exception> IEnumerator <ILineTree> IEnumerable <ILineTree> .GetEnumerator() { try { IFileInfo fi = FileProvider.GetFileInfo(FilePath); if (!ThrowIfNotFound && !fi.Exists) { return(empty.GetEnumerator()); } using (Stream s = fi.CreateReadStream()) { ILineTree tree = FileFormat.ReadLineTree(s, LineFormat); if (tree == null) { return(empty.GetEnumerator()); } ILineTree[] trees = new ILineTree[] { tree }; return(((IEnumerable <ILineTree>)trees).GetEnumerator()); } } catch (FileNotFoundException) when(!ThrowIfNotFound) { return(empty.GetEnumerator()); } }
private void DeleteDatabaseCommand(object parameter) { if (!(parameter is TreeNodeViewModel treeNode)) { return; } if (!(treeNode.NodePayload is DatabaseInfo database)) { return; } DatabaseServer server = treeNode.GetAncestorPayload <DatabaseServer>(); if (server == null) { return; } MessageBoxResult result = MessageBox.Show("Delete database \"" + database.Name + "\" ?", "DaJet", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result != MessageBoxResult.OK) { return; } IFileInfo scriptsCatalog = FileProvider.GetFileInfo($"{SCRIPTS_CATALOG_NAME}/{server.Identity.ToString().ToLower()}/{database.Identity.ToString().ToLower()}"); if (scriptsCatalog.Exists) { Directory.Delete(scriptsCatalog.PhysicalPath); } server.Databases.Remove(database); treeNode.Parent.TreeNodes.Remove(treeNode); SaveMetadataSettings(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddDbContext <ParcInfoContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); //var connection = new System.Data.SqlClient.SqlConnection("Server=DESKTOP-DDGJARM;Database=Parc_informatique; User Id=tsi;password=Pfe@2020;Integrated Security=false"); //connection.Open(); services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver()) .AddDefaultDashboardController(configurator => { configurator.SetDashboardStorage(new DashboardFileStorage(FileProvider.GetFileInfo("App_Data/Dashboards").PhysicalPath)); configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); }); services.AddDevExpressControls(); //services.AddSignalR(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddResponseCompression() .AddDevExpressControls() .AddMvc(); services.AddScoped <DashboardConfigurator>((IServiceProvider serviceProvider) => { DashboardConfigurator configurator = new DashboardConfigurator(); configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath); configurator.SetDashboardStorage(dashboardFileStorage); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); // Registers an SQL data source. DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString"); sqlDataSource.DataProcessingMode = DataProcessingMode.Client; SelectQuery query = SelectQueryFluentBuilder .AddTable("Categories") .Join("Products", "CategoryID") .SelectAllColumns() .Build("Products_Categories"); sqlDataSource.Queries.Add(query); dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml()); configurator.SetDataSourceStorage(dataSourceStorage); return(configurator); }); }
protected override IAsyncEnumerable <string>?EfficientQuery(PageQueryRequest query, CancellationToken cancellationToken = default) { async IAsyncEnumerable <string> ByRoute() { string path = Paths.GetRouteFile(RootPath, query.Route); await using var fs = await(await FileProvider.GetFileInfo(path).ConfigureAwait(false)).CreateReadStream().ConfigureAwait(false); var result = await JsonSerializer.DeserializeAsync <string[]>(fs, cancellationToken : cancellationToken) .ConfigureAwait(false); if (result is not null) { foreach (var item in result) { yield return(item); } } } if (!string.IsNullOrEmpty(query.Route)) { return(ByRoute().Paging(query.Pagination)); } return(null); }
public async Task It_tracks_extensions_that_are_not_file_providers(Language language) { var kernel = CreateKernel(language); var provider = new FileProvider(kernel); var projectDir = DirectoryUtility.CreateDirectory(); var fileToEmbed = new FileInfo(Path.Combine(projectDir.FullName, "file.txt")); File.WriteAllText(fileToEmbed.FullName, "for testing only"); var packageName = $"MyTestExtension.{Path.GetRandomFileName()}"; var packageVersion = "2.0.0-" + Guid.NewGuid().ToString("N"); var guid = Guid.NewGuid().ToString(); var nupkg = await KernelExtensionTestHelper.CreateExtensionNupkg( projectDir, $"await kernel.SendAsync(new SubmitCode(\"\\\"{guid}\\\"\"));", packageName, packageVersion, fileToEmbed); await kernel.SubmitCodeAsync($@" #i ""nuget:{nupkg.Directory.FullName}"" #r ""nuget:{packageName},{packageVersion}"" "); var file = provider.GetFileInfo("extensions/TestKernelExtension/resources/file.txt"); file.Should() .NotBeNull(); }
public async Task It_does_not_track_extensions_that_are_not_file_providers(Language language) { var kernel = CreateKernel(language); var provider = new FileProvider(kernel); var projectDir = DirectoryUtility.CreateDirectory(); var packageName = $"MyTestExtension.{Path.GetRandomFileName()}"; var packageVersion = "2.0.0-" + Guid.NewGuid().ToString("N"); var guid = Guid.NewGuid().ToString(); var nupkg = await KernelExtensionTestHelper.CreateExtensionNupkg( projectDir, $"await kernel.SendAsync(new SubmitCode(\"\\\"{guid}\\\"\"));", packageName, packageVersion); await kernel.SubmitCodeAsync($@" #i ""nuget:{nupkg.Directory.FullName}"" #r ""nuget:{packageName},{packageVersion}"" "); Action action = () => provider.GetFileInfo("extensions/TestKernelExtension/resources/file.txt"); action.Should().Throw <StaticContentSourceNotFoundException>(); }
private void DeleteWebServerCommand(object parameter) { if (!(parameter is TreeNodeViewModel treeNode)) { return; } if (!(treeNode.NodePayload is WebServer server)) { return; } MessageBoxResult result = MessageBox.Show("Удалить web сервер \"" + server.Name + "\" ?", "DaJet", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result != MessageBoxResult.OK) { return; } WebSettings.WebServers.Remove(server); SaveWebSettings(); IFileInfo catalog = FileProvider.GetFileInfo($"{WEB_SETTINGS_CATALOG_NAME}/{server.Identity.ToString().ToLower()}"); if (catalog.Exists) { Directory.Delete(catalog.PhysicalPath, true); } treeNode.Parent.TreeNodes.Remove(treeNode); }
public async Task <KeywordCollection> GetKeywords(CancellationToken cancellationToken = default) { await using var fs = await(await FileProvider.GetFileInfo(Paths.GetKeywordMetadata(RootPath)).ConfigureAwait(false)).CreateReadStream().ConfigureAwait(false); var result = await JsonSerializer.DeserializeAsync <KeywordCollection>(fs, cancellationToken : cancellationToken) .ConfigureAwait(false); return(result ?? throw new System.Exception("Keywords are null")); }
public async Task <KeywordCollection> GetKeywords(CancellationToken cancellationToken = default) { using var fs = await(await FileProvider.GetFileInfo(Path.Join(RootPath, "keywords", "all.json")).ConfigureAwait(false)).CreateReadStream().ConfigureAwait(false); var result = await JsonSerializer.DeserializeAsync <KeywordCollection>(fs, cancellationToken : cancellationToken) .ConfigureAwait(false); return(result); }
public async Task <CategoryTree> GetCategories(CancellationToken cancellationToken = default) { using var fs = await(await FileProvider.GetFileInfo(Path.Join(RootPath, "categories", "all.json")).ConfigureAwait(false)).CreateReadStream().ConfigureAwait(false); var result = await JsonSerializer.DeserializeAsync <CategoryTree>(fs, cancellationToken : cancellationToken) .ConfigureAwait(false); return(result); }
private async Task <string> Payload(string path) { FileInfo = FileProvider.GetFileInfo(path); var data = FileInfo.ContentType(); var content = await GetContentBase64Async(); return($"data:{data};base64,{content}"); }
public void it_cannot_resolve_unregistered_extensions(Language language) { var kernel = CreateKernel(language); var provider = new FileProvider(kernel); Action action = () => provider.GetFileInfo("extensions/not_found/resources/file.txt"); action.Should().Throw <StaticContentSourceNotFoundException>(); }
public void It_loads_content_from_root_provider(Language language) { var kernel = CreateKernel(language); var provider = new FileProvider(kernel); var file = provider.GetFileInfo("resources/dotnet-interactive.js"); file.Should() .NotBeNull(); }
public string AddFileVersionToPath(PathString requestPathBase, string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var resolvedPath = path; var queryStringOrFragmentStartIndex = path.IndexOfAny(QueryStringAndFragmentTokens); if (queryStringOrFragmentStartIndex != -1) { resolvedPath = path.Substring(0, queryStringOrFragmentStartIndex); } if (Uri.TryCreate(resolvedPath, UriKind.Absolute, out var uri) && !uri.IsFile) { // Don't append version if the path is absolute. return(path); } if (Cache.TryGetValue(path, out string value)) { return(value); } var cacheEntryOptions = new MemoryCacheEntryOptions(); cacheEntryOptions.AddExpirationToken(FileProvider.Watch(resolvedPath)); var fileInfo = FileProvider.GetFileInfo(resolvedPath); if (!fileInfo.Exists && requestPathBase.HasValue && resolvedPath.StartsWith(requestPathBase.Value, StringComparison.OrdinalIgnoreCase)) { var requestPathBaseRelativePath = resolvedPath.Substring(requestPathBase.Value.Length); cacheEntryOptions.AddExpirationToken(FileProvider.Watch(requestPathBaseRelativePath)); fileInfo = FileProvider.GetFileInfo(requestPathBaseRelativePath); } if (fileInfo.Exists) { value = QueryHelpers.AddQueryString(path, VersionKey, GetHashForFile(fileInfo)); } else { // if the file is not in the current server. value = path; } cacheEntryOptions.SetSize(value.Length * sizeof(char)); value = Cache.Set(path, value, cacheEntryOptions); return(value); }
public string ReadFile(string filename) { FileProvider = GetFileSystem(services); var path = NormalizePath(filename); IFileInfo fileInfo = FileProvider.GetFileInfo(path); var content = fileInfo.CreateReadStream(); var reader = new StreamReader(content); var fileContent = reader.ReadToEnd(); return(fileContent); }
public override async Task <WebResponse> Post(WebRequest request) { WebResponse response = new WebResponse(); response.StatusCode = 200; response.Header.Add("content-type", "text/html; charset=UTF-8"); IFileInfo startHtml = FileProvider.GetFileInfo("auth/launcher/login.html"); await response.WriteAsync(startHtml); return(response); }
public override async Task <T?> Get(TId id, CancellationToken cancellationToken = default) { using var fs = await(await FileProvider.GetFileInfo(GetPath(id)).ConfigureAwait(false)).CreateReadStream().ConfigureAwait(false); var result = await JsonSerializer.DeserializeAsync <T?>(fs, cancellationToken : cancellationToken) .ConfigureAwait(false); if (result != null) { result.Id = id; } return(result); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddCors(options => { options.AddPolicy("CorsPolicy", builder => { builder.WithOrigins("http://localhost:4200"); builder.WithMethods(new String[] { "GET", "POST" }); builder.WithHeaders("Content-Type"); }); }) .AddResponseCompression() .AddDevExpressControls() .AddMvc() .AddDefaultDashboardController((configurator, serviceProvider) => { configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath); configurator.SetDashboardStorage(dashboardFileStorage); DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage(); // Registers an SQL data source. DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString"); sqlDataSource.DataProcessingMode = DataProcessingMode.Client; SelectQuery query = SelectQueryFluentBuilder .AddTable("Categories") .Join("Products", "CategoryID") .SelectAllColumns() .Build("Products_Categories"); sqlDataSource.Queries.Add(query); dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml()); // Registers an Object data source. DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source"); dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml()); // Registers an Excel data source. DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source"); excelDataSource.FileName = FileProvider.GetFileInfo("Data/Sales.xlsx").PhysicalPath; excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1")); dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml()); configurator.SetDataSourceStorage(dataSourceStorage); configurator.DataLoading += (s, e) => { if (e.DataSourceName == "Object Data Source") { e.Data = Invoices.CreateData(); } }; }); }
public async Task <IList <TId> > GetPaging(Pagination pagination) { await EnsureConfig(); if (pagination.CurrentPage >= 0 && (pagination.CurrentPage < Config !.TotalPage || Config.TotalPage == 0 && pagination.CurrentPage == 0)) { string path = GetPagePath(pagination.CurrentPage); using var fs = await(await FileProvider.GetFileInfo(path).ConfigureAwait(false)).CreateReadStream().ConfigureAwait(false); return(JsonSerializer.DeserializeAsync <IList <TId> >(fs) .ConfigureAwait(false).GetAwaiter().GetResult()); }
protected virtual async Task <IList <TId> > GetIdList(string rootPath, CancellationToken cancellationToken = default) { await using var fs = await(await FileProvider.GetFileInfo(Paths.GetIdListFile(rootPath)).ConfigureAwait(false)) .CreateReadStream().ConfigureAwait(false); var result = await JsonSerializer.DeserializeAsync <IList <TId> >(fs, cancellationToken : cancellationToken) .ConfigureAwait(false); if (result is null) { throw new Exception("Id list is null."); } return(result); }
public async Task <BlogOptions> GetOptions(CancellationToken cancellationToken = default) { var file = await FileProvider.GetFileInfo(Workspace.BlogOptionPath); if (await file.Exists()) { using var st = await file.CreateReadStream(); return(await JsonSerializer.DeserializeAsync <BlogOptions>(st)); } else { return(new BlogOptions()); } }
private void SaveMetadataSettings() { IFileInfo fileInfo = FileProvider.GetFileInfo($"{METADATA_CATALOG_NAME}/{METADATA_SETTINGS_FILE_NAME}"); JsonSerializerOptions options = new JsonSerializerOptions() { WriteIndented = true }; string json = JsonSerializer.Serialize(MetadataSettings, options); using (StreamWriter writer = new StreamWriter(fileInfo.PhysicalPath, false, Encoding.UTF8)) { writer.Write(json); } }
public async Task It_does_not_track_extensions_that_are_not_file_providers(Language language) { var kernel = CreateKernel(language); var provider = new FileProvider(kernel, typeof(Program).Assembly); var extensionPackage = KernelExtensionTestHelper.GetOrCreateSimpleExtension(); await kernel.SubmitCodeAsync($@" #i ""nuget:{extensionPackage.PackageLocation}"" #r ""nuget:{extensionPackage.Name},{extensionPackage.Version}"" "); Action action = () => provider.GetFileInfo("extensions/TestKernelExtension/resources/file.txt"); action.Should().Throw <StaticContentSourceNotFoundException>(); }
public async Task It_tracks_extensions_that_are_not_file_providers(Language language) { var kernel = CreateKernel(language); var provider = new FileProvider(kernel, typeof(Program).Assembly); var extensionPackage = KernelExtensionTestHelper.GetOrCreateFileProviderExtension(); await kernel.SubmitCodeAsync($@" #i ""nuget:{extensionPackage.PackageLocation}"" #r ""nuget:{extensionPackage.Name},{extensionPackage.Version}"" "); var file = provider.GetFileInfo("extensions/TestKernelExtension/resources/file.txt"); file.Should() .NotBeNull(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddResponseCompression() .AddDevExpressControls() .AddMvc(); services.AddScoped <DashboardConfigurator>((IServiceProvider serviceProvider) => { DashboardConfigurator configurator = new DashboardConfigurator(); DashboardFileStorage dashboardFileStorage = new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath); configurator.SetDashboardStorage(dashboardFileStorage); configurator.ConfigureDataConnection += (s, e) => { e.ConnectionParameters = new ExtractDataSourceConnectionParameters(FileProvider.GetFileInfo("Data/SalesPerson.dat").PhysicalPath); }; return(configurator); }); }