コード例 #1
0
ファイル: Program.cs プロジェクト: AlexandreBurel/pwiz-mzdb
        public static void Main( string[] args )
        {
            /*MSAnalysisClass a = new MSAnalysisClass();
            a.Open( @"C:\test\100 fmol BSA\0_B4\1\1SRef" );
            MSSpectrumCollection c = a.MSSpectrumCollection;
            MSSpectrum s = c[1];
            MSSpectrumParameterCollection sp = s.MSSpectrumParameterCollection;
            MSSpectrumParameter p = sp[1];*/
            /*IAnalysisFactory factory = new AnalysisFactory();
            IAnalysis a = factory.Open( @"C:\test\MM48pos_20uM_1-A,8_01_9111.d" );
            ITraceDeclaration[] tdList = a.GetTraceDeclarations();
            List<ITraceDataCollection> tdcList = new List<ITraceDataCollection>();
            foreach( ITraceDeclaration td in tdList )
                tdcList.Add( a.GetTraceDataCollection( td.TraceId ) );
            ISpectrumSourceDeclaration[] ssdList = a.GetSpectrumSourceDeclarations();
            List<ISpectrumCollection> scList = new List<ISpectrumCollection>();
            foreach( ISpectrumSourceDeclaration ssd in ssdList )
                scList.Add( a.GetSpectrumCollection( ssd.SpectrumCollectionId ) );*/

            // create machine-global mutex (to allow only one SeeMS instance)
            bool success;
            ipcMutex = new Mutex( true, "seems unique instance", out success );
            if( !success )
            {
                // send args to the existing instance
                using( NamedPipeClientStream pipeClient =
                    new NamedPipeClientStream( ".", "seems pipe", PipeDirection.Out ) )
                {
                    pipeClient.Connect();
                    using( StreamWriter sw = new StreamWriter( pipeClient ) )
                    {
                        sw.WriteLine( args.Length );
                        foreach( string arg in args )
                            sw.WriteLine( arg );
                        sw.Flush();
                    }
                    //pipeClient.WaitForPipeDrain();
                }
                return;
            }

            ipcWorker = new BackgroundWorker();
            ipcWorker.DoWork += new DoWorkEventHandler( bgWorker_DoWork );
            ipcWorker.RunWorkerAsync();

            // Add the event handler for handling UI thread exceptions to the event.
            Application.ThreadException += new ThreadExceptionEventHandler( UIThread_UnhandledException );

            // Set the unhandled exception mode to force all Windows Forms errors to go through
            // our handler.
            Application.SetUnhandledExceptionMode( UnhandledExceptionMode.CatchException );
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault( false );

            // Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );

            try
            {
                MainForm = new seemsForm();
                MainForm.ParseArgs(args);
                if (!MainForm.IsDisposed)
                    Application.Run(MainForm);
            }
            catch (Exception e)
            {
                string message = e.ToString();
                if (e.InnerException != null)
                    message += "\n\nAdditional information: " + e.InnerException.ToString();
                MessageBox.Show(message,
                                "Unhandled Exception",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            /*MSAnalysisClass a = new MSAnalysisClass();
             * a.Open( @"C:\test\100 fmol BSA\0_B4\1\1SRef" );
             * MSSpectrumCollection c = a.MSSpectrumCollection;
             * MSSpectrum s = c[1];
             * MSSpectrumParameterCollection sp = s.MSSpectrumParameterCollection;
             * MSSpectrumParameter p = sp[1];*/
            /*IAnalysisFactory factory = new AnalysisFactory();
             * IAnalysis a = factory.Open( @"C:\test\MM48pos_20uM_1-A,8_01_9111.d" );
             * ITraceDeclaration[] tdList = a.GetTraceDeclarations();
             * List<ITraceDataCollection> tdcList = new List<ITraceDataCollection>();
             * foreach( ITraceDeclaration td in tdList )
             *  tdcList.Add( a.GetTraceDataCollection( td.TraceId ) );
             * ISpectrumSourceDeclaration[] ssdList = a.GetSpectrumSourceDeclarations();
             * List<ISpectrumCollection> scList = new List<ISpectrumCollection>();
             * foreach( ISpectrumSourceDeclaration ssd in ssdList )
             *  scList.Add( a.GetSpectrumCollection( ssd.SpectrumCollectionId ) );*/

            // create machine-global mutex (to allow only one SeeMS instance)
            bool success;

            ipcMutex = new Mutex(true, "seems unique instance", out success);
            if (!success)
            {
                // send args to the existing instance
                using (NamedPipeClientStream pipeClient =
                           new NamedPipeClientStream(".", "seems pipe", PipeDirection.Out))
                {
                    pipeClient.Connect();
                    using (StreamWriter sw = new StreamWriter(pipeClient))
                    {
                        sw.WriteLine(args.Length);
                        foreach (string arg in args)
                        {
                            sw.WriteLine(arg);
                        }
                        sw.Flush();
                    }
                    //pipeClient.WaitForPipeDrain();
                }
                return;
            }

            ipcWorker         = new BackgroundWorker();
            ipcWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            ipcWorker.RunWorkerAsync();

            // Add the event handler for handling UI thread exceptions to the event.
            Application.ThreadException += new ThreadExceptionEventHandler(UIThread_UnhandledException);

            // Set the unhandled exception mode to force all Windows Forms errors to go through
            // our handler.
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            try
            {
                MainForm = new seemsForm();
                MainForm.ParseArgs(args);
                if (!MainForm.IsDisposed)
                {
                    Application.Run(MainForm);
                }
            }
            catch (Exception e)
            {
                string message = e.ToString();
                if (e.InnerException != null)
                {
                    message += "\n\nAdditional information: " + e.InnerException.ToString();
                }
                MessageBox.Show(message,
                                "Unhandled Exception",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
コード例 #3
0
        public static int Main(string[] args)
        {
            // redirect console output to parent process;
            // must be before any calls to Console.WriteLine()
            AttachConsole(ATTACH_PARENT_PROCESS);

            /*MSAnalysisClass a = new MSAnalysisClass();
             * a.Open( @"C:\test\100 fmol BSA\0_B4\1\1SRef" );
             * MSSpectrumCollection c = a.MSSpectrumCollection;
             * MSSpectrum s = c[1];
             * MSSpectrumParameterCollection sp = s.MSSpectrumParameterCollection;
             * MSSpectrumParameter p = sp[1];*/
            /*IAnalysisFactory factory = new AnalysisFactory();
             * IAnalysis a = factory.Open( @"C:\test\MM48pos_20uM_1-A,8_01_9111.d" );
             * ITraceDeclaration[] tdList = a.GetTraceDeclarations();
             * List<ITraceDataCollection> tdcList = new List<ITraceDataCollection>();
             * foreach( ITraceDeclaration td in tdList )
             *  tdcList.Add( a.GetTraceDataCollection( td.TraceId ) );
             * ISpectrumSourceDeclaration[] ssdList = a.GetSpectrumSourceDeclarations();
             * List<ISpectrumCollection> scList = new List<ISpectrumCollection>();
             * foreach( ISpectrumSourceDeclaration ssd in ssdList )
             *  scList.Add( a.GetSpectrumCollection( ssd.SpectrumCollectionId ) );*/

            // Add the event handler for handling UI thread exceptions to the event.
            Application.ThreadException += UIThread_UnhandledException;

            // Set the unhandled exception mode to force all Windows Forms errors to go through
            // our handler.
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;


            var singleInstanceHandler = new SingleInstanceHandler(Application.ExecutablePath)
            {
                Timeout = 200
            };

            singleInstanceHandler.Launching += (sender, e) =>
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                var singleInstanceArgs = e.Args.ToArray();

                MainForm = new seemsForm();
                MainForm.ParseArgs(singleInstanceArgs);
                if (!MainForm.IsDisposed)
                {
                    Application.Run(MainForm);
                }
                e.ExitCode = Environment.ExitCode;
            };

            try
            {
                TestMode = args.Contains("--test");
                return(singleInstanceHandler.Connect(args));
            }
            catch (Exception e)
            {
                HandleException("Error connecting to single instance", e);
                return(1);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: junli-song/pwiz
        public static void Main(string[] args)
        {
            // redirect console output to parent process;
            // must be before any calls to Console.WriteLine()
            AttachConsole(ATTACH_PARENT_PROCESS);

            /*MSAnalysisClass a = new MSAnalysisClass();
             * a.Open( @"C:\test\100 fmol BSA\0_B4\1\1SRef" );
             * MSSpectrumCollection c = a.MSSpectrumCollection;
             * MSSpectrum s = c[1];
             * MSSpectrumParameterCollection sp = s.MSSpectrumParameterCollection;
             * MSSpectrumParameter p = sp[1];*/
            /*IAnalysisFactory factory = new AnalysisFactory();
             * IAnalysis a = factory.Open( @"C:\test\MM48pos_20uM_1-A,8_01_9111.d" );
             * ITraceDeclaration[] tdList = a.GetTraceDeclarations();
             * List<ITraceDataCollection> tdcList = new List<ITraceDataCollection>();
             * foreach( ITraceDeclaration td in tdList )
             *  tdcList.Add( a.GetTraceDataCollection( td.TraceId ) );
             * ISpectrumSourceDeclaration[] ssdList = a.GetSpectrumSourceDeclarations();
             * List<ISpectrumCollection> scList = new List<ISpectrumCollection>();
             * foreach( ISpectrumSourceDeclaration ssd in ssdList )
             *  scList.Add( a.GetSpectrumCollection( ssd.SpectrumCollectionId ) );*/

            // Add the event handler for handling UI thread exceptions to the event.
            Application.ThreadException += new ThreadExceptionEventHandler(UIThread_UnhandledException);

            // Set the unhandled exception mode to force all Windows Forms errors to go through
            // our handler.
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


            var singleInstanceHandler = new SingleInstanceHandler(Application.ExecutablePath)
            {
                Timeout = 200
            };

            singleInstanceHandler.Launching += (sender, e) =>
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                var singleInstanceArgs = e.Args.ToArray();

                MainForm = new seemsForm();
                MainForm.ParseArgs(singleInstanceArgs);
                if (!MainForm.IsDisposed)
                {
                    Application.Run(MainForm);
                }
            };

            try
            {
                singleInstanceHandler.Connect(args);
            }
            catch (Exception e)
            {
                string message = e.ToString();
                if (e.InnerException != null)
                {
                    message += "\n\nAdditional information: " + e.InnerException.ToString();
                }
                MessageBox.Show(message,
                                "Unhandled Exception",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }