Strange roster presence in agsXMPP (probably an android device) - c#

I am using the agsXMPP SDK to create a small GTalk client in C#.
XmppClientConnection connection = new XmppClientConnection();
.
.
.
connection.OnPresence += new PresenceHandler(xmpp_OnPresence);
private void xmpp_OnPresence(object sender, Presence pres)
{
Console.WriteLine(pres.pres.From.User); // this is "3aav33e8erudg29gzjg***"
}
I can read most contacts with their username, but some are not very useful.
This is the body:
<presence xmlns="jabber:client" from="3aav33e8erudg29gzjg*****c#public.talk.google.com/android_talkc2f2f*******" to="**************#gmail.com/agsXMPP678C2F26"><priority>24</priority><caps:c xmlns:caps="http://jabber.org/protocol/caps" node="http://www.android.com/gtalk/client/caps" ver="1.1" ext="pmuc-v1 voice-v1 video-v1 camera-v1" /><show>away</show><x xmlns="vcard-temp:x:update"><photo>4d211fc**************90a130a1345425b1e</photo></x></presence>
Is there any way to get a readable username from this? This person seems to be my contact, but I don't know who it is...

This are automatically created contacts from Google+ circles as far as I know.
The real Google id is hidden for privacy reasons. If you don't want these contacts you can disable them in the G+ Chat privacy settings.

Related

Adding contacts to People on Windows Phone 8.1 in C#

Is there a way to add contacts from my app to the People app on a Windows Phone 8.1? I looked at different things under the Contact class and nothing seems to work. There are different ways (like ContactManager, ContactPicket, etc.) to retrieve data but nothing seems to allow me to add a new contact as most of the stuff like SaveContactTask in Microsoft.Phone.Tasks is not implemented on WP 8.1.
J.
You don't have write access to the primary contact store on Windows Phone 8, but you have the ability to create your own contact store for the app which you can use to manage contacts created in your own app.
The mechanism is pretty simple:
using Windows.Phone.PersonalInformation;
public async void addPerson() {
var store = await ContactStore.CreateOrOpenAsync();
var contact = new StoredContact(store) {
DisplayName = "Mike Peterson"
};
var props = await contact.GetPropertiesAsync();
props.add(KnownContactProperties.Email, "mike#peterson.com");
props.add(KnownContactProperties.MobileTelephone, "+1 212 555 1234");
await contact.SaveAsync();
}
To inform the OS that you provide contact information, you need to add the ID_CAP_CONTACTS/Contacts capability to your app (in the Capabilities section of the appxmanifest). Contacts remain until the app is removed.
Private, owned by the app contacts are convenient for 'contact' data for the app.

Contact presence/status on Lync 2013 SDK shows "Presence unknown" until manual client search

I'm working on an automation service for lync that will automatically add people to an IM conversation based on their availability/lync "presence". It essentially goes down a list, checks who is online, and adds the first person to a call.
The problem I'm getting is that sometimes (usually when lync had to be restarted), it does not always fetch the contact's presence.
First I just had it grab the presence. Then I added code to check for the ContactInformationChanged event firing, but that does not seem to happen unless I go into the app and manually type the alias I'm looking for.
Is there a Refresh() method I'm missing somewhere? Or is there any way to force it to find this? Here's my search methods:
public Contact GetContact(string emailAddress)
{
Contact user;
lock (ContactLookupCache)
{
while (!ContactLookupCache.TryGetValue(emailAddress.ToLower(), out user))
{
lock (Client)
{
Client.ContactManager.BeginSearch(emailAddress, this.HandleContactLookup, null);
}
Monitor.Wait(ContactLookupCache);
}
}
return user;
}
public string GetContactPresenceState(Contact contact)
{
string presenceStatus = contact.GetContactInformation(ContactInformationType.Activity).ToString();
// see if the status is either "Presence unknown" or "Updating..."
if (IsUnknownPresenceState(presenceStatus))
{
lock (contact)
{
//bug?? This event seems to only fire sometimes when you search on the app for contact details
contact.ContactInformationChanged += (object sender, ContactInformationChangedEventArgs e) =>
{
if (e.ChangedContactInformation.Contains(ContactInformationType.Activity))
{
lock (contact)
{
presenceStatus = contact.GetContactInformation(ContactInformationType.Activity).ToString();
if(!IsUnknownPresenceState(presenceStatus))
Monitor.PulseAll(contact);
}
}
};
Monitor.Wait(contact);
}
}
return presenceStatus;
}
Also, sorry for the crappy code... I was just trying to get it to work and kept throwing more junk code in hoping something would help.
Could you verify that the code works fine for all the contacts in your contact list and it's just the ones that aren't listed where presence change events aren't raised correctly?
This makes sense to me given you are using the client SDK which will only tell you about events the client is interested in. For example it would be pretty traffic intensive if all 85,000 clients received the presence changes for the other 85,000 clients in a company.
I think you are in the realms of either polling the presence at regular intervals or adding the contacts to the client (perhaps under a relevant group just to keep things tidy).
Failing that you may want to looking into the UCMA SDK which is better suited to centralised services than the client SDK.

