Esempio n. 1
0
 public RouteDOMEngine(RouteEngineArgs args)
 {
     _RouteConfig = new RouteConfig();
     _RouteEngineArgs = args;
 }
Esempio n. 2
0
        private void StartDOMEngine(RouteEngineArgs args)
        {
            if (args == null)
                return;
            _RouteDOMEngine = new RouteDOMEngine(args);
            btnGenerate.IsEnabled = false;
            btnAddNewRoute.IsEnabled = false;
            int SecondsToComplete = 6; //Program specific value
            panelContainer.Children.Clear();
            MetroProgressBar progress = new MetroProgressBar();
            progress.IsIndeterminate = false;
            progress.Orientation = System.Windows.Controls.Orientation.Horizontal;
            progress.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            progress.Width = this.WindowWidth - 10;
            progress.Height = 30;
            Duration duration = new Duration(TimeSpan.FromSeconds((SecondsToComplete * 1.35)));
            DoubleAnimation doubleAnimatiion = new DoubleAnimation(200, duration);
            progress.Visibility = System.Windows.Visibility.Visible;
            progress.Foreground = Brushes.Green;
            progress.Background = Brushes.Transparent;
            progress.BorderBrush = Brushes.Gray;
            progress.BorderThickness = new Thickness(1, 1, 1, 1);
            progress.Padding = new Thickness(1, 1, 1, 1);
            progress.Tag = "Processing......";
            progress.Value = 0;
            lblStatus.Text = "Processing...";
            statusPanel.Visibility = System.Windows.Visibility.Visible;
            statusPanel.Children.Add(progress);
            try
            {
                TaskScheduler uiThread = TaskScheduler.FromCurrentSynchronizationContext();

                Action MainThreadDoWork = new Action(() =>
                {
                    _RouteDOMEngine.RUN();
                    System.Threading.Thread.Sleep(2000);
                });

                Action ExecuteProgressBar = new Action(() =>
                {
                    progress.BeginAnimation(MetroProgressBar.ValueProperty, doubleAnimatiion);
                });

                Action FinalThreadDoWOrk = new Action(() =>
                {
                    btnGenerate.IsEnabled = true;
                    btnAddNewRoute.IsEnabled = true;
                    statusPanel.Children.Remove(progress);
                    statusPanel.Visibility = System.Windows.Visibility.Hidden;
                    PopulateTiles();
                });

                Task MainThreadDoWorkTask = Task.Factory.StartNew(() => MainThreadDoWork());

                Task ExecuteProgressBarTask = new Task(ExecuteProgressBar);
                ExecuteProgressBarTask.RunSynchronously();

                MainThreadDoWorkTask.ContinueWith(t => FinalThreadDoWOrk(), uiThread);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error",MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }