// private static readonly HttpClient SingleClient = new HttpClient(); // If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(NativeActivityContext context) { var text = Text.Get(context); string filePath = File_Path.Get(context); string apiKey = API_KEY.Get(context); if (filePath != null) { var credential = GoogleCredential.FromFile(filePath).CreateScoped(LanguageServiceClient.DefaultScopes); var channel = new Grpc.Core.Channel(LanguageServiceClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials()); var client = LanguageServiceClient.Create(channel); var response = client.AnalyzeSentiment(new Document() { Content = text, Type = Document.Types.Type.PlainText }); var sentiment = response.DocumentSentiment; // Console.WriteLine($"Score: {sentiment.Score}"); // Console.WriteLine($"Magnitude: {sentiment.Magnitude}"); SentimentScore.Set(context, sentiment.Score); SentimentMagnitude.Set(context, sentiment.Magnitude); } else if (apiKey != null) { // @TODO Authentication using API Key [Work in progress] var nlp_base_url = "https://language.googleapis.com/v1beta2/"; var operation = "documents:analyzeSentiment"; var key = "?key=" + API_KEY.Get(context); var request_url = nlp_base_url + operation + key; object content = new { document = new { content = text, type = "PLAIN_TEXT" }, encodingType = "UTF8" }; Task <(HttpResponseMessage, String)> response_message = Task.Run(() => PostBasicAsync(request_url, content)); response_message.Wait(); (HttpResponseMessage result_json, String stringContent) = response_message.Result; // string request_content = stringContent.ReadAsStringAsync().Result; // ContentBody.Set(context, "\nStringContent - \n" + stringContent); GoogleNLPResponseMessage.Set(context, result_json); } }
private async void NextActivityPage() { CheckConnectionInternet.checkConnectivity(); if (string.IsNullOrEmpty(this.Email)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Email.", "Accept"); return; } if (!IsValid(this.Email)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter a real Email.", "Accept"); return; } var checkEmail = await App.MobileService.GetTable <User>().Where(p => p.Email == this.Email).ToListAsync(); if (checkEmail.Count > 0) { await Application.Current.MainPage.DisplayAlert( "Error", "This email has been registered.", "Try Another"); return; } if (string.IsNullOrEmpty(this.Password)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); return; } if (this.Password.Length < 7) { await Application.Current.MainPage.DisplayAlert( "Error", "Your Password length must be greather than 6.", "Accept"); return; } if (string.IsNullOrEmpty(this.ReEnterPassword)) { await Application.Current.MainPage.DisplayAlert( "Error", "You must enter an Password.", "Accept"); return; } if (!(Password.Equals(ReEnterPassword))) { await Application.Current.MainPage.DisplayAlert( "Error", "Passwords not match.", "Accept"); return; } if (!this.isReady) { await Application.Current.MainPage.DisplayAlert( "Error", "You must take a picture or select one", "Accept"); return; } this.IsRunning = true; CurrentUser.Email = Email; CurrentUser.IsActive = true; CurrentUser.Created_Date = DateTime.Now; byte[] encryted = System.Text.Encoding.Unicode.GetBytes(Password); var result = System.Convert.ToBase64String(encryted); int len = RandomId.length.Next(5, 10); User_Password password = new User_Password { Id = RandomId.RandomString(len), Password = result, User_Id_FK = CurrentUser.Id }; byteData = AzureStorage.Convert.ToByteArray(source); uploadedFilename = await AzureStorage.AzureStorage.UploadFileAsync(AzureStorage.ContainerType.Image, new MemoryStream(byteData)); string[] arr = source.Split('/'); File_Path filepath = new File_Path { Id = RandomId.RandomString(len), Type = "Image", Path = uploadedFilename, Filename = arr[arr.Length - 1], FileUrl = source, Saved_Date = DateTime.Today, User_Id_FK = CurrentUser.Id }; try { await App.MobileService.GetTable <Address>().InsertAsync(CurrentAddress); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } try { await App.MobileService.GetTable <User>().InsertAsync(CurrentUser); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } try { await App.MobileService.GetTable <User_Password>().InsertAsync(password); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } try { await App.MobileService.GetTable <File_Path>().InsertAsync(filepath); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok"); } /* * //logic azure upload blob * string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=lioncode;AccountKey=oY4jZN5nSf4g/4ATkgHIPAgjVRxF3fYS/R1BfhT1k9Li98e7vEYq4/DY4y38LHQ9zjvsvIXI8qEDYQWeeHbxHQ==;EndpointSuffix=core.windows.net"; * CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString); * CloudBlobClient blobClient = account.CreateCloudBlobClient(); * CloudBlobContainer blobContainer = blobClient.GetContainerReference("activitymaps"); * blobContainer.CreateIfNotExists(); * string sourcePath = this.source; * CloudBlockBlob destBlob = blobContainer.GetBlockBlobReference("activitymaps"); * * // Setup the number of the concurrent operations * TransferManager.Configurations.ParallelOperations = 64; * // Setup the transfer context and track the upload progress * SingleTransferContext context = new SingleTransferContext(); * // Upload a local blob * var task = TransferManager.UploadAsync( * sourcePath, destBlob, null, context, CancellationToken.None); * task.Wait(); */ this.IsRunning = false; MainViewModel.GetInstance().Login = new LoginViewModel(CurrentUser.Email); await Application.Current.MainPage.Navigation.PushAsync(new LoginPage()); }