Exemple #1
0
 /// <summary>
 /// returns the toc which is asynchronously completed.
 /// </summary>
 internal Toc <T> Start()
 {
     _toc        = new Toc <T>();
     _fetchState = FetchState.GET_TOC_INFO;
     _communicator.RegisterEventHandler(_port, TocPacketReceived);
     SendTocInfoRequest();
     return(_toc);
 }
 public void AddToc(uint crc, Toc <T> toc)
 {
     lock (_cached)
     {
         _cached[crc] = toc;
         if (GetFromFileCache(crc) == null)
         {
             toc.SerializeToFile(new FileInfo(Path.Combine(_cacheDirectory.FullName, GetFileName(crc))));
         }
     }
 }
        public static Toc <T> DeserializeFromFile(FileInfo file)
        {
            var asList = JsonConvert.DeserializeObject <List <T> >(
                File.ReadAllText(file.FullName));
            var fileResult = new Toc <T>();

            foreach (var element in asList)
            {
                fileResult.AddElement(element);
            }
            return(fileResult);
        }
        public Toc <T> GetByCrc(uint crc)
        {
            lock (_cached)
            {
                Toc <T> resultToc;
                if (!_cached.TryGetValue(crc, out resultToc))
                {
                    var cachedFile = GetFromFileCache(crc);
                    if (cachedFile != null)
                    {
                        var fromFile = Toc <T> .DeserializeFromFile(cachedFile);

                        _cached[crc] = fromFile;
                        resultToc    = fromFile;
                    }
                }
                return(resultToc);
            }
        }
 /// <summary>
 /// take elements from a cached LogToc.
 /// </summary>
 internal void AddFromCache(Toc <T> cached)
 {
     _tocContent = cached._tocContent;
 }
 protected void FetchTocFromTocFetcher()
 {
     CurrentToc = _tocFetcher.Start();
 }
 public Task <Toc <T> > RefreshToc()
 {
     CurrentToc = null;
     _loadTocDone.Reset();
     return(Task.Run(() => LoadToc()));
 }