/* unused code

        static void ShowErrorBox(object sender, ThreadExceptionEventArgs eargs)
        {
            ExceptionDialog ed;

            ed = new ExceptionDialog(eargs.Exception);
            ed.AddButtonHandler(new ButtonHandler(DialogResultHandler));
            ed.ShowAll();
        }

        static void DialogResultHandler(ExceptionDialog ed, DialogResult dr) {
            ed.Destroy();
        }
        */
        /// <summary>
        /// Starts the core of MonoDevelop.
        /// </summary>
        public static int Main(string[] args)
        {
            MonoDevelopOptions options = new MonoDevelopOptions ();
            options.ProcessArgs (args);
            string[] remainingArgs = options.RemainingArguments;

            string socket_filename = "/tmp/md-" + Environment.GetEnvironmentVariable ("USER") + "-socket";
            listen_socket = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
            EndPoint ep = new UnixEndPoint (socket_filename);

            // only reuse if we are being passed in a file
            if (remainingArgs.Length > 0 && File.Exists (socket_filename))
            {
                try
                {
                    listen_socket.Connect (ep);
                    listen_socket.Send (Encoding.UTF8.GetBytes (String.Join ("\n", remainingArgs)));
                    return 0;
                }
                catch
                {
                }
            }

            // why was this here
            // File.Delete (socket_filename);

            string name = Assembly.GetEntryAssembly ().GetName ().Name;
            string version = Assembly.GetEntryAssembly ().GetName ().Version.Major + "." + Assembly.GetEntryAssembly ().GetName ().Version.Minor;
            if (Assembly.GetEntryAssembly ().GetName ().Version.Build != 0)
                version += "." + Assembly.GetEntryAssembly ().GetName ().Version.Build;
            if (Assembly.GetEntryAssembly ().GetName ().Version.Revision != 0)
                version += "." + Assembly.GetEntryAssembly ().GetName ().Version.Revision;

            new Gnome.Program (name, version, Gnome.Modules.UI, remainingArgs);
            Gdk.Threads.Init();
            commandLineArgs = remainingArgs;

            //remoting check
            try {
                Dns.GetHostByName (Dns.GetHostName ());
            } catch {
                ErrorDialog dialog = new ErrorDialog (null);
                dialog.Message = "MonoDevelop failed to start. Local hostname cannot be resolved.";
                dialog.AddDetails ("Your network may be misconfigured. Make sure the hostname of your system is added to the /etc/hosts file.", true);
                dialog.Run ();
                return 1;
            }

            SplashScreenForm.SetCommandLineArgs(remainingArgs);

            if (!options.nologo) {
                SplashScreenForm.SplashScreen.ShowAll ();
                RunMainLoop ();
            }

            SetSplashInfo(0.05, "Initializing Addins ...");
            bool ignoreDefaultPath = false;
            string [] addInDirs = MonoDevelop.AddInSettingsHandler.GetAddInDirectories(out ignoreDefaultPath);
            AddInTreeSingleton.SetAddInDirectories(addInDirs, ignoreDefaultPath);
            RunMainLoop ();

            ArrayList commands = null;
            Exception error = null;

            try {
                SetSplashInfo(0.1, "Initializing Icon Service ...");
                ServiceManager.AddService(new IconService());
                SetSplashInfo(0.2, "Initializing Message Service ...");
                ServiceManager.AddService(new MessageService());
                SetSplashInfo(0.4, "Initializing Resource Service ...");
                ServiceManager.AddService(new ResourceService());
                SetSplashInfo(0.6, "Initializing Addin Services ...");

                AddinError[] errors = AddInTreeSingleton.InitializeAddins ();
                if (errors != null && errors.Length > 0) {
                    SplashScreenForm.SplashScreen.Hide ();
                    AddinLoadErrorDialog dlg = new AddinLoadErrorDialog (errors);
                    if (!dlg.Run ())
                        return 1;
                    SplashScreenForm.SplashScreen.Show ();
                    RunMainLoop ();
                }
                ServiceManager.InitializeServicesSubsystem("/Workspace/Services");

                SetSplashInfo(0.8, "Initializing Autostart Addins ...");
                commands = AddInTreeSingleton.AddInTree.GetTreeNode("/Workspace/Autostart").BuildChildItems(null);
                SetSplashInfo(1, "Loading MonoDevelop Workbench ...");
                RunMainLoop ();
                for (int i = 0; i < commands.Count - 1; ++i) {
                    ((ICommand)commands[i]).Run();
                    RunMainLoop ();
                }

                // no alternative for Application.ThreadException?
                // Application.ThreadException += new ThreadExceptionEventHandler(ShowErrorBox);

            } catch (Exception e) {
                error = e;
            } finally {
                if (SplashScreenForm.SplashScreen != null) {
                    SplashScreenForm.SplashScreen.Hide();
                }
            }

            if (error != null) {
                ErrorDialog dialog = new ErrorDialog (null);
                dialog.Message = "MonoDevelop failed to start. The following error has been reported: " + error.Message;
                dialog.AddDetails (error.ToString (), false);
                dialog.Run ();
                return 1;
            }

            // FIXME: we should probably track the last 'selected' one
            // and do this more cleanly
            try
            {
                listen_socket.Bind (ep);
                listen_socket.Listen (5);
                listen_socket.BeginAccept (new AsyncCallback (ListenCallback), listen_socket);
            }
            catch
            {
                Console.WriteLine ("Socket already in use");
            }

            // run the last autostart command, this must be the workbench starting command
            if (commands.Count > 0) {
                RunMainLoop ();
                ((ICommand)commands[commands.Count - 1]).Run();
            }

            // unloading services
            File.Delete (socket_filename);
            ServiceManager.UnloadAllServices();
            System.Environment.Exit (0);
            return 0;
        }
Esempio n. 2
0
		private bool CreateUnixSocketStream(string socketName)
		{
#if __MonoCS__ && !WINDOWS
			Socket socket = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);

			try
			{
				UnixEndPoint endPoint = new UnixEndPoint (socketName);
				socket.Connect (endPoint);
				stream = new NetworkStream (socket, true);
				return true;
			}
			catch (Exception ex)
			{
				baseException = ex;
				return false;
			}
#else
			baseException = new PlatformNotSupportedException ("This is not a Unix");
			return false;
#endif
		}
Esempio n. 3
0
		private Stream CreateUnixSocketStream() 
		{
#if __MonoCS__ && !WINDOWS

			Socket socket = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);

			try
			{
				UnixEndPoint endPoint = new UnixEndPoint (hostList);
				socket.Connect (endPoint);
				return new NetworkStream (socket, true);
			}
			catch (Exception ex)
			{
				return null;
			}
#else
			throw new PlatformNotSupportedException ("Unix sockets are only supported on this platform");
#endif		
		}