Skip to content

Commit 417477f

Browse files
author
Valtteri Heikkila
committed
Added OAuth2Live WinRT sample.
1 parent 636e26a commit 417477f

20 files changed

+2768
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Application
2+
x:Class="OAuth2Live.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:OAuth2Live">
6+
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
11+
<!--
12+
Styles that define common aspects of the platform look and feel
13+
Required by Visual Studio project and item templates
14+
-->
15+
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
16+
</ResourceDictionary.MergedDictionaries>
17+
18+
</ResourceDictionary>
19+
</Application.Resources>
20+
</Application>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
// App.xaml.cpp
3+
// Implementation of the App class.
4+
//
5+
6+
#include "pch.h"
7+
#include "MainPage.xaml.h"
8+
9+
using namespace OAuth2Live;
10+
11+
using namespace Platform;
12+
using namespace Windows::ApplicationModel;
13+
using namespace Windows::ApplicationModel::Activation;
14+
using namespace Windows::Foundation;
15+
using namespace Windows::Foundation::Collections;
16+
using namespace Windows::UI::Xaml;
17+
using namespace Windows::UI::Xaml::Controls;
18+
using namespace Windows::UI::Xaml::Controls::Primitives;
19+
using namespace Windows::UI::Xaml::Data;
20+
using namespace Windows::UI::Xaml::Input;
21+
using namespace Windows::UI::Xaml::Interop;
22+
using namespace Windows::UI::Xaml::Media;
23+
using namespace Windows::UI::Xaml::Navigation;
24+
25+
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
26+
27+
/// <summary>
28+
/// Initializes the singleton application object. This is the first line of authored code
29+
/// executed, and as such is the logical equivalent of main() or WinMain().
30+
/// </summary>
31+
App::App()
32+
{
33+
InitializeComponent();
34+
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
35+
}
36+
37+
/// <summary>
38+
/// Invoked when the application is launched normally by the end user. Other entry points
39+
/// will be used when the application is launched to open a specific file, to display
40+
/// search results, and so forth.
41+
/// </summary>
42+
/// <param name="args">Details about the launch request and process.</param>
43+
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args)
44+
{
45+
auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
46+
47+
// Do not repeat app initialization when the Window already has content,
48+
// just ensure that the window is active
49+
if (rootFrame == nullptr)
50+
{
51+
// Create a Frame to act as the navigation context and associate it with
52+
// a SuspensionManager key
53+
rootFrame = ref new Frame();
54+
55+
if (args->PreviousExecutionState == ApplicationExecutionState::Terminated)
56+
{
57+
// TODO: Restore the saved session state only when appropriate, scheduling the
58+
// final launch steps after the restore is complete
59+
}
60+
61+
if (rootFrame->Content == nullptr)
62+
{
63+
// When the navigation stack isn't restored navigate to the first page,
64+
// configuring the new page by passing required information as a navigation
65+
// parameter
66+
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments))
67+
{
68+
throw ref new FailureException("Failed to create initial page");
69+
}
70+
}
71+
// Place the frame in the current Window
72+
Window::Current->Content = rootFrame;
73+
// Ensure the current window is active
74+
Window::Current->Activate();
75+
}
76+
else
77+
{
78+
if (rootFrame->Content == nullptr)
79+
{
80+
// When the navigation stack isn't restored navigate to the first page,
81+
// configuring the new page by passing required information as a navigation
82+
// parameter
83+
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments))
84+
{
85+
throw ref new FailureException("Failed to create initial page");
86+
}
87+
}
88+
// Ensure the current window is active
89+
Window::Current->Activate();
90+
}
91+
}
92+
93+
/// <summary>
94+
/// Invoked when application execution is being suspended. Application state is saved
95+
/// without knowing whether the application will be terminated or resumed with the contents
96+
/// of memory still intact.
97+
/// </summary>
98+
/// <param name="sender">The source of the suspend request.</param>
99+
/// <param name="e">Details about the suspend request.</param>
100+
void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
101+
{
102+
(void) sender; // Unused parameter
103+
(void) e; // Unused parameter
104+
105+
//TODO: Save application state and stop any background activity
106+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// App.xaml.h
3+
// Declaration of the App class.
4+
//
5+
6+
#pragma once
7+
8+
#include "App.g.h"
9+
10+
namespace OAuth2Live
11+
{
12+
/// <summary>
13+
/// Provides application-specific behavior to supplement the default Application class.
14+
/// </summary>
15+
ref class App sealed
16+
{
17+
public:
18+
App();
19+
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args) override;
20+
21+
private:
22+
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
23+
};
24+
}
801 Bytes
Loading
329 Bytes
Loading
2.1 KB
Loading
429 Bytes
Loading

0 commit comments

Comments
 (0)