Make Windows 8 detect Ranorex as location service user

Class library usage, coding and language questions.
Brent Arata
Posts: 12
Joined: Mon Jan 27, 2014 10:33 pm

Make Windows 8 detect Ranorex as location service user

Post by Brent Arata » Tue Feb 03, 2015 12:18 am

I would like Ranorex to utilize .NET's location services in Windows 8 for geofencing automation but do not know how to configure Ranorex to do so. Is there a way to do this via Ranorex or in Windows 8?
Last edited by Support Team on Tue Feb 10, 2015 12:09 pm, edited 1 time in total.
Reason: Corrected Windows version in title

Brent Arata
Posts: 12
Joined: Mon Jan 27, 2014 10:33 pm

Re: Make Windows 8 detect Ranorex as location service user

Post by Brent Arata » Tue Feb 03, 2015 1:47 am

I was able to retrieve the coordinates by enabling location services in windows 8 by using the GeoCoordinateWatcher under the System.Device.Location namespace. However, I am still confused as to why the StatusChanged event handler was not being executed through Ranorex's implementation of the .NET framework.

Code: Select all


private GeoCoordinateWatcher watcher;

void ITestModule.Run() {
   ShowStatusUpdates();
}
		
private void ShowStatusUpdates() {
  watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
  watcher.TryStart(false, TimeSpan.FromSeconds(60));
			
  if (watcher.Permission.Equals(GeoPositionPermission.Granted)) {
	watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(StatusChanged);
	while (!watcher.Status.Equals(GeoPositionStatus.Ready) && !watcher.Status.Equals(GeoPositionStatus.NoData)) {
		Delay.Milliseconds(20);
       }
	GeoCoordinate newGeoCoordinate = watcher.Position.Location;
		System.Diagnostics.Debug.WriteLine("Lat: {0}, Long: {1}",
		newGeoCoordinate.Latitude,
		newGeoCoordinate.Longitude);
			watcher.Stop();
			watcher.Dispose();
   }
   else if (watcher.Permission.Equals(GeoPositionPermission.Denied) ||     watcher.Permission.Equals(GeoPositionPermission.Unknown)) {
  System.Diagnostics.Debug.WriteLine("Location services are disabled.  To enable them, Goto Settings -   Location - Enable Location Services.");
	watcher.Stop();
	watcher.Dispose();
  }
}
		
private void StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) {
	switch (e.Status) {
                case GeoPositionStatus.Initializing:
                    System.Diagnostics.Debug.WriteLine("Working on location fix");
                    break;

                case GeoPositionStatus.Ready:
                    System.Diagnostics.Debug.WriteLine("Have location");
                    GeoCoordinate newGeoCoordinate = watcher.Position.Location;
					  System.Diagnostics.Debug.WriteLine("Lat: {0}, Long: {1}",
			            newGeoCoordinate.Latitude,
			            newGeoCoordinate.Longitude);
					 watcher.Stop();
					 watcher.Dispose();
                    break;

                case GeoPositionStatus.NoData:
                    System.Diagnostics.Debug.WriteLine("No data");
                    watcher.Stop();
		    watcher.Dispose();
                    break;

                case GeoPositionStatus.Disabled:
                    System.Diagnostics.Debug.WriteLine("Disabled");
                    watcher.Stop();
		    watcher.Dispose();
                    break;
            }
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Make Windows 8 detect Ranorex as location service user

Post by Support Team » Tue Feb 10, 2015 1:18 pm

Brent Arata wrote:owever, I am still confused as to why the StatusChanged event handler was not being executed through Ranorex's implementation of the .NET framework.
Ranorex uses the default .NET Framework, it does not provide a special implementation of it.

I don't think that Ranorex has anything in particular to do with the fact that you don't see the event being fired. IMHO it is rather a timing issue. When I tried to execute your code, I only got the event every second time, even if I was not using Ranorex. When I then loaded the Ranorex plugins, I first did not get the event, but suddenly got it every time.

Great that you got the PositionChange event working.

Regards,
Alex
Ranorex Team
.
Image