Beispiel #1
0
        /// <summary>
        /// Gets tile image for the specified tile id.
        /// </summary>
        /// <param name="id">Tile details id.</param>
        /// <param name="level">Level of the image.</param>
        /// <param name="x">X axis image.</param>
        /// <param name="y">Y axis image.</param>
        /// <returns>Tile image for the specified image.</returns>
        public Stream GetTileImage(string id, int level, int x, int y)
        {
            Stream outputStream = null;

            try
            {
                string        pyramidFolderPath = Path.Combine(this.PyramidLocation, id, Constants.PyramidFolder);
                string        platesFolderPath  = Path.Combine(this.PyramidLocation, id, Constants.PlatesFolder);
                DirectoryInfo pyramidFolder     = new DirectoryInfo(pyramidFolderPath);
                DirectoryInfo platesFolder      = new DirectoryInfo(platesFolderPath);

                if (pyramidFolder.Exists)
                {
                    string pyramidPath = Path.Combine(this.PyramidLocation, id, Constants.TileImagePath);

                    string filename = string.Format(CultureInfo.InvariantCulture, pyramidPath, level, x, y, ImageFormat.Png.ToString());

                    if (File.Exists(filename))
                    {
                        using (Bitmap bmp = new Bitmap(filename, false))
                        {
                            if (bmp != null)
                            {
                                outputStream = new MemoryStream();
                                bmp.Save(outputStream, ImageFormat.Png);
                                outputStream.Seek(0, SeekOrigin.Begin);
                            }
                        }
                    }
                }
                else if (platesFolder.Exists)
                {
                    outputStream = PlateFileHelper.GetTileFromMultiplePlates(level, x, y, platesFolder.FullName);
                }
                else
                {
                    // If Pyramid folder is not available, then try to read from plate file.
                    FileInfo plateFile = pyramidFolder.Parent.GetFiles(Constants.PlateFileSearchPattern).FirstOrDefault();
                    if (plateFile != null && plateFile.Exists)
                    {
                        PlateFile plateFileInstance = new PlateFile(plateFile.FullName, level);
                        outputStream = plateFileInstance.GetFileStream(level, x, y);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (IOException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            catch (ObjectDisposedException ex)
            {
                ErrorHandler.LogException(ex);
                throw new FaultException(ex.Message);
            }
            return(outputStream);
        }