private void TransmitGetRequestStream(IAsyncResult ar) { Stream stream; try { stream = current_web_req.EndGetRequestStream(ar); } catch (Exception e) { Log.Exception("Failed to get the request stream", e); state = State.Idle; next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS); return; } TransmitState ts = (TransmitState)ar.AsyncState; StringBuilder sb = ts.StringBuilder; StreamWriter writer = new StreamWriter(stream); writer.Write(sb.ToString()); writer.Close(); state = State.WaitingForResponse; current_async_result = current_web_req.BeginGetResponse(TransmitGetResponse, ts); if (current_async_result == null) { next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS); hard_failures++; state = State.Idle; } }
private static int SetFilter(double low, double high, int taps, TransmitState trx_on) { SetFilter_DLL(low, high, taps, trx_on); SetRXListen(1); int i = SetFilter_DLL(low, high, taps, trx_on); SetRXListen(0); return(i); }
private void TransmitQueue() { int num_tracks_transmitted; // save here in case we're interrupted before we complete // the request. we save it again when we get an OK back // from the server queue.Save(); next_interval = DateTime.MinValue; if (post_url == null || !connected) { return; } string song_transmit_info = queue.GetTransmitInfo(out num_tracks_transmitted); Log.DebugFormat("Last.fm scrobbler sending '{0}' to {1}", song_transmit_info, post_url); StringBuilder sb = new StringBuilder(); sb.AppendFormat("s={0}", session_id); sb.Append(song_transmit_info); current_web_req = (HttpWebRequest)WebRequest.Create(post_url); current_web_req.UserAgent = LastfmCore.UserAgent; current_web_req.Method = "POST"; current_web_req.ContentType = "application/x-www-form-urlencoded"; current_web_req.ContentLength = sb.Length; TransmitState ts = new TransmitState(); ts.Count = num_tracks_transmitted; ts.StringBuilder = sb; state = State.WaitingForRequestStream; current_async_result = current_web_req.BeginGetRequestStream(TransmitGetRequestStream, ts); if (!(current_async_result.AsyncWaitHandle.WaitOne(TIME_OUT, false))) { Log.Warning("Audioscrobbler upload failed", "The request timed out and was aborted", false); next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS); hard_failures++; state = State.Idle; current_web_req.Abort(); } }
private void SetRecControl(TransmitState State, TFileInfo fileinfo) { if (State == TransmitState.Transmitting) { this.progressBar1.Value = Convert.ToInt32(((decimal)fileinfo.CurrLength / fileinfo.Length) * 100); this.labelFileLengthString.Text = IMLibrary3.Operation.Calculate.GetSizeStr(fileinfo.CurrLength) + "/" + fileinfo.LengthStr; } else if (State == TransmitState.Connected) { linkLabelOffline.Visible = false; if (isSend) { this.labelRequest.Text = "正在发送文件..."; } else { this.labelRequest.Text = "正在接收文件..."; } if (fileinfo.connectedType == ConnectedType.UDPLocal) { labelConType.Text = "[UDP直连]"; } else if (fileinfo.connectedType == ConnectedType.UDPRemote) { labelConType.Text = "[UDP直连]"; } else { labelConType.Text = "[服务器中转连接]"; } } else if (State == TransmitState.Over) { if (fileTransmitted != null) { fileTransmitted(this); //触发文件 } } }
private void TransmitQueue() { int num_tracks_transmitted; // save here in case we're interrupted before we complete // the request. we save it again when we get an OK back // from the server queue.Save(); next_interval = DateTime.MinValue; if (post_url == null || !connected) { return; } StringBuilder sb = new StringBuilder(); sb.AppendFormat("s={0}", session_id); sb.Append(queue.GetTransmitInfo(out num_tracks_transmitted)); current_web_req = (HttpWebRequest)WebRequest.Create(post_url); current_web_req.UserAgent = LastfmCore.UserAgent; current_web_req.Method = "POST"; current_web_req.ContentType = "application/x-www-form-urlencoded"; current_web_req.ContentLength = sb.Length; //Console.WriteLine ("Sending {0} ({1} bytes) to {2}", sb.ToString (), sb.Length, post_url); TransmitState ts = new TransmitState(); ts.Count = num_tracks_transmitted; ts.StringBuilder = sb; state = State.WaitingForRequestStream; current_async_result = current_web_req.BeginGetRequestStream(TransmitGetRequestStream, ts); if (!(current_async_result.AsyncWaitHandle.WaitOne(TIME_OUT, false))) { if (log.IsWarnEnabled) { log.Warn("Audioscrobbler upload failed." + " The request timed out and was aborted"); } next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS); hard_failures++; state = State.Idle; current_web_req.Abort(); } }
private void TransmitGetResponse(IAsyncResult ar) { WebResponse resp; try { resp = current_web_req.EndGetResponse(ar); } catch (Exception e) { Log.Warning(String.Format("Failed to get the response: {0}", e), false); state = State.Idle; next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS); return; } TransmitState ts = (TransmitState)ar.AsyncState; Stream s = resp.GetResponseStream(); StreamReader sr = new StreamReader(s, Encoding.UTF8); string line; line = sr.ReadLine(); DateTime now = DateTime.Now; if (line.StartsWith("FAILED")) { if (now - last_upload_failed_logged > TimeSpan.FromMinutes(FAILURE_LOG_MINUTES)) { Log.Warning("Audioscrobbler upload failed", line.Substring("FAILED".Length).Trim(), false); last_upload_failed_logged = now; } // retransmit the queue on the next interval hard_failures++; state = State.NeedTransmit; } else if (line.StartsWith("BADSESSION")) { if (now - last_upload_failed_logged > TimeSpan.FromMinutes(FAILURE_LOG_MINUTES)) { Log.Warning("Audioscrobbler upload failed", "session ID sent was invalid", false); last_upload_failed_logged = now; } // attempt to re-handshake (and retransmit) on the next interval session_id = null; next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS); state = State.NeedHandshake; return; } else if (line.StartsWith("OK")) { /* if we've previously logged failures, be nice and log the successful upload. */ if (last_upload_failed_logged != DateTime.MinValue) { Log.Debug("Audioscrobbler upload succeeded"); last_upload_failed_logged = DateTime.MinValue; } hard_failures = 0; // we succeeded, pop the elements off our queue queue.RemoveRange(0, ts.Count); queue.Save(); state = State.Idle; } else { if (now - last_upload_failed_logged > TimeSpan.FromMinutes(FAILURE_LOG_MINUTES)) { Log.Warning("Audioscrobbler upload failed", String.Format("Unrecognized response: {0}", line), false); last_upload_failed_logged = now; } state = State.Idle; } sr.Close(); }
private void SetRecControl(TransmitState State, TFileInfo fileinfo) { if (State == TransmitState.Transmitting) { this.progressBar1.Value = Convert.ToInt32(((decimal)fileinfo.CurrLength / fileinfo.Length) * 100); this.labelFileLengthString.Text = IMLibrary3.Operation.Calculate.GetSizeStr(fileinfo.CurrLength) + "/" + fileinfo.LengthStr; } else if (State == TransmitState.Connected) { linkLabelOffline.Visible = false; if (isSend) this.labelRequest.Text = "正在发送文件..."; else this.labelRequest.Text = "正在接收文件..."; if (fileinfo.connectedType == ConnectedType.UDPLocal) labelConType.Text = "[UDP直连]"; else if (fileinfo.connectedType == ConnectedType.UDPRemote) labelConType.Text = "[UDP直连]"; else labelConType.Text = "[服务器中转连接]"; } else if (State == TransmitState.Over) { if (fileTransmitted != null) fileTransmitted(this);//触发文件 } }
unsafe public static extern void SetTRX(TransmitState trx_on);
private static extern int SetFilter_DLL(double low, double high, int taps, TransmitState trx_on);