public User(User obj) { // copy all of the properties foreach (PropertyInfo pi in this.GetType().GetProperties()) { var val = pi.GetValue(obj, null); pi.SetValue(this, val, null); } }
private void invokeButton_Click(object sender, EventArgs e) { resultTextBox.Text = ""; User u = new User() { Name = "ogazitt", Password = "******", }; if (filenameTextBox.Text == "") { MessageBox.Show("filename must not be empty"); return; } FileStream fs = File.Open(filenameTextBox.Text, FileMode.Open); byte[] bytes = new byte[fs.Length]; int len = fs.Read(bytes, 0, bytes.Length); fs.Close(); if (urlTextBox.Text != "") WebServiceHelper.BaseUrl = urlTextBox.Text; if (checkBox1.CheckState == CheckState.Checked) { bytes = EncodeSpeech(bytes, len); WebServiceHelper.ContentType = "application/speex"; } else WebServiceHelper.ContentType = "application/json"; start = DateTime.Now; WebServiceHelper.SpeechToText(u, bytes, new WebServiceCallbackDelegate(WebServiceCallback), new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); }
/// <summary> /// Send an HTTP POST to start a new speech recognition transaction /// </summary> /// <param name="user">User to authenticate</param> /// <param name="encoding">Encoding string</param> /// <param name="del">Delegate to invoke when the request completes</param> /// <param name="netOpInProgressDel">Delegate to signal the network status</param> public static void SendPost(User user, string encoding, Delegate del, Delegate netOpInProgressDel) { string url = baseUrl + "/speech"; string verb = "POST"; // get a Uri for the service - this will be used to decode the host / port Uri uri = new Uri(url); string host = uri.Host; if (uri.Port != 80) host = String.Format("{0}:{1}", uri.Host, uri.Port); // construct the HTTP POST buffer string request = String.Format( "{0} {1} HTTP/1.1\r\n" + "User-Agent: TaskStore-WinPhone\r\n" + "TaskStore-Username: {2}\r\n" + "TaskStore-Password: {3}\r\n" + "Host: {4}\r\n" + "Content-Type: application/json\r\n" + "{5}\r\n" + "Transfer-Encoding: chunked\r\n\r\n", verb != null ? verb : "POST", url, user.Name, user.Password, host, encoding); byte[] buffer = Encoding.UTF8.GetBytes(request); // send the request HTTP header SendData( buffer, -1, new EventHandler<SocketAsyncEventArgs>(delegate(object o, SocketAsyncEventArgs e) { if (e.SocketError != SocketError.Success) { // signal that a network operation is done and unsuccessful netOpInProgressDel.DynamicInvoke(false, false); // clean up the socket CleanupSocket(); return; } // when the socket setup and HTTP POST + headers have been completed, // signal the caller del.DynamicInvoke(); }), netOpInProgressDel); }
public static void SendMessages(User user) { string msgs = GetMessages(); byte[] bytes = EncodeString(msgs); WebServiceHelper.SendTrace(user, bytes, null, null); }
private void GetUserDataCallback(User user) { // trace callback TraceHelper.AddMessage(String.Format("Finished Get User Data: {0}", constants == null ? "null" : "success")); if (user != null) { // reset and save the user credentials user.Synced = true; User = user; // reset the user's list types UserListTypes = user.ListTypes; // reset and save the user's tags Tags = user.Tags; // reset and save the user's tasklists TaskLists = user.TaskLists; // store the tasklists individually foreach (TaskList tl in taskLists) { // store the tasklist in the dictionary Lists[tl.ID] = tl; // create the tags collection (client-only property) foreach (Task t in tl.Tasks) t.CreateTags(tags); // save the tasklist in its own isolated storage file StorageHelper.WriteList(tl); } } }
private void VerifyUserCallback(User user, HttpStatusCode? code) { // run this on the UI thread Deployment.Current.Dispatcher.BeginInvoke(() => { switch (code) { case HttpStatusCode.OK: MessageBox.Show(String.Format("successfully linked with {0} account; data sync will start automatically.", Username.Text)); accountOperationSuccessful = true; user.Synced = true; App.ViewModel.User = user; App.ViewModel.SyncWithService(); break; case HttpStatusCode.NotFound: MessageBox.Show(String.Format("user {0} not found", Username.Text)); accountOperationSuccessful = false; break; case HttpStatusCode.Forbidden: MessageBox.Show(String.Format("incorrect password")); accountOperationSuccessful = false; break; case null: MessageBox.Show(String.Format("couldn't reach the server")); accountOperationSuccessful = false; break; default: MessageBox.Show(String.Format("account {0} was not successfully paired", Username.Text)); accountOperationSuccessful = false; break; } }); }
private void SyncUserButton_Click(object sender, RoutedEventArgs e) { if (MergeCheckbox.IsChecked == true) { MessageBoxResult result = MessageBox.Show( "leaving the 'merge' checkbox checked will merge the new lists on the phone with existing data in the account, potentially creating duplicate lists. " + "click ok to sync the account and merge the phone data, or cancel the operation.", "merge local data?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) return; } else { // clear the record queue RequestQueue.RequestRecord record = RequestQueue.DequeueRequestRecord(); while (record != null) { record = RequestQueue.DequeueRequestRecord(); } } User user = new User() { Name = Username.Text, Password = Password.Password, Email = Email.Text }; WebServiceHelper.VerifyUserCredentials( user, new VerifyUserCallbackDelegate(VerifyUserCallback), new MainViewModel.NetworkOperationInProgressCallbackDelegate(App.ViewModel.NetworkOperationInProgressCallback)); }
// Event handlers for settings tab private void SaveButton_Click(object sender, EventArgs e) { // if we made changes in the account info but didn't successfully carry them out, put up a warning dialog if (accountTextChanged && !accountOperationSuccessful) { MessageBoxResult result = MessageBox.Show( "account was not successfully created or paired (possibly because you haven't clicked the 'create' or 'pair' button). " + "click ok to dismiss the settings page and forget the changes to the account page, or cancel the operation.", "exit settings before creating or pairing an account?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } } else { // save the new account information User user = new User() { Name = Username.Text, Password = Password.Password, Email = Email.Text }; App.ViewModel.User = user; } // save the default tasklist in any case App.ViewModel.DefaultTaskList = DefaultListPicker.SelectedItem as TaskList; // trace page navigation TraceHelper.StartMessage("Settings: Navigate back"); // go back to main page NavigationService.GoBack(); }
private void CreateUserCallback(User user, HttpStatusCode? code) { // run this on the UI thread Deployment.Current.Dispatcher.BeginInvoke(() => { switch (code) { case HttpStatusCode.OK: case HttpStatusCode.Created: MessageBox.Show(String.Format("user account {0} successfully created", Username.Text)); accountOperationSuccessful = true; user.Synced = true; App.ViewModel.User = user; App.ViewModel.SyncWithService(); break; case HttpStatusCode.NotFound: MessageBox.Show(String.Format("user {0} not found", Username.Text)); accountOperationSuccessful = false; break; case HttpStatusCode.Conflict: MessageBox.Show(String.Format("user {0} already exists", Username.Text)); accountOperationSuccessful = false; break; case HttpStatusCode.InternalServerError: MessageBox.Show(String.Format("user {0} was not created successfully (missing a field?)", Username.Text)); accountOperationSuccessful = false; break; case null: MessageBox.Show(String.Format("couldn't reach the server")); accountOperationSuccessful = false; break; default: MessageBox.Show(String.Format("user {0} was not created", Username.Text)); accountOperationSuccessful = false; break; } }); }
public static void Start(User u, SpeechStateCallbackDelegate del, Delegate networkDel) { // StartStreamed is not reentrant - make sure the caller didn't violate the contract if (speechOperationInProgress == true) return; // set the flag speechOperationInProgress = true; // store the delegates passed in speechStateDelegate = del; networkDelegate = networkDel; user = u; // initialize the microphone information and speech buffer mic.BufferDuration = TimeSpan.FromSeconds(1); int length = mic.GetSampleSizeInBytes(mic.BufferDuration); speechBuffer = new byte[length]; speechBufferList.Clear(); bufferMutexList.Clear(); numBytes = 0; // trace the speech request TraceHelper.AddMessage("Starting Speech"); // initialize frame index frameCounter = 0; // callback when the mic gathered 1 sec worth of data if (initializedBufferReadyEvent == false) { mic.BufferReady += new EventHandler<EventArgs>(MicBufferReady); initializedBufferReadyEvent = true; } // connect to the web service, and once that completes successfully, // it will invoke the NetworkInterfaceCallback delegate to indicate the network quality // this delegate will then turn around and send the appropriate encoding in the SendPost call NetworkHelper.BeginSpeech( new NetworkInformationCallbackDelegate(NetworkInformationCallback), new NetworkDelegate(NetworkCallback)); }