コード例 #1
0
        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();
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: GeoTests.cs プロジェクト: ysq5202121/Exceptionless
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: GeoTests.cs プロジェクト: lbarahona30/Exceptionless
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: GeoTests.cs プロジェクト: zhangwxyc/Exceptionless
        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>()));
        }
コード例 #9
0
ファイル: FileStorageBaseTests.cs プロジェクト: vip32/Naos
        //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);
        }
コード例 #10
0
ファイル: GeoTests.cs プロジェクト: jackswei/Exceptionless
        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));
        }
コード例 #11
0
        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);
            }
        }