public void UpdateComponentsFromSource(mySettings.CachetSettings CachetConnectionSettings) { this.cachetComponents.Clear(); try { string prot = ""; if (CachetConnectionSettings.UseSSL) { prot = "https"; } else { prot = "http"; } System.Uri requestUri = new System.Uri(prot + "://" + CachetConnectionSettings.CachetHost + "/api/v1/components"); System.Net.HttpWebRequest web = System.Net.WebRequest.CreateHttp(requestUri); web.ContentType = "application/json; charset=utf-8"; web.Method = System.Net.WebRequestMethods.Http.Get; web.Accept = "application/json"; System.IO.StreamReader sr = new System.IO.StreamReader(web.GetResponse().GetResponseStream()); string responseBody = sr.ReadToEnd(); Newtonsoft.Json.Linq.JObject jObjectResponse = Newtonsoft.Json.Linq.JObject.Parse(responseBody); IList <Newtonsoft.Json.Linq.JToken> tokens = jObjectResponse["data"].Children().ToList(); foreach (Newtonsoft.Json.Linq.JToken jToken in tokens) { CachetInformation.CachetComponent cachetComponent = jToken.ToObject <CachetInformation.CachetComponent>(); this.AddComponent(cachetComponent); } } catch (System.Exception ex) { throw(ex); } }
private static void SetupDialog(bool permanent) { Console.Clear(); string setupMessage = "" + "**********************************************************************************" + CVars.newLine + "*********************************** Setup **********************************" + CVars.newLine + "**********************************************************************************" + CVars.newLine + "* *" + CVars.newLine; Console.Write(setupMessage); Console.Write("* Please enter the Token-ID: "); string NewBotToken = Console.ReadLine(); Console.WriteLine("* *"); Console.Write("* Please enter your first administrative ChatId: "); string NewFirstAdminChatId = Console.ReadLine(); Console.WriteLine("* *"); Console.WriteLine("* OK, next we'll setup your cachet instance. *"); Console.Write("* Enter your Cachet's dns name (no http or https url): "); string NewCachetHost = Console.ReadLine(); Console.WriteLine("* *"); Console.Write("* Your auth-token for Cachet: "); string NewCachetToken = Console.ReadLine(); Console.WriteLine("* *"); Console.Write("* Does your Cachetserver is reachable over https? <Y/n> "); ConsoleKeyInfo answer = Console.ReadKey(false); while (!(answer.Key == ConsoleKey.Y || answer.Key == ConsoleKey.Enter || answer.Key == ConsoleKey.N)) { Console.Write(CVars.newLine + "* Does your Cachetserver is reachable over https? <Y/n> "); answer = Console.ReadKey(false); } bool useHTTPs = true; if (answer.Key == System.ConsoleKey.Y || answer.Key == System.ConsoleKey.Enter) { useHTTPs = true; } else { useHTTPs = false; } Console.WriteLine("* *"); Console.WriteLine("* Congratulation. Setup completed. *"); mySettings.BotSettings NewBotSettings = new mySettings.BotSettings(NewBotToken, new string[] { NewFirstAdminChatId }); mySettings.CachetSettings NewCachetSettings = new mySettings.CachetSettings(NewCachetHost, NewCachetToken, useHTTPs); ConfigurationSettings = new mySettings.ConfigurationSettings(NewBotSettings, NewCachetSettings); if (permanent) { ConfigurationSettings.SaveSettingsToFile(mySettingsFilePath); Console.WriteLine("* *"); Console.WriteLine("* File settings.json saved. *"); } else { Console.WriteLine("* *"); Console.WriteLine("* Settings saved. *"); } }