Commit 46e398a0 authored by Ing. Jiří Fryč's avatar Ing. Jiří Fryč

new version

parent df40e3d7
No preview for this file type
......@@ -14,7 +14,16 @@ namespace KazetaNode.Libraries.KosApi
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
var res = library.Endpoint.RoomEvents(input.Arguments[0]);
res.Wait();
var response = res.Result;
ConsoleP.AppendDelimeter();
ConsoleP.AppendCols(new int[] { 20, 20, 20, 10 }, "course","from","to", "type");
foreach(KosRoomEvent ev in response.Events)
{
ConsoleP.AppendCols(new int[] { 20, 20, 20, 10 }, ev.Links.Course, ev.StartsAt.ToString("dd/MM/yy HH:mm"), ev.EndsAt.ToString("dd/MM/yy HH:mm"), ev.EventType);
}
ConsoleP.AppendDelimeter();
}
}
class CmdKosApiCourseInfo : Command<KosApi>
......@@ -49,4 +58,17 @@ namespace KazetaNode.Libraries.KosApi
ConsoleP.AppendDelimeter();
}
}
class CmdKosApiCaptureSingleCourse : Command<KosApi>
{
public CmdKosApiCaptureSingleCourse(KosApi library) : base(library)
{
}
public override string[] Aliases => new string[] { "kosapi-capture-single"};
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
namespace KazetaNode.Libraries.KosApi
{
class KosApi : AbstractLibrary
{
public override string Id => "kosapi";
public override string Name => "KosApi";
public override string Version => "1.0";
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
namespace KazetaNode.Libraries.KosApi
{
class KosApi : AbstractLibrary
{
public override string Id => "kosapi";
public override string Name => "KosApi";
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { new CmdKosApiCourseInfo(this),new CmdKosApiRoomInfo(this)};
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
protected internal RestEndpoint Endpoint { get; private set; }
public KosApi(dynamic config)
{
Endpoint = new RestEndpoint(config["clientid"], config["clientsecret"]);
}
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
}
}
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
protected internal RestEndpoint Endpoint { get; private set; }
public KosApi(dynamic config)
{
Endpoint = new RestEndpoint(config["clientid"], config["clientsecret"]);
}
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
}
}
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -27,4 +28,47 @@ namespace KazetaNode.Libraries.KosApi
public ParallelType Type { get; set; }
public string RoomId { get; set; }
}
class KosRoomResponse
{
[JsonProperty("events")]
public List<KosRoomEvent> Events { get; set; } = new List<KosRoomEvent>();
}
class KosRoomEventLinks
{
[JsonProperty("course")]
public string Course { get; set; }
[JsonProperty("room")]
public string Room { get; set; }
[JsonProperty("teachers")]
public List<string> Teachers { get; set; } = new List<string>();
[JsonProperty("students")]
public List<string> Students { get; set; } = new List<string>();
}
class KosRoomEvent
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("sequence_number")]
public int SequenceNumber { get; set; }
[JsonProperty("starts_at")]
public DateTime StartsAt { get; set; }
[JsonProperty("ends_at")]
public DateTime EndsAt { get; set; }
[JsonProperty("deleted")]
public bool Deleted { get; set; }
[JsonProperty("capacity")]
public int Capacity { get; set; }
[JsonProperty("occupied")]
public int Occupied { get; set; }
[JsonProperty("event_type")]
public string EventType { get; set; }
[JsonProperty("parallel")]
public string Parallel { get; set; }
[JsonProperty("links")]
public KosRoomEventLinks Links { get; set; } = new KosRoomEventLinks();
}
}
......@@ -13,7 +13,7 @@ namespace KazetaNode.Libraries.KosApi
{
class RestEndpoint
{
HttpClient Client;
HttpClient Client,SiriusClient;
string ClientId, ClientSecret;
JObject Token;
long NextTokenGeneration = 0;
......@@ -26,9 +26,16 @@ namespace KazetaNode.Libraries.KosApi
{
BaseAddress = new Uri("https://kosapi.feld.cvut.cz/api/3/")
};
SiriusClient = new HttpClient
{
BaseAddress= new Uri("https://sirius.fit.cvut.cz/api/v1/")
};
Client.DefaultRequestHeaders.Accept.Clear();
Client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/xml"));
SiriusClient.DefaultRequestHeaders.Accept.Clear();
SiriusClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
GetTokenAsync().Wait();
}
......@@ -55,6 +62,25 @@ namespace KazetaNode.Libraries.KosApi
return Token;
}
public async System.Threading.Tasks.Task<KosRoomResponse> RoomEvents(string code,DateTime? from=null,DateTime? to=null)
{
int diff = (7 + (DateTime.Now.DayOfWeek - DayOfWeek.Monday)) % 7;
if (from == null)
{
from = DateTime.Now.AddDays(-1 * diff).Date;
from = from?.AddHours(-(int)from?.Hour);
}
if (to == null)
{
to = DateTime.Now.AddDays(-1 * diff + 8).Date;
to = to?.AddHours(-(int)to?.Hour);
}
SiriusClient.DefaultRequestHeaders.Remove("Authorization");
var t = await GetTokenAsync();
SiriusClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + t["access_token"].ToString());
var res = await SiriusClient.GetAsync("rooms/" + code+ "/events?limit=100&from="+from?.ToString("o") + "&to="+to?.ToString("o"));
return Newtonsoft.Json.JsonConvert.DeserializeObject<KosRoomResponse>(await res.Content.ReadAsStringAsync());
}
public async System.Threading.Tasks.Task<bool> RoomExistAsync(string code)
{
XNamespace atom = "http://www.w3.org/2005/Atom";
......
using System;
using System.Collections.Generic;
using System.Text;
namespace KazetaNode.Libraries.TaskScheduler
{
class CmdTaskSchedulerStatus : Command<TaskScheduler>
{
public CmdTaskSchedulerStatus(TaskScheduler library) : base(library)
{
}
public override string[] Aliases => new string[] { "task-status" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
namespace KazetaNode.Libraries.TaskScheduler
{
class TaskScheduler : AbstractLibrary
{
public override string Id => "taskscheduler";
public override string Name => "Task scheduler";
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { };
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>() {
};
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment