📄 liveextract.cs
字号:
//Code by Gnilly (http://gnillydev.blogspot.com)
//Offical site: http://opencontacts.sourceforge.net
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Lesser General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Lesser General Public License for more details.
//You should have received a copy of the GNU Lesser General Public License
//along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Xml;
namespace OpenContactsNet
{
public class LiveExtract : IMailContactExtract
{
#region IMailContactExtract Members
public bool Extract( NetworkCredential credential, out MailContactList list )
{
list = new MailContactList();
bool result = false;
try
{
TicketAcquirer ticketAcquirer = new TicketAcquirer();
string ticket = ticketAcquirer.GetTicket( credential );
if ( string.IsNullOrEmpty( ticket ) )
{
return false;
}
UriBuilder urib = new UriBuilder();
urib.Scheme = "HTTPS";
urib.Path = string.Format( "/{0}/LiveContacts", credential.UserName );
urib.Host = "cumulus.services.live.com";
urib.Port = 443;
HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( urib.Uri );
string authHeader = string.Format( "WLID1.0 t=\"{0}\"", ticket );
request.Headers.Add( "Authorization", authHeader );
WebResponse response = request.GetResponse();
if ( response.ContentLength != 0 )
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load( response.GetResponseStream() );
XmlNodeList contacts = xmlDocument.SelectNodes( "/LiveContacts/Contacts/Contact" );
foreach ( XmlNode node in contacts )
{
XmlNode firstName = node.SelectSingleNode( "Profiles/Personal/FirstName" );
XmlNode lastName = node.SelectSingleNode( "Profiles/Personal/LastName" );
XmlNode firstMail = node.SelectSingleNode( "Emails/Email/Address" );
MailContact mailContact = new MailContact();
mailContact.Name = string.Format( "{0} {1}", firstName.InnerText, lastName.InnerText );
mailContact.Email = firstMail.InnerText;
list.Add( mailContact );
}
}
result = true;
}
catch
{
}
return result;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -