public static void Start(User u, SpeechHelper.SpeechStateCallbackDelegate del, Delegate networkDel)
        {
            // trace the speech request
            TraceHelper.AddMessage("Starting Speech");

            // Start is not reentrant - make sure the caller didn't violate the contract
            if (speechOperationInProgress == true)
                return;

            // store the delegates passed in
            speechStateDelegate = del;
            networkDelegate = networkDel;

            // set the flag
            speechOperationInProgress = true;

            // initialize the connection
            if (SpeechkitInitialize() == false)
            {
                Cancel(networkDel);
                return;
            }

            // start a new thread that starts the dictation
            DictationStart(RecognizerRecognizerType.Dictation);
        }
Exemple #2
0
        public User(User obj)
        {
            if (obj == null)
                return;

            // copy all of the properties
            foreach (PropertyInfo pi in this.GetType().GetProperties())
            {
                var val = pi.GetValue(obj, null);
                pi.SetValue(this, val, null);
            }
        }
        public static void Start(User u, SpeechHelper.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));
        }
Exemple #4
0
        private void CreateUserCallback(User user, HttpStatusCode? code)
        {
            this.BeginInvokeOnMainThread(() =>
            {
                string email = ((EntryElement)Email).Value;
                string pswd = ((EntryElement)Password).Value;

                // if the user came back null, the operation could not have completed successfully
                if (code == HttpStatusCode.OK || code == HttpStatusCode.Created)
                    if (user == null)
                        code = HttpStatusCode.ServiceUnavailable;
                switch (code)
                {
                    case HttpStatusCode.OK:
                    case HttpStatusCode.Created:
                        MessageBox.Show(String.Format("user account {0} successfully created", email));
                        accountOperationSuccessful = true;
                        user.Synced = true;
                        // the server no longer echos the password in the payload so keep the local value when successful
                        if (user.Password == null)
                            user.Password = pswd;
                        App.ViewModel.User = user;
                        App.ViewModel.SyncWithService();
                        break;
                    case HttpStatusCode.NotFound:
                        MessageBox.Show(String.Format("user {0} not found", email));
                        accountOperationSuccessful = false;
                        break;
                    case HttpStatusCode.Conflict:
                        MessageBox.Show(String.Format("user {0} already exists", email));
                        accountOperationSuccessful = false;
                        break;
                    case HttpStatusCode.NotAcceptable:
                        MessageBox.Show(String.Format("email address {0} is invalid or password is not strong enough", email));
                        accountOperationSuccessful = false;
                        break;
                    case HttpStatusCode.InternalServerError:
                        MessageBox.Show(String.Format("user {0} was not created successfully (missing a field?)", email));
                        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 - contact [email protected]", email));
                        accountOperationSuccessful = false;
                        break;
                }

                // update UI if successful
                if (accountOperationSuccessful)
                {
                    dvc.NavigationController.PopViewControllerAnimated(true);
                    CreateRoot();
                    dvc.ReloadData();
                }
                ResignFirstResponder();
            });
        }
Exemple #5
0
        void CreateUserButton_Click(object sender, EventArgs e)
        {
            // validate account info
            ((EntryElement)Email).FetchValue();
            ((EntryElement)Password).FetchValue();
            var email = ((EntryElement) Email).Value;
            var pswd = ((EntryElement) Password).Value;
            if (String.IsNullOrWhiteSpace(email) ||
                String.IsNullOrWhiteSpace(pswd))
            {
                MessageBox.Show("please enter a valid email address and password");
                return;
            }

            // process an account creation request
            User user = new User() { Email = email, Password = pswd };
            WebServiceHelper.CreateUser(
                user,
                new CreateUserCallbackDelegate(CreateUserCallback),
                new MainViewModel.NetworkOperationInProgressCallbackDelegate(App.ViewModel.NetworkOperationInProgressCallback));
        }
Exemple #6
0
        private void VerifyUserCallback(User user, HttpStatusCode? code)
        {
            // run this on the UI thread
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // if the user did not get returned, the operation could not have been successful
                if (code == HttpStatusCode.OK && user == null)
                    code = HttpStatusCode.ServiceUnavailable;
                switch (code)
                {
                    case HttpStatusCode.OK:
                        MessageBox.Show(String.Format("successfully connected to account {0}; data sync will start automatically.", Email.Text));
                        accountOperationSuccessful = true;
                        user.Synced = true;
                        // the server no longer echos the password in the payload so keep the local value when successful
                        if (user.Password == null)
                            user.Password = Password.Password;
                        App.ViewModel.User = user;
                        // prepare for sync by cleaning out the user queue and deleting the system queue ($ClientSettings comes from the server account)
                        RequestQueue.PrepareUserQueueForAccountConnect();
                        RequestQueue.DeleteQueue(RequestQueue.SystemQueue);
                        App.ViewModel.SyncWithService();
                        break;
                    case HttpStatusCode.NotFound:
                        MessageBox.Show(String.Format("user {0} not found", Email.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("did not successfully connect to account {0}", Email.Text));
                        accountOperationSuccessful = false;
                        break;
                }

                // update UI if successful
                if (accountOperationSuccessful)
                {
                    NotifyPropertyChanged("ConnectedMode");
                    NotifyPropertyChanged("CreateButtonText");
                    NotifyPropertyChanged("EnableButtons");
                    Email.IsEnabled = false;
                    Password.IsEnabled = false;
                    // return to main page
                    TraceHelper.StartMessage("Settings: Navigate back");
                    NavigationService.GoBack();
                }
            });
        }
Exemple #7
0
        private void CreateUserCallback(User user, HttpStatusCode? code)
        {
            // run this on the UI thread
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // if the user came back null, the operation could not have completed successfully
                if (code == HttpStatusCode.OK || code == HttpStatusCode.Created)
                    if (user == null)
                        code = HttpStatusCode.ServiceUnavailable;
                switch (code)
                {
                    case HttpStatusCode.OK:
                    case HttpStatusCode.Created:
                        MessageBox.Show(String.Format("user account {0} successfully created", Email.Text));
                        accountOperationSuccessful = true;
                        user.Synced = true;
                        // the server no longer echos the password in the payload so keep the local value when successful
                        if (user.Password == null)
                            user.Password = Password.Password;
                        App.ViewModel.User = user;
                        App.ViewModel.SyncWithService();
                        break;
                    case HttpStatusCode.NotFound:
                        MessageBox.Show(String.Format("user {0} not found", Email.Text));
                        accountOperationSuccessful = false;
                        break;
                    case HttpStatusCode.Conflict:
                        MessageBox.Show(String.Format("user {0} already exists", Email.Text));
                        accountOperationSuccessful = false;
                        break;
                    case HttpStatusCode.NotAcceptable:
                        MessageBox.Show(String.Format("email address {0} is invalid or password is not strong enough", Email.Text));
                        accountOperationSuccessful = false;
                        break;
                    case HttpStatusCode.InternalServerError:
                        MessageBox.Show(String.Format("user {0} was not created successfully (missing a field?)", Email.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 - contact [email protected]", Email.Text));
                        accountOperationSuccessful = false;
                        break;
                }

                // update UI if successful
                if (accountOperationSuccessful)
                {
                    NotifyPropertyChanged("ConnectedMode");
                    NotifyPropertyChanged("CreateButtonText");
                    NotifyPropertyChanged("EnableButtons");
                    Email.IsEnabled = false;
                    Password.IsEnabled = false;
                    // return to main page
                    TraceHelper.StartMessage("Settings: Navigate back");
                    NavigationService.GoBack();
                }
            });
        }
Exemple #8
0
        private void CreateUserButton_Click(object sender, RoutedEventArgs e)
        {
            // if we're connected, this is a disconnect request
            if (IsConnected)
            {
                // if the request queue isn't empty, warn the user
                if (RequestQueue.GetRequestRecord(RequestQueue.UserQueue) != null)
                {
                    MessageBoxResult result = MessageBox.Show(
                        "some of the changes you made on the phone haven't made it to your Zaplify account yet.  " +
                        "click ok to disconnect now and potentially lose these changes, or cancel the operation",
                        "disconnect now?",
                        MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.Cancel)
                        return;
                }

                // process the disconnect
                App.ViewModel.User = null;
                App.ViewModel.EraseAllData();
                WebServiceHelper.Disconnect();

                // reset the settings page
                NotifyPropertyChanged("ConnectedMode");
                NotifyPropertyChanged("CreateButtonText");
                NotifyPropertyChanged("EnableButtons");
                Email.IsEnabled = true;
                Email.Text = "";
                Password.IsEnabled = true;
                Password.Password = "";
                accountTextChanged = false;
                accountOperationSuccessful = false;
                foreach (var element in SettingsPanel.Children)
                {
                    // get the listpicker key and value
                    ListPicker listPicker = element as ListPicker;
                    if (listPicker == null)
                        continue;
                    listPicker.SelectedIndex = 0;
                }
                return;
            }

            // validate account info
            if (String.IsNullOrWhiteSpace(Email.Text) ||
                String.IsNullOrWhiteSpace(Password.Password))
            {
                MessageBox.Show("please enter a valid email address and password");
                return;
            }

            // process an account creation request
            User user = new User() { Email = Email.Text, Password = Password.Password };
            WebServiceHelper.CreateUser(
                user,
                new CreateUserCallbackDelegate(CreateUserCallback),
                new MainViewModel.NetworkOperationInProgressCallbackDelegate(App.ViewModel.NetworkOperationInProgressCallback));
        }
Exemple #9
0
        private void ConnectUserButton_Click(object sender, RoutedEventArgs e)
        {
            // validate account info
            if (String.IsNullOrWhiteSpace(Email.Text) ||
                String.IsNullOrWhiteSpace(Password.Password))
            {
                MessageBox.Show("please enter a valid email address and password");
                return;
            }

            // process an account connect request
            User user = new User() { Email = Email.Text, Password = Password.Password };
            WebServiceHelper.VerifyUserCredentials(
                user,
                new VerifyUserCallbackDelegate(VerifyUserCallback),
                new MainViewModel.NetworkOperationInProgressCallbackDelegate(App.ViewModel.NetworkOperationInProgressCallback));
        }
Exemple #10
0
 private static void Send(User user, string msgs, Delegate del, Delegate networkDel)
 {
     #if IOS
     WebServiceHelper.SendTrace(user, msgs, del, networkDel);
     #else
     //byte[] bytes = Encoding.UTF8.GetBytes(msgs);
     byte[] bytes = EncodeString(msgs);
     WebServiceHelper.SendTrace(user, bytes, del, networkDel);
     #endif
 }
Exemple #11
0
        public static void Start(User u, SpeechToTextCallbackDelegate speechToTextDel, SpeechStateCallbackDelegate speechStateDel, Delegate networkDel)
        {
            // trace the speech request
            TraceHelper.AddMessage("Starting Speech");

            // Start is not reentrant - make sure the caller didn't violate the contract
            if (speechOperationInProgress == true)
                return;

            // store the delegates passed in
            speechToTextDelegate = speechToTextDel;
            speechStateDelegate = speechStateDel;

            // initialize the connection
            if (InitializeSpeechKit() == false)
            {
                Cancel(networkDel);
                return;
            }

            // start a new thread that starts the dictation
            DictationStart(SKRecognizerType.SKDictationRecognizerType);
        }
Exemple #12
0
        // Send an HTTP POST to start a new speech recognition transaction
        public static void SendPost(User user, string encoding, Delegate del, Delegate netOpInProgressDel)
        {
            string url = SpeechUrl + "/api/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: {2}\r\n" +
                "Host: {3}\r\n" +
                "Content-Type: application/json\r\n" +
                "{4}\r\n" +                                     // encoding
                "Transfer-Encoding: chunked\r\n\r\n",
                verb != null ? verb : "POST",
                url,
            #if IOS
                UserAgents.IOSPhone,
            #else
                UserAgents.WinPhone,
            #endif
                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, OperationStatus.Failed);

                        // clean up the socket
                        CleanupSocket();

                        return;
                    }

                    // when the socket setup and HTTP POST + headers have been completed,
                    // signal the caller
                    del.DynamicInvoke();
                }),
                netOpInProgressDel);
        }
Exemple #13
0
 public static void SendCrashReport(User user, Delegate del, Delegate networkDel)
 {
     string contents = StorageHelper.ReadCrashReport();
     if (contents != null)
     {
         contents = "Crash Report\n" + contents;
         Send(user, contents, del, networkDel);
     }
 }
