Skip to content

Commit

Permalink
0.8.1841.34656
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Oct 12, 2018
1 parent 8c22503 commit cb7faee
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 65 deletions.
1 change: 1 addition & 0 deletions AcManager.Controls/WeatherComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}

private async Task UpdateHierarchicalWeatherList() {
if (!_loaded) return;
await WeatherManager.Instance.EnsureLoadedAsync();

HierarchicalGroup list;
Expand Down
2 changes: 1 addition & 1 deletion AcManager.Tools/AcManager.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@
<Compile Include="Helpers\WeatherProvider.cs" />
<Compile Include="Helpers\TimezoneDeterminer.cs" />
<Compile Include="Helpers\TracksLocator.cs" />
<Compile Include="Helpers\Api\GoogleApiProvider.cs" />
<Compile Include="Helpers\Api\TimezoneDbApiProvider.cs" />
<Compile Include="Helpers\Api\YahooApiProvider.cs" />
<Compile Include="Lists\AcEnabledOnlyCollection.cs" />
<Compile Include="Lists\AcWrapperCollectionView.cs" />
Expand Down
31 changes: 22 additions & 9 deletions AcManager.Tools/Data/WeatherTypeWrapped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,50 @@
using JetBrains.Annotations;

namespace AcManager.Tools.Data {
public sealed class WeatherTypeWrapped : Displayable {
public sealed class WeatherTypeWrapped : Displayable, IEquatable<WeatherTypeWrapped> {
public WeatherType Type { get; }

public WeatherTypeWrapped(WeatherType type) {
Type = type;
DisplayName = type.GetDescription();
}

private bool Equals(WeatherTypeWrapped other) {
return Type == other.Type;
public bool Equals(WeatherTypeWrapped other) {
return Type == other?.Type;
}

public override bool Equals(object obj) {
return !ReferenceEquals(null, obj) && (ReferenceEquals(this, obj) || obj is WeatherTypeWrapped w && Equals(w));
return obj is WeatherTypeWrapped w && w.Type == Type;
}

public override int GetHashCode() {
return (int)Type;
}

public static bool operator ==(WeatherTypeWrapped lhs, WeatherTypeWrapped rhs)
{
return lhs?.Type == rhs?.Type;
}

public static bool operator !=(WeatherTypeWrapped lhs, WeatherTypeWrapped rhs)
{
return !(lhs == rhs);
}

public override string ToString() {
return $@"W. TYPE: {Type}";
return $@"WeatherTypeWrapper({Type})";
}

public static readonly Displayable RandomWeather = new Displayable { DisplayName = ToolsStrings.Weather_Random };

[CanBeNull]
public static WeatherObject Unwrap(object obj, int? time, double? temperature) {
return obj is WeatherTypeWrapped weatherTypeWrapped
? WeatherManager.Instance.Enabled.Where(x => x.Fits(weatherTypeWrapped.Type, time, temperature)).RandomElementOrDefault()
: obj as WeatherObject;
if (obj is WeatherTypeWrapped weatherTypeWrapped) {
WeatherManager.Instance.EnsureLoaded();
return WeatherManager.Instance.Enabled.Where(x => x.Fits(weatherTypeWrapped.Type, time, temperature)).RandomElementOrDefault();
}

return obj as WeatherObject;
}

[CanBeNull]
Expand All @@ -51,7 +64,7 @@ public static object Deserialize([CanBeNull] string serialized) {
if (serialized == null) {
return RandomWeather;
}

if (serialized.StartsWith(@"*")) {
try {
return new WeatherTypeWrapped((WeatherType)(FlexibleParser.TryParseInt(serialized.Substring(1)) ?? 0));
Expand Down
2 changes: 2 additions & 0 deletions AcManager.Tools/Helpers/Api/KunosApiProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ public static async Task<BookingResult> TryToBookAsync(string ip, int portC, str
var requestUri = $@"http://{ip}:{portC}/SUB|{HttpUtility.UrlPathEncode(arguments)}";

try {
Logging.Debug("Request: " + requestUri);
var response = await LoadAsync(requestUri, OptionDirectRequestTimeout);
Logging.Debug("Response: " + response);
var split = response.Split(',');
switch (split[0]) {
case "OK":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Linq;
using AcManager.Internal;
using AcTools.Utils.Helpers;
using FirstFloor.ModernUI.Helpers;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
using TimeZoneConverter;

namespace AcManager.Tools.Helpers.Api {
public class GoogleApiProvider {
private const string RequestTimeZoneUri = "https://maps.googleapis.com/maps/api/timezone/xml?location={0},{1}&timestamp={2}&key={3}";
public class TimezoneDbApiProvider {
// private const string RequestTimeZoneUri = "https://maps.googleapis.com/maps/api/timezone/xml?location={0},{1}&timestamp={2}&key={3}";
private const string RequestTimeZoneUri = "https://api.timezonedb.com/v2.1/get-time-zone?key={2}&format=json&by=position&lat={0}&lng={1}";

[ItemNotNull]
public static async Task<TimeZoneInfo> DetermineTimeZoneAsync(GeoTagsEntry geoTags) {
var requestUri = string.Format(RequestTimeZoneUri, geoTags.LatitudeValue, geoTags.LongitudeValue,
InternalUtils.GetTimeZoneDbApiCode());

using (var order = KillerOrder.Create(new WebClient(), 5000)) {
var data = await order.Victim.DownloadStringTaskAsync(requestUri);

var doc = JObject.Parse(data);
var zoneId = doc.GetStringValueOnly("zoneName");
if (zoneId == null) throw new Exception("Invalid response");

Logging.Write("Returned zone ID: " + zoneId);

try {
Logging.Write("Parsed as: " + TZConvert.GetTimeZoneInfo(zoneId).ToSerializedString());
return TZConvert.GetTimeZoneInfo(zoneId);
} catch (TimeZoneNotFoundException) {
var rawOffset = doc.GetStringValueOnly(@"gmtOffset");
return TimeZoneInfo.CreateCustomTimeZone(zoneId, TimeSpan.FromSeconds(FlexibleParser.ParseDouble(rawOffset)), zoneId, zoneId);
}
}

/*var requestUri = string.Format(RequestTimeZoneUri, geoTags.LatitudeValue, geoTags.LongitudeValue,
DateTime.Now.ToUnixTimestamp(), InternalUtils.GetGoogleMapsApiCode());
using (var order = KillerOrder.Create(new WebClient(), 5000)) {
Expand All @@ -28,12 +49,11 @@ public static async Task<TimeZoneInfo> DetermineTimeZoneAsync(GeoTagsEntry geoTa
return TZConvert.GetTimeZoneInfo(zoneId);
} catch (TimeZoneNotFoundException) {
var rawOffset = doc.Descendants(@"raw_offset").FirstOrDefault()?.Value;
var dstOffset = doc.Descendants(@"dst_offset").FirstOrDefault()?.Value ?? @"0";
var zoneName = doc.Descendants(@"time_zone_name").FirstOrDefault()?.Value;
if (rawOffset == null || zoneName == null) throw new Exception("Invalid response");
return TimeZoneInfo.CreateCustomTimeZone(zoneId, TimeSpan.FromSeconds(FlexibleParser.ParseDouble(rawOffset)), zoneName, zoneName);
}
}
}*/
}
}
}
2 changes: 1 addition & 1 deletion AcManager.Tools/Helpers/TimezoneDeterminer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static async Task<TimeZoneInfo> TryToDetermineAsync(GeoTagsEntry geoTags)
}

try {
var result = await GoogleApiProvider.DetermineTimeZoneAsync(geoTags);
var result = await TimezoneDbApiProvider.DetermineTimeZoneAsync(geoTags);
CacheStorage.Set(key, result);
return result;
} catch (WebException e) {
Expand Down
4 changes: 2 additions & 2 deletions AcManager.Tools/Helpers/TracksLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public static async Task<GeoTagsEntry> TryToLocateAsync([CanBeNull] string addre
CacheStorage.Set(key, "");
return null;
} catch (WebException e) {
Logging.Warning("TryToLocateAsync(): " + e.Message);
Logging.Warning(e.Message);
return null;
} catch (Exception e) {
Logging.Warning("TryToLocateAsync(): " + e);
Logging.Warning(e);
CacheStorage.Set(key, "");
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion AcManager.Tools/Managers/Online/ServerEntry.Join.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private async Task Join(object o) {
return;
}

if (!IsBookedForPlayer && BookingMode && !ReferenceEquals(o, ActualJoin) && !ReferenceEquals(o, ForceJoin)) {
if (BookingMode && !ReferenceEquals(o, ActualJoin) && !ReferenceEquals(o, ForceJoin)) {
if (_factory == null) {
Logging.Error("Booking: UI factory is missing");
return;
Expand Down
9 changes: 5 additions & 4 deletions AcManager.Tools/Objects/TrackObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ private string GetSpecsLengthDisplay() {
return SpecsLength;
}

return D((value / 1000).Round(0.1) * SettingsHolder.CommonSettings.DistanceMultiplier + SettingsHolder.CommonSettings.SpaceDistancePostfix, SpecsLength);
return D((value * SettingsHolder.CommonSettings.DistanceMultiplier / 1000).Round(0.1) + SettingsHolder.CommonSettings.SpaceDistancePostfix,
SpecsLength);
}

private static readonly Regex SpecsWidthFix = new Regex(@"^(.+?)\s*[-–—]\s*(.+)$",
Expand All @@ -302,7 +303,7 @@ private string GetSpecsLengthDisplay() {
private string GetSpecsWidthDisplayPart(string original) {
var value = GetSpecsLengthValue(original, false);
if (!value.HasValue) return original;
return value.Value.Round(0.1) * SettingsHolder.CommonSettings.ShortDistanceMultiplier + SettingsHolder.CommonSettings.SpaceShortDistancePostfix;
return (value.Value * SettingsHolder.CommonSettings.ShortDistanceMultiplier ).Round(0.1)+ SettingsHolder.CommonSettings.SpaceShortDistancePostfix;
}

[CanBeNull]
Expand All @@ -321,7 +322,7 @@ private string GetSpecsWidthDisplay() {
}

if (double.TryParse(original, NumberStyles.Float | NumberStyles.Integer, CultureInfo.InvariantCulture, out var value)) {
return value * SettingsHolder.CommonSettings.ShortDistanceMultiplier + SettingsHolder.CommonSettings.SpaceShortDistancePostfix;
return (value * SettingsHolder.CommonSettings.ShortDistanceMultiplier).Round(0.1) + SettingsHolder.CommonSettings.SpaceShortDistancePostfix;
}

return original;
Expand Down Expand Up @@ -468,4 +469,4 @@ protected override AcCommonObjectPacker CreatePacker() {
throw new InformativeException("Can’t pack track", "At the moment, tracks packing is not implemented.");
}
}
}
}
4 changes: 3 additions & 1 deletion AcManager.Tools/Objects/UserChampionshipRoundExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ public UserChampionshipRoundExtended(TrackObjectBase track) {
}

[JsonConstructor]
public UserChampionshipRoundExtended([CanBeNull] string track, [CanBeNull] string weather, int surface) {
public UserChampionshipRoundExtended([CanBeNull] string track, [CanBeNull] string weather, int surface, int time, double temperature) {
if (track == null) {
Logging.Warning("Track=null!");
}

Time = time;
Temperature = temperature;
TrackId = track ?? TracksManager.Instance.GetDefault()?.IdWithLayout ?? @"imola";
Track = TracksManager.Instance.GetLayoutById(TrackId);
Weather = WeatherTypeWrapped.Deserialize(weather);
Expand Down
5 changes: 4 additions & 1 deletion AcManager/Pages/Dialogs/GameDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public GameDialog() {
_cancellationSource = new CancellationTokenSource();
CancellationToken = _cancellationSource.Token;

ProgressRing.Style = ExtraProgressRings.Styles.GetValueOrDefault(_progressStyles.Next);
if (!AppAppearanceManager.Instance.SoftwareRenderingMode) {
ProgressRing.Style = ExtraProgressRings.Styles.GetValueOrDefault(_progressStyles.Next);
}

Buttons = new[] { CancelButton };
}

Expand Down
6 changes: 3 additions & 3 deletions AcManager/Pages/Dialogs/TrackGeoTagsDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public ViewModel(TrackObjectBase track) {
Track = track;

if (track.GeoTags != null) {
Latitude = track.GeoTags.Latitude;
Longitude = track.GeoTags.Longitude;
Latitude = track.GeoTags.DisplayLatitude.Replace(@"lat", "");
Longitude = track.GeoTags.DisplayLongitude.Replace(@"lon", "");
} else {
Latitude = null;
Longitude = null;
Expand All @@ -118,7 +118,7 @@ private static string GetQuery(TrackObjectBase track) {

private static string GetMapAddress(TrackObjectBase track) {
var tags = track.GeoTags;
return CmHelpersProvider.GetAddress("map") + @"?t#" +
return CmHelpersProvider.GetAddress("map") + @"?ms#" +
(tags?.IsEmptyOrInvalid == false ? $"{tags.LatitudeValue};{tags.LongitudeValue}" : GetQuery(track));
}
}
Expand Down
14 changes: 9 additions & 5 deletions AcManager/Pages/Selected/SelectedTrackPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@

<mui:BbCodeBlock c:PropertiesGrid.Label="{x:Static c:ControlsStrings.AcObject_TrackGeoTagsLabel}"
Text="{Binding SelectedTrackConfiguration.GeoTags, TargetNullValue=''}" Placeholder="{x:Static t:ToolsStrings.Common_None}"
MouseDown="OnGeoTagsClick" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" />
MouseDown="OnGeoTagsClick" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis">
<mui:BbCodeBlock.ToolTip>
<TextBlock Text="{Binding SelectedTrackConfiguration.GeoTags.OriginalString, StringFormat='{}Original values: {0}'}" />
</mui:BbCodeBlock.ToolTip>
</mui:BbCodeBlock>

<Border c:PropertiesGrid.Label="{x:Static c:ControlsStrings.AcObject_YearLabel}"
ToolTip="{x:Static c:ControlsStrings.AcObject_YearLabel_CarTooltip}" mui:ContextMenuAdvancement.PropagateToChildren="True">
Expand Down Expand Up @@ -193,7 +197,7 @@
</c:PropertiesGrid>

<c:PropertiesGrid Columns="1" LabelPadding="0 1 0 0">
<!--length-->
<!-- Length -->
<Border c:PropertiesGrid.Label="Length:" mui:ContextMenuAdvancement.PropagateToChildren="True">
<FrameworkElement.ToolTip>
<ToolTip Content="{x:Static g:AppStrings.TrackSpecs_Length_FormatTooltip}"
Expand All @@ -217,7 +221,7 @@
Placeholder="{x:Static g:AppStrings.TrackSpecs_Length_FormatTooltip}" />
</Border>

<!--width-->
<!-- Width -->
<Border c:PropertiesGrid.Label="Width:" mui:ContextMenuAdvancement.PropagateToChildren="True">
<FrameworkElement.ToolTip>
<ToolTip Content="{x:Static g:AppStrings.TrackSpecs_Width_FormatTooltip}"
Expand All @@ -239,7 +243,7 @@
Placeholder="{x:Static g:AppStrings.TrackSpecs_Width_FormatTooltip}" />
</Border>

<!--pits-->
<!-- Pits -->
<Border c:PropertiesGrid.Label="Pits:" mui:ContextMenuAdvancement.PropagateToChildren="True">
<FrameworkElement.ToolTip>
<ToolTip Content="{x:Static g:AppStrings.TrackSpecs_Pitboxes_FormatTooltip}"
Expand All @@ -262,7 +266,7 @@
</Border>
</c:PropertiesGrid>

<!-- description -->
<!-- Description -->
<mui:BetterTextBox Style="{StaticResource Borderless}" Text="{Binding SelectedObject.Description}" AcceptsReturn="True" TextWrapping="Wrap"
Placeholder="None" />
</mui:SpacingStackPanel>
Expand Down
4 changes: 2 additions & 2 deletions AcManager/Pages/Selected/SelectedUserChampionship.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
</ComboBox.ItemContainerStyle>
</ComboBox>-->

<c:WeatherComboBox SelectedItem="{Binding Weather}" AllowRandomWeather="True" AllowWeatherByType="True"
c:ToolTips.Weather="{Binding WeatherObject}" />
<c:WeatherComboBox AllowRandomWeather="True" AllowWeatherByType="True" SelectedItem="{Binding Weather}"
c:ToolTips.Weather="{Binding WeatherObject, Mode=OneWay}" />
</mui:SpacingStackPanel>

<mui:SpacingStackPanel Spacing="4">
Expand Down
2 changes: 1 addition & 1 deletion AcTools/Utils/Helpers/Diapason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected override Diapason<int> CreateNew(List<Piece> pieces) {

protected override void GetDefaultLimits(out int minimum, out int maximum) {
minimum = 0;
maximum = 24 * 60 * 60 - 1;
maximum = 24 * 60 * 60 - 60;
}

protected override bool TryParse(string value, out int parsed) {
Expand Down
Loading

0 comments on commit cb7faee

Please sign in to comment.