protected override void OnInvoke(ScheduledTask task) { bool driverLoggedIn = false; ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60)); // Read manually updated driver location from file. string DriverLocation = ReadLocationFromFile(); //getGpsLocation(); //Getting GPS location from GPS sensor //GPSWait.WaitOne(); /* Reading isolated storage files for login details in main mobile application * if the logged in user is driver then update location using GPS */ IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication(); StreamReader Reader = null; string ReadText = ""; try { Reader = new StreamReader(new IsolatedStorageFileStream("LoginDetails.txt", FileMode.Open, fileStorage)); ReadText = Reader.ReadLine(); if (ReadText.Equals("Customer Logged In")) { driverLoggedIn = false; } else if (ReadText.Equals("Driver Logged In")) { driverLoggedIn = true; // Storing Driver ID ReadText = Reader.ReadLine(); string[] token = ReadText.Split(new char[] { ':' }); DriverID = Convert.ToInt32(token[1]); // Storing Cab ID ReadText = Reader.ReadLine(); token = ReadText.Split(new char[] { ':' }); CabID = Convert.ToInt32(token[1]); } Reader.Close(); } catch { MessageBox.Show("File it not created"); } if (driverLoggedIn && DriverID != -1) { ServiceReference1.ServiceClient clientForTesting = new ServiceReference1.ServiceClient(); if (DriverLocation != "LocationNotUpdatedManually" && DriverLocation != "Exception") { // Calling web service function to update Cab Location clientForTesting.UpdateLocationCompleted += new EventHandler<ServiceReference1.UpdateLocationCompletedEventArgs>(TestCallback); clientForTesting.UpdateLocationAsync(CabLatitude, CabLongitude, CabID); // lock the thread until web call is completed ServiceWait.WaitOne(); } ServiceWait = new AutoResetEvent(false); // Calling web service to check if there are any notifications regarding order clientForTesting.CheckForDriverBookingCompleted += new EventHandler<ServiceReference1.CheckForDriverBookingCompletedEventArgs>(CheckForDriverBookingCompletedReturnFunction); clientForTesting.CheckForDriverBookingAsync(CabID); ServiceWait.WaitOne(); // Calling web service to check if there are any notifications regard booking cancellation clientForTesting.CheckForDriverCancelledBookingsCompleted += new EventHandler<ServiceReference1.CheckForDriverCancelledBookingsCompletedEventArgs>(CheckForCancelledBookingsReturnFunction); clientForTesting.CheckForDriverCancelledBookingsAsync(CabID); ServiceWati2.WaitOne(); } //var toast = new ShellToast { Title = DateTime.Now.ToShortTimeString(), Content = "Background Agent Launched" }; //toast.Show(); NotifyComplete(); }