public ProcessingContext(Generator.Ctx parent, IReadFiles metaStorage) { ctxFile = new Generator.Ctx(parent); ctxFile.CreateValue(sFileDir); ctxFile.CreateValue(sFileName); ctxFile.CreateValue(sSheetName); var metaFiles = metaStorage.EnumerateFiles("").Where(fn => fn.EndsWith(".src.ini")); metas = Metadata.Load(metaStorage, metaFiles, ctxFile).ToArray(); dictExt2Kind = new Dictionary <string, string>(); foreach (var m in metas) { foreach (var Ext in m.FileNameExtension) { var ext = '.' + Ext.ToLowerInvariant(); if (!dictExt2Kind.TryGetValue(ext, out var kind)) { dictExt2Kind[ext] = m.FileContentKind; } else if (kind != m.FileContentKind) { throw new Exception($"Can't associate extension '{ext}' with two kinds of content ('{kind}' and '{m.FileContentKind}')"); } } } }
public async Task <IEnumerable <FileContentEntity> > ProcessDataByPage(IList <WikimediaEntity> listDownload) { ReadFiles = new ReadFiles(); GroupList = new GroupList(); ReadFileCodes = new ReadFileCodes(); ProcessConversionData = new ProcessConversionData(); var list = new List <FileContentEntity>(); var codes = ReadFileCodes.getListCodes(); foreach (var item in listDownload) { var result = await ReadFiles.ReadFileAsync(item.localPath, item.hour); var processedList = ProcessConversionData.ConvertDataToProcess(result, codes); var listGroup = GroupList.GetGroupedListByPage(processedList); var maxViewCont = listGroup.GetMax(item => item.viewCount); maxViewCont.period = item.hour; list.Add(maxViewCont); } return(list); }
public JsonFileProvider(string filePath, IReadFiles fileReader) { if (fileReader == null) { throw new ArgumentNullException("fileReader"); } if (filePath == null) { throw new ArgumentNullException("filePath"); } _filePath = filePath; _fileReader = fileReader; }
public static IEnumerable <Metadata> Load(IReadFiles storage, IEnumerable <string> files, Generator.Ctx parent) { foreach (var fname in files) { using (var stream = storage.OpenReadFile(fname)) using (var reader = new StreamReader(stream)) { var ctx = new Generator.Ctx(parent); ctx.CreateValue(sMetadataFile, fname); foreach (var m in Metadata.Create(reader, ctx)) { yield return(m); } } } }
public SqlLoader(IReadFiles fileReader) { FileReader = fileReader; }
public TargetsProvider(IProvideSettings settingsProvider, IReadFiles fileReader) { _settingsProvider = settingsProvider; _fileReader = fileReader; }
public SubDirReader(IReadFiles dir, string subDir) { this.dir = dir; this.subDir = subDir; }
public Reader(string xlsxFileName) { filename = xlsxFileName; var zipFiles = new FilesFromZip(new ZipFile(new FileStream(xlsxFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))); xmlFiles = zipFiles; resource = zipFiles; const string xlDir = "xl"; const string sCalcChainFile = "calcChain.xml"; if (xmlFiles.FileExists(Path.Combine(xlDir, sCalcChainFile))) { xmlFiles.RewriteFile(Path.Combine(xlDir, sCalcChainFile), null); // "delete" file XmlItem rel; var sRelsFile = Path.Combine(xlDir, "_rels", "workbook.xml.rels"); long nRelsFileSize; using (var stream = xmlFiles.OpenReadFile(sRelsFile)) { nRelsFileSize = stream.Length; using (var reader = XmlReader.Create(stream)) rel = XmlItem.Read(reader).First(); } using (var stream = new MemoryStream((int)nRelsFileSize)) { using (var writer = new XmlTextWriter(stream, Encoding.UTF8)) { writer.WriteStartDocument(); rel.WriteStartElementAndAttrs(writer); foreach (var r in rel.subItems) { if (!r.Attrs.Any(xa => xa.Name == "Target" && xa.Value == sCalcChainFile)) { r.WritePart(writer); } } writer.WriteEndElement(); writer.WriteEndDocument(); } xmlFiles.RewriteFile(sRelsFile, stream.GetBuffer()); } } using (var stream = xmlFiles.OpenReadFile(Path.Combine(xlDir, "styles.xml"))) using (var reader = XmlReader.Create(stream)) styles = StyleInfo.ReadStyles(XmlItem.Read(reader)); using (var stream = xmlFiles.OpenReadFile(Path.Combine(xlDir, "sharedStrings.xml"))) stringTable = ReadStringTable(stream).ToArray(); var sheetsDir = Path.Combine(xlDir, "worksheets"); var lstSheetsNames = new List <string>(8); using (var stream = xmlFiles.OpenReadFile(Path.Combine(xlDir, "workbook.xml"))) using (var reader = XmlReader.Create(stream)) { var wbook = XmlItem.Read(reader).ToArray(); var sheets = wbook.First(x => x.Name == "workbook").subItems.First(x => x.Name == "sheets").subItems.Where(x => x.Name == "sheet"); foreach (var name in sheets.Select(x => x.Attrs.First(a => a.Name == "name").Value)) { lstSheetsNames.Add(name); } } sheetNames = lstSheetsNames.ToArray(); sheetFiles = xmlFiles.EnumerateFiles(sheetsDir) // sort filenames like "xl/worksheets/sheet1.xml", ..., "xl/worksheets/sheet10.xml" in numerical order .OrderBy(sf => { var s = sf.Substring(19, sf.Length - 23); return(int.Parse(s)); }).ToArray(); }