Ejemplo n.º 1
0
        public static void RunProgress(string title, ProgressViewModel viewModel)
        {
            if (viewModel == null)
                throw new ArgumentNullException("viewModel");

            if (Application.Current == null) // testing
                return;

            viewModel.PropertyChanged += new PropertyChangedEventHandler(viewModel_PropertyChanged);

            ProgressView dialog = new ProgressView();
            dialog.Title = title;
            dialog.DataContext = viewModel;

            viewModel.Tag = dialog;

            dialog.Show();
        }
        public void Load(IEnumerable<string> files, int count, string title, Action callback)
        {
            ProgressViewModel progView = new ProgressViewModel();
            progView.Maximum = count;
            progView.Caption = "트랙 파일들을 로드합니다.";
            DialogService.RunProgress(title, progView);

            int cnt = 0;
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (sender, e) => {
                m_startTime = DateTime.MaxValue;
                m_endTime = DateTime.MinValue;

                foreach (string file in files) {
                    if (Application.Current != null && progView.IsCanceled) {
                        Application.Current.Dispatcher.Invoke((Action)(() => {
                            m_tracks.Clear();
                        }));
                        break;
                    }

                    cnt++;
                    Track track = m_loader.Load(file, false);
                    if (track != null) {
                        if (Application.Current != null) {
                            Application.Current.Dispatcher.Invoke((Action)(() => {
                                m_tracks.Add(track);
                            }));
                        } else {
                            m_tracks.Add(track);
                        }

                        if (track.CreateDate < m_startTime)
                            m_startTime = track.CreateDate;
                        if (track.CreateDate > m_endTime)
                            m_endTime = track.CreateDate;
                    }

                    //worker.ReportProgress(++cnt);

                    if (Application.Current != null) {
                        Application.Current.Dispatcher.Invoke((Action)(() => {
                            progView.Value = cnt;
                            progView.Message = file;
                        }));
                    }
                }
            };
            //worker.ProgressChanged += (sender, e) => { };
            worker.RunWorkerCompleted += (sender, e) => {
                if (callback != null)
                    callback();
            };
            //worker.WorkerReportsProgress = true;
            worker.RunWorkerAsync();
        }
Ejemplo n.º 3
0
 private ProgressViewModel CreateProgressView(int total)
 {
     ProgressViewModel progView = new ProgressViewModel();
     progView.Maximum = total;
     return progView;
 }