Esempio n. 1
0
 static ISolution LoadSolution(string solutionPath, Logger logger)
 {
     solutionPath = solutionPath.ApplyPathReplacementsForServer();
     ISolution solution;
     if (Directory.Exists(solutionPath))
     {
         var slnFiles = Directory.GetFiles(solutionPath, "*.sln");
         Console.WriteLine(slnFiles.Length);
         if (slnFiles.Length == 1)
         {
             solutionPath = slnFiles[0];
             logger.Debug("Found solution file - " + solutionPath);
             solution = new CSharpSolution(solutionPath, logger);
         }
         else
         {
             solution = new CSharpFolder(solutionPath, logger);
         }
     }
     else
     {
         solution = new CSharpSolution(solutionPath, logger);
     }
     return solution;
 }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            bool showHelp = false;
            string solutionPath = null;

            int port = 2000;

            var p = new OptionSet
                        {
                            {
                                "s|solution=", "The path to the solution file",
                                v => solutionPath = v
                            },
                            {
                                "p|port=", "Port number to listen on",
                                (int v) => port = v
                            },
                            {
                                "h|help", "show this message and exit",
                                v => showHelp = v != null
                            },
                        };

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'omnisharp --help' for more information.");
                return;
            }

            showHelp |= solutionPath == null;

            if (showHelp)
            {
                ShowHelp(p);
                return;
            }

            var solution = new CSharpSolution(solutionPath);

            var nancyHost = new NancyHost(new Bootstrapper(solution), new Uri("http://localhost:" + port));

            nancyHost.Start();

            Console.ReadLine();
            nancyHost.Stop();
        }
Esempio n. 3
0
        private static void StartServer(string solutionPath, int port, bool verbose)
        {
            try
            {
                Configuration.ConfigurationLoader.Load();
                var solution = new CSharpSolution();
                Console.CancelKeyPress +=
                    (sender, e) =>
                        {
                            solution.Terminated = true;
                            Console.WriteLine("Ctrl-C pressed");
                            e.Cancel = true;
                        };

                var nancyHost = new NancyHost(new Bootstrapper(solution, new NativeFileSystem(), verbose), new HostConfiguration{RewriteLocalhost=false}, new Uri("http://localhost:" + port));

                nancyHost.Start();
                Console.WriteLine("OmniSharp server is listening");
                solution.LoadSolution(solutionPath);
                Console.WriteLine("Solution has finished loading");
                while (!solution.Terminated)
                {
                    Thread.Sleep(1000);
                }

                Console.WriteLine("Quit gracefully");
                nancyHost.Stop();
            }
            catch(Exception e)
            {
                if(e is SocketException || e is HttpListenerException)
                {
                    Console.Error.WriteLine("Detected an OmniSharp instance already running on port " + port + ". Press a key.");
                    Console.ReadKey();
                    return;
                }
                throw;
            }
        }
Esempio n. 4
0
        private static void StartServer(string solutionPath, int port, bool verbose)
        {
            var lockfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lockfile-" + port);

            try
            {
                using (new FileStream(lockfile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
                {
                    var solution = new CSharpSolution(solutionPath);
                    Console.CancelKeyPress +=
                        (sender, e) =>
                            {
                                solution.Terminated = true;
                                Console.WriteLine("Ctrl-C pressed");
                                e.Cancel = true;
                            };

                    var nancyHost = new NancyHost(new Bootstrapper(solution, verbose), new Uri("http://localhost:" + port));

                    nancyHost.Start();

                    while (!solution.Terminated)
                    {
                        Thread.Sleep(1000);
                    }
                    
                    Console.WriteLine("Quit gracefully");
                    nancyHost.Stop();
                }
                DeleteLockFile(lockfile);
            }
            catch (IOException)
            {
                Console.WriteLine("Detected an OmniSharp instance already running on port " + port + ". Press a key.");
                Console.ReadKey();
            }
        }
Esempio n. 5
0
 public SolutionTest()
 {
     _solution = new CSharpSolution (new Logger (Verbosity.Verbose));
     _solution.LoadSolution (Environment.CurrentDirectory + "/Solution/minimal/minimal.sln");
 }
Esempio n. 6
0
        private static void StartServer(string solutionPath, string clientPathMode, int port, Verbosity verbosity)
        {
            var logger = new Logger(verbosity);
            try
            {
                Configuration.ConfigurationLoader.Load(clientPathMode);

                ISolution solution;
                if(Directory.Exists(solutionPath))
                {
                    solution = new CSharpFolder(logger);
                }
                else
                {
                    solution = new CSharpSolution(logger);
                }

                Console.CancelKeyPress +=
                    (sender, e) =>
                        {
                            solution.Terminate();
                            Console.WriteLine("Ctrl-C pressed");
                            e.Cancel = true;
                        };
                var nancyHost = new NancyHost(new Bootstrapper(
                                                solution,
                                                new NativeFileSystem(),
                                                logger),
                                                new HostConfiguration{RewriteLocalhost=false},
                                                new Uri("http://localhost:" + port));

                nancyHost.Start();
                logger.Debug("OmniSharp server is listening");
                solution.LoadSolution(solutionPath.ApplyPathReplacementsForServer());
                logger.Debug("Solution has finished loading");
                while (!solution.Terminated)
                {
                    Thread.Sleep(1000);
                }

                Console.WriteLine("Quit gracefully");
                nancyHost.Stop();
            }
            catch(Exception e)
            {
                if(e is SocketException || e is HttpListenerException)
                {
                    logger.Error("Detected an OmniSharp instance already running on port " + port + ". Press a key.");
                    Console.ReadKey();
                    return;
                }
                throw;
            }
        }
Esempio n. 7
0
 public SolutionTest()
 {
     var path = Environment.CurrentDirectory + "/Solution/minimal/minimal.sln";
     _solution = new CSharpSolution (new FileSystem(), path, new Logger(Verbosity.Verbose));
     _solution.LoadSolution ();
 }