Beispiel #1
0
        public RocketsCommand(OddityCore oddity, CacheService cacheService, RocketsEmbedGenerator rocketsEmbedGenerator)
        {
            _cacheService          = cacheService;
            _rocketsEmbedGenerator = rocketsEmbedGenerator;

            _cacheService.RegisterDataProvider(CacheContentType.Rockets, async p => await oddity.RocketsEndpoint.GetAll().ExecuteAsync());
        }
Beispiel #2
0
        public CompanyInfoCommand(OddityCore oddity, CacheService cacheService, CompanyInfoEmbedGenerator companyInfoEmbedGenerator)
        {
            _cacheService = cacheService;
            _companyInfoEmbedGenerator = companyInfoEmbedGenerator;

            _cacheService.RegisterDataProvider(CacheContentType.CompanyInfo, async p => await oddity.CompanyEndpoint.Get().ExecuteAsync());
        }
        public LaunchpadsCommand(OddityCore oddity, CacheService cacheService, LaunchpadsEmbedGenerator launchpadsEmbedGenerator)
        {
            _cacheService             = cacheService;
            _launchpadsEmbedGenerator = launchpadsEmbedGenerator;

            _cacheService.RegisterDataProvider(CacheContentType.Launchpads, async p => await oddity.LaunchpadsEndpoint.GetAll().ExecuteAsync());
        }
        public RoadsterCommand(OddityCore oddity, CacheService cacheService, RoadsterEmbedBuilder roadsterEmbedBuilder)
        {
            _cacheService         = cacheService;
            _roadsterEmbedBuilder = roadsterEmbedBuilder;

            _cacheService.RegisterDataProvider(CacheContentType.Roadster, async p => await oddity.RoadsterEndpoint.Get().ExecuteAsync());
        }
Beispiel #5
0
        public LaunchesListCommands(OddityCore oddity, PaginationService paginationService, CacheService cacheService, LaunchesListTableGenerator launchesListTableGenerator)
        {
            _oddity                     = oddity;
            _paginationService          = paginationService;
            _cacheService               = cacheService;
            _launchesListTableGenerator = launchesListTableGenerator;

            _allowedPaginationTypes = new List <CacheContentType>
            {
                CacheContentType.UpcomingLaunches,
                CacheContentType.PastLaunches,
                CacheContentType.AllLaunches,
                CacheContentType.FailedStarts,
                CacheContentType.FailedLandings,
                CacheContentType.LaunchesWithOrbit
            };

            Bot.Client.MessageReactionAdded += Client_MessageReactionAddedAsync;

            _cacheService.RegisterDataProvider(CacheContentType.UpcomingLaunches, async p => await _oddity.LaunchesEndpoint.GetUpcoming().ExecuteAsync());
            _cacheService.RegisterDataProvider(CacheContentType.PastLaunches, async p => await _oddity.LaunchesEndpoint.GetPast().ExecuteAsync());
            _cacheService.RegisterDataProvider(CacheContentType.AllLaunches, async p => await _oddity.LaunchesEndpoint.GetAll().ExecuteAsync());
            _cacheService.RegisterDataProvider(CacheContentType.FailedStarts, async p =>
            {
                var result = await _oddity.LaunchesEndpoint.Query()
                             .WithFieldEqual(q => q.Success, false)
                             .WithLimit(1000)
                             .ExecuteAsync();

                return(result.Data);
            });
        }
Beispiel #6
0
        public Bot()
        {
            _oddity            = new OddityCore();
            _diagnosticService = new DiagnosticService();

            _oddity.Timeout                 = new TimeSpan(0, 0, 2);
            _oddity.OnRequestSend          += Oddity_OnRequestSend;
            _oddity.OnResponseReceive      += Oddity_OnResponseReceive;
            _oddity.OnDeserializationError += Oddity_OnDeserializationError;

            Client              = new DiscordClient(GetClientConfiguration());
            CacheService        = new CacheService();
            LogExecutedCommands = true;

            Client.Ready          += Client_Ready;
            Client.Heartbeated    += Client_Heartbeat;
            Client.GuildCreated   += Client_GuildCreated;
            Client.GuildDeleted   += Client_GuildDeleted;
            Client.ClientErrored  += Client_ClientError;
            Client.SocketErrored  += Client_SocketError;
            Client.SocketClosed   += Client_SocketClosed;
            Client.Resumed        += Client_Resumed;
            Client.MessageCreated += Client_MessageCreated;

            _commands = Client.UseCommandsNext(GetCommandsConfiguration());
            _commands.CommandExecuted += Commands_CommandExecuted;
            _commands.CommandErrored  += Commands_CommandError;
            _commands.SetHelpFormatter <CustomHelpFormatter>();

            RegisterCommands();
        }
Beispiel #7
0
 public async Task <IReadOnlyList <LaunchInfo> > Upcoming()
 {
     using (var o = new OddityCore())
     {
         o.OnDeserializationError += OddityOnOnDeserializationError;
         return(await o.Launches.GetUpcoming().ExecuteAsync());
     }
 }
Beispiel #8
0
        private static async Task DisplayWithHighestSpeed(OddityCore oddity, uint count)
        {
            var satellites = await oddity.StarlinkEndpoint.Query()
                             .SortBy(p => p.VelocityKilometersPerSecond, false)
                             .WithLimit(count)
                             .ExecuteAsync();

            DisplaySatelliteData(satellites.Data, "Satellites with the highest speed:");
        }
Beispiel #9
0
        private static async Task DisplayWithLowestPeriapsis(OddityCore oddity, uint count)
        {
            var satellites = await oddity.StarlinkEndpoint.Query()
                             .SortBy(p => p.SpaceTrack.Periapsis)
                             .WithLimit(count)
                             .ExecuteAsync();

            DisplaySatelliteData(satellites.Data, "Satellites with the lowest periapsis:");
        }
Beispiel #10
0
        private static async Task DisplayWithHighestApoapsis(OddityCore oddity, uint count)
        {
            var satellites = await oddity.StarlinkEndpoint.Query()
                             .SortBy(p => p.SpaceTrack.Apoapsis, false)
                             .WithLimit(count)
                             .ExecuteAsync();

            DisplaySatelliteData(satellites.Data, "Satellites with the highest apoapsis:");
        }
Beispiel #11
0
        public DescriptionService(CacheService cacheService, OddityCore oddity)
        {
            _descriptionRefreshTimer          = new Timer(DescriptionUpdateIntervalMinutes * 60 * 1000);
            _descriptionRefreshTimer.Elapsed += DescriptionRefreshTimer_ElapsedAsync;
            _descriptionRefreshTimer.Start();

            _cacheService = cacheService;

            _cacheService.RegisterDataProvider(CacheContentType.NextLaunch, async p => await oddity.LaunchesEndpoint.GetNext().ExecuteAsync());
        }
        public SingleLaunchCommands(OddityCore oddity, CacheService cacheService, LaunchNotificationsService launchNotificationsService, LaunchInfoEmbedGenerator launchInfoEmbedGenerator)
        {
            _oddity       = oddity;
            _cacheService = cacheService;
            _launchNotificationsService = launchNotificationsService;
            _launchInfoEmbedGenerator   = launchInfoEmbedGenerator;

            _cacheService.RegisterDataProvider(CacheContentType.AllLaunches, async p => await _oddity.LaunchesEndpoint.GetAll().ExecuteAsync());
            _cacheService.RegisterDataProvider(CacheContentType.NextLaunch, async p => await _oddity.LaunchesEndpoint.GetNext().ExecuteAsync());
            _cacheService.RegisterDataProvider(CacheContentType.LatestLaunch, async p => await _oddity.LaunchesEndpoint.GetLatest().ExecuteAsync());
        }
Beispiel #13
0
        private static void DisplayRestOfUpcomingLaunches(OddityCore oddity)
        {
            var upcomingLaunches = oddity.Launches.GetUpcoming().Execute();

            Console.WriteLine("All upcoming launches:");
            Console.WriteLine("---------------------------------------------------------------------------");
            foreach (var launch in upcomingLaunches)
            {
                Console.WriteLine($"{launch.MissionName} ({launch.LaunchDateUtc}) at {launch.LaunchSite.SiteName}");
            }
        }
Beispiel #14
0
        public static void Main(string[] args)
        {
            var oddity = new OddityCore();

            oddity.OnDeserializationError += OddityOnOnDeserializationError;

            DisplayNextLaunch(oddity);
            DisplayRestOfUpcomingLaunches(oddity);

            Console.Read();
        }
Beispiel #15
0
        static async Task Main(string[] args)
        {
            var oddity = new OddityCore();

            // Optional
            oddity.OnDeserializationError += OddityOnDeserializationError;
            oddity.OnRequestSend          += Oddity_OnRequestSend;
            oddity.OnResponseReceive      += OddityOnResponseReceive;

            // Get company information
            var company = await oddity.Company.GetInfo().ExecuteAsync();

            // Get all history
            var history = await oddity.Company.GetHistory().ExecuteAsync();

            // Get history from the last two years and ordered descending
            var historyWithFilter = await oddity.Company.GetHistory()
                                    .WithRange(DateTime.Now.AddYears(-2), DateTime.Now)
                                    .Descending()
                                    .ExecuteAsync();

            // Get data about Falcon Heavy
            var falconHeavy = await oddity.Rockets.GetAbout(RocketId.FalconHeavy).ExecuteAsync();

            // Get list of all launchpads
            var allLaunchpads = await oddity.Launchpads.GetAll().ExecuteAsync();

            // Get information about the next launch
            var nextLaunch = await oddity.Launches.GetNext().ExecuteAsync();

            // Get data about all launches of Falcon 9 which has been launched to ISS. Next, sort it ascending
            var launchWithFilters = await oddity.Launches.GetAll()
                                    .WithRocketName("Falcon 9")
                                    .WithOrbit(OrbitType.ISS)
                                    .Ascending()
                                    .ExecuteAsync();

            // Get all capsule types
            var capsuleTypes = await oddity.Capsules.GetAll().ExecuteAsync();

            // Get capsule which has been launched 2015-04-14 at 20:10
            var capsuleWithFilters = await oddity.DetailedCapsules.GetAll()
                                     .WithOriginalLaunch(new DateTime(2015, 4, 14, 20, 10, 0))
                                     .ExecuteAsync();

            // Get all cores
            var allCores = await oddity.DetailedCores.GetAll().ExecuteAsync();

            // Get Roadster info
            var roadster = await oddity.Roadster.Get().ExecuteAsync();

            Console.Read();
        }
Beispiel #16
0
 private static async Task GetAllMissions()
 {
     await Task.Run(() =>
     {
         try
         {
             var appData = new HttpClient().GetAsync("https://launchpadx.herokuapp.com/api/update").Result;
             if (appData.StatusCode == HttpStatusCode.OK)
             {
                 var json          = JObject.Parse(appData.Content.ReadAsStringAsync().Result);
                 var newAppVer     = (string)json.SelectToken("currentVersion");
                 var currentAppVer = Application.ProductVersion.Remove(3);
                 if (newAppVer != currentAppVer)
                 {
                     MessageBox.Show($"New version is available and ready to use!\n\nFor more information please visit: https://github.com/skyffx/Launchpad" +
                                     $"\n\nYour current version: {currentAppVer}\nNew version: {newAppVer}",
                                     "—Launchpad—", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
         }
         catch (Exception)
         {
             // ignored
         }
         //
         var response = new HttpClient().GetAsync("https://api.spacexdata.com/v3/").Result;
         if (response.StatusCode == HttpStatusCode.OK)
         {
             try
             {
                 var missionsData  = new OddityCore().Launches.GetAll().Execute();
                 var appFormThread = new Thread(() => new MainForm(missionsData).ShowDialog());
                 appFormThread.SetApartmentState(ApartmentState.STA);
                 appFormThread.Start();
                 Application.Exit();
             }
             catch (Exception)
             {
                 MessageBox.Show($"SpaceX, we have a problem!\n\nhttps://api.spacexdata.com/v3/launches\n" +
                                 $"=> Request is not completed!\n\nPlease to run app again.",
                                 "—Launchpad—", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 Application.Exit();
             }
         }
         else
         {
             MessageBox.Show($"SpaceX, we have a problem!\nHttpStatusCode: {response.StatusCode.ToString()}",
                             "—Launchpad—", MessageBoxButtons.OK, MessageBoxIcon.Error);
             Application.Exit();
         }
     });
 }
Beispiel #17
0
        protected BuilderBase(OddityCore context)
        {
            Context = context;

            _serializationSettings = new JsonSerializerSettings
            {
                Error = JsonDeserializationError,
#if DEBUG
                CheckAdditionalContent = true,
                MissingMemberHandling  = MissingMemberHandling.Error
#endif
            };
        }
Beispiel #18
0
        public CoreInfoCommand(OddityCore oddity, CacheService cacheService, CoreInfoEmbedGenerator coreInfoEmbedGenerator)
        {
            _cacheService           = cacheService;
            _coreInfoEmbedGenerator = coreInfoEmbedGenerator;

            _cacheService.RegisterDataProvider(CacheContentType.CoreInfo, async p =>
            {
                var result = await oddity.CoresEndpoint.Query()
                             .WithFieldEqual(q => q.Serial, p)
                             .ExecuteAsync();
                return(result.Data.FirstOrDefault());
            });
        }
Beispiel #19
0
        public static async Task Main(string[] args)
        {
            var oddity    = new OddityCore();
            var stopWatch = Stopwatch.StartNew();

            oddity.OnDeserializationError += OddityOnOnDeserializationError;

            await DisplayNextLaunch(oddity);
            await DisplayRestOfUpcomingLaunches(oddity);

            Console.WriteLine($"Generated in {stopWatch.Elapsed.TotalSeconds:F1} seconds");
            Console.Read();
        }
Beispiel #20
0
        private static void DisplayNextLaunch(OddityCore oddity)
        {
            var nextLaunchData = oddity.Launches.GetNext().Execute();

            Console.WriteLine("Next launch data:");
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine("Mission name     | " + nextLaunchData.MissionName);
            Console.WriteLine("Launchpad        | " + nextLaunchData.LaunchSite.SiteLongName);
            Console.WriteLine("Launch date UTC  | " + nextLaunchData.LaunchDateUtc);
            Console.WriteLine("Rocket           | " + nextLaunchData.Rocket.RocketName);
            Console.WriteLine("Payloads         | " + string.Join(',', nextLaunchData.Rocket.SecondStage.Payloads.Select(p => p.PayloadId)));
            Console.WriteLine();
        }
Beispiel #21
0
        public LaunchNotificationsService(OddityCore oddity, CacheService cacheService)
        {
            _cacheService      = cacheService;
            _notificationTimes = new List <int> {
                10, 60, 60 * 24, 60 * 24 * 7
            };

            _notificationsUpdateTimer          = new System.Timers.Timer(UpdateNotificationsIntervalMinutes * 60 * 1000);
            _notificationsUpdateTimer.Elapsed += Notifications_UpdateTimerOnElapsed;
            _notificationsUpdateTimer.Start();

            _cacheService.RegisterDataProvider(CacheContentType.NextLaunch, async p => await oddity.LaunchesEndpoint.GetNext().ExecuteAsync());
        }
Beispiel #22
0
        public CoresCommand(OddityCore oddity, PaginationService paginationService, CacheService cacheService, CoresListTableGenerator coresListTableGenerator)
        {
            _paginationService       = paginationService;
            _cacheService            = cacheService;
            _coresListTableGenerator = coresListTableGenerator;

            _allowedPaginationTypes = new List <CacheContentType>
            {
                CacheContentType.Cores
            };
            _cacheService.RegisterDataProvider(CacheContentType.Cores, async p => await oddity.CoresEndpoint.GetAll().ExecuteAsync());

            Bot.Client.MessageReactionAdded += ClientOnMessageReactionAddedAsync;
        }
Beispiel #23
0
        private static async Task DisplayRestOfUpcomingLaunches(OddityCore oddity)
        {
            var upcomingLaunches = await oddity.LaunchesEndpoint.GetUpcoming().ExecuteAsync();

            Console.WriteLine("All upcoming launches:");
            Console.WriteLine("---------------------------------------------------------------------------");

            foreach (var launch in upcomingLaunches)
            {
                var formattedDate = GetFormattedDate(launch.DateUtc, launch.DatePrecision);
                Console.WriteLine($"{launch.Name} ({formattedDate}) at {launch.Launchpad.Value.FullName}");
            }

            Console.WriteLine();
        }
Beispiel #24
0
        private static async Task DisplayNextLaunch(OddityCore oddity)
        {
            var nextLaunchData = await oddity.LaunchesEndpoint.GetNext().ExecuteAsync();

            var formattedDate = GetFormattedDate(nextLaunchData.DateUtc, nextLaunchData.DatePrecision);

            Console.WriteLine("Next launch data:");
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine("Mission name     | " + nextLaunchData.Name);
            Console.WriteLine("Launchpad        | " + nextLaunchData.Launchpad.Value.FullName);
            Console.WriteLine("Launch date UTC  | " + formattedDate);
            Console.WriteLine("Rocket           | " + nextLaunchData.Rocket.Value.Name);
            Console.WriteLine("Payloads         | " + string.Join(", ", nextLaunchData.Payloads.Select(p => GetPayloadInfo(p.Value))));
            Console.WriteLine();
        }
Beispiel #25
0
        public static async Task Main()
        {
            var oddity    = new OddityCore();
            var stopWatch = Stopwatch.StartNew();

            oddity.OnDeserializationError += OddityOnOnDeserializationError;

            await DisplayWithHighestApoapsis(oddity, SatellitesPerTable);
            await DisplayWithLowestPeriapsis(oddity, SatellitesPerTable);
            await DisplayWithHighestSpeed(oddity, SatellitesPerTable);
            await DisplayWithLowestSpeed(oddity, SatellitesPerTable);

            Console.WriteLine($"Generated in {stopWatch.Elapsed.TotalSeconds:F1} seconds");
            Console.Read();
        }
Beispiel #26
0
 private void SetContextInNestedObjects(OddityCore context)
 {
     foreach (var property in GetType().GetRuntimeProperties())
     {
         if (property.GetValue(this) is ModelBase underlyingInstance)
         {
             underlyingInstance.SetContext(context);
         }
         else if (property.GetValue(this) is IEnumerable <ModelBase> collection)
         {
             foreach (var element in collection)
             {
                 element.SetContext(context);
             }
         }
     }
 }
Beispiel #27
0
 private static async Task GetAllMissions()
 {
     await Task.Run(() =>
     {
         try
         {
             var oddityCore     = new OddityCore();
             var launchesData   = oddityCore.LaunchesEndpoint.GetAll().Execute();
             var nextLaunch     = oddityCore.LaunchesEndpoint.GetNext().Execute();
             var mainFormThread = new Thread(() => new MainForm(launchesData, nextLaunch).ShowDialog());
             mainFormThread.SetApartmentState(ApartmentState.STA);
             mainFormThread.Start();
             Application.Exit();
         }
         catch
         {
             MessageBox.Show("An error occurred while retrieving data from server!\r\n" +
                             "Please to run app again.", $"—{Application.ProductName}—", MessageBoxButtons.OK, MessageBoxIcon.Error);
             Application.Exit();
         }
     });
 }
Beispiel #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LaunchesEndpoint{TData}"/> class.
 /// </summary>
 /// <param name="context">The Oddity context used to interact with API.</param>
 public LaunchesEndpoint(OddityCore context) : base(context, LibraryConfiguration.HighPriorityCacheLifetime)
 {
 }
Beispiel #29
0
 public async Task <IRoadsterInfo> Roadster()
 {
     using (var o = new OddityCore())
         return(new OddityRoadsterInfo(await o.Roadster.Get().ExecuteAsync()));
 }
Beispiel #30
0
 public async Task <DetailedCoreInfo> Core(string id)
 {
     using (var o = new OddityCore())
         return(await o.DetailedCores.GetAbout(id).ExecuteAsync());
 }