Esempio n. 1
0
 static bool tryGetStartupState(IDictionary<string, object> properties, out StartupState state)
 {
     object stateOb;
     if (properties.TryGetValue(KEY_STARTUP_STATE, out stateOb))
     {
         state = (StartupState)stateOb;
         return true;
     }
     state = StartupState.EMULATORS;
     return false;
 }
Esempio n. 2
0
 public static List<StartupStateHandler> GetStartupOptions(out StartupState selectedValue)
 {
     selectedValue = EmulatorsCore.Options.ReadOption(o => o.StartupState);
     List<StartupStateHandler> opts = new List<StartupStateHandler>();
     opts.Add(new StartupStateHandler() { Name = StartupState.LASTUSED.Translate(), Value = StartupState.LASTUSED });
     opts.Add(new StartupStateHandler() { Name = StartupState.EMULATORS.Translate(), Value = StartupState.EMULATORS });
     opts.Add(new StartupStateHandler() { Name = StartupState.GROUPS.Translate(), Value = StartupState.GROUPS });
     opts.Add(new StartupStateHandler() { Name = StartupState.PCGAMES.Translate(), Value = StartupState.PCGAMES });
     opts.Add(new StartupStateHandler() { Name = StartupState.FAVOURITES.Translate(), Value = StartupState.FAVOURITES });
     return opts;
 }
Esempio n. 3
0
        private void UpdateStartWithWindows()
        {
            ready = false;

            cbStartWithWindows.Text    = Resources.ApplicationSettingsForm_cbStartWithWindows_Text;
            cbStartWithWindows.Enabled = false;

            try
            {
                StartupState state = StartupManagerSingletonProvider.CurrentStartupManager.State;
                cbStartWithWindows.Checked = state == StartupState.Enabled || state == StartupState.EnabledByPolicy;

                if (state == StartupState.DisabledByUser)
                {
                    cbStartWithWindows.Text = Resources.ApplicationSettingsForm_cbStartWithWindows_DisabledByUser_Text;
                }
                else if (state == StartupState.DisabledByPolicy)
                {
                    cbStartWithWindows.Text = Resources.ApplicationSettingsForm_cbStartWithWindows_DisabledByPolicy_Text;
                }
                else if (state == StartupState.EnabledByPolicy)
                {
                    cbStartWithWindows.Text = Resources.ApplicationSettingsForm_cbStartWithWindows_EnabledByPolicy_Text;
                }
                else
                {
                    cbStartWithWindows.Enabled = true;
                }
            }
            catch (Exception e)
            {
                e.ShowError();
            }

            ready = true;
        }
Esempio n. 4
0
        public static StartupState ShowViewsDialog(StartupState currentState, bool showPC)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(Translator.Instance.switchview);

                int index = (int)currentState;

                dlg.Add(new GUIListItem(Translator.Instance.viewemulators));
                dlg.Add(new GUIListItem(Translator.Instance.viewgroups));
                dlg.Add(new GUIListItem(Translator.Instance.favourites));

                if (showPC)
                    dlg.Add(new GUIListItem(Translator.Instance.pcgames));
                else if (currentState == StartupState.PCGAMES)
                    index = 0;
                
                dlg.SelectedLabel = index;
                dlg.DoModal(Plugin.WINDOW_ID);

                index = dlg.SelectedLabel;
                if (index > -1)
                    return (StartupState)index;
            }
            return currentState;
        }
Esempio n. 5
0
 protected void SetStartupState(StartupState startupState)
 {
     var model = EmulatorsMainModel.Instance();
     model.StartupState = startupState;
 }
Esempio n. 6
0
        /// <summary>
        /// Stops the service.
        /// </summary>
        public void Stop()
        {
            m_Diagnostics.Log(
                LevelToLog.Trace,
                HostConstants.LogPrefix,
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.Kernel_LogMessage_StoppingService_WithType,
                    GetType()));

            m_StartupState = StartupState.Stopping;
            try
            {
                StopService();
                m_StartupState = StartupState.Stopped;

                m_Diagnostics.Log(
                    LevelToLog.Trace,
                    HostConstants.LogPrefix,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.Kernel_LogMessage_ServiceStopped_WithType,
                        GetType()));
            }
            catch (Exception e)
            {
                m_StartupState = StartupState.Failed;

                m_Diagnostics.Log(
                    LevelToLog.Trace,
                    HostConstants.LogPrefix,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.Kernel_LogMessage_FailedToStopService_WithTypeAndError,
                        GetType(),
                        e));

                throw;
            }
        }
