コード例 #1
0
ファイル: Main.cs プロジェクト: yonifra/Xamarin.Sport
        //This is the main entry point of the application.
        static void Main(string[] args)
        {
            try
            {
                UIApplication.Main(args, null, "AppDelegate");
            }
            catch (Exception e)
            {
                var ex = e.GetBaseException();
                Console.WriteLine("**SPORT MAIN EXCEPTION**\n\n" + ex);
                InsightsManager.Report(ex, Xamarin.Insights.Severity.Critical);
                throw;
            }

            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                try
                {
                    var ex = ((Exception)e.ExceptionObject).GetBaseException();
                    Console.WriteLine("**SPORT UNHANDLED EXCEPTION**\n\n" + ex);
                    InsightsManager.Report(ex, Xamarin.Insights.Severity.Critical);
                }
                catch
                {
                }
            };
        }
コード例 #2
0
        public void GetFastestActivitySongsWithNoActivitiesOrSongs_ExceptionThrown()
        {
            sut = new InsightsManager();
            Action exceptionAction = () => sut.GetFastestActivityWithListeningHistory(new Dictionary <object, List <object> >());

            exceptionAction.Should().Throw <IndexOutOfRangeException>().WithMessage("No activities in parsed array dictionary.");
        }
コード例 #3
0
        public override UIViewController PopViewController(bool animated)
        {
            try
            {
                var obj = Element.GetType().InvokeMember("StackCopy", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder, Element, null);
                if (obj != null)
                {
                    var pages = obj as Stack <Page>;
                    if (pages != null && pages.Count >= 2)
                    {
                        var copy = new Page[pages.Count];
                        pages.CopyTo(copy, 0);

                        var prev = copy[1];
                        ChangeTheme(prev);
                    }
                }
            }
            catch (Exception e)
            {
                InsightsManager.Report(e);
            }

            return(base.PopViewController(animated));
        }
コード例 #4
0
        /// <inheritdoc/>
        public void MakeRunningAndListeningHistoryComparisonWithDateRange(DateTime startDate, DateTime endDate)
        {
            var subsetMappedSongsToActivities = new Dictionary <object, List <object> >();

            foreach (var item in activitiesAndSongs.Keys)
            {
                if (item is StravaActivity stravaRun)
                {
                    if (stravaRun.start_date.Date >= startDate.Date && stravaRun.start_date.Date <= endDate)
                    {
                        subsetMappedSongsToActivities.Add(stravaRun, activitiesAndSongs[stravaRun]);
                    }
                }
                else if (item is Fitbit.Api.Portable.Models.Activities fitBitRun)
                {
                    if (fitBitRun.StartTime.Date >= startDate.Date && fitBitRun.StartTime.Date <= endDate)
                    {
                        subsetMappedSongsToActivities.Add(fitBitRun, activitiesAndSongs[fitBitRun]);
                    }
                }
            }

            var insightsManager = new InsightsManager();

            fastestActivityAndSongs = insightsManager.GetFastestActivityWithListeningHistory(subsetMappedSongsToActivities);
        }
コード例 #5
0
        public async Task <MobileServiceUser> DisplayWebView()
        {
            try
            {
                return(await AzureService.Instance.Client.LoginAsync(Forms.Context, MobileServiceAuthenticationProvider.Google));
            }
            catch (Exception e)
            {
                InsightsManager.Report(e);
            }

            return(null);
        }
コード例 #6
0
 protected override void OnRegistered(Context context, string registrationId)
 {
     try
     {
         App.CurrentAthlete.DeviceToken = registrationId;
         MessagingCenter.Send <App>(App.Current, Messages.RegisteredForRemoteNotifications);
     }
     catch (Exception e)
     {
         InsightsManager.Report(e);
         Debug.WriteLine(e);
     }
 }
コード例 #7
0
 public void RegisterForPushNotifications()
 {
     try
     {
         GcmClient.CheckDevice(Forms.Context);
         GcmClient.CheckManifest(Forms.Context);
         GcmClient.Register(Forms.Context, GcmBroadcastReceiver.SENDER_IDS);
     }
     catch (Exception e)
     {
         InsightsManager.Report(e);
         Debug.WriteLine(e);
     }
 }
