Exemple #1
0
        /// <summary>
        /// Execute method.
        /// </summary>
        /// <param name="pipe">NamedPipeServerStream</param>
        public override void execute(NamedPipeServerStream pipe)
        {
            ReturnCode       returnCode       = ReturnCode.Success;
            ConfigSerializer configSerializer = new ConfigSerializer();

            byte[] messagebuffer  = new byte[100];
            byte[] originalbuffer = new byte[100];
            int    i = 0;

            do
            {
                pipe.Read(messagebuffer, 0, messagebuffer.Length);
                System.Buffer.BlockCopy(messagebuffer, 0, originalbuffer, i, messagebuffer.Length);
                Array.Resize(ref originalbuffer, originalbuffer.Length + 100);
                messagebuffer = new byte[100];
                i             = i + 100;
            }while (!pipe.IsMessageComplete);

            try
            {
                TypeCobolConfiguration config = new TypeCobolConfiguration();
                config        = configSerializer.Deserialize(originalbuffer);
                config.Format = TypeCobolOptionSet.CreateFormat(config.EncFormat, ref config);
                returnCode    = CLI.runOnce(config); //Try to run TypeCobol ad get status in returnCode
            }
            catch
            {
                returnCode = ReturnCode.FatalError;
            }
            finally
            {
                //Write a "reponse" to the client which is waiting
                pipe.WriteByte((byte)returnCode);
            }
        }
