public StateTracker(IEliteDangerousApi api) { var apiEvents = api.Events.Events(); apiEvents.DockedEvent.Select(d => new DockedUpdate(true, d.StationName)) .Merge(apiEvents.LocationEvent .Where(l => l.Docked) .Select(l => new DockedUpdate(l.Docked, l.StationName))) .Merge(apiEvents.UndockedEvent.Select(_ => new DockedUpdate(false, ""))) .Subscribe(x => { Station.OnNext(x.Station); IsDocked.OnNext(x.IsDocked); }, _ => {}, () => { Station.OnCompleted(); IsDocked.OnCompleted(); }); apiEvents.FsdJumpEvent.Select(d => d.StarSystem) .Merge(apiEvents.LocationEvent.Select(l => l.StarSystem)) .Subscribe(x => System.OnNext(x), _ => {}, () => System.OnCompleted()); Location = Station .CombineLatest(System, (station, system) => (station, system)) .CombineLatest(IsDocked, (stationUpdate, isDocked) => new LocationUpdate(isDocked, stationUpdate.system, stationUpdate.station)); }
public Core(ILogger <Core> log, IEliteDangerousApi api) { Console.Write("Authorize connection in MATRIC, then enter PIN:"); var parser = new FileIniDataParser(); if (!File.Exists(ConfigName)) { File.Create(ConfigName).Close(); } ; InitData = parser.ReadFile(ConfigName); PIN = InitData["DECK"]["PIN"]; matric = new Matric.Integration.Matric(AppName); if (String.IsNullOrEmpty(PIN)) { matric.RequestAuthorizePrompt(); PIN = Console.ReadLine(); } matric.PIN = PIN; matric.OnConnectedClientsReceived += Matric_OnConnectedClientsReceived; matric.GetConnectedClients(); InitData["DECK"]["PIN"] = PIN; parser.WriteFile(ConfigName, InitData); // Get our dependencies through dependency injection _log = log; _api = api; Console.Title = AppName; }
public MainWindowViewModel(IEliteDangerousApi api, MissionCatchUp missionCatchUp, MissionTargetManager missionTargetManager, StateTracker tracker) { Router = new RoutingState(); Activator = new ViewModelActivator(); api.Events().OnCatchedUp .Select(_ => true) .ObserveOn(RxApp.MainThreadScheduler) .ToPropertyEx(this, x => x.DoneLoading); // Change what is showing this.WhenActivated(disposables => { var filledMissionCountChanged = missionTargetManager .Connect() .Where(m => m.IsFilled) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out var stationMissions) .DisposeMany(); api.Events().OnStart .Select(_ => new LocationUpdate(false, "", "")) .Merge(tracker.Location) .CombineLatest(filledMissionCountChanged.Select(_ => 0).Prepend(0), (dockedLocation, _) => dockedLocation) .CombineLatest(api.Events().OnCatchedUp.Delay(TimeSpan.FromMilliseconds(50)), (location, _) => location) // .Where(_ => DoneLoading) .ObserveOn(RxApp.MainThreadScheduler) .Select(e => { var showTurnIn = e.IsDocked ? stationMissions.Any(m => m.Station == e.Station) : stationMissions.Any(m => m.System == e.System); return(showTurnIn // true ? (IRoutableViewModel)((App)Application.Current).Services .GetService <TurnInViewModel>() ! : (IRoutableViewModel)((App)Application.Current).Services .GetService <MissionStatsViewModel>() !); } ) .Do(vm => Router.Navigate.Execute(vm)) .Subscribe(_ => { }) .DisposeWith(disposables); }); Task.Run(() => { missionCatchUp.CatchUp(); api.StartAsync(); }); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); _api = host.Services.GetRequiredService <IEliteDangerousApi>(); _socketHandler = host.Services.GetRequiredService <WebSocketHandler>(); _variableService = host.Services.GetRequiredService <VariablesService>(); _eliteVaInstaller = host.Services.GetRequiredService <EliteVaInstaller>(); _log = host.Services.GetRequiredService <ILogger <Program> >(); await _api.InitializeAsync(); // Sub to events _api.Events.AllEvent += async(sender, e) => await Broadcast("Event", e, true, false); // Sub to statuses _api.Cargo.OnChange += async(sender, e) => await Broadcast("Cargo", _api.Cargo, true, true); _api.Market.OnChange += async(sender, e) => await Broadcast("Market", _api.Market, true, true); _api.Modules.OnChange += async(sender, e) => await Broadcast("Modules", _api.Modules, true, true); _api.Outfitting.OnChange += async(sender, e) => await Broadcast("Outfitting", _api.Outfitting, true, true); _api.Shipyard.OnChange += async(sender, e) => await Broadcast("Shipyard", _api.Shipyard, true, true); _api.Ship.OnChange += async(sender, e) => await Broadcast("Status", _api.Ship, true, true); _api.NavRoute.OnChange += async(sender, e) => await Broadcast("NavRoute", _api.NavRoute, true, true); _api.Backpack.OnChange += async(sender, e) => await Broadcast("Backpack", _api.Backpack, true, true); // Sub to options _api.Bindings.OnChange += async(sender, e) => await _socketHandler.Broadcast(new WebSocketMessage("Bindings", RemoveLineEndings(_api.Bindings.ToXml())), true, true); // Send userprofile await _socketHandler.Broadcast(new WebSocketMessage("UserProfile", UserProfile.Get()), true, true); // Send latest eliteva version await _socketHandler.Broadcast(new WebSocketMessage("EliteVA.Latest", await _eliteVaInstaller.GetLatestVersion()), true, true); await _api.StartAsync(); await host.RunAsync(); }
public WebSocketHandler(ILogger <WebSocketHandler> log, IEliteDangerousApi api, EliteVaInstaller eliteVaInstaller) { _log = log; _api = api; _eliteVaInstaller = eliteVaInstaller; _eliteVaInstaller.OnStart += async(sender, e) => { await Broadcast(new WebSocketMessage("EliteVA.Start", null)); }; _eliteVaInstaller.OnProgress += async(sender, e) => { await Broadcast(new WebSocketMessage("EliteVA.Progress", e.ProgressPercentage)); }; _eliteVaInstaller.OnNewTask += async(sender, e) => { await Broadcast(new WebSocketMessage("EliteVA.Task", e)); }; _eliteVaInstaller.OnFinished += async(sender, e) => { await Broadcast(new WebSocketMessage("EliteVA.Finished", null)); }; _eliteVaInstaller.OnError += async(sender, e) => { await Broadcast(new WebSocketMessage("EliteVA.Error", e)); }; _frontendWebSockets = new List <WebSocket>(); _clientWebSockets = new List <WebSocket>(); _pluginWebSockets = new List <WebSocket>(); _frontendCatchupMessages = new List <WebSocketMessage>(); _clientCatchupMessages = new List <WebSocketMessage>(); _pluginCatchupMessages = new List <WebSocketMessage>(); WebSocketLogs.OnLog += async(sender, e) => await Broadcast(new WebSocketMessage("Log", JsonConvert.SerializeObject(e)), WebSocketType.FrontEnd, true, false); }
public Core(ILogger <Core> log, IEliteDangerousApi api) { // Get our dependencies through dependency injection _log = log; _api = api; }
/// <summary> /// Wrapper for event modules /// </summary> /// <param name="api"> The EliteDangerousAPI </param> protected EliteDangerousEventModule(IEliteDangerousApi api) { EliteAPI = api; }
/// <inheritdoc /> public LandingPadModule(IEliteDangerousApi api, ILogger <LandingPadModule> log) : base(api) { _log = log; }