コード例 #8
0
        protected override void OnCreate(global::Android.OS.Bundle bundle)
        {
            if (InsightsManager.IsEnabled)
            {
                Xamarin.Insights.Initialize(Keys.InsightsApiKey, this);
            }

            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                try
                {
                    var ex = ((Exception)e.ExceptionObject).GetBaseException();
                    Console.WriteLine("**SPORT MAIN ACTIVITY EXCEPTION**\n\n" + ex);
                    InsightsManager.Report(ex, Xamarin.Insights.Severity.Critical);
                }
                catch
                {
                }
            };

            try
            {
                base.OnCreate(bundle);
                Window.SetSoftInputMode(SoftInput.AdjustPan);
                Xamarin.Forms.Forms.Init(this, bundle);
                ImageCircleRenderer.Init();

                //We're using the value of the StyleId as the content description for use w/ Xamarin UITest / XTC
                Xamarin.Forms.Forms.ViewInitialized += (sender, e) =>
                {
                    if (!string.IsNullOrWhiteSpace(e.View.StyleId))
                    {
                        e.NativeView.ContentDescription = e.View.StyleId;
                    }
                };

                LoadApplication(new App());

                var color = new ColorDrawable(Color.Transparent);
                ActionBar.SetIcon(color);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
コード例 #9
0
        /// <inheritdoc/>
        public void MakeRunningAndListeningHistoryComparison()
        {
            // Determine what date to search on...
            DateTime dateToSearchOn = new DateTime();

            if (activitiesAndSongs.Keys.First() is StravaActivity stravaActivity)
            {
                dateToSearchOn = stravaActivity.start_date;
            }
            else if (activitiesAndSongs.Keys.First() is Fitbit.Api.Portable.Models.Activities fitBitActivity)
            {
                dateToSearchOn = fitBitActivity.StartTime.DateTime;
            }

            Dictionary <object, List <object> > subsetMappedSongsToActivities = new Dictionary <object, List <object> >();

            foreach (var item in activitiesAndSongs.Keys)
            {
                if (item is StravaActivity stravaRun)
                {
                    if (stravaRun.start_date.Date == dateToSearchOn.Date)
                    {
                        subsetMappedSongsToActivities.Add(stravaRun, activitiesAndSongs[stravaRun]);
                    }
                }
                else if (item is Fitbit.Api.Portable.Models.Activities fitBitRun)
                {
                    if (fitBitRun.StartTime.DateTime.Date == dateToSearchOn.Date)
                    {
                        subsetMappedSongsToActivities.Add(fitBitRun, activitiesAndSongs[fitBitRun]);
                    }
                }
            }
            // Then make comparison
            var insightsManager = new InsightsManager();

            fastestActivityAndSongs = insightsManager.GetFastestActivityWithListeningHistory(subsetMappedSongsToActivities);
        }
コード例 #10
0
        public async Task <MobileServiceUser> DisplayWebView()
        {
            try
            {
                var window = UIKit.UIApplication.SharedApplication.KeyWindow;
                var root   = window.RootViewController;
                if (root != null)
                {
                    var current = root;
                    while (current.PresentedViewController != null)
                    {
                        current = current.PresentedViewController;
                    }

                    return(await AzureService.Instance.Client.LoginAsync(current, MobileServiceAuthenticationProvider.Google));
                }
            }
            catch (Exception e)
            {
                InsightsManager.Report(e);
            }

            return(null);
        }
コード例 #11
0
        internal static bool HandlePushNotification(Context context, Intent intent)
        {
            string message;

            if (!intent.Extras.ContainsKey("message"))
            {
                return(false);
            }

            message = intent.Extras.Get("message").ToString();
            var title = intent.Extras.Get("title").ToString();

            var activityIntent = new Intent(context, typeof(MainActivity));
            var payloadValue   = GetPayload(intent);

            activityIntent.PutExtra("payload", payloadValue);
            activityIntent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(context, 0, activityIntent, PendingIntentFlags.UpdateCurrent);

            var n = new Notification.Builder(context);

            n.SetSmallIcon(Resource.Drawable.ic_successstatus);
            n.SetLights(global::Android.Graphics.Color.Blue, 300, 1000);
            n.SetContentIntent(pendingIntent);
            n.SetContentTitle(title);
            n.SetTicker(message);
            n.SetLargeIcon(global::Android.Graphics.BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon));
            n.SetSmallIcon(Resource.Drawable.ic_trophy_white);
            n.SetContentText(message);
            n.SetVibrate(new long[] {
                200,
                200,
                100,
            });

            var nm = NotificationManager.FromContext(context);

            nm.Notify(0, n.Build());

            if (MainActivity.IsRunning)
            {
                try
                {
                    message.ToToast();
                    var payload = GetPayload(intent);
                    var pl      = JsonConvert.DeserializeObject <NotificationPayload>(payload);

                    if (payloadValue != null)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            MessagingCenter.Send <App, NotificationPayload>(App.Current, Messages.IncomingPayloadReceivedInternal, pl);
                        });
                    }
                }
                catch (Exception e)
                {
                    InsightsManager.Report(e, Insights.Severity.Error);
                }
            }

            return(true);
        }
