Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AssetManager"/> class with the specified path
        /// pointing to the root of the asset directory.
        /// </summary>
        /// <param name="rootDir">Path pointing to the asset directory.</param>
        /// <exception cref="ArgumentNullException"><paramref name="rootDir"/> is null.</exception>
        /// <exception cref="DirectoryNotFoundException"><paramref name="rootDir"/> does not exists.</exception>
        public AssetManager(string rootDir)
        {
            if (string.IsNullOrWhiteSpace(rootDir))
            {
                throw new ArgumentNullException(nameof(rootDir));
            }
            if (!Directory.Exists(rootDir))
            {
                throw new DirectoryNotFoundException($"Could not find directory at '{Path.GetFullPath(rootDir)}'.");
            }

            _rootDir   = rootDir;
            _providers = new Dictionary <Type, AssetProvider>();

            // Register the AssetProviders.
            var tableProvider = new CsvDataTableAssetProvider();

            RegisterProvider(typeof(CsvDataTable <>), tableProvider);
            // Register typeof(CsvDataTable) to the same instance of the type CsvDataRow<>.
            // Which enables us to do things like this AssetManaget.Get<CsvDataTable>();
            RegisterProvider(typeof(CsvDataTableCollection), tableProvider);

            _table = tableProvider.Table;

            var fingerprintJsonPath = Path.Combine(_rootDir, "fingerprint.json");
            var fingerprintJson     = File.ReadAllText(fingerprintJsonPath);

            _fingerprint = Fingerprint.FromJson(fingerprintJson);
        }
        private Fingerprint DownloadFingerprint(Uri rootPath)
        {
            var builder = new UriBuilder(rootPath);

            builder.Path = Path.Combine(builder.Path, "fingerprint.json");
            var fingerprintPath = builder.Uri;
            var fingerprintJson = _webClient.DownloadString(fingerprintPath);

            return(Fingerprint.FromJson(fingerprintJson));
        }