private Stream BeginLoadStreamAsync(TileIndex id)
        {
            string imagePath = GetImagePath(id);

            return(new FileStream(imagePath, FileMode.Open, FileAccess.Read));
        }
        public void BeginLoadImage(TileIndex id)
        {
            if (pendingImages.Contains(id))
            {
                return;
            }

            bool beganLoading = false;

            if (memoryServer.Contains(id))
            {
                // do nothing
            }
            else
            {
                if (allowFastNetworkLoad && sourceServer.CanLoadFast(id))
                {
                    sourceServer.BeginLoadImage(id);
                    beganLoading = true;
                }
                else
                {
                    switch (mode)
                    {
                    case TileSystemMode.OnlineOnly:
                        if (sourceServer.Contains(id))
                        {
                            sourceServer.BeginLoadImage(id);
                            beganLoading = true;
                        }
                        break;

                    case TileSystemMode.OnlineAndCache:
                        if (fileServer.Contains(id))
                        {
                            fileServer.BeginLoadImage(id);
                            beganLoading = true;
                        }
                        else if (sourceServer.Contains(id))
                        {
                            sourceServer.BeginLoadImage(id);
                            beganLoading = true;
                        }
                        break;

                    case TileSystemMode.CacheOnly:
                        if (fileServer.Contains(id))
                        {
                            fileServer.BeginLoadImage(id);
                            beganLoading = true;
                        }
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
                if (beganLoading)
                {
                    bool wasLatestError = latestFailuredId != null && latestFailuredId.Value.Equals(id);
                    if (!memoryServer.Contains(id) && !wasLatestError)
                    {
                        pendingImages.Add(id);
                    }
                }
            }

            latestFailuredId = null;
        }
 public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream)
 {
     fileServer.BeginSaveImage(id, image, stream);
 }
 public bool IsLoaded(TileIndex id)
 {
     return(memoryServer.Contains(id));
 }
 public BitmapSource this[TileIndex id]
 {
     get { return(memoryServer[id]); }
 }
예제 #6
0
 public override bool Contains(TileIndex id)
 {
     return(isNetworkAvailable && MinLevel <= id.Level && id.Level <= MaxLevel);
 }
예제 #7
0
        public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream)
        {
            string imagePath = GetImagePath(id);

            bool errorWhileDeleting = false;

            bool containsOld = Contains(id);

            if (containsOld && saveOption == SaveOption.ForceUpdate)
            {
                try
                {
                    File.Delete(imagePath);
                }
                catch (IOException exc)
                {
                    // todo возможно, тут добавить файл в очередь на удаление или перезапись новым содержимым
                    // когда он перестанет быть блокированным
                    MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation("{0} - error while deleting tile {1}: {2}", ServerName, id, exc.Message);
                    errorWhileDeleting = true;
                }
            }

            bool shouldSave = saveOption == SaveOption.ForceUpdate && !errorWhileDeleting ||
                              saveOption == SaveOption.PreserveOld && !containsOld;

            if (shouldSave)
            {
                MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation(String.Format("{0}: begin to save: id = {1}", ServerName, id));
                FileMap[id] = true;

                Statistics.IntValues["ImagesSaved"]++;

                BitmapSource bmp = image;
                if (!bmp.IsFrozen)
                {
                }

                ThreadPool.QueueUserWorkItem(new WaitCallback((unused) =>
                {
                    // Try to write tile to cache. Conflicts are possible
                    // especially in case of multiple Map control instances.
                    // That's why exception is only dumped to debug output.
                    try
                    {
                        if (stream == null)
                        {
                            ScreenshotHelper.SaveBitmapToFile(bmp, imagePath);
                        }
                        else
                        {
                            ScreenshotHelper.SaveStreamToFile(stream, imagePath);
                        }
                    }
                    catch (Exception exc)
                    {
                        Debug.WriteLine(String.Format("Error writing tile to cache: {0}", exc.Message));
                    }
                }));
            }
        }
예제 #8
0
 protected abstract string CreateRequestUriCore(TileIndex index);
예제 #9
0
 public string CreateRequestUri(TileIndex id)
 {
     return(CreateRequestUriCore(id));
 }
예제 #10
0
 public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream)
 {
     cache[id] = image;
 }
예제 #11
0
 public BitmapSource this[TileIndex id] => cache[id];
예제 #12
0
 public override bool Contains(TileIndex id)
 {
     return(cache.ContainsKey(id));
 }