Beispiel #1
0
        public static List <PoiData> BuildPoiResponse(string json)
        {
            var jobject = JObject.Parse(json);

            var result = new List <PoiData>();

            if ((jobject["pois"] as JObject) == null)
            {
                return(result);
            }

            foreach (var element in (jobject["pois"] as JObject).Properties().Select(x => x.Name))
            {
                var poiResponse = new PoiData();

                poiResponse.Core          = CreateFwData <FwCore>(jobject, element, "fw_core", FillGeneric <FwCore>);
                poiResponse.Time          = CreateFwData <FwTime>(jobject, element, "fw_time", FillGeneric <FwTime>);
                poiResponse.Xml3ds        = CreateFwData <FwXml3d>(jobject, element, "fw_xml3d", FillGeneric <FwXml3d>);
                poiResponse.Contacts      = CreateFwData <FwContact>(jobject, element, "fw_contact", FillGeneric <FwContact>);
                poiResponse.Media         = CreateFwData <FwMedia>(jobject, element, "fw_media", FillGeneric <FwMedia>);
                poiResponse.Relationships = CreateFwData <List <FwRelationship> >(jobject, element, "fw_relationships", FillGeneric <List <FwRelationship> >);
                poiResponse.Markers       = CreateFwData <FwMarker>(jobject, element, "fw_marker", FillGeneric <FwMarker>);

                poiResponse.Id = element;

                result.Add(poiResponse);
            }

            return(result);
        }
Beispiel #2
0
        public async Task <AddPoiResponse> AddPoiAsync(PoiData poiData)
        {
            using (var client = new HttpClient())
            {
                var url = string.Format("{0}/{1}", _url, "add_poi");

                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                    NullValueHandling = NullValueHandling.Ignore
                };

                poiData.Id = null;

                var poiStringData = JsonConvert.SerializeObject(poiData, Newtonsoft.Json.Formatting.Indented, jsonSerializerSettings);

                var jsonContent = new StringContent(poiStringData);

                var response = await client.PostAsync(url, jsonContent);

                var content = await response.Content.ReadAsStringAsync();

                try
                {
                    return(JsonConvert.DeserializeObject <AddPoiResponse>(content));
                }
                catch (Exception)
                {
                    throw new Exception(content);
                }
            }
        }
