コード例 #1
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)
                {
                }

                Task saveTask = Task.Factory.StartNew(() =>
                {
                    if (stream == null)
                    {
                        ScreenshotHelper.SaveBitmapToFile(bmp, imagePath);
                    }
                    else
                    {
                        ScreenshotHelper.SaveStreamToFile(stream, imagePath);
                    }
                }).WithExceptionThrowingInDispatcher(Dispatcher);
            }
        }
コード例 #2
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));
                    }
                }));
            }
        }