コード例 #1
0
        void UploadSheet(string path, StringBuilder errors)
        {
            var importer = new SheetImporter();
            var password = importer.ImportPassword(errors, path);

            if (password == "")
            {
                errors.AppendFormat("{0} has no password set in cell AA1\n", path);
                return;
            }

            byte[] bytes = null;
            try
            {
                bytes = System.IO.File.ReadAllBytes(path);
            }
            catch (Exception e)
            {
                errors.AppendLine(e.Message);
                return;
            }

            string file = System.IO.Path.GetFileName(path).Replace(" ", "_");

            password = password.Replace(" ", "_").Replace("/", "_");

            mainWindow.SendUpload(password, bytes, file);

            errors.AppendFormat("{0} uploaded to {1}.\n", path, password);

            // now scrape the sheet
            importer.ImportSheet(path, errors);
        }
コード例 #2
0
        void ImportSpirits(string path, StringBuilder errors)
        {
            var importer = new SheetImporter();

            // now scrape the sheet
            importer.ImportSpirits(path, errors);
        }
コード例 #3
0
        private static void HandleSheet <TSheet, TRow>(ExcelWorkbook workbook, string sheetName)
            where TSheet : ScriptableObject
            where TRow : new()
        {
            var importFilename = GetImportFilePath(workbook, sheetName, ImportBasePath, PrefixAssetName);

            SheetImporter.ImportData <TSheet, TRow>(workbook, sheetName, importFilename);
        }
コード例 #4
0
        private void ProcessDetailFiles(SpreadsheetDocument targetWorkbook)
        {
            // load all the files from the output
            var files = Directory.GetFiles(Path.Combine(Settings.RootFolder, Constants.ReportFolderName))
                        .Aggregate(new List <ProcessingRecord>(), (list, s) =>
            {
                list.Add(new ProcessingRecord()
                {
                    AbsolutePath = s,
                    Filename     = Path.GetFileName(s),
                    Processed    = false
                });

                return(list);
            }).OrderBy(pr => pr.Filename).ToList();

            // this will take care of the SiteAssessmentReport.csv that is in the root folder alongside the summary report
            files.Insert(0, new ProcessingRecord()
            {
                AbsolutePath = Path.Combine(Settings.RootFolder, Constants.FinalSiteReportCsv),
                Filename     = Path.GetFileName(Path.Combine(Settings.RootFolder, Constants.FinalSiteReportCsv)),
                Processed    = false
            });

            // track total number of files and which one we are currently processing
            var counter = 1;
            var total   = files.Count();

            try
            {
                var importerTop  = Console.CursorTop;
                var importerLeft = Console.CursorLeft;

                foreach (var file in files)
                {
                    ProgressCallback(new SMATGeneratorProgressInfo()
                    {
                        TotalFilesMax      = total,
                        TotalFilesPosition = counter,
                    });

                    try
                    {
                        Trace.WriteLine(string.Format("Processing import for source file {0}", file.AbsolutePath), TraceCategory);

                        using (var importer = new SheetImporter(targetWorkbook, file, ProgressCallback))
                        {
                            importer.Import();
                        }

                        file.Processed = true;

                        Trace.WriteLine(string.Format("Processed import for source file {0}", file.AbsolutePath), TraceCategory);
                    }
                    catch (Exception err)
                    {
                        Trace.TraceError(err.ToString());
                    }
                    finally
                    {
                        counter++;
                    }
                }
            }
            catch (Exception err)
            {
                Trace.TraceError("Error in ImportManager.ProcessDetailFiles, could not continue.");
                Trace.TraceError(err.ToString());
            }
            finally
            {
                // report full progress at the end for consistency
                ProgressCallback(new SMATGeneratorProgressInfo()
                {
                    TotalFilesMax      = total,
                    TotalFilesPosition = total,
                });
            }
        }