コード例 #1
0
            public RelaysIdHandler(RestfulRelayServer parent) : base(parent)
            {
                allowedMethods      = "GET, HEAD, PUT";
                supportedMediaTypes = "application/vnd.collection+json"; // required Content-Type for the body of a PUT request
                // ProcessRequest will use a JSON Schema to validate the PUT request body, which must be a
                // Collection+JSON document with a filled-out template object
                // Example PUT request body:
                //
                // { "template" :
                //  {
                //   "data" : [
                //    {"prompt" : "Change the Relay State (Open or Close)", "name" : "State", "value" : "Open"}
                //   ]
                //  }
                // }
                string schemaJson = @"{
                  'description': 'A Collection+JSON document representing a filled-out template',
                  'type': 'object',
                  'properties': {
                    'template': {
                      'type':'object', 
                      'properties': {
                        'data': {
                          'type':'array', 
                          'items': {
                            'type':'object', 
                            'properties': {
                              'prompt':{'type':'string'},
                              'name':{'type':'string'},
                              'value':{'type':'string'}
                            }
                          }
                        }
                      }
                    }
                  }
                }";

                putRequestBodySchema = JsonSchema.Parse(schemaJson);

                // make the template JObject
                JObject templateObj = new JObject
                {
                    { "data", new JArray
                      {
                          new JObject
                          {
                              { "prompt", "Change the Relay State (Open or Close)" },
                              { "name", "State" },
                              { "value", "" }
                          }
                      } }
                };

                templateString = JsonConvert.SerializeObject(templateObj);
            }
コード例 #2
0
 public void StartServer(string args)
 {
     try
     {
         if (this.SupportsRelay)
         {
             if (RegisterRelays())
             {
                 string hostname = "";
                 // adapterID 0 usually represents the outbound LAN port
                 hostname = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0).ToLower();
                 if (serv != null)
                 {
                     serv.Dispose();
                 }
                 serv = new RestfulRelayServer(RelayPorts, hostname);
                 CrestronConsole.ConsoleCommandResponse("Now serving REST API rooted at http://" + hostname + "/cws/api for the control system's " +
                                                        NumberOfRelayPorts + " relay ports.");
             }
             else
             {
                 CrestronConsole.ConsoleCommandResponse("Could not start server: unable to register all relays");
             }
         }
         else
         {
             CrestronConsole.ConsoleCommandResponse("This control system does not support relays, so the Relay API could not be created");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.ConsoleCommandResponse("Error in startserver user command: " + e.Message);
     }
     finally {
     }
 }
コード例 #3
0
 public RelaysIdWebhooksSubidHandler(RestfulRelayServer parent) : base(parent)
 {
     allowedMethods = "DELETE";
 }
コード例 #4
0
 public RelaysIdWebhooksHandler(RestfulRelayServer parent) : base(parent)
 {
     allowedMethods      = "POST";
     supportedMediaTypes = "text/uri-list";
 }
コード例 #5
0
 public RelaysHandler(RestfulRelayServer parent) : base(parent)
 {
     allowedMethods = "GET, HEAD";
 }
コード例 #6
0
 public DefaultHandler(RestfulRelayServer parent) : base(parent)
 {
     allowedMethods = ""; // Server doesn't care what the HTTP method is for an unrouted request
 }
コード例 #7
0
 public MyHttpHandler(RestfulRelayServer parent)
 {
     server = parent;
 }