示例#1
0
 public void SendResponse(MyWebRequest req)
 {
     string text;
     try
     {
         text = this.GetPlaylist(req);
     }
     catch (Exception ex)
     {
         text = ex.Message;
     }
     req.GetResponse().SendText(text);
 }
示例#2
0
 private void DelFavouriteRequest(MyWebRequest req)
 {
     FavouriteDel favouriteDel = FavouriteDel.Run(this._device.Proxy.SessionState.session, int.Parse(req.Parameters["id"].Split("#".ToCharArray(), 2)[0]));
     MyWebResponse response = req.GetResponse();
     int num1 = 1;
     string str1 = this._device.Web.GetMime(".xml").ToString();
     string charset1 = "utf-8";
     response.AddHeader((HttpHeader)num1, str1, charset1);
     byte[] bytes = Encoding.UTF8.GetBytes(favouriteDel.GetXState());
     int num2 = 0;
     string str2 = bytes.Length.ToString();
     string charset2 = "utf-8";
     response.AddHeader((HttpHeader)num2, str2, charset2);
     int code = 200;
     response.SendHeaders(code);
     response.GetStream().Write(bytes, 0, bytes.Length);
 }
示例#3
0
 private void LoginRequest(MyWebRequest obj)
 {
     this.Proxy.Login();
     MyWebResponse response = obj.GetResponse();
     byte[] bytes = Encoding.UTF8.GetBytes(this.Proxy.SessionState.ToString());
     int num1 = 1;
     string str1 = "text/xml";
     string charset1 = "utf-8";
     response.AddHeader((HttpHeader)num1, str1, charset1);
     int num2 = 0;
     string str2 = bytes.Length.ToString();
     string charset2 = "utf-8";
     response.AddHeader((HttpHeader)num2, str2, charset2);
     int code = 200;
     response.SendHeaders(code);
     response.GetStream().Write(bytes, 0, bytes.Length);
 }
示例#4
0
 private void ScreenRequest(MyWebRequest myWebRequest)
 {
     if (!myWebRequest.Parameters.ContainsKey("id"))
     {
         this._device.Web.Send404(myWebRequest);
     }
     else
     {
         byte[] bytes = Encoding.UTF8.GetBytes(TranslationScreen.XRun(this._device.Proxy.SessionState.session, int.Parse(myWebRequest.Parameters["id"])).ToString());
         MyWebResponse response = myWebRequest.GetResponse();
         int num1 = 1;
         string str1 = this._device.Web.GetMime(".xml").ToString();
         string charset1 = "utf-8";
         response.AddHeader((HttpHeader)num1, str1, charset1);
         int num2 = 0;
         string str2 = bytes.Length.ToString();
         string charset2 = "utf-8";
         response.AddHeader((HttpHeader)num2, str2, charset2);
         int code = 200;
         response.SendHeaders(code);
         response.GetStream().Write(bytes, 0, bytes.Length);
     }
 }
示例#5
0
 public override void Play(MyWebRequest req)
 {
     GetStream getStream = GetStream.Run(this._device.Proxy.SessionState.session, int.Parse(req.Parameters["id"].Split("#".ToCharArray(), 2)[0]));
     if (!getStream.IsSuccess())
     {
         if (getStream.error != ApiError.incorrect)
             throw new Exception(getStream.error.ToString());
         while (!this._device.Proxy.Login() && this._device.Proxy.SessionState.error == ApiError.noconnect)
             TtvProxy.Log.WriteInfo("Попыдка авторизации на torrent-tv.ru");
         if (!this._device.Proxy.SessionState.IsSuccess())
             throw new Exception("No authorized");
         this.Play(req);
     }
     else
     {
         TorrentStream ts = this._device.Proxy.GetTsClient(getStream.source);
         Task<string> task;
         if (ts == null)
         {
             if (!req.Client.Connected)
                 return;
             ts = new TorrentStream(req.Client);
             ts.Connect();
             task = ts.Play(getStream.source, getStream.type, 0);
             if (task != null)
                 this._device.Proxy.AddToTsPool(ts);
         }
         else
         {
             task = ts.GetPlayTask();
             ts.Owner.Add(req.Client);
         }
         if (task != null && !task.IsCompleted)
             task.Wait();
         else if (task == null)
             throw new FileNotFoundException();
         if (string.IsNullOrEmpty(task.Result))
         {
             this._device.Proxy.RemoveFromTsPoos(ts);
             req.GetResponse().SendText("AceStream TimeOut");
         }
         else
         {
             string result = task.Result;
             string str = string.Empty;
             try
             {
                 str = this._device.Proxy.FindBroadcastUrl(result);
                 if (string.IsNullOrEmpty(str))
                     str = this._device.Proxy.StartBroadcastStream(result, (string)null);
                 this._device.Proxy.AddVlcBroadcastClient(str, req.Client);
                 req.GetResponse().SendStream(str, (Action<MyWebRequest>)null);
                 if (req.Client.Connected)
                     req.Client.Close();
                 if (!this._device.Proxy.StopBroadcast(str, result))
                     return;
                 ts.Disconnect(true);
                 this._device.Proxy.RemoveFromTsPoos(ts);
             }
             catch (Exception ex)
             {
                 TtvProxy.Log.WriteError(ex.Message);
                 ts.Disconnect(true);
                 this._device.Proxy.RemoveFromTsPoos(ts);
                 this._device.Proxy.StopBroadcast(str, result);
             }
         }
     }
 }
示例#6
0
 public void SendFile(MyWebRequest req, string fpath)
 {
     if (!System.IO.File.Exists(fpath))
         this.Send404(req);
     FileStream fileStream = System.IO.File.OpenRead(fpath);
     MyWebResponse response = req.GetResponse();
     response.AddHeader(HttpHeader.ContentType, this._mimes[Path.GetExtension(fpath)].ToString(), "utf-8");
     response.AddHeader(HttpHeader.ContentLength, fileStream.Length.ToString(), "utf-8");
     fileStream.CopyTo(response.GetStream());
 }
示例#7
0
 public void Send404(MyWebRequest req)
 {
     MyWebResponse response = req.GetResponse();
     response.AddHeader(HttpHeader.ContentType, "text/html; charset=UTF-8", "utf-8");
     byte[] bytes = Encoding.UTF8.GetBytes("<h1>404. Файл не найден</h1>");
     response.AddHeader(HttpHeader.ContentLength, bytes.Length.ToString(), "utf-8");
     response.SendHeaders(200);
     try
     {
         response.GetStream().Write(bytes, 0, bytes.Length);
     }
     catch (Exception ex)
     {
         TtvProxy.Log.Write(ex.Message, TypeMessage.Error);
     }
 }