Beispiel #3
0
        private static PoiData GetPoiData(string dir, PoiCategory category, PoiCountry country)
        {
            try
            {
                var filename  = $"{dir}\\{GetFileName(category)}";
                var xml       = File.ReadAllText(filename);
                var listOfPoi = GpxFileParser.Parse(xml, category, country, Guid.NewGuid());
                var count     = listOfPoi.Count;
                //DateTime creation = File.GetCreationTime(filename);
                DateTime modificationDate = File.GetLastWriteTime(filename);

                var pd = new PoiData()
                {
                    Category    = category,
                    DateCreated = modificationDate,
                    PointCount  = count,
                    Url         = $"PoiData/{country}/{GetFileName(category)}",
                    Description = "",
                    Id          = GetGuid(country, category)
                };

                return(pd);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Default constructor that requires a path to be passed in
        /// </summary>
        /// <param name="path"></param>
        public Creation(string path)
        {
            _universePath = path;
            ShipData      = LoadData <ShipData>(@"Data/shipData.json");
            _worldInfo    = LoadData <WorldInfo>(@"Data/worldTags.json");
            _starData     = LoadData <StarData>(@"Data/starData.json");
            _charData     = LoadData <CharData>(@"Data/characterData.json");
            PoiData       = LoadData <PoiData>(@"Data/pointsOfInterest.json");
            ProblemData   = LoadData <ProblemData>(@"Data/problemData.json");
            // SocietyData = LoadData<SocietyData>(@"Data/societyData.json");
            SocietyData = null;
            AlienData   = LoadData <AlienData>(@"Data/alienData.json");

            MaleFirstNameGeneration = new NameGeneration();
            MaleFirstNameGeneration.GenerateChain(_charData.MaleName);

            FemaleFirstNameGeneration = new NameGeneration();
            FemaleFirstNameGeneration.GenerateChain(_charData.FemaleName);

            StarNameGeneration = new NameGeneration();
            StarNameGeneration.GenerateChain(_starData.Stars);

            PlanetNameGeneration = new NameGeneration();
            PlanetNameGeneration.GenerateChain(_starData.Planets);

            // LastNameGeneration = new NameGeneration();
            // LastNameGeneration.GenerateChain(CharData.LastName);

            CharacterNameGenerations.Add(MaleFirstNameGeneration);
            CharacterNameGenerations.Add(FemaleFirstNameGeneration);
            // CharacterNameGenerations.Add(LastNameGeneration);
        }
Beispiel #5
0
 private void WriteNewObject(JsonWriter writer, PoiData poi, JsonSerializer serializer, string propertyName, object value)
 {
     if(value != null)
     {
         writer.WritePropertyName(propertyName);
         serializer.Serialize(writer, value);
     }
 }
Beispiel #6
0
 private void WriteNewObject(JsonWriter writer, PoiData poi, JsonSerializer serializer, string propertyName, object value)
 {
     if (value != null)
     {
         writer.WritePropertyName(propertyName);
         serializer.Serialize(writer, value);
     }
 }
        protected void NotifyDataChanged(PoiViewItemList poiData = null)
        {
            if (GpsUtils.HasLocation(MyLocation))
            {
                if (poiData is null)
                {
                    var poiList = Database.GetItems(MyLocation, Settings.MaxDistance);
                    PoiData = new PoiViewItemList(poiList, MyLocation, Settings.MaxDistance, Settings.Categories, iGpsUtilities);
                }
                else
                {
                    PoiData = poiData;
                }

                //fetch selected point again
                if (SelectedPoi != null)
                {
                    var selectedPoi = PoiData.Find(x => x.Poi.Id == SelectedPoi.Poi.Id);
                    if (selectedPoi != null)
                    {
                        selectedPoi.Selected = true;
                        SelectedPoi          = selectedPoi;
                    }
                    else
                    {
                        SelectedPoi = null;
                    }
                }

                var args = new DataChangedEventArgs()
                {
                    PoiData = PoiData
                };
                DataChanged?.Invoke(this, args);
            }
            else
            {
                var args = new DataChangedEventArgs()
                {
                    PoiData = null
                };
                DataChanged?.Invoke(this, args);
            }
        }
Beispiel #8
0
        public async Task <string> UpdatePoiAsync(PoiData poiData)
        {
            using (var client = new HttpClient())
            {
                var url = string.Format("{0}/{1}", _url, "update_poi");

                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                    NullValueHandling = NullValueHandling.Ignore
                };

                var poiStringData = JsonConvert.SerializeObject(poiData, Newtonsoft.Json.Formatting.Indented, jsonSerializerSettings);

                var jsonContent = new StringContent(poiStringData);

                var response = await client.PostAsync(url, jsonContent);

                var content = await response.Content.ReadAsStringAsync();

                return(content);
            }
        }
Beispiel #9
0
 public DownloadViewItem(PoisToDownload fromDatabase, PoiData fromInternet)
 {
     this.fromDatabase = fromDatabase;
     this.fromInternet = fromInternet;
 }
Beispiel #10
0
        public Universe AddPoi(Universe universe, PoiDefaultSettings poiDefaultSettings, PoiData poiData)
        {
            universe.PointsOfInterest ??= new List <PointOfInterest>();

            var starId = string.IsNullOrEmpty(poiDefaultSettings.StarId)
                ? null
                : poiDefaultSettings.StarId;

            if (starId == null)
            {
                foreach (var star in universe.Stars)
                {
                    var max = poiDefaultSettings.PoiRange == null || poiDefaultSettings.PoiRange.Length == 0 ||
                              poiDefaultSettings.PoiRange[0] == -1 || poiDefaultSettings.PoiRange[1] == -1
                        ? Rand.Next(2, 5)
                        : Rand.Next(poiDefaultSettings.PoiRange[0], poiDefaultSettings.PoiRange[1] + 1);

                    var poiCount = 0;

                    while (poiCount < max)
                    {
                        var poi = new PointOfInterest();

                        // Generate a POI ID
                        IdGen.GenerateId(poi);

                        if (universe.PointsOfInterest.Exists(a => a.Id == poi.Id))
                        {
                            continue;
                        }

                        // Set the POI information with randomized data
                        poi.StarId = star.Id;
                        universe.Zones.Single(a => a.StarId == star.Id).PointsOfInterest.Add(poi.Id);
                        poi.Name = star.Name + " " + ToRoman(poiCount + 1);
                        var type = poiData.PointsOfInterest[Rand.Next(0, poiData.PointsOfInterest.Count)];
                        poi.Type       = type.Type;
                        poi.OccupiedBy = type.OccupiedBy[Rand.Next(0, type.OccupiedBy.Count)];
                        poi.Situation  = type.Situation[Rand.Next(0, type.Situation.Count)];

                        universe.PointsOfInterest.Add(poi);

                        poiCount++;
                    }
                }
            }
            else
            {
                var locId = (from stars in universe.Stars select new { ID = stars.Id })
                            .Single(a => a.ID == starId).ID;

                if (string.IsNullOrEmpty(locId))
                {
                    throw new FileNotFoundException("No locations with ID " + starId + " found");
                }

                var max = poiDefaultSettings.PoiRange == null || poiDefaultSettings.PoiRange.Length == 0 ||
                          poiDefaultSettings.PoiRange[0] == -1 || poiDefaultSettings.PoiRange[1] == -1
                    ? Rand.Next(1, 5)
                    : Rand.Next(poiDefaultSettings.PoiRange[0], poiDefaultSettings.PoiRange[1] + 1);

                var poiCount = 0;

                while (poiCount < max)
                {
                    var poi = new PointOfInterest();

                    // Generate a POI ID
                    IdGen.GenerateId(poi);

                    if (universe.PointsOfInterest.Exists(a => a.Id == poi.Id))
                    {
                        continue;
                    }

                    // Set the POI information with randomized data
                    poi.StarId = starId;
                    universe.Zones.Single(a => a.StarId == starId).PointsOfInterest.Add(poi.Id);
                    poi.Name = universe.Stars.Single(a => a.Id == starId).Name + " " + ToRoman(poiCount + 1);
                    var type = poiData.PointsOfInterest[Rand.Next(0, poiData.PointsOfInterest.Count)];
                    poi.Type       = type.Type;
                    poi.OccupiedBy = type.OccupiedBy[Rand.Next(0, type.OccupiedBy.Count)];
                    poi.Situation  = type.Situation[Rand.Next(0, type.Situation.Count)];

                    universe.PointsOfInterest.Add(poi);

                    poiCount++;
                }
            }

            return(universe);
        }
Beispiel #11
0
 public string UpdatePoi(PoiData poiData)
 {
     return(UpdatePoiAsync(poiData).ResultSynchronizer());
 }
Beispiel #12
0
 public AddPoiResponse AddPoi(PoiData poiData)
 {
     return(AddPoiAsync(poiData).ResultSynchronizer());
 }