diff --git a/Pages/Conference.cshtml b/Pages/Conference.cshtml index 6a00265..b8fe755 100644 --- a/Pages/Conference.cshtml +++ b/Pages/Conference.cshtml @@ -4,113 +4,112 @@ @using global::c3stream.DataModels @using static ConferenceModel @{ - if (c3stream.Conferences.All(c => c.Acronym != Request.Query["c"])) { - Response.Redirect("/"); - return; - } + if (c3stream.Conferences.All(c => c.Acronym != Request.Query["c"])) { + Response.Redirect("/"); + return; + } - var cookie = c3stream.UpdateCookie(Request, Response, $"/Conference?c={Request.Query["c"]}"); - ViewData["Title"] = Request.Query["c"]; - var wc = new WebClient(); - var conference = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]); - if (conference.Ongoing) { - c3stream.UpdateConference(conference); - } - wc.Dispose(); - await using var db = new Database.DbConn(); - var states = db.States.ToList(); + var cookie = c3stream.UpdateCookie(Request, Response, $"/Conference?c={Request.Query["c"]}"); + ViewData["Title"] = Request.Query["c"]; + var conference = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]); + if (conference.Ongoing) { + c3stream.UpdateConference(conference); + } + await using var db = new Database.DbConn(); + var states = db.States.ToList(); } - - - - - - - - - - - - - @foreach (var talk in Request.Query["orderby"] == "published" ? conference.Talks.OrderByDescending(p => p.ReleaseDate) : conference.Talks.OrderBy(p => p.Date)) { - var state = states.FirstOrDefault(p => p.TalkId == talk.Guid && p.UserId == cookie)?.State; - var isWatched = state == "watched"; - var isMarked = state == "marked"; - var file = $"{talk.Slug}.mp4"; - var eventName = talk.Tags.Count <= 1 ? conference.Acronym : talk.Tags[0].Replace("-", "-
"); - var category = talk.Tags.Count switch { - 0 => "", - 1 => talk.Tags[0], - 2 => "", - 3 => talk.Tags[2], - 4 => talk.Tags[3], - 5 => talk.Tags[3], - 6 => talk.Tags[3], // rc3: is this correct? - _ => "" - }; - - - - - @if (isWatched) { - - } - else if (isMarked) { - - } - else { - - } - - - - - } - + + + + + + + + + + + + + @foreach (var talk in Request.Query["orderby"] == "published" ? conference.Talks.OrderByDescending(p => p.ReleaseDate) : conference.Talks.OrderBy(p => p.Date)) { + var state = states.FirstOrDefault(p => p.TalkId == talk.Guid && p.UserId == cookie)?.State; + var isWatched = state == "watched"; + var isMarked = state == "marked"; + var file = $"{talk.Slug}.mp4"; + var eventName = talk.Tags.Count <= 1 ? conference.Acronym : talk.Tags[0].Replace("-", "-
"); + var category = talk.Tags.Count switch { + 0 => "", + 1 => talk.Tags[0], + 2 => "", + 3 => talk.Tags[2], + 4 => talk.Tags[3], + 5 => talk.Tags[3], + 6 => talk.Tags[3], // rc3: is this correct? + _ => "" + }; + + + + + @if (isWatched) { + + } + else if (isMarked) { + + } + else { + + } + + + + + } +
Event - @Html.Raw(Request.Query["orderby"] == "published" ? $"Published" : $"Date")CategoryTitleSpeaker(s)LangActions
@Html.Raw(eventName)@(Request.Query["orderby"] == "published" ? talk.ReleaseDate?.Date.ToShortDateString() : talk.Date?.Date.ToShortDateString())@category@talk.Title@talk.Title@talk.Title@(talk.Persons.Any() ? talk.Persons.Aggregate((s, s1) => $"{s}, {s1}") : "")@talk.OriginalLanguage -
- - - - @if (System.IO.File.Exists(System.IO.Path.Combine(c3stream.CachePath, conference.Acronym, file))) { - - - - } - else { - - - - } - - - - @if (isWatched) { - - - } - else if (isMarked) { - - - } - else { - - - } -
-
Event + @Html.Raw(Request.Query["orderby"] == "published" ? $"Published" : $"Date") + CategoryTitleSpeaker(s)LangActions
@Html.Raw(eventName)@(Request.Query["orderby"] == "published" ? talk.ReleaseDate?.Date.ToShortDateString() : talk.Date?.Date.ToShortDateString())@category@talk.Title@talk.Title@talk.Title@(talk.Persons.Any() ? talk.Persons.Aggregate((s, s1) => $"{s}, {s1}") : "")@talk.OriginalLanguage +
+ + + + @if (System.IO.File.Exists(System.IO.Path.Combine(c3stream.CachePath, conference.Acronym, file))) { + + + + } + else { + + + + } + + + + @if (isWatched) { + + + } + else if (isMarked) { + + + } + else { + + + } +
+
\ No newline at end of file diff --git a/c3stream.cs b/c3stream.cs index 55a35ba..a1c005b 100644 --- a/c3stream.cs +++ b/c3stream.cs @@ -2,10 +2,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; +using System.Net.Http; using c3stream.DataModels; -using c3stream.Pages; -using LinqToDB.Common; using LinqToDB.Data; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -39,8 +37,8 @@ namespace c3stream { Directory.CreateDirectory(DataPath); if (!File.Exists(DbPath)) File.Copy(Path.Combine(DataPath, "database.init.sqlite"), DbPath); - - DataConnection.DefaultSettings = new Database.Settings(); + + DataConnection.DefaultSettings = new Database.Settings(); foreach (var conference in Conferences) UpdateConference(conference); @@ -63,16 +61,16 @@ namespace c3stream { //TODO: move this to the database as well public static void UpdateConference(ConferenceObject conference) { - using var wc = new WebClient(); + using var httpc = new HttpClient(); var jsonpath = Path.Combine(DataPath, conference.Acronym + "_index.json"); var json = ""; if (!File.Exists(jsonpath)) { - json = wc.DownloadString($"https://api.media.ccc.de/public/conferences/{conference.Acronym}"); + json = httpc.GetStringAsync($"https://api.media.ccc.de/public/conferences/{conference.Acronym}").Result; File.WriteAllText(jsonpath, json); } else if (conference.Ongoing) { - json = wc.DownloadString($"https://api.media.ccc.de/public/conferences/{conference.Acronym}"); + json = httpc.GetStringAsync($"https://api.media.ccc.de/public/conferences/{conference.Acronym}").Result; } else { json = File.ReadAllText(jsonpath); @@ -91,13 +89,13 @@ namespace c3stream { var cookie = ""; //if new bookmark is in uri if (request.Query.ContainsKey("bookmark") && Guid.TryParseExact(request.Query["bookmark"], "D", out _)) { - response.Cookies.Append("bookmark", request.Query["bookmark"], new CookieOptions {Expires = DateTimeOffset.MaxValue}); + response.Cookies.Append("bookmark", request.Query["bookmark"], new CookieOptions { Expires = DateTimeOffset.MaxValue }); cookie = request.Query["bookmark"]; } //if no cookie exists or cookie is invalid else if (!request.Cookies.ContainsKey("bookmark") || !Guid.TryParseExact(request.Cookies["bookmark"], "D", out _)) { var guid = Guid.NewGuid().ToString(); - response.Cookies.Append("bookmark", guid, new CookieOptions {Expires = DateTimeOffset.MaxValue}); + response.Cookies.Append("bookmark", guid, new CookieOptions { Expires = DateTimeOffset.MaxValue }); cookie = guid; } else { @@ -134,4 +132,4 @@ namespace c3stream { } } } -} +} \ No newline at end of file