예제 #1
0
        private static async Task PushMessagesToHub(CancellationToken ct)
        {
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    PushMessage msgObject = msgSendQueue.Take();

                    if (msgObject == null)
                    {
                        continue;
                    }

                    string message = msgObject.ToString();
                    switch (msgObject.Type)
                    {
                    case PushMessage.PushType.Android:
                        await _client.SendGcmNativeNotificationAsync(message);

                        break;

                    case PushMessage.PushType.Apple:
                        await _client.SendAppleNativeNotificationAsync(message);

                        break;

                    case PushMessage.PushType.Windows:
                        await _client.SendWindowsNativeNotificationAsync(message);

                        break;

                    case PushMessage.PushType.WindowsPhone:
                        await _client.SendWindowsNativeNotificationAsync(message);

                        break;
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #2
0
        public ActionResult SendMessage(string message, string data)
        {
            string[]           checkedItems = JsonConvert.DeserializeObject <string[]>(data);
            List <SmartDevice> items        = BlobTable <SmartDevice> .GetAllItems();

            if (items != null && items.Count > 0)
            {
                foreach (string chkitem in checkedItems)
                {
                    int         index = items.FindIndex(i => i.Id == chkitem);
                    SmartDevice item  = (index >= 0) ? items[index] : null;
                    if (item != null)
                    {
                        Scf.Net.PushHub.PushMessage msg = new Scf.Net.PushHub.PushMessage();
                        msg.DeviceId = item.DeviceId;
                        msg.Message  = message;
                        msg.Type     = Scf.Net.PushHub.PushMessage.PushType.Unknown;

                        switch (item.Platform)
                        {
                        case SmartDevice.PlatformType.Android:
                            msg.Type = Scf.Net.PushHub.PushMessage.PushType.Android;
                            break;

                        case SmartDevice.PlatformType.Apple:
                            msg.Type = Scf.Net.PushHub.PushMessage.PushType.Apple;
                            break;

                        case SmartDevice.PlatformType.UWP:
                            msg.Type = Scf.Net.PushHub.PushMessage.PushType.Windows;
                            break;

                        case SmartDevice.PlatformType.Windows:
                            msg.Type = Scf.Net.PushHub.PushMessage.PushType.WindowsPhone;
                            break;
                        }
                        PushManager.SendMessage(msg);
                    }
                }
            }
            //Task.Run(async () =>
            //{
            //    var tmpitem = await SmartMonitorDataManager<SmartDevice>.GetItemsAsync(d => !d.Completed);
            //    List<SmartDevice> items = tmpitem.ToList();
            //    foreach (string itemid in checkedItems)
            //    {
            //        int index = items.FindIndex(i => i.Id == itemid);
            //        SmartDevice item = (index >= 0) ? items[index] : null;
            //        if (item != null)
            //        {
            //            PushMessage msg = new PushMessage();
            //            msg.DeviceId = item.DeviceId;
            //            msg.Message = message;
            //            msg.Type = PushMessage.PushType.Unknown;

            //            switch (item.Platform)
            //            {
            //                case SmartDevice.PlatformType.Android:
            //                    msg.Type = PushMessage.PushType.Android;
            //                    break;
            //                case SmartDevice.PlatformType.Apple:
            //                    msg.Type = PushMessage.PushType.Apple;
            //                    break;
            //                case SmartDevice.PlatformType.UWP:
            //                    msg.Type = PushMessage.PushType.Windows;
            //                    break;
            //                case SmartDevice.PlatformType.Windows:
            //                    msg.Type = PushMessage.PushType.Windows;
            //                    break;
            //            }
            //            PushNotificationManager.Instance.SendMessage(msg);
            //        }
            //    }
            //});
            return(RedirectToAction("Index"));
        }
예제 #3
0
 public static void SendMessage(PushMessage msg)
 {
     msgSendQueue.Add(msg);
 }