예제 #1
0
        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.");
            }
        }
예제 #2
0
        private async void Initialize()
        {// Create new Map with basemap
            Map myMap = new Map(Basemap.CreateImageryWithLabels());

            myMap.InitialViewpoint = new Viewpoint(34.05293, -118.24368, 6000);

            // Assign the map to the MapView
            MyMapView.Map = myMap;



            try
            {
                // Initialize the LocatorTask with the provided service Uri
                _geocoder = await LocatorTask.CreateAsync(_serviceUri);

                var vm = CoreDependencyService.GetViewModel <SearchViewModel>();
                vm.MapView = MyMapView;
                // Enable the UI controls now that the LocatorTask is ready
                MySuggestButton.IsEnabled = true;
                MySearchBar.IsEnabled     = true;
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }
        }
예제 #3
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"]);
        }
예제 #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 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 }
            };
        }
        public CurrentLocationPage()
        {
            InitializeComponent();
            Initialize();
            var vm = CoreDependencyService.GetViewModel <SearchViewModel>();

            vm.MapView = MyMapView;
        }
예제 #8
0
        private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
        {
            CoreDependencyService.GetService <ILogService, LogService>().LogException(
                unobservedTaskExceptionEventArgs.Exception,
                "MainApplication -TaskSchedulerOnUnobservedTaskException");

            unobservedTaskExceptionEventArgs.Exception.ConsoleWrite();
        }
예제 #9
0
        private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
        {
            var ex = unhandledExceptionEventArgs.ExceptionObject as Exception;

            CoreDependencyService.GetService <ILogService, LogService>().LogException(
                ex,
                "MainApplication -CurrentDomainOnUnhandledException");

            ex.ConsoleWrite();
        }
예제 #10
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);
        }
        public HubCommunicationLogic()
        {
            hub = new HubConnectionBuilder()
                  .WithUrl(userBase)
                  .WithConsoleLogger()
                  .Build();

            hub.On <string>("Send", data =>
            {
                CoreDependencyService.SendViewModelMessage <TodoViewModel>(CoreSettings.DataUpdated, "data");
            });
        }
예제 #12
0
 public UsersCell() : base()
 {
     ContextActions.Add(new MenuItem()
     {
         Text    = "Make Favorite",
         Command = new Command(async(obj) =>
         {
             var item = ((RandomUser)BindingContext);
             await CoreDependencyService.GetViewModel <AppViewModel>().AddToFavorites(item);
         })
     });
 }
예제 #13
0
 public FavoritesCell() : base()
 {
     ContextActions.Add(new MenuItem()
     {
         Text          = "Delete",
         IsDestructive = true,
         Command       = new Command(async(obj) =>
         {
             var item = ((RandomUser)BindingContext);
             await CoreDependencyService.GetViewModel <AppViewModel>().RemoveFavorites(item);
         })
     });
 }
예제 #14
0
        public TodoPageCell()
        {
            this.Height = 65;
            title       = new Label()
            {
                Margin   = new Thickness(0, 8, 0, 0),
                FontSize = 22
            };
            date = new Label()
            {
                FontSize  = 14,
                TextColor = Color.DarkGray,
                Margin    = new Thickness(0, 0, 0, 8),
            };

            var rightPanel = new StackLayout()
            {
                Children = { title, date }
            };

            var img = new CachedImage()
            {
                Margin                = new Thickness(10, 0, 3, 0),
                HeightRequest         = 55,
                WidthRequest          = 55,
                DownsampleHeight      = 55,
                DownsampleWidth       = 55,
                Aspect                = Aspect.AspectFit,
                CacheDuration         = TimeSpan.FromDays(30),
                VerticalOptions       = LayoutOptions.Center,
                DownsampleUseDipUnits = true,
                Source                = "todorowimage.png"
            };

            this.ContextActions.Add(new MenuItem()
            {
                Text          = "Delete",
                IsDestructive = true,
                Command       = new Command(async(obj) => {
                    var item = (Todo)BindingContext;
                    await CoreDependencyService.GetViewModel <TodoViewModel>().DeleteItem(item);
                })
            });


            View = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Children    = { img, rightPanel }
            };
        }
 private void StartBackgroundingMethod(object obj)
 {
     if (BackgroundButtonTitle.StartsWith("Stop", System.StringComparison.OrdinalIgnoreCase))
     {
         DataBLL.TimerService.Stop();
         BackgroundButtonTitle = "Background Timer";
     }
     else
     {
         var timerService = CoreDependencyService.GetService <IIntervalCallback, TimerCallbackService>(true);
         DataBLL.TimerService.Start(1, timerService);
         BackgroundButtonTitle = $"Stop {BackgroundButtonTitle}";
     }
 }
        public void TimeElapsedEvent()
        {
            //example of routing execution to some view model in the application
            var vm = CoreDependencyService.GetViewModel <SimpleViewModel>();

            vm.DisplayNotification(new LocalNotification()
            {
                Id      = 1,
                Title   = "Timer Event",
                Icon    = "icon.png",
                Message = $"The timer event fired {DateTime.Now.ToShortTimeString()}"
            });

#if DEBUG
            Console.WriteLine("*****************   I am a little teapot *****************************");
#endif
        }
예제 #17
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            var fileSrv = CoreDependencyService.GetService <IFileStore, FileStore>();

            fileSrv?.GetAsync <InAppBillingPurchase>("adsRemoved").ContinueWith((t) => {
                var result = t.Result;
                if (result.Error != null)
                {
                    if (AdBuddizHandler.Instance.IsReadyToShowAd)
                    {
                        AdBuddizHandler.Instance.ShowAd();
                    }
                }
            });
        }
예제 #18
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);
            }
        }
예제 #19
0
        public Nav4()
        {
            this.NeedOverrideSoftBackButton = true;
#if __IOS__
            this.OverrideBackButton = true;
#endif

            this.Title = "Nav4";

            var btnBack = new CoreButton()
            {
                Style        = CoreStyles.LightOrange,
                Text         = "Back",
                AutomationId = "btnBack",
                Command      = new Command(async(obj) =>
                {
                    await Navigation.PopTo <Nav2>(true);
                })
            };

            var btnRelease = new CoreButton()
            {
                Style        = CoreStyles.LightOrange,
                Text         = "Release Resources",
                AutomationId = "btnRelease",
                Command      = new Command((obj) =>
                {
                    CoreDependencyService.ReleaseResources <Nav4ViewModel>();
                })
            };

            var lbl = new Label()
            {
                Margin = 5
            };
            lbl.SetBinding(Label.TextProperty, "AnimalDescription");

            Content = new CompressedStackLayout()
            {
                Padding  = 20,
                Spacing  = 10,
                Children = { btnBack, btnRelease, lbl }
            };
        }
예제 #20
0
        public override async void PerformFetch(UIApplication application, Action <UIBackgroundFetchResult> completionHandler)
        {
            Console.WriteLine("PerformFetch called...");
            var result = UIBackgroundFetchResult.NoData;

            try
            {
                var logic = CoreDependencyService.GetBusinessLayer <TodoBusinessLogic>();
                var data  = await logic.GetAllByCurrentUser();

                result = UIBackgroundFetchResult.NewData;
            }
            catch (Exception ex)
            {
                result = UIBackgroundFetchResult.Failed;
            }
            finally
            {
                completionHandler(result);
            }
        }
예제 #21
0
 void SendMessageToMainPage(string body)
 {
     CoreDependencyService.SendViewModelMessage(CoreSettings.RemoteNotificationReceived, body);
 }
예제 #22
0
        private void Delete()
        {
            var str = (string)this.BindingContext;

            CoreDependencyService.GetViewModel <ContextMenuViewModel>().OnViewMessageReceived("NameDeleted", str);
        }
예제 #23
0
 public static void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
 {
     CoreSettings.DeviceToken = deviceToken;
     CoreDependencyService.SendViewModelMessage(CoreSettings.TokenReceived, deviceToken);
 }
        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 }
            };
        }