public void TestLocalDownloadInfoPacket() { LocalDownloadInfoPacket packet = new LocalDownloadInfoPacket(new VideoInfo("videoId", 1), "path"); var buffer = LocalDownloadInfoPacket.Encode(packet); var packet2 = LocalDownloadInfoPacket.Decode(buffer); Assert.AreNotSame(packet, packet2); Assert.AreEqual(packet.Path, packet2.Path); Assert.AreNotSame(packet.Info, packet2.Info); Assert.AreEqual(packet.Info.VideoId, packet2.Info.VideoId); Assert.AreEqual(packet.Info.VideoName, packet2.Info.VideoName); Assert.AreEqual(packet.Info.StreamId, packet2.Info.StreamId); }
private void onReceiveCompleted(object sender, ReceiveEventArgs args) { try { if (args.ByteLength > 0) { using (MemoryStream ms = new MemoryStream(args.ReceivedBytes)) { ParamCode code = (ParamCode)PacketBase.ReadInt(ms); byte[] buffer = null; switch (code) { case ParamCode.VideoInfosTimePeriods: updateVideoInfosTimePeriods(VideoDataInfoParam.Decode(ms)); break; case ParamCode.DownloadBegin: beginDownload(DownloadInfoParam.Decode(ms)); break; case ParamCode.DownloadToLocal: downloadToLocal(PacketBase.ReadString(ms)); break; case ParamCode.VideoPacket: getVideoStreamsPacket(VideoDataParam.Decode(ms)); break; case ParamCode.ProbeTime: setProbeTime(PacketBase.ReadTime(ms)); break; case ParamCode.DownloadInfosAll: feedbackDownloadInfosToClient(); break; case ParamCode.DownloadControl: var controlCode = (DownloadControlCode)PacketBase.ReadInt(ms); onDownloadControl(controlCode, ms); break; case ParamCode.LocalDownloadPath: onLocalDownloadPath(PacketBase.ReadString(ms)); break; case ParamCode.LocalDownloadBegin: onLocalDownloadStart(LocalDownloadInfoPacket.Decode(ms)); break; } if (buffer != null) { send((ParamCode)code, buffer); } } } } catch (IOException ex) { sendMessage(MessageType.Warn, ex.Message, null); } catch (Exception ex) { sendMessage(MessageType.Error, ex.Message, null); Console.WriteLine(ex.ToString()); } }