示例#1
0
 public Asset(string Name, string Description, string Author, string AssetName, string Thumbnail, string Category, string UpdatedDate)
 {
     this.Name        = Name;
     this.Description = Description;
     this.Author      = Author;
     this.AssetName   = AssetName;
     this.Thumbnail   = Thumbnail;
     this.Category    = Category;
     this.UpdatedDate = UpdatedDate == null ? DateTime.MinValue : DateTime.Parse(UpdatedDate);
     assetCategory    = AssetCategory.FromString(Category);
 }
示例#2
0
        /// <summary>
        /// Generate asset objects from the file manifests for a category.
        /// </summary>
        /// <param name="assetCategory">An asset category</param>
        /// <returns>A list of Asset</returns>
        public List <Asset> GenerateAssets(AssetCategory assetCategory)
        {
            List <Asset> buffer       = new List <Asset>();
            string       pathToFolder = Path.Combine(MANIFESTS_TEMP, assetCategory.Value);

            Directory.CreateDirectory(pathToFolder);

            foreach (string file in Directory.GetFiles(pathToFolder, "*.json"))
            {
                using (FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        buffer.Add(JsonConvert.DeserializeObject <Asset>(reader.ReadToEnd()));
                    }
                }
            }
            return(buffer);
        }
示例#3
0
        /// <summary>
        /// Fetch all manifests for a single category.
        /// </summary>
        /// <param name="assetCategory">The category of asset manifest to fetch</param>
        /// <param name="progress">An IProgress object to report download activities.</param>
        public async Task GetAssetManifestsAsync(AssetCategory assetCategory, EventHandler <WriteObjectProgressArgs> progress = null)
        {
            if (client == null)
            {
                throw new Exception("You must authenticate first.");
            }


            string manifestFolderPath = Path.Combine(MANIFESTS_TEMP, assetCategory.Value);

            // Delete the existing manifests if they exist, prevents old assets from being redownloaded.
            if (Directory.Exists(manifestFolderPath))
            {
                Directory.Delete(manifestFolderPath, true);
                Directory.CreateDirectory(manifestFolderPath);
            }

            var buckets = await client.ListBucketsAsync().ConfigureAwait(false);

            foreach (var bucket in buckets.Buckets)
            {
                Dictionary <string, object> properties = new Dictionary <string, object>();
                properties.Add("Prefix", $"{assetCategory.Value}/");

                var keys = await client.GetAllObjectKeysAsync(bucket.BucketName, null, properties).ConfigureAwait(false);

                foreach (var fileKey in keys.Where(k => k.EndsWith(".json")))
                {
                    using (var response = await client.GetObjectAsync(bucket.BucketName, fileKey).ConfigureAwait(false))
                    {
                        string pathToFile = Path.Combine(MANIFESTS_TEMP, fileKey);

                        response.WriteObjectProgressEvent += progress;
                        await response.WriteResponseStreamToFileAsync(pathToFile, false, CancellationToken.None).ConfigureAwait(false);

                        response.WriteObjectProgressEvent -= progress;
                    }
                }
            }
        }