コード例 #1
0
        private void PersistList(object state)
        {
            List <DownloadItem> downloadsToSave = new List <DownloadItem>();

            using (DownloadManager.Instance.LockDownloadList(false))
            {
                IList <Core.Downloader> downloads = DownloadManager.Instance.Downloads;

                for (int i = 0; i < downloads.Count; i++)
                {
                    if (downloads[i].State == DownloaderState.Ended)
                    {
                        continue;
                    }

                    Core.Downloader downloader = downloads[i];

                    DownloadItem di = new DownloadItem();
                    di.LocalFile          = downloader.LocalFile;
                    di.rl                 = downloader.ResourceLocation;
                    di.mirrors            = downloader.Mirrors.ToArray();
                    di.remoteInfo         = downloader.RemoteFileInfo;
                    di.requestedSegments  = downloader.RequestedSegments;
                    di.createdDateTime    = downloader.CreatedDateTime;
                    di.extendedProperties = new SerializableDictionary <string, object>(downloader.ExtendedProperties);

                    using (downloader.LockSegments())
                    {
                        di.Segments = new SegmentItem[downloader.Segments.Count];

                        for (int j = 0; j < downloader.Segments.Count; j++)
                        {
                            SegmentItem si  = new SegmentItem();
                            Segment     seg = downloader.Segments[j];

                            si.Index = seg.Index;
                            si.InitialStartPositon = seg.InitialStartPosition;
                            si.StartPositon        = seg.StartPosition;
                            si.EndPosition         = seg.EndPosition;

                            di.Segments[j] = si;
                        }
                    }

                    downloadsToSave.Add(di);
                }
            }

            SaveObjects(downloadsToSave);
        }
コード例 #2
0
        private static void LoadPersistedObjects(DownloadItem[] downloads)
        {
            for (int i = 0; i < downloads.Length; i++)
            {
                List <Segment> segments = new List <Segment>();

                for (int j = 0; j < downloads[i].Segments.Length; j++)
                {
                    Segment seg = new Segment();
                    seg.Index = downloads[i].Segments[j].Index;
                    seg.InitialStartPosition = downloads[i].Segments[j].InitialStartPositon;
                    seg.StartPosition        = downloads[i].Segments[j].StartPositon;
                    seg.EndPosition          = downloads[i].Segments[j].EndPosition;

                    segments.Add(seg);
                }

                Core.Downloader d = DownloadManager.Instance.Add(
                    downloads[i].rl,
                    downloads[i].mirrors,
                    downloads[i].LocalFile,
                    segments,
                    downloads[i].remoteInfo,
                    downloads[i].requestedSegments,
                    false,
                    downloads[i].createdDateTime);

                if (downloads[i].extendedProperties != null)
                {
                    SerializableDictionary <string, object> .Enumerator e = downloads[i].extendedProperties.GetEnumerator();

                    while (e.MoveNext())
                    {
                        d.ExtendedProperties.Add(e.Current.Key, e.Current.Value);
                    }
                }
            }
        }