Sunteți pe pagina 1din 8

Ministerul Educaiei al Republicii Moldova

Universitatea Tehnic a Moldovei


Facultatea Calculatoare, Informatic i Microelectronic

Raport
Lucrarea de laborator nr. 3
Programarea Aplicaiilor Incorporate i Independente de Platform

Tema: Elaborarea unei aplicaii pe platforma Windows Phone

A efectuat:

St. gr. TI-114 Vasilachi Igor

A verificat:

Antohi I.

Chiinu 2013

Sarcina lucrrii:
Elaborarea unei aplicaii cu urmtoarelor funcionaliti:
Crearea unui RSS reader;
Postarea unui mesaje/status pe Facebook;
Crearea unui reminder;
Efectuarea lucrrii:
Pentru a crea un proiect pe platforma Windows Phone este nevoie de descrcat de pe site-ul
oficial de la Microsoft pachetul Windows Phone SDK, standart el vine n format Web Installer. Dup
ce se va instala acest pachet se va deschide aplicaia Microsoft Visual Studio 2010 for Windows
Phone, acesta este un IDE ce ajut la dezvoltarea aplicaiilor pentru Windows Phone.
n urmtoarele imagini sunt reprezentate funcionalitile aplicaiei, fiecare funcionalitate
utiliznd o pagin separat.

Imaginea 1 Facebook i Rss reader

Imaginea 2 Reminder-ul
Anexa A: RssReader.cs
namespace RFRWindowsPhone
{
public partial class RssReader : PhoneApplicationPage
{
public RssReader()
{
InitializeComponent();
}
private void loadFeedButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new
System.Uri("http://feeds.reuters.com/reuters/entertainment"));
}
private void webClient_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(e.Error.Message);
});
}

else
{
this.State["feed"] = e.Result;
UpdateFeedList(e.Result);
}

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)


{
if (this.State.ContainsKey("feed"))
{
if (feedListBox.Items.Count == 0)
{
UpdateFeedList(State["feed"] as string);
}
}
}
private void UpdateFeedList(string feedXML)
{
StringReader stringReader = new StringReader(feedXML);
XmlReader xmlReader = XmlReader.Create(stringReader);
SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
feedListBox.ItemsSource = feed.Items;
loadFeedButton.Content = "Refresh Feed";
});
}
private void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem;

}
}

if (sItem.Links.Count > 0)
{
Uri uri = sItem.Links.FirstOrDefault().Uri;
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = uri;
webBrowserTask.Show();
}

Anexa B: MainPage.css - Facebook


namespace RFRWindowsPhone

