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

            return(new FileStream(imagePath, FileMode.Open, FileAccess.Read));
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream)
 {
     fileServer.BeginSaveImage(id, image, stream);
 }
Ejemplo n.º 4
0
 public bool IsLoaded(TileIndex id)
 {
     return(memoryServer.Contains(id));
 }
Ejemplo n.º 5
0
 public BitmapSource this[TileIndex id]
 {
     get { return(memoryServer[id]); }
 }
Ejemplo n.º 6
0
 public override bool Contains(TileIndex id)
 {
     return(isNetworkAvailable && MinLevel <= id.Level && id.Level <= MaxLevel);
 }
Ejemplo n.º 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));
                    }
                }));
            }
        }
Ejemplo n.º 8
0
 protected abstract string CreateRequestUriCore(TileIndex index);
Ejemplo n.º 9
0
 public string CreateRequestUri(TileIndex id)
 {
     return(CreateRequestUriCore(id));
 }
Ejemplo n.º 10
0
 public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream)
 {
     cache[id] = image;
 }
Ejemplo n.º 11
0
 public BitmapSource this[TileIndex id] => cache[id];
Ejemplo n.º 12
0
 public override bool Contains(TileIndex id)
 {
     return(cache.ContainsKey(id));
 }