Esempio n. 7
0
        private void WatchdogTimerCallback(Object o)
        {
            IAMDatabase db = null;

            try
            {
                //check if we need to stop any service
                db = new IAMDatabase(localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword);
                db.openDB();
                db.Timeout = 600;

                //Limpa status lixo
                db.ExecuteNonQuery("delete from service_status where last_status < DATEADD(day,-15,getdate())");

                //seleciona os servicos comproblema ou parados
                DataTable dtServices = db.Select("select * from service_status where started_at is null or last_status < DATEADD(hour,-1,getdate()) or case when started_at is null then cast(getdate() as date) else cast(started_at as date) end <> cast(getdate() as date)");
                if (dtServices != null && dtServices.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtServices.Rows)
                    {
                        String svcName = dr["service_name"].ToString();

                        if (svcName.ToLower().IndexOf("watchdog") >= 0)
                        {
                            continue;
                        }

                        TextLog.Log("Watchdog", "Killing service '" + svcName + "'");
                        Killall(svcName);
                        Killall("IAM" + svcName);
                    }
                }

                db.closeDB();
            }
            catch { }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }

                db = null;
            }

            try
            {
                ServiceController[] services = ServiceController.GetServices();

                foreach (ServiceController service in ServiceController.GetServices())
                {
                    try
                    {
                        switch (service.ServiceName.ToLower())
                        {
                        case "iambackup":
                        case "iamdispatcher":
                        case "iamengine":
                        case "iaminbound":
                        case "iamreport":
                        case "iamproxy":
                        case "iammultiproxy":
                        case "iammessenger":
                        case "iamworkflowprocessor":
                            StartupState stMode = StartMode(service.ServiceName);

                            switch (stMode)
                            {
                            case StartupState.Automatic:
                                if ((service.Status.Equals(ServiceControllerStatus.Stopped)) || (service.Status.Equals(ServiceControllerStatus.StopPending)))
                                {
                                    TextLog.Log("Watchdog", "Starting service '" + service.DisplayName + "'");
                                    service.Start();

                                    try
                                    {
                                        db = new IAMDatabase(localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword);
                                        db.openDB();
                                        db.Timeout = 600;

                                        db.AddUserLog(LogKey.Watchdog, null, "Watchdog", UserLogLevel.Warning, 0, 0, 0, 0, 0, 0, 0, "Starting service '" + service.DisplayName + "'");

                                        db.closeDB();
                                    }
                                    catch { }
                                    finally
                                    {
                                        if (db != null)
                                        {
                                            db.Dispose();
                                        }

                                        db = null;
                                    }
                                }
                                break;

                            default:
                                TextLog.Log("Watchdog", "Unknow action for service start mode '" + stMode.ToString() + "' for service '" + service.DisplayName + "'");
                                break;
                            }

                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        TextLog.Log("Watchdog", "Erro ao processar o controle do serviço '" + service.DisplayName + "': " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                TextLog.Log("Watchdog", "Erro ao processar o controle dos serviços: " + ex.Message);
            }
        }
Esempio n. 8
0
        public void Run()
        {
            var thread = new Thread(_Run);

            var existing = Interlocked.CompareExchange(ref _thread, thread, null);
            if (null != existing)
            {
                return;
            }

            StartupState state = new StartupState();
            thread.SetApartmentState(ApartmentState.MTA);
            thread.IsBackground = true;
            thread.Start(state);
            state.WaitForStartup();
        }
Esempio n. 9
0
 public AppDesiredState(string packageFamilyName, DesiredState state, string version, StartupState startUp, string appxSource, string dep0Source, string dep1Source, string certificateSource, string certificateTarget)
 {
     PackageFamilyName = packageFamilyName;
     State             = state;
     Version           = version;
     StartUp           = startUp;
     AppxSource        = appxSource;
     Dep0Source        = dep0Source;
     Dep1Source        = dep1Source;
     CertificateSource = certificateSource;
     CertificateTarget = certificateTarget;
 }
Esempio n. 10
0
 // Use this for initialization
 void Start()
 {
     Game.Initialize();
     this.state = StartupState.TitleCard;
 }
Esempio n. 11
0
        /// <summary>
        /// Initialized the kernel by allowing all the kernel services to
        /// go through their initialization processes.
        /// </summary>
        /// <design>
        /// <para>
        /// This method ensures that all the services are operational and
        /// have been started. Once all the services are capable of
        /// running then we return focus to the object that started the
        /// kernel.
        /// </para>
        /// <para>
        /// The <c>Kernel.Start</c> method does not specifically start a
        /// new thread for the services to run on (although individual
        /// services may start new threads). This is done specifically because
        /// eventually the focus needs to return to the UI thread. After all
        /// this is where the user interaction will take place on. Thus there
        /// is no reason for the kernel to have it's own thread.
        /// </para>
        /// </design>
        public void Start()
        {
            m_Diagnostics.Log(
                LevelToLog.Info,
                HostConstants.LogPrefix,
                Resources.Kernel_LogMessage_KernelStarting);

            m_State = StartupState.Starting;

            // In order to keep this flexible we will need to sort the services
            // so that the startup order guarantuees that each service will have
            // its dependencies and requirements running before it does.
            // Obviously this is prone to cyclic loops ...
            var startupOrder = DetermineServiceStartupOrder();

            foreach (var service in startupOrder)
            {
                // Grab the actual current service so that we can put it in the
                // lambda expression without having it wiped or replaced on us
                var currentService = service;

                var dependencyHolder = currentService as IHaveServiceDependencies;
                if (dependencyHolder != null)
                {
                    if (!dependencyHolder.IsConnectedToAllDependencies)
                    {
                        throw new KernelStartupFailedException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      Resources.Exceptions_Messages_KernelStartupFailedDueToMissingServiceDependency_WithService,
                                      currentService.GetType()));
                    }

                    // There is no need to check that all the dependencies are up and
                    // running because:
                    // - We know that all the services started prior to the current one
                    //   are running (otherwise we would have thrown).
                    // - We know that all services are sorted by dependency, the dependent
                    //   services last and the independent services first.
                    // So this means that all dependencies must be running.
                }

                if (currentService.StartupState != StartupState.Started)
                {
                    EventHandler <ProgressEventArgs> handler = (s, e) =>
                    {
                        var finishedPercentage = (double)startupOrder.IndexOf(currentService) / startupOrder.Count;
                        var currentPercentage  = e.Progress / (100.0 * startupOrder.Count);
                        var total = finishedPercentage + currentPercentage;

                        RaiseOnStartupProgress((int)Math.Floor(total * 100), e.Description, e.HasErrors);
                    };

                    currentService.OnStartupProgress += handler;
                    try
                    {
                        currentService.Start();
                        if (currentService.StartupState != StartupState.Started)
                        {
                            throw new KernelServiceStartupFailedException(
                                      string.Format(
                                          CultureInfo.InvariantCulture,
                                          Resources.Exceptions_Messages_KernelServiceStartupFailed_WithService,
                                          currentService.GetType()));
                        }
                    }
                    finally
                    {
                        currentService.OnStartupProgress -= handler;
                    }
                }
            }

            m_Diagnostics.Log(
                LevelToLog.Info,
                HostConstants.LogPrefix,
                Resources.Kernel_LogMessage_KernelStartupComplete);

            m_State = StartupState.Started;
            SendStartupCompleteMessage();
        }
 public void EnterModelContext(MediaPortal.UI.Presentation.Workflow.NavigationContext oldContext, MediaPortal.UI.Presentation.Workflow.NavigationContext newContext)
 {
     if (startupState == StartupState.LASTUSED)
     {
         startupState = EmulatorsCore.Options.ReadOption(o => o.StartupState);
         if (startupState == StartupState.LASTUSED)
             startupState = EmulatorsCore.Options.ReadOption(o => o.LastStartupState);
     }
     updateState(newContext);
 }
Esempio n. 13
0
        /// <summary>
        /// Initialized the kernel by allowing all the kernel services to 
        /// go through their initialization processes.
        /// </summary>
        /// <design>
        /// <para>
        /// This method ensures that all the services are operational and
        /// have been started. Once all the services are capable of
        /// running then we return focus to the object that started the 
        /// kernel.
        /// </para>
        /// <para>
        /// The <c>Kernel.Start</c> method does not specifically start a
        /// new thread for the services to run on (although individual
        /// services may start new threads). This is done specifically because
        /// eventually the focus needs to return to the UI thread. After all
        /// this is where the user interaction will take place on. Thus there
        /// is no reason for the kernel to have it's own thread.
        /// </para>
        /// </design>
        public void Start()
        {
            m_Diagnostics.Log(
                LevelToLog.Info,
                HostConstants.LogPrefix,
                Resources.Kernel_LogMessage_KernelStarting);

            m_State = StartupState.Starting;

            // In order to keep this flexible we will need to sort the services
            // so that the startup order guarantuees that each service will have
            // its dependencies and requirements running before it does.
            // Obviously this is prone to cyclic loops ...
            var startupOrder = DetermineServiceStartupOrder();
            foreach (var service in startupOrder)
            {
                // Grab the actual current service so that we can put it in the
                // lambda expression without having it wiped or replaced on us
                var currentService = service;

                var dependencyHolder = currentService as IHaveServiceDependencies;
                if (dependencyHolder != null)
                {
                    if (!dependencyHolder.IsConnectedToAllDependencies)
                    {
                        throw new KernelStartupFailedException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                Resources.Exceptions_Messages_KernelStartupFailedDueToMissingServiceDependency_WithService,
                                currentService.GetType()));
                    }

                    // There is no need to check that all the dependencies are up and
                    // running because:
                    // - We know that all the services started prior to the current one
                    //   are running (otherwise we would have thrown).
                    // - We know that all services are sorted by dependency, the dependent
                    //   services last and the independent services first.
                    // So this means that all dependencies must be running.
                }

                if (currentService.StartupState != StartupState.Started)
                {
                    EventHandler<ProgressEventArgs> handler = (s, e) =>
                        {
                            var finishedPercentage = (double)startupOrder.IndexOf(currentService) / startupOrder.Count;
                            var currentPercentage = e.Progress / (100.0 * startupOrder.Count);
                            var total = finishedPercentage + currentPercentage;

                            RaiseOnStartupProgress((int)Math.Floor(total * 100), e.Description, e.HasErrors);
                        };

                    currentService.OnStartupProgress += handler;
                    try
                    {
                        currentService.Start();
                        if (currentService.StartupState != StartupState.Started)
                        {
                            throw new KernelServiceStartupFailedException(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    Resources.Exceptions_Messages_KernelServiceStartupFailed_WithService,
                                    currentService.GetType()));
                        }
                    }
                    finally
                    {
                        currentService.OnStartupProgress -= handler;
                    }
                }
            }

            m_Diagnostics.Log(
                LevelToLog.Info,
                HostConstants.LogPrefix,
                Resources.Kernel_LogMessage_KernelStartupComplete);

            m_State = StartupState.Started;
            SendStartupCompleteMessage();
        }
Esempio n. 14
0
        public void Shutdown()
        {
            m_Diagnostics.Log(
                LevelToLog.Info,
                HostConstants.LogPrefix,
                Resources.Kernel_LogMessage_KernelStopping);

            m_State = StartupState.Stopping;

            // In order to keep this flexible we will need to sort the services
            // so that the startup order guarantuees that each service will have
            // its dependencies and requirements running before it does.
            // Obviously this is prone to cyclic loops ...
            var startupOrder = DetermineServiceStartupOrder();

            // Reverse the order so that we move from most dependent
            // to least dependent
            startupOrder.Reverse();

            foreach (var service in startupOrder)
            {
                try
                {
                    service.Stop();
                }
                catch
                {
                    // An exception occured. Ignore it and move on
                    // we're about to destroy the appdomain the service lives in.
                }
            }

            // Run the final shut down action. This will normally dispose the
            // IOC container etc.
            if (m_ShutdownAction != null)
            {
                m_ShutdownAction();
            }

            m_State = StartupState.Stopped;

            m_Diagnostics.Log(
                LevelToLog.Info,
                HostConstants.LogPrefix,
                Resources.Kernel_LogMessage_KernelStopped);
        }