Пример #1
0
 private void RemoveLogWindow(object commandParameter)
 {
     if (commandParameter != null)
     {
         MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure you want to delete: " + commandParameter.ToString() + "?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
         if (messageBoxResult == MessageBoxResult.Yes)
         {
             if (this.tourItemFactory.EditLogs(currentItem.Name, commandParameter.ToString(), "Test", 1, 1, "Test", DateTime.Today, true) == null)
             {
                 MessageBox.Show("There has been an error deleting your log, please try again!");
             }
         }
         Tours.Clear();
         currentItem = null;
         currentLog  = null;
         RaisePropertyChangedEvent(nameof(CurrentMap));
         RaisePropertyChangedEvent(nameof(CurrentPic));
         RaisePropertyChangedEvent(nameof(CurrentItem));
         RaisePropertyChangedEvent(nameof(CurrentLog));
         FillListBox();
     }
     else
     {
         MessageBox.Show("Please click on a Tour and then click on this Button again to delete a tour!");
     }
 }
Пример #2
0
        public void GetTourMapImage(TourItem tourItem)
        {
            try
            {
                log.Info($"Try to get tour image");
                string apiKey    = ConfigurationManager.AppSettings.Get("MQApiKey");
                string url       = $"https://www.mapquestapi.com/staticmap/v5/map?key={apiKey}&start={tourItem.Start}&end={tourItem.Destination}&session={tourItem.RouteSessionID}&size=800,400";
                string filename  = Path.GetRandomFileName() + ".png";
                string imagePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
                                   ConfigurationManager.AppSettings.Get("MapFolder");

                if (!Directory.Exists(imagePath))
                {
                    Directory.CreateDirectory(imagePath);
                }

                imagePath = imagePath + filename;
                WebClient mapWebClient = new WebClient();
                mapWebClient.DownloadFile(url, imagePath);

                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.UriSource   = new Uri(imagePath);
                image.EndInit();

                tourItem.RouteImage     = image;
                tourItem.RouteImagePath = imagePath;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                log.Error($"Error occoured after trying to get tour data from MapQuest \n Details: {e}");
            }
        }
Пример #3
0
        public string GetTourData(TourItem tourItem)
        {
            try
            {
                log.Info($"Try to get tour data from MapQuest");
                string apiKey    = ConfigurationManager.AppSettings.Get("MQApiKey");
                string routeType = tourItem.RouteType.ToString();
                string url       = $"https://www.mapquestapi.com/directions/v2/route?key={apiKey}&from={tourItem.Start}&to={tourItem.Destination}&routeType={routeType}&locale=de_DE&unit=k";

                var request = WebRequest.Create(url);
                request.Method = "GET";

                using var webResponse = request.GetResponse();
                using var webStream   = webResponse.GetResponseStream();

                using var reader = new StreamReader(webStream);
                string data = reader.ReadToEnd();

                Console.WriteLine(data);

                return(data);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                log.Error($"Error occoured after trying to get tour data from MapQuest \n Details: {e}");
                return("");
            }
        }
Пример #4
0
        public void AlterTourDetails(TourItem alterTourItem)
        {
            try
            {
                log.Info($"Try to alter Tour details in database");

                string sqlAlterTour = "UPDATE tours SET tourname=@tname, startp=@start, destination=@dest, tourdescription=@tdesc, " +
                                      "routeinformation=@rinf, routeimagepath=@img, tourdistance=@tdist, fuelused=@fuel, routetype=@rtype" +
                                      " WHERE tourid=@tid";

                _conn.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(sqlAlterTour, _conn);
                cmd.Parameters.AddWithValue("tname", alterTourItem.TourName);
                cmd.Parameters.AddWithValue("start", alterTourItem.Start);
                cmd.Parameters.AddWithValue("dest", alterTourItem.Destination);
                cmd.Parameters.AddWithValue("tdesc", alterTourItem.TourDescription);
                cmd.Parameters.AddWithValue("rinf", alterTourItem.RouteInformation);
                cmd.Parameters.AddWithValue("img", alterTourItem.RouteImagePath);
                cmd.Parameters.AddWithValue("tdist", alterTourItem.TourDistance);
                cmd.Parameters.AddWithValue("fuel", alterTourItem.FuelUsed);
                cmd.Parameters.AddWithValue("rtype", (int)alterTourItem.RouteType);
                cmd.Parameters.AddWithValue("tid", alterTourItem.TourId);
                cmd.Prepare();
                cmd.ExecuteNonQuery();
                _conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                log.Error($"Error occoured after trying to alter Log item in database \n Details: {e}");
            }
        }
