Ejemplo n.º 1
0
        /// <summary>
        /// Gives the Forecast Service-friendly name for
        /// this parameter.
        /// </summary>
        /// <param name="self">
        /// The parameter to convert.
        /// </param>
        /// <returns>
        /// The service-friendly <see cref="string"/>.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown when the parameter does not have a corresponding
        /// friendly name.
        /// </exception>
        public static string ToValue(this DSUnit self)
        {
            switch (self)
            {
            case DSUnit.US:
                return("us");

            case DSUnit.SI:
                return("si");

            case DSUnit.CA:
                return("ca");

            case DSUnit.UK:
                return("uk");

            case DSUnit.UK2:
                return("uk2");

            case DSUnit.Auto:
                return("auto");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     The most general method to retrieve the observed (in the past) or forecasted (in the future) hour-by-hour weather and daily weather
        ///     conditions for a particular date. A Time Machine request is identical in structure to a Forecast Request, except:
        ///     * The 'currently' data point will refer to the time provided, rather than the current time.
        ///     * The 'minutely' data block will be omitted, unless you are requesting a time within an hour of the present.
        ///     * The 'hourly data block will contain data points starting at midnight (local time) of the day requested, and continuing
        ///       until midnight (local time) of the following day.
        ///     * The 'daily' data block will contain a single data point referring to the requested date.
        ///     * The 'alerts' data block will be omitted.
        /// </summary>
        /// <param name="latitude">The latitude to retrieve data for.</param>
        /// <param name="longitude">The longitude to retrieve data for.</param>
        /// <param name="date">Requested date</param>
        /// <param name="excludes">Any blocks that should be excluded from the request.</param>
        /// <param name="extends">The type of forecast to retrieve extended results for. Currently limited to hourly blocks.</param>
        /// <param name="unit">Default <see cref="DSUnit.Auto"/></param>
        /// <param name="language">Default <see cref="Language.English"/></param>
        /// <returns>A <see cref="Task"/> for a <see cref="Forecast"/> with the requested data, or null if the data was corrupted.</returns>
        /// <exception cref="System.Net.Http.HttpRequestException">Thrown when the service returned anything other than a 200 (Status OK) code.</exception>
        public Task <Forecast> GetWeatherByDate(
            double latitude,
            double longitude,
            DateTimeOffset date,
            IList <Extend> extends,
            IList <Exclude> excludes,
            DSUnit unit       = DSUnit.Auto,
            Language language = Language.English)
        {
            ThrowExceptionIfApiKeyInvalid();

            var unitValue     = unit.ToValue();
            var extendList    = (extends != null) ? string.Join(",", extends.Select(x => x.ToValue())) : string.Empty;
            var excludeList   = (excludes != null) ? string.Join(",", excludes.Select(x => x.ToValue())) : string.Empty;
            var languageValue = language.ToValue();
            var unixTime      = date.ToUnixTime();

            var requestUrl = string.Format(
                CultureInfo.InvariantCulture,
                SpecificTimeConditionsUrl,
                _apiKey,
                latitude,
                longitude,
                unixTime,
                unitValue,
                extendList,
                excludeList,
                languageValue);

            return(GetForecastFromUrlAsync(requestUrl));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///    Returns the current weather conditions, included an hour-by-hour forecast for the next 48 hours and possible alerts
 /// </summary>
 /// <param name="latitude">The latitude to retrieve data for.</param>
 /// <param name="longitude">The longitude to retrieve data for.</param>
 /// <param name="unit">Default is <see cref="DSUnit.Auto"/></param>
 /// <param name="language">Default is <see cref="Language.English"/></param>
 /// <returns>A <see cref="Forecast"/> with the requested data, or null if the data was corrupted.</returns>
 /// <exception cref="System.Net.Http.HttpRequestException">Thrown when the service returned anything other than a 200 (Status OK) code.</exception>
 public Task <Forecast> GetCurrentWeather(
     double latitude,
     double longitude,
     DSUnit unit       = DSUnit.Auto,
     Language language = Language.English)
 {
     return(GetWeather(latitude, longitude,
                       new Extend[0],
                       new Exclude[] { /*Exclude.Daily, */ Exclude.Minutely }, // I don't exclude the daily as Daily[0] has additional info on the current day
                       unit, language));
 }
Ejemplo n.º 4
0
 /// <summary>
 ///    Returns the current weather conditions, included an hour-by-hour forecast for the next 48 hours, the daily forecast for the next 7 days and possible alerts
 /// </summary>
 /// <param name="latitude">The latitude to retrieve data for.</param>
 /// <param name="longitude">The longitude to retrieve data for.</param>
 /// <param name="unit">Default is <see cref="DSUnit.Auto"/></param>
 /// <param name="language">Default is <see cref="Language.English"/></param>
 /// <returns>A <see cref="Forecast"/> with the requested data, or null if the data was corrupted.</returns>
 /// <exception cref="System.Net.Http.HttpRequestException">Thrown when the service returned anything other than a 200 (Status OK) code.</exception>
 public Task <Forecast> GetForecast(
     double latitude,
     double longitude,
     DSUnit unit       = DSUnit.Auto,
     Language language = Language.English)
 {
     return(GetWeather(latitude, longitude,
                       new Extend[0],
                       new Exclude[] { Exclude.Minutely },
                       unit, language));
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Retrieve the observed (in the past) or forecasted (in the future) hour-by-hour weather and daily weather
 ///     conditions for a particular date. A Time Machine request is identical in structure to a Forecast Request, except:
 ///     * The 'currently' data point will refer to the time provided, rather than the current time.
 ///     * The 'minutely' data block will be omitted, unless you are requesting a time within an hour of the present.
 ///     * The 'hourly data block will contain data points starting at midnight (local time) of the day requested, and continuing
 ///       until midnight (local time) of the following day.
 ///     * The 'daily' data block will contain a single data point referring to the requested date.
 ///     * The 'alerts' data block will be omitted.
 /// </summary>
 /// <param name="latitude">The latitude to retrieve data for.</param>
 /// <param name="longitude">The longitude to retrieve data for.</param>
 /// <param name="date">Requested date</param>
 /// <param name="unit">Default <see cref="DSUnit.Auto"/></param>
 /// <param name="language">Default <see cref="Language.English"/></param>
 /// <returns>A <see cref="Task"/> for a <see cref="Forecast"/> with the requested data, or null if the data was corrupted.</returns>
 /// <exception cref="System.Net.Http.HttpRequestException">Thrown when the service returned anything other than a 200 (Status OK) code.</exception>
 public Task <Forecast> GetWeatherByDate(
     double latitude,
     double longitude,
     DateTimeOffset date,
     DSUnit unit       = DSUnit.Auto,
     Language language = Language.English)
 {
     return
         (GetWeatherByDate(
              latitude,
              longitude,
              date,
              null,
              null,
              unit,
              language));
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Retrieve the observed (in the past) or forecasted (in the future) hour-by-hour weather and daily weather
 ///     conditions for a particular date. A Time Machine request is identical in structure to a Forecast Request, except:
 ///     * The 'currently' data point will refer to the time provided, rather than the current time.
 ///     * The 'minutely' data block will be omitted, unless you are requesting a time within an hour of the present.
 ///     * The 'hourly data block will contain data points starting at midnight (local time) of the day requested, and continuing
 ///       until midnight (local time) of the following day.
 ///     * The 'daily' data block will contain a single data point referring to the requested date.
 ///     * The 'alerts' data block will be omitted.
 /// </summary>
 /// <param name="latitude">The latitude to retrieve data for.</param>
 /// <param name="longitude">The longitude to retrieve data for.</param>
 /// <param name="date">Requested date</param>
 /// <param name="excludes">Any blocks that should be excluded from the request.</param>
 /// <param name="unit">Default <see cref="DSUnit.Auto"/></param>
 /// <param name="language">Default <see cref="Language.English"/></param>
 /// <returns>A <see cref="Task"/> for a <see cref="Forecast"/> with the requested data, or null if the data was corrupted.</returns>
 public Task <Forecast> GetWeatherByDate(
     double latitude,
     double longitude,
     DateTime date,
     IList <Exclude> excludes,
     DSUnit unit       = DSUnit.Auto,
     Language language = Language.English)
 {
     return
         (GetWeatherByDate(
              latitude,
              longitude,
              date,
              null,
              excludes,
              unit,
              language));
 }
Ejemplo n.º 7
0
        public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring)
        {
            DbBreakpoint Bp = new DbBreakpoint();

            Bp.Player = pl;
            Bp.Gas    = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count();
            Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15);
            DbStats statlast = null;

            foreach (DbStats stat in pl.Stats)
            {
                if (stat.Gameloop > bp)
                {
                    break;
                }
                statlast = stat;
            }
            if (statlast != null)
            {
                Bp.Army     = statlast.Army;
                Bp.Kills    = statlast.MineralsKilledArmy;
                Bp.Upgrades = statlast.MineralsUsedCurrentTechnology;
            }

            List <DbUnit> dbUnits = null;

            foreach (var ent in pl.Spawns)
            {
                if (ent.Gameloop > bp)
                {
                    break;
                }
                dbUnits = ent.Units.ToList();
            }
            Bp.Units   = new List <DSUnit>();
            Bp.DbUnits = new List <DbUnit>();
            if (dbUnits != null)
            {
                foreach (DbUnit unit in dbUnits)
                {
                    DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name);
                    if (dsUnit == null)
                    {
                        DSUnit newdsUnit = new DSUnit();
                        newdsUnit.Name       = unit.Name;
                        newdsUnit.BP         = bpstring;
                        newdsUnit.Breakpoint = Bp;
                        newdsUnit.Count      = 1;
                        newdsUnit.DSPlayer   = pl;
                        Bp.Units.Add(newdsUnit);
                    }
                    else
                    {
                        dsUnit.Count++;
                    }
                    unit.Breakpoint = Bp;
                    Bp.DbUnits.Add(unit);
                }
            }

            Bp.DbUpgrades = new List <DbUpgrade>();
            foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp))
            {
                upgrade.Breakpoint = Bp;
                Bp.DbUpgrades.Add(upgrade);
            }

            string dsUnitsString    = "";
            string dbUnitsString    = "";
            string dbUpgradesString = "";

            foreach (DSUnit unit in Bp.Units)
            {
                string        name  = unit.Name;
                UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name);
                if (bunit != null)
                {
                    name = bunit.ID.ToString();
                }
                dsUnitsString += name + "," + unit.Count + "|";
            }
            if (dsUnitsString.Any())
            {
                dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1);
            }

            foreach (DbUnit unit in Bp.DbUnits)
            {
                string        name  = unit.Name;
                UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name);
                if (bunit != null)
                {
                    name = bunit.ID.ToString();
                }
                dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|";
            }
            if (dbUnitsString.Any())
            {
                dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1);
            }


            foreach (DbUpgrade upgrade in Bp.DbUpgrades)
            {
                dbUpgradesString += upgrade.Upgrade + "|";
            }
            if (dbUpgradesString.Any())
            {
                dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1);
            }

            Bp.dsUnitsString    = dsUnitsString;
            Bp.dbUnitsString    = dbUnitsString;
            Bp.dbUpgradesString = dbUpgradesString;

            return(Bp);
        }
