Example #1
0
        public async Task Upload()
        {
            var fileReader = new StreamReader(_file.FullName);
            var count      = 0;

            _productfileconfig = await VendorsConfig.GetProductFileConfigByVendorId(_vendor.Id);

            _imagefileconfig = await VendorsConfig.GetImageFileConfigByVendorId(_vendor.Id);

            for (var i = 1; i < _vendor.RowAt; ++i)
            {
                await fileReader.ReadLineAsync();
            }

            var totalLines = File.ReadAllLines(_file.FullName).Count();
            var line       = await fileReader.ReadLineAsync();

            while (!String.IsNullOrEmpty(line))
            {
                await InsertVendorProduct(line);

                line = await fileReader.ReadLineAsync();

                count++;

                var percentage = (((double)count + 1) / totalLines - _vendor.RowAt) * 100.00;
                System.Console.WriteLine("{1:#0.00}% Inserting product for vendor: {0}", _vendor.VendorName, percentage);
            }

            System.Console.WriteLine("Done uploading {0} products for {1}", count, _vendor.VendorName);
            fileReader.Close();

            await MoveFile();
        }
Example #2
0
        public async Task Upload()
        {
            //			System.Console.WriteLine("Uploading ");
            _productfileconfig = await VendorsConfig.GetProductFileConfigByVendorId(_vendor.Id);

            _imagefileconfig = await VendorsConfig.GetImageFileConfigByVendorId(_vendor.Id);

            var xlApplication = new Application();

            xlApplication.DisplayAlerts = false;

            var xlWorkbook  = xlApplication.Workbooks.Open(_file.FullName);
            var xlWorksheet = (Worksheet)xlWorkbook.Worksheets.Item[1];

            _range = xlWorksheet.UsedRange;

            await InsertVendorProducts();

            //Cleanup
            _range.Clear();
            Marshal.FinalReleaseComObject(_range);
            _range = null;

            Marshal.FinalReleaseComObject(xlWorksheet);
            xlWorksheet = null;

            xlWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);
            Marshal.FinalReleaseComObject(xlWorkbook);
            xlWorkbook = null;

            xlApplication.Quit();
            Marshal.FinalReleaseComObject(xlApplication);
            xlApplication = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            await MoveFile();
        }