Ejemplo n.º 1
0
 private static bool CheckSingleInstance(string[] args, SingleInstanceHelper singleInstance)
 {
     try
     {
         if (!singleInstance.Start())
         {
             SingleInstanceHelper.SignalFirstInstance(args);
             return(false);
         }
     }
     catch (RemotingException ex)
     {
         DialogResult result = MessageBox.Show(Properties.Resources.RemotingFailedQuestion,
                                               Core.Application.NameAndVersion, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (result == DialogResult.No)
         {
             ShowStartupError(ex, Properties.Resources.RemotingCallFailed);
             return(false);
         }
     }
     catch (Exception ex)
     {
         ShowStartupError(ex, Properties.Resources.RemotingCallFailed);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 private bool CheckSingleInstance()
 {
     try
     {
         bool singleInstance = SingleInstanceHelper.Start();
         if (!singleInstance)
         {
             SingleInstanceHelper.SignalFirstInstance(Args);
         }
         return(singleInstance);
     }
     catch (RemotingException ex)
     {
         var result = MessageBox.Show(Properties.Resources.RemotingFailedQuestion,
                                      Core.Application.NameAndVersion, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (result == DialogResult.No)
         {
             throw new StartupException(Properties.Resources.RemotingCallFailed, ex);
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw new StartupException(Properties.Resources.RemotingCallFailed, ex);
     }
 }
Ejemplo n.º 3
0
 private static void RegisterIpcChannel(MainForm mainForm)
 {
     try
     {
         SingleInstanceHelper.RegisterIpcChannel((s, e) =>
         {
             mainForm.SecondInstanceStarted(e.Args);
         });
     }
     catch (Exception ex)
     {
         throw new StartupException(Properties.Resources.IpcRegisterFailed, ex);
     }
 }
Ejemplo n.º 4
0
 private static bool RegisterIpcChannel(IWindsorContainer container)
 {
     try
     {
         SingleInstanceHelper.RegisterIpcChannel((s, e) =>
         {
             var mainView = container.Resolve <IMainView>();
             mainView.SecondInstanceStarted(e.Args);
         });
     }
     catch (Exception ex)
     {
         ShowStartupError(ex, Properties.Resources.IpcRegisterFailed);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 5
0
      internal static void Execute(string[] args, IWindsorContainer container)
      {
         var arguments = Arguments.Parse(args);
         var errorArguments = arguments.Where(x => x.Type == ArgumentType.Unknown || x.Type == ArgumentType.Error).ToList();
         if (errorArguments.Count != 0)
         {
            MessageBox.Show(Arguments.GetUsageMessage(errorArguments), Core.Application.NameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
         }

         AppDomain.CurrentDomain.AssemblyResolve += (s, e) => CustomResolve(e, container);

         // Issue 180 - Restore the already running instance to the screen.
         using (var singleInstance = new SingleInstanceHelper())
         {
            if (!CheckSingleInstance(args, singleInstance))
            {
               return;
            }

            var logger = container.Resolve<ILogger>();
            InitializeLogging(container, logger);

            if (!CheckMonoVersion(logger))
            {
               return;
            }

            var prefs = container.Resolve<IPreferenceSet>();
            if (!InitializePreferences(prefs, logger, arguments.Any(x => x.Type == ArgumentType.ResetPrefs)))
            {
               return;
            }

            if (!ClearCacheFolder(prefs.CacheDirectory, logger))
            {
               return;
            }

            LoadPlugins(container);

            if (!RegisterIpcChannel(container))
            {
               return;
            }

            var mainView = container.Resolve<IMainView>();
            if (!InitializeMainView(container, arguments, mainView))
            {
               return;
            }

            ExceptionDialog.RegisterForUnhandledExceptions(
               Core.Application.NameAndVersionWithRevision, 
               Environment.OSVersion.VersionString, 
               ex => logger.Error(ex.Message, ex));

            System.Windows.Forms.Application.ApplicationExit += (s, e) =>
            {
               // Save preferences
               prefs.Save();
               // Save the benchmark collection
               var benchmarkContainer = container.Resolve<IProteinBenchmarkCollection>();
               benchmarkContainer.Write();
            };
            System.Windows.Forms.Application.Run((Form)mainView);
         }
      }
Ejemplo n.º 6
0
 private static bool CheckSingleInstance(string[] args, SingleInstanceHelper singleInstance)
 {
    try
    {
       if (!singleInstance.Start())
       {
          SingleInstanceHelper.SignalFirstInstance(args);
          return false;
       }
    }
    catch (RemotingException ex)
    {
       DialogResult result = MessageBox.Show(Properties.Resources.RemotingFailedQuestion, 
          Core.Application.NameAndVersion, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
       if (result == DialogResult.No)
       {
          ShowStartupError(ex, Properties.Resources.RemotingCallFailed);
          return false;
       }
    }
    catch (Exception ex)
    {
       ShowStartupError(ex, Properties.Resources.RemotingCallFailed);
       return false;
    }
    return true;
 }
Ejemplo n.º 7
0
        internal static void Execute(string[] args, IWindsorContainer container)
        {
            var arguments      = Arguments.Parse(args);
            var errorArguments = arguments.Where(x => x.Type == ArgumentType.Unknown || x.Type == ArgumentType.Error).ToList();

            if (errorArguments.Count != 0)
            {
                MessageBox.Show(Arguments.GetUsageMessage(errorArguments), Core.Application.NameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            AppDomain.CurrentDomain.AssemblyResolve += (s, e) => CustomResolve(e, container);

            // Issue 180 - Restore the already running instance to the screen.
            using (var singleInstance = new SingleInstanceHelper())
            {
                if (!CheckSingleInstance(args, singleInstance))
                {
                    return;
                }

                var logger = container.Resolve <ILogger>();
                InitializeLogging(container, logger);

                if (!CheckMonoVersion(logger))
                {
                    return;
                }

                var prefs = container.Resolve <IPreferenceSet>();
                if (!InitializePreferences(prefs, logger, arguments.Any(x => x.Type == ArgumentType.ResetPrefs)))
                {
                    return;
                }

                if (!ClearCacheFolder(prefs.CacheDirectory, logger))
                {
                    return;
                }

                LoadPlugins(container);

                if (!RegisterIpcChannel(container))
                {
                    return;
                }

                var mainView = container.Resolve <IMainView>();
                if (!InitializeMainView(container, arguments, mainView))
                {
                    return;
                }

                ExceptionDialog.RegisterForUnhandledExceptions(
                    Core.Application.NameAndVersionWithRevision,
                    Environment.OSVersion.VersionString,
                    ex => logger.Error(ex.Message, ex));

                System.Windows.Forms.Application.ApplicationExit += (s, e) =>
                {
                    // Save preferences
                    prefs.Save();
                };
                System.Windows.Forms.Application.Run((Form)mainView);
            }
        }
Ejemplo n.º 8
0
        public void Strap(string[] args)
        {
            #region Parse Arguments

             IEnumerable<Argument> arguments = Arguments.Parse(args);
             IEnumerable<Argument> errorArguments = arguments.Where(x => x.Type == ArgumentType.Unknown || x.Type == ArgumentType.Error);
             if (errorArguments.Count() != 0)
             {
            MessageBox.Show(Arguments.GetUsageMessage(errorArguments), Core.Application.NameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
             }

             #endregion

             #region Process Arguments

             _prefs.Process(arguments);

             #endregion

             try
             {
            _prefs.Initialize();
             }
             catch (Exception ex)
             {
            ShowStartupError(ex, Properties.Resources.UserPreferencesFailed);
            return;
             }

             // Issue 180 - Restore the already running instance to the screen.
             using (var singleInstance = new SingleInstanceHelper())
             {
            #region Check Single Instance

            try
            {
               if (!singleInstance.Start())
               {
                  SingleInstanceHelper.SignalFirstInstance(args);
                  return;
               }
            }
            catch (RemotingException ex)
            {
               if (MessageBox.Show(Properties.Resources.RemotingFailedQuestion, Core.Application.NameAndVersion, MessageBoxButtons.YesNo, MessageBoxIcon.Warning).Equals(DialogResult.No))
               {
                  ShowStartupError(ex, Properties.Resources.RemotingCallFailed);
                  return;
               }
            }
            catch (Exception ex)
            {
               ShowStartupError(ex, Properties.Resources.RemotingCallFailed);
               return;
            }

            #endregion

            #region Setup Logging

            // create messages view (hooks into logging messages)
            ServiceLocator.Resolve<IMessagesView>();
            // write log header
            _logger = ServiceLocator.Resolve<ILogger>();
            _logger.Info(String.Empty);
            _logger.Info(String.Format(CultureInfo.InvariantCulture, "Starting - HFM.NET v{0}", Core.Application.VersionWithRevision));
            _logger.Info(String.Empty);
            // check for Mono runtime
            if (Core.Application.IsRunningOnMono)
            {
               Version monoVersion = null;
               try
               {
                  monoVersion = Core.Application.GetMonoVersionNumer();
               }
               catch (Exception ex)
               {
                  _logger.Warn(Properties.Resources.MonoDetectFailed, ex);
               }

               if (monoVersion != null)
               {
                  try
                  {
                     ValidateMonoVersion(monoVersion);
                  }
                  catch (InvalidOperationException ex)
                  {
                     ShowStartupError(ex, ex.Message);
                     return;
                  }
                  _logger.Info("Running on Mono v{0}...", monoVersion);
               }
               else
               {
                  _logger.Info("Running on Mono...");
               }
            }

            #endregion

            #region Setup Cache Folder

            try
            {
               ClearCacheFolder();
            }
            catch (Exception ex)
            {
               ShowStartupError(ex, Properties.Resources.CacheSetupFailed);
               return;
            }

            #endregion

            #region Load Plugins

            var pluginLoader = ServiceLocator.Resolve<Core.Plugins.PluginLoader>();
            pluginLoader.Load();

            #endregion

            #region Register IPC Channel

            try
            {
               SingleInstanceHelper.RegisterIpcChannel(NewInstanceDetected);
            }
            catch (Exception ex)
            {
               ShowStartupError(ex, Properties.Resources.IpcRegisterFailed);
               return;
            }

            #endregion

            #region Initialize Main View

            var mainView = ServiceLocator.Resolve<IMainView>();
            var mainPresenter = ServiceLocator.Resolve<MainPresenter>();
            mainPresenter.Arguments = arguments;
            try
            {
               mainView.Initialize(mainPresenter);
            }
            catch (Exception ex)
            {
               ShowStartupError(ex, Properties.Resources.FailedToInitUI);
               return;
            }

            mainView.WorkUnitHistoryMenuEnabled = false;
            var database = ServiceLocator.Resolve<IUnitInfoDatabase>();
            if (database.Connected)
            {
               database.UpgradeExecuting += DatabaseUpgradeExecuting;
               try
               {
                  database.Upgrade();
                  mainView.WorkUnitHistoryMenuEnabled = true;
               }
               catch (Exception ex)
               {
                  ShowStartupError(ex, Properties.Resources.WuHistoryUpgradeFailed, false);
               }
               finally
               {
                  database.UpgradeExecuting -= DatabaseUpgradeExecuting;
               }
            }

            #endregion

            #region Register the Unhandled Exception Dialog

            ExceptionDialog.RegisterForUnhandledExceptions(Core.Application.NameAndVersionWithRevision,
               Environment.OSVersion.VersionString, ExceptionLogger);

            #endregion

            System.Windows.Forms.Application.Run((Form)mainView);
             }
        }