Ejemplo n.º 8
0
        public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring)
        {
            DbBreakpoint Bp = new DbBreakpoint();

            Bp.Player = pl;
            Bp.Gas    = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count();
            Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15);
            DbStats statlast = pl.Stats.Where(x => x.Gameloop <= bp).LastOrDefault();

            if (statlast != null)
            {
                Bp.Army     = statlast.Army;
                Bp.Kills    = statlast.MineralsKilledArmy;
                Bp.Upgrades = statlast.MineralsUsedCurrentTechnology;
            }

            List <DbUnit> dbUnits   = null;
            var           spawnlast = pl.Spawns.Where(x => x.Gameloop <= bp).LastOrDefault();

            if (spawnlast != null)
            {
                dbUnits = spawnlast.Units.ToList();
            }

            Bp.Units   = new List <DSUnit>();
            Bp.DbUnits = new List <DbUnit>();
            if (dbUnits != null)
            {
                foreach (DbUnit unit in dbUnits)
                {
                    DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name);
                    if (dsUnit == null)
                    {
                        Bp.Units.Add(new DSUnit()
                        {
                            Name       = unit.Name,
                            BP         = bpstring,
                            Breakpoint = Bp,
                            Count      = 1,
                            DSPlayer   = pl
                        });
                    }
                    else
                    {
                        dsUnit.Count++;
                    }
                    unit.Breakpoint = Bp;
                    Bp.DbUnits.Add(unit);
                }
            }

            Bp.DbUpgrades = new List <DbUpgrade>();
            foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp))
            {
                upgrade.Breakpoint = Bp;
                Bp.DbUpgrades.Add(upgrade);
            }

            string dsUnitsString    = "";
            string dbUnitsString    = "";
            string dbUpgradesString = "";

            foreach (DSUnit unit in Bp.Units)
            {
                string name = unit.Name;
                int    id   = NameService.GetUnitId(null, unit.Name);
                if (id >= 0)
                {
                    name = id.ToString();
                }
                dsUnitsString += name + "," + unit.Count + "|";
            }
            if (dsUnitsString.Any())
            {
                dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1);
            }

            foreach (DbUnit unit in Bp.DbUnits)
            {
                string name = unit.Name;
                int    id   = NameService.GetUnitId(null, unit.Name);
                if (id >= 0)
                {
                    name = id.ToString();
                }
                dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|";
            }
            if (dbUnitsString.Any())
            {
                dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1);
            }


            foreach (DbUpgrade upgrade in Bp.DbUpgrades)
            {
                dbUpgradesString += upgrade.Upgrade + "|";
            }
            if (dbUpgradesString.Any())
            {
                dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1);
            }

            Bp.dsUnitsString    = dsUnitsString;
            Bp.dbUnitsString    = dbUnitsString;
            Bp.dbUpgradesString = dbUpgradesString;

            return(Bp);
        }