private void OnChangeCompilerStateEx(PascalABCCompiler.ICompiler sender, PascalABCCompiler.CompilerState State, string FullFileName)
        {

            string RusName = null;
            string FileName = null;
            if (FullFileName != null)
                FileName = Path.GetFileName(FullFileName);
            switch (State)
            {
                case PascalABCCompiler.CompilerState.CompilationStarting:
                    RusName = VECStringResources.Get("STATE_START_COMPILING_ASSEMBLY{0}");
                    SetCompilingButtonsEnabled(false);
                    ParsedFiles.Clear();
                    break;
                case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATE_BEGINCOMPILEFILE{0}"); break;
                case PascalABCCompiler.CompilerState.CompileInterface: RusName = VECStringResources.Get("STATE_COMPILEINTERFACE{0}"); break;
                case PascalABCCompiler.CompilerState.CompileImplementation: RusName = VECStringResources.Get("STATE_COMPILEIMPLEMENTATION{0}"); break;
                case PascalABCCompiler.CompilerState.EndCompileFile: RusName = VECStringResources.Get("STATE_ENDCOMPILEFILE{0}"); break;
                case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATE_CODEGENERATION{0}"); break;
                case PascalABCCompiler.CompilerState.ReadDLL: RusName = VECStringResources.Get("STATE_READDLL{0}"); break;
                case PascalABCCompiler.CompilerState.SavePCUFile: RusName = VECStringResources.Get("STATE_SAVEPCUFILE{0}"); break;
                case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = VECStringResources.Get("STATE_READPCUFILE{0}"); break;
                case PascalABCCompiler.CompilerState.PCUReadingError: RusName = VECStringResources.Get("STATE_PCUREADINGERROR{0}"); break;
                case PascalABCCompiler.CompilerState.PCUWritingError: RusName = VECStringResources.Get("STATE_PCUWRITINGERROR{0}"); break;
                case PascalABCCompiler.CompilerState.SemanticTreeConversion: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERSION{0}"); break;
                case PascalABCCompiler.CompilerState.SemanticTreeConverterConnected: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERTERCONNECTED{0}"); break;
                case PascalABCCompiler.CompilerState.SyntaxTreeConversion: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERSION{0}"); break;
                case PascalABCCompiler.CompilerState.SyntaxTreeConverterConnected: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERTERCONNECTED{0}"); break;
                case PascalABCCompiler.CompilerState.ParserConnected:
                    FileName = Path.GetFileName(FileName);
                    if(sender.CompilerType== PascalABCCompiler.CompilerType.Standart)
                        RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}{1}"), sender.ParsersController.LastParser, FileName);
                    else
                        RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}"), FileName);
                    FileName = null;
                    break;
                case PascalABCCompiler.CompilerState.Ready:
                    RusName = VECStringResources.Get("STATE_READY");
                    if (!StartingCompleted)
                    {
                        switch (sender.CompilerType)
                        {
                            case PascalABCCompiler.CompilerType.Standart:
                                standartCompiler = (PascalABCCompiler.Compiler)sender;
                                break;
                            case PascalABCCompiler.CompilerType.Remote:
                                remoteCompiler = (PascalABCCompiler.RemoteCompiler)sender;
                                break;
                        }
                        if (!(defaultCompilerType == PascalABCCompiler.CompilerType.Remote) || (standartCompiler.State == PascalABCCompiler.CompilerState.Ready && (remoteCompiler != null && remoteCompiler.State == PascalABCCompiler.CompilerState.Ready)))
                            StartingCompleted = true;
                        AddCompilerTextToCompilerMessages(sender, VECStringResources.Get("SUPPORTED_LANGUAGES") + Environment.NewLine);
                        foreach (PascalABCCompiler.SupportedSourceFile ssf in standartCompiler.SupportedSourceFiles)
                            AddCompilerTextToCompilerMessages(sender, string.Format(VECStringResources.Get("CM_LANGUAGE_{0}"), ssf) + Environment.NewLine);
                        if (StartingCompleted)
                        {
                            ChangeVisualEnvironmentState(VisualEnvironmentState.FinishCompilerLoading, standartCompiler);
                            compilerLoaded = true;
            				VisualPABCSingleton.MainForm.StartTimer();
                            /*if (!ThreadPool.QueueUserWorkItem(new WaitCallback(CompileTestProgram)))
                                CompileTestProgram(null);*/
                            if (!ThreadPool.QueueUserWorkItem(new WaitCallback(LoadPlugins)))
                                LoadPlugins(null);
                            
                            SetCompilingButtonsEnabled(true);
                            SetDebugButtonsEnabled(true);
                        }
                    }
                    else
                    {
                        if (Compiler == sender)
                        {
                            SetCompilingButtonsEnabled(true);
                        }
                    }
                    break;
                case PascalABCCompiler.CompilerState.Reloading:
                    if (Compiler == sender)
                        SetCompilingButtonsEnabled(false);
                    RusName = VECStringResources.Get("STATE_RELOADING");
                    break;
                case PascalABCCompiler.CompilerState.CompilationFinished:
                    RusName = VECStringResources.Get("STATE_COMPILATIONFINISHED{0}");
                    if (Compiler.ErrorsList.Count == 0)
                    {
                        SaveSourceFilesIfCompilationOk();
                        AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_OK_{0}MS") + Environment.NewLine, (DateTime.Now - compilationStartTime).TotalMilliseconds) + Environment.NewLine);
                    }
                    else
                    {
                        List<PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                        AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_{0}_ERROS") + Environment.NewLine, ErrorsList.Count));
                        foreach (PascalABCCompiler.Errors.Error Err in ErrorsList)
                            AddTextToCompilerMessages(Err.ToString() + Environment.NewLine);
                    }

                    break;
                default: 
                    //RusName = State.ToString(); 
                    break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                    RusName = string.Format(RusName, FileName);
                else RusName = string.Format(RusName, "");
                RusName += Environment.NewLine;
                AddCompilerTextToCompilerMessages(sender, RusName);
            }

            RusName = null;
            switch (State)
            {
                case PascalABCCompiler.CompilerState.BeginParsingFile:
                    ParsedFiles.Add(FullFileName);
                    break;
                case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATETEXT_BEGINCOMPILEFILE{0}"); break;
                //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
                case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATETEXT_CODEGENERATION{0}"); break;
                //case PascalABCCompiler.CompilerState.ReadDLL: 
                //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
                case PascalABCCompiler.CompilerState.Ready:
                    if (Compiler != null)
                    {
                        List<PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                        if (ErrorsList.Count > 0)
                        {
                            RusName = string.Format(VECStringResources.Get("STATETEXT_{0}_ERROS"), ErrorsList.Count);
                        }
                        else
                            if (Compilation)
                            {
                                if (Compiler.Warnings.Count > 0)
                                    RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES_{1}WARNINGS"), Compiler.LinesCompiled, Compiler.Warnings.Count);
                                else
                                    RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES"), Compiler.LinesCompiled);
                            }
                            else
                                RusName = VECStringResources.Get("STATETEXT_READY");
                    }
                    else
                        RusName = VECStringResources.Get("STATETEXT_READY");
                    break;
                case PascalABCCompiler.CompilerState.Reloading: RusName = VECStringResources.Get("STATETEXT_RELOADING"); break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                    RusName = string.Format(RusName, FileName);
                SetStateText(RusName);


            }
            if (!Compilation && State == PascalABCCompiler.CompilerState.CompilationStarting)
                Compilation = true;
            if (Compilation && State == PascalABCCompiler.CompilerState.Ready)
                Compilation = false;
        }
        private void OnChangeCompilerStateEx(PascalABCCompiler.ICompiler sender, PascalABCCompiler.CompilerState State, string FullFileName)
        {
            string RusName  = null;
            string FileName = null;

            if (FullFileName != null)
            {
                FileName = Path.GetFileName(FullFileName);
            }
            switch (State)
            {
            case PascalABCCompiler.CompilerState.CompilationStarting:
                RusName = VECStringResources.Get("STATE_START_COMPILING_ASSEMBLY{0}");
                SetCompilingButtonsEnabled(false);
                ParsedFiles.Clear();
                break;

            case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATE_BEGINCOMPILEFILE{0}"); break;

            case PascalABCCompiler.CompilerState.CompileInterface: RusName = VECStringResources.Get("STATE_COMPILEINTERFACE{0}"); break;

            case PascalABCCompiler.CompilerState.CompileImplementation: RusName = VECStringResources.Get("STATE_COMPILEIMPLEMENTATION{0}"); break;

            case PascalABCCompiler.CompilerState.EndCompileFile: RusName = VECStringResources.Get("STATE_ENDCOMPILEFILE{0}"); break;

            case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATE_CODEGENERATION{0}"); break;

            case PascalABCCompiler.CompilerState.ReadDLL: RusName = VECStringResources.Get("STATE_READDLL{0}"); break;

            case PascalABCCompiler.CompilerState.SavePCUFile: RusName = VECStringResources.Get("STATE_SAVEPCUFILE{0}"); break;

            case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = VECStringResources.Get("STATE_READPCUFILE{0}"); break;

            case PascalABCCompiler.CompilerState.PCUReadingError: RusName = VECStringResources.Get("STATE_PCUREADINGERROR{0}"); break;

            case PascalABCCompiler.CompilerState.PCUWritingError: RusName = VECStringResources.Get("STATE_PCUWRITINGERROR{0}"); break;

            case PascalABCCompiler.CompilerState.SemanticTreeConversion: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERSION{0}"); break;

            case PascalABCCompiler.CompilerState.SemanticTreeConverterConnected: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERTERCONNECTED{0}"); break;

            case PascalABCCompiler.CompilerState.SyntaxTreeConversion: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERSION{0}"); break;

            case PascalABCCompiler.CompilerState.SyntaxTreeConverterConnected: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERTERCONNECTED{0}"); break;

            case PascalABCCompiler.CompilerState.ParserConnected:
                FileName = Path.GetFileName(FileName);
                if (sender.CompilerType == PascalABCCompiler.CompilerType.Standart)
                {
                    RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}{1}"), sender.ParsersController.LastParser, FileName);
                }
                else
                {
                    RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}"), FileName);
                }
                FileName = null;
                break;

            case PascalABCCompiler.CompilerState.Ready:
                RusName = VECStringResources.Get("STATE_READY");
                if (!StartingCompleted)
                {
                    switch (sender.CompilerType)
                    {
                    case PascalABCCompiler.CompilerType.Standart:
                        standartCompiler = (PascalABCCompiler.Compiler)sender;
                        break;

                    case PascalABCCompiler.CompilerType.Remote:
                        remoteCompiler = (PascalABCCompiler.RemoteCompiler)sender;
                        break;
                    }
                    if (!(defaultCompilerType == PascalABCCompiler.CompilerType.Remote) || (standartCompiler.State == PascalABCCompiler.CompilerState.Ready && (remoteCompiler != null && remoteCompiler.State == PascalABCCompiler.CompilerState.Ready)))
                    {
                        StartingCompleted = true;
                    }
                    AddCompilerTextToCompilerMessages(sender, VECStringResources.Get("SUPPORTED_LANGUAGES") + Environment.NewLine);
                    foreach (PascalABCCompiler.SupportedSourceFile ssf in standartCompiler.SupportedSourceFiles)
                    {
                        AddCompilerTextToCompilerMessages(sender, string.Format(VECStringResources.Get("CM_LANGUAGE_{0}"), ssf) + Environment.NewLine);
                    }
                    if (StartingCompleted)
                    {
                        ChangeVisualEnvironmentState(VisualEnvironmentState.FinishCompilerLoading, standartCompiler);
                        compilerLoaded = true;
                        VisualPABCSingleton.MainForm.StartTimer();

                        /*if (!ThreadPool.QueueUserWorkItem(new WaitCallback(CompileTestProgram)))
                         *  CompileTestProgram(null);*/
                        if (!ThreadPool.QueueUserWorkItem(new WaitCallback(LoadPlugins)))
                        {
                            LoadPlugins(null);
                        }

                        SetCompilingButtonsEnabled(true);
                        SetDebugButtonsEnabled(true);
                    }
                }
                else
                {
                    if (Compiler == sender)
                    {
                        SetCompilingButtonsEnabled(true);
                    }
                }
                break;

            case PascalABCCompiler.CompilerState.Reloading:
                if (Compiler == sender)
                {
                    SetCompilingButtonsEnabled(false);
                }
                RusName = VECStringResources.Get("STATE_RELOADING");
                break;

            case PascalABCCompiler.CompilerState.CompilationFinished:
                RusName = VECStringResources.Get("STATE_COMPILATIONFINISHED{0}");
                if (Compiler.ErrorsList.Count == 0)
                {
                    SaveSourceFilesIfCompilationOk();
                    AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_OK_{0}MS") + Environment.NewLine, (DateTime.Now - compilationStartTime).TotalMilliseconds) + Environment.NewLine);
                }
                else
                {
                    List <PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                    AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_{0}_ERROS") + Environment.NewLine, ErrorsList.Count));
                    foreach (PascalABCCompiler.Errors.Error Err in ErrorsList)
                    {
                        AddTextToCompilerMessages(Err.ToString() + Environment.NewLine);
                    }
                }

                break;

            default:
                //RusName = State.ToString();
                break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                {
                    RusName = string.Format(RusName, FileName);
                }
                else
                {
                    RusName = string.Format(RusName, "");
                }
                RusName += Environment.NewLine;
                AddCompilerTextToCompilerMessages(sender, RusName);
            }

            RusName = null;
            switch (State)
            {
            case PascalABCCompiler.CompilerState.BeginParsingFile:
                ParsedFiles.Add(FullFileName);
                break;

            case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATETEXT_BEGINCOMPILEFILE{0}"); break;

            //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
            case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATETEXT_CODEGENERATION{0}"); break;

            //case PascalABCCompiler.CompilerState.ReadDLL:
            //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
            case PascalABCCompiler.CompilerState.Ready:
                if (Compiler != null)
                {
                    List <PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                    if (ErrorsList.Count > 0)
                    {
                        RusName = string.Format(VECStringResources.Get("STATETEXT_{0}_ERROS"), ErrorsList.Count);
                    }
                    else
                    if (Compilation)
                    {
                        if (Compiler.Warnings.Count > 0)
                        {
                            RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES_{1}WARNINGS"), Compiler.LinesCompiled, Compiler.Warnings.Count);
                        }
                        else
                        {
                            RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES"), Compiler.LinesCompiled);
                        }
                    }
                    else
                    {
                        RusName = VECStringResources.Get("STATETEXT_READY");
                    }
                }
                else
                {
                    RusName = VECStringResources.Get("STATETEXT_READY");
                }
                break;

            case PascalABCCompiler.CompilerState.Reloading: RusName = VECStringResources.Get("STATETEXT_RELOADING"); break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                {
                    RusName = string.Format(RusName, FileName);
                }
                SetStateText(RusName);
            }
            if (!Compilation && State == PascalABCCompiler.CompilerState.CompilationStarting)
            {
                Compilation = true;
            }
            if (Compilation && State == PascalABCCompiler.CompilerState.Ready)
            {
                Compilation = false;
            }
        }
 public void LoadRemoteCompiler()
 {
     remoteCompiler = new PascalABCCompiler.RemoteCompiler(PascalABCCompiler.ConsoleCompilerConstants.MaxProcessMemoryMB, OnChangeCompilerState, SourceFilesProvider);
 }
 public void LoadRemoteCompiler()
 {
     remoteCompiler = new PascalABCCompiler.RemoteCompiler(PascalABCCompiler.ConsoleCompilerConstants.MaxProcessMemoryMB, OnChangeCompilerState, SourceFilesProvider);
 }