/// <summary>
    /// 初始化 Natasha 组件
    /// </summary>
    public static Task Initialize(bool initializeReference = true)
    {
#if DEBUG
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
#endif
        if (!_hasInitialize)
        {
            lock (_lock)
            {
                if (!_hasInitialize)
                {
                    _hasInitialize = true;

                    Task.Run(() => { var host = new AdhocWorkspace(); });
                    var task1 = Task.Run(() => { NatashaComponentRegister.RegistSyntax <NatashaCSharpSyntax>(); });
                    var task2 = Task.Run(() => {
                        NatashaComponentRegister.RegistDomain <NatashaAssemblyDomain>(initializeReference);
                        NatashaComponentRegister.RegistCompiler <NatashaCSharpCompiler>();
                        NatashaCSharpCompiler.AddSemanticAnalysistor(UsingAnalysistor.Creator());
                    });
                    Task.WaitAll(task1, task2);
                }
            }
        }
#if DEBUG
        stopwatch.Stop();
        Console.WriteLine($"\r\n================ [Regist] \t注册组件总时长: {stopwatch.ElapsedMilliseconds}ms ================ \r\n");
#endif
        return(Task.CompletedTask);
    }
示例#2
0
 public NatashaCSharpEngine(string name)
 {
     Syntax   = new NatashaCSharpSyntax();
     Compiler = new NatashaCSharpCompiler();
     Compiler.AssemblyName = name;
     Compiler.StreamCompileFailedHandler += NatashaEngine_StreamCompileFailedHandler;
     Compiler.FileCompileFailedHandler   += NatashaEngine_FileCompileFailedHandler;;
 }
示例#3
0
 /// <summary>
 /// 初始化 Natasha 组件
 /// </summary>
 public static Task Initialize(bool initializeReference = true)
 {
     if (!_hasInitialize)
     {
         lock (_lock)
         {
             if (!_hasInitialize)
             {
                 _hasInitialize = true;
                 NatashaComponentRegister.RegistDomain <NatashaAssemblyDomain>(initializeReference);
                 NatashaComponentRegister.RegistCompiler <NatashaCSharpCompiler>();
                 NatashaComponentRegister.RegistSyntax <NatashaCSharpSyntax>();
                 NatashaCSharpCompiler.AddSemanticAnalysistor(UsingAnalysistor.Creator());
             }
         }
     }
     return(Task.CompletedTask);
 }