예제 #1
0
 public void ToJson(ref Utf8JsonWriter json, string?name)
 {
     if (name != null)
     {
         json.WriteStartObject(name);
     }
     else
     {
         json.WriteStartObject();
     }
     json.WriteString(nameof(Name), Name);
     NativeCore.ListToJsonArrayHelper(json, nameof(Methods), Methods.Values.ToList());
     json.WriteEndObject();
 }
예제 #2
0
 public void ToJson(ref Utf8JsonWriter json, string?name)
 {
     if (name != null)
     {
         json.WriteStartObject(name);
     }
     else
     {
         json.WriteStartObject();
     }
     json.WriteString(nameof(Name), Name);
     ReturnType?.ToJson(ref json, nameof(ReturnType));
     IntendedReturnType?.ToJson(ref json, nameof(IntendedReturnType));
     NativeCore.ListToJsonArrayHelper(json, nameof(Parameters), Parameters);
     json.WriteEndObject();
 }
예제 #3
0
        public static IntPtr GetNativeMetadata([IntendedType(typeof(ProgrammingPlatform))] int programmingPlaformNumber)
        {
            var utf8 = new UTF8Encoding();

            try{
                var output = new ArrayBufferWriter <byte>(BUFFER_SIZE);
                var json   = new Utf8JsonWriter(output, state: default);
                json.WriteStartObject();

                if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "config.json")))
                {
                    json.WriteString("Error", "No config found config.json");
                }
                else
                {
                    try
                    {
                        var configurationBuilder = new ConfigurationBuilder()
                                                   .SetBasePath(Directory.GetCurrentDirectory())
                                                   .AddJsonFile("config.json", true);
                        var config = configurationBuilder.Build();
                        var nativeSourceSettings = config.GetSection("NativeSources").Get <NativeSourceSettings>();
                        var assembliesNotFound   = new List <string>();
                        var assemblyFiles        = new List <FileInfo>();
                        //foreach(var assembly in nativeSourceSettings.Assemblies.Distinct()){
                        // foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies().Distinct()){
                        //     var filePath = Path.GetFullPath(assembly.FullName);
                        //     var assemblyFile = new FileInfo(filePath);
                        //     if(!assemblyFile.Exists){
                        //         assembliesNotFound.Add(assembly.FullName);
                        //     }
                        //     else{
                        //         assemblyFiles.Add(assemblyFile);
                        //     }
                        // }

                        // if(assembliesNotFound.Count > 0){
                        //     var assembliesNotFoundArrayJson = NativeCore.ListToJsonArrayHelper(assembliesNotFound);
                        //     return Marshal.StringToCoTaskMemUTF8($"{{\"Error\": \"The following assemblies were not found (defined in conifg.json): {assembliesNotFoundArrayJson}\"}}");
                        // }
                        var assemblies = new Dictionary <string, NativeAssemblyDescription>();
                        foreach (var assembly in new[] { typeof(NativeCore).Assembly })
                        {
                            var assemblyFile = new FileInfo($"{Assembly.GetExecutingAssembly().FullName.Split(",").FirstOrDefault()}.dll");
                            var namespaces   = ProcessAssembly(assembly, (ProgrammingPlatform)programmingPlaformNumber);
                            assemblies.Add(assemblyFile.FullName, new NativeAssemblyDescription(assemblyFile.Name, assemblyFile.DirectoryName.Replace("\\", "/"))
                            {
                                Namespaces = namespaces
                            });
                        }

                        NativeCore.ListToJsonArrayHelper(json, "Data", assemblies.Values.ToList());
                    }
                    catch (InvalidOperationException ioex)
                    {
                        json.WriteString("Error", "Error build metadata.");
                        json.WriteString("Exception", ioex.ToString());
                    }
                    catch (Exception ex) {
                    }
                }

                json.WriteNumber(nameof(json.BytesWritten), json.BytesWritten);
                json.WriteNumber(nameof(json.BytesCommitted), json.BytesCommitted);
                json.WriteEndObject();
                json.Flush();
                var holdPointer = Marshal.StringToCoTaskMemUTF8(utf8.GetString(output.OutputAsSpan));
                //arrayBufferHold.Add(holdPointer, output);
                return(holdPointer);
            }
            catch (Exception ex) {
                var catchOutput = new ArrayBufferWriter <byte>(BUFFER_SIZE);
                var catchJson   = new Utf8JsonWriter(catchOutput, state: default);
                catchJson.WriteStartObject();
                catchJson.WriteString("Error", "Error processing or validating metadata.");
                catchJson.WriteString("Exception", ex.ToString());
                catchJson.WriteEndObject();
                catchJson.Flush();
                return(Marshal.StringToCoTaskMemUTF8(utf8.GetString(catchOutput.OutputAsSpan)));
            }
        }