コード例 #12
0
        public void GetFastestActivitySongs_FastestActivitySongsReturned()
        {
            var now = DateTime.UtcNow;

            var activity1 = new StravaActivity
            {
                type          = "Run",
                average_speed = 3.5,
                start_date    = now.AddHours(-2),
                elapsed_time  = 3600
            };
            var listOfActivity1PlayHistory = new List <object>
            {
                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-2),
                    Track    = new SimpleTrack
                    {
                        Name       = "Song 1",
                        DurationMs = 3600
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-2).AddMinutes(5),
                    Track    = new SimpleTrack
                    {
                        Name       = "Song 2",
                        DurationMs = 3600
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-2).AddMinutes(10),
                    Track    = new SimpleTrack
                    {
                        Name       = "Song 3",
                        DurationMs = 3600
                    }
                }
            };

            var activity2 = new StravaActivity
            {
                type          = "Run",
                average_speed = 4.5,
                start_date    = now.AddHours(-1),
                elapsed_time  = 3600
            };

            var listOfActivity2PlayHistory = new List <object>
            {
                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-1).AddMinutes(5),
                    Track    = new SimpleTrack
                    {
                        Name       = "Faster Song 1",
                        DurationMs = 600
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-1).AddMinutes(10),
                    Track    = new SimpleTrack
                    {
                        Name       = "Faster Song 2",
                        DurationMs = 900
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-1).AddMinutes(15),
                    Track    = new SimpleTrack
                    {
                        Name       = "Faster Song 3",
                        DurationMs = 1200
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-1).AddMinutes(20),
                    Track    = new SimpleTrack
                    {
                        Name       = "Faster Song 4",
                        DurationMs = 600
                    }
                },
            };

            var sampleData = new Dictionary <object, List <object> >
            {
                { activity1, listOfActivity1PlayHistory },
                { activity2, listOfActivity2PlayHistory }
            };

            sut = new InsightsManager();
            var result = sut.GetFastestActivityWithListeningHistory(sampleData);

            result.Keys.Should().Contain(activity2);
            result.Keys.Should().HaveCount(1);
            result.Values.ToList()[0].Should().BeEquivalentTo(listOfActivity2PlayHistory);
        }
コード例 #13
0
        public void GetFastestActivitySongsWithMultipleTypesOfActivity_FastestActivitySongsReturned()
        {
            var now = DateTime.UtcNow;

            var activity1 = new StravaActivity
            {
                type          = "Run",
                average_speed = 3.5,
                start_date    = now.AddHours(-2),
                elapsed_time  = 3600
            };
            var listOfActivity1PlayHistory = new List <object>
            {
                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-2),
                    Track    = new SimpleTrack
                    {
                        Name       = "Song 1",
                        DurationMs = 3600
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-2).AddMinutes(5),
                    Track    = new SimpleTrack
                    {
                        Name       = "Song 2",
                        DurationMs = 3600
                    }
                },

                new PlayHistoryItem
                {
                    PlayedAt = now.AddHours(-2).AddMinutes(10),
                    Track    = new SimpleTrack
                    {
                        Name       = "Song 3",
                        DurationMs = 3600
                    }
                }
            };

            var activity2 = new Fitbit.Api.Portable.Models.Activities
            {
                ActivityTypeId = 1,
                Duration       = 3600,
                Speed          = 4.5,
                StartTime      = now.AddHours(-2)
            };

            var listOfActivity2PlayHistory = new List <object>
            {
                new LastTrack
                {
                    TimePlayed = now.AddHours(-2),
                    Name       = "Last FM song 1",
                    Duration   = new TimeSpan(0, 3, 0)
                },
                new LastTrack
                {
                    TimePlayed = now.AddHours(-2).AddMinutes(3),
                    Name       = "Last FM song 2",
                    Duration   = new TimeSpan(0, 3, 0)
                },
            };

            var sampleData = new Dictionary <object, List <object> >
            {
                { activity1, listOfActivity1PlayHistory },
                { activity2, listOfActivity2PlayHistory }
            };


            sut = new InsightsManager();
            var result = sut.GetFastestActivityWithListeningHistory(sampleData);

            result.Keys.Should().Contain(activity2);
            result.Keys.Should().HaveCount(1);
            result.Values.ToList()[0].Should().BeEquivalentTo(listOfActivity2PlayHistory);
        }