示例#1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();

            //manager.SendSms(getActiveUser().Id, "http://www.google.com");
            ApplicationUser currentUser = getActiveUser();

            if (currentUser == null)
            {
                return;
            }

            User dbUser = RestDispatcher.ExecuteRequest <User>("users/" + currentUser.UserName, Method.GET);


            IEnumerable <User> collection = RestDispatcher.ExecuteRequest <IEnumerable <User> >("users/team/" + dbUser.teamId, Method.GET);

            foreach (User usr in collection)
            {
                ApplicationUser appUser = manager.FindByNameAsync(usr.username).Result;
                if (appUser == null)
                {
                    continue;
                }
                manager.SendSmsAsync(appUser.Id, currentUser.UserName +
                                     " is Pushing, would you like to contribute? If so go to " + RestDispatcher.GetApiRoot() + "contributions/" + appUser.UserName);
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                // User is authenticated
                // Load team data
                // Load user data
                // Load battle data

                ApplicationUser user = getActiveUser();
                if (user == null)
                {
                    return;
                }
                string userName = user.UserName;


                IRestResponse userResponse = RestDispatcher.ExecuteRequest("users/" + userName, Method.GET);
                if (userResponse.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return;
                }
                User          dbUser       = RestDispatcher.Deserialize <User>(userResponse);
                IRestResponse teamResponse = RestDispatcher.ExecuteRequest("teams/" + dbUser.teamId, Method.GET);
                if (teamResponse.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return;
                }
                Team dbTeam = RestDispatcher.Deserialize <Team>(teamResponse);

                IRestResponse battleResponse = RestDispatcher.ExecuteRequest("battles/" + dbTeam.currentBattle, Method.GET);
                Battle        dbBattle       = RestDispatcher.Deserialize <Battle>(battleResponse);
                callJavaScript("parseBattleData", battleResponse.Content);
                //if (battleResponse.StatusCode == System.Net.HttpStatusCode.OK)
                //{
                //   Battle dbBattle = RestDispatcher.Deserialize<Battle>(battleResponse);
                //  callJavaScript("parseBattleData", battleResponse.Content);

//                }

                callJavaScript("parseUserData", userResponse.Content);
                callJavaScript("parseTeamData", teamResponse.Content);
            }
            else
            {
                // User not authenticated
            }
        }
示例#3
0
        protected void GetUserButton_Click(object sender, EventArgs e)
        {
            ApplicationUser user = getActiveUser();

            if (user == null)
            {
                return;
            }
            IRestResponse userResponse = RestDispatcher.ExecuteRequest("users/" + user.UserName, Method.GET);

            if (userResponse.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return;
            }
            User dbUser = RestDispatcher.Deserialize <User>(userResponse);

            callJavaScript("simpleAlert", userResponse.Content);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="apUser"></param>
        /// <param name="targetTeam"></param>
        /// <returns></returns>
        public static bool DeclareBattle(ApplicationUser apUser, string targetTeam)
        {
            // Check if a battle is happening
            // If no battle, send message saying no battle happening
            //  and say that a battle will be declared

            User dbUser = RestDispatcher.ExecuteRequest <User>("users/" + apUser.UserName, Method.GET);

            if (dbUser == null)
            {
                Console.WriteLine("Could not find user with name: {0}", apUser.UserName);
                return(false);
            }

            string teamName = dbUser.teamId;
            Team   myTeam   = RestDispatcher.ExecuteRequest <Team>("teams/" + teamName, Method.GET);

            if (myTeam == null)
            {
                Console.WriteLine("Could not find team with name: {0}", teamName);
                return(false);
            }

            if (targetTeam.Equals(myTeam.teamname, StringComparison.OrdinalIgnoreCase))
            {
                // You're attacking your own team, that's not allowed
                // Send message saying as such

                // This one is for logging.
                Console.WriteLine("{0} has tried to attack own team.", apUser.UserName);
                return(false);
            }

            if (!myTeam.currentBattle.Equals("none"))
            {
                // We are in battle, so don't start another
                Console.WriteLine("{0} has tried to start a battle, but {1} is already engaged in one.", apUser.UserName, myTeam.teamname);
                return(false);
            }

            Team theirTeam = RestDispatcher.ExecuteRequest <Team>("teams/" + targetTeam, Method.GET);

            if (theirTeam == null)
            {
                Console.WriteLine("Could not find target team with name: {0}", targetTeam);
                return(false);
            }

            // We have the enemy team, are they in battle?
            if (!theirTeam.currentBattle.Equals("none"))
            {
                Console.WriteLine("{0} has tried to start a battle against {1}, but {1} is already in battle.", apUser.UserName, targetTeam);
                return(false);
            }

            String test   = "testbattle";
            var    battle = new Battle();

            battle.battleId = test;
            battle.scores   = new List <int> {
                1, -1
            };
            battle.offsets = new List <int> {
                1, -1
            };
            battle.initiator    = dbUser.username;
            battle.participants = new List <string> {
                myTeam.teamname, theirTeam.teamname
            };
            //battle.participants = new List<Score>();
            //battle.participants.Add(new Score(myTeam.teamname, 0));
            //battle.participants.Add(new Score(theirTeam.teamname, 1));
            battle.declaration = new DateTime();
            Random random    = new Random();
            int    extraMins = random.Next(5);

            battle.initiation = battle.declaration.AddMinutes(extraMins);
            battle.duration   = (5 + random.Next(10));
            RestRequest battlePost = new RestRequest("battles", Method.POST);

            battlePost.AddJsonBody(battle);
            IRestResponse battleResponse = RestDispatcher.ExecuteRequest(battlePost);


            return(false);
        }