コード例 #1
0
ファイル: Program.cs プロジェクト: roundedsquare/Houhou-SRS
        public static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));

            // This app uses a mutex to make sure it is started only one time.
            // In this context, keep in mind that the mutex is the only
            // shared resource between instances of the application.

            // Acquire parameters.
            // There is one optional parameter:
            // 
            // [0] - Boolean - Indicates if the Main Window should be started.
            // - Default is True.

            RunMainWindow = (args.Any() ? ParsingHelper.ParseBool(args[0]) : null) ?? true;

            // Check the mutex.
            if (RunOnceMutex.WaitOne(TimeSpan.Zero, true))
            {
                // The application is not already running. So let's start it.
                Run();

                // Once the application is shutdown, release the mutex.
                RunOnceMutex.ReleaseMutex();
            }
            else
            {
                // The application is already running.
                // Transmit a command to open/focus the main window using the pipe system.
                using (NamedPipeHandler handler = new NamedPipeHandler(InstanceHelper.InterfaceApplicationGuid))
                {
                    handler.Write(PipeMessageEnum.OpenOrFocus.ToString());
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: roundedsquare/Houhou-SRS
        /// <summary>
        /// Initializes the application, runs it, and manages
        /// the resources.
        /// </summary>
        public static void Run()
        {
            // Initialize the logging system.
            LogHelper.InitializeLoggingSystem();

            // Initialize settings.
            InitializeUserSettings();

            // Initialize the configuration system.
            ConfigurationHelper.InitializeConfiguration();

            // Create the application.
            App app = new App();

            // Load the navigation actor.
            NavigationActor.Instance = new NavigationActor();

            // Start loading user resources.
            RadicalStore.Instance.InitializeAsync();
            SrsLevelStore.Instance.InitializeAsync();

            // Load the autostart configuration.
            AutostartBusiness.Instance.Load();

            // Start the version business.
            VersionBusiness.Initialize();

            // Start the SRS business.
            SrsBusiness.Initialize();

            using (NamedPipeHandler pipeHandler = new NamedPipeHandler(InstanceHelper.InterfaceApplicationGuid))
            {
                // Listen for incoming pipe messages, to allow other processes to
                // communicate with this one.
                PipeActor.Initialize(pipeHandler);
                pipeHandler.StartListening();

                // Run the app.
                app.InitializeComponent();
                AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
                app.DispatcherUnhandledException += OnUnhandledException;
                TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
                app.Run();

                // The execution blocks here until the application exits.
            }
        }
コード例 #3
0
ファイル: PipeActor.cs プロジェクト: roundedsquare/Houhou-SRS
 private PipeActor(NamedPipeHandler handler)
 {
     _handler = handler;
     _handler.MessageReceived += OnMessageReceived;
 }
コード例 #4
0
ファイル: PipeActor.cs プロジェクト: roundedsquare/Houhou-SRS
 /// <summary>
 /// Creates and initializes the instance.
 /// </summary>
 public static void Initialize(NamedPipeHandler handler)
 {
     Instance = new PipeActor(handler);
 }