Ejemplo n.º 1
0
        // POST tables/Bid
        public async Task <IHttpActionResult> PostBid(Bid item)
        {
            //get the logged in user information and extract name identifier
            var user = this.User as ClaimsPrincipal;

            if (user != null)
            {
                var userIDClaim = user.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);
                if (userIDClaim != null)
                {
                    item.Bidder = userIDClaim.Value;
                }
            }

            Bid current = await InsertAsync(item);

            //send a notification about the new bid
            var msg = new TemplatePushMessage();

            msg.Add("ItemName", current.AuctionItem.Name);
            msg.Add("BidAmount", item.BidAmount.ToString());

            try
            {
                var outcome = await this.Configuration.GetPushClient().SendAsync(msg);
            }
            catch (Exception ex)
            {
                Configuration.Services.GetTraceWriter().Error("Could not send notifiation message", ex);
            }

            return(CreatedAtRoute("Tables", new { id = current.Id }, current));
        }
Ejemplo n.º 2
0
        // POST tables/Bid
        public async Task <IHttpActionResult> PostBid(Bid item)
        {
            ServiceUser user = this.User as ServiceUser;

            if (user != null && user.Id != null)
            {
                Services.Log.Info(user.Id);
                item.Bidder = user.Id;
                Bid current = await InsertAsync(item);

                //post notification
                var msg = new TemplatePushMessage();
                msg.Add("ItemName", current.AuctionItem.Name);
                msg.Add("BidAmount", item.BidAmount.ToString());
                var outcome = await Services.Push.SendAsync(msg);

                Services.Log.Info(string.Format("Failure: {0}\r\nSuccess: {1}\r\nState: {2}", outcome.Failure, outcome.Success, outcome.State));

                return(CreatedAtRoute("Tables", new { id = current.Id }, current));
            }
            else
            {
                Services.Log.Info("identity is not present");
                return(base.StatusCode(System.Net.HttpStatusCode.BadRequest));
            }
        }
