private static string CreateNewAdapterConfig(AdapterContext.AdapterModel ctx) { bool adapterValid = false; string nwAdapterName = string.Empty; do { if (!string.IsNullOrEmpty(nwAdapterName)) { write("Adapter name already used!", ConsoleColor.Red); } nwAdapterName = input("Enter a new adapter name:", ConsoleColor.Yellow); if (string.IsNullOrEmpty(nwAdapterName) || ctx.Adapters.Any(o => o.Name.ToLower() == nwAdapterName.ToLower())) { adapterValid = false; } else { adapterValid = true; } } while (adapterValid == false); int nwAdapterPollRate = PromptForPollRate(); var nwAdapter = new AdapterContext.DataModel.AdapterConfig() { Name = nwAdapterName, PollRate = nwAdapterPollRate, Created = DateTime.UtcNow, LastStarted = DateTime.UtcNow }; ctx.Adapters.Add(nwAdapter); ctx.SaveChanges(); return(nwAdapter.Name); }
private static string SelectAdapterConfig(AdapterContext.AdapterModel ctx) { string selectedAdapterName = string.Empty; List <string> adapterNames = ctx.Adapters.Select(o => o.Name).ToList(); adapterNames.Add("** Create a new Config **"); if (adapterNames.Count == 1) { write("No Adapters available, please create a new one.", ConsoleColor.Red); selectedAdapterName = CreateNewAdapterConfig(ctx); } else { int selectedAdapterIndex = prompt("Choose an Adapter Config to use:", true, adapterNames.ToArray()); if (selectedAdapterIndex == adapterNames.Count - 1) { selectedAdapterName = CreateNewAdapterConfig(ctx); } else { selectedAdapterName = adapterNames[selectedAdapterIndex]; } } return(selectedAdapterName); }
public AdapterQuery(AdapterContext.AdapterModel ctx) { Field <AdapterConfigType>( name: "adapterconfig", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "name" }), resolve: context => { var name = context.GetArgument <string>("name"); return(ctx.Adapters.Where(o => o.Name.ToLower() == name.ToLower()).ToList()); } ); }
static void Main(string[] args) { if (System.IO.File.Exists(logPath)) { var fsi = new System.IO.FileInfo(logPath); if (fsi.Length > Math.Pow(10, 7)) { System.IO.File.WriteAllText(logPath, ""); log("Log file reset"); } } _handler += new EventHandler(Handler); log("Application started"); Console.Title = "PC Adapter"; var ctx = new AdapterContext.AdapterModel(); ctx.Database.CreateIfNotExists(); bool skipPrompts = false; string adapterName = string.Empty; string defaultView = "0"; if (args.Length > 0) { string tmpName = args[0]; if (ctx.Adapters.Any(o => o.Name.ToLower() == tmpName.ToLower())) { adapterName = args[0]; skipPrompts = true; } if (args.Length > 1) { defaultView = args[1]; } } if (string.IsNullOrEmpty(adapterName)) { adapterName = SelectAdapterConfig(ctx); } using (var _adapter = new Adapter(ctx, adapterName)) { _adapter.Updated += Adapter_Updated; if (!skipPrompts) { if (ask($"Would you like to configure Adapter '{_adapter.Config.Name}'?", true, true)) { if (ask($"Would you like to change the Polling Rate for Adapter '{_adapter.Config.Name}'? Current Poll Rate is {_adapter.Config.PollRate}ms", true, true)) { int nwAdapterPollRate = PromptForPollRate(); _adapter.Config.PollRate = nwAdapterPollRate; } } if (ask("Would you like to configure DataItems before we begin?", true, true)) { ConfigureDataItems(_adapter); } } if (skipPrompts || ask("Are you ready to start monitoring?")) { //AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; SetConsoleCtrlHandler(_handler, true); Monitor(_adapter, defaultView); //AppDomain.CurrentDomain.ProcessExit -= CurrentDomain_ProcessExit; } } if (!skipPrompts) { write("Press enter to exit"); Console.ReadLine(); } log("Application closing"); }
public AdapterAPIController() { this._ctx = new AdapterContext.AdapterModel("DefaultConnection"); }
public GraphQlController() { this.ctx = new AdapterContext.AdapterModel(); }