private async Task CheckAndCreateCacheFolder(string path = null)
        {
            await _storageService.CreateDirectoryIfNotThere("Cache");

            await _storageService.CreateDirectoryIfNotThere(ImageCachePath);

            if (!string.IsNullOrEmpty(path))
            {
                await _storageService.CreateDirectoryIfNotThere(path);
            }
        }
        private async Task CreateDownload(string source, IApiClient client, LocalItem localItem)
        {
            var existingRequest = BackgroundTransferService.Requests.FirstOrDefault(x => x.Tag != null && x.Tag.Contains(localItem.Id));

            if (existingRequest != null)
            {
                return;
            }

            await _storageService.CreateDirectoryIfNotThere("AnyTime");

            await _storageService.CreateDirectoryIfNotThere("Shared\\Transfers");

            await _storageService.CreateDirectoryIfNotThere("Shared\\Transfers\\Sync");

            var stringVersion = ApplicationManifest.Current.App.Version;

            var downloader = new BackgroundTransferRequest(new Uri(source, UriKind.Absolute));

            downloader.Headers.Add("X-MediaBrowser-Token", client.AccessToken);
            var authorization = string.Format("MediaBrowser UserId=\"{0}\", Client=\"{1}\", Device=\"{2}\", DeviceId=\"{3}\", Version=\"{4}\"", client.CurrentUserId, client.ClientName, client.DeviceName, client.DeviceId, stringVersion);

            downloader.Headers.Add("Authorization", authorization);
            downloader.Method = "GET";
            downloader.Tag    = JsonConvert.SerializeObject(new JobData(localItem.Id, localItem.LocalPath, localItem.Item.Name, localItem.Item.Type));

            var downloadLocation = new Uri(string.Format(Constants.AnyTime.DownloadLocation, localItem.Id), UriKind.RelativeOrAbsolute);

            downloader.DownloadLocation       = downloadLocation;
            downloader.TransferStatusChanged += DownloaderOnTransferStatusChanged;

            if (BackgroundTransferService.Requests.Count() == 25)
            {
                // TODO: error or something
                var i = 1;
            }

            var complete = BackgroundTransferService.Requests.Where(x => x.TransferStatus == TransferStatus.Completed).ToList();

            if (!complete.IsNullOrEmpty())
            {
                foreach (var request in complete)
                {
                    BackgroundTransferService.Remove(request);
                }
            }

            _transferService.Add(downloader);
        }
예제 #3
0
        private async Task LoadItems()
        {
            if (_items != null)
            {
                return;
            }

            await _storageService.CreateDirectoryIfNotThere("Cache");

            var json = await GetString(ItemsFile);

            var items = await json.DeserialiseAsync <List <LocalItem> >();

            _items = items ?? new List <LocalItem>();
        }
        private async Task SaveItems()
        {
            if (_items.IsNullOrEmpty())
            {
                return;
            }

            await _storageService.CreateDirectoryIfNotThere("Cache");

            var json = await _items.SerialiseAsync();

            await _storageService.WriteAllTextAsync(ItemsFile, json);
        }