123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using FlutterCodeGenerator.Helper;
- using FlutterCodeGenerator.Map.Interface;
- using FlutterCodeGenerator.Model;
- using FlutterCodeGenerator.ModelTypes;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace FlutterCodeGenerator.Map
- {
- internal class OtherServiceMap : IServiceMap
- {
- private List<Type> _typeList;
- public string ServiceName { get; private set; }
- public List<ComplexModelType> UsedComplexModelTypeList { get; }
- public OtherServiceMap(List<Type> types)
- {
- ServiceName = "OtherService";
- _typeList = types;
- UsedComplexModelTypeList = new List<ComplexModelType>();
- GenerateDataCache.Instance.SetCurrentServiceMap(this);
- foreach (var type in _typeList)
- {
- try
- {
- var parameterModelType = ModelTypeGenerator.Create(type, type.Name, true);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Type is {type.FullName},Error:{ex}");
- throw;
- }
- }
- }
- public string GetServiceDartString()
- {
- return null;
- }
- public string GetServiceModelDartString()
- {
- var dartString = new StringBuilder();
- var importServiceList = new List<string>();
- var alreadyGeneratedList = GenerateDataCache.Instance.AlreadyGeneratedList;
- foreach (var modelType in UsedComplexModelTypeList)
- {
- if (!alreadyGeneratedList.Any(x => x.Key.ParameterType.Name == modelType.ParameterType.Name && x.Key.ParameterType.Namespace == modelType.ParameterType.Namespace))
- {
- if (modelType is EnumModelType enumModelType)
- {
- if (enumModelType.UserDefinedEnumDictionary.Any(x => x.Key >= 1000))
- {
- continue;
- }
- else
- {
- alreadyGeneratedList.Add(modelType, ServiceName);
- dartString.AppendLine(modelType.GetDartString());
- }
- }
- else
- {
- alreadyGeneratedList.Add(modelType, ServiceName);
- dartString.AppendLine(modelType.GetDartString());
- }
- }
- else
- {
- var importService = alreadyGeneratedList.FirstOrDefault(x => x.Key.ParameterType.Name == modelType.ParameterType.Name && x.Key.ParameterType.Namespace == modelType.ParameterType.Namespace).Value;
- if (importService == null)
- {
- throw new Exception("Import Service is null");
- }
- if (importService != ServiceName && !importServiceList.Contains(importService))
- {
- importServiceList.Add(importService);
- }
- }
- }
- if (string.IsNullOrWhiteSpace(dartString.ToString()))
- {
- return null;
- }
- var serviceModelDartString = new StringBuilder();
- foreach (var importService in importServiceList)
- {
- serviceModelDartString.AppendLine($"import '{LetterConverterHelper.FirstCharToLower(importService[0..^7])}.m.dart';");
- }
- if (importServiceList.Count > 0)
- {
- serviceModelDartString.AppendLine();
- }
- var dartStringInfo = dartString.ToString();
- if (dartStringInfo.Contains("JsonRpcUtils"))
- {
- serviceModelDartString.AppendLine(CommonParameters.StringUtils);
- serviceModelDartString.AppendLine();
- }
- if (dartStringInfo.Contains("FJsonConvert"))
- {
- serviceModelDartString.AppendLine(CommonParameters.StringJsonConvert);
- serviceModelDartString.AppendLine();
- }
- serviceModelDartString.AppendLine(dartStringInfo);
- return serviceModelDartString.ToString();
- }
- }
- }
|