예제 #1
0
 public static void DebugException(this IMvxLog logger, string message, Exception exception, params object[] formatParams)
 {
     if (logger.IsDebugEnabled())
     {
         logger.Log(MvxLogLevel.Debug, message.AsFunc(), exception, formatParams);
     }
 }
예제 #2
0
 public static void Debug(this IMvxLog logger, string message)
 {
     if (logger.IsDebugEnabled())
     {
         logger.Log(MvxLogLevel.Debug, message.AsFunc());
     }
 }
예제 #3
0
 public static void DebugException(this IMvxLog logger, string message, Exception exception)
 {
     if (logger.IsDebugEnabled())
     {
         logger.Log(MvxLogLevel.Debug, message.AsFunc(), exception);
     }
 }
예제 #4
0
 public static void Warn(this IMvxLog logger, string message)
 {
     if (logger.IsWarnEnabled())
     {
         logger.Log(MvxLogLevel.Warn, message.AsFunc());
     }
 }
예제 #5
0
 public static void Info(this IMvxLog logger, string message)
 {
     if (logger.IsInfoEnabled())
     {
         logger.Log(MvxLogLevel.Info, message.AsFunc());
     }
 }
예제 #6
0
 public static void Trace(this IMvxLog logger, string message)
 {
     if (logger.IsTraceEnabled())
     {
         logger.Log(MvxLogLevel.Trace, message.AsFunc());
     }
 }
예제 #7
0
 public static void Error(this IMvxLog logger, string message)
 {
     if (logger.IsErrorEnabled())
     {
         logger.Log(MvxLogLevel.Error, message.AsFunc());
     }
 }
예제 #8
0
 public static void Fatal(this IMvxLog logger, string message)
 {
     if (logger.IsFatalEnabled())
     {
         logger.Log(MvxLogLevel.Fatal, message.AsFunc());
     }
 }
예제 #9
0
        public async Task <bool> PurchaseAsync(Rate rate)
        {
            try
            {
                var productId = rate.Id.ToString();

                var connected = await CrossInAppBilling.Current.ConnectAsync();

                if (!connected)
                {
                    // Не удалось подключиться к биллингу, устройство в автономном режиме, оповещаем пользователя
                    return(false);
                }

                // Пробуем купить товар
                var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase, "apppayload");

                if (purchase == null)
                {
                    // Купить не удалось, оповещаем пользователя

                    return(false);
                }
                else
                {
                    // Покупка совершена, сохраняем информацию
                    var id    = purchase.Id;
                    var token = purchase.PurchaseToken;
                    var state = purchase.State;

                    // Вызываем после успешной покупки или позднее (необходимо вызвать ConnectAsync() раньше времени):
                    if (Device.RuntimePlatform == Device.Android)
                    {
                        var consumedItem = await CrossInAppBilling.Current.ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);

                        if (consumedItem != null)
                        {
                            // Товар использован
                        }
                    }
                    else
                    {
                        //
                    }
                }
            }
            catch (Exception ex)
            {
                // Произошла ошибка, оповещаем пользователя.
                _logger.Log(MvxLogLevel.Debug, () => "Purchase Error", ex);
                return(false);
            }
            finally
            {
                // Отключаемся, это нормально если не удалось связаться.
                await CrossInAppBilling.Current.DisconnectAsync();
            }

            return(true);
        }
        public async Task <string> GetLocationCityNameAsync()
        {
            try
            {
                var location = await geolocation.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.Lowest, timeout));

                var place = (await geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude))?.First();
                return(place.Locality);
            }
            catch (Exception ex)
            {
                logger.Log(MvxLogLevel.Warn, () => ex.Message, ex);
                throw new LocationException(AppResources.CanNotGetCityName, ex);
            }
        }
 public async Task <CurrentWeatherResponse> GetWeatherAsync(string cityName)
 {
     try
     {
         return(await apiClient.GetWeatherByCityNameAsync(cityName));
     }
     catch (Exception ex) when(ex is AggregateException ||
                               ex is ArgumentException ||
                               ex is OpenWeatherMapException)
     {
         throw new WeatherException(AppResources.CityNameIsIncorrect, ex);
     }
     catch (Exception ex)
     {
         logger.Log(MvxLogLevel.Error, () => ex.Message, ex);
         throw new WeatherException(AppResources.SomethingIsWrong, ex);
     }
 }
예제 #12
0
 public static void Error(this IMvxLog logger, Func <string> messageFunc)
 {
     GuardAgainstNullLogger(logger);
     logger.Log(MvxLogLevel.Error, messageFunc);
 }
예제 #13
0
 private static void LogFormat(this IMvxLog logger, MvxLogLevel logLevel, string message, params object[] args)
 {
     logger.Log(logLevel, message.AsFunc(), null, args);
 }
예제 #14
0
 public static void Fatal(this IMvxLog logger, Func <string> messageFunc)
 {
     logger.Log(MvxLogLevel.Fatal, messageFunc);
 }
예제 #15
0
 public static bool IsDebugEnabled(this IMvxLog logger)
 {
     GuardAgainstNullLogger(logger);
     return(logger.Log(MvxLogLevel.Debug, null));
 }