Ejemplo n.º 3
0
        public async Task <HttpResponseMessage> Post()
        {
            var data = await this.Request.Content.ReadAsAsync <JObject>();

            var method = (string)data["method"];

            if (method == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            if (method == "send")
            {
                var serialize = new JsonSerializer();

                var token   = (string)data["token"];
                var payload = (JObject)data["payload"];
                var type    = (string)data["type"];

                if (payload == null || token == null)
                {
                    return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
                }

                if (type == "template")
                {
                    TemplatePushMessage message = new TemplatePushMessage();
                    var keys = payload.Properties();
                    foreach (JProperty key in keys)
                    {
                        Services.Log.Info("Key: " + key.Name);
                        message.Add(key.Name, (string)key.Value);
                    }
                    var result = await Services.Push.SendAsync(message, "World");
                }
                else if (type == "gcm")
                {
                    GooglePushMessage message = new GooglePushMessage();
                    message.JsonPayload = payload.ToString();
                    var result = await Services.Push.SendAsync(message);
                }
                else
                {
                    ApplePushMessage message = new ApplePushMessage();
                    Services.Log.Info(payload.ToString());
                    message.JsonPayload = payload.ToString();
                    var result = await Services.Push.SendAsync(message);
                }
            }
            else
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
        public async Task Post(JObject data)
        {
            var message = new TemplatePushMessage()
            {
                { "patientId",  data.GetValue("patientId").Value<string>() },
                { "doctorId",  data.GetValue("doctorId").Value<string>() },
                { "message", data.GetValue("message").Value<string>() }
            };

            await GetPushClient().SendTemplateNotificationAsync(message);
        }
        public void Dictionary_IsCaseInsensitive()
        {
            // Arrange
            TemplatePushMessage pushMessage = new TemplatePushMessage();
            pushMessage.Add("key", "value");

            // Act
            string actual = pushMessage["KEY"];

            Assert.Equal("value", actual);
        }
        public async Task Post(JObject data)
        {
            var message = new TemplatePushMessage()
            {
                { "patientId", data.GetValue("patientId").Value <string>() },
                { "doctorId", data.GetValue("doctorId").Value <string>() },
                { "message", data.GetValue("message").Value <string>() }
            };

            await GetPushClient().SendTemplateNotificationAsync(message);
        }
Ejemplo n.º 7
0
        private async Task SendPush(Job job)
        {
            TemplatePushMessage message = new TemplatePushMessage()
            {
                { "message", "New job assigned: " + job.Title },
            };

            try
            {
                this.Services.Log.Info("Sending push to user: "******"Push sent: " + pushResponse);
            }
            catch (Exception ex)
            {
                this.Services.Log.Error("Error sending push: " + ex.Message);
            }
        }
        public async Task<HttpResponseMessage> Post()
        {
            var data = await this.Request.Content.ReadAsAsync<JObject>();
            var method = (string)data["method"];

            if (method == null)
            {
                return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
            }

            if (method == "send")
            {
                var serialize = new JsonSerializer();

                var token = (string)data["token"];


                if (data["payload"] == null || token == null)
                {
                    return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
                }

                // Payload could be a string or a dictionary
                var payloadString = data["payload"].ToString();

                var type = (string)data["type"];
                var tag = (string)data["tag"];


                if (type == "template")
                {
                    TemplatePushMessage message = new TemplatePushMessage();
                    var payload = JObject.Parse(payloadString);
                    var keys = payload.Properties();
                    foreach (JProperty key in keys)
                    {
                        this.traceWriter.Info("Key: " + key.Name);

                        message.Add(key.Name, (string)key.Value);
                    }
                    var result = await this.pushClient.SendAsync(message);
                }
                else if (type == "gcm")
                {
                    GooglePushMessage message = new GooglePushMessage();
                    message.JsonPayload = payloadString;
                    var result = await this.pushClient.SendAsync(message);
                }
                else if (type == "apns")
                {
                    ApplePushMessage message = new ApplePushMessage();
                    this.traceWriter.Info(payloadString.ToString());
                    message.JsonPayload = payloadString.ToString();
                    var result = await this.pushClient.SendAsync(message);
                }
                else if (type == "wns")
                {
                    var wnsType = (string)data["wnsType"];
                    WindowsPushMessage message = new WindowsPushMessage();
                    message.XmlPayload = payloadString;
                    message.Headers.Add("X-WNS-Type", type + '/' + wnsType);
                    if (tag != null)
                    {
                        await this.pushClient.SendAsync(message, tag);
                    }
                    else
                    {
                        await this.pushClient.SendAsync(message);
                    }
                }
            }
            else
            {
                return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
            }

            return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
        }
        public async Task <HttpResponseMessage> Post()
        {
            var data = await this.Request.Content.ReadAsAsync <JObject>();

            var method = (string)data["method"];

            if (method == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            if (method == "send")
            {
                var serialize = new JsonSerializer();

                var token = (string)data["token"];


                if (data["payload"] == null || token == null)
                {
                    return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
                }

                // Payload could be a string or a dictionary
                var payloadString = data["payload"].ToString();

                var type = (string)data["type"];
                var tag  = (string)data["tag"];


                if (type == "template")
                {
                    TemplatePushMessage message = new TemplatePushMessage();
                    var payload = JObject.Parse(payloadString);
                    var keys    = payload.Properties();
                    foreach (JProperty key in keys)
                    {
                        this.traceWriter.Info("Key: " + key.Name);

                        message.Add(key.Name, (string)key.Value);
                    }
                    var result = await this.pushClient.SendAsync(message, "World");
                }
                else if (type == "gcm")
                {
                    GooglePushMessage message = new GooglePushMessage();
                    message.JsonPayload = payloadString;
                    var result = await this.pushClient.SendAsync(message);
                }
                else if (type == "apns")
                {
                    ApplePushMessage message = new ApplePushMessage();
                    this.traceWriter.Info(payloadString.ToString());
                    message.JsonPayload = payloadString.ToString();
                    var result = await this.pushClient.SendAsync(message);
                }
                else if (type == "wns")
                {
                    var wnsType = (string)data["wnsType"];
                    WindowsPushMessage message = new WindowsPushMessage();
                    message.XmlPayload = payloadString;
                    message.Headers.Add("X-WNS-Type", type + '/' + wnsType);
                    if (tag != null)
                    {
                        await this.pushClient.SendAsync(message, tag);
                    }
                    else
                    {
                        await this.pushClient.SendAsync(message);
                    }
                }
            }
            else
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }