static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); string text = @"namespace HelloWorld { public class Test { public Test(){ Name=""111""; } public string Name; public int Age{get;set;} } }"; //根据脚本创建动态类 AssemblyCSharpBuilder oop = new AssemblyCSharpBuilder("test"); oop.Add(text); Type type = oop.GetTypeFromShortName("Test"); Console.WriteLine(type.Name); var action = NDelegate.RandomDomain().Action(""); var a = action.Method; Console.WriteLine(action.Method.Module.Assembly); Console.WriteLine(DomainManagement.IsDeleted(action.GetDomain().Name)); Console.ReadKey(); }
public void Run(int port) { NatashaInitializer.InitializeAndPreheating(); _Logger?.LogInformation("初始化动态代码引擎"); this.Port = port; _requestReception = ServiceProvider.GetService <IRequestReception>(); _tcpListener = new TcpListener(IPAddress.Any, port); _tcpListener.Start(); _Logger?.LogInformation("Gateway started, port:{0}", port); if (ServerCert != null) { _Logger?.LogInformation("Use ssl,certificate hash:{0}", ServerCert.GetCertHashString()); } while (true) { try { var socket = _tcpListener.AcceptSocket(); Task.Run(() => _requestReception.Interview(socket)); } catch (Exception ex) { _Logger?.LogError(ex, ex.Message); break; } } }
public TestCaller() { NatashaInitializer.InitializeAndPreheating(); string temp = "Hello"; Dict = new Dictionary<string, Action<CallModel, object>>(); Type type = typeof(CallModel); PrecisionDict = PrecisionDictOperator.CreateFromType(type); FuzzyDict = FuzzyDictOperator.CreateFromType(type); HashDict = HashDictOperator.CreateFromType(type); //LinkHandler = LinkOperator.CreateFromType(type); //FuzzyLinkHandler = FuzzyLinkOperator.CreateFromType(type); //HashLinkHandler = HashLinkOperator.CreateFromType(type); Model = new CallModel(); Dynamic = new CallModel(); DictModel = new CallModel(); PrecisionDict.New(); FuzzyDict.New(); HashDict.New(); Dict["Name"] = NDelegate.DefaultDomain().Action<CallModel, object>("arg1.Name=(string)arg2;"); for (int i = 0; i < 3000; i++) { Model.Name = "Hello"; Dynamic.Name = "Hello"; Dict["Name"](DictModel, "Hello"); PrecisionDict.Set("Name", "Hello"); } }
public static IServiceCollection AddLibraWpc(this IServiceCollection services, Func <LibraOption, LibraOption> optAction) { NatashaInitializer.InitializeAndPreheating(); LibraProtocalAnalysis.Provider = services.BuildServiceProvider(); optAction?.Invoke(new LibraOption()); return(services); }
static void Main(string[] args) { //Natasha 4.0 注册编译组件 NatashaInitializer.InitializeAndPreheating(); NSucceedLog.Enabled = true; //注入接口和实现 FrameworkService.AddInjection <DefaultTypeService>(); FrameworkService.AddInjection <IHelloServices, DefaultHelloService>(); FrameworkService.RefreshRpcControllers(); //添加AOP Aop <HelloRpc> .Before["GetHello"] = (instance, parameters) => { Console.WriteLine("Aop In Before()!"); }; Aop <HelloRpc> .After["GetHello"] = (instance, parameters) => { Console.WriteLine("Aop In After()!"); }; //接收路由及参数 //string controller = args[0]; string controller = "Hello"; //string parameter = args[1]; string parameter = "World"; Console.WriteLine(); //传递路由和参数 var result = FrameworkCaller.Caller(controller, parameter); Console.WriteLine("Output : " + result); Console.WriteLine(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { NatashaInitializer.InitializeAndPreheating(); NatashaController.Builder = (ApplicationBuilder)app; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; }); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); NatashaController.Endpoints = endpoints.DataSources; }); }
public static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); string result = NDelegate.RandomDomain().Func <string>("return \"a\";")(); CreateHostBuilder(args).Build().Run(); }
public void Test6() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier <TestVirtual2>(); var func = proxier.GetDefaultCreator <TestVirtual2>(); var testAbstact = func(); Assert.Equal(11, testAbstact.Get("0")); }
public async void Test7() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier <TestTaskAbstract>(); var func = proxier.GetDefaultCreator <TestTaskAbstract>(); var testAbstact = func(); Assert.Equal(0, await testAbstact.Get("0")); }
public void Test5() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier <TestVirtual2>(); proxier["Get"] = "return value.Length+5;"; var func = proxier.GetDefaultCreator <TestVirtual2>(); var testAbstact = func(); Assert.Equal(6, testAbstact.Get("0")); }
public void Test() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier <TestAbstact>(); proxier["Get"] = "return value.Length;"; var func = proxier.GetDefaultCreator <TestAbstact>(); TestAbstact testAbstact = func(); Assert.Equal(1, testAbstact.Get("1")); }
public void Test2() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier(); proxier.Implement(typeof(TestInterface1)); var func = proxier.GetDefaultCreator <TestInterface1>(); var testAbstact = func(); Assert.Equal(0, testAbstact.GetInfo1("0")); }
public void Test3() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier <TestInterface2>(); proxier["GetInfo2"] = "return value.Length;"; var func = proxier.GetCreator(); var testAbstact = func(); Assert.Equal(1, testAbstact.GetInfo2("0")); }
/// <summary> /// 初始化比较耗时 /// </summary> public static void Init() { if (!isInit) { NatashaInitializer.InitializeAndPreheating(); //NatashaComponentRegister.RegistDomain<NatashaAssemblyDomain>(); //NatashaComponentRegister.RegistCompiler<NatashaCSharpCompiler>(); //NatashaComponentRegister.RegistSyntax<NatashaCSharpSyntax>(); isInit = true; } }
static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); var domainName = Test(); for (int i = 0; i < 6; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); } Console.WriteLine(domainName); Console.WriteLine(DomainManagement.IsDeleted(domainName)); Console.ReadKey(); }
public void Test9() { NatashaInitializer.InitializeAndPreheating(); var proxier = new Proxier <TestAbstact>(); proxier.ClassBuilder.Ctor(ctor => ctor .Public() .Param <int>("value") .Body("_value = value;") ); proxier.ClassBuilder.PrivateReadonlyField <int>("_value"); proxier["Get"] = "return _value;"; var func = proxier.GetCreator <int>(); TestAbstact testAbstact = func(10); Assert.Equal(10, testAbstact.Get("1")); }
static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); //var hwFunc = FastMethodOperator // .RandomDomain() // .Param(typeof(string), "str1") // .Param<string>("str2") // .Body("return str1+str2;") // .Return<string>() // .Compile<Func<string, string, string>>(); //Console.WriteLine(hwFunc("Hello", " World!")); string temp = NDelegate.RandomDomain().Func <string>("return (new A()).Name;")(); Console.WriteLine(temp); //var a123 = NClass.UseDomain(typeof(Program).GetDomain()); //var domain = DomainManagement.Random; //var type = NDelegate.UseDomain(domain,item=>item.AssemblyName="a").GetType($"[assembly: AssemblyKeyFileAttribute(\"c:\\\\vs2019\\\\natasha.snk\")]" +"[assembly: AssemblyVersion(\"1.3.3.3\")]public class A{ public A(){Name=\"1\"; }public string Name;}"); //var func = NDelegate.UseDomain(domain).Func<string>("return (new A()).Name;"); //Console.WriteLine(type.FullName); //Console.WriteLine(func()); ////type.RemoveReferences(); //type = NDelegate.UseDomain(domain,item=>item.AssemblyName="a").GetType($"[assembly: AssemblyKeyFileAttribute(\"c:\\\\vs2019\\\\natasha.snk\")]" + "[assembly: AssemblyVersion(\"2.3.3.4\")]public class A{ public A(){Name=\"2\"; }public string Name;}"); //func = NDelegate.UseDomain(domain).Func<string>("return (new A()).Name;"); //Console.WriteLine(type.FullName); //Console.WriteLine(func()); //domain = DomainManagement.Create("a"); //using (DomainManagement.Lock("a")) //{ // Console.WriteLine(domain == (NatashaAssemblyDomain)AssemblyLoadContext.CurrentContextualReflectionContext); //} Console.ReadKey(); }
public BenchmarkTest() { NErrorLog.Enabled = true; NatashaInitializer.InitializeAndPreheating(); model = new TestModel(); _imMap = ImMap <string> .Empty; _imHashMap = ImHashMap <string, string> .Empty; FuzzyHandler = model.Model1.FuzzyTree(); HashHandler = model.Model1.HashTree(); PrecisionHandler = model.Model1.PrecisioTree(); DictHandler = model.Model1; Dictionary <int, string> hashDict = new(); foreach (var item in model.Model1) { _imHashMap = _imHashMap.AddOrUpdate(item.Key, item.Value); _imMap = _imMap.AddOrUpdate(Int32.Parse(item.Key), item.Value); hashDict[Int32.Parse(item.Key)] = item.Value; } HashCodePrecisionHandler = hashDict.CustomerTree(item => item.ToString()); ConDictHandler = new ConcurrentDictionary <string, string>(model.Model1); ReadonlyDictHandler = ImmutableDictionary.CreateRange(DictHandler); }
static Prepare() { #if !NETFRAMEWORK NatashaInitializer.InitializeAndPreheating(); #endif }
static PrepareTest() { NatashaInitializer.InitializeAndPreheating(); }
static void Main(string[] args) { // string code = @"public class A{ // public string A{get;set;} //public string B{get;set;} //public string C{get;set;} //public void Test( ){NormalTestModel result = new NormalTestModel();int i=0 ; var t=new{Name=""""};return result;Console.WriteLine( ""aa"");} //}"; // var _options = new CSharpParseOptions(LanguageVersion.Preview); // var tree = SyntaxFactory.ParseSyntaxTree(code.Trim(), _options).GetRoot().NormalizeWhitespace().SyntaxTree; // using (var workspace = new AdhocWorkspace()) // { // tree = Formatter.Format(tree.GetRoot(), workspace).SyntaxTree; // } // Console.WriteLine(tree.ToString()); // Console.WriteLine(); NatashaInitializer.InitializeAndPreheating(); //var func = NDelegate.RandomDomain().Func<int>("return 1;"); //Console.WriteLine(func()); /* * NatashaInitializer.Initialize(); * string text = @"namespace HelloWorld * { * public class Test * { * public Test(){ * Name=""111""; * } * * public string Name; * public int Age{get;set;} * } * }"; * //根据脚本创建动态类 * AssemblyCSharpBuilder oop = new AssemblyCSharpBuilder("test"); * oop.Domain = DomainManagement.Random; * //oop.Domain.AddReferencesFromDllFile(typeof(object).Assembly.Location); * oop.Add(text); * Type type = oop.GetTypeFromShortName("Test"); * * Console.WriteLine(type.Name); * * var action = NDelegate.UseDomain(oop.Domain).Action(""); * var a = action.Method; * Console.WriteLine(action.Method.Module.Assembly); * Console.WriteLine(DomainManagement.IsDeleted(action.GetDomain().Name)); * * //var nClass = NClass * // .RandomDomain(); * //nClass.DelegateHandler. * //type = NClass * // .RandomDomain().Namespace("") * // .Name("Test") * // .Ctor(item => item * // .Public() * // .Body("Name = null;") * // ) * // .PublicField<string>("Name") * // .GetType(); * //type.Assembly * //CSharpScript.EvaluateAsync */ Console.ReadKey(); }
static AbstractValidationProvider() { #if !NETFRAMEWORK NatashaInitializer.InitializeAndPreheating(); #endif }
static FindTreeTest() { NatashaInitializer.InitializeAndPreheating(); }
static CSharpExecutor() { NatashaInitializer.InitializeAndPreheating(true); }
static TableInfomation() { NatashaInitializer.InitializeAndPreheating(); _realTableNameMapping = new ConcurrentDictionary <Type, string>(); }
static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); NDelegate.RandomDomain().Action("Console.WriteLine(\"Hello World!\");")(); Console.ReadKey(); }
static TableInfomationInitor() { NatashaInitializer.InitializeAndPreheating(); }
static FluentValidationCore() { NatashaInitializer.InitializeAndPreheating(); }
static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); //var hwFunc = FastMethodOperator // .RandomDomain() // .Param(typeof(string), "str1") // .Param<string>("str2") // .Body("return str1+str2;") // .Return<string>() // .Compile<Func<string, string, string>>(); //Console.WriteLine(hwFunc("Hello", " World!")); //var assembly = typeof(object).Assembly; //var path = assembly.Location; //var r1 = MetadataReference.CreateFromFile(path); //MetadataReference.CreateFromAssembly //MetadataReference.CreateFromStream(assembly.strea); //string temp = NDelegate.RandomDomain().Func<string>("return (new A()).Name;")(); //Console.WriteLine(temp); //var a123 = NClass.UseDomain(typeof(Program).GetDomain()); //var domain = DomainManagement.Random; //var type = NDelegate.UseDomain(domain,item=>item.AssemblyName="a").GetType($"[assembly: AssemblyKeyFileAttribute(\"c:\\\\vs2019\\\\natasha.snk\")]" +"[assembly: AssemblyVersion(\"1.3.3.3\")]public class A{ public A(){Name=\"1\"; }public string Name;}"); //var func = NDelegate.UseDomain(domain).Func<string>("return (new A()).Name;"); //Console.WriteLine(type.FullName); //Console.WriteLine(func()); ////type.RemoveReferences(); //type = NDelegate.UseDomain(domain,item=>item.AssemblyName="a").GetType($"[assembly: AssemblyKeyFileAttribute(\"c:\\\\vs2019\\\\natasha.snk\")]" + "[assembly: AssemblyVersion(\"2.3.3.4\")]public class A{ public A(){Name=\"2\"; }public string Name;}"); //func = NDelegate.UseDomain(domain).Func<string>("return (new A()).Name;"); //Console.WriteLine(type.FullName); //Console.WriteLine(func()); //domain = DomainManagement.Create("a"); //using (DomainManagement.Lock("a")) //{ // Console.WriteLine(domain == (NatashaAssemblyDomain)AssemblyLoadContext.CurrentContextualReflectionContext); //} // var temp1 = new Test (){ X = 1, Y = 2 }; // Console.WriteLine(CSharpScript.EvaluateAsync<int>(@" //var result = X+Y; //result+=""X"".Length; //result+=""Y"".Length; //result+=""XY"".Length; //X = X * Y; //result+=X; //result+=X.Y; //return result; //", //ScriptOptions //.Default //.AddReferences(typeof(Test).Assembly) //.WithImports("Core31"), //globals: temp1).Result); //var func = NDelegate // .RandomDomain() // .WithFirstArgInvisible() // .Func<Test,int>(@" //var b = c; //Show(b); ////var s = new Test1(); //Task.Run(()=>{ Show(); }); //return 0;")(new Test()); //Console.WriteLine(1.WithScript("return arg+1;").Execute<double>()); //Test instance = new Test(); //instance.WithScript("Show();").Execute(); //NDelegate // .RandomDomain() // .WithFirstArgInvisible("arg") // .Func<Test, int>(@" //arg.Show(); ////var a = Show(); //var b = c; //Show(c); //Console.WriteLine(1); //return 0;")(new Test()); Console.ReadKey(); }
static void Main(string[] args) { NatashaInitializer.InitializeAndPreheating(); BenchmarkRunner.Run <BenchmarkTest>(); Console.ReadKey(); }