Ejemplo n.º 1
0
        public void Error(Exception e, [CallerMemberName] string memberName = "",
                          [CallerFilePath] string sourceFilePath            = "",
                          [CallerLineNumber] int sourceLineNumber           = 0)
        {
            if (string.IsNullOrEmpty(e.Message))
            {
                return;
            }

            AndroidLog.Error(_target, "member name: " + memberName);
            AndroidLog.Error(_target, "source file path: " + sourceFilePath);
            AndroidLog.Error(_target, "source line number: " + sourceLineNumber);
            AndroidLog.Error(_target, e.Message);

            if (!string.IsNullOrEmpty(e.StackTrace))
            {
                AndroidLog.Error(_target, e.StackTrace);
            }

            CrashlyticsLog(e);
            Writer.Write(e);

            if (_xamarinInsights)
            {
                Dictionary <string, string> additionalInfo = new Dictionary <string, string>
                {
                    { "Member Name", memberName },
                    { "Source Filepath", sourceFilePath },
                    { "Source Line Number", sourceLineNumber.ToString() },
                    { "CallStack", _traceEventCache.Callstack }
                };

                Insights.Report(e, additionalInfo);
            }
        }
Ejemplo n.º 2
0
        public async Task SendMessageAsync(string data)
        {
            if (!Connected)
            {
                return;
            }

            try
            {
                _outStream = _btSocket.OutputStream;
            }
            catch (Exception ex)
            {
                Log.Error(_tag, $"Cannot get OutputStream from BT device: {ex.Message}, {ex.StackTrace}.");
            }

            byte[] buffer = Encoding.UTF8.GetBytes(data);

            try
            {
                await _outStream.WriteAsync(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                Log.Error(_tag, $"Cannot write data to BT device: {ex.Message}, {ex.StackTrace}.");
            }
        }
Ejemplo n.º 3
0
 public static void e(string tag, string msg)
 {
     if (LOG_ENABLE)
     {
         Log.Error(tag, msg);
     }
 }
Ejemplo n.º 4
0
        public void Error(string e, [CallerMemberName] string memberName = "",
                          [CallerFilePath] string sourceFilePath         = "",
                          [CallerLineNumber] int sourceLineNumber        = 0)
        {
            if (e == null)
            {
                e = _defaultLogString;
            }

            AndroidLog.Error(_target, e);
            CrashlyticsLog(e);
            Writer.Write(e);

            if (_xamarinInsights)
            {
                Dictionary <string, string> additionalInfo = new Dictionary <string, string>
                {
                    { "Member Name", memberName },
                    { "Source Filepath", sourceFilePath },
                    { "Source Line Number", sourceLineNumber.ToString() },
                    { "CallStack", _traceEventCache.Callstack }
                };

                Insights.Report(new Exception(e), additionalInfo);
            }
        }
Ejemplo n.º 5
0
        protected override void Write(LogEventInfo logEvent)
        {
            var logMessage = this.Layout.Render(logEvent);

            if (logEvent.Level.Equals(LogLevel.Info))
            {
                Log.Info(logEvent.LoggerName, logMessage);
                return;
            }
            if (logEvent.Level.Equals(LogLevel.Debug))
            {
                Log.Debug(logEvent.LoggerName, logMessage);
                return;
            }
            if (logEvent.Level.Equals(LogLevel.Warn))
            {
                Log.Warn(logEvent.LoggerName, logMessage);
                return;
            }
            if (logEvent.Level.Equals(LogLevel.Error))
            {
                Log.Error(logEvent.LoggerName, logMessage);
                return;
            }
        }
Ejemplo n.º 6
0
 public void OnRdioUserAppApprovalNeeded(Intent authIntent)
 {
     try {
         StartActivityForResult(authIntent, 100);
     } catch (ActivityNotFoundException) {
         Log.Error("Auth", "Rdio App not found");
     }
 }
                public void Log(LogLevel level, string format, object param1, object param2)
                {
                    switch (level)
                    {
                    case LogLevel.Debug:
                        AndroidLog.Debug(_name, format, param1, param2);
                        break;

                    case LogLevel.Info:
                        AndroidLog.Info(_name, format, param1, param2);
                        break;

                    case LogLevel.Warn:
                        AndroidLog.Warn(_name, format, param1, param2);
                        break;

                    case LogLevel.Error:
                        AndroidLog.Error(_name, format, param1, param2);
                        break;
                    }
                }
Ejemplo n.º 8
0
            protected override void nextStageAction()
            {
                try
                {
                    //foreach (var fx in ValidGlyphs.Select(s => GetFeedbackFX(s))) fx.Deactivate();
                    foreach (var glyph in ValidGlyphs)
                    {
                        var fx = GetFeedbackFX(glyph);
                        if (glyph == null || fx == null)
                        {
                            continue;
                        }
                        fx.Stop();
                        fx.Deactivate();
                        glyph.FeedbackSFX = null;
                    }

                    //Current.SpellBeingCast = GlyphsSortedByAngle[0];
                    //Current.SetAllSpellButtonsEnabledState(false);

                    Plugin.Vibrate.CrossVibrate.Current.Vibration(15);
                    GlyphsSortedByAngle[0].ProgressSFX?.Play();
                    //AttitudeProvider.FrameShift = Current.SpellBeingCast.ZeroStance;
                    //CurrentStage = new GlyphCastingStage($"{Current.SpellBeingCast.SpellName} Glyph 0", Focus, Current.SpellBeingCast.Glyphs[0], AttitudeProvider);

                    var activity = SpellCastingActivity.Current;
                    activity.adapter = new GlyphDisplayAdapter(activity, new List <Glyph>());
                    activity.RunOnUiThread(() => activity.listView.Adapter = activity.adapter);

                    //AttitudeProvider.Deactivate();
                    //GravityProvider.Deactivate();

                    StageReturn(GlyphsSortedByAngle[0]);
                }
                catch (Exception e)
                {
                    Log.Error("Spell selection stage", e.Message);
                    throw;
                }
            }
                public void Log(LogLevel level, object message)
                {
                    var s = message.ToString();

                    switch (level)
                    {
                    case LogLevel.Debug:
                        AndroidLog.Debug(_name, s);
                        break;

                    case LogLevel.Info:
                        AndroidLog.Info(_name, s);
                        break;

                    case LogLevel.Warn:
                        AndroidLog.Warn(_name, s);
                        break;

                    case LogLevel.Error:
                        AndroidLog.Error(_name, s);
                        break;
                    }
                }
Ejemplo n.º 10
0
        public async Task <Rental[]> GetRentals(int page)
        {
            bool needsAuth = false;

            for (int i = 0; i < 4; i++)
            {
                try {
                    if (needsAuth)
                    {
                        if (await LoginToHubway().ConfigureAwait(false))
                        {
                            needsAuth = false;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (string.IsNullOrEmpty(credentials.UserId))
                    {
                        credentials.UserId = await GetHubwayUserId().ConfigureAwait(false);

                        if (string.IsNullOrEmpty(credentials.UserId))
                        {
                            needsAuth = true;
                            continue;
                        }
                    }

                    var rentalsUrl = HubwayRentalsUrl + credentials.UserId;
                    if (page > 0)
                    {
                        rentalsUrl += "?pageNumber=" + page;
                    }
                    var answer = await Client.GetStringAsync(rentalsUrl).ConfigureAwait(false);

                    var parser = new SimpleHtmlParser();
                    var doc    = parser.ParseString(answer);
                    var div    = doc.GetElementsByTagName("section")
                                 .OfType <XmlElement> ()
                                 .First(s => s.GetAttribute("class") == "ed-profile-page__content");
                    var rows = div.GetElementsByTagName("div")
                               .OfType <XmlElement> ()
                               .Where(n => n.ContainsClass("ed-table__item_trip"));
                    return(rows.Select(row => {
                        var cells = row.GetElementsByTagName("div").OfType <XmlElement> ().ToList();

                        /* 0 <div>
                         * 1   <div>time start
                         * 2   <div>station start
                         *   </div>
                         * 3 <div>
                         * 4   <div>time end
                         * 5   <div>station end
                         *   </div>
                         * 6 <div>duration
                         * 7 <div>billed
                         */
                        var rental = new Rental {
                            FromStationName = cells[2].InnerText.Trim(),
                            ToStationName = cells[5].InnerText.Trim(),
                            Duration = ParseRentalDuration(cells[6].InnerText.Trim()),
                            Price = ParseRentalPrice(cells[7].InnerText.Trim()),
                            DepartureTime = DateTime.Parse(cells[1].InnerText,
                                                           System.Globalization.CultureInfo.InvariantCulture),
                            ArrivalTime = DateTime.Parse(cells[4].InnerText,
                                                         System.Globalization.CultureInfo.InvariantCulture)
                        };
                        rental.Id = ((long)rental.DepartureTime.GetHashCode()) << 32;
                        rental.Id |= (uint)rental.ArrivalTime.GetHashCode();
                        return rental;
                    }).ToArray());
                } catch (HttpRequestException htmlException) {
                    // Super hacky but oh well
                    if (!needsAuth)
                    {
                        needsAuth = htmlException.Message.Contains("302");
                    }
                    continue;
                } catch (Exception e) {
                    AnalyticsHelper.LogException("RentalsGenericError", e);
                    Log.Error("RentalsGenericError", e.ToString());
                    break;
                }
            }

            return(null);
        }
Ejemplo n.º 11
0
        public async Task <Rental[]> GetRentals(int page)
        {
            bool needsAuth  = false;
            var  rentalsUrl = HubwayRentalsUrl;

            if (page > 0)
            {
                rentalsUrl += "/" + (page * 20);
            }

            for (int i = 0; i < 4; i++)
            {
                try {
                    if (needsAuth)
                    {
                        var content = new FormUrlEncodedContent(new Dictionary <string, string> {
                            { "username", credentials.Username },
                            { "password", credentials.Password }
                        });
                        var login = await Client.PostAsync(HubwayLoginUrl, content).ConfigureAwait(false);

                        if (login.StatusCode == HttpStatusCode.Found)
                        {
                            needsAuth = false;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    var answer = await Client.GetStringAsync(rentalsUrl).ConfigureAwait(false);

                    var doc = new HtmlDocument();
                    doc.LoadHtml(answer);
                    var div   = doc.GetElementById("content");
                    var table = div.Element("table");
                    return(table.Element("tbody").Elements("tr").Select(row => {
                        var items = row.Elements("td").ToArray();
                        return new Rental {
                            Id = long.Parse(items[0].InnerText.Trim()),
                            FromStationName = items [1].InnerText.Trim(),
                            ToStationName = items [3].InnerText.Trim(),
                            Duration = ParseRentalDuration(items [5].InnerText.Trim()),
                            Price = ParseRentalPrice(items [6].InnerText.Trim()),
                            DepartureTime = DateTime.Parse(items[2].InnerText,
                                                           System.Globalization.CultureInfo.InvariantCulture),
                            ArrivalTime = DateTime.Parse(items[4].InnerText,
                                                         System.Globalization.CultureInfo.InvariantCulture)
                        };
                    }).ToArray());
                } catch (HttpRequestException htmlException) {
                    // Super hacky but oh well
                    if (!needsAuth)
                    {
                        needsAuth = htmlException.Message.Contains("302");
                    }
                    continue;
                } catch (Exception e) {
                    Log.Error("RentalsGenericError", e.ToString());
                    break;
                }
            }

            return(null);
        }
 protected override void Error(ILog log, string message, object extraData, LogData logData, DateTime time)
 {
     Log.Error(Tag, message);
 }
Ejemplo n.º 13
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            lock (this._startLocker)
            {
                if (!this._started)
                {
                    ILogger log = null;
                    try
                    {
                        MessagingCenter.Instance.Subscribe <FormsApplication, ServiceLogMessage>(
                            this,
                            nameof(ServiceLogMessage),
                            (_, logMessage) => Device.BeginInvokeOnMainThread(
                                () =>
                        {
                            if (this._logMessages.Count > c_MaxLogMessages)
                            {
                                this._logMessages.RemoveAt(0);
                            }

                            this._logMessages.Add(logMessage);
                        }));

                        var listenEndPoint  = new IPEndPoint(IPAddress.Loopback, this._settings.ListenPort);
                        var serviceProvider = this.CreateServiceProvider();

                        this._serviceScope = serviceProvider.CreateScope();
                        log = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger(this.GetType().Name);

                        var socksServer = this._serviceScope.ServiceProvider.GetRequiredService <SocksServer>();
                        socksServer.Start();

                        var notification = new Notification.Builder(this)
                                           .SetSubText(listenEndPoint.ToString())
                                           .SetVisibility(NotificationVisibility.Secret)
                                           .SetSmallIcon(Resource.Drawable.ic_stat_socks)
                                           .SetContentIntent(
                            PendingIntent.GetActivity(
                                this,
                                0,
                                new Intent(this, typeof(MainActivity)).AddFlags(ActivityFlags.ReorderToFront),
                                PendingIntentFlags.UpdateCurrent))
                                           .SetOngoing(true)
                                           .Build();
                        this.StartForeground(1, notification);

                        this._started = true;
                        this.NotifyStatusUpdate();
                    }
                    catch (Exception ex)
                    {
                        if (log != null)
                        {
                            log.LogError(ex, "Failed to start service");
                        }
                        else
                        {
                            Log.Error(nameof(MangleSocks), Throwable.FromException(ex), "Failed to start service");
                        }

                        this.StopSelfResult(1);
                    }
                }

                return(StartCommandResult.Sticky);
            }
        }
Ejemplo n.º 14
0
 public void error(string tag, string text)
 {
     ALog.Error(tag, text);
 }