public void DisplayCockpitInstance()
        {
            frm = new frmCockpit();
            frm.LoadLayout("Cessna 152 ASOBO");
            frm.Show();
            Thread.Sleep(1000);
            var result = GetRequest("INDCATED AIRSPEED", "knots");

            frm.ResultUpdate(result);
            Thread.Sleep(3000);
            result.Result = 100;
            frm.ResultUpdate(result);
            Thread.Sleep(3000);
            result.Result = 200;
            Thread.Sleep(3000);
            frm.Close();
            frm.Dispose();
        }
Beispiel #2
0
 private void ReloadCockpit(string text)
 {
     if (string.IsNullOrEmpty(text))
     {
         text = "Generic";
     }
     if (cockpit != null)
     {
         //cockpit.Close();
         cockpit.Dispose();
     }
     cockpit               = new frmCockpit();
     cockpit.LogMessage   += DebugMessage;
     cockpit.RequestValue += RequestVariable;
     cockpit.FormClosed   += Cockpit_Closed;
     if (cbFullScreen.Checked)
     {
         cockpit.WindowState     = FormWindowState.Maximized;
         cockpit.FormBorderStyle = FormBorderStyle.None;
     }
     else
     {
         cockpit.WindowState     = FormWindowState.Normal;
         cockpit.Height          = (int)txtCockpitHeight.Value;
         cockpit.Width           = (int)txtCockpitWidth.Value;
         cockpit.FormBorderStyle = FormBorderStyle.FixedDialog;
         cbCockpitCentre_CheckedChanged(null, null);
     }
     cockpit.Text = string.Format("Cockpit{0}", string.IsNullOrEmpty(text) ? "" : (" - " + text));
     cockpit.Show();
     cockpit.LoadLayout(text); // This should force all viible controls to be removed and re-added with new dimensions
     try
     {
         foreach (var requestResult in requestResults)
         {
             try
             {
                 cockpit.ResultUpdate(requestResult);
             }
             catch
             {
                 // If one plugin generates an error, it should not prevent others from being updated
             }
         }
     }
     catch { }
     RequestAllVariables(); // Resubmit all previous requests, in case server disconnected from FS
     cockpit.Focus();
 }
Beispiel #3
0
        private void ReceiveResultFromServer(object sender, ClientRequestResult requestResult)
        {
            string message = string.Format("Value Update: {0}({1}) = {2}", requestResult.Request.Name, requestResult.Request.Unit, requestResult.Result);

            DebugMessage(this, message);

            if (requestResults.Any(x => x.Request.Name == requestResult.Request.Name && x.Request.Unit == requestResult.Request.Unit))
            {
                lock (requestResults)
                {
                    requestResults.First(x => x.Request.Name == requestResult.Request.Name && x.Request.Unit == requestResult.Request.Unit).Result = requestResult.Result;
                }
            }
            else
            {
                requestResults.Add(requestResult);
            }

            UpdateValuesGrid(requestResult);
            // Received a new value for a request - identify which plugins need this variable and send it
            if (requestResult.Request.Name == "FS CONNECTION")
            {
                // Just informing us the current connection state to the Flight Simulator = display it on screen
                var existingConnectionState = this.Controls.Find("cbFSRunning", true);
                foreach (Control connectionStateLabel in existingConnectionState)
                {
                    if ((bool)requestResult.Result)
                    {
                        if (!((CheckBox)existingConnectionState.First()).Checked)
                        {
                            // Re-request all previous variables after reconnect
                            foreach (var variableRequest in requestResults.Where(x => x.Request.Name != "FS CONNECTION"))
                            {
                                RequestVariable(variableRequest.Request);
                            }
                        }
                        UpdateObject(connectionStateLabel, "Checked", true);
                    }
                    else
                    {
                        UpdateObject(connectionStateLabel, "Checked", false);
                    }
                }
            }
            if (requestResult.Request.Name == "TITLE")
            {
                // New aircraft selected
                if (requestResult.Result != null && cmbCockpitLayout.Items.Contains(requestResult.Result?.ToString()) && cbAutoCockpitLayout.Checked)
                {
                    // User wants to auto-select the aircraft
                    UpdateObject(cmbCockpitLayout, "SelectedIndex", cmbCockpitLayout.Items.IndexOf(requestResult.Result?.ToString()));
                    //cmbCockpitLayout.SelectedIndex = cmbCockpitLayout.Items.IndexOf(requestResult.Result?.ToString());
                    if (cockpit != null)
                    {
                        // Cockpit already display - reload with the new layout
                        ReloadCockpit(requestResult.Result.ToString());
                    }
                }
            }
            else
            {
                if (cockpit != null)
                {
                    cockpit.ResultUpdate(requestResult);
                }
            }
        }