Example #1
0
        /// <summary>
        /// Loads image data from a local file and set it to current image data.
        /// </summary>
        /// <param name="item">Target item</param>
        internal async Task LoadSetAsync(FileItemViewModel item)
        {
            _tokenSourceLoading?.TryCancel();             // Canceling already canceled source will be simply ignored.

            try
            {
                _tokenSourceLoading = new CancellationTokenSourcePlus();

                byte[] data = null;
                if (item.IsAvailableLocal && item.CanLoadDataLocal)
                {
                    data = await FileAddition.ReadAllBytesAsync(ComposeLocalPath(item), _tokenSourceLoading.Token);
                }

                CurrentItem      = item;
                CurrentImageData = data;
            }
            catch (OperationCanceledException)
            {
                // None.
            }
            catch (FileNotFoundException)
            {
                item.Status       = FileStatus.NotCopied;
                item.IsAliveLocal = false;
            }
            catch (IOException)
            {
                item.IsAvailableLocal = false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Failed to load image data from local file.\r\n{ex}");
                throw new UnexpectedException("Failed to load image data from local file.", ex);
            }
            finally
            {
                _tokenSourceLoading?.Dispose();
            }
        }
Example #2
0
 /// <summary>
 /// Stops operation.
 /// </summary>
 internal void Stop()
 {
     StopAutoTimer();
     _tokenSourceWorking?.TryCancel();             // Canceling already canceled source will be simply ignored.
 }