static void Main(string[] args) { IExcelConverter converter = new ExcelConverter(); IFileStorage fileStore = new FolderFileStorage(); // Input Excel file var inputFilePath = @"C:\_git\ExcelDataExporter\tst\Resources\Financial Sample.xlsx"; var inputStream = fileStore.GetFileStream(inputFilePath); // Load Stream converter.LoadStream(inputStream); // Convert Excel To XML //var xmlString = converter.GetXML("); var xmlString = converter.GetXML("Excel", "RowItem", "http://sample.com"); // Save Instance fileStore.SaveFile("Excel.xml", StreamHelpers.ConvertStringToStream(xmlString)); // Convert Excel To JSON var jsonString = converter.GetJSON(); // Save Instance fileStore.SaveFile("Excel_JSON.json", StreamHelpers.ConvertStringToStream(jsonString)); Console.ReadKey(); }
/// <summary> /// 从指定的文件中获取单词数组 /// </summary> /// <param name="folderName">文件夹名称</param> /// <param name="fileName">文件名</param> /// <returns>单词、注释组成的字符串集合</returns> public static async Task <string[]> GetWordArrByTxt(string folderName, string fileName) { if (string.IsNullOrWhiteSpace(folderName)) { throw new ArgumentNullException("folderName"); } if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentNullException("fileName"); } IFileStorage storage = new FolderFileStorage(folderName); //var file = (await storage.GetFileListAsync(@"folderName\*")).FirstOrDefault(); string content = await storage.GetFileContentsAsync(fileName); if (string.IsNullOrWhiteSpace(content)) { return new string[] { } } ; // 使用当前系统环境的换行字符串 var wordArr = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); return(wordArr); }
private async Task <IGeoIpService> GetResolverAsync(ILoggerFactory loggerFactory) { if (String.IsNullOrEmpty(_options.MaxMindGeoIpKey)) { _logger.LogInformation("Configure {SettingKey} to run geo tests.", nameof(AppOptions.MaxMindGeoIpKey)); return(new NullGeoIpService()); } string dataDirectory = PathHelper.ExpandPath(".\\"); var storage = new FolderFileStorage(new FolderFileStorageOptions { Folder = dataDirectory, LoggerFactory = loggerFactory }); if (!await storage.ExistsAsync(DownloadGeoIPDatabaseJob.GEO_IP_DATABASE_PATH)) { var job = new DownloadGeoIPDatabaseJob(_options, GetService <ICacheClient>(), storage, loggerFactory); var result = await job.RunAsync(); Assert.NotNull(result); Assert.True(result.IsSuccess); } return(new MaxMindGeoIpService(storage, loggerFactory)); }
public void CanUseDataDirectory() { var storage = new FolderFileStorage(DATA_DIRECTORY_QUEUE_FOLDER); Assert.NotNull(storage.Folder); Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder); Assert.True(storage.Folder.EndsWith("Queue\\"), storage.Folder); }
public virtual void CanUseDataDirectory() { const string DATA_DIRECTORY_QUEUE_FOLDER = @"|DataDirectory|\Queue"; var storage = new FolderFileStorage(DATA_DIRECTORY_QUEUE_FOLDER); Assert.NotNull(storage.Folder); Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder); Assert.True(storage.Folder.EndsWith("Queue" + Path.DirectorySeparatorChar), storage.Folder); }
public GeoTests() { var dataDirectory = PathHelper.ExpandPath(".\\"); var storage = new FolderFileStorage(dataDirectory); if (!storage.ExistsAsync(MindMaxGeoIPResolver.GEO_IP_DATABASE_PATH).Result) { var job = new DownloadGeoIPDatabaseJob(storage).Run(); Assert.NotNull(job); Assert.True(job.IsSuccess); } _resolver = new MindMaxGeoIPResolver(storage); }
public virtual void CanUseDataDirectory() { const string DATA_DIRECTORY_QUEUE_FOLDER = @"|DataDirectory|\Queue"; var storage = new FolderFileStorage( new FolderFileStorageOptions { LoggerFactory = Substitute.For <ILoggerFactory>(), Folder = DATA_DIRECTORY_QUEUE_FOLDER }); Assert.NotNull(storage.Folder); Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder); Assert.True(storage.Folder.EndsWith("Queue" + Path.DirectorySeparatorChar), storage.Folder); }
private async Task <IGeoIpService> GetResolverAsync(ILoggerFactory loggerFactory) { var dataDirectory = PathHelper.ExpandPath(".\\"); var storage = new FolderFileStorage(dataDirectory); if (!await storage.ExistsAsync(MaxMindGeoIpService.GEO_IP_DATABASE_PATH)) { var job = new DownloadGeoIPDatabaseJob(GetService <ICacheClient>(), storage, loggerFactory); var result = await job.RunAsync(); Assert.NotNull(result); Assert.True(result.IsSuccess); } return(new MaxMindGeoIpService(storage, loggerFactory.CreateLogger <MaxMindGeoIpService>())); }
//public virtual async Task WillRespectStreamOffsetAsync() //{ // await this.ResetAsync(); // var storage = this.GetStorage(); // if (storage == null) // { // return; // } // using (storage) // { // var path = "doe.txt"; // using (var memoryStream = new MemoryStream()) // { // long offset; // using (var writer = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true)) // { // writer.AutoFlush = true; // await writer.WriteAsync("John"); // offset = memoryStream.Position; // await writer.WriteAsync("Doe"); // } // memoryStream.Seek(offset, SeekOrigin.Begin); // await storage.SaveFileAsync(path, memoryStream); // } // Assert.Equal("Doe", await storage.GetFileContentsAsync(path)); // } //} public virtual void CanUseDataDirectory() { const string DATA_DIRECTORY_QUEUE_FOLDER = @"|DataDirectory|\Queue"; #pragma warning disable CA2000 // Dispose objects before losing scope var storage = new FolderFileStorage( new FolderFileStorageOptions { LoggerFactory = Substitute.For <ILoggerFactory>(), Folder = DATA_DIRECTORY_QUEUE_FOLDER }); #pragma warning restore CA2000 // Dispose objects before losing scope Assert.NotNull(storage.Folder); Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder); Assert.True(storage.Folder.EndsWith("Queue" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase), storage.Folder); }
private static async Task <IGeoIPService> GetResolverAsync() { if (_service != null) { return(_service); } var dataDirectory = PathHelper.ExpandPath(".\\"); var storage = new FolderFileStorage(dataDirectory); if (!await storage.ExistsAsync(MindMaxGeoIPService.GEO_IP_DATABASE_PATH)) { var job = new DownloadGeoIPDatabaseJob(new InMemoryCacheClient(), storage); var result = await job.RunAsync(); Assert.NotNull(result); Assert.True(result.IsSuccess); } return(_service = new MindMaxGeoIPService(storage)); }
public async Task GeneratePerformanceData() { var currentBatchCount = 0; var parserPluginManager = IoC.GetInstance <EventParserPluginManager>(); var dataDirectory = Path.GetFullPath(@"..\..\Pipeline\Data\"); foreach (var file in Directory.GetFiles(dataDirectory)) { File.Delete(file); } Dictionary <string, UserInfo> _mappedUsers = new Dictionary <string, UserInfo>(); Dictionary <string, string> _mappedIPs = new Dictionary <string, string>(); var storage = new FolderFileStorage(Path.GetFullPath(@"..\..\..\")); foreach (var file in await storage.GetFileListAsync(@"Api\App_Data\storage\q\*")) { var eventPostInfo = await storage.GetObjectAsync <EventPostInfo>(file.Path); byte[] data = eventPostInfo.Data; if (!String.IsNullOrEmpty(eventPostInfo.ContentEncoding)) { data = data.Decompress(eventPostInfo.ContentEncoding); } var encoding = Encoding.UTF8; if (!String.IsNullOrEmpty(eventPostInfo.CharSet)) { encoding = Encoding.GetEncoding(eventPostInfo.CharSet); } string input = encoding.GetString(data); var events = parserPluginManager.ParseEvents(input, eventPostInfo.ApiVersion, eventPostInfo.UserAgent); foreach (var ev in events) { ev.Date = new DateTimeOffset(new DateTime(2020, 1, 1)); ev.ProjectId = null; ev.OrganizationId = null; ev.StackId = null; if (ev.Message != null) { ev.Message = RandomData.GetSentence(); } var keysToRemove = ev.Data.Keys.Where(k => !k.StartsWith("@") && k != "MachineName" && k != "job" && k != "host" && k != "process").ToList(); foreach (var key in keysToRemove) { ev.Data.Remove(key); } ev.Data.Remove(Event.KnownDataKeys.UserDescription); var identity = ev.GetUserIdentity(); if (identity != null) { if (!_mappedUsers.ContainsKey(identity.Identity)) { _mappedUsers.Add(identity.Identity, new UserInfo(Guid.NewGuid().ToString(), currentBatchCount.ToString())); } ev.SetUserIdentity(_mappedUsers[identity.Identity]); } var request = ev.GetRequestInfo(); if (request != null) { request.Cookies?.Clear(); request.PostData = null; request.QueryString?.Clear(); request.Referrer = null; request.Host = RandomData.GetIp4Address(); request.Path = $"/{RandomData.GetWord(false)}/{RandomData.GetWord(false)}"; request.Data.Clear(); if (request.ClientIpAddress != null) { if (!_mappedIPs.ContainsKey(request.ClientIpAddress)) { _mappedIPs.Add(request.ClientIpAddress, RandomData.GetIp4Address()); } request.ClientIpAddress = _mappedIPs[request.ClientIpAddress]; } } InnerError error = ev.GetError(); while (error != null) { error.Message = RandomData.GetSentence(); error.Data.Clear(); (error as Error)?.Modules.Clear(); error = error.Inner; } var environment = ev.GetEnvironmentInfo(); environment?.Data.Clear(); } // inject random session start events. if (currentBatchCount % 10 == 0) { events.Insert(0, events[0].ToSessionStartEvent()); } await storage.SaveObjectAsync($"{dataDirectory}\\{currentBatchCount++}.json", events); } }