public PeerCastStationSettings()
 {
     Logger           = new LoggerSettings();
       Listeners        = new ListenerSettings[0];
       AccessController = new AccessControllerSettings();
       YellowPages      = new YellowPageSettings[0];
 }
Ejemplo n.º 2
0
        }                                                           //time you have wait for location variable

        public static async Task <bool> StartListeningAsync(GLFlag flag, int StartDelay = 1000, double minimumTime = 6.0, bool includeHeading = false, ListenerSettings listenerSettings = null)
        {
            flag.Flag = true;
            Task <bool> startAnswer;

            if (AppGeolocator.Current.IsListening)
            {
                startAnswer = Task.FromResult(true);
            }
            else
            {
                startAnswer     = Current.StartListeningAsync(TimeSpan.FromSeconds(minimumTime), 0, includeHeading, listenerSettings);//work if true
                MinimumListTime = minimumTime;
                await Task.Delay(StartDelay);
            }
            return(await startAnswer);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start listening for changes
        /// </summary>
        /// <param name="minimumTime">Time</param>
        /// <param name="minimumDistance">Distance</param>
        /// <param name="includeHeading">Include heading or not</param>
        /// <param name="listenerSettings">Optional settings (iOS only)</param>
        public async Task <bool> StartListeningAsync(TimeSpan minimumTime, double minimumDistance, bool includeHeading = false, ListenerSettings listenerSettings = null)
        {
            if (minimumDistance < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumDistance));
            }

            if (isListening)
            {
                throw new InvalidOperationException("Already listening");
            }

            // if no settings were passed in, instantiate the default settings. need to check this and create default settings since
            // previous calls to StartListeningAsync might have already configured the location manager in a non-default way that the
            // caller of this method might not be expecting. the caller should expect the defaults if they pass no settings.
            if (listenerSettings == null)
            {
                listenerSettings = new ListenerSettings();
            }

#if __IOS__
            var hasPermission = false;
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                if (listenerSettings.AllowBackgroundUpdates)
                {
                    hasPermission = await CheckAlwaysPermissions();
                }
                else
                {
                    hasPermission = await CheckWhenInUsePermission();
                }
            }

            if (!hasPermission)
            {
                throw new GeolocationException(GeolocationError.Unauthorized);
            }
#endif

#if __IOS__ || __MACOS__
            this.includeHeading = includeHeading;
#endif

            // keep reference to settings so that we can stop the listener appropriately later
            this.listenerSettings = listenerSettings;

            var desiredAccuracy = DesiredAccuracy;

            // set background flag
#if __IOS__
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                manager.AllowsBackgroundLocationUpdates = listenerSettings.AllowBackgroundUpdates;
            }

            // configure location update pausing
            if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0))
            {
                manager.PausesLocationUpdatesAutomatically = listenerSettings.PauseLocationUpdatesAutomatically;

                switch (listenerSettings.ActivityType)
                {
                case ActivityType.AutomotiveNavigation:
                    manager.ActivityType = CLActivityType.AutomotiveNavigation;
                    break;

                case ActivityType.Fitness:
                    manager.ActivityType = CLActivityType.Fitness;
                    break;

                case ActivityType.OtherNavigation:
                    manager.ActivityType = CLActivityType.OtherNavigation;
                    break;

                default:
                    manager.ActivityType = CLActivityType.Other;
                    break;
                }
            }
#endif

            // to use deferral, CLLocationManager.DistanceFilter must be set to CLLocationDistance.None, and CLLocationManager.DesiredAccuracy must be
            // either CLLocation.AccuracyBest or CLLocation.AccuracyBestForNavigation. deferral only available on iOS 6.0 and above.
            if (CanDeferLocationUpdate && listenerSettings.DeferLocationUpdates)
            {
                minimumDistance = CLLocationDistance.FilterNone;
                desiredAccuracy = CLLocation.AccuracyBest;
            }

            isListening             = true;
            manager.DesiredAccuracy = desiredAccuracy;
            manager.DistanceFilter  = minimumDistance;

