2using System.Collections;
3using System.Collections.Generic;
6using NPOI.SS.UserModel;
7using NPOI.XSSF.UserModel;
14 public Dictionary<string, EMod>
fileProviders =
new Dictionary<string, EMod>(PathComparer.Default);
23 string[] array =
new string[3]
29 foreach (
string key
in array)
41 string sheetName = sheet.SheetName;
45 if ((
object)sourceData ==
null)
47 Debug.Log(
"#source skipping sheet " + sheetName);
53 list = sourceData.GetField<IList>(
"rows");
61 int count = list2.Count;
62 Debug.Log(
"#source loading sheet " + sheetName);
63 ExcelParser.path =
file;
64 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(
file);
65 if (!sourceData.
ImportData(sheet, fileNameWithoutExtension, overwrite:
true))
67 throw new SourceParseException(
"#source failed to import data " + sourceData.GetType().Name +
":" + fileNameWithoutExtension +
"/" + sheetName);
70 int num =
ERROR.
msg.Split(
'/')[^1].ToInt();
76 return (sourceData,
item);
80 Debug.LogError(
$"#source failed to load sheet {sheetName}\n{arg}");
85 public IEnumerable<SourceData>
ImportFilesCached(IEnumerable<string> imports,
bool resetData =
true)
87 SourceCache[] array = imports.Select(SourceCache.GetOrCreate).Distinct().ToArray();
88 Dictionary<SourceCache, (string, ISheet[], ISheet)> dictionary = (from c in array
89 where c.IsDirtyOrEmpty
90 select
PrefetchWorkbook(c.SheetFile.FullName)).ToArray().ToDictionary(((
string file, ISheet[]
sheets, ISheet element) p) => SourceCache.GetOrCreate(p.file));
92 HashSet<SourceData> hashSet =
new HashSet<SourceData> { elements };
93 SourceCache[] array2 = array;
94 foreach (SourceCache sourceCache
in array2)
96 string arg = sourceCache.SheetFile.ShortPath();
97 if (
fileProviders.TryGetValue(sourceCache.SheetFile.FullName, out var value))
99 sourceCache.SetMod(value);
102 if (sourceCache.IsDirtyOrEmpty)
104 if (dictionary.TryGetValue(sourceCache, out var value2) && value2.Item3 !=
null)
107 sourceCache.EmplaceCache(
"Element",
item);
108 value?.sourceRows.UnionWith(
item);
109 Debug.Log(
string.Format(
"#source workbook {0}:{1}:{2}", arg,
"Element",
item.Length));
112 else if (sourceCache.TryGetCache(
"Element", out rows))
114 int num = elements.ImportRows(rows);
115 value?.sourceRows.UnionWith(rows);
116 Debug.Log(
string.Format(
"#source workbook-cache {0}:{1}:{2}", arg,
"Element", num));
120 foreach (SourceCache sourceCache2
in array2)
122 string text = sourceCache2.SheetFile.ShortPath();
123 if (sourceCache2.IsDirtyOrEmpty)
125 if (!dictionary.TryGetValue(sourceCache2, out var value3) || value3.Item2.Length == 0)
129 Debug.Log(
"#source workbook " + text);
130 ISheet[] item2 = value3.Item2;
131 foreach (ISheet sheet
in item2)
133 if (sheet.SheetName ==
"Element")
138 if ((
object)sourceData !=
null)
140 int? num2 = array3?.Length;
141 if (num2.HasValue && num2.GetValueOrDefault() > 0)
143 sourceCache2.EmplaceCache(sheet.SheetName, array3);
144 sourceCache2.Mod?.sourceRows.UnionWith(array3);
145 hashSet.Add(sourceData);
151 foreach (KeyValuePair<
string,
SourceData.
BaseRow[]> item3 in sourceCache2.Source)
153 item3.Deconstruct(out var key, out var value4);
159 if (sourceData2 is
SourceElement || (
object)sourceData2 ==
null)
170 Debug.Log(
"#source cached rows are empty " + text +
":" + text2);
174 sourceCache2.Mod?.sourceRows.UnionWith(array4);
175 Debug.Log(
$"#source workbook-cache {text}:{text2}:{num3}");
176 hashSet.Add(sourceData2);
186 public static void HotInit(IEnumerable<SourceData> sourceData)
188 Debug.Log(
"#source resetting data...");
189 foreach (
SourceData sourceDatum
in sourceData)
196 catch (Exception arg)
198 Debug.LogError(
$"#source failed to reset dirty data {sourceDatum.GetType().Name}\n{arg}");
201 Debug.Log(
"#source initialized data");
206 using FileStream @is = File.Open(
file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
207 XSSFWorkbook xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
208 List<ISheet> list =
new List<ISheet>();
210 for (
int i = 0; i < xSSFWorkbook.NumberOfSheets; i++)
212 ISheet sheetAt = xSSFWorkbook.GetSheetAt(i);
216 if ((
object)sourceData !=
null)
226 Debug.Log(
"#source workbook-prefetch " +
file.ShortPath());
static SourceManager sources
override bool ImportData(ISheet sheet, string bookname, bool overwrite=false)
override int ImportRows(IEnumerable< BaseRow > sourceRows)
string ISheet[] ISheet element PrefetchWorkbook(string file)
IEnumerable< SourceData > ImportFilesCached(IEnumerable< string > imports, bool resetData=true)
static void HotInit(IEnumerable< SourceData > sourceData)
Dictionary< string, EMod > fileProviders
SourceImporter(IReadOnlyDictionary< string, SourceData > sourceMapping)
SourceData FindSourceByName(string name)
readonly IReadOnlyDictionary< string, SourceData > _sourceMapping
SourceData.BaseRow[] LoadBySheetName(ISheet sheet, string file)