Example #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            Bootstrap = new Bootstrap();
            Shell     = new Shell();
            var unprocessed = Shell.ProcessArguments(args, Bootstrap.Container, typeof(TopLevelCommands));

            if (unprocessed.Length > 0)
            {
                log.Warn("Unprocessed arguments: " + string.Join(", ", unprocessed));
            }

            //simple console wait
            if (args.Length == 0)
            {
                InitComponents();
                ProcessLock.LockByKey();
                DisposeComponents();
            }
            else if (Shell.IsShellEnabled)
            {
                InitComponents();
                Shell.StartLineEditor();
                DisposeComponents();
            }
            Bootstrap.Dispose();
        }
Example #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            Bootstrap = new Bootstrap();
            Shell     = new Shell();
            var unprocessed = Shell.ProcessArguments(args, Bootstrap.Container, typeof(TopLevelCommands));

            if (unprocessed.Length > 0)
            {
                //var noServiceFlag = unprocessed.Where(x => x.Contains("no"));
                //if (noServiceFlag.Count()>0)
                //{
                //    unprocessed = unprocessed.Where(x => !noServiceFlag.Contains(x)).ToArray();
                //}
                if (unprocessed.Length > 0)
                {
                    log.Warn("Unprocessed arguments: " + string.Join(", ", unprocessed));
                }
            }

            //Bootstrap.Container.Resolve<PerformanceCountersTracker>().Start(
            //    TimeSpan.FromSeconds(10), "Performance");

            //simple console wait));)
            if (args.Length == 0)
            {
                InitComponents();
                ProcessLock.LockByKey();
                DisposeComponents();
            }
            else if (Shell.IsShellEnabled)
            {
                Shell.StartLineEditor();
            }
            Bootstrap.Dispose();

            //ProcessLock.LockByLine();
        }
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            //  If the application GUI shouldn't be loaded
            if (_preventGUILaunch)
            {
                return;
            }

            using (ProcessLock processLock = new ProcessLock(configMutex))
            {
                if (processLock.AlreadyExists)
                {
                    Log.Warn("Main: Configuration is already running");
                    Win32API.ActivatePreviousInstance();
                }

                // Check for a MediaPortal Instance running and don't allow Configuration to start
                using (ProcessLock mpLock = new ProcessLock(mpMutex))
                {
                    if (mpLock.AlreadyExists)
                    {
                        DialogResult dialogResult = MessageBox.Show(
                            "MediaPortal has to be closed for configuration.\nClose MediaPortal and start Configuration?",
                            "MediaPortal", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (dialogResult == DialogResult.Yes)
                        {
                            Util.Utils.KillProcess("Watchdog");
                            Util.Utils.KillProcess("MediaPortal");
                            Log.Info("MediaPortal closed, continue running Configuration.");
                        }
                        else
                        {
                            Log.Warn("Main: MediaPortal is running - start of Configuration aborted");
                            return;
                        }
                    }
                }

                string MpConfig = Assembly.GetExecutingAssembly().Location;
#if !DEBUG
                // Check TvPlugin version
                string tvPlugin = Config.GetFolder(Config.Dir.Plugins) + "\\Windows\\TvPlugin.dll";
                if (File.Exists(tvPlugin) && !_avoidVersionChecking)
                {
                    string tvPluginVersion = FileVersionInfo.GetVersionInfo(tvPlugin).ProductVersion;
                    string CfgVersion      = FileVersionInfo.GetVersionInfo(MpConfig).ProductVersion;
                    if (CfgVersion != tvPluginVersion)
                    {
                        string strLine = "TvPlugin and MediaPortal don't have the same version.\r\n";
                        strLine += "Please update the older component to the same version as the newer one.\r\n";
                        strLine += "MpConfig Version: " + CfgVersion + "\r\n";
                        strLine += "TvPlugin Version: " + tvPluginVersion;
                        MessageBox.Show(strLine, "MediaPortal", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Log.Info(strLine);
                        return;
                    }
                }
#endif

                FileInfo mpFi = new FileInfo(MpConfig);
                Log.Info("Assembly creation time: {0} (UTC)", mpFi.LastWriteTimeUtc.ToUniversalTime());

                Form applicationForm = null;

                Thumbs.CreateFolders();

                switch (startupMode)
                {
                case StartupMode.Normal:
                    Log.Info("Create new standard setup");
                    applicationForm = new SettingsForm(_debugOptions);
                    break;
                }

                if (applicationForm != null)
                {
                    Log.Info("start application");
                    Application.Run(applicationForm);
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            try
            {
                IFileSystem      iFileSystem  = new FileSystem();
                INetwork         iDownloader  = new Downloader();
                ILogger          iLogger      = new Logger("/home/brush/wrf/log.txt");
                IProcessLauncher iProcess     = new ProcessLauncher();
                IEnvironment     iEnvironment = new WrfSharp.Runner.Implementations.Environment();

                ProcessLock lockFile = ProcessLock.TryLock();
                if (lockFile != null)
                {
                    using (lockFile)
                    {
                        string connectionString =
                            ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
                        IDatabase iDatabase = MySQL.OpenConnection(connectionString);

                        iLogger.Log("Testing DB connectivity...");
                        if (!iDatabase.TestConnection())
                        {
                            iLogger.LogLine("....Connection failed. Check connection string.");
                        }
                        else
                        {
                            iLogger.LogLine("....Connection succeeded.");
                        }

                        List <PhysicsConfigurationProcessed> physicsConfigs = LoadPhysicsConfigurationsFromConfiguration();
                        iLogger.LogLine($"Loading configuration...");
                        WrfConfiguration config = LoadConfigurationFromAppSettings(iLogger);
                        iLogger.LogLine("...done");

                        string stateText = "Prepping";

                        _timer = new Timer(delegate(object state)
                        {
                            iDatabase.Checkin(stateText, DateTime.Now);
                        }, null, 0, 1000 * 60);

                        if (args.Length > 0 && args[0].ToLower() == "nodownload")
                        {
                            iLogger.LogLine("Downloading of new data skipped...");
                        }
                        else
                        {
                            PrepStage(iFileSystem, iDownloader, iLogger, iProcess, config);
                        }

                        Random rand = new Random();
                        physicsConfigs = physicsConfigs.OrderBy(m => rand.Next()).ToList();

                        // infinity if -1
                        if (config.MaximumNumberOfRuns == -1)
                        {
                            config.MaximumNumberOfRuns = int.MaxValue;
                        }

                        stateText = "Computing";

                        for (int c = 0; c < config.MaximumNumberOfRuns && c < physicsConfigs.Count; c++)
                        {
                            PhysicsConfigurationProcessed physicsConfig = physicsConfigs[c];
                            ComputeStage(iFileSystem, iLogger, iProcess,
                                         iEnvironment, iDatabase, config, physicsConfig);
                        }

                        iDatabase.Checkin("Done", DateTime.Now);
                    }
                }
                else
                {
                    //iLogger.LogLine("WrfSharp appears to be running already, or port 666 is in use.");
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText("crash.txt", ex.ToString());
            }
        }
Example #5
0
 public OrderedLock(ProcessLock nodeLock, ProcessLock dotnetLock)
 {
     NodeLock   = nodeLock;
     DotnetLock = dotnetLock;
 }