#if __IOS__ || __MACOS__
            if (listenerSettings.ListenForSignificantChanges)
            {
                manager.StartMonitoringSignificantLocationChanges();
            }
            else
            {
                manager.StartUpdatingLocation();
            }
#elif __TVOS__
            //not supported
#endif

            return(true);
        }
        /// <summary>
        /// Start listening for changes
        /// </summary>
        /// <param name="minimumTime">Time</param>
        /// <param name="minimumDistance">Distance</param>
        /// <param name="includeHeading">Include heading or not</param>
        /// <param name="listenerSettings">Optional settings (iOS only)</param>
        public Task <bool> StartListeningAsync(TimeSpan minTime, double minDistance, bool includeHeading = false, ListenerSettings settings = null)
        {
            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance");
            }
            if (IsListening)
            {
                throw new InvalidOperationException("This Geolocator is already listening");
            }

            watcher = new GeoCoordinateWatcher(DesiredAccuracy.ToAccuracy());
            watcher.MovementThreshold = minDistance;
            watcher.PositionChanged  += WatcherOnPositionChanged;
            watcher.StatusChanged    += WatcherOnStatusChanged;
            watcher.Start();

            return(Task.FromResult(true));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start listening for changes
        /// </summary>
        /// <param name="minimumTime">Time</param>
        /// <param name="minimumDistance">Distance</param>
        /// <param name="includeHeading">Include heading or not</param>
        /// <param name="listenerSettings">Optional settings (iOS only)</param>
        public async Task <bool> StartListeningAsync(TimeSpan minimumTime, double minimumDistance, bool includeHeading = false, ListenerSettings listenerSettings = null)
        {
            var hasPermission = await CheckPermissions();

            if (!hasPermission)
            {
                throw new GeolocationException(GeolocationError.Unauthorized);
            }


            var minTimeMilliseconds = minimumTime.TotalMilliseconds;

            if (minTimeMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumTime));
            }
            if (minimumDistance < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumDistance));
            }
            if (IsListening)
            {
                throw new InvalidOperationException("This Geolocator is already listening");
            }

            var providers = Providers;

            listener = new GeolocationContinuousListener(Manager, minimumTime, providers);
            listener.PositionChanged += OnListenerPositionChanged;
            listener.PositionError   += OnListenerPositionError;

            var looper = Looper.MyLooper() ?? Looper.MainLooper;

            listeningProviders.Clear();
            for (var i = 0; i < providers.Length; ++i)
            {
                var provider = providers[i];

                //we have limited set of providers
                if (ProvidersToUseWhileListening != null &&
                    ProvidersToUseWhileListening.Length > 0)
                {
                    //the provider is not in the list, so don't use it.
                    if (!ProvidersToUseWhileListening.Contains(provider))
                    {
                        continue;
                    }
                }


                listeningProviders.Add(provider);
                Manager.RequestLocationUpdates(provider, (long)minTimeMilliseconds, (float)minimumDistance, listener, looper);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public async Task <bool> StartListeningAsync(TimeSpan minTime, double minDistance, bool includeHeading = false, ListenerSettings settings = null)
        {
            var hasPermission = await CheckPermissions();

            if (!hasPermission)
            {
                return(false);
            }


            var minTimeMilliseconds = minTime.TotalMilliseconds;

            if (minTimeMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException("minTime");
            }
            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance");
            }
            if (IsListening)
            {
                throw new InvalidOperationException("This Geolocator is already listening");
            }

            var providers = Providers;

            listener = new GeolocationContinuousListener(Manager, minTime, providers);
            listener.PositionChanged += OnListenerPositionChanged;
            listener.PositionError   += OnListenerPositionError;

            Looper looper = Looper.MyLooper() ?? Looper.MainLooper;

            for (int i = 0; i < providers.Length; ++i)
            {
                Manager.RequestLocationUpdates(providers[i], (long)minTimeMilliseconds, (float)minDistance, listener, looper);
            }

            return(true);
        }
        /// <inheritdoc/>
        public async Task <bool> StartListeningAsync(int minTime, double minDistance, bool includeHeading = false, ListenerSettings settings = null)
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permissions.Abstractions.Permission.Location).ConfigureAwait(false);

            if (status != Permissions.Abstractions.PermissionStatus.Granted)
            {
                Console.WriteLine("Currently does not have Location permissions, requesting permissions");

                var request = await CrossPermissions.Current.RequestPermissionsAsync(Permissions.Abstractions.Permission.Location);

                if (request[Permissions.Abstractions.Permission.Location] != Permissions.Abstractions.PermissionStatus.Granted)
                {
                    Console.WriteLine("Location permission denied, can not get positions async.");
                    return(false);
                }
                providers = manager.GetProviders(enabledOnly: false).Where(s => s != LocationManager.PassiveProvider).ToArray();
            }

            if (providers.Length == 0)
            {
                providers = manager.GetProviders(enabledOnly: false).Where(s => s != LocationManager.PassiveProvider).ToArray();
            }

            if (minTime < 0)
            {
                throw new ArgumentOutOfRangeException("minTime");
            }
            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance");
            }
            if (IsListening)
            {
                throw new InvalidOperationException("This Geolocator is already listening");
            }

            listener = new GeolocationContinuousListener(manager, TimeSpan.FromMilliseconds(minTime), providers);
            listener.PositionChanged += OnListenerPositionChanged;
            listener.PositionError   += OnListenerPositionError;

            Looper looper = Looper.MyLooper() ?? Looper.MainLooper;

            for (int i = 0; i < providers.Length; ++i)
            {
                manager.RequestLocationUpdates(providers[i], minTime, (float)minDistance, listener, looper);
            }

            return(true);
        }
        /// <summary>
        /// Start listening for changes
        /// </summary>
        /// <param name="minimumTime">Time</param>
        /// <param name="minimumDistance">Distance</param>
        /// <param name="includeHeading">Include heading or not</param>
        /// <param name="listenerSettings">Optional settings (iOS only)</param>
        public Task <bool> StartListeningAsync(TimeSpan minimumTime, double minimumDistance, bool includeHeading = false, ListenerSettings listenerSettings = null)
        {
            if (minimumTime.TotalMilliseconds <= 0 && minimumDistance <= 0)
            {
                throw new ArgumentException("You must specify either a minimumTime or minimumDistance, setting a minimumDistance will always take precedence over minTime");
            }

            if (minimumTime.TotalMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumTime));
            }

            if (minimumDistance < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minimumDistance));
            }

            if (isListening)
            {
                throw new InvalidOperationException();
            }

            isListening = true;

            var loc = GetGeolocator();

            loc.ReportInterval    = (uint)minimumTime.TotalMilliseconds;
            loc.MovementThreshold = minimumDistance;
            loc.PositionChanged  += OnLocatorPositionChanged;
            loc.StatusChanged    += OnLocatorStatusChanged;

            return(Task.FromResult(true));
        }
