timelapse/Timelapse.Api/Extension.cs

95 lines
2.6 KiB
C#
Raw Normal View History

2021-12-28 07:25:39 +00:00
using System;
using System.Collections.Generic;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Net;
namespace Timelapse.Api
{
public abstract class TimelapseExtension
{
internal string __id;
internal bool _recording;
internal bool _onex;
protected bool Recording {get {return _recording;}set{if(value){StartRecording();} else{StopRecording();}}}
protected bool OneX {get {return _onex;}set{if(value) {EnableOneX();} else {DisableOneX();} }}
public abstract void OnInit();
public string Name {get;internal set;}
public virtual async Task OnNewFrame(Image<Rgb24> frame)
{
}
public virtual void OnLoadProject(TimelapseProject project)
{
}
///<summary>
///URL for in html pages
///</summary>
public string GET_URL(string href)
{
return $"/api/Extension/GetExtensionPage?extId={WebUtility.UrlEncode(__id)}&subPage={WebUtility.UrlEncode(href)}";
}
protected string GetExtensionProjectData()
{
if(!Extensions.Callbacks.ProjectLoaded())
{
return null;
}
string p = Path.Combine(Extensions.Callbacks.GetProjectDirectoryLocation(),"ExtensionData",__id);
Directory.CreateDirectory(p);
return p;
}
protected string GetExtensionData()
{
string p = Path.Combine(Extensions.UserData,"ExtensionData",__id);
Directory.CreateDirectory(p);
return p;
}
public bool IsProjectLoaded()
{
return Extensions.Callbacks.ProjectLoaded();
}
public virtual void OnStartRecording()
{
}
public virtual void OnStopRecording()
{
}
protected void StartRecording()
{
Extensions.Callbacks.StartRecording();
}
protected void StopRecording()
{
Extensions.Callbacks.StopRecording();
}
protected void EnableOneX()
{
Extensions.Callbacks.EnableOneX();
}
protected void DisableOneX()
{
Extensions.Callbacks.DisableOneX();
}
public virtual void OnEnableOneX()
{
}
public virtual void OnDisableOneX()
{
}
public virtual async Task<IActionResult> OnHandleRequest(string path)
{
return new NotFoundResult();
}
}
}