Example #1
0
        public void SendInvitations([FromForm] int game_id)
        {
            //CloudMessagingService.GameInvitation(Sub, game_id);

            var game = DatabaseService.GetGame(game_id, Sub);

            if (game.WinCode != String.Empty)
            {
                foreach (int uid in game.UserIds)
                {
                    var user = DatabaseService.GetUserById(uid);
                    CloudMessagingService.GameInvitation(user.Sub, game_id);
                }
            }
        }
Example #2
0
 public void WinTest([FromForm] int game_id, [FromForm] string first_name, [FromForm] string last_name)
 {
     CloudMessagingService.GameEnded(game_id, first_name, last_name);
 }
Example #3
0
        private bool SendNotification(CloudMessagingService service, Content content, ref HttpStatusCode result)
        {
            if (content.registration_ids.Length == 0)
            {
                return(true);
            }

            string message = Json.Serialize(content);

            byte[] byteArray = Encoding.UTF8.GetBytes(message);
            string url = string.Empty, apiKey = string.Empty;

            switch (service)
            {
            case CloudMessagingService.GCM:
                url    = "https://android.googleapis.com/gcm/send";
                apiKey = GcmApiKey;
                Logger.Instance.LogFormat(LogType.Debug, this, Properties.Resources.DebugSendMessage, "eAlarm", message);
                break;

            case CloudMessagingService.FCM:
                url    = "https://fcm.googleapis.com/fcm/send";
                apiKey = FcmApiKey;
                Logger.Instance.LogFormat(LogType.Debug, this, Properties.Resources.DebugSendMessage, "fAlarm", message);
                break;

            default:
                Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.ErrorMessagingServiceNotFound);
                return(false);
            }

            ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = WebRequestMethods.Http.Post;
            request.KeepAlive   = false;
            request.ContentType = "application/json";
            request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
            request.ContentLength = byteArray.Length;

            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    HttpStatusCode responseCode = ((HttpWebResponse)response).StatusCode;

                    StreamReader reader         = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    String       responseString = reader.ReadToEnd();

                    Logger.Instance.LogFormat(LogType.Debug, this, Properties.Resources.DebugGetResponse, responseCode, responseString);

                    if (responseCode != HttpStatusCode.OK)
                    {
                        result = responseCode;
                        return(false);
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.LogException(this, exception);
            }

            return(true);
        }
Example #4
0
 public void SendInvitationTest([FromForm] string sub, [FromForm] int game_id)
 {
     CloudMessagingService.GameInvitation(sub, game_id);
 }