Exemple #1
0
        public async Task CheckDownloadStatusAsync(IReadOnlyList <DownloadOperation> operations)
        {
            ImageItem.Init();
            var task = ImageItem.DownloadBitmapForListAsync();

            var folder = await AppSettings.Instance.GetSavingFolderAsync();

            var item = await folder.TryGetItemAsync(ImageItem.GetFileNameForDownloading());

            if (item != null)
            {
                if (item is StorageFile file)
                {
                    _resultFile = file;
                    var prop = await _resultFile.GetBasicPropertiesAsync();

                    if (prop.Size > 0)
                    {
                        Progress = 100;
                    }
                }
            }
            if (Progress != 100)
            {
                var downloadOperation = operations.Where(s => s.Guid == DownloadOperationGUID).FirstOrDefault();
                if (downloadOperation != null)
                {
                    var progress = new Progress <DownloadOperation>();
                    progress.ProgressChanged += Progress_ProgressChanged;
                    _cts = new CancellationTokenSource();
                    await downloadOperation.StartAsync().AsTask(_cts.Token, progress);
                }
                else
                {
                    DisplayIndex = (int)DisplayMenu.Retry;
                }
            }
        }
        private async Task <IStorageFile> GetLocalRulesFileAsync()
        {
            var folder = ApplicationData.Current.LocalFolder;

            string       filePath = this.downloadLocation.ToString().TrimStart('\\');
            IStorageFile file     = await folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists);

            var properties = await file.GetBasicPropertiesAsync();

            if (properties.Size != 0)
            {
                TaskCompletionSource <object> stateUpdated = new TaskCompletionSource <object>();
                Task dispatcherTask = DispatcherHelper.RunAsync(() =>
                {
                    this.State = TransferRequestState.Complete;
                    stateUpdated.SetResult(null);
                });

                await stateUpdated.Task;
            }

            return(file);
        }
Exemple #3
0
        private async Task <IStorageFile> GetLocalRulesFileAsync()
        {
            try
            {
                var folder = ApplicationData.Current.LocalFolder;

                IStorageFile file = await folder.CreateFileAsync(this.localFileName, CreationCollisionOption.OpenIfExists);

                var properties = await file.GetBasicPropertiesAsync();

                if (properties.Size != 0)
                {
                    this.NeedDownload = false;
                    this.Status       = "Tap to open rules";
                }

                return(file);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
        /// <summary>
        /// Gets a file's size.
        /// </summary>
        private async Task <long> GetSizeAsync(IStorageFile file)
        {
            BasicProperties fileProperties = await file.GetBasicPropertiesAsync().AsTask().ConfigureAwait(false);

            return((long)fileProperties.Size);
        }
Exemple #5
0
        private static async Task<ZipArchiveEntry> DoCreateEntryFromFile(ZipArchive destination, IStorageFile sourceFile, string entryName, CompressionLevel? compressionLevel)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");
            if (sourceFile == null)
                throw new ArgumentNullException("sourceFile");
            if (entryName == null)
                throw new ArgumentNullException("entryName");
            using (Stream stream = (await sourceFile.OpenReadAsync()).AsStream())
            {
                ZipArchiveEntry zipArchiveEntry = compressionLevel.HasValue ? destination.CreateEntry(entryName, compressionLevel.Value) : destination.CreateEntry(entryName);

                var props = await sourceFile.GetBasicPropertiesAsync();

                DateTime dateTime = props.DateModified.UtcDateTime;
                if (dateTime.Year < 1980 || dateTime.Year > 2107)
                    dateTime = new DateTime(1980, 1, 1, 0, 0, 0);
                zipArchiveEntry.LastWriteTime = (DateTimeOffset)dateTime;
                using (Stream destination1 = zipArchiveEntry.Open())
                {
                    await stream.CopyToAsync(destination1);
                }
                return zipArchiveEntry;
            }
        }
Exemple #6
0
        private static async Task <bool> PullRoamingData(FileSyncInfo info)
        {
            var romingFolder = ApplicationData.Current.RoamingFolder;
            var folder       = ApplicationData.Current.LocalFolder;

            // ローカル側のファイルを取得
            // LocalFolderからfileまでの相対的なフォルダ構造を再現
            IStorageFile localFile           = null;
            bool         isNotExistLocalFile = false;
            {
                var folderPathStack = info.RelativeFilePath.Split('/', '\\').ToList();
                var parentFolder    = folder;
                foreach (var folderName in folderPathStack.Take(folderPathStack.Count - 1 /* without file name */))
                {
                    parentFolder = await parentFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);
                }

                var fileName = folderPathStack.Last();
                localFile = await parentFolder.TryGetItemAsync(fileName) as IStorageFile;

                if (localFile == null)
                {
                    localFile = await parentFolder.CreateFileAsync(fileName);

                    isNotExistLocalFile = true;
                }

                if (localFile == null)
                {
                    throw new Exception();
                }
            }

            IStorageFile roamingFile = null;

            {
                var folderPathStack = info.RelativeFilePath.Split('/', '\\').ToList();
                var parentFolder    = romingFolder;
                foreach (var folderName in folderPathStack.Take(folderPathStack.Count - 1 /* without file name */))
                {
                    parentFolder = await parentFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);
                }

                var fileName = folderPathStack.Last();
                roamingFile = await parentFolder.TryGetItemAsync(fileName) as IStorageFile;

                if (roamingFile == null)
                {
                    Debug.WriteLine(info.RelativeFilePath + " はローミングフォルダに存在しません。");
                    return(false);
                }
            }



            if (isNotExistLocalFile)
            {
                await roamingFile.CopyAndReplaceAsync(localFile);

                Debug.WriteLine(localFile.Path + "をローカルにコピー");
            }
            else
            {
                // ローカル側ファイルとinfo.UpdateAtを比較して
                // ローカル側ファイルが古い場合
                // ローミングファイルをローカル側ファイルに上書きコピー
                var localProp = await localFile.GetBasicPropertiesAsync();

                if (info.UpdateAt > localProp.DateModified)
                {
                    await roamingFile.CopyAndReplaceAsync(localFile);

                    Debug.WriteLine(localFile.Path + "をローカルにコピー(上書き)");
                }
            }

            return(true);
        }
