Which four lines of code should you use to create the Run() method on line SP13?

###BeginCaseStudy###
Case Study: 3
E-reader app
Background
You are developing a Windows Store style e-reader app.
Business Requirements
• Users must be able to upload e-books and documents and download them to ereader devices.
• Users must be able to set a password to restrict access to their e-books and
documents.
• Users must be able to create and store encrypted metadata about their e-books
and documents.
• The app must replace system-generated error messages with custom-defined
messages. These custom messages must come from a list of approved text.
• User actions such as printing pages, saving users’ current locations in
documents, and taking notes should be enabled from buttons on an AppBar
control.

• The app must provide trial functionality that will expire after 14 days. If the
app expires while it is running, the app must display an expiration message to
the user and prompt the user to purchase the app.
Technical Requirements
General:
• Configuration files must be read-only. All user settings must be stored in the
Contoso Settings Service.
• The SocialPoller background task must run the code in the DoWork() method
to collect content from the Contoso feed.
• The UI must always remain responsive to user actions.
Security
• Secured e-book and document passwords must to be encrypted so that only the user
who created the passwords can retrieve the metadata associated to the e-books and
documents.
• The system must log all exceptions through the auditing object and notify technicians
of the issue.
Storage:
• The app must cache the next two chapters to the local device for users to read
while disconnected from the network. This cache must be persisted if a reboot
is performed.
• User state such as the current location in an e-book or document must be
stored in the Microsoft SQL Azure database.
• User settings such as font sizes and colors must be stored through the Contoso
Settings Service.
Network:
• Communication between the app and e-book vendors must occur over an
encrypted communication channel.
• Communication must use certificates to enable the SSL connection.
Trial Functionality:
• The isPrintEnabled variable must determine if the user can print.
• The isMarketEnabled variable must determine if the user can use the
marketplace.
• The isTrialEnabled variable must determine if the application is still in trial
mode.
Printing:
• The default printing options are portrait orientation and grayscale color mode.
• The app must enable the user to select the media size and printing orientation.
SocialPoller.es

Auditor.cs

ContentPage.es

Book.cs

Book.cs

SocialPost.es

Pagel.xaml.es

App.xaml.cs

###EndCaseStudy###

DRAG DROP
You need to call the DoWork() method asynchronously in a background task.
Which four lines of code should you use to create the Run() method on line SP13? (To answer, move
the appropriate lines of code from the list of code segments to the answer area and arrange them in
the correct order.)

###BeginCaseStudy###
Case Study: 3
E-reader app
Background
You are developing a Windows Store style e-reader app.
Business Requirements
• Users must be able to upload e-books and documents and download them to ereader devices.
• Users must be able to set a password to restrict access to their e-books and
documents.
• Users must be able to create and store encrypted metadata about their e-books
and documents.
• The app must replace system-generated error messages with custom-defined
messages. These custom messages must come from a list of approved text.
• User actions such as printing pages, saving users’ current locations in
documents, and taking notes should be enabled from buttons on an AppBar
control.

• The app must provide trial functionality that will expire after 14 days. If the
app expires while it is running, the app must display an expiration message to
the user and prompt the user to purchase the app.
Technical Requirements
General:
• Configuration files must be read-only. All user settings must be stored in the
Contoso Settings Service.
• The SocialPoller background task must run the code in the DoWork() method
to collect content from the Contoso feed.
• The UI must always remain responsive to user actions.
Security
• Secured e-book and document passwords must to be encrypted so that only the user
who created the passwords can retrieve the metadata associated to the e-books and
documents.
• The system must log all exceptions through the auditing object and notify technicians
of the issue.
Storage:
• The app must cache the next two chapters to the local device for users to read
while disconnected from the network. This cache must be persisted if a reboot
is performed.
• User state such as the current location in an e-book or document must be
stored in the Microsoft SQL Azure database.
• User settings such as font sizes and colors must be stored through the Contoso
Settings Service.
Network:
• Communication between the app and e-book vendors must occur over an
encrypted communication channel.
• Communication must use certificates to enable the SSL connection.
Trial Functionality:
• The isPrintEnabled variable must determine if the user can print.
• The isMarketEnabled variable must determine if the user can use the
marketplace.
• The isTrialEnabled variable must determine if the application is still in trial
mode.
Printing:
• The default printing options are portrait orientation and grayscale color mode.
• The app must enable the user to select the media size and printing orientation.
SocialPoller.es

Auditor.cs

ContentPage.es

Book.cs

Book.cs

SocialPost.es

Pagel.xaml.es

App.xaml.cs

###EndCaseStudy###

DRAG DROP
You need to call the DoWork() method asynchronously in a background task.
Which four lines of code should you use to create the Run() method on line SP13? (To answer, move
the appropriate lines of code from the list of code segments to the answer area and arrange them in
the correct order.)

Answer: See the explanation

Explanation:
Box 1:

Box 2:

Box 3:

Box 4:

Note:
* IBackgroundTaskInstance.GetDeferral method
Informs the system that the background task might continue to perform work after the
IBackgroundTask.Run method returns.
* Example:
public async void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine(“Start background download in background task!!!”);
// Associate a cancellation handler with the background task.
//taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
// Get the deferral object from the task instance, and take a reference to the taskInstance;
_deferral = taskInstance.GetDeferral();
//m_BKDownload.ResumeAll();
// Check if file already downloaded
string inputuri = “http://www.johnhaydon.com/wpcontent/uploads/2011/07/google_plus_logo.jpg”;
string FileName = inputuri.Split(new[] { ‘/’ }).LastOrDefault();
bool b_fileFounded = false;
IReadOnlyList<StorageFile> outputFiles = await KnownFolders.PicturesLibrary.GetFilesAsync();
foreach (var file in outputFiles)
{
if (file.Name == FileName)
{
b_fileFounded = true;

}
}
if (b_fileFounded == false)
{
Debug.WriteLine(“downloading {0} in the background task”, FileName);
StorageFile destinationFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
FileName, CreationCollisionOption.GenerateUniqueName);
var downloadOperation = m_BKDownload.CreateDownload(new Uri(inputuri), destinationFile);
await downloadOperation.StartAsync().AsTask();
}
_deferral.Complete();
}
http://msdn.microsoft.com/enus/library/windows/apps/windows.applicationmodel.background.ibackgroundtaskinstance.aspx



Leave a Reply 0

Your email address will not be published. Required fields are marked *