Beispiel #1
0
        static void Main(string[] args)
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

            Uri uri = null;

            if (args.Length > 0)
            {
                // a URI was passed and needs to be handled
                try {
                    uri = new Uri(args[0].Trim());
                }
                catch (UriFormatException) {
                    Console.WriteLine("Invalid URI.");
                }
            }

            IUriHandler handler = UriHandler.GetHandler();

            if (handler != null)
            {
                // the singular instance of the application is already running
                if (uri != null)
                {
                    handler.HandleUri(uri);
                }

                // the process will now exit without displaying the main form
                //...
            }
            else
            {
                // this must become the singular instance of the application
                UriHandler.Register();

                MainForm  = new MainForm();
                NetClient = new CardboardRealityNetClient();
                NetClient.Initialize();

                if (uri != null)
                {
                    // a URI was passed, handle it locally
                    MainForm.Shown += (o, e) => new UriHandler().HandleUri(uri);
                }

                NetClientUpdateTimer.Tick += new EventHandler(TimerEventProcessor);

                // Sets the timer interval to 5 seconds.
                NetClientUpdateTimer.Interval = 50;
                NetClientUpdateTimer.Start();

                // load and display the main form
                System.Windows.Forms.Application.Run(MainForm);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the URI handler from the singular instance of the application, or null if there is no other instance.
        /// </summary>
        /// <returns></returns>
        public static IUriHandler GetHandler()
        {
            try {
                IpcClientChannel channel = new IpcClientChannel();
                ChannelServices.RegisterChannel(channel, true);
                string      address = String.Format("ipc://{0}/UriHandler", IPC_CHANNEL_NAME);
                IUriHandler handler = (IUriHandler)RemotingServices.Connect(typeof(IUriHandler), address);

                // need to test whether connection was established
                TextWriter.Null.WriteLine(handler.ToString());

                return(handler);
            }
            catch {
                Console.WriteLine("Couldn't get remote UriHandler object.");
                Console.WriteLine();
            }

            return(null);
        }