// Receives the image path and returns the businesscard public override async Task <Businesscard> getCard(string imagePath) { try { using (var image = File.OpenRead(imagePath)) { Businesscard card = MakeEmptyCard(); Debug.WriteLine("AZUREVISION - Received image"); var textHeaders = await cv.ReadInStreamAsync(image); string operationLocation = textHeaders.OperationLocation; string operationId = operationLocation.Substring(operationLocation.Length - 36); // Extract the text ReadOperationResult results = null; Debug.WriteLine("AZUREVISION - sending image to Azure Service"); do { results = await cv.GetReadResultAsync(Guid.Parse(operationId)); }while ((results.Status == OperationStatusCodes.Running || results.Status == OperationStatusCodes.NotStarted)); Debug.WriteLine("AZUREVISION - received information from Azure Service"); card = await analyzeText(formatResults(results)); PrintCard(card); return(card); } } catch (Exception ex) { throw new BadRequestException(ex.ToString()); } }
// Sends the card to the endpoint and returns a boolean indicating if this was succesfull or not public async Task SendCardsAsync(Businesscard card) { try { // Serializing the businesscard object into a json string string json = JsonSerializer.Serialize <Businesscard>(card, serializerOptions); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; // Send the card asynchronously to the url and wait for the response // Constants.RestUrl references a constants class response = await client.PostAsync(Constants.RestUrl, content); if (response.IsSuccessStatusCode) { // If the response was succesful (200 statuscode) then the card was sent succesfully Debug.WriteLine("RestService: card was sent succesfully"); } else { // If not then something went wrong, let the calling part of the application know with an exception Debug.WriteLine("RestService: card could not be sent to the endpoint!"); throw new RestException("RestService: card wasn't sent succesfully"); } } catch (Exception ex) { throw new RestException("RestService: Card wasn't sent succesfully - Probably due to lack of internet connection"); } }
private Businesscard makeCard() { Businesscard card = new Businesscard(); card.Company = getHighest(companyDic, true); card.Name = getHighest(nameDic, true); card.Jobtitle = getHighest(jobTitleDic, true); card.Phone = getHighest(phoneDic, false); card.Mobile = getHighest(mobileDic, false); card.Email = getHighest(emailDic, false); card.Fax = getHighest(faxDic, false); string[] address = getHighest(addressDic, true).Split(','); if (address?.Length > 0) { card.Street = address[0].Trim(); } if (address?.Length > 1) { string city = ""; for (int i = 1; i < address.Length; i++) { city += " " + address[i]; } card.City = city.Trim(); } card.Nature = getHighest(natureDic, true); card.Extra = extraField; return(card); }
public Task <int> SaveBusinesscardAsync(Businesscard card) { if (card.Id != 0) { // Update an existing businesscard. return(database.UpdateAsync(card)); } else { // Save a new businesscard. return(database.InsertAsync(card)); } }
// Initialize page and set binding context to BusinesscardsEntryViewModel using an existing businesscard public BusinesscardEntryPage(Businesscard card) { InitializeComponent(); BindingContext = new BusinesscardEntryViewModel(Navigation, card); MessagingCenter.Subscribe <BusinesscardEntryViewModel>(this, "endpoint", (sender) => { save.IsEnabled = false; delete.IsEnabled = false; }); MessagingCenter.Subscribe <BusinesscardEntryViewModel>(this, "endpoint_done", (sender) => { save.IsEnabled = true; delete.IsEnabled = true; }); }
// Easy function used to print the card public void PrintCard(Businesscard card) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Company: " + card.Company); sb.AppendLine("Name: " + card.Name); sb.AppendLine("Nature: " + card.Nature); sb.AppendLine("JobTitle: " + card.Jobtitle); sb.AppendLine("Phone: " + card.Phone); sb.AppendLine("Mobile: " + card.Mobile); sb.AppendLine("Email:" + card.Email); sb.AppendLine("Fax: " + card.Fax); sb.AppendLine("Street: " + card.Street); sb.AppendLine("City: " + card.City); sb.AppendLine("Date: " + card.Date); sb.AppendLine("Origin: " + card.Origin); sb.AppendLine("Extra: " + card.Extra); Debug.WriteLine(sb.ToString()); }
// Make an empty card public Businesscard MakeEmptyCard() { Businesscard card = new Businesscard(); card.Company = ""; card.Name = ""; card.Nature = ""; card.Jobtitle = ""; card.Phone = ""; card.Mobile = ""; card.Email = ""; card.Fax = ""; card.Street = ""; card.City = ""; card.Date = new DateTime(); card.Origin = ""; card.Extra = ""; return(card); }
// Function to store the image locally as an unscanned card for later use private async Task StoreLocally() { // Create a new card and fill in the information Businesscard card = new Businesscard(); string filename = CameraService.PhotoPath.ToString(); card.Base64 = imageService.ConvertImageToBase64(filename); card.Date = DateTime.Now; card.Company = "Tap here to scan the card"; card.Name = "Unscanned card"; card.Extra = "UNSCANNEDCARD"; // Note: this value is very important since it is used to identify which card is unscanned and which is not (DO NOT CHANGE) // save the card locally await App.Database.SaveBusinesscardAsync(card); // refresh the page to show it on the mainpage OnAppearingTest(); Debug.WriteLine("Stored the card locally because the OCR Service isn't available"); DependencyService.Get <IToast>().LongAlert("Stored the card.\nTry to rescan when connected to the internet."); }
// Initialize ViewModel, navigation and commands public BusinesscardEntryViewModel(INavigation navigation) { Navigation = navigation; restService = new RestService(); imageService = new ImageTransformationService(); mailService = new MailService(); _company = new ValidatableObject <string>(); _name = new ValidatableObject <string>(); _email = new ValidatableObject <string>(); _phone = new ValidatableObject <string>(); _mobile = new ValidatableObject <string>(); _fax = new ValidatableObject <string>(); Card = new Businesscard(); SaveBusinessCard = new Command(async() => await OnSave()); DeleteBusinessCard = new Command(async() => await OnDelete()); AddValidations(); }
public Task <int> DeleteBusinesscardAsync(Businesscard card) { // Delete a businesscard. return(database.DeleteAsync(card)); }