public static async Task <IActionResult> StartTripManager([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "tripmanagers")] HttpRequest req, [OrchestrationClient] DurableOrchestrationClient context, ILogger log) { try { string requestBody = new StreamReader(req.Body).ReadToEnd(); TripItem trip = JsonConvert.DeserializeObject <TripItem>(requestBody); // The manager instance id is the trip code var instanceId = trip.Code; await StartInstance(context, trip, instanceId, log); //NOTE: Unfortunately this does not work the same way as before when it was using HttpMessageResponse //var reqMessage = req.ToHttpRequestMessage(); //var res = context.CreateCheckStatusResponse(reqMessage, trip.Code); //res.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromSeconds(10)); //return (ActionResult)new OkObjectResult(res.Content); return((ActionResult) new OkObjectResult("NOTE: No status URLs are returned!")); } catch (Exception ex) { var error = $"StartTripManager failed: {ex.Message}"; log.LogError(error); return(new BadRequestObjectResult(error)); } }
public static async Task Cleanup([ActivityTrigger] TripItem trip, ILogger log) { log.LogInformation($"Cleanup for {trip.Code} starting...."); if (ServiceFactory.GetSettingService().IsPersistDirectly()) { var persistenceService = ServiceFactory.GetPersistenceService(); trip = await persistenceService.AbortTrip(trip); } else { //TODO: Go through the Trips APIs } await Externalize(trip, Constants.EVG_SUBJECT_TRIP_ABORTED); // Send an event telemetry ServiceFactory.GetLoggerService().Log("Trip aborted", new Dictionary <string, string> { { "Code", trip.Code }, { "Passenger", $"{trip.Passenger.FirstName} {trip.Passenger.LastName}" }, { "Destination", $"{trip.Destination.Latitude} - {trip.Destination.Longitude}" }, { "Mode", $"{trip.Type}" } }); }
public async Task <IActionResult> PutTripItem([FromRoute] string id, [FromBody] TripItem tripItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tripItem.trip_id) { return(BadRequest()); } _context.Entry(tripItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TripItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ObservableCollection <UserItem> > GetUsersTripsItemsAsync(TripItem tripItem) { try { IEnumerable <TripUserItem> items = await tripuserTable.Where(i => i.TripId == tripItem.Id).ToEnumerableAsync(); List <UserItem> users = new List <UserItem>(); foreach (var id in items) { IEnumerable <UserItem> user = await userTable.Where(i => i.Id == id.UserId).ToEnumerableAsync(); users.AddRange(user.ToList()); } return(new ObservableCollection <UserItem>(users)); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"Sync error: {0}", e.Message); } return(null); }
public async Task RecycleTripDriver(TripItem trip) { var error = ""; try { var driver = trip.Driver; if (driver != null) { driver = await RetrieveDriver(trip.Driver.Code); driver.IsAcceptingRides = true; await UpsertDriver(driver, true); } } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - RecycleTripDriver - Error: {error}"); } }
public async Task <TripItem> AbortTrip(TripItem trip) { var error = ""; try { trip.EndDate = DateTime.Now; trip.IsAborted = true; trip = await UpsertTrip(trip, true); var driver = trip.Driver; if (driver != null) { driver = await RetrieveDriver(trip.Driver.Code); driver.IsAcceptingRides = true; await UpsertDriver(driver, true); } return(trip); } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - AbortTrip - Error: {error}"); } }
public async Task <TripItem> CheckTripCompletion(TripItem trip) { var error = ""; try { // TODO: We need a way to determine when the trip is over // TODO: It is ridiculous, but for now, I am checking to see if the driver location equals the trip destination location :-) var driver = await RetrieveDriver(trip.Driver.Code); if (driver != null && driver.Latitude == trip.Destination.Latitude && driver.Longitude == trip.Destination.Longitude) { trip.EndDate = DateTime.Now; } trip.MonitorIterations++; trip = await UpsertTrip(trip, true); return(trip); } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - CheckTripCompletion - Error: {error}"); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Payment); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); var textViewName = FindViewById <TextView>(Resource.Id.textViewName); var textViewAmount = FindViewById <TextView>(Resource.Id.textViewAmount); listView = FindViewById <ListView>(Resource.Id.listView1); tripFriends = JsonConvert.DeserializeObject <ObservableCollection <UserItem> >(Intent.GetStringExtra("Friends")); paymentItem = JsonConvert.DeserializeObject <PaymentItem>(Intent.GetStringExtra("PaymentItem")); tripItem = JsonConvert.DeserializeObject <TripItem>(Intent.GetStringExtra("TripItem")); GetPaymentUser(); textViewName.Text = paymentItem.Name; textViewAmount.Text = "" + paymentItem.Amount; var adapter = new PaymentAdapter(this, paymentContributors, tripFriends); listView.Adapter = adapter; var swipeContainer = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeContainer); swipeContainer.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight, Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight, Android.Resource.Color.HoloRedLight); swipeContainer.Refresh += SwipeContainer_Refresh; }
public static async Task <TripItem> FindNNotifyDrivers([ActivityTrigger] TripItem trip, ILogger log) { log.LogInformation($"FindNNotifyDrivers for {trip.Code} starting...."); List <DriverItem> availableDrivers = new List <DriverItem>(); if (ServiceFactory.GetSettingService().IsPersistDirectly()) { var persistenceService = ServiceFactory.GetPersistenceService(); availableDrivers = await persistenceService.RetrieveDrivers(trip.Source.Latitude, trip.Source.Longitude, ServiceFactory.GetSettingService().GetDriversLocationRadiusInMiles()); if (availableDrivers.Count > 0) { trip = await persistenceService.AssignTripAvailableDrivers(trip, availableDrivers); } } else { //TODO: Go through the Driver APIs } foreach (var driver in availableDrivers) { //TODO: Out of scope } if (availableDrivers.Count > 0) { await Externalize(trip, Constants.EVG_SUBJECT_TRIP_DRIVERS_NOTIFIED); } return(trip); }
public async void DeleteTripItem(TripItem item) { if (item != null) { //delete all history IEnumerable <HistoryItem> historyItems = await historyTable.Where(i => i.TripId == item.Id).ToEnumerableAsync(); foreach (HistoryItem hitem in historyItems) { await historyTable.DeleteAsync(hitem); } //delete all payments IEnumerable <PaymentItem> paymentItems = await paymentTable.Where(i => i.TripId == item.Id).ToEnumerableAsync(); foreach (PaymentItem pitem in paymentItems) { IEnumerable <UserPaymentItem> userPayitem = await userpaymentTabel.Where(i => i.PayId == pitem.Id).ToEnumerableAsync(); foreach (UserPaymentItem uitem in userPayitem) { await userpaymentTabel.DeleteAsync(uitem); } await paymentTable.DeleteAsync(pitem); } await tripTable.DeleteAsync(item); } }
public async Task SaveTripItemAsync(TripItem item, ObservableCollection <UserItem> users) { if (item.Id == null) { await tripTable.InsertAsync(item); } else if (users == null) { await tripTable.UpdateAsync(item); return; } else { await tripTable.UpdateAsync(item); DeleteUsersFromTripAsync(item); } foreach (var user in users) { await tripuserTable.InsertAsync(new TripUserItem() { TripId = item.Id, UserId = user.Id }); } }
public async Task <TripItem> AssignTripDriver(TripItem trip, string driverCode) { var error = ""; try { var driver = await RetrieveDriver(driverCode); driver.IsAcceptingRides = false; // NOTE: Make sure the driver is not at the destination already!!! driver.Latitude = trip.Source.Latitude; driver.Longitude = trip.Source.Longitude; await UpsertDriver(driver, true); trip.Driver = driver; trip.AcceptDate = DateTime.Now; trip = await UpsertTrip(trip, true); return(trip); } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - AssignTripDriver - Error: {error}"); } }
private void DeleteTripItem(object param) { TripItem ti = (TripItem)param; _tripRepository.DeleteTripItem(ti.Id); TripItems.Remove(ti); BuildItemList(); }
private async Task AddItem(string name, Category category, int amount) { TripItem ti = new TripItem(name, category, amount); int id = await _tripRepository.AddTripItem(Trip.Id, ti); ti.Id = id; TripItems.Add(ti); }
public TripItemDTO(TripItem tripItem) { Id = tripItem.Id; CheckedIn = tripItem.CheckedIn; Amount = tripItem.Amount; Name = tripItem.Name; Category = new TripCategoryDTO(tripItem.Category); }
public async Task Enqueue(TripItem trip) { await InitializeStorage(); if (_tripManagersQueue != null) { await _tripManagersQueue.SendMessageAsync(JsonConvert.SerializeObject(trip)); } }
public async void DeleteUsersFromTripAsync(TripItem tripItem) { IEnumerable <TripUserItem> tripUserItems = await tripuserTable.Where(i => i.TripId == tripItem.Id).ToEnumerableAsync(); foreach (TripUserItem item in tripUserItems) { await tripuserTable.DeleteAsync(item); } }
//private Tuple<ObservableCollection<string>, ObservableCollection<string>, ObservableCollection<string>> obserlist; //private decimal pay_sum; //private decimal return_sum; //private decimal your_sum; public Algo2(List <PaymentItem> paylist, UserItem thisuser, HashSet <UserItem> trip_Users, TripItem trip) { this.payList = paylist; this.thisUser = thisuser; this.trip_users = trip_Users; this.tripitem = trip; //this.user_payment = new ObservableCollection<UserPaymentItem>(); trip_users.Add(thisUser); }
public async Task Enqueue(TripItem trip) { await InitializeStorage(); if (_tripManagersQueue != null) { var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(trip)); await _tripManagersQueue.AddMessageAsync(queueMessage); } }
public static async Task NotifyOtherDrivers([ActivityTrigger] TripItem trip, ILogger log) { log.LogInformation($"NotifyOtherDrivers starting...."); trip.AvailableDrivers.Remove(trip.Driver); foreach (var driver in trip.AvailableDrivers) { //TODO: Out of scope } }
public async Task <IActionResult> Index(string Name, TripItem FaveTripItem) { int userID = await _context.Login(Name, FaveTripItem); if (userID <= 0) { return(NotFound()); } return(Redirect($"user/details/{userID}")); }
private void listViewClick(object sender, AdapterView.ItemClickEventArgs e) { var activity = (Intent)null; activity = new Intent(this, typeof(TripActivity)); TripItem trip = tripsList[e.Position]; activity.PutExtra("Trip", JsonConvert.SerializeObject(trip)); StartActivity(activity); }
public async Task <IActionResult> PostTripItem([FromBody] TripItem tripItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Trips.Add(tripItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTripItem", new { id = tripItem.trip_id }, tripItem)); }
public async Task TripDeleted(TripItem trip) { var error = ""; try { try { // Terminate a trip manager var baseUrl = _settingService.GetTerminateTripManagerOrchestratorBaseUrl(); var key = _settingService.GetTerminateTripManagerOrchestratorApiKey(); if (string.IsNullOrEmpty(baseUrl) || string.IsNullOrEmpty(key)) { throw new Exception("Trip manager orchestrator base URL and key must be both provided"); } await Utilities.Post <dynamic, dynamic>(null, trip, $"{baseUrl}/tripmanagers/{trip.Code}/terminate?code={key}", new Dictionary <string, string>()); } catch (Exception) { // Report ...but do not re-throw as it is possible not to have a trip manager running //throw new Exception(error); } try { // Terminate a trip monitor var baseUrl = _settingService.GetTerminateTripMonitorOrchestratorBaseUrl(); var key = _settingService.GetTerminateTripMonitorOrchestratorApiKey(); if (string.IsNullOrEmpty(baseUrl) || string.IsNullOrEmpty(key)) { throw new Exception("Trip monitor orchestrator base URL and key must be both provided"); } await Utilities.Post <dynamic, dynamic>(null, trip, $"{baseUrl}/tripmonitors/{trip.Code}-M/terminate?code={key}", new Dictionary <string, string>()); } catch (Exception) { // Report ...but do not re-throw as it is possible not to have a trip monitor running //throw new Exception(error); } } catch (Exception ex) { error = ex.Message; // Report ...but do not re-throw as it is possible not to have trip manager or monitor running //throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - TripDeleted - Error: {error}"); } }
public static async Task RecycleTripDriver([ActivityTrigger] TripItem trip, ILogger log) { log.LogInformation($"RecycleTripDriver for {trip.Code} starting...."); if (ServiceFactory.GetSettingService().IsPersistDirectly()) { var persistenceService = ServiceFactory.GetPersistenceService(); await persistenceService.RecycleTripDriver(trip); } else { //TODO: Go through the Trips APIs } }
public async Task <TripItem> UpsertTrip(TripItem trip, bool isIgnoreChangeFeed = false) { var error = ""; double cost = 0; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } // Just making sure... trip.CollectionType = ItemCollectionTypes.Trip; trip.UpsertDate = DateTime.Now; bool blInsert = false; if (trip.Id == "") { trip.Code = Utilities.GenerateRandomAlphaNumeric(8); trip.Id = $"{trip.Code}-{trip.CollectionType}"; blInsert = true; } if (trip.EndDate != null) { trip.Duration = ((DateTime)trip.EndDate - trip.StartDate).TotalSeconds; } var response = await(await GetDocDBClient(_settingService)).UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(_docDbDatabaseName, _docDbDigitalMainCollectionName), trip); cost = response.RequestCharge; if (!isIgnoreChangeFeed && blInsert) { await _changeNotifierService.TripCreated(trip, await RetrieveActiveTripsCount()); } } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - UpsertTrip - Error: {error}"); } return(trip); }
public static async Task CompleteTrip([ActivityTrigger] TripItem trip, ILogger log) { log.LogInformation($"CompleteTrip for {trip.Code} starting...."); await Externalize(trip, Constants.EVG_SUBJECT_TRIP_COMPLETED); // Send an event telemetry ServiceFactory.GetLoggerService().Log("Trip completed", new Dictionary <string, string> { { "Code", trip.Code }, { "Passenger", $"{trip.Passenger.FirstName} {trip.Passenger.LastName}" }, { "Destination", $"{trip.Destination.Latitude} - {trip.Destination.Longitude}" }, { "Mode", $"{trip.Type}" } }); }
public async Task <IActionResult> Create(int id, [Bind("TripItemId,ZooId,TripId")] TripItem tripItem) { if (ModelState.IsValid) { tripItem.Zoo = _context.Zoos.FirstOrDefault(z => z.ZooId == id); tripItem.ZooId = _context.Zoos.FirstOrDefault(z => z.ZooId == id).ZooId; _context.Add(tripItem); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Trips")); } ViewData["TripId"] = new SelectList(_context.Trips, "TripId", "Name", tripItem.TripId); ViewData["ZooId"] = new SelectList(_context.Zoos, "ZooId", "Name", tripItem.ZooId); return(View("Index", "Trips")); }
public async Task <TripItem> UpsertTrip(TripItem trip, bool isIgnoreChangeFeed = false) { var error = ""; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } // Just making sure... trip.CollectionType = ItemCollectionTypes.Trip; trip.UpsertDate = DateTime.Now; bool blInsert = false; if (trip.Id == "") { trip.Code = Utilities.GenerateRandomAlphaNumeric(8); trip.Id = $"{trip.Code}-{trip.CollectionType}"; blInsert = true; } if (trip.EndDate != null) { trip.Duration = ((DateTime)trip.EndDate - trip.StartDate).TotalSeconds; } var response = await(await GetCosmosContainer()).UpsertItemAsync(trip, new PartitionKey(trip.Code.ToUpper())); if (!isIgnoreChangeFeed && blInsert) { await _changeNotifierService.TripCreated(trip, await RetrieveActiveTripsCount()); } return(response.Resource); } catch (Exception ex) { error = ex.Message; throw new Exception(ex.Message, ex); } finally { _loggerService.Log($"{LOG_TAG} - UpsertTrip - Error: {error}"); } }
public static void CreateTripMonitor([ActivityTrigger] TripItem trip, [Queue("%TripMonitorsQueue%", Connection = "AzureWebJobsStorage")] out string queueTripCode, ILogger log) { log.LogInformation($"CreateTripMonitor starting...."); // Enqueue the trip code to be monitored queueTripCode = trip.Code; // Send an event telemetry ServiceFactory.GetLoggerService().Log("Trip monitored", new Dictionary <string, string> { { "Code", trip.Code }, { "Passenger", $"{trip.Passenger.FirstName} {trip.Passenger.LastName}" }, { "Destination", $"{trip.Destination.Latitude} - {trip.Destination.Longitude}" }, { "Mode", $"{trip.Type}" } }); }