main
walon 2021-10-12 14:08:18 +08:00
parent 1dc7e0b84f
commit 48c2ce74b7
5 changed files with 109 additions and 100 deletions

View File

@ -37,14 +37,14 @@ namespace LubanAssistant
{ {
this.tab1 = this.Factory.CreateRibbonTab(); this.tab1 = this.Factory.CreateRibbonTab();
this.group3 = this.Factory.CreateRibbonGroup(); this.group3 = this.Factory.CreateRibbonGroup();
this.group1 = this.Factory.CreateRibbonGroup();
this.group2 = this.Factory.CreateRibbonGroup();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SetRootFile = this.Factory.CreateRibbonButton(); this.SetRootFile = this.Factory.CreateRibbonButton();
this.load = this.Factory.CreateRibbonButton(); this.load = this.Factory.CreateRibbonButton();
this.group1 = this.Factory.CreateRibbonGroup();
this.reloadData = this.Factory.CreateRibbonButton();
this.group2 = this.Factory.CreateRibbonGroup();
this.saveAll = this.Factory.CreateRibbonButton(); this.saveAll = this.Factory.CreateRibbonButton();
this.saveSelected = this.Factory.CreateRibbonButton(); this.saveSelected = this.Factory.CreateRibbonButton();
this.reloadData = this.Factory.CreateRibbonButton(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.tab1.SuspendLayout(); this.tab1.SuspendLayout();
this.group3.SuspendLayout(); this.group3.SuspendLayout();
this.group1.SuspendLayout(); this.group1.SuspendLayout();
@ -63,24 +63,9 @@ namespace LubanAssistant
// group3 // group3
// //
this.group3.Items.Add(this.SetRootFile); this.group3.Items.Add(this.SetRootFile);
this.group3.Items.Add(this.load);
this.group3.Name = "group3"; this.group3.Name = "group3";
// //
// group1
//
this.group1.Items.Add(this.load);
this.group1.Items.Add(this.reloadData);
this.group1.Name = "group1";
//
// group2
//
this.group2.Items.Add(this.saveAll);
this.group2.Items.Add(this.saveSelected);
this.group2.Name = "group2";
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// SetRootFile // SetRootFile
// //
this.SetRootFile.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge; this.SetRootFile.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
@ -92,10 +77,30 @@ namespace LubanAssistant
// load // load
// //
this.load.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge; this.load.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.load.Label = "加载数据表"; this.load.Label = "设置配置根目录";
this.load.Name = "load"; this.load.Name = "load";
this.load.ScreenTip = "--input_data_dir 中指定的根目录而不是当前配置表的input属性指定目录";
this.load.ShowImage = true; this.load.ShowImage = true;
this.load.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnLoadClick); this.load.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnChooseDataDirClick);
//
// group1
//
this.group1.Items.Add(this.reloadData);
this.group1.Name = "group1";
//
// reloadData
//
this.reloadData.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.reloadData.Label = "加载数据";
this.reloadData.Name = "reloadData";
this.reloadData.ShowImage = true;
this.reloadData.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnLoadDataClick);
//
// group2
//
this.group2.Items.Add(this.saveAll);
this.group2.Items.Add(this.saveSelected);
this.group2.Name = "group2";
// //
// saveAll // saveAll
// //
@ -113,12 +118,9 @@ namespace LubanAssistant
this.saveSelected.ShowImage = true; this.saveSelected.ShowImage = true;
this.saveSelected.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnSaveSelectedClick); this.saveSelected.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnSaveSelectedClick);
// //
// reloadData // openFileDialog1
// //
this.reloadData.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge; this.openFileDialog1.FileName = "openFileDialog1";
this.reloadData.Label = "重新加载";
this.reloadData.Name = "reloadData";
this.reloadData.ShowImage = true;
// //
// AssistantTab // AssistantTab
// //

View File

@ -26,7 +26,15 @@ namespace LubanAssistant
} }
} }
public string DataDir { get; set; } public string InputDataDir
{
get => Properties.Settings.Default.dataDir;
set
{
Properties.Settings.Default.dataDir = value;
Properties.Settings.Default.Save();
}
}
private void AssistantTab_Load(object sender, RibbonUIEventArgs e) private void AssistantTab_Load(object sender, RibbonUIEventArgs e)
{ {
@ -85,20 +93,11 @@ namespace LubanAssistant
} }
} }
private void BtnLoadClick(object sender, RibbonControlEventArgs e) private void BtnChooseDataDirClick(object sender, RibbonControlEventArgs e)
{ {
if (!HasSetRootDefineFile())
{
MessageBox.Show("请先设置Root定义文件");
return;
}
if (TryChooseInputDataDir(out var dataDir)) if (TryChooseInputDataDir(out var dataDir))
{ {
DataDir = dataDir; InputDataDir = dataDir;
if (PromptIgnoreNotSaveData())
{
LoadDataToCurrentDoc();
}
} }
} }
@ -108,34 +107,26 @@ namespace LubanAssistant
return true; return true;
} }
private async Task LoadDataToCurrentDoc() private void LoadDataToCurrentDoc()
{ {
MessageBox.Show($"从目录:{DataDir} 加载数据");
if (!TryGetTableName(out var tableName)) if (!TryGetTableName(out var tableName))
{ {
MessageBox.Show($"meta行未指定table名"); MessageBox.Show($"meta行未指定table名");
return; return;
} }
string inputDataDir = DataDir; Task.Run(async () =>
{
try
{
await LoadUtil.LoadDataToCurrentDoc(RootDefineFile, InputDataDir, tableName);
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace, e.Message);
}
});
IAgent agent = new LocalAgent();
var loader = new CfgDefLoader(agent);
await loader.LoadAsync(RootDefineFile);
var rawDefines = loader.BuildDefines();
TimeZoneInfo timeZoneInfo = null;
var excludeTags = new List<string>();
var ass = new DefAssembly("", timeZoneInfo, excludeTags, agent);
ass.Load(rawDefines);
DefAssemblyBase.LocalAssebmly = ass;
var table = ass.GetCfgTable(tableName);
await DataLoaderUtil.LoadTableAsync(agent, table, inputDataDir, "", "");
} }
private bool PromptIgnoreNotSaveData() private bool PromptIgnoreNotSaveData()
@ -155,9 +146,14 @@ namespace LubanAssistant
return true; return true;
} }
private void BtnReloadClick(object sender, RibbonControlEventArgs e) private void BtnLoadDataClick(object sender, RibbonControlEventArgs e)
{ {
if (!Directory.Exists(DataDir)) if (!HasSetRootDefineFile())
{
MessageBox.Show("未设置root定义文件");
return;
}
if (!Directory.Exists(InputDataDir))
{ {
MessageBox.Show("未设置加载目录"); MessageBox.Show("未设置加载目录");
return; return;

View File

@ -0,0 +1,46 @@
using Bright.Common;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.Utils;
using Luban.Job.Common.Defs;
using Luban.Server.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LubanAssistant
{
static class LoadUtil
{
public static async Task LoadDataToCurrentDoc(string rootDefineFile, string inputDataDir, string tableName)
{
IAgent agent = new LocalAgent();
var loader = new CfgDefLoader(agent);
await loader.LoadAsync(rootDefineFile);
var rawDefines = loader.BuildDefines();
TimeZoneInfo timeZoneInfo = null;
var excludeTags = new List<string>();
var ass = new DefAssembly("", timeZoneInfo, excludeTags, agent);
ass.Load(rawDefines);
DefAssemblyBase.LocalAssebmly = ass;
var table = ass.GetCfgTable(tableName);
if (table == null)
{
throw new Exception($"table:{tableName}不存在");
}
await DataLoaderUtil.LoadTableAsync(agent, table, inputDataDir, "", "");
var datas = ass.GetTableAllDataList(table);
MessageBox.Show($"table:{table.FullName} input:{StringUtil.CollectionToString(table.InputFiles)} record num:{datas.Count}");
}
}
}

View File

@ -538,6 +538,7 @@
<Compile Include="AssistantTab.Designer.cs"> <Compile Include="AssistantTab.Designer.cs">
<DependentUpon>AssistantTab.cs</DependentUpon> <DependentUpon>AssistantTab.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="LoadUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@ -34,8 +34,6 @@ namespace Luban.Job.Cfg.Defs
public new static DefAssembly LocalAssebmly { get => (DefAssembly)DefAssemblyBase.LocalAssebmly; set => DefAssemblyBase.LocalAssebmly = value; } public new static DefAssembly LocalAssebmly { get => (DefAssembly)DefAssemblyBase.LocalAssebmly; set => DefAssemblyBase.LocalAssebmly = value; }
public Service CfgTargetService { get; private set; }
private readonly string _patchName; private readonly string _patchName;
private readonly List<string> _excludeTags; private readonly List<string> _excludeTags;
@ -53,11 +51,7 @@ namespace Luban.Job.Cfg.Defs
public bool NeedExport(List<string> groups) public bool NeedExport(List<string> groups)
{ {
if (groups.Count == 0) return true;
{
return true;
}
return groups.Any(g => CfgTargetService.Groups.Contains(g));
} }
private readonly List<Patch> _patches = new List<Patch>(); private readonly List<Patch> _patches = new List<Patch>();
@ -124,44 +118,14 @@ namespace Luban.Job.Cfg.Defs
return Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList(); return Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList();
} }
public List<DefTypeBase> GetExportTypes()
{
var refTypes = new Dictionary<string, DefTypeBase>();
var targetService = CfgTargetService;
foreach (var refType in targetService.Refs)
{
if (!this.Types.ContainsKey(refType))
{
throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 类型不存在");
}
if (!refTypes.TryAdd(refType, this.Types[refType]))
{
throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 重复引用");
}
}
foreach (var e in this.Types)
{
if (!refTypes.ContainsKey(e.Key) && (e.Value is DefEnum))
{
refTypes.Add(e.Key, e.Value);
}
}
foreach (var table in GetExportTables())
{
refTypes[table.FullName] = table;
table.ValueTType.Apply(RefTypeVisitor.Ins, refTypes);
}
return refTypes.Values.ToList();
}
public void Load(Defines defines) public void Load(Defines defines)
{ {
SupportDatetimeType = true; SupportDatetimeType = true;
TopModule = defines.TopModule; TopModule = defines.TopModule;
this._patches.AddRange(defines.Patches);
foreach (var e in defines.Enums) foreach (var e in defines.Enums)
{ {
AddType(new DefEnum(e)); AddType(new DefEnum(e));