예제 #1
0
        static byte[] getBytes(Guid guid, DownloadCode code, object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                PacketBase.WriteBytes(ms, guid);
                PacketBase.WriteBytes(ms, (int)code);
                switch (code)
                {
                case DownloadCode.DownloadInfo:
                    PacketBase.WriteBytes(ms, DownloadInfoParam.Encode((DownloadInfoParam)obj));
                    break;

                case DownloadCode.Name:
                case DownloadCode.Quality:
                case DownloadCode.ErrorInfo:
                    PacketBase.WriteBytes(ms, (string)obj);
                    break;

                case DownloadCode.Size:
                case DownloadCode.Speed:
                    PacketBase.WriteBytes(ms, (long)obj);
                    break;

                case DownloadCode.IsLocalDownload:
                    PacketBase.WriteBytes(ms, (bool)obj);
                    break;

                case DownloadCode.TimePeriodsAll:
                case DownloadCode.TimePeriodsCompleted:
                    PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray((TimePeriodPacket[])obj));
                    break;

                case DownloadCode.Status:
                    PacketBase.WriteBytes(ms, (int)(DownloadStatus)obj);
                    break;

                case DownloadCode.UpdatedLastestTime:
                    PacketBase.WriteBytes(ms, (DateTime)obj);
                    break;

                case DownloadCode.GoTop:
                    break;
                }
                return(ms.ToArray());
            }
        }
예제 #2
0
        public static DownloadExpandPart Decode(MemoryStream ms)
        {
            Guid         guid = PacketBase.ReadGuid(ms);
            DownloadCode code = (DownloadCode)PacketBase.ReadInt(ms);
            Object       obj  = null;

            switch (code)
            {
            case DownloadCode.DownloadInfo:
                obj = DownloadInfoParam.Decode(ms);
                break;

            case DownloadCode.Name:
            case DownloadCode.Quality:
            case DownloadCode.ErrorInfo:
                obj = PacketBase.ReadString(ms);
                break;

            case DownloadCode.Size:
            case DownloadCode.Speed:
                obj = PacketBase.ReadLong(ms);
                break;

            case DownloadCode.IsLocalDownload:
                obj = PacketBase.ReadBool(ms);
                break;

            case DownloadCode.TimePeriodsAll:
            case DownloadCode.TimePeriodsCompleted:
                obj = TimePeriodPacket.DecodeArray(ms);
                break;

            case DownloadCode.Status:
                obj = (DownloadStatus)PacketBase.ReadInt(ms);
                break;

            case DownloadCode.UpdatedLastestTime:
                obj = PacketBase.ReadTime(ms);
                break;

            case DownloadCode.GoTop:
                obj = null;
                break;
            }
            return(new DownloadExpandPart(guid, code, obj));
        }
        public static DownloadInfoExpandPacket Decode(MemoryStream ms)
        {
            Guid          guid            = PacketBase.ReadGuid(ms);
            IDownloadInfo di              = DownloadInfoParam.Decode(ms);
            string        name            = PacketBase.ReadString(ms);
            string        quality         = PacketBase.ReadString(ms);
            long          size            = PacketBase.ReadLong(ms);
            bool          isLocalDownload = PacketBase.ReadBool(ms);

            TimePeriodPacket[] tps       = TimePeriodPacket.DecodeArray(ms);
            TimePeriodPacket[] tpsc      = TimePeriodPacket.DecodeArray(ms);
            DownloadStatus     status    = (DownloadStatus)PacketBase.ReadInt(ms);
            string             errorInfo = PacketBase.ReadString(ms);
            DateTime           time      = PacketBase.ReadTime(ms);
            long speed = PacketBase.ReadLong(ms);

            return(new DownloadInfoExpandPacket(guid, di, name, quality, size, isLocalDownload, tps, tpsc, status, errorInfo, time, speed));
        }
 public static byte[] Encode(IDownloadInfoExpand packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, packet.GuidCode);
         PacketBase.WriteBytes(ms, DownloadInfoParam.Encode(packet.DownloadInfo));
         PacketBase.WriteBytes(ms, packet.Name);
         PacketBase.WriteBytes(ms, packet.Quality);
         PacketBase.WriteBytes(ms, packet.Size);
         PacketBase.WriteBytes(ms, packet.IsLocalDownload);
         PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriodsAll));
         PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriodsCompleted));
         PacketBase.WriteBytes(ms, (int)packet.DownloadStatus);
         PacketBase.WriteBytes(ms, packet.ErrorInfo);
         PacketBase.WriteBytes(ms, packet.UpdatedLastestTime);
         PacketBase.WriteBytes(ms, packet.Speed);
         return(ms.ToArray());
     }
 }
예제 #5
0
 private void write()
 {
     try
     {
         if (!new FileInfo(_fileName).Directory.Exists)
         {
             new FileInfo(_fileName).Directory.Create();
         }
         using (FileStream fs = new FileStream(_fileName, FileMode.Create, FileAccess.Write, FileShare.Read))
         {
             write(fs, ParamCode.DownloadBase, DownloadInfoParam.Encode(DownloadInfo));
             write(fs, ParamCode.VideoBaseInfo, VideoBasePacket.Encode(VideoBase));
             write(fs, ParamCode.TimePeriods, VideoTimePeriodsPacket.Encode(TimePeriods));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
예제 #6
0
        private void readPacket(Stream ms)
        {
            int length = PacketBase.ReadInt(ms);
            int code   = PacketBase.ReadInt(ms);

            byte[] buffer = PacketBase.ReadByteArray(ms, length - 4);
            switch ((ParamCode)code)
            {
            case ParamCode.VideoBaseInfo:
                if (buffer.Length > 20 && (VideoBase == null || VideoBase.Length == 0))
                {
                    VideoBase = VideoBasePacket.Decode(buffer);
                }
                break;

            case ParamCode.TimePeriods:
                TimePeriods = VideoTimePeriodsPacket.Decode(buffer);
                break;

            case ParamCode.DownloadBase:
                DownloadInfo = DownloadInfoParam.Decode(buffer);
                break;
            }
        }
예제 #7
0
 public DownloadInfoParam(DownloadInfoParam param)
     : this(param as ISourceInfo, param as ITimePeriod, param as IVideoInfo, param.DownloadPath)
 {
 }