コード例 #1
0
        /// <summary>
        /// Creates a new instance monitor.
        /// </summary>
        public InstanceMonitor(TileApiConfiguration apiConfiguration, InstanceConfiguration instanceConfiguration, ApiBootstrapper.InstanceLoaderDelegate instanceLoader)
        {
            _filesToMonitor = new List<FileMonitor>();
            _hasChanged = false;
            _lastChange = DateTime.Now.Ticks;
            _reloadDelegate = instanceLoader;
            _apiConfiguration = apiConfiguration;
            _instanceConfiguration = instanceConfiguration;

            _timer = new Timer(Tick, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
        }
コード例 #2
0
        /// <summary>
        /// Loads a new instance.
        /// </summary>
        /// <param name="apiConfiguration"></param>
        /// <param name="instanceConfiguration"></param>
        /// <returns></returns>
        private static bool LoadInstance(TileApiConfiguration apiConfiguration, InstanceConfiguration instanceConfiguration)
        {
            // get data file configuration.
            var data = instanceConfiguration.Data;

            // get mapcss configuration.
            var mapCSS = instanceConfiguration.MapCSS;
            if (string.IsNullOrWhiteSpace(mapCSS))
            {

            }

            // get the format.
            var format = instanceConfiguration.Format;

            // get the include file.
            try
            {
                // create routing instance.
                OsmSharp.Logging.Log.TraceEvent("Bootstrapper", OsmSharp.Logging.TraceEventType.Information,
                    string.Format("Creating {0} instance...", instanceConfiguration.Name));
                switch (format.ToLowerInvariant())
                {
                    case "osm-xml":
                        using (var stream = new FileInfo(data).OpenRead())
                        {
                            var streamSource = new XmlOsmStreamSource(stream);
                            using (var cssStream = new FileInfo(mapCSS).OpenRead())
                            {
                                ApiBootstrapper.BuildTileServer("tiles_" +
                                    instanceConfiguration.Name, streamSource, cssStream, apiConfiguration.Cache);
                            }
                        }
                        break;
                    case "osm-pbf":
                        using (var stream = new FileInfo(data).OpenRead())
                        {
                            var streamSource = new PBFOsmStreamSource(stream);
                            using (var cssStream = new FileInfo(mapCSS).OpenRead())
                            {
                                ApiBootstrapper.BuildTileServer("tiles_" +
                                    instanceConfiguration.Name, streamSource, cssStream, apiConfiguration.Cache);
                            }
                        }
                        break;
                    default:
                        throw new Exception(string.Format("Unrecognised raw osm format: {0}", format));
                }
                OsmSharp.Logging.Log.TraceEvent("Bootstrapper", OsmSharp.Logging.TraceEventType.Information,
                    string.Format("Instance {0} created successfully!", instanceConfiguration.Name));
            }
            catch (Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("Bootstrapper", OsmSharp.Logging.TraceEventType.Error,
                    string.Format("Exception occured while creating instance {0}:{1}",
                    instanceConfiguration.Name, ex.ToInvariantString()));
                return false;
            }
            return true;
        }