The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StreamController.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using Teknik.Areas.Stream.ViewModels;
  8. using Teknik.Attributes;
  9. using Teknik.Controllers;
  10. using Teknik.Filters;
  11. namespace Teknik.Areas.Stream.Controllers
  12. {
  13. [TeknikAuthorize]
  14. public class StreamController : DefaultController
  15. {
  16. [TrackPageView]
  17. [AllowAnonymous]
  18. public ActionResult Index()
  19. {
  20. ViewBag.Title = "Teknikam";
  21. StreamViewModel model = new StreamViewModel();
  22. return View(model);
  23. }
  24. [HttpGet]
  25. [AllowAnonymous]
  26. public FileStreamResult ViewStream(int id)
  27. {
  28. try
  29. {
  30. if (Config.StreamConfig.Enabled)
  31. {
  32. if (id > 0 && id <= Config.StreamConfig.Sources.Count)
  33. {
  34. // ID is valid, so let's get the stream
  35. string source = Config.StreamConfig.Sources[id - 1];
  36. //Create a WebRequest to get the file
  37. HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(source);
  38. //Create a response for this request
  39. HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
  40. return File(fileResp.GetResponseStream(), fileResp.ContentType);
  41. }
  42. }
  43. }
  44. catch (Exception)
  45. {
  46. }
  47. return null;
  48. }
  49. }
  50. }