Exemple #7
0
        public async Task AddStorageFileAsync(IStorageFile file, bool temporary = false)
        {
            try
            {
                await _transcodeWait.WaitAsync();

                var model    = DataContext as ChannelViewModel;
                var type     = file.ContentType;
                var progress = new Progress <double?>(UpdateProgressBar);
                var setting  = App.RoamingSettings.Read <MediaTranscodeOptions>(Constants.AUTO_TRANSCODE_MEDIA);
                var props    = await file.GetBasicPropertiesAsync();

                _cancellationToken = new CancellationTokenSource();

                var transcodeFailed = false;

                if (setting == MediaTranscodeOptions.Always || (setting == MediaTranscodeOptions.WhenNeeded && props.Size >= (ulong)model.UploadLimit))
                {
                    MediaType?mediaType = null;

                    if (type.StartsWith("audio"))
                    {
                        mediaType = MediaType.Audio;
                    }
                    else if (type.StartsWith("video"))
                    {
                        mediaType = MediaType.Video;
                    }
                    else if (type.StartsWith("image"))
                    {
                        mediaType = MediaType.Photo;
                    }

                    if (mediaType != null)
                    {
                        model.IsTranscoding = true;
                        transcodeProgress.IsIndeterminate = true;
                        transcodeOverlay.Visibility       = Visibility.Visible;

                        var newFile = await TryTranscodeMediaAsync(file, mediaType.Value, progress, _cancellationToken.Token);

                        if (newFile != null)
                        {
                            temporary = true;
                            file      = newFile;
                        }
                        else
                        {
                            if (!_cancellationToken.IsCancellationRequested)
                            {
                                transcodeFailed = true;
                            }
                        }
                    }

                    props = await file.GetBasicPropertiesAsync();

                    transcodeProgress.IsIndeterminate = false;
                    transcodeOverlay.Visibility       = Visibility.Collapsed;
                }

                var fileModel = await FileUploadModel.FromStorageFileAsync(file, props, temporary, transcodeFailed);

                model.FileUploads.Add(fileModel);

                model.IsTranscoding = false;

                _transcodeWait.Release();
            }
            catch { }
        }
Exemple #8
0
        private async void UpdateBoundSize(IStorageFile _backingFile)
        {
            var props = await _backingFile.GetBasicPropertiesAsync();

            FileSize = GetHumanReadableSize(props.Size);
        }
Exemple #9
0
        private async Task <DateTimeOffset> GetDateModifiedAsync(IStorageFile file)
        {
            var props = await file.GetBasicPropertiesAsync();

            return(props.DateModified);
        }
Exemple #10
0
        private async Task <ulong> GetSizeAsync(IStorageFile file)
        {
            var props = await file.GetBasicPropertiesAsync();

            return(props.Size);
        }
 private static async Task<EmailMessage> CreateAttachmentObject(IStorageFile attachmentTempFile, Unity.Core.AttachmentData attachment, EmailMessage mail)
 {
     await (FileIO.WriteBytesAsync(attachmentTempFile, attachment.Data).AsTask());
     var properties = await attachmentTempFile.GetBasicPropertiesAsync();
     if (properties.Size < (ulong)(attachment.DataSize))
     {
         mail.Attachments.Add(new EmailAttachment(attachment.FileName, RandomAccessStreamReference.CreateFromFile(attachmentTempFile)));
     }
     return mail;
 }
 public async Task <IPortableFileBasicProperties> GetBasicPropertiesAsync()
 {
     return((await _baseFile.GetBasicPropertiesAsync()).AsPortableBasicProperties());
 }
 private async void UpdateBoundSize(IStorageFile _backingFile)
 {
     var props = await _backingFile.GetBasicPropertiesAsync();
     FileSize = GetHumanReadableSize(props.Size);
 }
 /// <summary>
 /// Gets a file's size.
 /// </summary>
 private async Task<long> GetSizeAsync(IStorageFile file)
 {
     BasicProperties fileProperties = await file.GetBasicPropertiesAsync().AsTask().ConfigureAwait(false);
     return (long)fileProperties.Size;
 }