Ejemplo n.º 1
0
        public async void ProcessCodes()
        {
            //var client = new HttpClient();
            //client.BaseAddress = new Uri(""); // TODO: set Azure BLOB path

            //using (var stream = client.GetStreamAsync("codes.xlsx").Result)
            //{
            //    _excelManager.ProcessExcelPackage(stream);
            //}

            //client.Dispose();

            // but, if access key is private, we need to use SDK
            var cloudStorageAccount = CloudStorageAccount.Parse("--connectionString--");

            var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
            var cloudContainer  = cloudBlobClient.GetContainerReference("codefiles");

            var filesList = await cloudContainer.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.None, 10, new BlobContinuationToken(), null, null);

            foreach (var listBlobItem in filesList.Results)
            {
                var blobItem = (CloudBlockBlob)listBlobItem;
                var fileBlob = cloudContainer.GetBlockBlobReference(blobItem.Name);

                var stream = new MemoryStream();
                await fileBlob.DownloadToStreamAsync(stream);

                _excelManager.ProcessExcelPackage(stream);

                await fileBlob.DeleteAsync();
            }
        }
Ejemplo n.º 2
0
        public void ProcessCodes()
        {
            var folderName = @"CodeFiles\";
            var folderPath = $@"{Directory.GetCurrentDirectory()}\{folderName}";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            var directoryInfo = new DirectoryInfo(folderPath);
            var files         = directoryInfo.GetFiles("*.xlsx");

            foreach (var file in files)
            {
                _excelManager.ProcessExcelPackage(file);
                //using (var content = new ExcelPackage(file))
                //{
                //    var worksheet = content.Workbook.Worksheets[1];
                //    var numberOfCodes = worksheet.Dimension.Rows;

                //    for (int i = 1; i <= numberOfCodes; i++)
                //    {
                //        var code = worksheet.Cells[i, 1].Value.ToString();
                //        var isWinning = bool.Parse(worksheet.Cells[i, 2].Value.ToString());

                //        if (!_codeRepository.GetAll().Any(x => x.CodeValue == code))
                //        {
                //            var codeObject = new Code
                //            {
                //                CodeValue = code,
                //                IsWinning = isWinning
                //            };

                //            _codeRepository.Insert(codeObject);
                //            Console.WriteLine("Code inserted.");
                //        }
                //    }
                //}

                File.Delete(file.FullName);
            }
        }
Ejemplo n.º 3
0
        public void ProcesCodes()
        {
            var folderName = "LocalStorage\\";
            var folderPath = $@"{Directory.GetCurrentDirectory()}\{folderName}";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            var directoryInfo = new DirectoryInfo(folderPath);
            var files         = directoryInfo.GetFiles("*.xlsx");

            foreach (var file in files)
            {
                _excelManager.ProcessExcelPackage(file);
                File.Delete(file.FullName);
            }
        }
Ejemplo n.º 4
0
        public async void ProcessCodes()
        {
            var cloudStorageAccount = CloudStorageAccount.Parse(
                "DefaultEndpointsProtocol=https;AccountName=codesstorage;AccountKey=SfHe0RsrmCWxarOx+ayW4kcJzSaagIHk0eiRybwStibnWPJTSFrI5yhx8E7aShYM51xAb9pDxq7tBRNf1pi/HQ==;EndpointSuffix=core.windows.net");

            var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
            var cloudContainer  = cloudBlobClient.GetContainerReference("codefiles");

            var filesList = await cloudContainer.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.None, 10,
                                                                         new BlobContinuationToken(), null, null);

            foreach (var listBlobItem in filesList.Results)
            {
                var blobItem = (CloudBlockBlob)listBlobItem;
                var fileBlob = cloudContainer.GetBlockBlobReference(blobItem.Name);

                var stream = new MemoryStream();
                await fileBlob.DownloadToStreamAsync(stream);

                _excelManager.ProcessExcelPackage(stream);

                await fileBlob.DeleteAsync();
            }
        }