{
public partial class MainPage : PhoneApplicationPage
{
private const string FBApiID = "254928747992451";
private const string ExtendedPermisions = "publish_stream";
private static FacebookClient client;
public MainPage()
{
client = new FacebookClient();
client.PostCompleted += (o, args) =>
{
if (args.Error != null)
{
var error = args.Error as FacebookApiException;
if (error.ErrorCode == 190)
{
Dispatcher.BeginInvoke(() => MessageBox.Show("Eroare de autentificare !!"));
SaveToken(null);
client.AccessToken = null;
return;
}
Dispatcher.BeginInvoke(() => MessageBox.Show(error.Message));
return;
}
var result = (IDictionary<string, object>)args.GetResultData();
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Messajul a fost postat cu succes!");
Browser.Visibility = System.Windows.Visibility.Collapsed;
});
};

if (GetToken() != null)
client.AccessToken = GetToken();
InitializeComponent();

private void BrowserNavitaged(object sender, System.Windows.Navigation.NavigationEventArgs


e)

{
FacebookOAuthResult oauthResult;
if (!client.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
return;
}
if (oauthResult.IsSuccess)
{
//Process result
client.AccessToken = oauthResult.AccessToken;
SaveToken(client.AccessToken);
LoginSucceded();
}
else
{
//Process Error
MessageBox.Show(oauthResult.ErrorDescription);
Browser.Visibility = System.Windows.Visibility.Collapsed;
}

}
private void LoginSucceded()
{
Browser.Visibility = System.Windows.Visibility.Collapsed;
PostToWall();
}
private void PostToWall()
{
var parameters = new Dictionary<string, object>();
parameters["message"] = tbMessage.Text;
client.PostAsync("me/feed", parameters);
}
private void SaveToken(String token)
{
if (!IsolatedStorageSettings.ApplicationSettings.Contains("token"))
IsolatedStorageSettings.ApplicationSettings.Add("token", token);
else
IsolatedStorageSettings.ApplicationSettings["token"] = token;
IsolatedStorageSettings.ApplicationSettings.Save();
}
private string GetToken()
{
if (!IsolatedStorageSettings.ApplicationSettings.Contains("token"))
return null;
else
return IsolatedStorageSettings.ApplicationSettings["token"] as string;
}
private void postFacebook_Click(object sender, RoutedEventArgs e)
{
//Cheking if there's internet
if (!NetworkInterface.GetIsNetworkAvailable())
{
Dispatcher.BeginInvoke(() => { MessageBox.Show("No Internet Connection, Try again
later"); });
return;
}
if (client.AccessToken == null)
{
var parameters = new Dictionary<string, object>();
parameters["client_id"] = FBApiID;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "touch";
parameters["scope"] = ExtendedPermisions;
Browser.Visibility = System.Windows.Visibility.Visible;
string t = client.GetLoginUrl(parameters).AbsoluteUri;
Browser.Navigate(client.GetLoginUrl(parameters));
}
else
PostToWall();
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (Browser.Visibility == System.Windows.Visibility.Visible)
{
Browser.Visibility = System.Windows.Visibility.Collapsed;

e.Cancel = true;
}
base.OnBackKeyPress(e);
}
private void reminder_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/ShowReminder.xaml", UriKind.Relative));
}
private void button3_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/RssReader.xaml", UriKind.Relative));
}
}

Anexa C: RssGetTextTrim.cs
using
using
using
using
using

System;
System.Net;
System.Windows.Data;
System.Globalization;
System.Text.RegularExpressions;

namespace RFRWindowsPhone
{
public class RssGetTextTrim : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
int maxLength = 200;
int strLength = 0;
string fixedString = "";
// Remove HTML tags.
fixedString = Regex.Replace(value.ToString(), "<[^>]+>", string.Empty);
// Remove newline characters
fixedString = fixedString.Replace("\r", "").Replace("\n", "");
// Remove encoded HTML characters
fixedString = HttpUtility.HtmlDecode(fixedString);
strLength = fixedString.ToString().Length;
if (strLength == 0) {return null; }
else if (strLength >= maxLength)
{
fixedString = fixedString.Substring(0, maxLength);
fixedString = fixedString.Substring(0, fixedString.LastIndexOf(" "));
}
fixedString += "...";
return fixedString;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();

}
}

Anexa D: ShowReminder.cs
namespace RFRWindowsPhone
{
public partial class ShowReminder : PhoneApplicationPage
{
public ShowReminder()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
string reminderName = Guid.NewGuid().ToString();
Reminder reminder = new Reminder(reminderName);
reminder.Title = this.txtTitle.Text;
reminder.Content = this.txtContent.Text;
double seconds = 10.0;
double.TryParse(this.txtSeconds.Text, out seconds);
reminder.BeginTime = DateTime.Now.AddSeconds(seconds);
reminder.ExpirationTime = reminder.BeginTime.AddSeconds(5.0);
reminder.RecurrenceType = RecurrenceInterval.Daily;
ScheduledActionService.Add(reminder);
this.NavigationService.GoBack();
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.GoBack();
}
}
}

Concluzii:
Efectund aceast lucrare de laborator m-am familizarizat cu pachetul SDK de la Windows
Phone ce mi-a oferit posibiliatea de a crea aplicaii rapid i uor. Am creat o simpl aplicaie care
efectueaz urmtoarele operaii ca Postarea unui mesaj pe Facebook, citirea unui Rss i afiarea lui
ntr-o list, crearea unui reminder care lucreaz n background.