Exemplo n.º 1
0
        void SetResult(CredentialPickerResults res)
        {
            if (res.ErrorCode == 0)
            {
                Status.Text = String.Format("OK");
            }
            else
            {
                Status.Text = String.Format("Error returned from CredPicker API: {0}", res.ErrorCode);
            }

            Domain.Text          = res.CredentialDomainName;
            Username.Text        = res.CredentialUserName;
            Password.Text        = res.CredentialPassword;
            CredentialSaved.Text = (res.CredentialSaved ? "true" : "false");
            switch (res.CredentialSaveOption)
            {
            case CredentialSaveOption.Hidden:
                CheckboxState.Text = "Hidden";
                break;

            case CredentialSaveOption.Selected:
                CheckboxState.Text = "Selected";
                break;

            case CredentialSaveOption.Unselected:
                CheckboxState.Text = "Unselected";
                break;
            }
        }
        void SetResult(CredentialPickerResults res)
        {
            TextBox status = rootPage.FindName("Status") as TextBox;

            status.Text = String.Format("OK (Returned Error Code: {0})", res.ErrorCode);
            TextBox domain = rootPage.FindName("Domain") as TextBox;

            domain.Text = res.CredentialDomainName;
            TextBox username = rootPage.FindName("Username") as TextBox;

            username.Text = res.CredentialUserName;
            TextBox password = rootPage.FindName("Password") as TextBox;

            password.Text = res.CredentialPassword;
            TextBox credsaved = rootPage.FindName("CredentialSaved") as TextBox;

            credsaved.Text = (res.CredentialSaved ? "true" : "false");
            TextBox checkboxState = rootPage.FindName("CheckboxState2") as TextBox;

            switch (res.CredentialSaveOption)
            {
            case CredentialSaveOption.Hidden:
                checkboxState.Text = "Hidden";
                break;

            case CredentialSaveOption.Selected:
                checkboxState.Text = "Selected";
                break;

            case CredentialSaveOption.Unselected:
                checkboxState.Text = "Unselected";
                break;
            }
        }
        private async void Launch_Click(object sender, RoutedEventArgs e)
        {
            if ((Target.Text.Length != 0) && (Message.Text.Length != 0))
            {
                try
                {
                    CredentialPickerResults credPickerResults = await Windows.Security.Credentials.UI.CredentialPicker.PickAsync(Target.Text, Message.Text);

                    SetResult(credPickerResults);
                }
                catch (Exception ex)
                {
                    SetError(ex.GetType().ToString() + ": " + ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        void SetResult(CredentialPickerResults res)
        {
            Page    outputFrame = (Page)rootPage.OutputFrame.Content;
            TextBox status      = outputFrame.FindName("Status") as TextBox;

            if (res.ErrorCode == 0)
            {
                status.Text = String.Format("OK");
            }
            else
            {
                status.Text = String.Format("Error returned from CredPicker API: {0}", res.ErrorCode);
            }
            TextBox domain = outputFrame.FindName("Domain") as TextBox;

            domain.Text = res.CredentialDomainName;
            TextBox username = outputFrame.FindName("Username") as TextBox;

            username.Text = res.CredentialUserName;
            TextBox password = outputFrame.FindName("Password") as TextBox;

            password.Text = res.CredentialPassword;
            TextBox credsaved = outputFrame.FindName("CredentialSaved") as TextBox;

            credsaved.Text = (res.CredentialSaved ? "true" : "false");
            TextBox checkboxState = outputFrame.FindName("CheckboxState") as TextBox;

            switch (res.CredentialSaveOption)
            {
            case CredentialSaveOption.Hidden:
                checkboxState.Text = "Hidden";
                break;

            case CredentialSaveOption.Selected:
                checkboxState.Text = "Selected";
                break;

            case CredentialSaveOption.Unselected:
                checkboxState.Text = "Unselected";
                break;
            }
        }
Exemplo n.º 5
0
        private static void InvokeCallbackCommand( CredentialInteraction selectedCredential, CredentialPickerResults result )
        {
            Contract.Requires( selectedCredential != null );
            Contract.Requires( result != null );

            INamedCommand button = null;

            if ( result.ErrorCode == 0x800704C7U )
            {
                // select cancel button
                button = selectedCredential.CancelCommand;
            }
            else
            {
                // set credential
                selectedCredential.SavedByCredentialManager = result.CredentialSaved;
                selectedCredential.UserElectedToSaveCredential = result.CredentialSaveOption == CredentialSaveOption.Selected;
                selectedCredential.Credential = result.Credential.ToArray();
                selectedCredential.DomainName = result.CredentialDomainName;
                selectedCredential.UserName = result.CredentialUserName;
                selectedCredential.Password = result.CredentialPassword;

                // select accept button
                button = selectedCredential.DefaultCommand;
            }

            // execute command for button
            if ( button != null && button.CanExecute() )
                button.Execute();
        }
Exemplo n.º 6
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            (Application.Current as App).context = context;
            ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;

            if (settings.Values["LoginSaved"] == null)
            {
                settings.Values["Username"]   = "";
                settings.Values["Password"]   = "";
                settings.Values["LoginSaved"] = false;
            }
            if (await context.AuthenticationIsRequiredAsync())
            {
                while (!loginSuccess)
                {
                    if ((bool)ApplicationData.Current.LocalSettings.Values["LoginSaved"])
                    {
                        context.AuthenticationCredentials = new Credentials(settings.Values["Username"].ToString(), settings.Values["Password"].ToString());
                        loginSuccess = await context.ValidateCredentialsAsync();

                        if (!loginSuccess)
                        {
                            settings.Values["LoginSaved"] = false;
                        }
                    }
                    else
                    {
                        CredentialPickerResults cpr = await CredentialPicker.PickAsync(new CredentialPickerOptions()
                        {
                            AuthenticationProtocol = AuthenticationProtocol.Basic,
                            Caption = "iMessage Bridge Login",
                            Message = "Authentication is required.",
                            CredentialSaveOption = CredentialSaveOption.Unselected,
                            TargetName           = "."
                        });

                        if (cpr.Credential != null)
                        {
                            if (cpr.CredentialSaved)
                            {
                                settings.Values["LoginSaved"] = true;
                                settings.Values["Username"]   = cpr.CredentialUserName;
                                settings.Values["Password"]   = cpr.CredentialPassword;
                            }
                            context.AuthenticationCredentials = new Credentials(cpr.CredentialUserName, cpr.CredentialPassword);
                            loginSuccess = await context.ValidateCredentialsAsync();

                            if (!loginSuccess)
                            {
                                settings.Values["LoginSaved"] = false;
                            }
                        }
                        else
                        {
                            Application.Current.Exit();
                        }
                    }
                }
            }
            await context.InitAsync();

            foreach (KeyValuePair <int, Recipient> r in context.Recipients)
            {
                recipientsListBox.Items.Add(r.Value);
            }
            foreach (KeyValuePair <int, Conversation> c in context.Conversations)
            {
                conversationsListBox.Items.Add(c.Value);
            }

            context.StreamUpdate += async(s, ev) =>
            {
                if (ev.Error == null)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        streamEventsListBox.Items.Add(ev.EventType + " | " + ev.ObjectType + " | " + ev.Object);
                        switch (ev.ObjectType)
                        {
                        case ObjectType.Recipient:
                            recipientsListBox.Items.Clear();
                            foreach (KeyValuePair <int, Recipient> r in context.Recipients)
                            {
                                recipientsListBox.Items.Add(r.Value);
                            }
                            break;

                        case ObjectType.Conversation:
                            conversationsListBox.Items.Clear();
                            foreach (KeyValuePair <int, Conversation> c in context.Conversations)
                            {
                                conversationsListBox.Items.Add(c.Value);
                                if (currentConversation != null)
                                {
                                    if (currentConversation.Id == c.Value.Id)
                                    {
                                        currentConversation = c.Value;
                                        conversationMessagesListBox.Items.Clear();
                                        foreach (Message m in currentConversation.Messages)
                                        {
                                            conversationMessagesListBox.Items.Add(m);
                                        }
                                    }
                                }
                            }
                            break;
                        }
                        if (ev.EventType == EventType.Add && ev.ObjectType == ObjectType.Message)
                        {
                            var message = ev.Object as Message;
                            if (!message.FromMe)
                            {
                                string pictureFileName = Path.GetTempFileName();
                                if (message.From.HasPicture)
                                {
                                    using (IInputStream iis = await context.DownloadRecipientPictureAsync(message.From.Id))
                                        using (FileStream fs = File.Create(pictureFileName))
                                            iis.AsStreamForRead().CopyTo(fs);
                                }

                                ToastNotifier tn = ToastNotificationManager.CreateToastNotifier();
                                XmlDocument nx   = new XmlDocument();
                                nx.LoadXml(string.Format(@"<toast>
    <visual>
        <binding template=""ToastGeneric"">
            <text hint-maxLines=""1"">{0}</text>
            <text>{1}</text>
            <image placement=""appLogoOverride"" hint-crop=""circle"" src=""{2}""/>
        </binding>
    </visual>
    <actions>
        <input id=""replyTextBox"" type=""text"" placeHolderContent=""Reply...""/>
        <action
          content=""Send""
          arguments=""address={3}&sms={4}""/>
    </actions>
</toast>", message.From.Name, message.Text, message.From.HasPicture ? pictureFileName : "", message.From.Address, message.ServiceType == ServiceType.SMS ? "1" : "0"));
                                ToastNotification n = new ToastNotification(nx);
                                tn.Show(n);
                            }
                        }
                    });
                }
                else if (ev.Error.Message.ToLower().Contains("closed")) // Reconnect when the stream closes unexpectedly.
                {
                    await context.StartStreamAsync();
                }
                else
                {
                    throw ev.Error;
                }
            };
        }