Selenium Webdriver automation with emails

I'm currently trying to use Selenium Webdriver (C#) to automate a Forgot Password -> Reset Password workflow, where the user navigates to a page and supplies their username, and the backend code validates the username, then sends an email with a reset password link to the email address associated with their account.
I'm able to automate the process up to the point where the code sends the email, but I don't know any ways of checking for the email and/or clicking a link in the email, so I was hoping someone more experienced with Selenium/automation may be able to give me a few pointers.
Ideally the test should not care about the email address that the email is being sent to. Is there a way for Selenium WebDriver or some 3rd party package to catch the email being sent?
Thanks for any input or suggestions.
No. You are talking about setting up an email server, which is not an easy task.
You should send it to a test work email (if this is for a company), or a public email (hotmail/gmail), or if security is not an issue at all, the easiest place to send it would be a disposable email (mailinator)
You could try PutsBox. You can send an email to whatever-you-want#putsbox.com, wait for a few seconds (SMTP stuff ins't instantaneous) then check your email via http://preview.putsbox.com/p/whatever-you-want/last.
Have a look at this post tutorial, it can give you some ideas.
There is no integration of selenium with email clients like Thunderbird/Outlook. But if you have a web interface of the same email client, then you can access the email from browser and using selenium you can read and respond to the emails. I have tried this recently and it works fine where I have used web Outlook for testing.
Hope this helps.
Hi I was in a similar situation and was able to successfully implement a way to get an activation or forgotten password links.
Using Java Mail API I was able to trigger a method when such action is performed which goes into a Folder and read a specific message line then get the link and open it up in a browser using WebDriver.
However the main drawback with this is the inconsistency of reading a specific folder, sometimes emails goes to spam or other folder (in case of Gmail the new Social Folder) making it invisible or difficult to be retrieved.
Overall i think its a process that shouldn't really be automated, In terms of testing it should be done more code base level by mocking responses.
Snippet below should give you an idea on how to go about implementing
public class RefactoredMail {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("imap.gmail.com", "username", "password");
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message msg = inbox.getMessage(inbox.getMessageCount());
Address[] in = msg.getFrom();
for (Address address : in) {
System.out.println("FROM:" + address.toString());
}
Multipart mp = (Multipart) msg.getContent();
BodyPart bp = mp.getBodyPart(0);
System.out.println("SENT DATE:" + msg.getSentDate());
System.out.println("SUBJECT:" + msg.getSubject());
System.out.println("CONTENT:" + bp.getContent());
System.out.println("Activation Link:" + ((String)
bp.getContent()).startsWith("http"));
String [] line = new String[1];
line [0] = mp.getContentType().toString();
System.out.println("Activation Link:" + (mp.getBodyPart(0).getLineCount()));
System.out.println("Activation Link:" +line[0]);
} catch (Exception e) {
e.printStackTrace();
}
//WebDriver Stuffs
public String activationUrl() {
//getting the url link and making it a global variable .... etc
//Accessing the link
}
}
You can use https://github.com/cmendible/netDumbster or http://ndumbster.sourceforge.net/default.html. I've used one i forget which. This will host an smtp listener and allow you to make assertions against any email it receives. Its kind of awesome! The caveat is you need to be able to control where the server delivers mail in the environment you are testing.

How to send email with C# on Windows Phone 8 with from field

As I tried to explain in the title, I need to send emails in my WP8 app from my own account not by the existing accounts on the phone. I plan to use this for password reset process. What I currently use is:
private void Button_Click(object sender, RoutedEventArgs e)
{
EmailComposeTask emailcomposer = new EmailComposeTask();
emailcomposer.To = "AMailAdress";
emailcomposer.Subject = "subject from test app";
emailcomposer.Body = "This is a test mail from Email Composer";
emailcomposer.Show();
}
This just sends via user's accounts. Shortly, I need a way to set from field sending an email. Any help is appreciated.
You should better send email from the server, not from windows phone app.
If it doesn't need user's account then there is no reason for the email to be created from the phone.
Maybe you can POST to an URL with required info, and make the server (your service) send the email.

How do I get Google Calendar feed from user's access token?

Using OAuth I do get access token from Google. The sample that comes with Google and even this one:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
show how to use Tasks API. However, I want to use Calendar API. I want to get access to user's calendar. Can anybody tell me how do I do that?
Take a look at the samples:
Getting Started with the .NET Client Library
On the right side of the page linked above there is a screen shot showing the sample projects contained in the Google Data API solution. They proofed to be very helpful (I used them to start my own Google Calendar application).
I recommend keeping both your own solution and the sample solution open. This way you can switch between the examples and your own implementation.
I also recommend to use the NuGet packages:
Google.GData.AccessControl
Google.GData.Calendar
Google.GData.Client
Google.GData.Extensions
and more ...
This way you easily stay up to date.
Sample to get the users calendars:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
}

Categories