/// <summary> /// Constrói um texto a partir de um template embarcado no assembly. /// Os templates devem existir na pasta "/meta/templates". /// </summary> /// <param name="templateName">Nome do template embarcado.</param> /// <param name="argPairs"> /// Parâmetros repassados para o template. /// Um vetor de chaves e valores. /// Nas posições pares devem constar os nomes dos argumentos e nas /// posições ímpares devem constar seus valores. /// </param> /// <returns>O texto construído pela aplicação do template</returns> public static string ApplyTemplate(string templateName, params object[] argPairs) { if ((argPairs.Length % 2) != 0) { throw new Exception("Quantidade inválida de argumentos. O vetor deveria ter uma coleção de chaves e valores."); } var template = EmbeddedFiles.RetrieveTextFile(templateName); if (template == null) { throw new Exception("O template não existe embarcado: " + templateName); } var context = new ExpressionContext(); for (var i = 0; i < argPairs.Length; i += 2) { var key = argPairs[i].ToString(); var value = argPairs[i + 1]; context[key] = value; } var expression = ExpressionParser.ParseTemplate(template); var html = expression.Evaluate(context); return(html); }
public void Extract_embedded_to_a_file() { var embeddedFile = new EmbeddedFiles <MiruCli.Program>(); embeddedFile.ExtractFile("miru.cmd", A.TempPath("EmbeddedFileTest", "miru.cmd")); File.Exists(A.TempPath("EmbeddedFileTest", "miru.cmd")); }
public static void Main(string[] args) { string packedRippleSpaceFile = "./default-ripplespace"; for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-h": case "--help": Console.WriteLine("Nibriboard Server"); Console.WriteLine("By Starbeamrainbowlabs"); Console.WriteLine(); Console.WriteLine("Usage:"); Console.WriteLine(" ./Nibriboard.exe [options]"); Console.WriteLine(); Console.WriteLine("Options:"); Console.WriteLine(" -h --help Shows this message"); Console.WriteLine(" -f --file [filepath] Specify the path to the packed ripplespace file to load. Defaults to '{0}'.", packedRippleSpaceFile); Console.WriteLine(); return; case "-f": case "--file": packedRippleSpaceFile = args[++i]; break; } } Log.WriteLine($"[core] Nibriboard Server {NibriboardServer.Version}, built on {NibriboardServer.BuildDate.ToString("R")}"); Log.WriteLine("[core] An infinite whiteboard for those big ideas."); Log.WriteLine("[core] By Starbeamrainbowlabs"); Log.WriteLine("[core] Starting"); Log.WriteLine("[core] Detected embedded files: "); EmbeddedFiles.WriteResourceList(); Log.WriteLine("[core] Loading ripple space from \"{0}\".", packedRippleSpaceFile); NibriboardServer server = new NibriboardServer(packedRippleSpaceFile); Task.WaitAll( server.Start(), server.StartCommandListener() ); }
/// <summary> /// Converts this string into a standardized "identifier". /// </summary> public static string ToIdentifier(this string path) { return(EmbeddedFiles.NormalizeManifestPath(path)); }
public override async Task <HttpConnectionAction> HandleHttpRequest(HttpRequest request, HttpResponse response) { if (request.Method != HttpMethod.GET) { response.ResponseCode = HttpResponseCode.MethodNotAllowed; response.ContentType = "text/plain"; await response.SetBody("Error: That method isn't supported yet."); logRequest(request, response); return(HttpConnectionAction.Continue); } // TODO: Make authentication happen on the websocket only if (request.Url == "/" && !ShouldAcceptConnection(request, response)) { return(HttpConnectionAction.Continue); } if (request.Url == "/Settings.json") { string settingsJson = JsonConvert.SerializeObject(clientSettings); response.ContentLength = settingsJson.Length; response.Headers.Add("etag", Hash.SHA1(settingsJson)); response.ContentType = "application/json"; await response.SetBody(settingsJson); Log.WriteLine("[Http/ClientSettings] Sent settings to {0}", request.ClientAddress); return(HttpConnectionAction.Continue); } string expandedFilePath = getEmbeddedFileReference(request.Url); if (!embeddedFiles.Contains(expandedFilePath)) { expandedFilePath += "index.html"; } if (!embeddedFiles.Contains(expandedFilePath)) { response.ResponseCode = HttpResponseCode.NotFound; response.ContentType = "text/plain"; await response.SetBody($"Can't find '{expandedFilePath}'."); logRequest(request, response); return(HttpConnectionAction.Continue); } response.ContentType = LookupMimeType(expandedFilePath); byte[] embeddedFile = EmbeddedFiles.ReadAllBytes(expandedFilePath); // Generate and attach the etag to the response response.Headers.Add("etag", Hash.SHA1(embeddedFile)); if (request.GetHeaderValue("if-none-match", string.Empty).Replace("\"", "") == response.Headers["etag"]) { // It's the same! Tell them so. response.ContentLength = 0; response.ResponseCode = HttpResponseCode.NotModified; return(HttpConnectionAction.Continue); } try { await response.SetBody(embeddedFile); } catch (Exception error) { Log.WriteLine($"[Nibriboard/EmbeddedFileHandler] Error: {error.Message} Details:"); Log.WriteLine(error.ToString()); } logRequest(request, response); return(HttpConnectionAction.Continue); }