public Catch(DartType guard, Option <VariableDeclaration> exception, Option <VariableDeclaration> stackTrace, Statement body) { this.guard = guard; this.exception = exception; this.stackTrace = stackTrace; this.body = body; }
public TypeParameter(Flag flags, List <Expression> annotations, StringReference name, DartType bound, Option <DartType> defaultType) { this.flags = flags; this.annotations = annotations; this.name = name; this.bound = bound; this.defaultType = defaultType; }
public Catch(ComponentReader reader) { fileOffset = new FileOffset(reader); guard = reader.ReadDartType(); exception = reader.ReadOption(r => new VariableDeclaration(r)); stackTrace = reader.ReadOption(r => new VariableDeclaration(r)); body = reader.ReadStatement(); }
/// <summary> /// 请求镖车位置 /// </summary> public void C2S_ReqDartPos(DartType type) { //Debug.Log("C2S_ReqDartPos activityType:"+type); pt_req_cart_pos_d613 msg = new pt_req_cart_pos_d613(); msg.type = (byte)(int)type; NetMsgMng.SendMsg(msg); }
public readonly Option <DartType> defaultType; // type used when the parameter is not passed public TypeParameter(ComponentReader reader) { flags = (Flag)reader.ReadByte(); annotations = reader.ReadList(r => r.ReadExpression()); name = new StringReference(reader); bound = reader.ReadDartType(); defaultType = reader.ReadOption(r => r.ReadDartType()); }
/// <summary> /// 开始运镖,type青铜1、白银2、黄金3 /// </summary> public void C2S_StartDart(int type, DartType activityType) { //Debug.Log("C2S_StartDart type:"+type+",activityType:"+activityType); pt_req_start_cart_escort_d612 msg = new pt_req_start_cart_escort_d612(); msg.cart_type = (byte)type; msg.type = (byte)(int)activityType; NetMsgMng.SendMsg(msg); }
public Field(CanonicalNameReference canonicalName, Flag flags, Name name, List <Expression> annotations, DartType type, Option <Expression> initializer) { this.canonicalName = canonicalName; this.flags = flags; this.name = name; this.annotations = annotations; this.type = type; this.initializer = initializer; }
public ExtendedProperty(string uid, KeyValuePair <string, JToken> keyValuePair, int depth) { //this.depth = depth; this.Uid = uid + "_" + keyValuePair.Key; this.KeyValuePair = keyValuePair; UpdateNameByNamingConventionsType(); this.type = DartHelper.ConverDartType(keyValuePair.Value.Type); PropertyAccessorType = ConfigHelper.Instance.Config.PropertyAccessorType; }
// Equivalent to a FunctionType with no type parameters or named parameters, // and where all positional parameters are required. public SimpleFunctionType(ComponentReader reader) { positionalParameters = reader.ReadList(r => r.ReadDartType()); // https://github.com/dart-lang/sdk/blob/master/pkg/kernel/lib/binary/ast_from_binary.dart#L1889 // MISSING! // positionalParameterNames = reader.ReadList(r => new StringReference(r)); // Console.WriteLine(string.Join(", ", positionalParameterNames.Select(n => reader.GetString(n.index)))); returnType = reader.ReadDartType(); }
public FunctionType(List <TypeParameter> typeParameters, uint requiredParameterCount, uint totalParameterCount, List <DartType> positionalParameters, List <NamedDartType> namedParameters, CanonicalNameReference typedefReference, DartType returnType) { this.typeParameters = typeParameters; this.requiredParameterCount = requiredParameterCount; this.totalParameterCount = totalParameterCount; this.positionalParameters = positionalParameters; this.namedParameters = namedParameters; this.typedefReference = typedefReference; this.returnType = returnType; }
public Field(CanonicalNameReference canonicalName, UriReference fileUri, FileOffset fileOffset, FileOffset fileEndOffset, Flag flags, Name name, List <Expression> annotations, DartType type, Option <Expression> initializer) { this.canonicalName = canonicalName; this.fileUri = fileUri; this.fileOffset = fileOffset; this.fileEndOffset = fileEndOffset; this.flags = flags; this.name = name; this.annotations = annotations; this.type = type; this.initializer = initializer; }
public Field(ComponentReader reader) { reader.CheckTag(Tag); canonicalName = new CanonicalNameReference(reader); fileUri = new UriReference(reader); fileOffset = new FileOffset(reader); fileEndOffset = new FileOffset(reader); flags = (Flag)reader.ReadByte(); name = new Name(reader); annotations = reader.ReadList(r => r.ReadExpression()); type = reader.ReadDartType(); initializer = reader.ReadOption(r => r.ReadExpression()); }
public FunctionType(ComponentReader reader) { typeParameters = reader.ReadList(r => new TypeParameter(r)); requiredParameterCount = reader.ReadUint(); totalParameterCount = reader.ReadUint(); positionalParameters = reader.ReadList(r => r.ReadDartType()); namedParameters = reader.ReadList(r => new NamedDartType(r)); // #v12: CanonicalNameReference typedefReference; // #v12+: Option<TypedefType> typedef; typedefReference = new CanonicalNameReference(reader); //typedef = reader.ReadOption(r => new TypedefType(r)); returnType = reader.ReadDartType(); }
public static String GetDartTypeString(DartType dartType) { switch (dartType) { case DartType.String: return "String"; case DartType.Int: return "int"; case DartType.Object: return "Object"; case DartType.Bool: return "bool"; case DartType.Double: return "double"; default: return ""; } }
public static String GetDartTypeString(DartType dartType) { switch (dartType) { case DartType.String: return("String"); case DartType.Int: return("int"); case DartType.Object: return("Object"); case DartType.Bool: return("bool"); case DartType.Double: return("double"); default: return(""); } }
public SimpleFunctionType(List <DartType> positionalParameters, DartType returnType) { this.positionalParameters = positionalParameters; this.returnType = returnType; }
public static void Build(Assembly assembly, string outputDir, string packageName, string packageDescription = null, bool verbose = false) { // NOTE: Parameters have been already validated! if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } // Load or create Flutter package if it doesn't already exist DartProject dartProject = InitializePackage(outputDir, packageName, packageDescription, verbose); // Configure and resolve package dependencies ConfigurePackageDependencies(dartProject, verbose); // Delete all the "testing" project files dartProject.TestFolder.Clear(); string dartPackageName = dartProject.Name; Console.WriteLine("Parsing .NET assembly..."); // Load all the assembly types: this call the assembly resolver. ICollection <Type> protocolTypes; try { protocolTypes = assembly.GetExportedTypes(); } catch (Exception ex) { string error = $"Error loading the assembly. Verify that your .NET project not reference some native library.\nDetails: {ex.Message}"; throw new Exception(error); } //------------------------------------------------------------------------------------- // Load all classes that need to be exported in Dart and check if everything is valid //------------------------------------------------------------------------------------- // Force to add this exception type export //ICollection<Type> flutterEx = new List<Type>() { typeof(flutnet.sdk.FlutterException), typeof(flutnet.sdk.FlutterRunException) }; // Base SDK types ICollection <Type> flutnetSdkTypes = new List <Type>() { typeof(PlatformOperationException), typeof(FlutnetException), }; ICollection <Type> sysDataTypes = new List <Type>() { typeof(FlutnetErrorCode), typeof(EventArgs), }; protocolTypes = protocolTypes.Concat(flutnetSdkTypes).Concat(sysDataTypes).Distinct().ToList(); // Exception types ICollection <Type> exceptionTypes = protocolTypes.Where(t => t.IsValidPlatformOperationException()).ToList(); // Find out if some exception have some decoration: invalid!!! ICollection <Type> decoratedExceptions = exceptionTypes.Where(t => t.GetCustomAttributes(typeof(PlatformDataAttribute), true).Length > 0 || t.GetCustomAttributes(typeof(PlatformServiceAttribute), true).Length > 0).ToList(); if (decoratedExceptions.Any()) { string errorMessage = string.Join("\n", decoratedExceptions.Select(t => $"The type {t.FullName} is a {typeof(PlatformOperationException).Name}: cannot be decorated with annotations.").ToArray()); throw new Exception(errorMessage); } List <Type> referencedTypesFromException = new List <Type>(); foreach (Type type in exceptionTypes) { // Extract all the property types for each class List <Type> properties = DartSupport.GetAllReferencedTypes(type, protocolTypes).ToList(); referencedTypesFromException.AddRange(properties.Where(p => p.IsValidPlatformOperationException() == false)); } // Verify that not exists classes with both decorations [FlutterData] and [FlutterService] ICollection <Type> multipleAttributeType = protocolTypes.Where(t => (t.IsClass || t.IsEnum || t.IsInterface) && t.GetCustomAttributes(typeof(PlatformDataAttribute), true).Length > 0 && t.GetCustomAttributes(typeof(PlatformServiceAttribute), true).Length > 0 ).ToList(); if (multipleAttributeType.Any()) { string errorMessage = string.Join("\n", multipleAttributeType.Select(t => $"The type {t.Name} cannot have both attribute {nameof(PlatformDataAttribute)} and {nameof(PlatformServiceAttribute)}").ToArray()); throw new Exception(errorMessage); } // Find all the classes marked as [FlutterData]: will be converted into Dart classes with FromJson and ToJson methods. ICollection <Type> dataTypes = protocolTypes.Where(t => sysDataTypes.Contains(t) || // To ensure the inclusion about FlutnetErrorCode & EventArgs ((t.IsClass || t.IsEnum) && t.GetCustomAttributes(typeof(PlatformDataAttribute), true).Length > 0) // user declared [PlatformData] ).ToList(); // Take in consideration even all the property/fields types included in this classes List <Type> referencedTypes = new List <Type>(); foreach (Type type in dataTypes) { // Extrac all the property types for each class List <Type> properties = DartSupport.GetAllReferencedTypes(type, protocolTypes).ToList(); referencedTypes.AddRange(properties); } // Add all the types referenced from FlutterData classes foreach (Type t in referencedTypes) { if (dataTypes.Contains(t) == false) { dataTypes.Add(t); } } // Add all the types referenced from some FlutterException class foreach (Type et in referencedTypesFromException) { if (dataTypes.Contains(et) == false) { dataTypes.Add(et); } } // Find all the classes or interface (even abstract) marked as [FlutterService]: all their method will be converted into Dart project. ICollection <Type> serviceTypes = protocolTypes .Where(t => t.IsValidPlatformService() && t.GetCustomAttributes(typeof(PlatformServiceAttribute), true).Length > 0) .ToArray(); // Map each service with all his methods and events Dictionary <Type, List <MethodInfo> > serviceToMethods = new Dictionary <Type, List <MethodInfo> >(); Dictionary <Type, List <EventInfo> > serviceToEvents = new Dictionary <Type, List <EventInfo> >(); // Take in consideration even all the types referenced by this methods(params and return types) -> will be considered as [FlutterData] List <Type> methodsTypes = new List <Type>(); List <Type> eventArgsTypes = new List <Type>(); foreach (Type service in serviceTypes) { #region Operations // Extract all the PUBLIC methods marked as "FlutterOperation" List <MethodInfo> flutterOperations = service.GetPlatformOperations().ToList(); serviceToMethods.Add(service, flutterOperations); // Check for each platform operation the return and params class types foreach (MethodInfo methodInfo in flutterOperations) { // Extract all the class properties Type returnType = DartReturnType.GetNestedType(methodInfo.ReturnType); if (returnType != typeof(void)) { List <Type> properties = DartSupport.GetAllReferencedTypes(returnType, protocolTypes).ToList(); methodsTypes.AddRange(properties); bool isCustom = protocolTypes.Contains(returnType); if (isCustom) { methodsTypes.Add(returnType); } } foreach (ParameterInfo paramInfo in methodInfo.GetParameters()) { List <Type> properties = DartSupport.GetAllReferencedTypes(paramInfo.ParameterType, protocolTypes).ToList(); methodsTypes.AddRange(properties); bool isCustom = protocolTypes.Contains(paramInfo.ParameterType); if (isCustom) { methodsTypes.Add(paramInfo.ParameterType); } } } #endregion #region Events // Exrract all the events marked as PlaftormEvent List <EventInfo> flutterEvents = service.GetPlatformEvents().ToList(); serviceToEvents.Add(service, flutterEvents); foreach (EventInfo e in flutterEvents) { // Get the associated EventArgs Type args = e.GetPlatformEventArgs(); eventArgsTypes.Add(args); List <Type> properties = DartSupport.GetAllReferencedTypes(args, protocolTypes).ToList(); eventArgsTypes.AddRange(properties); /* * if (args.BaseType == typeof(EventArgs)) // Extend EventArgs * { * * } * else if(args == typeof(EventArgs)) // Empty args * { * * }*/ } #endregion } // Add all the method types in the data types collection foreach (Type mt in methodsTypes) { if (dataTypes.Contains(mt) == false) { dataTypes.Add(mt); } } // Add all the events args type foreach (Type argsType in eventArgsTypes) { if (dataTypes.Contains(argsType) == false) { dataTypes.Add(argsType); } } // FlutterData dataTypes = dataTypes.Where(t => t.IsValidPlatformOperationException() == false).Distinct().ToList(); // Find all data typed NOT marked with decoration ICollection <Type> notMarkedDataTypes = dataTypes.Where(t => sysDataTypes.Contains(t) == false && // Skip check on system data type protocolTypes.Contains(t) && t.GetCustomAttributes(typeof(PlatformDataAttribute), true).Length <= 0).ToList(); if (notMarkedDataTypes.Any()) { string[] notMarkedTypeNames = notMarkedDataTypes.Select(t => $" - {t.FullName} not marked with [PlatformData] decoration.").ToArray(); string errorList = string.Join("\n", notMarkedTypeNames); throw new Exception($"Some types may need [PlatformData] decoration: \n{errorList}\n"); } // Verify that all the data types not extends somethings: // inheritance is not supported by the generator for flutter data. Type[] extendedDataTypes = dataTypes.Where(t => DartSupport.HaveInheritance(dataTypes, t)).ToArray(); // We enable PlatformData Inheritance: the base type must be PlatformData to (or NULL) Type[] platformDataSubtypes = extendedDataTypes.ToArray(); // PlatformData Super Types with no attribute Type[] invalidPlatformDataSuperTypes = platformDataSubtypes.Where(subT => subT.BaseType != null && !sysDataTypes.Contains(subT.BaseType) && // Skip system data type, like EventArgs subT.BaseType.GetCustomAttributes(typeof(PlatformDataAttribute), true).Length <= 0).ToArray(); if (invalidPlatformDataSuperTypes.Any()) { throw new FlutterInheritedDataException(invalidPlatformDataSuperTypes); } // Verify that all the classe marker with flutnet.sdk.FlutterData + FlutterException are compatible with Dart language // !!! NOTE: we check both FlutterData and FlutterException classes. Type[] invalidDataTypes = DartSupport.GetUnsupportedDartTypes(dataTypes.Concat(exceptionTypes).ToList()).ToArray(); if (invalidDataTypes.Any()) { throw new FlutterUnsupportedDartTypeException(invalidDataTypes); } // JOIN DATA + EXCEPTIONS + SERVICE ICollection <Type> allExportedTypes = dataTypes.Concat(exceptionTypes).Concat(serviceToMethods.Keys).ToList(); // Verificy that all the methods types (return and params) are supported in Dart List <Exception> errors = new List <Exception>(); foreach (var srv in serviceToMethods) { Type service = srv.Key; List <MethodInfo> methods = srv.Value; List <EventInfo> events = serviceToEvents.ContainsKey(srv.Key) ? serviceToEvents[srv.Key] : new List <EventInfo>(0); List <string> uniqueOperationNames = new List <string>(); // Find all unsupported flutter operation MethodInfo[] invalidMethods = service.GetUnsupportedPlatformOperations(); foreach (MethodInfo method in invalidMethods) { errors.Add(new Exception($"Invalid Method {method.Name}, for {service.Name}: cannot mark NON PUBLIC methods with {nameof(PlatformOperationAttribute)}.")); } // Check if the method is supported foreach (MethodInfo method in methods) { // Extract the method name: must be unique (Dart language NOT support Method Overloading) string operationName = DartSupport.GetDartMethodName(method.Name); if (uniqueOperationNames.Contains(operationName)) { errors.Add(new FlutterOperationException(service, method, operationName)); } uniqueOperationNames.Add(operationName); // Each method cannot have attributes with the same name, because Dart is NOT KEY SENSITIVE // Example: bool login( string Password, string password) ---> error! bool duplicatedParamName = method.GetParameters().Select(p => p.Name.ToUpper()).Distinct().Count() < method.GetParameters().Length; if (duplicatedParamName) { var duplicatedGroups = method.GetParameters().GroupBy( k => k.Name.ToUpper(), e => e.Name ); IEnumerable <string> duplicatedParams = duplicatedGroups.Select(g => $"Duplicated: {g.ToArray()}\n"); errors.Add(new Exception($"Invalid Method {method.Name}, for {service.Name}: params cannot have the same name (NOT KEY_SENSITIVE)!\n {duplicatedParams}")); } Type invalidReturnType = null; // Extract all the properties for the class Type returnType = DartReturnType.GetNestedType(method.ReturnType); if (returnType != typeof(void)) { if (DartSupport.IsSupportedByDart(returnType, allExportedTypes) == false) { invalidReturnType = method.ReturnType; } } List <ParameterInfo> invalidParameters = new List <ParameterInfo>(); foreach (ParameterInfo paramInfo in method.GetParameters()) { if (DartSupport.IsSupportedByDart(paramInfo.ParameterType, allExportedTypes) == false) { invalidParameters.Add(paramInfo); } } if (invalidReturnType != null || invalidParameters.Count > 0) { errors.Add(new FlutterOperationException(service, method, invalidParameters, invalidReturnType)); } } // Find all unsupported flutter operation EventInfo[] invalidEvents = service.GetUnsupportedPlatformEvents(); // Check if all events are supported foreach (EventInfo @event in invalidEvents) { errors.Add(new Exception($"Invalid Event {@event.Name}, for {service.Name}. [PlatformEvent] must be implemented using EventHandler or EventHandler<T> pattern!")); } } // Some methods to export in Dart (FlutterOperation) are not supported if (errors.Any()) { throw new MultipleException(errors); } // All the checks ended well // ---------------------------------------- // Convert all the C# Types in Dart types // ---------------------------------------- // Generate all the classes marked with [FlutterData] Dictionary <Type, DartType> dartDataTypes = new Dictionary <Type, DartType>(); foreach (Type type in dataTypes) { DartType dartType = new DartType(allExportedTypes, type, dartPackageName); dartDataTypes.Add(type, dartType); } // Generate all the classes marked with [FlutterService] Dictionary <Type, DartService> dartServiceTypes = new Dictionary <Type, DartService>(); foreach (KeyValuePair <Type, List <MethodInfo> > srv in serviceToMethods) { Type service = srv.Key; List <MethodInfo> methods = srv.Value; List <EventInfo> events = serviceToEvents.ContainsKey(srv.Key) ? serviceToEvents[srv.Key] : new List <EventInfo>(0); DartService dartService = new DartService(allExportedTypes, service, methods, events, dartPackageName, SignatureTools.GetCSharpSignature); dartServiceTypes.Add(service, dartService); } // Genenerate all the FlutterException hinerited classes Dictionary <Type, DartType> flutterExceptionTypes = new Dictionary <Type, DartType>(); foreach (Type type in exceptionTypes) { DartType dartType = new DartType(allExportedTypes, type, dartPackageName); flutterExceptionTypes.Add(type, dartType); } // Join all dart types for FlutterException and [FlutterData] ICollection <DartType> exportedDataAndExceptionType = dartDataTypes.Select(t => t.Value).Concat(flutterExceptionTypes.Select(e => e.Value)).ToList(); // --------------------------------------------------------- // Check the number of objects that will be generated // --------------------------------------------------------- // PlatformData Count int platformDataCount = dartDataTypes.Count - 1; // exclude internal PlatformErrorCode; // PlatformOperationException Count int platformOperationExceptionCount = flutterExceptionTypes.Count - 2; // exclude PlatformOperationException base class + internal FlutnetException // PlatformService Count int platformServiceCount = dartServiceTypes.Count; // PlatformOperation Count int platformOperationCount = dartServiceTypes.Values.Sum(s => s.Methods.Count); // PlatformEvent Count int platformEventCount = dartServiceTypes.Values.Sum(s => s.Events.Count); if (verbose) { Console.WriteLine($"Found {platformServiceCount} PlatformServices"); Console.WriteLine($"Found {platformOperationCount} PlatformOperations"); Console.WriteLine($"Found {platformEventCount} PlatformEvents"); Console.WriteLine($"Found {platformDataCount} PlatformData"); Console.WriteLine($"Found {platformOperationExceptionCount} PlatformOperationExceptions"); } // ---------------------------------------- // Delete all the files in the project "lib/" folder // ---------------------------------------- DirectoryInfo libDir = dartProject.LibFolder; libDir.Clear(); string libPath = Path.GetFullPath(libDir.FullName); // ---------------------------------------- // Start generating all the project files // ---------------------------------------- Console.WriteLine($"Start generating all the dart project files ...", verbose); // Generate all the Dart PlatformData classes foreach (DartType dartType in dartDataTypes.Values) { string filePath = DartSupport.GetDartFilePath(libPath, dartType); string folderPath = DartSupport.GetDartDirectoryPath(libPath, dartType); if (Directory.Exists(folderPath) == false) { Directory.CreateDirectory(folderPath); } DartGenerator.GenerateDartTypeFile(dartType, exportedDataAndExceptionType, filePath); } // Generate all the exception foreach (DartType dartType in flutterExceptionTypes.Values) { string filePath = DartSupport.GetDartFilePath(libPath, dartType); string folderPath = DartSupport.GetDartDirectoryPath(libPath, dartType); if (Directory.Exists(folderPath) == false) { Directory.CreateDirectory(folderPath); } DartGenerator.GenerateDartTypeFile(dartType, exportedDataAndExceptionType, filePath, skipCopyWith: true); } // For each FlutterService we generate: // - the service class // - all the FAKE classes that wrap RETURN and PARAMS for methods foreach (DartService dartSrv in dartServiceTypes.Values) { foreach (DartMethod method in dartSrv.Methods) { // Return Object generator string returnFilePath = DartSupport.GetDartFilePath(libPath, method.ReturnObj); string folderReturnFilePath = DartSupport.GetDartDirectoryPath(libPath, method.ReturnObj); if (Directory.Exists(folderReturnFilePath) == false) { Directory.CreateDirectory(folderReturnFilePath); } DartGenerator.GenerateDartTypeFile(method.ReturnObj, exportedDataAndExceptionType, returnFilePath, skipDynamicJson: true, skipCopyWith: true); // Param Object generator string paramFilePath = DartSupport.GetDartFilePath(libPath, method.ParamObj); string folderParamFilePath = DartSupport.GetDartDirectoryPath(libPath, method.ParamObj); if (Directory.Exists(folderParamFilePath) == false) { Directory.CreateDirectory(folderParamFilePath); } DartGenerator.GenerateDartTypeFile(method.ParamObj, exportedDataAndExceptionType, paramFilePath, skipDynamicJson: true, skipCopyWith: true); } // // Generate the service class // DartType dartType = dartSrv.Type; string filePath = DartSupport.GetDartFilePath(libPath, dartType); string folderPath = DartSupport.GetDartDirectoryPath(libPath, dartType); if (Directory.Exists(folderPath) == false) { Directory.CreateDirectory(folderPath); } DartGenerator.GenerateDartServiceFile(dartSrv, exportedDataAndExceptionType, filePath); } // Prendo tutti i tipi relativi ai metodi dei servizi (sono stati generati solo per i metodi) List <DartType> allFakeDartTypes = dartServiceTypes.SelectMany(s => s.Value.Methods) .SelectMany(m => new[] { m.ReturnObj, m.ParamObj }).ToList(); List <DartType> serviceDartType = dartServiceTypes.Values.Select(s => s.Type).ToList(); IEnumerable <DartType> indexedTypes = dartDataTypes.Values //.Concat(allFakeDartTypes) .Concat(serviceDartType); // 20201202 - skip index file to prevent class name collision // Generating index.dart //string indexPath = Path.Combine(libPath, DartFiles.IndexFileName); //DartGenerator.GenerateIndexFile(dartPackageName, indexedTypes, indexPath); // Generating bridge.dart string bridgePath = Path.Combine(libPath, DartFiles.BridgeFileName); DartGenerator.GenerateBridgeFile(bridgePath); // Generating converters.dart string converterPath = Path.Combine(libPath, DartFiles.ConvertersFileName); DartGenerator.GenerateConverterFile(converterPath); // Generating exceptions.dart string exceptionsPath = Path.Combine(libPath, DartFiles.ExceptionsFileName); DartGenerator.GenerateExportFile(flutterExceptionTypes.Values, exceptionsPath); // Default generation path string dartProjectPath = dartProject.WorkingDir.FullName; // Temp folder link used by flutnet to build the folder DirectoryInfo tempLinkedFolderInfo = null; bool isWindows = Utilities.OperatingSystem.IsWindows(); // Windows ISSUES for build_runner --> PATH to LONG (create a temp mklink for the project folder) if (isWindows) { // Get Windows system location DirectoryInfo winSystemFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System)); // Like "C:\" string winSystemDrive = Path.GetPathRoot(winSystemFolder.FullName); // Folder Link JUNCTION "C:\_flutnet.tmp_" string tempProjectPath = Path.Combine(winSystemDrive, "_flutnet.tmp_"); tempLinkedFolderInfo = new DirectoryInfo(tempProjectPath); try { int counter = 0; // Find the first free folder name like "C:\_flutnet.tmp_" or "C:\_flutnet.tmp0_" or "C:\_flutnet.tmp1_" while (tempLinkedFolderInfo.Exists && tempLinkedFolderInfo.IsSymbolic() == false) { tempProjectPath = Path.Combine(winSystemDrive, $"_flutnet.tmp{counter}_"); tempLinkedFolderInfo = new DirectoryInfo(tempProjectPath); counter++; } if (tempLinkedFolderInfo.Exists) { // Delete the oldest link FlutnetShell.RunCommand($"rmdir \"{tempLinkedFolderInfo.FullName}\"", Path.GetPathRoot(tempLinkedFolderInfo.FullName), verbose); } // Make the folder link in C:\_flutnet_\ Console.WriteLine($"Creating link {tempLinkedFolderInfo.FullName} for building the dart project...", verbose); // Make the linked folder (JUNCTION) FlutnetShell.RunCommand($"mklink /d /J \"{tempLinkedFolderInfo.FullName}\" \"{dartProject.WorkingDir.FullName}\"", winSystemDrive, verbose); tempLinkedFolderInfo = new DirectoryInfo(tempLinkedFolderInfo.FullName); if (tempLinkedFolderInfo.Exists == false || tempLinkedFolderInfo.IsSymbolic() == false) { throw new Exception($"{tempProjectPath} creation failed"); } // ****************************************** // The project is changed to the symbolic link // ****************************************** dartProjectPath = tempLinkedFolderInfo.FullName; } catch (Exception) { Console.WriteLine($"{tempProjectPath} creation failed: use default location {dartProject.WorkingDir.FullName}", verbose); dartProjectPath = dartProject.WorkingDir.FullName; } } Console.WriteLine($"End of generation procedure in progress ...", verbose); int buildRunnerErrorCount = 0; RetryBuildRunner: // // Run flutter build_runner command to generate "fromjson" e "tojson" methods. // try { FlutterTools.BuildBuildRunner(dartProjectPath, buildRunnerErrorCount > 0, verbose); } catch (Exception) { buildRunnerErrorCount++; // The runner build command can fail if the dart pacgake are not // update correctry, so retry after that if (buildRunnerErrorCount <= 1) { //Console.WriteLine($"Clean flutter project ...", verbose); FlutterTools.Clean(dartProjectPath); //Console.WriteLine($"Execute flutter pub upgrade ...", verbose); FlutterTools.PubUpgrade(dartProjectPath, verbose); Console.WriteLine($"flutter pub run build_runner build failed. Retrying updating the packages...", verbose); //Console.WriteLine($"Get flutter packages ...", verbose); FlutterTools.GetDependencies(dartProjectPath); goto RetryBuildRunner; } throw; } // Windows ISSUES for build_runner --> PATH to LONG (create a temp mklink for the project folder) if (isWindows && tempLinkedFolderInfo != null && tempLinkedFolderInfo.Exists && tempLinkedFolderInfo.IsSymbolic()) { // Delete the link Console.WriteLine($"Deleting link {tempLinkedFolderInfo.FullName} ...", verbose); FlutnetShell.RunCommand($"rmdir \"{tempLinkedFolderInfo.FullName}\"", Path.GetPathRoot(tempLinkedFolderInfo.FullName), verbose); } // // MODIFING AUTO-GENERATED PART G. FILE (JSON) replacing fromJson -> fromJsonDynamic and toJson -> toJsonDinamic // // MODIFING AUTO-GENERATED PART G. FILE PLATFORM-DATA foreach (DartType dartType in dartDataTypes.Values) { string dartPartialFilePath = DartSupport.GetDartPartialFilePath(libPath, dartType); DartGenerator.FixDartGPartedJsonFile(dartType, dartPartialFilePath); } // MODIFING AUTO-GENERATED PART G. FILE EXCEPTIONS foreach (DartType dartType in flutterExceptionTypes.Values) { string dartPartialFilePath = DartSupport.GetDartPartialFilePath(libPath, dartType); DartGenerator.FixDartGPartedJsonFile(dartType, dartPartialFilePath); } // MODIFING AUTO-GENERATED PART G. FILE CMD/RES fake classes foreach (DartService dartSrv in dartServiceTypes.Values) { foreach (DartMethod method in dartSrv.Methods) { // Return Object generator string returnPartialFilePath = DartSupport.GetDartPartialFilePath(libPath, method.ReturnObj); DartGenerator.FixDartGPartedJsonFile(method.ReturnObj, returnPartialFilePath); // Param Object generator string paramPartialFilePath = DartSupport.GetDartPartialFilePath(libPath, method.ParamObj); DartGenerator.FixDartGPartedJsonFile(method.ParamObj, paramPartialFilePath); } } Console.WriteLine($"Flutter package \"{dartProject.WorkingDir.FullName}\" generated/updated successfully."); }
public NamedDartType(ComponentReader reader) { name = new StringReference(reader); type = reader.ReadDartType(); }
public NamedDartType(StringReference name, DartType type) { this.name = name; this.type = type; }