Пример #5
0
        public override async Task <List <TourItem> > GetTours(SearchTourItem searchParams)
        {
            int    time = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
            string url  = string.Format("https://search.bankturov.ru/api/mobile/v1/search?departure_id={0}&destination_id={1}&adult_num={2}&child_num={3}&arrivalDateFrom={4}&arrivalDateTo={5}&nonstop=true&ticket=true&nightsStart={6}&nightsEnd={7}&hotelStars[]=1&hotelStars[]=2&hotelStars[]=3&hotelStars[]=4&hotelStars[]=5&mealType[]=1&mealType[]=2&mealType[]=3&mealType[]=4&mealType[]=5&mealType[]=6&resort_id[]={11}&minCost={8}&maxCost={9}&valute=RUB&offer_currency=RUB&source=search_online_page&_={10}",
                                        searchParams.FromCityId, searchParams.ToCityId, searchParams.AdultCount, searchParams.ChildCount, searchParams.DateFrom, searchParams.DateTo, searchParams.NightStart, searchParams.NightEnd, searchParams.MinCost, searchParams.MaxCost, time);

            var    httpClient = new HttpClient();
            string html       = await httpClient.GetStringAsync(url);

            dynamic result = JsonConvert.DeserializeObject(html);

            Console.WriteLine(result);
            var tours = new List <TourItem>();

            if (result.success == false)
            {
                return(tours);
            }

            foreach (var el in result.data.rows)
            {
                var tour = new TourItem()
                {
                    Cost            = el.costValues.RUB.source,
                    MealDescription = el.meal_description,
                    Resort          = el.curort,
                    Date            = el.date,
                    PageUrl         = String.Format("https://sletat.ru/tour/{0}-{1}-{2}", el.to, el.offer_id, el.search_id),
                };
                tours.Add(tour);
            }
            return(tours);
        }
Пример #6
0
        public void DeleteItems(TourItem deleteTourItem)
        {
            try
            {
                // Delete all Logs from tour
                foreach (var logItem in deleteTourItem.Log)
                {
                    DeleteLogItems(logItem);
                }

                // delete Tour
                log.Info($"Try to delete tour item from database");
                string sqlDelteTour = "DELETE FROM tours WHERE tourid=@tid";

                _conn.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(sqlDelteTour, _conn);
                cmd.Parameters.AddWithValue("tid", deleteTourItem.TourId);
                cmd.Prepare();
                cmd.ExecuteNonQuery();
                _conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                log.Error($"Error occoured after trying to delete tour item from database \n Details: {e}");
            }
        }
Пример #7
0
        public void AddFavorite(TourItem tour)
        {
            if (tour.IsFavorite)
            {
                DataBase.Delete(tour.Id, DBTable.FavoriteTour);
                tour.IsFavorite = false;
            }
            else
            {
                var items = DataBase.Query <FoundTour>(DBTable.FoundTour).Where(res =>
                                                                                tour.CityTo == res.Tour.CityTo &&
                                                                                tour.HotelId == res.Tour.HotelId &&
                                                                                tour.Cost == res.Tour.Cost &&
                                                                                tour.MealDescription == res.Tour.MealDescription &&
                                                                                tour.TownName == res.Tour.TownName).Limit(1).ToList();

                if (items.Count == 0)
                {
                    DataBase.Insert(tour, DBTable.FavoriteTour);
                    tour.IsFavorite = true;
                }
                else
                {
                    tour.Id         = items[0].Id;
                    tour.IsFavorite = true;
                }
            }
        }
Пример #8
0
        public void ParseError()
        {
            _jsonObject = JObject.Parse("{\"route\":{\"routeError\":{\"errorCode\":2,\"message\":\"\"}},\"info\":{\"statuscode\":402,\"messages\":[\"We are unable to route with the given locations.\"]}}");
            _item       = new TourItem();

            _tourItemFactory.LoadJsonData(_item, _jsonObject);

            Assert.AreEqual("We are unable to route with the given locations.", _item.TourDescription);
        }
