public SetRevitDataForm(LyrebirdChannel c, GHClient p) { parent = p; channel = c; InitializeComponent(); // Position the form. Left = 0; Top = 0; //MessageBox.Show(string.Format("The system is {0} and the endpoint is:\n{1}", client.State.ToString(), client.Endpoint.Address.ToString())); if (channel != null) { try { string test = channel.DocumentName(); if (test == null) { MessageBox.Show("Error!!!!!!!!!!"); } RevitObject[] temp = channel.FamilyNames().ToArray(); if (temp != null && temp.Any()) { familyNames = channel.FamilyNames().ToList(); } else { MessageBox.Show("The Lyrebird Service for Revit could not be found. Make sure the service is turned on and try again."); this.Close(); } } catch (Exception ex) { MessageBox.Show("Error\n" + ex.ToString()); } if (familyNames != null && familyNames.Count > 0) { familyComboBox.ItemsSource = familyNames; familyComboBox.DisplayMemberPath = "FamilyName"; bool check = false; if (parent.FamilyName != null) { for (int i = 0; i < familyNames.Count; i++) { string famName = familyNames[i].FamilyName; if (famName == parent.FamilyName) { familyComboBox.SelectedIndex = i; check = true; } } } if (!check) { familyComboBox.SelectedIndex = 0; } } } }
public override Task Execute() { var accessToken = SettingsManager.Get("access_token"); SettingsManager.Remove("access_token"); GHClient.RemoveCredentials(accessToken); Console.WriteLine("You're now logged out."); return(Task.FromResult(0)); }
static async Task ConsoleHub(CommandParser parser) { // Initialize the prompt from the settings. if (SettingsManager.Exists("prompt")) { var prompt = SettingsManager.Get("prompt"); Ui.DefaultPrompt = prompt; } if (!SettingsManager.Exists("access_token")) { Console.WriteLine("Seems like you haven't logged in yet. Let's do it!"); var loginCmd = new LoginCommand(); await loginCmd.Execute(); } // Initialize the credentials of the user with the access token. var accessToken = SettingsManager.Get("access_token"); GHClient.SetCredentials(accessToken); // Get the current logged in user to show the data. var currentUser = await GHClient.client.User.Current(); Ui.WriteLineGreen($"You're logged in as {currentUser.Name} ({currentUser.Email})"); string[] dividedCommand; while (true) { Ui.WritePrompt(); var input = Console.ReadLine(); dividedCommand = parser.SplitInput(input); Command cmd = null; try { cmd = parser.ParseCommand(dividedCommand); } catch (Exception error) { Ui.WriteLineRed(error.Message); } if (cmd != null) { Ui.NewLine(); await cmd.Execute(); } } }
public override async Task Execute() { // Check first if we're already logged in. if (SettingsManager.Exists("access_token")) { Console.WriteLine("You're already logged in. Log out first if you want to switch accounts."); return; } var loginUrl = GHClient.GetLoginUrl(); Console.WriteLine("This app uses OAuth to log into your account."); Console.WriteLine("The app will attempt to open a window in 5 seconds, in case it doesn't work"); Console.WriteLine("Open this URL:"); Console.WriteLine(loginUrl); System.Threading.Thread.Sleep(5000); Process.Start(loginUrl.ToString()); Console.WriteLine("...And once you finish, copy the URL and press any key. I'll be waiting."); Console.ReadKey(); Console.WriteLine("Ready? Great! Copy the URL that you got over here."); var responseUrl = Console.ReadLine(); if (String.IsNullOrEmpty(responseUrl) || !responseUrl.StartsWith("http://localhost/oauth") || !responseUrl.Contains("?code=")) { Console.WriteLine("That doesn't seem like a valid URL >.<"); Environment.Exit(0); } Console.WriteLine("Nice! Wait a second, we're getting your access token..."); var accessToken = await GHClient.GetAccessToken(responseUrl); GHClient.SetCredentials(accessToken); // Save this access token. SettingsManager.Set("access_token", accessToken); }