コード例 #1
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            var dict = new Dictionary <string, string>();

            base.OnMessageReceived(message);

            if (message.GetNotification() != null)
            {
                dict.Add("Title", message.GetNotification().Title);
                dict.Add("Message", message.GetNotification().Body);
                foreach (var key in message.Data.Keys)
                {
                    dict.Add(key, message.Data[key]);
                }
            }

            // NOTE: test messages sent via the Azure portal will be received here
            else
            {
                foreach (var key in message.Data.Keys)
                {
                    dict.Add(key, message.Data[key]);
                }
            }

            CoreDependencyService.SendViewModelMessage(CoreSettings.RemoteNotificationReceived, dict);

            CoreDependencyService.GetDependency <INotificationManager>().SendNotification(dict["Title"], dict["Message"]);
        }
コード例 #2
0
        public PageTwoCell()
        {
            lblName = new Label()
            {
                FontSize = 12
            };
            lblPhone = new Label()
            {
                TextColor = Color.Gray,
                FontSize  = 10
            };


            ContextActions.Add(new MenuItem()
            {
                Text          = "Delete",
                IsDestructive = true,
                Command       = new Command((obj) => {
                    var p = (Person)this.BindingContext;
                    CoreDependencyService.SendViewModelMessage <AppViewModel>(CoreSettings.DeletePersonTag, p.Id);
                })
            });

            View = new StackLayout()
            {
                Padding  = new Thickness(10, 5, 0, 5),
                Children = { lblName, lblPhone }
            };
        }
コード例 #3
0
ファイル: CoreAzurePush.IOS.cs プロジェクト: thejibb/Core
        public static void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // make sure we have a payload
            if (options != null && options.ContainsKey(new NSString("aps")))
            {
                // get the APS dictionary and extract message payload. Message JSON will be converted
                // into a NSDictionary so more complex payloads may require more processing
                NSDictionary aps        = options.ObjectForKey(new NSString("aps")) as NSDictionary;
                string       payload    = string.Empty;
                NSString     payloadKey = new NSString("alert");
                if (aps.ContainsKey(payloadKey))
                {
                    payload = aps[payloadKey].ToString();
                }

                if (!string.IsNullOrWhiteSpace(payload))
                {
                    CoreDependencyService.SendViewModelMessage(CoreSettings.RemoteNotificationReceived, payload);
                }
            }
            else
            {
                Debug.WriteLine($"Received request to process notification but there was no payload.");
            }
        }
コード例 #4
0
        public override void OnNewToken(string token)
        {
            CoreSettings.DeviceToken = token;
            CoreDependencyService.SendViewModelMessage(CoreSettings.TokenReceived, token);

            base.OnNewToken(token);
        }
コード例 #5
0
        public static void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            if (options != null && options.ContainsKey(new NSString("aps")))
            {
                var dict      = new Dictionary <string, string>();
                var aps       = options.ObjectForKey(new NSString("aps")) as NSDictionary;
                var alertDict = aps.ObjectForKey(new NSString("alert")) as NSDictionary;

                var title    = new NSString("title");
                var message  = new NSString("messageParam");
                var metaData = new NSString("metaData");

                if (alertDict.ContainsKey(title))
                {
                    dict.Add("Title", alertDict[title].ToString());
                }
                if (alertDict.ContainsKey(title))
                {
                    dict.Add("Message", alertDict[message].ToString());
                }
                if (aps.ContainsKey(metaData))
                {
                    dict.Add("MetaData", aps[metaData].ToString());
                }

                if (dict.Count != 0)
                {
                    CoreDependencyService.SendViewModelMessage(CoreSettings.RemoteNotificationReceived, dict);
                }
            }
            else
            {
                Debug.WriteLine($"Received request to process notification but there was no payload.");
            }
        }
コード例 #6
0
        public override void OnTokenRefresh()
        {
            string token = FirebaseInstanceId.Instance.Token;

            // NOTE: logging the token is not recommended in production but during
            // development it is useful to test messages directly from Firebase
            Log.Info(debugTag, $"Token received: {token}");

            CoreSettings.DeviceToken = token;
            CoreDependencyService.SendViewModelMessage(CoreSettings.TokenReceived, token);
        }