Exemple #14
0
        private RootElement InitializeAccountSettings()
        {
            user = App.ViewModel.User;
            ThemedRootElement accountRootElement = null;

            // initialize the Account element based on whether connected or disconnected
            if (IsConnected)
            {
                // initialize account controls
                Email = new StringElement("Email", user.Email);
                // create unicode bullet characters for every character in the password
                var sb = new StringBuilder();
                if (user != null && user.Password != null)
                    foreach (var c in user.Password)
                        sb.Append("\u25CF"); // \u2022
                Password = new StringElement("Password", sb.ToString());

                // create buttons
                var button = new ButtonListElement()
                {
                    new Button() { Caption = "Disconnect",  Background = "Images/darkgreybutton.png", Clicked = DisconnectUserButton_Click },
                };
                button.Margin = 0f;

                // create the account root element
                accountRootElement = new ThemedRootElement("Account")
                {
                    new Section()
                    {
                        Email,
                        Password,
                    },
                    new Section()
                    {
                        button
                    }
                };
            }
            else
            {
                // initialize account controls
                Email = new EntryElement("Email", "Enter email", user != null ? user.Email : null);
                Password = new EntryElement("Password", "Enter password", user != null ? user.Password : null, true);

                var createButton = new ButtonListElement()
                {
                    new Button() { Caption = "Create a new account",  Background = "Images/darkgreybutton.png", Clicked = CreateUserButton_Click },
                };
                createButton.Margin = 0f;
                var connectButton = new ButtonListElement()
                {
                    new Button() { Caption = "Connect to an existing account", Background = "Images/darkgreybutton.png", Clicked = ConnectUserButton_Click },
                };
                connectButton.Margin = 0f;

                // create the account root element
                accountRootElement = new ThemedRootElement("Account")
                {
                    new Section()
                    {
                        Email,
                        Password,
                    },
                    new Section()
                    {
                        createButton,
                    },
                    new Section()
                    {
                        connectButton
                    }
                };
            }

            return accountRootElement;
        }
Exemple #15
0
 public static void Start(User u, SpeechStateCallbackDelegate del, Delegate networkDel)
 {
     switch (SpeechProvider)
     {
         case SpeechProviders.NativeSpeech:
             NativeSpeechHelper.Start(u, del, networkDel);
             break;
         case SpeechProviders.NuanceSpeech:
             NuanceSpeechHelper.Start(u, del, networkDel);
             break;
     }
 }
Exemple #16
0
        private void VerifyUserCallback(User user, HttpStatusCode? code)
        {
            this.BeginInvokeOnMainThread(() =>
            {
                string email = ((EntryElement)Email).Value;
                string pswd = ((EntryElement)Password).Value;

                // if the user did not get returned, the operation could not have been successful
                if (code == HttpStatusCode.OK && user == null)
                    code = HttpStatusCode.ServiceUnavailable;
                switch (code)
                {
                    case HttpStatusCode.OK:
                        MessageBox.Show(String.Format("successfully connected to account {0}; data sync will start automatically.", email));
                        accountOperationSuccessful = true;
                        user.Synced = true;
                        // the server no longer echos the password in the payload so keep the local value when successful
                        if (user.Password == null)
                            user.Password = pswd;
                        App.ViewModel.User = user;
                        // prepare the user queue and remove the system queue (the $ClientSettings will be lost because the server is authoritative)
                        RequestQueue.PrepareUserQueueForAccountConnect();
                        RequestQueue.DeleteQueue(RequestQueue.SystemQueue);
                        App.ViewModel.SyncWithService();
                        break;
                    case HttpStatusCode.NotFound:
                        MessageBox.Show(String.Format("user {0} not found", email));
                        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("did not successfully connect to account {0}", email));
                        accountOperationSuccessful = false;
                        break;
                }

                // update UI if successful
                if (accountOperationSuccessful)
                {
                    dvc.NavigationController.PopViewControllerAnimated(true);
                    CreateRoot();
                    dvc.ReloadData();
                }
                ResignFirstResponder();
            });
        }
Exemple #17
0
 public static void SendMessages(User user)
 {
     string msgs = GetMessages();
     Send(user, msgs, null, null);
 }