private ProfileStation ProfileStationOutfittingAndShipyard(ProfileStation lastStation)
 {
     if (lastStation.stationServices.Exists(s => s.Key.ToLowerInvariant() == "outfitting"))
     {
         Logging.Debug("Getting station outfitting data");
         string outfitting = obtainProfile(ServerURL() + SHIPYARD_URL, out DateTime outfittingTimestamp);
         outfitting = "{\"lastStarport\":" + outfitting + "}";
         JObject outfittingJson = JObject.Parse(outfitting);
         lastStation.outfitting          = OutfittingFromProfile(outfittingJson);
         lastStation.outfittingupdatedat = Dates.fromDateTimeToSeconds(outfittingTimestamp);
     }
     if (lastStation.stationServices.Exists(s => s.Key.ToLowerInvariant() == "shipyard"))
     {
         Logging.Debug("Getting station shipyard data");
         Thread.Sleep(5000);
         string shipyard = obtainProfile(ServerURL() + SHIPYARD_URL, out DateTime shipyardTimestamp);
         shipyard = "{\"lastStarport\":" + shipyard + "}";
         JObject shipyardJson = JObject.Parse(shipyard);
         lastStation.ships             = ShipyardFromProfile(shipyardJson);
         lastStation.shipyardupdatedat = Dates.fromDateTimeToSeconds(shipyardTimestamp);
     }
     return(lastStation);
 }
        public static ProfileStation ProfileStation(DateTime marketTimestamp, JObject marketJson)
        {
            ProfileStation lastStation = null;

            try
            {
                string lastStarport = (string)marketJson["lastStarport"]["name"];
                long?  marketId     = (long?)marketJson["lastStarport"]["id"];
                lastStation = new ProfileStation
                {
                    name                      = lastStarport,
                    marketId                  = marketId,
                    economyShares             = EconomiesFromProfile(marketJson),
                    eddnCommodityMarketQuotes = CommodityQuotesFromProfile(marketJson),
                    prohibitedCommodities     = ProhibitedCommoditiesFromProfile(marketJson),
                    commoditiesupdatedat      = Dates.fromDateTimeToSeconds(marketTimestamp),
                    json                      = marketJson
                };

                List <KeyValuePair <string, string> > stationServices = new List <KeyValuePair <string, string> >();
                foreach (var jToken in marketJson["lastStarport"]["services"])
                {
                    // These are key value pairs. The Key is the name of the service, the Value is its state.
                    var serviceJSON = (JProperty)jToken;
                    var service     = new KeyValuePair <string, string>(serviceJSON.Name, serviceJSON.Value.ToString());
                    stationServices.Add(service);
                }
                lastStation.stationServices = stationServices;
            }
            catch (JsonException ex)
            {
                Logging.Error("Failed to parse companion station data", ex);
            }
            Logging.Debug("Station is " + JsonConvert.SerializeObject(lastStation));
            return(lastStation);
        }