Ejemplo n.º 1
0
        public AppWizard()
        {
            InitializeComponent();

            // kill previous instances of Environment Assessment Web Service that may be running
            CWebServiceManager.Kill();

            // create progress related objects
            base.TaskbarItemInfo = new TaskbarItemInfo();
            ProgressInfo         = new ObservableCollection <CTaskInfo> {
            };
            CFunctions.EnableCollectionSynchronization(ProgressInfo, _ProgressInfoLock);

            // initialize containers
            cntTop = new Border {
                Name = "cntTop", Height = 110, Background = new SolidColorBrush(Colors.White), VerticalAlignment = VerticalAlignment.Top
            };
            DockPanel topPanel = new DockPanel()
            {
                Name = "topPanel"
            };

            cntTop.Child = topPanel;

            cntNav = new Border {
                Name = "cntNavigation", HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 110, 0, 60), Width = 210, Background = new SolidColorBrush(Colors.LightAccent),
            };
            DockPanel navPanel = new DockPanel()
            {
                Name = "navPanel"
            };

            cntNav.Child = navPanel;

            cntBottom = new Border {
                Name = "cntBottom", Height = 60, BorderThickness = new Thickness(0, 1, 0, 0), BorderBrush = new SolidColorBrush(Colors.LightGray), Margin = new Thickness(12, 0, 12, 0), VerticalAlignment = VerticalAlignment.Bottom,
            };
            DockPanel btmPanel = new DockPanel()
            {
                Name = "btmPanel"
            };

            cntBottom.Child = btmPanel;

            cntMain = new Border {
                Name = "cntMain", Margin = new Thickness(210, 110, 0, 60), Background = new SolidColorBrush(Colors.White)
            };
            DockPanel mainPanel = new DockPanel()
            {
                Name = "mainPanel"
            };

            cntMain.Child = mainPanel;

            // add pages
            List <string> ButtonText = new List <string>()
            {
                "< _Previous", "_Next >", "_Cancel"
            };

            pnlWelcome = new Controls.WelcomePanel();
            pnlWelcome.tbkTitle.Text    = "Analyze your server environment";
            pnlWelcome.tbkSubTitle.Text = "Collects data from vSphere and Hyper-V.";
            pnlWelcome.tbkTerms.Text    = "This program is provided as-is with no implied warranties whatsoever as to its functionality, operability, use or fitness for any purpose. We disclaim any liability regarding the use of this program, even if previously advised of such. By using this sofware you agree to these terms.";
            Pages.Add(new Page(pnlWelcome.tbkTitle.Text, pnlWelcome.tbkSubTitle.Text, new List <Control> {
                pnlWelcome
            }, ButtonText));

            pnlServers = new Controls.ServerPanel();
            pnlServers.lvServers.SetBinding(ItemsControl.ItemsSourceProperty, new Binding()
            {
                Path = new PropertyPath("CService"), NotifyOnTargetUpdated = true
            });
            pnlServers.lvServers.ItemsSource = DiscoveredServers;
            //[ or pnlServers.lvServers.SelectionChanged link to next and previous buttons];

            pnlServers.lgvServer.Columns.Add(new GridViewColumn {
                Header = "Server", DisplayMemberBinding = new Binding("Name"), Width = 140
            });
            pnlServers.lgvServer.Columns.Add(new GridViewColumn {
                Header = "Type", DisplayMemberBinding = new Binding("Type"), Width = 120
            });
            pnlServers.lgvServer.Columns.Add(new GridViewColumn {
                Header = "Credentials", DisplayMemberBinding = new Binding("UserName"), Width = 145
            });
            //pnlServers.ComponentUpdated link to next and previous buttons

            CWorker OnServiceDiscoverWorker = new CWorker();

            OnServiceDiscoverWorker.DoWork             += OnServiceDiscoverWorker_DoWork;
            OnServiceDiscoverWorker.RunWorkerCompleted += OnServiceDiscoverWorker_RunWorkerCompleted;
            Pages.Add(new Page("Server Connections", "Configure the credentials to \r\naccess vSphere and Hyper-V.", new List <Control> {
                pnlServers
            }, ButtonText, OnServicePageValidateHandler, OnServiceDiscoverWorker));

            pnlProgress = new Controls.ProgressPanel();
            //pnlProgress.lblProgress.Content = "Collecting Data...";
            pnlProgress.lvProgress.SetBinding(ItemsControl.ItemsSourceProperty, new Binding()
            {
                Path = new PropertyPath("CTaskStatus"), NotifyOnTargetUpdated = true
            });
            pnlProgress.lvProgress.ItemsSource = ProgressInfo;
            pnlProgress.lgvProgress.Columns.Add(new GridViewColumn {
                Header = "Action", CellTemplate = (DataTemplate)FindResource("ProgressActionTemplate"), Width = 385
            });                                                                                                                                                              //DisplayMemberBinding = new Binding("Details")
            pnlProgress.lgvProgress.Columns.Add(new GridViewColumn {
                Header = "Duration", DisplayMemberBinding = new Binding("Duration"), Width = 100
            });

            CWorker OnDataCollectWorker = new CWorker();

            OnDataCollectWorker.WorkerReportsProgress = true;
            OnDataCollectWorker.DoWork             += OnDataCollectWorker_DoWork;
            OnDataCollectWorker.ProgressChanged    += OnDataCollectWorker_ProgressChanged;
            OnDataCollectWorker.RunWorkerCompleted += OnDataCollectWorker_RunWorkerCompleted;
            pnlProgress.pbProgress.Value            = 10;
            Pages.Add(new Page("Data Collection", "Collecting data from \r\nvSphere and Hyper-V.", new List <Control> {
                pnlProgress
            }, ButtonText, null, OnDataCollectWorker));

            MainGrid.Children.Add(cntTop);
            MainGrid.Children.Add(cntNav);
            MainGrid.Children.Add(cntMain);
            MainGrid.Children.Add(cntBottom);

            // update navigation
            foreach (Control c in Navigation.Controls)
            {
                navPanel.Children.Add(c);
            }

            // update content for first page
            lblTitle = new Label {
                FontFamily = new FontFamily("Segoe UI"), FontSize = 21, Foreground = new SolidColorBrush(Colors.DarkGray), Margin = new Thickness(26, -4, 0, 0), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Width = 700
            };
            tbkSubTitle = new TextBlock {
                FontFamily = new FontFamily("Segoe UI"), FontSize = 14, Foreground = new SolidColorBrush(Colors.MediumGray), VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(-694, 40, 0, 0),
            };
            topPanel.Children.Add(lblTitle);
            topPanel.Children.Add(tbkSubTitle);

            int btnHeight = 30, btnWidth = 82;

            btnPrevious = new Button()
            {
                Content = ButtonText[0], Height = btnHeight, Width = btnWidth, Margin = new Thickness(460, 0, 8, 0), HorizontalAlignment = HorizontalAlignment.Right, FontSize = 14, ToolTip = "Go to previous page", Style = FindResource("WizardNextPreviousButtonStyle") as Style
            };
            btnNext = new Button()
            {
                Content = ButtonText[1], Height = btnHeight, Width = btnWidth, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 14, Style = FindResource("WizardNextPreviousButtonStyle") as Style, ToolTip = "Go to next page"
            };
            btnCancelFinish = new Button()
            {
                Content = ButtonText[2], Height = btnHeight, Width = btnWidth, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 14, Style = FindResource("WizardOKCancelButtonStyle") as Style, IsCancel = true, ToolTip = "Close wizard"
            };
            btnNext.Click         += btnNext_Click;
            btnPrevious.Click     += btnPrevious_Click;
            btnCancelFinish.Click += btnCancelFinish_Click;
            btmPanel.Children.Add(btnPrevious);
            btmPanel.Children.Add(btnNext);
            btmPanel.Children.Add(btnCancelFinish);

            // register navigation change event
            Navigation.ActivePageChanged += MainWizard_ActivePageChanged;

            // run update page for first page
            UpdatePage();
        }