public DigitalInputActionBase(string name, DigitalActionType type)
 {
     Name = name; Type = type;
 }
Exemplo n.º 2
0
        public override void OnPost(HttpListenerRequest request, HttpListenerResponse response)
        {
            // Check if the request has the correct json content
            if (request.ContentType == null)
            {
                ConsoleManager.LogError("Missing Content-Type in " + ActionName);
                return;
            }
            if (!request.ContentType.Equals("application/json"))
            {
                return;
            }

            string jsonBody = ResponseFactory.JsonStringFromRequest(request);

            // Data parsing:
            JToken t           = JToken.Parse(jsonBody);
            int    componentId = (int)t.SelectToken("id");

            JObject           obj       = (JObject)t.SelectToken("data");
            DigitalActionType eventType = (DigitalActionType)(int)obj.SelectToken("action");

            switch (eventType)
            {
            case DigitalActionType.None:
                InputDispatcher.UpdatePushButtonAction(componentId, null);
                break;

            case DigitalActionType.LaunchApp:
                string actionName = (string)obj.SelectToken("name");
                string appPath    = (string)obj.SelectToken("path");
                InputDispatcher.UpdatePushButtonAction(componentId, new ActionRunProgram(actionName)
                {
                    FullAppDirectory = appPath, AppName = actionName
                });
                break;

            case DigitalActionType.OpenWebsite:
                string uri    = (string)obj.SelectToken("websiteUri");
                string name   = (string)obj.SelectToken("name");
                var    action = new ActionOpenWebsite()
                {
                    WebsiteName = name, WebsiteUri = uri
                };
                action.Init();
                InputDispatcher.UpdatePushButtonAction(componentId, action);
                break;

            case DigitalActionType.Macro:
                ActionRunMacro.MacroType macroType = (ActionRunMacro.MacroType)(int) obj.SelectToken("macroType");
                string macroText = (string)obj.SelectToken("macroText");
                InputDispatcher.UpdatePushButtonAction(componentId, new ActionRunMacro(macroType, macroText));
                break;     // TODO add selected keys to execute macro
            }
            // Store new action mapping:
            InputDispatcher.UpdateActionMappingFile();

            // Send response to the frontend
            string jsonResponse = "{\"result\":true}";

            ResponseFactory.GenerateResponse(response, jsonResponse);
        }