Skip to content

Commit 303a3dc

Browse files
committed
add windowsLiveAuth sample
1 parent d8cb525 commit 303a3dc

25 files changed

+3318
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Application
2+
x:Class="WindowsLiveAuth.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:WindowsLiveAuth">
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/***
2+
* ==++==
3+
*
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
****/
17+
18+
#include "pch.h"
19+
#include "MainPage.xaml.h"
20+
21+
using namespace WindowsLiveAuth;
22+
23+
using namespace Platform;
24+
using namespace Windows::ApplicationModel;
25+
using namespace Windows::ApplicationModel::Activation;
26+
using namespace Windows::Foundation;
27+
using namespace Windows::Foundation::Collections;
28+
using namespace Windows::UI::Xaml;
29+
using namespace Windows::UI::Xaml::Controls;
30+
using namespace Windows::UI::Xaml::Controls::Primitives;
31+
using namespace Windows::UI::Xaml::Data;
32+
using namespace Windows::UI::Xaml::Input;
33+
using namespace Windows::UI::Xaml::Interop;
34+
using namespace Windows::UI::Xaml::Media;
35+
using namespace Windows::UI::Xaml::Navigation;
36+
37+
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
38+
39+
/// <summary>
40+
/// Initializes the singleton application object. This is the first line of authored code
41+
/// executed, and as such is the logical equivalent of main() or WinMain().
42+
/// </summary>
43+
App::App()
44+
{
45+
InitializeComponent();
46+
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
47+
}
48+
49+
/// <summary>
50+
/// Invoked when the application is launched normally by the end user. Other entry points
51+
/// will be used when the application is launched to open a specific file, to display
52+
/// search results, and so forth.
53+
/// </summary>
54+
/// <param name="args">Details about the launch request and process.</param>
55+
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args)
56+
{
57+
auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
58+
59+
// Do not repeat app initialization when the Window already has content,
60+
// just ensure that the window is active
61+
if (rootFrame == nullptr)
62+
{
63+
// Create a Frame to act as the navigation context and associate it with
64+
// a SuspensionManager key
65+
rootFrame = ref new Frame();
66+
67+
if (args->PreviousExecutionState == ApplicationExecutionState::Terminated)
68+
{
69+
// TODO: Restore the saved session state only when appropriate, scheduling the
70+
// final launch steps after the restore is complete
71+
72+
}
73+
74+
if (rootFrame->Content == nullptr)
75+
{
76+
// When the navigation stack isn't restored navigate to the first page,
77+
// configuring the new page by passing required information as a navigation
78+
// parameter
79+
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments))
80+
{
81+
throw ref new FailureException("Failed to create initial page");
82+
}
83+
}
84+
// Place the frame in the current Window
85+
Window::Current->Content = rootFrame;
86+
// Ensure the current window is active
87+
Window::Current->Activate();
88+
}
89+
else
90+
{
91+
if (rootFrame->Content == nullptr)
92+
{
93+
// When the navigation stack isn't restored navigate to the first page,
94+
// configuring the new page by passing required information as a navigation
95+
// parameter
96+
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments))
97+
{
98+
throw ref new FailureException("Failed to create initial page");
99+
}
100+
}
101+
// Ensure the current window is active
102+
Window::Current->Activate();
103+
}
104+
}
105+
106+
/// <summary>
107+
/// Invoked when application execution is being suspended. Application state is saved
108+
/// without knowing whether the application will be terminated or resumed with the contents
109+
/// of memory still intact.
110+
/// </summary>
111+
/// <param name="sender">The source of the suspend request.</param>
112+
/// <param name="e">Details about the suspend request.</param>
113+
void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
114+
{
115+
(void) sender; // Unused parameter
116+
(void) e; // Unused parameter
117+
118+
//TODO: Save application state and stop any background activity
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/***
2+
* ==++==
3+
*
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
****/
17+
18+
#pragma once
19+
20+
#include "App.g.h"
21+
22+
namespace WindowsLiveAuth
23+
{
24+
/// <summary>
25+
/// Provides application-specific behavior to supplement the default Application class.
26+
/// </summary>
27+
ref class App sealed
28+
{
29+
public:
30+
App();
31+
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args) override;
32+
33+
private:
34+
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
35+
};
36+
}
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)