Exemple #2
0
        /// <summary>
        /// Handle the Configuration change notification.
        /// </summary>
        /// <param name="arguments">The arguments</param>
        public void DidChangeConfigurationParams(IEnumerable <string> arguments)
        {
            var options = TypeCobolOptionSet.GetCommonTypeCobolOptions(TypeCobolConfiguration);

            options.Parse(arguments);

            //Adding default copies folder
            var folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            TypeCobolConfiguration.CopyFolders.Add(folder + @"\DefaultCopies\");

            if (TypeCobolConfiguration.Telemetry)
            {
                AnalyticsWrapper.Telemetry.DisableTelemetry = false; //If telemetry arg is passed enable telemetry
            }
            if (TypeCobolConfiguration.ExecToStep >= ExecutionStep.Generate)
            {
                TypeCobolConfiguration.ExecToStep = ExecutionStep.SemanticCheck; //Language Server does not support Cobol Generation for now
            }
            var typeCobolOptions = new TypeCobolOptions
            {
                HaltOnMissingCopy = TypeCobolConfiguration.HaltOnMissingCopyFilePath != null,
                ExecToStep        = TypeCobolConfiguration.ExecToStep,
#if EUROINFO_RULES
                AutoRemarksEnable = TypeCobolConfiguration.AutoRemarks
#endif
            };

            CompilationProject = new CompilationProject(WorkspaceName, RootDirectoryFullName, Extensions, TypeCobolConfiguration.Format.Encoding, TypeCobolConfiguration.Format.EndOfLineDelimiter, TypeCobolConfiguration.Format.FixedLineLength, TypeCobolConfiguration.Format.ColumnsLayout, typeCobolOptions);

            if (OpenedFileCompiler.Count > 0)
            {
                RefreshOpenedFiles();
            }
            else
            {
                RefreshCustomSymbols();
            }
        }
Exemple #3
0
        static int Main(string[] argv)
        {
            bool        help        = false;
            bool        version     = false;
            bool        once        = false;
            StartClient startClient = StartClient.No;
            var         config      = new TypeCobolConfiguration();

            config.CommandLine = string.Join(" ", argv);
            var pipename = "TypeCobol.Server";

            var p = TypeCobolOptionSet.GetCommonTypeCobolOptions(config);

            //Add custom options for CLI
            p.Add(string.Format("USAGE\n {0} [OPTIONS]... [PIPENAME]\n VERSION:\n {1} \n DESCRIPTION: \n Run the TypeCObol parser server", PROGNAME, PROGVERSION));
            p.Add("k|startServer:",
                  "Start the server if not already started, and executes commandline.\n" + "By default the server is started in window mode\n" + "'{hidden}' hide the window.",
                  v =>
            {
                if ("hidden".Equals(v, StringComparison.InvariantCultureIgnoreCase))
                {
                    startClient = StartClient.HiddenWindow;
                }
                else
                {
                    startClient = StartClient.NormalWindow;
                }
            });
            p.Add("1|once", "Parse one set of files and exit. If present, this option does NOT launch the server.", v => once = (v != null));
            p.Add("h|help", "Output a usage message and exit.", v => help = (v != null));
            p.Add("V|version", "Output the version number of " + PROGNAME + " and exit.", v => version = (v != null));


            //Add DefaultCopies to running session
            var folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            config.CopyFolders.Add(folder + @"\DefaultCopies\");

            try {
                List <string> args;
                try {
                    args = p.Parse(argv);
                } catch (OptionException ex) {
                    return(exit(ReturnCode.FatalError, ex.Message));
                }

                if (help)
                {
                    p.WriteOptionDescriptions(Console.Out);
                    return(0);
                }
                if (version)
                {
                    Console.WriteLine(PROGVERSION);
                    return(0);
                }
                if (config.Telemetry)
                {
                    AnalyticsWrapper.Telemetry.DisableTelemetry = false; //If telemetry arg is passed enable telemetry
                }

                if (config.OutputFiles.Count == 0 && config.ExecToStep >= ExecutionStep.Generate)
                {
                    config.ExecToStep = ExecutionStep.SemanticCheck; //If there is no given output file, we can't run generation, fallback to SemanticCheck
                }
                if (config.OutputFiles.Count > 0 && config.InputFiles.Count != config.OutputFiles.Count)
                {
                    return(exit(ReturnCode.OutputFileError, "The number of output files must be equal to the number of input files."));
                }

                if (args.Count > 0)
                {
                    pipename = args[0];
                }


                //"startClient" will be true when "-K" is passed as an argument in command line.
                if (startClient != StartClient.No && once)
                {
                    pipename = "TypeCobol.Server";
                    using (NamedPipeClientStream namedPipeClient = new NamedPipeClientStream(pipename))
                    {
                        try {
                            namedPipeClient.Connect(100);
                        } catch (TimeoutException tEx) {
                            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                            if (startClient == StartClient.NormalWindow)
                            {
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                            }
                            else
                            {
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                            }
                            startInfo.FileName  = "cmd.exe";
                            startInfo.Arguments = @"/c " + folder + Path.DirectorySeparatorChar + "TypeCobol.CLI.exe";
                            process.StartInfo   = startInfo;
                            process.Start();

                            namedPipeClient.Connect(1000);
                        }

                        namedPipeClient.WriteByte(68);

                        ConfigSerializer configSerializer = new ConfigSerializer();
                        var configBytes = configSerializer.Serialize(config);

                        namedPipeClient.Write(configBytes, 0, configBytes.Length);
                        //Wait for the response "job is done"
                        var returnCode = namedPipeClient.ReadByte(); //Get running server ReturnCode
                        return(exit((ReturnCode)returnCode, ""));
                    }
                }

                //option -1
                else if (once)
                {
                    var returnCode = CLI.runOnce(config);
                    if (returnCode != ReturnCode.Success)
                    {
                        return(exit(returnCode, "Operation failled"));
                    }
                }
                else
                {
                    runServer(pipename);
                }
            }
            catch (Exception e) {
                AnalyticsWrapper.Telemetry.TrackException(e);
                return(exit(ReturnCode.FatalError, e.Message));
            }

            return(exit((int)ReturnCode.Success, "Success"));
        }
Exemple #4
0
        /// <summary>
        /// Handle the Configuration change notification.
        /// </summary>
        /// <param name="arguments">The arguments</param>
        public void DidChangeConfigurationParams(IEnumerable <string> arguments)
        {
            TypeCobolConfiguration = new TypeCobolConfiguration();
            var options = TypeCobolOptionSet.GetCommonTypeCobolOptions(TypeCobolConfiguration);

            var errors = TypeCobolOptionSet.InitializeCobolOptions(TypeCobolConfiguration, arguments, options);

            //Adding default copies folder
            var folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            TypeCobolConfiguration.CopyFolders.Add(folder + @"\DefaultCopies\");

            if (TypeCobolConfiguration.Telemetry)
            {
                AnalyticsWrapper.Telemetry.TelemetryVerboseLevel = TelemetryVerboseLevel.Completion; //If telemetry arg is passed enable telemetry
            }
            if (TypeCobolConfiguration.ExecToStep >= ExecutionStep.Generate)
            {
                TypeCobolConfiguration.ExecToStep = ExecutionStep.CrossCheck; //Language Server does not support Cobol Generation for now
            }
            var typeCobolOptions = new TypeCobolOptions
            {
                HaltOnMissingCopy = TypeCobolConfiguration.HaltOnMissingCopyFilePath != null,
                ExecToStep        = TypeCobolConfiguration.ExecToStep,
#if EUROINFO_RULES
                AutoRemarksEnable = TypeCobolConfiguration.AutoRemarks
#endif
            };

            CompilationProject = new CompilationProject(_workspaceName, _rootDirectoryFullName, _extensions, TypeCobolConfiguration.Format.Encoding, TypeCobolConfiguration.Format.EndOfLineDelimiter, TypeCobolConfiguration.Format.FixedLineLength, TypeCobolConfiguration.Format.ColumnsLayout, typeCobolOptions);

            if (TypeCobolConfiguration.CopyFolders != null && TypeCobolConfiguration.CopyFolders.Count > 0)
            {
                foreach (var copyFolder in TypeCobolConfiguration.CopyFolders)
                {
                    CompilationProject.SourceFileProvider.AddLocalDirectoryLibrary(copyFolder, false,
                                                                                   new[] { ".cpy" }, TypeCobolConfiguration.Format.Encoding,
                                                                                   TypeCobolConfiguration.Format.EndOfLineDelimiter, TypeCobolConfiguration.Format.FixedLineLength);
                }
            }

            if (OpenedFileCompiler.Count > 0)
            {
                RefreshOpenedFiles();
            }
            else
            {
                RefreshCustomSymbols();
            }

            //Dispose previous watcher before setting new ones
            _DepWatcher.Dispose();
            foreach (var depFolder in TypeCobolConfiguration.Dependencies)
            {
                _DepWatcher.SetDirectoryWatcher(depFolder);
            }
            foreach (var intrinsicFolder in TypeCobolConfiguration.Copies)
            {
                _DepWatcher.SetDirectoryWatcher(intrinsicFolder);
            }
        }