コード例 #1
0
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            HasOptionsMenu = true;
            container      = TinyIoC.TinyIoCContainer.Current;
            //TODO: Add TinyIOC and move these to app start
            webService = container.Resolve <WlcWebService> ();
            var parser = new WlcHtmlParse();

            var prefs = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);

            myStatsUrl = prefs.GetString("statsUrl", "");
            csrfToken  = prefs.GetString("csrfToken", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            adapter = new StatsBarAdapter(this.Activity);

            fadeinAnimation  = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.abc_fade_in);
            fadeoutAnimation = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.abc_fade_out);

            // Get the data here
            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });
                today = await webService.GetRecord(StoredCookies, "today.json", csrfToken);

                yesterday = await webService.GetRecord(StoredCookies, "yesterday.json", csrfToken);

                var contentStr = await webService.GetStats(StoredCookies, "/profiles/" + profile.id.ToString() + "/stats_calendar");

                myStats = parser.GetStats(contentStr);

                if (today != null)
                {
                    byte[] imageBytes = await webService.GetProfileImage(profile.user.photo);

                    // IBitmap is a type that provides basic image information such as dimensions
                    profileImage = await BitmapLoader.Current.Load(new MemoryStream(imageBytes), null /* Use original width */, null /* Use original height */);
                }

                ((StatsBarAdapter)adapter).Stats = myStats.OrderByDescending(x => x.StatDate).ToList();
                if (!Activity.IsFinishing)
                {
                    updateView();
                    if (loading != null)
                    {
                        loading.Visibility  = ViewStates.Gone;
                        listView.Visibility = ViewStates.Visible;
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            actionBarBackgroundDrawable = new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.MediumAquamarine);
            actionBarBackgroundDrawable.SetAlpha(0);
            Activity.ActionBar.SetBackgroundDrawable(actionBarBackgroundDrawable);
        }
コード例 #2
0
        public override async Task <CreateChallengeResponse> CreateChallenge(CreateChallengeRequest request, ServerCallContext context)
        {
            // TODO: Validation...

            var result = await _challengeService.CreateChallengeAsync(
                new ChallengeName(request.Name),
                request.Game.ToEnumeration <Game>(),
                new BestOf(request.BestOf),
                new Entries(request.Entries),
                new ChallengeDuration(TimeSpan.FromDays(request.Duration)),
                new UtcNowDateTimeProvider(),
                new Scoring(request.Scoring.Items.OrderBy(item => item.Order).ToDictionary(item => item.StatName, item => item.StatWeighting)));

            if (result.IsValid)
            {
                var response = new CreateChallengeResponse
                {
                    Challenge = ChallengeProfile.Map(result.Response)
                };

                return(context.Ok(response));
            }

            throw context.FailedPreconditionRpcException(result);
        }
コード例 #3
0
        public override async Task <SynchronizeChallengeResponse> SynchronizeChallenge(SynchronizeChallengeRequest request, ServerCallContext context)
        {
            var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>();

            if (!await _challengeService.ChallengeExistsAsync(challengeId))
            {
                throw context.NotFoundRpcException("Challenge not found.");
            }

            var challenge = await _challengeService.FindChallengeAsync(challengeId);

            var result = await _challengeService.SynchronizeChallengeAsync(challenge, new UtcNowDateTimeProvider());

            if (result.IsValid)
            {
                var response = new SynchronizeChallengeResponse
                {
                    Challenge = ChallengeProfile.Map(result.Response)
                };

                return(context.Ok(response));
            }

            throw context.FailedPreconditionRpcException(result);
        }
コード例 #4
0
    List <ChallengeProfile> LoadSkins()
    {
        skinStatus.Clear();
        var command = @"SELECT * FROM challenges ORDER BY id";
        var profile = new ChallengeProfile();

        using (var dbConnection = new SqliteConnection("URI=file:" + Application.dataPath + "/StreamingAssets/main.db"))
        {
            using (var dbCommand = dbConnection.CreateCommand())
            {
                dbConnection.Open();

                dbCommand.CommandText = command;

                using (var dbReader = dbCommand.ExecuteReader())
                {
                    while (dbReader.Read())
                    {
                        if (dbReader.GetValue(0) != null)
                        {
                            var skin = new ChallengeProfile();
                            skin.id       = dbReader.GetInt32(0);
                            skin.finished = dbReader.GetInt32(3);

                            skinStatus.Add(skin);
                        }
                    }
                }
            }
        }
        return(skinStatus);
    }
コード例 #5
0
ファイル: SQLread.cs プロジェクト: shotskeber/KitchensWrath
    List <ChallengeProfile> LoadChallenges()
    {
        challenges.Clear();
        var command = @"SELECT * FROM challenges ORDER BY id";
        var profile = new ChallengeProfile();

        using (var dbConnection = new SqliteConnection("URI=file:" + Application.dataPath + "/DBs/main.db"))
        {
            using (var dbCommand = dbConnection.CreateCommand())
            {
                dbConnection.Open();

                dbCommand.CommandText = command;

                using (var dbReader = dbCommand.ExecuteReader())
                {
                    while (dbReader.Read())
                    {
                        if (dbReader.GetValue(0) != null)
                        {
                            var challenge = new ChallengeProfile();
                            challenge.id       = dbReader.GetInt32(0);
                            challenge.desc     = dbReader.GetString(1);
                            challenge.type     = dbReader.GetString(2);
                            challenge.finished = dbReader.GetInt32(3);

                            challenges.Add(challenge);
                        }
                    }
                }
            }
        }
        return(challenges);
    }
コード例 #6
0
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            webService = new WlcWebService();

            var prefs            = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);
            var myStatsUrl       = prefs.GetString("statsUrl", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            csrfToken = prefs.GetString("csrfToken", "");
            adapter   = new StatsColorBarAdapter(Activity);

            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });

                var contentStr = await webService.GetStats(StoredCookies, "/profiles/" + profile.id.ToString() + "/stats_calendar");

                myStats = WlcHelpers.GetStats(contentStr);
                ((StatsColorBarAdapter)adapter).Stats = myStats.OrderByDescending(x => x.StatDate).ToList();
//				today = await webService.GetRecord(StoredCookies, "today.json", csrfToken);
                if (!Activity.IsFinishing)
                {
                    UpdateView();
                }
            } catch (Exception ex) {
            }
        }
コード例 #7
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile>(ChallengeProfileStr, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });

//				client = new RestClient ("https://game.wholelifechallenge.com");
//				client.CookieContainer = StoredCookies;
//				client.FollowRedirects = true;
//				request = new RestRequest("wlcny15/teams/7569/leaderboards.json", Method.GET);
//				request.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
//				request.AddHeader("X-CSRF-TOKEN", CSRFToken);
//				request.AddHeader("Referer", "https://game.wholelifechallenge.com/wlcny15/hub");
//				request.AddParameter("challenge_profile_id", profile.id);
//				request.AddParameter("per", 50);
//
//				var resp = await client.ExecuteGetTaskAsync(request);
//				var content = resp.Content;
//				var serializerSettings = new JsonSerializerSettings() {
//					NullValueHandling = NullValueHandling.Ignore,
//					DateParseHandling = DateParseHandling.None
//				};
//				adapter.Leaderboard = JsonConvert.DeserializeObject<Core.Leaderboard.Leaderboard>(content, serializerSettings);
//
//				if(!Activity.IsFinishing) {
//					UpdateView();
//				}
            } catch {
            }
            // Create your fragment here
        }
コード例 #8
0
        public static async Task PublishChallengeStartedIntegrationEventAsync(this IServiceBusPublisher publisher, IChallenge challenge)
        {
            var integrationEvent = new ChallengeStartedIntegrationEvent
            {
                Challenge = ChallengeProfile.Map(challenge)
            };

            await publisher.PublishAsync(integrationEvent);
        }
コード例 #9
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            try {
                profile = JsonConvert.DeserializeObject <ChallengeProfile> (ChallengeProfileStr, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
            } catch (Exception ex) {
            }
        }
コード例 #10
0
        public static async Task PublishChallengeSynchronizedIntegrationEventAsync(this IServiceBusPublisher publisher, IChallenge challenge)
        {
            var integrationEvent = new ChallengeSynchronizedIntegrationEvent
            {
                ChallengeId = challenge.Id,
                Scoreboard  =
                {
                    challenge.Participants.Select(participant => ChallengeProfile.Map(challenge, participant))
                }
            };

            await publisher.PublishAsync(integrationEvent);
        }
コード例 #11
0
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            webService = new WlcWebService();

            var prefs            = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);
            var myStatsUrl       = prefs.GetString("statsUrl", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            csrfToken = prefs.GetString("csrfToken", "");
            adapter   = new ReflectionAdapter(Activity);
            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });

                client = new RestClient("https://game.wholelifechallenge.com");
                client.CookieContainer = StoredCookies;
                client.FollowRedirects = true;
                //TODO: parametrize the team id!
                postsReq = new RestRequest("api/frontend/current_user/teams/7569/posts.json", Method.GET);
                postsReq.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                postsReq.AddHeader("X-CSRF-TOKEN", csrfToken);
                postsReq.AddHeader("Referer", "https://game.wholelifechallenge.com/wlcmay15/hub");
                postsReq.AddParameter("per", 10);
                var resp = await client.ExecuteGetTaskAsync(postsReq);

                var content = resp.Content;
                serializerSettings = new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    DateParseHandling = DateParseHandling.None
                };
                //_record = JsonConvert.DeserializeObject<DailyRecord> (contentStr.Result);

                int teamId = profile.teams.Select(x => x.id).First();

                adapter.ReflectionFeed = JsonConvert.DeserializeObject <Feed> (content, serializerSettings);
//				adapter.ReflectionFeed = await webService.GetReflections(teamId, 0, 10, StoredCookies, csrfToken);
                if (!Activity.IsFinishing)
                {
                    UpdateView();
                }
            } catch (Exception ex) {
            }
        }
コード例 #12
0
        public override async Task <SnapshotChallengeParticipantResponse> SnapshotChallengeParticipant(
            SnapshotChallengeParticipantRequest request,
            ServerCallContext context
            )
        {
            var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>();

            if (!await _challengeService.ChallengeExistsAsync(challengeId))
            {
                throw context.NotFoundRpcException("Challenge not found.");
            }

            var challenge = await _challengeService.FindChallengeAsync(challengeId);

            var result = await _challengeService.SnapshotChallengeParticipantAsync(
                challenge,
                request.GamePlayerId.ParseStringId <PlayerId>(),
                new UtcNowDateTimeProvider(),
                scoring => request.Matches.Select(
                    match => new Match(
                        new GameUuid(match.GameUuid),
                        new DateTimeProvider(match.GameCreatedAt.ToDateTime()),
                        match.GameDuration.ToTimeSpan(),
                        scoring.Map(match.Stats),
                        new UtcNowDateTimeProvider()))
                .ToImmutableHashSet());

            if (result.IsValid)
            {
                var response = new SnapshotChallengeParticipantResponse
                {
                    Participant = ChallengeProfile.Map(challenge, result.Response)
                };

                return(context.Ok(response));
            }

            throw context.FailedPreconditionRpcException(result);
        }
コード例 #13
0
        public override async Task <RegisterChallengeParticipantResponse> RegisterChallengeParticipant(
            RegisterChallengeParticipantRequest request,
            ServerCallContext context
            )
        {
            var httpContext = context.GetHttpContext();

            var userId = httpContext.GetUserId();

            var challengeId = request.ChallengeId.ParseEntityId <ChallengeId>();

            if (!await _challengeService.ChallengeExistsAsync(challengeId))
            {
                throw context.NotFoundRpcException("Challenge not found.");
            }

            var challenge = await _challengeService.FindChallengeAsync(challengeId);

            var result = await _challengeService.RegisterChallengeParticipantAsync(
                challenge,
                userId,
                request.ParticipantId.ParseEntityId <ParticipantId>(),
                request.GamePlayerId.ParseStringId <PlayerId>(),
                new UtcNowDateTimeProvider());

            if (result.IsValid)
            {
                var response = new RegisterChallengeParticipantResponse
                {
                    Participant = ChallengeProfile.Map(challenge, result.Response)
                };

                return(context.Ok(response));
            }

            throw context.FailedPreconditionRpcException(result);
        }