コード例 #7
0
        public HubCommunicationLogic()
        {
            hub = new HubConnectionBuilder()
                  .WithUrl(userBase)
                  .WithConsoleLogger()
                  .Build();

            hub.On <string>("Send", data =>
            {
                CoreDependencyService.SendViewModelMessage <TodoViewModel>(CoreSettings.DataUpdated, "data");
            });
        }
コード例 #8
0
        public async Task ConnectToServerAsync()
        {
            var uri = new Uri(CoreSettings.Config.WebApi["websocket"]);
            await client.ConnectAsync(uri, cts.Token);

#if __IOS__
            //await client.ConnectAsync(new Uri("ws://localhost:5001"), cts.Token);
#else
            //await client.ConnectAsync(new Uri("ws://10.0.2.2:5000"), cts.Token);
#endif

            UpdateClientState();

            await Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    WebSocketReceiveResult result;
                    var message = new ArraySegment <byte>(new byte[4096]);
                    do
                    {
                        result                  = await client.ReceiveAsync(message, cts.Token);
                        var messageBytes        = message.Skip(message.Offset).Take(result.Count).ToArray();
                        string serialisedMessae = Encoding.UTF8.GetString(messageBytes);

                        try
                        {
                            var msg = JsonConvert.DeserializeObject <Message>(serialisedMessae);
                            CoreDependencyService.SendViewModelMessage(CoreSettings.WebSocketMessageReceived, msg);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Invalide message format. {ex.Message}");
                        }
                    } while (!result.EndOfMessage);
                }
            }, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            void UpdateClientState()
            {
                var isConnected = client.State == WebSocketState.Open ? true : false;

                CoreDependencyService.SendViewModelMessage(CoreSettings.WebSocketStateChanged, isConnected);
            }
        }
コード例 #9
0
        public AppointmentCell()
        {
            this.Height = 65;
            img         = new CachedImage()
            {
                Margin                = new Thickness(8, 0, 4, 0),
                HeightRequest         = 32,
                WidthRequest          = 32,
                DownsampleWidth       = 32,
                DownsampleHeight      = 32,
                DownsampleUseDipUnits = true,
                RetryCount            = 0,
                RetryDelay            = 250,
                LoadingPlaceholder    = "placeholder.png",
                CacheDuration         = TimeSpan.FromDays(10),
                Source                = "calendar.png"
            };

            lblTitle = new Label()
            {
                Margin = new Thickness(5, 5, 5, -5),
            };


            lblFullDisplay = new Label()
            {
                Style = CoreStyles.AddressCell,
            };

            var rightPanel = new StackLayout()
            {
                Padding  = 0,
                Children = { lblTitle, lblFullDisplay }
            };

            embeddedMenu = new MenuItem()
            {
                Text          = "Embedded",
                IsDestructive = false
            };
            embeddedMenu.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            ContextActions.Add(embeddedMenu);

            deleteMenu = new MenuItem()
            {
                Text          = "Delete",
                IsDestructive = true,
                AutomationId  = "deleteMenu",
                Command       = new Command(async(obj) =>
                {
                    var appt             = (Appointment)obj;
                    appt.MarkedForDelete = true;
                    var sqlite           = CoreDependencyService.GetService <ISqliteDb, SqliteDb>();
                    var result           = await sqlite.AddOrUpdate <Appointment>(appt);
                    if (result.Success)
                    {
                        CoreDependencyService.SendViewModelMessage <DataExampleViewModel>(CoreSettings.RefreshAppoints, null);
                    }
                })
            };
            deleteMenu.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            ContextActions.Add(deleteMenu);

            View = new StackContainer(true)
            {
                Orientation = StackOrientation.Horizontal,
                Children    = { img, rightPanel }
            };
        }
コード例 #10
0
ファイル: CoreAzurePush.IOS.cs プロジェクト: thejibb/Core
 public static void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
 {
     CoreSettings.DeviceToken = deviceToken;
     CoreDependencyService.SendViewModelMessage(CoreSettings.TokenReceived, deviceToken);
 }
コード例 #11
0
ファイル: FirebaseService.Droid.cs プロジェクト: thejibb/Core
 void SendMessageToMainPage(string body)
 {
     CoreDependencyService.SendViewModelMessage(CoreSettings.RemoteNotificationReceived, body);
 }