コード例 #1
0
        public string sendNotification(Device device, string message)
        {
            WebRequest request = WebRequest.Create(gcmUrl);

            request.Method = gcmMethod;
            request.ContentType = gcmContentType;
            request.Headers.Add(string.Format("Authorization: key={0}", appId));
            request.Headers.Add(string.Format("Sender: id={0}", senderId));

            string postData = "collapse_key=score_update&" +
                "time_to_live=108" +
                "&delay_while_idle=1" +
                "&data.message=" + message +
                "&data.time=" + System.DateTime.Now.ToString() +
                "&registration_id=" + device.RegistrationId + "";

            Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);

            String responseFromServer = reader.ReadToEnd();

            reader.Close();
            dataStream.Close();
            response.Close();

            return responseFromServer;
        }
コード例 #2
0
 public Device Create(Device device)
 {
     var dalDevice = AutoMapper.Mapper.Map<DalDevice>(device);
     var newDevice = _deviceRepository.Create(dalDevice);
        _unit.Commit();
     return AutoMapper.Mapper.Map<Device>(newDevice);
 }
コード例 #3
0
 //URL POST :   http://localhost:50538/RestService/RestService.svc/RegisterDevice
 public Response RegisterDevice(DeviceInfoContract deviceInfo)
 {
     var user = _userService.GetBy(deviceInfo.UserLogin);
     if (user != null)
     {
         var newDevice = new Device
         {
             RegistrationId = deviceInfo.RegistrationId,
             Imei = deviceInfo.Imei,
             User = user
         };
         _deviceService.Create(newDevice);
         return new SuccessResponse();
     }
     else
     {
         return new FailureResponse();
     }
 }