示例#1
0
        public void OnRefreshLocalImagesFromDirectory()
        {
            loadingLocalFilesTaskCancellationToken = new CancellationTokenSource();
            loadingLocalFilesTaskCancellationToken.Token.Register(() =>
            {
            });
            this.LoadingFilesFromDirectory = false;
            Task task = new Task(() =>
            {
                try
                {
                    var standardMessage            = "Зчитування з папки. Будь ласка, зачекайте...";
                    this.LoadingFilesFromDirectory = true;
                    this.StatusMessage             = standardMessage;
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        LocalImageCollection.Clear();
                    });
                    var localImages = LocalImage.ReadAllLocalImagesFromDirectory((progress) => {
                        this.StatusMessage = standardMessage + " Прогрес - " + progress.ToString("0") + "%";
                    }).OrderBy(r => Path.GetFileName(r.LocalPath));

                    if (localImages.Count() == 0)
                    {
                        MessageBox.Show("Немає зображень у папках", "Немає зображень", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        foreach (var localImage in localImages)
                        {
                            LocalImageCollection.Add(localImage);
                        }
                    });
                    this.LoadingFilesFromDirectory = false;
                    this.StatusMessage             = "Готово";
                }
                catch (LocalImageFileReadException exception)
                {
                    MessageBox.Show("Пошкоджене ім'я файлу - " + exception.FilePath, "Файл пошкоджено, видаліть його!");
                    this.StatusMessage             = "Delete: " + exception.FilePath;
                    this.LoadingFilesFromDirectory = false;
                }
            }, loadingLocalFilesTaskCancellationToken.Token);

            task.Start();
            task.ContinueWith((t) =>
            {
                this.StatusMessage             = "Готово";
                this.LoadingFilesFromDirectory = false;
            });
        }
示例#2
0
        public void OnRefreshLocalImagesFromDirectory()
        {
            loadingLocalFilesTaskCancellationToken = new CancellationTokenSource();
            loadingLocalFilesTaskCancellationToken.Token.Register(() =>
            {
            });
            this.LoadingFilesFromDirectory = false;
            Task task = new Task(() =>
            {
                try
                {
                    var standardMessage            = "Reading from directory. Please Wait...";
                    this.LoadingFilesFromDirectory = true;
                    this.StatusMessage             = standardMessage;
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        LocalImageCollection.Clear();
                    });
                    var localImages = LocalImage.ReadAllLocalImagesFromDirectory((progress) => {
                        this.StatusMessage = standardMessage + " Progress: " + progress + "%";
                    }).OrderBy(r => Path.GetFileName(r.LocalPath));

                    if (localImages.Count() == 0)
                    {
                        MessageBox.Show("No Images in the directories", "No Images", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        foreach (var localImage in localImages)
                        {
                            LocalImageCollection.Add(localImage);
                        }
                    });
                    this.LoadingFilesFromDirectory = false;
                    this.StatusMessage             = "Ready";
                }
                catch (LocalImageFileReadException exception)
                {
                    MessageBox.Show("Curropt File Name: " + exception.FilePath, "File Curropt, Delete It");
                    this.StatusMessage             = "Delete: " + exception.FilePath;
                    this.LoadingFilesFromDirectory = false;
                }
            }, loadingLocalFilesTaskCancellationToken.Token);

            task.Start();
            task.ContinueWith((t) =>
            {
                this.StatusMessage             = "Ready";
                this.LoadingFilesFromDirectory = false;
            });
        }