我有几个模型:// RichTextBox pingCheckStdOut in Form1 created by the IDE:
this.pingCheckStdOut = new System.Windows.Forms.RichTextBox();
// my code:
// Calling the async task from here
private async void pingCheckInitBtn_Click(object sender, EventArgs e)
{
string ipAddress = pingCheckIpAddressBox.Text;
string ldapUsername = usernameBox.Text;
string ldapPassword = passwordBox.Text;
string command = "";
await Task.Run(() => sshAllStdOut(ipaddress, ldapUsername, ldapPassword, command));
}
// the code I'm having trouble with (want to change pingCheckStdOut to a variable)
private async Task sshAllStdOut(string ipaddress, string ldapUsername, string ldapPassword, string command)
{
SshClient client = new SshClient(ipaddress, 22, ldapUsername, ldapPassword);
client.Connect();
var stream = client.CreateShellStream("dumb", 120, 24, 360, 600, 1024);
var reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
writer.AutoFlush = true;
while (stream.Length == 0)
{
Thread.Sleep(1000);
}
WriteStream(command, writer, stream);
while (client.IsConnected)
{
string line = reader.ReadLine();
if (line != null)
{
//This is the line I'd like to convert into a "variable" for example:
// updateGUI(line, pingCheckStdOut) instead of passing directly
updateGUI(line);
Thread.Sleep(100);
}
if (line == "server_name:~ $ ")
{
client.Disconnect();
}
}
}
/* This is my code to update the GUI from the thread */
delegate void SetTextCallback(string output);
public void updateGUI(string input)
{
string output = input;
if (this.InvokeRequired)
{
// It's on a different thread, use Invoke.
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke
(d, new object[] { output });
}
else
{
// Else it's on the same thread, no need for Invoke
this.pingCheckStdOut.Text = output;
}
}
// This method is passed in to the SetTextCallBack delegate
// to set the Text property of the RichTextBox.
public void SetText(string output)
{
this.pingCheckStdOut.AppendText(output + "\n");
pingCheckStdOut.ScrollToCaret();
}
,Tickets
,Seats
,Sections
。
TicketTypes
Ticket belongs_to Seat
Seat belongs_to Section
和Section belongs_to a TicketType
包含所有价格信息。
目前,要获取我需要做的一些价格信息TicketType
选择座位,然后为该部分执行另一个选择语句,然后为票证类型执行另一个。
是否有更有效的方法来获取我需要的信息?我尝试使用ticket.seat.section.ticket_type.things_i_need
,joins
和merge
但无法获得我需要的信息。
答案 0 :(得分:0)
我不确定你是否尝试过这个但我认为会是:
@ticket = Ticket.includes(seat: { section: [:ticket_type] }).find(params[:id])
@ticket.seat.section.ticket_type.things_i_need