Пример #9
0
        public void ParseWork()
        {
            _jsonObject = JObject.Parse("{\"route\":{\"fuelUsed\":0.23,\"realTime\":653,\"distance\":3.693,\"time\":501,\"sessionId\":\"55e60cd9-00b6-001a-02b7-20ac-00163e7dd551\",\"legs\":[{\"maneuvers\":[{\"index\":0,\"narrative\":\"Start out going east on Clarendon Blvd toward N Queen St.\",\"distance\":0.031,\"formattedTime\":\"00:00:06\"},{\"index\":2,\"narrative\":\"Turn right onto 14th St N.\",\"distance\":0.003,\"formattedTime\":\"00:00:05\"},{\"index\":3,\"narrative\":\"Merge onto Arlington Blvd/US-50 W via the ramp on the left.\",\"distance\":1.606,\"formattedTime\":\"00:02:31\"},{\"index\":4,\"narrative\":\"Turn left onto N Fillmore St.\",\"distance\":0.408,\"formattedTime\":\"00:01:14\"},{\"index\":5,\"narrative\":\"Stay straight to go onto S Walter Reed Dr.\",\"distance\":0.884,\"formattedTime\":\"00:02:29\"},{\"index\":6,\"narrative\":\"Turn slight left onto S Glebe Rd/VA-120.\",\"distance\":0.593,\"formattedTime\":\"00:01:24\"},{\"index\":7,\"narrative\":\"2400 S GLEBE RD is on the right.\",\"distance\":0,\"formattedTime\":\"00:00:00\"}]}],\"formattedTime\":\"00:08:21\",\"routeError\":{\"message\":\"\",\"errorCode\":-400}},\"info\":{\"statuscode\":0,\"messages\":[]}}");
            _item       = new TourItem();

            _tourItemFactory.LoadJsonData(_item, _jsonObject);

            Assert.AreEqual(0.23f, _item.FuelUsed);
        }
Пример #10
0
 private void ApplyNewTourItem(TourItem item)
 {
     Title       = item.Title;
     Text        = item.Text;
     Gif         = item.Gif;
     VideoSource = new ResourceVideoSource()
     {
         Path = item.Video
     };
 }
