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

new version

parent f6a00294
No preview for this file type
This diff is collapsed.
......@@ -34,7 +34,7 @@ namespace KazetaNode.Coms
return new Postman
{
Exchange = "",
Route = node,
Route = "app.kazeta.node."+node,
Message = message
};
}
......@@ -92,11 +92,11 @@ namespace KazetaNode.Coms
this.Multiple = true;
return this;
}
public void Send()
public void Send(bool expectresponse = true)
{
if (TimeStart != -1)
throw new Exception("Already started");
Program.Network.SendPostMan(this);
Program.Network.SendPostMan(this, expectresponse);
}
}
}
......@@ -15,20 +15,29 @@ namespace KazetaNode.Coms
[JsonProperty("sender")]
public string Sender { get; set; }
[JsonProperty("message_type")]
public abstract string MessageType { get; }
public string MessageType { get { return this.GetType().FullName; } }
public Postman Response(IMessage msg)
{
msg.ResponseId = this.MessageId;
return Postman.SendToNode(this.Sender, msg);
}
}
class TestMessage : IMessage
{
public override string MessageType => this.GetType().FullName;
}
class DiscoveryRequest : IMessage
{
}
class DiscoveryResponse : IMessage
{
}
class DiscoveryMessage : IMessage
{
public override string MessageType => this.GetType().FullName;
}
class DiscoveryReplyMessage : IMessage
{
public override string MessageType => this.GetType().FullName;
}
}
......@@ -116,10 +116,11 @@ namespace KazetaNode.Coms
consumer: consumer);
}
internal void SendPostMan(Postman postman)
internal void SendPostMan(Postman postman, bool expectresponse=true)
{
postman.TimeStart = watch.ElapsedMilliseconds;
Postmans.Add(postman);
if(expectresponse)
Postmans.Add(postman);
postman.Message.Sender = Program.NodeId;
Program.Network.channel.BasicPublish(postman.Exchange, postman.Route, null, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(postman.Message)));
}
......
......@@ -148,10 +148,15 @@ namespace KazetaNode
}
break;
case ConsoleKey.Backspace:
Line = Line.Substring(0, Line.Length-1);
Console.Write(' ');
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
LinePos--;
if (Line.Length > 0)
{
Line = Line.Substring(0, Line.Length - 1);
Console.Write(' ');
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
LinePos--;
}
else
Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop);
break;
default:
if(LinePos<Line.Length)
......
......@@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>KazetaNode</RootNamespace>
<StartupObject>KazetaNode.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
......
......@@ -18,7 +18,7 @@ namespace KazetaNode.Libraries
public abstract AbstractLibraryInstance CreateCaptureInstance();
public abstract List<Command> Commands { get; }
public abstract Dictionary<string, Tuple<Type, ReceiveMessage>> Messages { get; }
public abstract List<Tuple<Type, ReceiveMessage>> Messages { get; }
private static List<AbstractLibrary> libraries =null;
public static List<AbstractLibrary> Initialize(dynamic libraryConfig)
......@@ -28,7 +28,8 @@ namespace KazetaNode.Libraries
{
new Ffmpeg.Ffmpeg(),
new KosApi.KosApi(libraryConfig?["kosapi"]),
new Room.Room()
new Room.Room(),
new LocalStorage.LocalStorage(libraryConfig?["localstorage"])
};
return libraries;
}
......
......@@ -15,7 +15,7 @@ namespace KazetaNode.Libraries.ArtNet
public override List<Command> Commands => new List<Command>() { new CmdArtNetSelect(),new CmdArtNetSend() };
public override Dictionary<string, Tuple<Type, ReceiveMessage>> Messages => new Dictionary<string, Tuple<Type,ReceiveMessage>>() { [""] = null };
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
public override AbstractLibraryInstance CreateCaptureInstance()
{
......
......@@ -33,7 +33,7 @@ namespace KazetaNode.Libraries.Ffmpeg
public override List<Command> Commands => new List<Command>() { new CmdNdiFindSources(), new CmdNdiTakeScreenshot(),new CmdNdiCapture() };
public override Dictionary<string, Tuple<Type, Network.ReceiveMessage>> Messages => throw new NotImplementedException();
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
public override AbstractLibraryInstance CreateCaptureInstance()
{
......
......@@ -13,9 +13,9 @@ namespace KazetaNode.Libraries.FileShare
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { };
public override Dictionary<string, Tuple<Type, Network.ReceiveMessage>> Messages => throw new NotImplementedException();
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()
{
......
......@@ -44,7 +44,7 @@ namespace KazetaNode.Libraries.KosApi
ConsoleP.AppendDelimeter();
foreach (var par in course.Parallels)
{
ConsoleP.AppendCols(new int[] { 10,10,10,10,10 },par.Type.ToString(), par.Day.ToString(),Program.GetLibrary<Room.Room>(typeof(Room.Room)).RoomExist(par.RoomId)?"@green": "@red", par.RoomId,"@reset",par.FromHM[0]+":"+par.FromHM[1],par.ToHM[0]+":"+par.ToHM[1]);
ConsoleP.AppendCols(new int[] { 10,10,10,10,10 },par.Type.ToString(), par.Day.ToString(),Program.GetLibrary<Room.Room>().RoomExist(par.RoomId)?"@green": "@red", par.RoomId,"@reset",par.FromHM[0]+":"+par.FromHM[1],par.ToHM[0]+":"+par.ToHM[1]);
}
ConsoleP.AppendDelimeter();
}
......
......@@ -13,9 +13,9 @@ namespace KazetaNode.Libraries.KosApi
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { new CmdKosApiCourseInfo(this),new CmdKosApiRoomInfo(this)};
public override Dictionary<string, Tuple<Type, Network.ReceiveMessage>> Messages => throw new NotImplementedException();
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; }
......
using KazetaNode.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace KazetaNode.Libraries.LocalStorage
{
class CmdLocalStorageStatus : Command
{
private LocalStorage localStorage;
public CmdLocalStorageStatus(LocalStorage localStorage)
{
this.localStorage = localStorage;
}
public override string[] Aliases => new string[] { "storage-status" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
ConsoleP.AppendDelimeter();
ConsoleP.AppendCols(new int[] { 16,16,16,16,16 },"Drive","Path","Used","Max","Free");
ConsoleP.AppendDelimeter();
foreach (var loc in localStorage.Locations) {
DriveInfo info = new DriveInfo(loc.FullPath);
ConsoleP.AppendCols(new int[] { 16, 16, 16, 16, 16 }, info.Name,loc.RelativePath, FileSystemHelper.DirSize(Directory.CreateDirectory(loc.FullPath)) / 1048576 +"MB", loc.MaxSize+"MB",info.AvailableFreeSpace/1048576+"MB");
}
ConsoleP.AppendDelimeter();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
using System.IO;
namespace KazetaNode.Libraries.LocalStorage
{
class LocalStorage
{
class LocalStorage : AbstractLibrary
{
public override string Id => "localstorage";
public override string Name => "Local storage";
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { new CmdLocalStorageStatus(this) };
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
protected internal List<LocalStorageLocation> Locations = new List<LocalStorageLocation>();
public LocalStorage(dynamic config)
{
foreach(dynamic loc in config)
{
Locations.Add(new LocalStorageLocation()
{
FullPath = Path.GetFullPath(loc["path"]),
RelativePath = loc["path"],
MaxSize =Int32.Parse(loc["max_usage"]),
Primary=Boolean.Parse(loc["primary"])
});
}
}
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
}
class LocalStorageLocation
{
public string FullPath { get; protected internal set; }
public string RelativePath { get; protected internal set; }
public int MaxSize { get; protected internal set; } = int.MaxValue;
public bool Primary { get; protected internal set; } = true;
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace KazetaNode.Libraries.Room
{
class CmdRoomInfo : Command
{
public override string[] Aliases => new string[] { "room-info" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
}
}
class CmdRoomCacheRefresh : Command<Room>
{
public CmdRoomCacheRefresh(Room library) : base(library)
{
}
public override string[] Aliases => new string[] { "cache-refresh-room" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
this.library.Update();
}
}
}
using KazetaNode.Coms;
using System;
using System.Collections.Generic;
using System.Text;
namespace KazetaNode.Libraries.Room
{
class MsgRoomSynchronizeRequest : IMessage
{
}
class MsgRoomSynchronizeResponse : IMessage
{
public List<RoomModelBasic> Rooms { get; protected internal set; } = new List<RoomModelBasic>();
}
}
......@@ -13,16 +13,20 @@ namespace KazetaNode.Libraries.Room
{
public List<CaptureMode> Only { get; set; } = new List<CaptureMode>();
public List<string> Script { get; set; } = new List<string>();
}
class RoomModel
}
class RoomModelBasic
{
public string Id { get; set; }
public List<CaptureMode> Modes { get; set; } = new List<CaptureMode>();
public List<VideoQuality> Capability { get; set; } = new List<VideoQuality>();
}
class RoomModel : RoomModelBasic
{
public List<RoomTrigger> Capture { get; set; }
public List<RoomTrigger> Terminate { get; set; }
public List<RoomTrigger> Initialize { get; set; }
public List<VideoQuality> Capability { get; set; } = new List<VideoQuality>();
public List<NdiSourceDescriptor> Sources { get; set; } = new List<NdiSourceDescriptor>();
}
}
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using KazetaNode.Coms;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
......@@ -16,12 +17,25 @@ namespace KazetaNode.Libraries.Room
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>();
public override List<Command> Commands => new List<Command>() {
new CmdRoomInfo(),new CmdRoomCacheRefresh(this)
};
public override Dictionary<string, Tuple<Type, Network.ReceiveMessage>> Messages => throw new NotImplementedException();
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>()
{
Tuple.Create<Type,Network.ReceiveMessage>(typeof(MsgRoomSynchronizeRequest),ReceiveRequest)
};
protected internal void ReceiveRequest(IMessage msg)
{
msg.Response(new MsgRoomSynchronizeResponse()
{
Rooms= LocalRooms.Values.ToList<RoomModelBasic>()
}).Send(false);
}
protected internal Dictionary<string, RoomModel> LocalRooms { get; set; } = new Dictionary<string, RoomModel>();
protected internal Dictionary<string, Tuple<List<string>, RoomModel>> RemoteRooms { get; set; } = new Dictionary<string, Tuple<List<string>, RoomModel>>();
protected internal Dictionary<string, Tuple<HashSet<string>, RoomModelBasic>> RemoteRooms { get; set; } = new Dictionary<string, Tuple<HashSet<string>, RoomModelBasic>>();
public override AbstractLibraryInstance CreateCaptureInstance()
{
......@@ -37,15 +51,31 @@ namespace KazetaNode.Libraries.Room
LocalRooms.Add(r.Id, r);
}
public void Update()
{
Postman.SendToChannel(Channels.Discovery, new MsgRoomSynchronizeRequest()).During(
msg_raw =>
{
MsgRoomSynchronizeResponse msg = (MsgRoomSynchronizeResponse)msg_raw;
foreach (RoomModelBasic room in msg.Rooms)
{
if (!RemoteRooms.ContainsKey(room.Id))
RemoteRooms.Add(room.Id, Tuple.Create<HashSet<string>, RoomModelBasic>(new HashSet<string>() { msg.Sender }, room));
RemoteRooms[room.Id].Item1.Add(msg.Sender);
ConsoleP.AppendLine("Room '" + room.Id + "' capturable from Node '" + msg.Sender + "'.");
}
}).ExpectMultiple().Timeout(5_000).Send();
}
public bool RoomExist(string room)
{
return LocalRooms.ContainsKey(room) || RemoteRooms.ContainsKey(room);
}
public List<string> RemoteRoomNodes(string room)
public HashSet<string> RemoteRoomNodes(string room)
{
return RemoteRooms.ContainsKey(room) ? RemoteRooms[room].Item1:null;
}
public RoomModel RoomDescription(string room)
public RoomModelBasic RoomDescription(string room)
{
return LocalRooms.ContainsKey(room) ? LocalRooms[room] : (RemoteRooms.ContainsKey(room) ? RemoteRooms[room].Item2 : null);
}
......
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Libraries;
using KazetaNode.Libraries.Room;
namespace KazetaNode.Modules.Capture.Commands
{
class CmdCapture : Command
{
public override string[] Aliases => new string[] { "capture" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
}
}
class CmdCaptureScreenshot : Command
{
public override string[] Aliases => new string[] { "capture-screenshot" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
Room lib = Program.GetLibrary<Room>();
}
}
}
......@@ -15,13 +15,11 @@ namespace KazetaNode.Modules.Capture.Messages
private int quality = 1;
public int Quality { get { return quality; } set { this.quality = value < 1 ? 1 : (value > 31 ? 31 : value); } }
public override string MessageType => throw new NotImplementedException();
}
class CameraSnapshotResponse : IMessage
{
public byte[] Image { get; set; }
public override string MessageType => throw new NotImplementedException();
}
}
......@@ -9,18 +9,15 @@ namespace KazetaNode.Modules.Capture.Messages
[TopicMessage]
class CaptureAuction : IMessage
{
public override string MessageType => throw new NotImplementedException();
}
[TopicMessage]
class CaptureBid : IMessage
{
public override string MessageType => throw new NotImplementedException();
}
[DirectMessage]
class CaptureAssign : IMessage
{
public override string MessageType => throw new NotImplementedException();
}
}
......@@ -8,7 +8,6 @@ namespace KazetaNode.Modules.Persist.Messages
class StorageSpaceQuery : IMessage
{
public override string MessageType => throw new NotImplementedException();
}
class StorageSpaceLocationResponse
{
......@@ -22,20 +21,16 @@ namespace KazetaNode.Modules.Persist.Messages
public long TotalFreeSpace { get; set; }
public long TotalProjectCount { get; set; }
public StorageSpaceLocationResponse[] Locations { get; set; }
public override string MessageType => throw new NotImplementedException();
}
class StorageRequest : IMessage
{
public string ProjectId { get; set; }
public long RequiredSize { get; set; }
public override string MessageType => throw new NotImplementedException();
}
class StorageResponse : IMessage
{
public string Url { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public override string MessageType => throw new NotImplementedException();
}
}
......@@ -6,7 +6,6 @@ using KazetaNode.Modules.Capture;
using KazetaNode.Modules.Deliver;
using KazetaNode.Modules.Persist;
using KazetaNode.Modules.Process;
using KazetaNode.Shared.Messages;
using Newtonsoft.Json;
using RabbitMQ.Client;
using System.Linq;
......@@ -37,9 +36,9 @@ namespace KazetaNode
public static Dictionary<string, Command> Commands=new Dictionary<string, Command>();
public static T GetLibrary<T>(Type type) where T: AbstractLibrary
public static T GetLibrary<T>() where T : AbstractLibrary
{
return (T)Libraries.FirstOrDefault(lib => lib.GetType().IsEquivalentTo(type));
return (T)Libraries.FirstOrDefault(lib => lib.GetType().IsEquivalentTo(typeof(T)));
}
private static void RegisterCommands(params Command[] cmds)
......@@ -51,6 +50,8 @@ namespace KazetaNode
static void Main(string[] args)
{
TestMessage msg = new TestMessage();
var a=msg.MessageType;
RegisterCommands(new CmdTestNetwork(),new CmdNetworkDiscovery());
ConsoleP.WriteLine("Kazeta node (version " + version + ")");
ConsoleP.WriteLine("=====================================");
......@@ -86,7 +87,11 @@ namespace KazetaNode
}
Libraries = AbstractLibrary.Initialize(yamlObject["libraries"]);
foreach (AbstractLibrary lib in Libraries)
{
RegisterCommands(lib.Commands.ToArray());
foreach (var r in lib.Messages)
Network.RegisterHandler(r.Item1, r.Item2);
}
if (true)
InteractiveMode();
else
......
{
"profiles": {
"KazetaNode": {
"commandName": "Project"
}
}
}
\ No newline at end of file
using KazetaNode.Coms;
using System;
using System.Collections.Generic;
using System.Text;
namespace KazetaNode.Shared.Messages
{
class DiscoveryRequest : IMessage
{
public override string MessageType => throw new NotImplementedException();
}
class DiscoveryResponse : IMessage
{
public override string MessageType => throw new NotImplementedException();
}
}
......@@ -18,6 +18,10 @@ libraries:
kosapi:
clientid: 314b28ac-b629-424d-b33b-ee1eec37596e
clientsecret: dLSsmSehALSSwW5x3DnUwxSz7GsaQFPS
localstorage:
- path: ./data
primary: true
max_usage: 2048
experimentional:
net_timeout: 250
commands:
......
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