|
@@ -10,29 +10,25 @@ using System.Text;
|
|
|
|
|
|
namespace FlutterCodeGenerator.Helper
|
|
namespace FlutterCodeGenerator.Helper
|
|
{
|
|
{
|
|
- public class CodeGenerator
|
|
|
|
|
|
+ public class CodeGeneratorForWing
|
|
{
|
|
{
|
|
- private readonly string _generatedFolderPath;
|
|
|
|
|
|
+ private const string WingDllName = "WingInterfaceLibrary.dll";
|
|
|
|
+ private const string FlyinsonoFolder = "fis_lib_jsonrpc";
|
|
|
|
+
|
|
|
|
+ private readonly string _generatedFolderPathForFlyinsono;
|
|
private readonly string _dllPath;
|
|
private readonly string _dllPath;
|
|
private readonly string _rpcTextPath;
|
|
private readonly string _rpcTextPath;
|
|
private readonly string _serviceFolderPath;
|
|
private readonly string _serviceFolderPath;
|
|
- private const string _dllName = "WingInterfaceLibrary.dll";
|
|
|
|
- private readonly string _indexDart = "index.dart";
|
|
|
|
- private readonly string _rpcDart = "rpc.dart";
|
|
|
|
- private Dictionary<string, IServiceMap> _serviceMapDictionary;
|
|
|
|
- private List<string> _generatedServiceFileNameList;
|
|
|
|
- private List<string> _generatedServiceModelFileNameList;
|
|
|
|
-
|
|
|
|
- public static readonly string StringDartCore = "import 'dart:core';";
|
|
|
|
- public static readonly string StringClientBase = "import 'package:fis_jsonrpc/client_base.dart';";
|
|
|
|
- public static readonly string StringJsonConvert = "import 'package:fis_common/json_convert.dart';";
|
|
|
|
- public static readonly string StringUtils = "import 'package:fis_jsonrpc/utils.dart';";
|
|
|
|
|
|
+ private readonly Dictionary<string, IServiceMap> _serviceMapDictionary;
|
|
|
|
+ private readonly List<string> _generatedServiceFileNameList;
|
|
|
|
+ private readonly List<string> _generatedServiceModelFileNameList;
|
|
|
|
|
|
- public CodeGenerator(string dllPath, string filePath)
|
|
|
|
|
|
+ public CodeGeneratorForWing(string dllPath, string filePath)
|
|
{
|
|
{
|
|
- _generatedFolderPath = filePath;
|
|
|
|
|
|
+ GenerateDataCache.Instance.CurrentGenerator = EnumCodeGenerator.Wing.ToString();
|
|
|
|
+ _generatedFolderPathForFlyinsono = Path.Combine(filePath, FlyinsonoFolder);
|
|
_dllPath = dllPath;
|
|
_dllPath = dllPath;
|
|
- _serviceFolderPath = Path.Combine(_generatedFolderPath, "services");
|
|
|
|
|
|
+ _serviceFolderPath = Path.Combine(_generatedFolderPathForFlyinsono, "services");
|
|
_rpcTextPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "rpc.txt");
|
|
_rpcTextPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "rpc.txt");
|
|
_serviceMapDictionary = new Dictionary<string, IServiceMap>();
|
|
_serviceMapDictionary = new Dictionary<string, IServiceMap>();
|
|
_generatedServiceFileNameList = new List<string>() { "platform.dart" };
|
|
_generatedServiceFileNameList = new List<string>() { "platform.dart" };
|
|
@@ -43,10 +39,10 @@ namespace FlutterCodeGenerator.Helper
|
|
|
|
|
|
private void LoadDll()
|
|
private void LoadDll()
|
|
{
|
|
{
|
|
- var dll = Directory.GetFiles(_dllPath, _dllName).FirstOrDefault();
|
|
|
|
|
|
+ var dll = Directory.GetFiles(_dllPath, WingDllName).FirstOrDefault();
|
|
if (dll == null)
|
|
if (dll == null)
|
|
{
|
|
{
|
|
- throw new Exception($"The {_dllName} is not found!");
|
|
|
|
|
|
+ throw new DllNotFoundException($"The {WingDllName} is not found!");
|
|
}
|
|
}
|
|
var assemblybytes = File.ReadAllBytes(dll);
|
|
var assemblybytes = File.ReadAllBytes(dll);
|
|
var assembly = Assembly.Load(assemblybytes);
|
|
var assembly = Assembly.Load(assemblybytes);
|
|
@@ -68,7 +64,7 @@ namespace FlutterCodeGenerator.Helper
|
|
foreach (var interfaceType in interfaceTypes)
|
|
foreach (var interfaceType in interfaceTypes)
|
|
{
|
|
{
|
|
var sericeName = interfaceType.Name[1..];
|
|
var sericeName = interfaceType.Name[1..];
|
|
- var serviceMap = new ServiceMap(interfaceType);
|
|
|
|
|
|
+ var serviceMap = new ServiceMap(interfaceType, null);
|
|
_serviceMapDictionary.Add(LetterConverterHelper.FirstCharToLower(sericeName), serviceMap);
|
|
_serviceMapDictionary.Add(LetterConverterHelper.FirstCharToLower(sericeName), serviceMap);
|
|
}
|
|
}
|
|
var otherServiceMap = new OtherServiceMap(restNeedGeneratedTypes);
|
|
var otherServiceMap = new OtherServiceMap(restNeedGeneratedTypes);
|
|
@@ -77,11 +73,11 @@ namespace FlutterCodeGenerator.Helper
|
|
|
|
|
|
private void CheckDirectory()
|
|
private void CheckDirectory()
|
|
{
|
|
{
|
|
- if (Directory.Exists(_generatedFolderPath))
|
|
|
|
|
|
+ if (Directory.Exists(_generatedFolderPathForFlyinsono))
|
|
{
|
|
{
|
|
- Directory.Delete(_generatedFolderPath, true);
|
|
|
|
|
|
+ Directory.Delete(_generatedFolderPathForFlyinsono, true);
|
|
}
|
|
}
|
|
- Directory.CreateDirectory(_generatedFolderPath);
|
|
|
|
|
|
+ Directory.CreateDirectory(_generatedFolderPathForFlyinsono);
|
|
Directory.CreateDirectory(_serviceFolderPath);
|
|
Directory.CreateDirectory(_serviceFolderPath);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -100,12 +96,12 @@ namespace FlutterCodeGenerator.Helper
|
|
if (serviceMap.Value is ServiceMap)
|
|
if (serviceMap.Value is ServiceMap)
|
|
{
|
|
{
|
|
var serviceDartString = new StringBuilder();
|
|
var serviceDartString = new StringBuilder();
|
|
- serviceDartString.AppendLine(StringDartCore);
|
|
|
|
|
|
+ serviceDartString.AppendLine(CommonParameters.StringDartCore);
|
|
serviceDartString.AppendLine();
|
|
serviceDartString.AppendLine();
|
|
- serviceDartString.AppendLine(StringClientBase);
|
|
|
|
|
|
+ serviceDartString.AppendLine(CommonParameters.StringClientBase);
|
|
if (serviceString.Contains("FJsonConvert"))
|
|
if (serviceString.Contains("FJsonConvert"))
|
|
{
|
|
{
|
|
- serviceDartString.AppendLine(StringJsonConvert);
|
|
|
|
|
|
+ serviceDartString.AppendLine(CommonParameters.StringJsonConvert);
|
|
}
|
|
}
|
|
serviceDartString.AppendLine();
|
|
serviceDartString.AppendLine();
|
|
if (serviceModelDartString != null)
|
|
if (serviceModelDartString != null)
|
|
@@ -152,7 +148,7 @@ namespace FlutterCodeGenerator.Helper
|
|
private void GenerateRpcDart()
|
|
private void GenerateRpcDart()
|
|
{
|
|
{
|
|
var dartString = new StringBuilder();
|
|
var dartString = new StringBuilder();
|
|
- var rpcFilePath = Path.Combine(_generatedFolderPath, _rpcDart);
|
|
|
|
|
|
+ var rpcFilePath = Path.Combine(_generatedFolderPathForFlyinsono, CommonParameters.RpcDart);
|
|
var rpcString = File.ReadAllText(_rpcTextPath);
|
|
var rpcString = File.ReadAllText(_rpcTextPath);
|
|
var tempStringArray = rpcString.Split("*******Separator******");
|
|
var tempStringArray = rpcString.Split("*******Separator******");
|
|
if (tempStringArray.Length != 2)
|
|
if (tempStringArray.Length != 2)
|
|
@@ -179,7 +175,7 @@ namespace FlutterCodeGenerator.Helper
|
|
private void GenerateIndexDart()
|
|
private void GenerateIndexDart()
|
|
{
|
|
{
|
|
var dartString = new StringBuilder();
|
|
var dartString = new StringBuilder();
|
|
- var indexFilePath = Path.Combine(_serviceFolderPath, _indexDart);
|
|
|
|
|
|
+ var indexFilePath = Path.Combine(_serviceFolderPath, CommonParameters.IndexDart);
|
|
|
|
|
|
foreach (var fileName in _generatedServiceFileNameList.OrderBy(x => x))
|
|
foreach (var fileName in _generatedServiceFileNameList.OrderBy(x => x))
|
|
{
|
|
{
|