static void Main(string[] args) { var rpcServer = new RpcServer("server01", "http://localhost:58355/"); rpcServer.Connection.Received += (data) => Console.WriteLine("ECHO: " + data); rpcServer.OnRpc("add", (long a, long b) => a + b); rpcServer.OnRpc("getFile", (string name) => { return(System.IO.File.OpenRead(System.IO.Path.GetFileName(name))); }); rpcServer.Start().Wait(); rpcServer.Register().Wait(); Console.WriteLine("Ready"); Console.ReadLine(); rpcServer.Unregister().Wait(); }
static void Main(string[] args) { // string baseUrl = "http://localhost:49826"; string baseUrl = "http://ldicocco.azurewebsites.net/"; var rpcServer = new RpcServer("server01", baseUrl); rpcServer.Connection.Received += (data) => Console.WriteLine("ECHO: " + data); rpcServer.OnRpc("getFileSystemEntries", (string root, string path) => { if (!Roots.Instance.ContainsRoot(root) || path.Contains("../")) { return(null); } var rootPath = Roots.Instance[root]; var di = new DirectoryInfo(rootPath + path); var dirs = di.EnumerateFileSystemInfos().Select(i => new { i.Name, Path = i.FullName.Replace(rootPath, ""), IsDirectory = i.Attributes.HasFlag(FileAttributes.Directory) }).ToArray(); return(dirs.OrderByDescending(i => i.IsDirectory).ThenBy(i => i.Name)); }); rpcServer.OnRpc("getFile", (string path, string root) => { if (!Roots.Instance.ContainsRoot(root) || path.Contains("../")) { return(null); } var rootPath = Roots.Instance[root]; return(File.OpenRead(rootPath + path)); }); rpcServer.Start().Wait(); rpcServer.Register().Wait(); Console.WriteLine("Ready"); Console.ReadLine(); rpcServer.Unregister().Wait(); }