Exemplo n.º 1
0
        internal void HandleInputs(RuntimeTask runtime)
        {
            if (!IsAvailable())
            {
                return;
            }

            Log.Write(LOG_CAT, (LogLevel)10, $"HandleInputs");

            var inputs = Program.Current.Me.GetValue <Dictionary <string, object> >("ControlModule.Inputs");

            foreach (var action in actions)
            {
                if (action.Value.ContainsKey(InputEvent.Press))
                {
                    var methods = action.Value[InputEvent.Press];
                    if (inputs.ContainsKey(action.Key) &&
                        !lastActions.Contains(action.Key))
                    {
                        foreach (var method in methods)
                        {
                            runtime.StartProgram(method);
                        }
                    }
                }
                if (action.Value.ContainsKey(InputEvent.Release))
                {
                    var methods = action.Value[InputEvent.Release];
                    if (!inputs.ContainsKey(action.Key) &&
                        lastActions.Contains(action.Key))
                    {
                        foreach (var method in methods)
                        {
                            runtime.StartProgram(method);
                        }
                    }
                }
            }

            lastActions = new HashSet <string>(inputs.Keys);
        }
Exemplo n.º 2
0
        void Initialize()
        {
            DrawLogo();

            Deserializer decoder       = TryInitStorageDecoder();
            bool         hasStoredData = decoder != null;

            sch     = new Scheduler();
            runtime = null;

            if (decoder != null)
            {
                try
                {
                    decoder.ReadObject(Log.D);
                    decoder.ReadObject(timerController = new TimerController());
                    decoder.ReadObject(runtime         = new RuntimeTask(timerController));
                    decoder.ReadObject(VariablesStorage.Shared);
                    decoder.ReadObject(CMMapper.Shared);
                }
                catch (Exception e)
                {
                    hasStoredData = false;
                    Log.WriteFormat(LOG_CAT, LogLevel.Error, "state restoring failed: {0}", e.ToString());
                }

                decoder.Dispose();
            }

            if (!hasStoredData)
            {
                LogLevels();
                timerController = new TimerController();
                runtime         = new RuntimeTask(timerController);
                VariablesStorage.Clear();
                CMMapper.Shared.Clear();

                ScheduleParse(true);
            }
        }