Beispiel #1
0
        public static async Task <ResourcePack> CreateNewResourcePackAsync(StorageFile file, User author, string name, string description = null)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            if (author == null)
            {
                throw new ArgumentNullException(nameof(author));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Debug.WriteLine($"Creating new resource pack from file {file.Path}.");

            var verison = await DetectVersion(file);

            var resourcePack = new ResourcePack(author, name, verison, description);

            using (var resourceStream = await file.OpenStreamForReadAsync())
            {
                if (await StorageSource.UploadFileAsync(await file.OpenStreamForReadAsync(), $"{RESOURCE_PACKS_FOLDER_NAME}/{resourcePack.FileName}") == null)
                {
                    Debug.WriteLine($"Resource Pack file {file.Path} failed to upload.");
                    return(null);
                }
            }

            if (!await RestApiService <ResourcePack> .Add(resourcePack))
            {
                Debug.WriteLine($"Resource Pack {resourcePack.Key} failed to upload.");
                return(null);
            }

            return(resourcePack);
        }