Пример #11
0
        public override async Task <List <TourItem> > GetTours(SearchTourItem searchParams)
        {
            try
            {
                var    t      = searchParams.DateTo.Split('.');
                string dateTo = t[2] + t[1] + t[0];

                t = searchParams.DateFrom.Split('.');
                string dateFrom = t[2] + t[1] + t[0];

                string urlParams = string.Format("ADULT={0}&CHILD={1}&CHECKIN_BEG={2}&CHECKIN_END={3}&NIGHTMAX={4}&NIGHTMIN={5}&STATE={6}&CURRENCY=1&PARTITION_PRICE=40&COSTMAX={9}&COSTMIN={8}&FILTER=6&PRICE_PAGE=1&RECONPAGE=400&UFILTER=0&REGULAR=True&CHARTER=True&SORT_TYPE=0&REGIONTO=&TOWNFROM={7}",
                                                 searchParams.AdultCount, searchParams.ChildCount, dateFrom, dateTo, searchParams.NightEnd, searchParams.NightStart, searchParams.ToCityId, searchParams.FromCityId, searchParams.MinCost, searchParams.MaxCost);

                string url = "https://webapisearch.anextour.com/b2c/Search?" + urlParams;

                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");

                string html = await httpClient.GetStringAsync(url);

                var result = new List <TourItem>();

                dynamic items = JsonConvert.DeserializeObject(html);

                foreach (var it in items[0].prices)
                {
                    try
                    {
                        string date = it.CheckIn;
                        date = date.Substring(6, 2) + "." + date.Substring(4, 2) + "." + date.Substring(0, 4);
                        var item = new TourItem()
                        {
                            Cost            = it.converted_price,
                            PageUrl         = "https://www.anextour.com" + it.Slug + "?" + urlParams,
                            HotelId         = (int)it.HotelInc,
                            MealDescription = it.MealNote,
                            Date            = date,
                            TownName        = it.TownName,
                            CityTo          = items[0].state.name
                        };
                        result.Add(item);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new List <TourItem>());
            }
        }
Пример #12
0
        private void AddTourItem(object commandParameter)
        {
            TourItem newItem = _tourItemFactory.AddTourItem();

            TourItemsList.Add(newItem);

            if (TourItemsList.Count < 2)
            {
                PreselectListviewItem();
            }
        }
Пример #13
0
        public bool DeleteTour(TourItem currentItem)
        {
            bool state = false;

            if (tours.Contains(currentItem))
            {
                tours.Remove(currentItem);
                state = true;
            }
            return(state);
        }
Пример #14
0
        public void LoadTourDataJson(ObservableCollection <TourItem> tourItems)
        {
            log.Info($"Try to open open-File-Dialog");

            try
            {
                var dialog = new OpenFileDialog();
                dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                dialog.FileName         = "TourData";                             // Default file name
                dialog.DefaultExt       = ".json";                                // Default file extension
                dialog.Filter           = "Tour Data Export File (.json)|*.json"; // Filter files by extension

                // Show open file dialog box
                bool?result = dialog.ShowDialog();

                // Process open file dialog box results
                if (result == true)
                {
                    // Open document
                    log.Info($"Try to load & parse JSON file");
                    string          jsonDataString = File.ReadAllText(dialog.FileName);
                    List <TourItem> jsonTourItems  = JsonConvert.DeserializeObject <List <TourItem> >(jsonDataString);
                    foreach (var tourItem in jsonTourItems)
                    {
                        TourItem tempTour       = AddItems();
                        int      tempTourTourId = tempTour.TourId;
                        tourItem.TourId = tempTourTourId;
                        AlterTourDetails(tourItem);
                        if (tourItem.Log.Count > 0)
                        {
                            foreach (var logItem in tourItem.Log)
                            {
                                LogItem tempLog = new LogItem();
                                tempLog.TourId = tempTourTourId;
                                AddLogItems(tempLog);
                                logItem.TourId = tempLog.TourId;
                                logItem.LogId  = tempLog.LogId;
                                AlterLogItems(logItem);
                            }
                        }
                        tourItems.Add(tourItem);
                    }
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                log.Error($"Error occoured after trying to Load Data from File System \n Details: {e}");
            }
            log.Info($"Dialog abborted :0");
        }
Пример #15
0
 public void DeleteTourItem(TourItem deleteTourItem)
 {
     try
     {
         log.Info($"Try to delete Tour Item");
         tourItemDAO.DeleteItems(deleteTourItem);
     }
     catch (Exception e)
     {
         log.Error($"Error occoured after trying to delete Tour Item \n Details: {e}");
         Console.WriteLine(e);
     }
 }
Пример #16
0
 public void GetImage(TourItem tourItem)
 {
     try
     {
         log.Info($"Try to Get Image");
         tourItemDAO.GetTourMapImage(tourItem);
     }
     catch (Exception e)
     {
         log.Error($"Error occoured after trying to Get Image \n Details: {e}");
         Console.WriteLine(e);
     }
 }
Пример #17
0
        public bool AddTour(TourItem tour)
        {
            foreach (var item in tours)
            {
                if (item.Name == tour.Name)
                {
                    return(false);
                }
            }

            tours.Add(tour);
            return(true);
        }
Пример #18
0
 public void AddLogItem(LogItem addLogItem, TourItem selectedTourItem)
 {
     try
     {
         log.Info($"Try to add Log Item");
         addLogItem.Date   = DateTime.Now;
         addLogItem.TourId = selectedTourItem.TourId;
         tourItemDAO.AddLogItems(addLogItem);
     }
     catch (Exception e)
     {
         log.Error($"Error occoured after trying to add Log Item \n Details: {e}");
         Console.WriteLine(e);
     }
 }
Пример #19
0
 public void AlterLogItem(TourItem selectedTourItem)
 {
     try
     {
         log.Info($"Try to alter Log Items");
         foreach (var logItem in selectedTourItem.Log)
         {
             tourItemDAO.AlterLogItems(logItem);
         }
     }
     catch (Exception e)
     {
         log.Error($"Error occoured after trying to alter Log Items \n Details: {e}");
         Console.WriteLine(e);
     }
 }
Пример #20
0
        public void LoadJsonData(TourItem alterTourItem, JObject jsonObject)
        {
            try
            {
                log.Info($"Try to Parse JSON from Tour Data");
                string infoCode    = "";
                string infoMessage = "";

                int errorCode = (int)jsonObject["route"]?["routeError"]?["errorCode"];
                if (errorCode > 0)
                {
                    infoCode    = (string)jsonObject["info"]?["statuscode"];
                    infoMessage = (string)jsonObject["info"]?["messages"]?[0];
                    log.Info($"Tour not Valid Error Code: {errorCode}; Info Code: {infoCode}; Info Messsage: {infoMessage}");
                    alterTourItem.Destination     = "Not a Valid Tour";
                    alterTourItem.Start           = "Not a Valid Tour";
                    alterTourItem.TourDescription = $"{infoMessage}";
                    return;
                }

                alterTourItem.TourDistance   = (float)jsonObject["route"]?["distance"];
                alterTourItem.FuelUsed       = (float)jsonObject["route"]?["fuelUsed"];
                alterTourItem.RouteSessionID = (string)jsonObject["route"]?["sessionId"];


                alterTourItem.RouteInformation = $"Directions of Route From {alterTourItem.Start} to {alterTourItem.Destination}\n" +
                                                 $"Tour distance: {alterTourItem.TourDistance}km\n" +
                                                 $"Tour Time: {jsonObject["route"]?["formattedTime"]}\n---------------\n";

                JToken maneuverArray = (JArray)jsonObject["route"]?["legs"]?[0]?["maneuvers"];
                if (maneuverArray != null)
                {
                    foreach (var maneuversSource in maneuverArray)
                    {
                        alterTourItem.RouteInformation +=
                            $"{(int) maneuversSource["index"] + 1}. {maneuversSource["narrative"]}; \n" +
                            $"\tDirection distance {maneuversSource["distance"]}km; \n" +
                            $"\tTime for Direction {maneuversSource["formattedTime"]}\n\n";
                    }
                }
            }
            catch (Exception e)
            {
                log.Error($"Error occoured after trying to Parse JSON \n Details: {e}");
                Console.WriteLine(e);
            }
        }
Пример #21
0
 // called by script when score item object is intsantiated
 public void SetTextElements(TourItem tourItem)
 {
     // draw the name of the question
     questionName.text = tourItem.itemName;
     // draw text to say if item is correct
     if (tourItem.isCorrect)
     {
         isCorrectText.text  = "Correct";
         isCorrectText.color = Color.green;
     }
     else
     {
         isCorrectText.text  = "Incorrect";
         isCorrectText.color = Color.red;
     }
     // draw the time it took to answer the question
     timeText.text = tourItem.answerTime.ToString();
 }
Пример #22
0
    private void setContentFromFile(TourItem item)
    {
        System.IO.StreamReader streamReader = null;
        try
        {
            string directory = ConfigurationManager.AppSettings["HelpFilesRoute"];
            string extension = ConfigurationManager.AppSettings["HelpFilesExtension"];
            if (!string.IsNullOrEmpty(directory) && !directory.EndsWith("/"))
            {
                directory += "/";
            }
            if (!string.IsNullOrEmpty(extension) && !extension.StartsWith("."))
            {
                extension = "." + extension;
            }

            string language = LanguageUtilities.GetLanguageFromContext();

            string title = item.content;
            string file  = Server.MapPath(directory + item.content + "_" + language + extension);
            if (System.IO.File.Exists(file))
            {
                streamReader = new System.IO.StreamReader(file);
                item.content = streamReader.ReadToEnd();
            }
            else
            {
                item.content = "";
            }

            item.title += " <small><span class='label label-default'>" + title + "</span></small>";
        }
        catch (Exception x)
        {
            log.Error("Error loading content from help file", x);
        }
        finally
        {
            if (streamReader != null)
            {
                streamReader.Close();
            }
        }
    }
Пример #23
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            string   webRootPath = _webHostEnvironment.WebRootPath;
            TourItem tourItem    = await _db.TourItem.FindAsync(id);

            if (tourItem != null)
            {
                var imagePath = Path.Combine(webRootPath, tourItem.Image.TrimStart('\\'));

                if (System.IO.File.Exists(imagePath))
                {
                    System.IO.File.Delete(imagePath);
                }
                _db.TourItem.Remove(tourItem);
                await _db.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #24
0
        public void AlterTourDetails(TourItem alterTourItem)
        {
            try
            {
                string tourDataJson = tourItemDAO.GetTourData(alterTourItem);

                log.Info($"Try to alter Tour Data");
                JObject jsonObject = JObject.Parse(tourDataJson);
                LoadJsonData(alterTourItem, jsonObject);

                tourItemDAO.GetTourMapImage(alterTourItem);
                tourItemDAO.AlterTourDetails(alterTourItem);
            }
            catch (Exception e)
            {
                log.Error($"Error occoured after trying to alter Log Item \n Details: {e}");
                Console.WriteLine(e);
            }
        }
Пример #25
0
 public async Task CreatePDF(string tourName, TourItem mockItem = null)
 {
     PDFHandler tempHandler = new();
     await tempHandler.CreatePDF(tourName, mockItem);
 }
Пример #26
0
 public void Setup()
 {
     test          = ConfigurationManager.AppSettings.Get("DBTest");
     _database     = Database.Instance(test);
     _itemList     = _database.GetItems();
     _testTourItem = _itemList[^ 1];
 public bool DeleteTour(TourItem currentItem)
 {
     return(dataAccess.DeleteTour(currentItem));
 }
 public bool AddTour(TourItem tour)
 {
     return(dataAccess.AddTour(tour));
 }
Пример #29
0
 public async Task CreatePDF(string tourName, TourItem mockItem = null)
 {
     await tourItemDAO.CreatePDF(tourName, mockItem);
 }
Пример #30
0
 public void AlterTourDetails(TourItem alterTourItem)
 {
     dataAccess.AlterTourDetails(alterTourItem);
 }