HyperionScreenCap/ApiServer.cs
/// <summary>
/// DO NOT RENAME THIS METHOD. The name is used in the reflection code above.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
DO NOT RENAME THIS METHOD. The name is used in the reflection code above.
DO NOT RENAME THIS METHOD . The name is used in the reflection code above .
[RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "/API")]
        private IHttpContext API(IHttpContext context)
        {
            LOG.Info("API server command received");
            context.Response.ContentType = ContentType.TEXT;
            string responseText = "No valid API command received.";
            string command = context.Request.QueryString["command"] ?? "";
            string force = context.Request.QueryString["force"] ?? "false";
            if ( !string.IsNullOrEmpty(command) )
            {
                LOG.Info($"Processing API command: {command}");
                if ( command == "ON" || command == "OFF" )
                {
                    if ( SettingsManager.ApiExcludedTimesEnabled && force.ToLower() == "false" )
                    {
                        if ( (DateTime.Now.TimeOfDay >= SettingsManager.ApiExcludeTimeStart.TimeOfDay &&
                             DateTime.Now.TimeOfDay <= SettingsManager.ApiExcludeTimeEnd.TimeOfDay) ||
                            ((SettingsManager.ApiExcludeTimeStart.TimeOfDay > SettingsManager.ApiExcludeTimeEnd.TimeOfDay) &&
                             ((DateTime.Now.TimeOfDay <= SettingsManager.ApiExcludeTimeStart.TimeOfDay &&
                               DateTime.Now.TimeOfDay <= SettingsManager.ApiExcludeTimeEnd.TimeOfDay) ||
                              (DateTime.Now.TimeOfDay >= SettingsManager.ApiExcludeTimeStart.TimeOfDay &&
                               DateTime.Now.TimeOfDay >= SettingsManager.ApiExcludeTimeEnd.TimeOfDay))) )
                        {
                            responseText = "API exclude times enabled and within time range.";
                            LOG.Info($"Sending response: {responseText}");
                            context.Response.SendResponse(responseText);
                            return context;
                        }
                    }
                    _mainForm.ToggleCapture((MainForm.CaptureCommand) Enum.Parse(typeof(MainForm.CaptureCommand), command));
                    responseText = $"API command {command} completed successfully.";
                }
                if ( command == "STATE" )
                {
                    responseText = $"{_mainForm.CaptureEnabled}";
                }
            }
            else
            {
                LOG.Warn("API Command Empty / Invalid");
            }
            LOG.Info($"Sending response: {responseText}");
            context.Response.SendResponse(responseText);
            return context;
        }
[ RestRoute ( HttpMethod = HttpMethod . GET , PathInfo = " " ) ] private IHttpContext API ( IHttpContext context ) { LOG . Info ( " " ) ; context . Response . ContentType = ContentType . TEXT ; string responseText = " " ; string command = context . Request . QueryString [ " " ] ?? " " ; string force = context . Request . QueryString [ " " ] ?? " " ; if ( ! string . IsNullOrEmpty ( command ) ) { LOG . Info ( $" Processing API command:  { command } " ) ; if ( command == " " || command == " " ) { if ( SettingsManager . ApiExcludedTimesEnabled && force . ToLower ( ) == " " ) { if ( ( DateTime . Now . TimeOfDay >= SettingsManager . ApiExcludeTimeStart . TimeOfDay && DateTime . Now . TimeOfDay <= SettingsManager . ApiExcludeTimeEnd . TimeOfDay ) || ( ( SettingsManager . ApiExcludeTimeStart . TimeOfDay > SettingsManager . ApiExcludeTimeEnd . TimeOfDay ) && ( ( DateTime . Now . TimeOfDay <= SettingsManager . ApiExcludeTimeStart . TimeOfDay && DateTime . Now . TimeOfDay <= SettingsManager . ApiExcludeTimeEnd . TimeOfDay ) || ( DateTime . Now . TimeOfDay >= SettingsManager . ApiExcludeTimeStart . TimeOfDay && DateTime . Now . TimeOfDay >= SettingsManager . ApiExcludeTimeEnd . TimeOfDay ) ) ) ) { responseText = " " ; LOG . Info ( $" Sending response:  { responseText } " ) ; context . Response . SendResponse ( responseText ) ; return context ; } } _mainForm . ToggleCapture ( ( MainForm . CaptureCommand ) Enum . Parse ( typeof ( MainForm . CaptureCommand ) , command ) ) ; responseText = $" API command  { command }  completed successfully. " ; } if ( command == " " ) { responseText = $" { _mainForm . CaptureEnabled } " ; } } else { LOG . Warn ( " " ) ; } LOG . Info ( $" Sending response:  { responseText } " ) ; context . Response . SendResponse ( responseText ) ; return context ; }
DO NOT RENAME THIS METHOD.
DO NOT RENAME THIS METHOD .
// Only process valid commands // Check for deactivate API between certain times
None
context
IHttpContext
None