KinectWithVRServer.MainWindow.Window_Initialized C# (CSharp) Method

Window_Initialized() private method

private Window_Initialized ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void Window_Initialized(object sender, EventArgs e)
        {
            //Report to the log which Kinect versions are unavaliable
            if (!avaliableDLLs.HasKinectV1)
            {
                HelperMethods.WriteToLog("Warning: Kinect v1 support is unvaliable due to missing DLLs!", this);
            }
            if (!avaliableDLLs.HasKinectV2)
            {
                HelperMethods.WriteToLog("Warning: Kinect v2 support is unvaliable due to missing DLLs!", this);
            }
            if (!avaliableDLLs.HasNetworkedKinect)
            {
                HelperMethods.WriteToLog("Warning: Networked Kinect support is unvaliable due to missing DLLs!", this);
                //Remove the option to add a networked kinect if the dll isn't avaliable
                nkStackPanel.Visibility = System.Windows.Visibility.Collapsed;
                AddNKButton.IsEnabled = false;
            }

            //Setup the timer to update the GUI with the server runtime
            uptimeUpdateTimer = new System.Timers.Timer();
            uptimeUpdateTimer.Interval = 500;
            uptimeUpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(uptimeUpdateTimer_Elapsed);

            KinectBase.MasterSettings tempSettings = new KinectBase.MasterSettings();

            //Create the server core (this does NOT start the server)
            server = new ServerCore(verbose, tempSettings, this);

            //Set all the data for the data grids
            VoiceButtonDataGrid.ItemsSource = server.serverMasterOptions.voiceButtonCommands;
            VoiceTextDataGrid.ItemsSource = server.serverMasterOptions.voiceTextCommands;

            if (startupFile != null && startupFile != "")
            {
                try
                {
                    server.serverMasterOptions = HelperMethods.LoadSettings(startupFile);
                    UpdateGUISettings();
                }
                catch
                {
                    MessageBox.Show("Error: The startup settings file failed to load!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    HelperMethods.WriteToLog("Startup settings (" + startupFile + ") failed to load.");
                }
            }

            //TODO: Handle starting Kinects based on the loaded settings file
            //Initialize the data for the available Kinect v1s
            if (avaliableDLLs.HasKinectV1)
            {
                KinectV1Wrapper.StatusEventArgs[] currentStatuses = KinectV1Wrapper.StatusHelper.GetAllKinectsStatus();
                for (int i = 0; i < currentStatuses.Length; i++)
                {
                    AvailableKinectData tempData = new AvailableKinectData();

                    tempData.UniqueID = currentStatuses[i].UniqueKinectID;
                    tempData.Status = currentStatuses[i].Status;
                    tempData.KinectTypeString = GetKinectTypeString(currentStatuses[i].Status, currentStatuses[i].isXBox360Kinect);
                    tempData.kinectType = KinectVersion.KinectV1;

                    if (i == 0 && tempData.Status == KinectStatus.Connected)
                    {
                        tempData.UseKinect = true;
                        tempData.KinectID = 0;
                        server.serverMasterOptions.kinectOptionsList.Add((IKinectSettings)(new KinectV1Wrapper.Settings(tempData.UniqueID, (int)tempData.KinectID)));
                        server.kinects.Add((new KinectV1Wrapper.Core(ref server.serverMasterOptions, true, (int)tempData.KinectID)));
                        tempData.ServerStatus = "Running";
                    }
                    else
                    {
                        tempData.UseKinect = false;
                        tempData.KinectID = null;
                    }
                    tempData.PropertyChanged += useKinect_PropertyChanged;
                    availableKinects.Add(tempData);
                }
            }

            //Initialize the data for the available Kinect v2s
            if (avaliableDLLs.HasKinectV2)
            {
                KinectV2Wrapper.StatusHelper.StartKinectV2Service();
                KinectV2Wrapper.StatusEventArgs[] currentStatuses2 = KinectV2Wrapper.StatusHelper.GetAllKinectsStatus();
                for (int i = 0; i < currentStatuses2.Length; i++)
                {
                    AvailableKinectData tempData = new AvailableKinectData();

                    tempData.UniqueID = currentStatuses2[i].UniqueKinectID;
                    tempData.Status = currentStatuses2[i].Status;
                    tempData.KinectTypeString = "Kinect v2";
                    tempData.kinectType = KinectVersion.KinectV2;
                    //Note: Unlike the Kinect v1, we don't automatically launch a Kinect v2
                    tempData.UseKinect = false;
                    tempData.KinectID = null;
                    tempData.PropertyChanged += useKinect_PropertyChanged;
                    availableKinects.Add(tempData);
                }
            }

            KinectStatusBlock.Text = availableKinects.Count.ToString();
            kinectsAvailableDataGrid.ItemsSource = availableKinects;
            UpdatePageListing();
            GenerateImageSourcePickerLists();

            if (avaliableDLLs.HasKinectV1)
            {
                //Subscribe to the v1 status changed event
                KinectV1Wrapper.StatusHelper v1StatusHelper = new KinectV1Wrapper.StatusHelper();
                v1StatusHelper.StatusChanged += v1StatusHelper_KinectV1StatusChanged;
            }
            if (avaliableDLLs.HasKinectV2)
            {
                //Subscribe to the v2 status changed event
                KinectV2Wrapper.StatusHelper v2StatusHelper = new KinectV2Wrapper.StatusHelper();
                v2StatusHelper.StatusChanged += v2StatusHelper_KinectV2StatusChanged;
            }

            //Populate the skeleton data and set the binding for the data grid
            GenerateSkeletonDataGridData();
            SkeletonSettingsDataGrid.ItemsSource = server.serverMasterOptions.mergedSkeletonOptions.individualSkeletons;

            //Populate and setup the voice recognition lists
            GenerateVoiceRecogEngineList();
            GenerateAudioSourceList();
            VoiceKinectComboBox.SelectedIndex = 0;

            //Set defaults where needed
            FeedbackJointTypeComboBox.SelectedIndex = 0;
            SkelSortModeComboBox.SelectedIndex = 5;

            //Set the items source for the servers display grid
            ServersDataGrid.ItemsSource = configuredServers;

            //Set the initial shader for the depth image
            depthEffect = new Shaders.NoScalingEffect();
            DepthImage.Effect = depthEffect;

            if (startOnLaunch)
            {
                startServerButton_Click(this, new RoutedEventArgs());
            }
        }
MainWindow