-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Tacke
committed
Oct 10, 2021
1 parent
3d11e0a
commit e1b8150
Showing
6 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Meadow.Foundation.Web.Maple.Server; | ||
using Meadow.Foundation.Web.Maple.Server.Routing; | ||
using System; | ||
using System.IO; | ||
|
||
namespace MeadowApp | ||
{ | ||
public class TimeHandler : RequestHandlerBase | ||
{ | ||
internal class TimeInfo | ||
{ | ||
public TimeInfo() | ||
{ | ||
SystemTime = DateTime.UtcNow; | ||
} | ||
|
||
public DateTime SystemTime { get; set; } | ||
} | ||
|
||
public override bool IsReusable => true; | ||
|
||
[HttpGet] | ||
public IActionResult GetTime() | ||
{ | ||
return new JsonResult(new TimeInfo()); | ||
} | ||
|
||
[HttpPut] | ||
public IActionResult SetTime() | ||
{ | ||
try | ||
{ | ||
string json; | ||
|
||
using (var reader = new StreamReader(Context.Request.InputStream)) | ||
{ | ||
json = reader.ReadToEnd(); | ||
} | ||
|
||
var info = SimpleJson.SimpleJson.DeserializeObject<TimeInfo>(json); | ||
|
||
if (info.SystemTime != DateTime.MinValue) | ||
{ | ||
MeadowApp.Device.SetClock(info.SystemTime); | ||
return new OkResult(); | ||
} | ||
|
||
return new StatusCodeResult(System.Net.HttpStatusCode.InternalServerError); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new ServerErrorResult(ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters