Exemple #1
0
        /************************************************************************************************************************/

        /// <summary>
        /// Obsługa przerwania po kliknięciu przycisku "Edit launch" - edycja wybranego lotu, zapisanie zmian w bazie i aktualizacja listy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editButton_Click(object sender, EventArgs e)
        {
            DialogForm dialogForm = new DialogForm();

            dialogForm.editedLaunch = activeLaunch;

            if (dialogForm.ShowDialog() == DialogResult.OK)
            {
                activeLaunch = dialogForm.editedLaunch;
            }
            else
            {
                return;
            }

            using (var context = new LaunchContext())
            {
                Launch launch = context.launches.Find(activeLaunch.LaunchId);
                launch.Clone(activeLaunch);

                context.SaveChanges();
            }

            ListReload();
        }
Exemple #2
0
        /************************************************************************************************************************/

        /// <summary>
        /// Metoda służąca do przepisania zawartości jednego startu do drugiego.
        /// </summary>
        /// <param name="launch"></param>
        public void Clone(Launch launch)
        {
            LaunchId              = launch.LaunchId;
            name                  = launch.name;
            windowStart           = launch.windowStart;
            windowEnd             = launch.windowEnd;
            launchProvider        = launch.launchProvider;
            rocketFullName        = launch.rocketFullName;
            location              = launch.location;
            locationGoogleMapsUrl = launch.locationGoogleMapsUrl;
            favourite             = launch.favourite;
        }
        /************************************************************************************************************************/

        /// <summary>
        /// Metoda odpowiedzialna za dodawanie startu do ulubionych lub usuwanie go stamtąd.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void favCheckBox_Click(object sender, EventArgs e)
        {
            using (var context = new LaunchContext())
            {
                Launch launch = context.launches.Find(activeLaunch.LaunchId);
                launch.favourite = !launch.favourite;
                context.SaveChanges();
                favLaunchesList.Items.Add(new ListViewItem(launch.ShortData));
            }
            if (tabsControl.SelectedIndex == 0)
            {
                ListReload();
            }
        }
        /************************************************************************************************************************/

        /// <summary>
        /// Przerwanie pochodzące od timera. Celem jego jest wyświetlenie powiadomienia o ulubionych startach,
        /// do których pozostało mniej niż 15 minut.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void NotifyCheckInTimer(Object source, ElapsedEventArgs e)
        {
            Action timerUpdate = () => {
                using (var context = new LaunchContext())
                {
                    String msg    = "";
                    bool   notify = false;
                    foreach (ListViewItem launchItem in favLaunchesList.Items)
                    {
                        Launch launch = context.launches.Find(int.Parse(launchItem.Text));
                        try
                        {
                            var timeToStart = DateTime.Now.Subtract(launch.windowStart).Days;

                            if (timeToStart >= -1 && timeToStart < 1)
                            {
                                timeToStart = DateTime.Now.Subtract(launch.windowStart).Minutes;

                                if (timeToStart >= -15 && !alreadyNotyfied.Contains(launch))
                                {
                                    if (timeToStart <= 0)
                                    {
                                        notify = true;
                                        alreadyNotyfied.Add(launch);
                                        msg = launch.name;
                                        break;
                                    }
                                }
                            }
                        }
                        catch
                        {
                            return;
                        }
                    }

                    if (notify == true)
                    {
                        LaunchAlert alert = new LaunchAlert();
                        alert.showAlert(msg);
                    }
                }
            };

            Invoke(new Action(timerUpdate));
        }
Exemple #5
0
        /************************************************************************************************************************/

        /// <summary>
        /// Metoda porównująca, czy dwa loty są tożsame.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            Launch launch = (Launch)obj;

            if (string.Compare(launch.name, name) != 0)
            {
                return(false);
            }
            if (string.Compare(launch.status, status) != 0)
            {
                return(false);
            }
            if (!launch.windowStart.Equals(windowStart))
            {
                return(false);
            }
            if (!launch.windowEnd.Equals(windowEnd))
            {
                return(false);
            }
            if (string.Compare(launch.launchProvider, launchProvider) != 0)
            {
                return(false);
            }
            if (string.Compare(launch.rocketFullName, rocketFullName) != 0)
            {
                return(false);
            }
            if (string.Compare(launch.location, location) != 0)
            {
                return(false);
            }
            if (string.Compare(launch.locationGoogleMapsUrl, locationGoogleMapsUrl) != 0)
            {
                return(false);
            }

            return(true);
        }
Exemple #6
0
        /************************************************************************************************************************/

        /// <summary>
        /// Obsługa przerwania po kliknięciu przycisku "Add launch" - dodawanie nowego lotu do bazy, potem aktualizacja listy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, EventArgs e)
        {
            addButton.Enabled = false;
            Launch launch = new Launch();

            DialogForm dialogForm = new DialogForm();

            if (dialogForm.ShowDialog() == DialogResult.OK)
            {
                launch = dialogForm.editedLaunch;

                using (var context = new LaunchContext())
                {
                    context.launches.Add(launch);
                    context.SaveChanges();
                }
            }
            this.ListReload();
            addButton.Enabled = true;
        }
Exemple #7
0
        /************************************************************************************************************************/

        /// <summary>
        /// Obsługa przerwania po kliknięciu przycisku "Remove launch" - usunięcie wybranego lotu, zapisanie zmian w bazie i aktualizacja listy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure?", "Remove launches", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result != DialogResult.OK)
            {
                return;
            }

            using (var context = new LaunchContext())
            {
                foreach (ListViewItem item in activeList.SelectedItems)
                {
                    Launch launchToRemove = context.launches.Find(int.Parse(item.Text));
                    context.launches.Remove(launchToRemove);
                }
                context.SaveChanges();
            }
            this.ListReload();
        }
Exemple #8
0
        /// <summary>
        /// Parse jsonResponse and create Launch objects
        ///
        /// if failed throws one ouf exceptions: SerializationException,KeyNotFoundException
        /// </summary>
        /// <param name="jsonApiResponse"></param> json response for launch request. Response must have proper composition
        public List <Launch> parseLaunchRequest(String jsonApiResponse)
        {
            JsonArray results = new JsonArray();

            try
            {
                var serializer = new JavaScriptSerializer();
                var response   = serializer.Deserialize <dynamic>(jsonApiResponse);
                results = response["results"];
            }
            catch (System.Runtime.Serialization.SerializationException exception)
            {
                Console.WriteLine("Parsing goes wrong, not proper json file");
                Console.WriteLine("Exception message:" + exception.ToString());
                throw new InvalidOperationException("Parsing goes wrong, not proper json file");
            }

            var launchList = new List <Launch>();

            foreach (JsonObject launchData in results)
            {
                Launch launch = new Launch();
                try
                {
                    launch.name = launchData["name"].ToString();
                    JsonObject nestedLaunchInfo = (JsonObject)launchData["status"];
                    launch.status = nestedLaunchInfo["name"].ToString();

                    var windowStartString = launchData["window_start"].ToString();
                    launch.windowStart = DateTime.ParseExact(windowStartString, "yyyy-MM-ddTHH:mm:ssZ",
                                                             System.Globalization.CultureInfo.InvariantCulture);

                    var windowEndString = launchData["window_end"].ToString();
                    launch.windowEnd = DateTime.ParseExact(windowEndString, "yyyy-MM-ddTHH:mm:ssZ",
                                                           System.Globalization.CultureInfo.InvariantCulture);

                    nestedLaunchInfo      = (JsonObject)launchData["launch_service_provider"];
                    launch.launchProvider = nestedLaunchInfo["name"].ToString();

                    nestedLaunchInfo      = (JsonObject)launchData["rocket"];
                    nestedLaunchInfo      = (JsonObject)nestedLaunchInfo["configuration"];
                    launch.rocketFullName = nestedLaunchInfo["full_name"].ToString();

                    JsonObject padInfo = (JsonObject)launchData["pad"];
                    if (padInfo["map_url"] != null)
                    {
                        String mapInfo = (String)padInfo["map_url"];
                        launch.locationGoogleMapsUrl = mapInfo.ToString();
                    }


                    padInfo         = (JsonObject)padInfo["location"];
                    launch.location = padInfo["name"].ToString();

                    launchList.Add(launch);
                }
                catch (System.Collections.Generic.KeyNotFoundException exception)
                {
                    Console.WriteLine("Parsing goes wrong, key not found in dictionary");
                    Console.WriteLine("Exception message:" + exception.ToString());
                    throw new InvalidOperationException("Parsing goes wrong, key not found in dictionary");
                }
            }

            return(launchList);
        }