Ejemplo n.º 9
0
 public virtual Listener CreateListener(Proxy owner, ListenerSettings settings)
 {
     return(new Listener(owner, settings));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Start listening for changes
        /// </summary>
        /// <param name="minimumTime">Time</param>
        /// <param name="minimumDistance">Distance</param>
        /// <param name="includeHeading">Include heading or not</param>
        /// <param name="listenerSettings">Optional settings (iOS only)</param>
        public Task <bool> StartListeningAsync(TimeSpan minTime, double minDistance, bool includeHeading = false, ListenerSettings settings = null)
        {
            if (minTime.TotalMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException("minTime");
            }
            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance");
            }
            if (isListening)
            {
                throw new InvalidOperationException();
            }

            isListening = true;

            var loc = GetGeolocator();

            loc.ReportInterval    = (uint)minTime.TotalMilliseconds;
            loc.MovementThreshold = minDistance;
            loc.PositionChanged  += OnLocatorPositionChanged;
            loc.StatusChanged    += OnLocatorStatusChanged;

            return(Task.FromResult(true));
        }
        /// <inheritdoc/>
        public Task <bool> StartListeningAsync(int minTime, double minDistance, bool includeHeading = false, ListenerSettings settings = null)
        {
            if (minTime < 0)
            {
                throw new ArgumentOutOfRangeException("minTime");
            }
            if (minDistance < 0)
            {
                throw new ArgumentOutOfRangeException("minDistance");
            }
            if (isListening)
            {
                throw new InvalidOperationException("Already listening");
            }

            // if no settings were passed in, instantiate the default settings. need to check this and create default settings since
            // previous calls to StartListeningAsync might have already configured the location manager in a non-default way that the
            // caller of this method might not be expecting. the caller should expect the defaults if they pass no settings.
            if (settings == null)
            {
                settings = new ListenerSettings();
            }

            // keep reference to settings so that we can stop the listener appropriately later
            listenerSettings = settings;

            double desiredAccuracy = DesiredAccuracy;

            #region apply settings to location manager
            // set background flag
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                manager.AllowsBackgroundLocationUpdates = settings.AllowBackgroundUpdates;
            }

            // configure location update pausing
            if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0))
            {
                manager.PausesLocationUpdatesAutomatically = settings.PauseLocationUpdatesAutomatically;

                if (settings.ActivityType == ActivityType.AutomotiveNavigation)
                {
                    manager.ActivityType = CLActivityType.AutomotiveNavigation;
                }
                else if (settings.ActivityType == ActivityType.Fitness)
                {
                    manager.ActivityType = CLActivityType.Fitness;
                }
                else if (settings.ActivityType == ActivityType.Other)
                {
                    manager.ActivityType = CLActivityType.Other;
                }
                else if (settings.ActivityType == ActivityType.OtherNavigation)
                {
                    manager.ActivityType = CLActivityType.OtherNavigation;
                }
            }

            // to use deferral, CLLocationManager.DistanceFilter must be set to CLLocationDistance.None, and CLLocationManager.DesiredAccuracy must be
            // either CLLocation.AccuracyBest or CLLocation.AccuracyBestForNavigation. deferral only available on iOS 6.0 and above.
            if (CanDeferLocationUpdate && settings.DeferLocationUpdates)
            {
                minDistance     = CLLocationDistance.FilterNone;
                desiredAccuracy = CLLocation.AccuracyBest;
            }
            #endregion

            isListening             = true;
            manager.DesiredAccuracy = desiredAccuracy;
            manager.DistanceFilter  = minDistance;

            if (settings?.ListenForSignificantChanges ?? false)
            {
                manager.StartMonitoringSignificantLocationChanges();
            }
            else
            {
                manager.StartUpdatingLocation();
            }

            if (includeHeading && CLLocationManager.HeadingAvailable)
            {
                manager.StartUpdatingHeading();
            }

            return(Task.FromResult(true));
        }
        public async Task <bool> StartListeningAsync(TimeSpan minTime, double minDistance, bool includeHeading = false, ListenerSettings listenerSettings = null)
        {
            if (!client.IsConnected)
            {
                await ConnectAsync();
            }

            if (!client.IsConnected)
            {
                return(await Task.FromResult(false));
            }

            var minTimeMilliseconds = (long)minTime.TotalMilliseconds;
            var locationRequest     = new LocationRequest();

            locationRequest.SetSmallestDisplacement(Convert.ToInt64(minDistance))
            .SetFastestInterval(minTimeMilliseconds)
            .SetInterval(minTimeMilliseconds)
            .SetMaxWaitTime(minTimeMilliseconds * 6)
            .SetPriority(GetPriority());

            var result = await LocationServices.FusedLocationApi
                         .RequestLocationUpdatesAsync(client, locationRequest, callbacks);

            if (result.IsSuccess)
            {
                IsListening = true;
            }

            return(result.IsSuccess);
        }