public async Task <IHttpActionResult> TestNotificationAsync(int deviceId)
        {
            try
            {
                var message = new InformationDeviceMessage
                {
                    DeviceId    = deviceId,
                    Direction   = MovingDirection.DownOrExit,
                    Door        = DoorStatus.Open,
                    Location    = "test location",
                    Other       = "other",
                    Status      = Status.Alert,
                    Temperature = 22
                };

                var response = await PushNotificationFacade.Instance.Service.SendNotificationAsync(deviceId, message);

                if (response.IsSuccess == false)
                {
                    return(BadRequest(response.Message));
                }
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            PushNotificationFacade.Instance.Initialize("Endpoint=sb://solutrack.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=SZNnZdpl0lITr/6EdopOLVPuCRdZVWa05FLYYbALOWs=", "solutrack");

            System.Console.WriteLine("Menu:");
            System.Console.WriteLine("1. Login");
            System.Console.WriteLine("2. Logout");
            System.Console.WriteLine("3. Send Notification");
            System.Console.WriteLine("4. Exit");


            string input = System.Console.ReadLine();

            while (input != "4")
            {
                switch (input)
                {
                case ("1"):
                {
                    System.Console.Write("Enter the device handle: ");
                    string handle = System.Console.ReadLine();
                    if (string.IsNullOrEmpty(handle))
                    {
                        return;
                    }

                    var registrationResponse = AsyncHelpers.RunSync <Response <string> >(() =>
                        {
                            return(PushNotificationFacade.Instance.Service.RegisterDeviceAsync(Platform.gcm, handle, "synergo", new List <int> {
                                1, 2, 3
                            }));
                        });
                    if (registrationResponse.IsSuccess == false)
                    {
                        System.Console.WriteLine(registrationResponse.Message);
                        return;
                    }

                    registrationId = registrationResponse.Value;
                    System.Console.WriteLine("Your device is registered");
                    break;
                }

                case ("2"):
                {
                    var unregisterResponse = AsyncHelpers.RunSync <Response>(() =>
                        {
                            return(PushNotificationFacade.Instance.Service.UnregisterDeviceAsync(registrationId));
                        });
                    if (unregisterResponse.IsSuccess == false)
                    {
                        System.Console.WriteLine(unregisterResponse.Message);
                        return;
                    }
                    //registrationId = string.Empty;
                    System.Console.WriteLine("Your device is unregistered");
                    break;
                }

                case ("3"):
                {
                    var message = new InformationDeviceMessage
                    {
                        DeviceId    = 1,
                        Direction   = MovingDirection.DownOrExit,
                        Door        = DoorStatus.Open,
                        Location    = "test location",
                        Other       = "other",
                        Status      = Status.Alert,
                        Temperature = 22
                    };

                    var sendResponse = AsyncHelpers.RunSync <Response>(() =>
                        {
                            return(PushNotificationFacade.Instance.Service.SendNotificationAsync(1, message));
                        });
                    if (sendResponse.IsSuccess == false)
                    {
                        System.Console.WriteLine(sendResponse.Message);
                        return;
                    }
                    //registrationId = string.Empty;
                    System.Console.WriteLine("Notification sent");
                    break;
                }
                }
                input = System.Console.ReadLine();
            }
        }
 public async Task <Response> SendNotificationAsync(int deviceId, InformationDeviceMessage message)
 {
     return(await SendGenericNotificationAsync(deviceId, message, MessageType.device_info));
 }