diff --git a/.gitattributes b/.gitattributes index 5aec15cd..39d53163 100644 --- a/.gitattributes +++ b/.gitattributes @@ -19,8 +19,10 @@ *.inf text eol=crlf *.inx text eol=crlf *.js text eol=crlf +*.json text eol=crlf *.jsproj text eol=crlf *.rc text eol=crlf +*.resjson text eol=crlf *.rgs text eol=crlf *.sln text eol=crlf *.vcxproj text eol=crlf diff --git a/README.md b/README.md index 37876aae..4b4ce0dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # Universal Windows app samples + This repo contains the samples that demonstrate the API usage patterns for the Universal Windows Platform (UWP) in the Windows Software Development Kit (SDK) for Windows 10. These code samples were created with the Universal Windows templates available in Visual Studio, and are designed to run on desktop, mobile, and future devices that support the Universal Windows Platform. ## Universal Windows Platform development + These samples require Visual Studio 2015 and the Windows Software Development Kit (SDK) for Windows 10 to build, test, and deploy your Universal Windows apps. [Get a free copy of Visual Studio 2015 Community Edition with support for building Universal Windows apps](http://go.microsoft.com/fwlink/?LinkID=280676) @@ -11,17 +13,30 @@ Additionally, to stay on top of the latest updates to Windows and the developmen [Become a Windows Insider](https://insider.windows.com/) ## Using the samples -The easiest way to use these samples without using Git is to download the zip file containing the current version (using the link below or by clicking the "Download ZIP" button on the repo page). You can then unzip the samples and use them in Visual Studio 2015. + +The easiest way to use these samples without using Git is to download the zip file containing the current version (using the link below or by clicking the "Download ZIP" button on the repo page). You can then unzip the entire archive and use the samples in Visual Studio 2015. [Download the samples ZIP](../../archive/master.zip) + **Notes:** + * Before you unzip the archive, right-click it, select Properties, and then select Unblock. + * Be sure to unzip the entire archive, and not just individual samples. The samples all depend on the SharedContent folder in the archive. + * In Visual Studio 2015, the platform target defaults to ARM, so be sure to change that to x64 or x86 if you want to test on a non-ARM device. + The samples use Linked files in Visual Studio to reduce duplication of common files, including sample template files and image assets. These common files are stored in the SharedContent folder at the root of the repository and referred to in the project files using links. +**Reminder:** If you unzip individual samples, they will not build due to references to other portions of the ZIP file that were not unzipped. You must unzip the entire archive if you intend to build the samples. + For more info about the programming models, platforms, languages, and APIs demonstrated in these samples, please refer to the guidance, tutorials, and reference topics provided in the Windows 10 documentation available in the [Windows Developer Center](https://dev.windows.com). These samples are provided as-is in order to indicate or demonstrate the functionality of the programming models and feature APIs for Windows. ## Contributions + These samples are direct from the feature teams and we welcome your input on issues and suggestions for new samples. At this time we are not accepting new samples from the public, but check back here as we evolve our contribution model. +## See also + +For additional Windows samples, see [Windows on GitHub](http://microsoft.github.io/windows/). + ## Samples by category @@ -116,44 +131,45 @@ These samples are direct from the feature teams and we welcome your input on iss - + + - + - + - + - + - + - + - +
Context menu (XAML) Downloadable fonts (DirectWrite)Line spacing (DirectWrite)Drag and drop
Line spacing (DirectWrite) Focus visuals Full screen modeHTML WebView control
HTML WebView control ListView and GridView Lock screen appsMessage dialog
Message dialog Multiple views OCRPrinting
Printing Pull to refresh Window resizingScaling according to DPI
Scaling according to DPI Splash screen State triggersTitle bar
Title bar Disabling selection User interaction modeCommanding
Commanding Downloadable fonts (XAML) Responsiveness techniquesTailored multiple views
Tailored multiple views XAML UI basics
@@ -212,10 +228,10 @@ These samples are direct from the feature teams and we welcome your input on iss Accelerometer Activity detection sensor - AllJoyn consumer experiences + AllJoyn Consumer experiences - AllJoyn producer experiences + AllJoyn Producer experiences Altimeter Background sensors @@ -334,7 +350,7 @@ These samples are direct from the feature teams and we welcome your input on iss Identity, security, and encryption - Account picture name + User information Credential locker Credential picker @@ -376,11 +392,12 @@ These samples are direct from the feature teams and we welcome your input on iss Navigation + Back Button Master/detail Pivot - Projection + Projection XAML navigation menu XHR, handling navigation errors, and URL schemes @@ -451,7 +468,7 @@ These samples are direct from the feature teams and we welcome your input on iss Tiles, toasts, and notifications - Badge + Notifications Secondary tiles \ No newline at end of file diff --git a/Samples/Accelerometer/README.md b/Samples/Accelerometer/README.md index 4c5b435a..fc88df7d 100644 --- a/Samples/Accelerometer/README.md +++ b/Samples/Accelerometer/README.md @@ -1,4 +1,4 @@ - @@ -54,9 +54,10 @@ When you choose the **Enable** button for the **Data Events** option, the app be ## Build the sample -1. Start Microsoft Visual Studio 2015 and select **File** \> **Open** \> **Project/Solution**. -2. Go to the directory to which you unzipped the sample. Then go to the subdirectory containing the sample in the language you desire - either C++ or C\#. Double-click the Visual Studio 2015 Solution (.sln) file. -3. Press Ctrl+Shift+B, or select **Build** \> **Build Solution**. +1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build. +2. Start Microsoft Visual Studio 2015 and select **File** \> **Open** \> **Project/Solution**. +3. Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio 2015 Solution (.sln) file. +4. Press Ctrl+Shift+B, or select **Build** \> **Build Solution**. ## Run the sample diff --git a/Samples/AccountPictureName/README.md b/Samples/AccountPictureName/README.md deleted file mode 100644 index 789d459b..00000000 --- a/Samples/AccountPictureName/README.md +++ /dev/null @@ -1,53 +0,0 @@ - -# Account picture name sample - -This sample demonstrates different ways of getting the name of the user that is currently logged in. It also demonstrates how to get and set the image used for the user's tile. - -Specifically, this sample demonstrates the following scenarios: - -- How to get the [**DisplayName**](http://msdn.microsoft.com/library/windows/apps/hh921595) for the current logged on user. -- How to get the first and last name for the current logged on user. (This is available only for Microsoft accounts. An empty string is returned if a Microsoft account is not available.) -- How to obtain the logged on user's account picture as a bitmap. You can get request three different types: small, large, and video. If the size that is requested is not available an empty file is returned. -- How to set the account picture for the currently logged on user. You can set three different types: small, large, and video. (More than one type can be set in the same call, but a small image must be accompanied by a large image and/or video.) -- How to register for a change event for account picture updates. - -**Note** The Universal Windows app samples require Visual Studio 2015 to build and Windows 10 to execute. - -To obtain information about Windows 10, go to [Windows 10](http://go.microsoft.com/fwlink/?LinkID=532421) - -To obtain information about Microsoft Visual Studio 2015 and the tools for developing Windows apps, go to [Visual Studio 2015](http://go.microsoft.com/fwlink/?LinkID=532422) - -## Related topics - -### Reference - -[**Windows.System.UserProfile** namespace](http://msdn.microsoft.com/library/windows/apps/br241881) - -## System requirements - -**Client:** Windows 10 - -**Server:** Windows Server 2016 Technical Preview - -**Phone:** Not supported - -## Build the sample - -1. Start Microsoft Visual Studio 2015 and select **File** \> **Open** \> **Project/Solution**. -2. Go to the directory to which you unzipped the sample. Then go to the subdirectory containing the sample in the language you desire - either C++, C#, or JavaScript. Double-click the Visual Studio 2015 Solution (.sln) file. -3. Press Ctrl+Shift+B, or select **Build** \> **Build Solution**. - -## Run the sample - -The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it. - -### Deploying the sample - -- Select Build > Deploy Solution. - -### Deploying and running the sample - -- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or select Debug > Start Without Debugging. - diff --git a/Samples/AccountPictureName/cpp/GetAccountPicture.xaml.cpp b/Samples/AccountPictureName/cpp/GetAccountPicture.xaml.cpp deleted file mode 100644 index 6570deef..00000000 --- a/Samples/AccountPictureName/cpp/GetAccountPicture.xaml.cpp +++ /dev/null @@ -1,155 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -#include "pch.h" -#include "GetAccountPicture.xaml.h" - -using namespace SDKTemplate; - -using namespace concurrency; -using namespace Platform; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::Storage; -using namespace Windows::Storage::Streams; -using namespace Windows::System::UserProfile; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Controls::Primitives; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::UI::Xaml::Media::Imaging; -using namespace Windows::UI::Xaml::Navigation; - -GetAccountPicture::GetAccountPicture() : rootPage(MainPage::Current) -{ - InitializeComponent(); -} - -void GetAccountPicture::GetSmallImageButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - HideImageAndVideoControls(); - - if (UserInformation::NameAccessAllowed) - { - auto smallImageFile = UserInformation::GetAccountPicture(AccountPictureKind::SmallImage); - if (smallImageFile != nullptr) - { - rootPage->NotifyUser("Path = " + smallImageFile->Path, NotifyType::StatusMessage); - create_task(smallImageFile->OpenReadAsync()).then( - [this](task imageStreamTask) - { - try - { - auto imageStream = imageStreamTask.get(); - auto bitmapImage = ref new BitmapImage(); - bitmapImage->SetSource(imageStream); - SmallImage->Source = bitmapImage; - SmallImage->Visibility = Windows::UI::Xaml::Visibility::Visible; - } - catch (Exception^ ex) - { - rootPage->NotifyUser("Error opening stream: " + ex->Message, NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("Small account picture is not available.", NotifyType::ErrorMessage); - } - } - else - { - rootPage->NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } -} - -void GetAccountPicture::GetLargeImageButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - HideImageAndVideoControls(); - - if (UserInformation::NameAccessAllowed) - { - auto largeImageFile = UserInformation::GetAccountPicture(AccountPictureKind::LargeImage); - if (largeImageFile != nullptr) - { - rootPage->NotifyUser("Path = " + largeImageFile->Path, NotifyType::StatusMessage); - create_task(largeImageFile->OpenReadAsync()).then( - [this](task imageStreamTask) - { - try - { - auto imageStream = imageStreamTask.get(); - auto bitmapImage = ref new BitmapImage(); - bitmapImage->SetSource(imageStream); - LargeImage->Source = bitmapImage; - LargeImage->Visibility = Windows::UI::Xaml::Visibility::Visible; - } - catch (Exception^ ex) - { - rootPage->NotifyUser("Error opening stream: " + ex->Message, NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("No large account picture image returned for current user.", NotifyType::ErrorMessage); - } - } - else - { - rootPage->NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } -} - -void GetAccountPicture::GetVideoButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - HideImageAndVideoControls(); - - if (UserInformation::NameAccessAllowed) - { - auto videoFile = UserInformation::GetAccountPicture(AccountPictureKind::Video); - if (videoFile != nullptr) - { - rootPage->NotifyUser("Path = " + videoFile->Path, NotifyType::StatusMessage); - create_task(videoFile->OpenReadAsync()).then( - [this](task videoStreamTask) - { - try - { - auto videoStream = videoStreamTask.get(); - MediaPlayer->SetSource(videoStream, "video/mp4"); - MediaPlayer->Visibility = Windows::UI::Xaml::Visibility::Visible; - } - catch (Exception^ ex) - { - rootPage->NotifyUser("Error opening stream: " + ex->Message, NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("Video is not available.", NotifyType::ErrorMessage); - } - } - else - { - rootPage->NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } -} - -void GetAccountPicture::HideImageAndVideoControls() -{ - SmallImage->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - LargeImage->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - MediaPlayer->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} diff --git a/Samples/AccountPictureName/cpp/GetAccountPicture.xaml.h b/Samples/AccountPictureName/cpp/GetAccountPicture.xaml.h deleted file mode 100644 index 0d6ad31b..00000000 --- a/Samples/AccountPictureName/cpp/GetAccountPicture.xaml.h +++ /dev/null @@ -1,31 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -#pragma once - -#include "GetAccountPicture.g.h" -#include "MainPage.xaml.h" - -namespace SDKTemplate -{ - [Windows::Foundation::Metadata::WebHostHidden] - public ref class GetAccountPicture sealed - { - public: - GetAccountPicture(); - private: - MainPage^ rootPage; - void GetSmallImageButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void GetLargeImageButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void GetVideoButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void HideImageAndVideoControls(); - }; -} diff --git a/Samples/AccountPictureName/cpp/GetUserDisplayName.xaml.cpp b/Samples/AccountPictureName/cpp/GetUserDisplayName.xaml.cpp deleted file mode 100644 index ecc0c71d..00000000 --- a/Samples/AccountPictureName/cpp/GetUserDisplayName.xaml.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -#include "pch.h" -#include "GetUserDisplayName.xaml.h" - -using namespace SDKTemplate; - -using namespace concurrency; -using namespace Platform; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::System::UserProfile; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Controls::Primitives; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::UI::Xaml::Navigation; - -GetUserDisplayName::GetUserDisplayName() : rootPage(SDKTemplate::MainPage::Current) -{ - InitializeComponent(); -} - -void GetUserDisplayName::GetDisplayNameButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - if (UserInformation::NameAccessAllowed) - { - create_task(UserInformation::GetDisplayNameAsync()).then([this](String^ displayName) - { - if (displayName != nullptr) - { - rootPage->NotifyUser("Display name = " + displayName, NotifyType::StatusMessage); - } - else - { - rootPage->NotifyUser("No display name was returned.", NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("Access to name disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } -} diff --git a/Samples/AccountPictureName/cpp/GetUserFirstAndLastName.xaml.cpp b/Samples/AccountPictureName/cpp/GetUserFirstAndLastName.xaml.cpp deleted file mode 100644 index d1fa5cda..00000000 --- a/Samples/AccountPictureName/cpp/GetUserFirstAndLastName.xaml.cpp +++ /dev/null @@ -1,77 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -#include "pch.h" -#include "GetUserFirstAndLastName.xaml.h" - -using namespace SDKTemplate; - -using namespace concurrency; -using namespace Platform; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::System::UserProfile; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Controls::Primitives; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::UI::Xaml::Navigation; - -GetUserFirstAndLastName::GetUserFirstAndLastName() : rootPage(MainPage::Current) -{ - InitializeComponent(); -} - -void GetUserFirstAndLastName::GetFirstNameButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - if (UserInformation::NameAccessAllowed) - { - create_task(UserInformation::GetFirstNameAsync()).then([this](String^ firstName) - { - if (firstName != nullptr) - { - rootPage->NotifyUser("First name = " + firstName, NotifyType::StatusMessage); - } - else - { - rootPage->NotifyUser("No first name was returned.", NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("Access to name disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } -} - -void GetUserFirstAndLastName::GetLastNameButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - if (UserInformation::NameAccessAllowed) - { - create_task(UserInformation::GetLastNameAsync()).then([this](String^ lastName) - { - if (lastName != nullptr) - { - rootPage->NotifyUser("Last name = " + lastName, NotifyType::StatusMessage); - } - else - { - rootPage->NotifyUser("No last name was returned.", NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("Access to name disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } -} diff --git a/Samples/AccountPictureName/cpp/GetUserFirstAndLastName.xaml.h b/Samples/AccountPictureName/cpp/GetUserFirstAndLastName.xaml.h deleted file mode 100644 index c337a2bb..00000000 --- a/Samples/AccountPictureName/cpp/GetUserFirstAndLastName.xaml.h +++ /dev/null @@ -1,29 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -#pragma once - -#include "GetUserFirstAndLastName.g.h" -#include "MainPage.xaml.h" - -namespace SDKTemplate -{ - [Windows::Foundation::Metadata::WebHostHidden] - public ref class GetUserFirstAndLastName sealed - { - public: - GetUserFirstAndLastName(); - private: - MainPage^ rootPage; - void GetFirstNameButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void GetLastNameButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - }; -} diff --git a/Samples/AccountPictureName/cpp/SampleConfiguration.cpp b/Samples/AccountPictureName/cpp/SampleConfiguration.cpp deleted file mode 100644 index a28a9369..00000000 --- a/Samples/AccountPictureName/cpp/SampleConfiguration.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -#include "pch.h" -#include "MainPage.xaml.h" -#include "SampleConfiguration.h" - -using namespace SDKTemplate; -using namespace Platform; -using namespace Windows::ApplicationModel; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Controls::Primitives; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::UI::Xaml::Interop; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::UI::Xaml::Navigation; - -Platform::Array^ MainPage::scenariosInner = ref new Platform::Array -{ - { "Get display name", "SDKTemplate.GetUserDisplayName" }, - { "Get first and last name", "SDKTemplate.GetUserFirstAndLastName" }, - { "Get account picture", "SDKTemplate.GetAccountPicture" }, - { "Set account picture and listen for changes", "SDKTemplate.SetAccountPicture" } -}; - -void App::OnActivated(IActivatedEventArgs^ args) -{ - // Check to see if the app was activated via a protocol - if (args->Kind == ActivationKind::Protocol) - { - auto protocolArgs = safe_cast(args); - if (protocolArgs->Uri->SchemeName->Equals("ms-accountpictureprovider")) - { - if (Window::Current->Content == nullptr) - { - auto rootFrame = ref new Frame(); - TypeName pageType = { "SDKTemplate.MainPage", TypeKind::Custom }; - rootFrame->Navigate(pageType); - Window::Current->Content = rootFrame; - Window::Current->Activate(); - } - - MainPage::Current->NavigateToScenario("SDKTemplate.SetAccountPicture"); - } - } -} diff --git a/Samples/AccountPictureName/cpp/SetAccountPicture.xaml.cpp b/Samples/AccountPictureName/cpp/SetAccountPicture.xaml.cpp deleted file mode 100644 index 4b565f9f..00000000 --- a/Samples/AccountPictureName/cpp/SetAccountPicture.xaml.cpp +++ /dev/null @@ -1,160 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -#include "pch.h" -#include "SetAccountPicture.xaml.h" - -using namespace SDKTemplate; - -using namespace concurrency; -using namespace Platform; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::Storage; -using namespace Windows::Storage::Streams; -using namespace Windows::Storage::Pickers; -using namespace Windows::System::UserProfile; -using namespace Windows::UI::Core; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Controls::Primitives; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::UI::Xaml::Media::Imaging; -using namespace Windows::UI::Xaml::Navigation; - -SetAccountPicture::SetAccountPicture() : rootPage(MainPage::Current) -{ - InitializeComponent(); -} - -void SetAccountPicture::OnNavigatedTo(NavigationEventArgs^ e) -{ - accountPictureChangedToken = UserInformation::AccountPictureChanged += ref new EventHandler(this, &SetAccountPicture::PictureChanged); -} - -void SetAccountPicture::OnNavigatedFrom(NavigationEventArgs^ e) -{ - UserInformation::AccountPictureChanged -= accountPictureChangedToken; -} - -void SetAccountPicture::SetImageButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - FileOpenPicker^ imagePicker = ref new FileOpenPicker(); - imagePicker->ViewMode = PickerViewMode::Thumbnail; - imagePicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary; - imagePicker->FileTypeFilter->Append(".jpg"); - imagePicker->FileTypeFilter->Append(".jpeg"); - imagePicker->FileTypeFilter->Append(".png"); - imagePicker->FileTypeFilter->Append(".bmp"); - - create_task(imagePicker->PickSingleFileAsync()).then( - [this](StorageFile^ imageFile) - { - if (imageFile != nullptr) - { - rootPage->NotifyUser("Setting " + imageFile->Name + " as account picture ...", - NotifyType::StatusMessage); - create_task(UserInformation::SetAccountPictureAsync(imageFile)).then( - [this](SetAccountPictureResult setPictureResult) - { - if (setPictureResult == SetAccountPictureResult::Success) - { - rootPage->NotifyUser("Successfully updated account picture.", NotifyType::StatusMessage); - } - else - { - rootPage->NotifyUser("Setting account picture failed.", NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("No image was selected.", NotifyType::StatusMessage); - } - }); -} - -void SetAccountPicture::SetVideoButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - FileOpenPicker^ videoPicker = ref new FileOpenPicker(); - videoPicker->ViewMode = PickerViewMode::Thumbnail; - videoPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary; - videoPicker->FileTypeFilter->Append(".mp4"); - videoPicker->FileTypeFilter->Append(".wmv"); - videoPicker->FileTypeFilter->Append(".mpeg"); - videoPicker->FileTypeFilter->Append(".mov"); - - create_task(videoPicker->PickSingleFileAsync()).then( - [this](StorageFile^ videoFile) - { - if (videoFile != nullptr) - { - rootPage->NotifyUser("Setting " + videoFile->Name + " as account picture ...", - NotifyType::StatusMessage); - create_task(UserInformation::SetAccountPictureAsync(videoFile)).then( - [this](SetAccountPictureResult setPictureResult) - { - if (setPictureResult == SetAccountPictureResult::Success) - { - rootPage->NotifyUser("Successfully updated account picture.", NotifyType::StatusMessage); - } - else - { - rootPage->NotifyUser("Setting account picture failed.", NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("No video was selected.", NotifyType::StatusMessage); - } - }); -} - -void SetAccountPicture::PictureChanged(Platform::Object^ sender, Platform::Object^ e) -{ - Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() - { - if (UserInformation::NameAccessAllowed) - { - auto largeImageFile = UserInformation::GetAccountPicture(AccountPictureKind::LargeImage); - if (largeImageFile != nullptr) - { - create_task(largeImageFile->OpenReadAsync()).then( - [this](task imageStreamTask) - { - try - { - auto imageStream = imageStreamTask.get(); - auto bitmapImage = ref new BitmapImage(); - bitmapImage->SetSource(imageStream); - AccountPictureImage->Source = bitmapImage; - AccountPictureImage->Visibility = Windows::UI::Xaml::Visibility::Visible; - } - catch (Exception^ ex) - { - rootPage->NotifyUser("Failed to read from stream. " + ex->Message, NotifyType::ErrorMessage); - } - }); - } - else - { - rootPage->NotifyUser("No large account picture image returned for current user.", NotifyType::ErrorMessage); - } - } - else - { - rootPage->NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType::ErrorMessage); - } - })); -} diff --git a/Samples/AccountPictureName/cs/AccountPictureName.sln b/Samples/AccountPictureName/cs/AccountPictureName.sln deleted file mode 100644 index 8924a937..00000000 --- a/Samples/AccountPictureName/cs/AccountPictureName.sln +++ /dev/null @@ -1,43 +0,0 @@ - - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.22609.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountPictureName", "AccountPictureName.csproj", "{CF1CD0D5-BF6B-457A-9927-8079FC667CA4}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|ARM = Debug|ARM - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|ARM = Release|ARM - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|ARM.ActiveCfg = Debug|ARM - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|ARM.Build.0 = Debug|ARM - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|ARM.Deploy.0 = Debug|ARM - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|x64.ActiveCfg = Debug|x64 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|x64.Build.0 = Debug|x64 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|x64.Deploy.0 = Debug|x64 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|x86.ActiveCfg = Debug|x86 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|x86.Build.0 = Debug|x86 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Debug|x86.Deploy.0 = Debug|x86 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|ARM.ActiveCfg = Release|ARM - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|ARM.Build.0 = Release|ARM - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|ARM.Deploy.0 = Release|ARM - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|x64.ActiveCfg = Release|x64 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|x64.Build.0 = Release|x64 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|x64.Deploy.0 = Release|x64 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|x86.ActiveCfg = Release|x86 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|x86.Build.0 = Release|x86 - {CF1CD0D5-BF6B-457A-9927-8079FC667CA4}.Release|x86.Deploy.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal - - diff --git a/Samples/AccountPictureName/cs/GetAccountPicture.xaml.cs b/Samples/AccountPictureName/cs/GetAccountPicture.xaml.cs deleted file mode 100644 index 53a4af87..00000000 --- a/Samples/AccountPictureName/cs/GetAccountPicture.xaml.cs +++ /dev/null @@ -1,151 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Navigation; -using System; -using Windows.Storage; -using Windows.Storage.Streams; -using Windows.UI.Xaml.Media.Imaging; -using Windows.System.UserProfile; - -namespace SDKTemplate -{ - public sealed partial class GetAccountPicture : Page - { - private MainPage rootPage; - - public GetAccountPicture() - { - this.InitializeComponent(); - } - - protected override void OnNavigatedTo(NavigationEventArgs e) - { - rootPage = MainPage.Current; - } - - private async void GetSmallImageButton_Click(object sender, RoutedEventArgs e) - { - HideImageAndVideoControls(); - - if (UserInformation.NameAccessAllowed) - { - // The small picture returned by GetAccountPicture() is 96x96 pixels in size. - StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile; - if (image != null) - { - rootPage.NotifyUser("Path = " + image.Path, NotifyType.StatusMessage); - - try - { - IRandomAccessStream imageStream = await image.OpenReadAsync(); - BitmapImage bitmapImage = new BitmapImage(); - bitmapImage.SetSource(imageStream); - SmallImage.Source = bitmapImage; - SmallImage.Visibility = Visibility.Visible; - } - catch (Exception ex) - { - rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage); - } - } - else - { - rootPage.NotifyUser("Small account picture is not available.", NotifyType.StatusMessage); - } - } - else - { - rootPage.NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType.ErrorMessage); - } - } - - private async void GetLargeImageButton_Click(object sender, RoutedEventArgs e) - { - HideImageAndVideoControls(); - - if (UserInformation.NameAccessAllowed) - { - // The large picture returned by GetAccountPicture() is 448x448 pixels in size. - StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.LargeImage) as StorageFile; - if (image != null) - { - rootPage.NotifyUser("Path = " + image.Path, NotifyType.StatusMessage); - - try - { - IRandomAccessStream imageStream = await image.OpenReadAsync(); - BitmapImage bitmapImage = new BitmapImage(); - bitmapImage.SetSource(imageStream); - LargeImage.Source = bitmapImage; - LargeImage.Visibility = Visibility.Visible; - } - catch (Exception ex) - { - rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage); - } - } - else - { - rootPage.NotifyUser("Large account picture is not available.", NotifyType.StatusMessage); - } - } - else - { - rootPage.NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType.ErrorMessage); - } - } - - private async void GetVideoButton_Click(object sender, RoutedEventArgs e) - { - HideImageAndVideoControls(); - - if (UserInformation.NameAccessAllowed) - { - // The video returned from getAccountPicture is 448x448 pixels in size. - StorageFile video = UserInformation.GetAccountPicture(AccountPictureKind.Video) as StorageFile; - if (video != null) - { - rootPage.NotifyUser("Path: " + video.Path, NotifyType.StatusMessage); - - try - { - IRandomAccessStream videoStream = await video.OpenAsync(FileAccessMode.Read); - MediaPlayer.SetSource(videoStream, "video/mp4"); - MediaPlayer.Visibility = Visibility.Visible; - } - catch (Exception ex) - { - rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage); - } - } - else - { - rootPage.NotifyUser("Video is not available.", NotifyType.StatusMessage); - } - } - else - { - rootPage.NotifyUser("Access to account picture disabled by Privacy Setting or Group Policy.", NotifyType.ErrorMessage); - } - } - - private void HideImageAndVideoControls() - { - SmallImage.Visibility = Visibility.Collapsed; - LargeImage.Visibility = Visibility.Collapsed; - MediaPlayer.Visibility = Visibility.Collapsed; - } - - } -} diff --git a/Samples/AccountPictureName/cs/GetUserDisplayName.xaml.cs b/Samples/AccountPictureName/cs/GetUserDisplayName.xaml.cs deleted file mode 100644 index 9288f48a..00000000 --- a/Samples/AccountPictureName/cs/GetUserDisplayName.xaml.cs +++ /dev/null @@ -1,54 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Navigation; -using System; -using Windows.System.UserProfile; - -namespace SDKTemplate -{ - public sealed partial class GetUserDisplayName : Page - { - private MainPage rootPage; - - public GetUserDisplayName() - { - this.InitializeComponent(); - } - - protected override void OnNavigatedTo(NavigationEventArgs e) - { - rootPage = MainPage.Current; - } - - private async void GetDisplayNameButton_Click(object sender, RoutedEventArgs e) - { - if (UserInformation.NameAccessAllowed) - { - string displayName = await UserInformation.GetDisplayNameAsync(); - if (string.IsNullOrEmpty(displayName)) - { - rootPage.NotifyUser("No display name was returned.", NotifyType.StatusMessage); - } - else - { - rootPage.NotifyUser("Display name = " + displayName, NotifyType.StatusMessage); - } - } - else - { - rootPage.NotifyUser("Access to name disabled by Privacy Setting or Group Policy.", NotifyType.ErrorMessage); - } - } - } -} diff --git a/Samples/AccountPictureName/cs/GetUserFirstAndLastName.xaml.cs b/Samples/AccountPictureName/cs/GetUserFirstAndLastName.xaml.cs deleted file mode 100644 index ba1643b7..00000000 --- a/Samples/AccountPictureName/cs/GetUserFirstAndLastName.xaml.cs +++ /dev/null @@ -1,74 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Navigation; -using System; -using Windows.System.UserProfile; - -namespace SDKTemplate -{ - public sealed partial class GetUserFirstAndLastName : Page - { - private MainPage rootPage; - - public GetUserFirstAndLastName() - { - this.InitializeComponent(); - } - - protected override void OnNavigatedTo(NavigationEventArgs e) - { - rootPage = MainPage.Current; - } - - private async void GetFirstNameButton_Click(object sender, RoutedEventArgs e) - { - if (UserInformation.NameAccessAllowed) - { - string firstName = await UserInformation.GetFirstNameAsync(); - if (string.IsNullOrEmpty(firstName)) - { - rootPage.NotifyUser("No first name was returned.", NotifyType.StatusMessage); - } - else - { - rootPage.NotifyUser("First name = " + firstName, NotifyType.StatusMessage); - } - } - else - { - rootPage.NotifyUser("Access to name disabled by Privacy Setting or Group Policy.", NotifyType.ErrorMessage); - } - } - - private async void GetLastNameButton_Click(object sender, RoutedEventArgs e) - { - if (UserInformation.NameAccessAllowed) - { - string lastName = await UserInformation.GetLastNameAsync(); - if (string.IsNullOrEmpty(lastName)) - { - rootPage.NotifyUser("No last name was returned.", NotifyType.StatusMessage); - } - else - { - rootPage.NotifyUser("Last name = " + lastName, NotifyType.StatusMessage); - } - } - else - { - rootPage.NotifyUser("Access to name disabled by Privacy Setting or Group Policy.", NotifyType.ErrorMessage); - } - } - } -} diff --git a/Samples/AccountPictureName/cs/SampleConfiguration.cs b/Samples/AccountPictureName/cs/SampleConfiguration.cs deleted file mode 100644 index acbb82e6..00000000 --- a/Samples/AccountPictureName/cs/SampleConfiguration.cs +++ /dev/null @@ -1,82 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -using System; -using System.Collections.Generic; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Activation; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Navigation; - -namespace SDKTemplate -{ - public partial class MainPage : Page - { - public const string FEATURE_NAME = "Account picture name C# sample"; - - List scenarios = new List - { - new Scenario() { Title = "Get display name", ClassType = typeof(GetUserDisplayName) }, - new Scenario() { Title = "Get first and last name", ClassType = typeof(GetUserFirstAndLastName) }, - new Scenario() { Title = "Get account picture", ClassType = typeof(GetAccountPicture) }, - new Scenario() { Title = "Set account picture and listen for changes", ClassType = typeof(SetAccountPicture) } - }; - - public void NavigateToScenario(Type type) - { - for (int index = 0; index < scenarios.Count; index++) - { - if (scenarios[index].ClassType == type) - { - ScenarioControl.SelectedIndex = index; - break; - } - } - } - } - - public class Scenario - { - public string Title { get; set; } - public Type ClassType { get; set; } - } - - /// - /// Provides sample-specific behavior to supplement the default Application class. - /// - sealed partial class App : Application - { - protected override void OnActivated(IActivatedEventArgs args) - { - // Check to see if the app was activated via a protocol - if (args.Kind == ActivationKind.Protocol) - { - var protocolArgs = (ProtocolActivatedEventArgs)args; - - // This app was activated via the Account picture apps section in PC Settings / Personalize / Account picture. - // Here you would do app-specific logic so that the user receives account picture selection UX. - if (protocolArgs.Uri.Scheme == "ms-accountpictureprovider") - { - // The Content might be null if App has not yet been activated, if so first activate the main page. - if (Window.Current.Content == null) - { - Frame rootFrame = new Frame(); - rootFrame.Navigate(typeof(MainPage)); - Window.Current.Content = rootFrame; - Window.Current.Activate(); - } - MainPage.Current.NavigateToScenario(typeof(SDKTemplate.SetAccountPicture)); - } - } - } - } -} diff --git a/Samples/AccountPictureName/cs/SetAccountPicture.xaml.cs b/Samples/AccountPictureName/cs/SetAccountPicture.xaml.cs deleted file mode 100644 index a6cfa5be..00000000 --- a/Samples/AccountPictureName/cs/SetAccountPicture.xaml.cs +++ /dev/null @@ -1,158 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// This code is licensed under the MIT License (MIT). -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Navigation; -using System; - -using System.Linq; -using System.Collections.Generic; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.Graphics.Display; -using Windows.UI.ViewManagement; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Core; -using Windows.Storage.Pickers; -using Windows.Storage; -using Windows.Storage.Streams; -using Windows.UI.Xaml.Media.Imaging; -using Windows.System.UserProfile; - - -namespace SDKTemplate -{ - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - public sealed partial class SetAccountPicture : Page - { - MainPage rootPage = MainPage.Current; - - public SetAccountPicture() - { - this.InitializeComponent(); - } - - protected override void OnNavigatedTo(NavigationEventArgs e) - { - rootPage = MainPage.Current; - - //Listen to AccountPictureChanged event - UserInformation.AccountPictureChanged += this.PictureChanged; - } - - protected override void OnNavigatedFrom(NavigationEventArgs e) - { - //Remove listener to AccountPictureChanged event - UserInformation.AccountPictureChanged -= this.PictureChanged; - } - - private async void SetImageButton_Click(object sender, RoutedEventArgs e) - { - - FileOpenPicker imagePicker = new FileOpenPicker - { - ViewMode = PickerViewMode.Thumbnail, - SuggestedStartLocation = PickerLocationId.PicturesLibrary, - FileTypeFilter = { ".jpg", ".jpeg", ".png", ".bmp" } - }; - - StorageFile imageFile = await imagePicker.PickSingleFileAsync(); - if (imageFile != null) - { - // SetAccountPictureAsync() accepts 3 storageFile objects for setting the small image, large image, and video. - // More than one type can be set in the same call, but a small image must be accompanied by a large image and/or video. - // If only a large image is passed, the small image will be autogenerated. - // If only a video is passed, the large image and small will be autogenerated. - // Videos must be convertable to mp4, <=5MB, and height and width >= 448 pixels. - - // Setting the Account Picture will fail if user disallows it in PC Settings. - SetAccountPictureResult result = await UserInformation.SetAccountPicturesAsync(null, imageFile, null); - if (result == SetAccountPictureResult.Success) - { - rootPage.NotifyUser("Account picture was successfully changed.", NotifyType.StatusMessage); - } - else - { - rootPage.NotifyUser("Account picture could not be changed.", NotifyType.StatusMessage); - AccountPictureImage.Visibility = Visibility.Collapsed; - } - } - } - - private async void SetVideoButton_Click(object sender, RoutedEventArgs e) - { - FileOpenPicker videoPicker = new FileOpenPicker - { - ViewMode = PickerViewMode.Thumbnail, - SuggestedStartLocation = PickerLocationId.VideosLibrary, - FileTypeFilter = { ".mp4", ".mpeg", ".wmv", ".mov" } - }; - - StorageFile videoFile = await videoPicker.PickSingleFileAsync(); - if (videoFile != null) - { - // SetAccountPictureAsync() accepts 3 storageFile objects for setting the small image, large image, and video. - // More than one type can be set in the same call, but small image must be accompanied by a large image and/or video. - // If only a large image is passed, the small image will be autogenerated. - // If only a video is passed, the large image and small will be autogenerated. - // Videos must be convertable to mp4, <=5MB, and height and width >= 448 pixels. - - // Setting the Account Picture will fail if a user disallows it in PC Settings. - SetAccountPictureResult result = await UserInformation.SetAccountPicturesAsync(null, null, videoFile); - if (result == SetAccountPictureResult.Success) - { - rootPage.NotifyUser("Video account picture was successfully changed.", NotifyType.StatusMessage); - } - else - { - rootPage.NotifyUser("Account picture could not be changed.", NotifyType.StatusMessage); - AccountPictureImage.Visibility = Visibility.Collapsed; - } - } - } - - private async void PictureChanged(object sender, object e) - { - await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => - { - // The large picture returned by GetAccountPicture() is 448x448 pixels in size. - StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.LargeImage) as StorageFile; - if (image != null) - { - try - { - IRandomAccessStream imageStream = await image.OpenReadAsync(); - BitmapImage bitmapImage = new BitmapImage(); - bitmapImage.SetSource(imageStream); - rootPage.NotifyUser("LargeImage path = " + image.Path, NotifyType.StatusMessage); - AccountPictureImage.Source = bitmapImage; - AccountPictureImage.Visibility = Visibility.Visible; - } - catch (Exception ex) - { - rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage); - } - } - else - { - rootPage.NotifyUser("Large Account Picture is not available.", NotifyType.StatusMessage); - } - }); - } - - } -} diff --git a/Samples/AccountPictureName/js/html/getAccountPicture.html b/Samples/AccountPictureName/js/html/getAccountPicture.html deleted file mode 100644 index 269a568d..00000000 --- a/Samples/AccountPictureName/js/html/getAccountPicture.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - -
-
-

Description:

-
-

Get the Account Picture for the current user. You can get request three different types: small, large, and video. If the size that is requested is not available an empty file is returned.

-
-
-
- - - -
- image holder - image holder - -
-
-
- - - \ No newline at end of file diff --git a/Samples/AccountPictureName/js/html/setAccountPicture.html b/Samples/AccountPictureName/js/html/setAccountPicture.html deleted file mode 100644 index dbceeee0..00000000 --- a/Samples/AccountPictureName/js/html/setAccountPicture.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - -
-
-

Description:

-
-

Set the Account Picture image for the current logon user. The setAccountPicture method takes three parameters as input: small image, large image, and video. More than one type can be set in the same call, but a small image must be accompanied - by a large image and/or video. Pass a null for parameters you don't want to set. A change event can be listened to for Account Picture updates. The images below change by listening to the update.

-
-
-
- - - image holder - image holder - -
-
- - - \ No newline at end of file diff --git a/Samples/AccountPictureName/js/html/userFirstAndLastName.html b/Samples/AccountPictureName/js/html/userFirstAndLastName.html deleted file mode 100644 index dff86647..00000000 --- a/Samples/AccountPictureName/js/html/userFirstAndLastName.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - -
-
-

Description:

-
-

Get the First and Last Name for the current user. This is only available for Microsoft Accounts, an empty string will be returned if not available.

-
-
- - -
- - - \ No newline at end of file diff --git a/Samples/AccountPictureName/js/js/getAccountPicture.js b/Samples/AccountPictureName/js/js/getAccountPicture.js deleted file mode 100644 index 3f09d36e..00000000 --- a/Samples/AccountPictureName/js/js/getAccountPicture.js +++ /dev/null @@ -1,71 +0,0 @@ -//// Copyright (c) Microsoft Corporation. All rights reserved - -(function () { - "use strict"; - var page = WinJS.UI.Pages.define("/html/getAccountPicture.html", { - ready: function (element, options) { - hideVisibleHolders(); - document.getElementById("getSmallImage").addEventListener("click", getSmallImage, false); - document.getElementById("getLargeImage").addEventListener("click", getLargeImage, false); - document.getElementById("getVideo").addEventListener("click", getVideo, false); - } - }); - - function getSmallImage() { - hideVisibleHolders(); - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - // The small picture returned by getAccountPicture() is 96x96 pixels in size. - var image = Windows.System.UserProfile.UserInformation.getAccountPicture(Windows.System.UserProfile.AccountPictureKind.smallImage); - if (image) { - document.getElementById("smallImageHolder").style.visibility = "visible"; - document.getElementById("smallImageHolder").src = URL.createObjectURL(image, { oneTimeOnly: true }); - WinJS.log && WinJS.log("Path: " + image.path, "sample", "status"); - } else { - WinJS.log && WinJS.log("Small account picture is not available.", "sample", "status"); - } - } else { - WinJS.log && WinJS.log("Access to account picture disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } - - function getLargeImage() { - hideVisibleHolders(); - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - // The large picture returned by getAccountPicture() is 448x448 pixels in size. - var image = Windows.System.UserProfile.UserInformation.getAccountPicture(Windows.System.UserProfile.AccountPictureKind.largeImage); - if (image) { - document.getElementById("largeImageHolder").style.visibility = "visible"; - document.getElementById("largeImageHolder").src = URL.createObjectURL(image, { oneTimeOnly: true }); - WinJS.log && WinJS.log("Path: " + image.path, "sample", "status"); - } else { - WinJS.log && WinJS.log("Large account picture is not available.", "sample", "status"); - } - } else { - WinJS.log && WinJS.log("Access to account picture disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } - - function getVideo() { - hideVisibleHolders(); - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - // The video returned from getAccountPicture is 448x448 pixels in size. - var video = Windows.System.UserProfile.UserInformation.getAccountPicture(Windows.System.UserProfile.AccountPictureKind.video); - if (video) { - document.getElementById("videoHolder").style.visibility = "visible"; - document.getElementById("videoHolder").src = URL.createObjectURL(video, { oneTimeOnly: true }); - document.getElementById("videoHolder").play(); - WinJS.log && WinJS.log("Path: " + video.path, "sample", "status"); - } else { - WinJS.log && WinJS.log("Video is not available.", "sample", "status"); - } - } else { - WinJS.log && WinJS.log("Access to account picture disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } - - function hideVisibleHolders() { - document.getElementById("smallImageHolder").style.visibility = "hidden"; - document.getElementById("largeImageHolder").style.visibility = "hidden"; - document.getElementById("videoHolder").style.visibility = "hidden"; - } -})(); diff --git a/Samples/AccountPictureName/js/js/sample-configuration.js b/Samples/AccountPictureName/js/js/sample-configuration.js deleted file mode 100644 index de7c2f00..00000000 --- a/Samples/AccountPictureName/js/js/sample-configuration.js +++ /dev/null @@ -1,32 +0,0 @@ -//// Copyright (c) Microsoft Corporation. All rights reserved - -(function () { - "use strict"; - - var sampleTitle = "Account picture name JS sample"; - - var scenarios = [ - { url: "/html/userDisplayName.html", title: "Get display name" }, - { url: "/html/userFirstAndLastName.html", title: "Get first and last name" }, - { url: "/html/getAccountPicture.html", title: "Get account picture" }, - { url: "/html/setAccountPicture.html", title: "Set account picture and listen for changes" } - ]; - - WinJS.Navigation.addEventListener("navigating", function (e) { - if (e.detail && e.detail.state && e.detail.state.activatedEventArgs) { - var uri = e.detail.state.activatedEventArgs[0].uri; - if (uri && uri.schemeName === "ms-accountpictureprovider") { - // This app was activated via the Account picture apps section in Settings. - // Here you would do app-specific logic for providing the user with account picture selection UX - setImmediate(function () { - WinJS.Navigation.navigate(scenarios[3].url).done(); - }); - } - } - }); - - WinJS.Namespace.define("SdkSample", { - sampleTitle: sampleTitle, - scenarios: new WinJS.Binding.List(scenarios) - }); -})(); diff --git a/Samples/AccountPictureName/js/js/setAccountPicture.js b/Samples/AccountPictureName/js/js/setAccountPicture.js deleted file mode 100644 index 12d0d68a..00000000 --- a/Samples/AccountPictureName/js/js/setAccountPicture.js +++ /dev/null @@ -1,102 +0,0 @@ -//// Copyright (c) Microsoft Corporation. All rights reserved - -(function () { - "use strict"; - var page = WinJS.UI.Pages.define("/html/setAccountPicture.html", { - ready: function (element, options) { - hideVisibleHolders(); - document.getElementById("setImage").addEventListener("click", setImage, false); - document.getElementById("setVideo").addEventListener("click", setVideo, false); - Windows.System.UserProfile.UserInformation.addEventListener("accountpicturechanged", accountPictureChanged); - } - }); - - function setImage() { - hideVisibleHolders(); - var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); - openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail; - openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary; - openPicker.fileTypeFilter.replaceAll([".bmp", ".png", ".jpg", ".jpeg"]); - - openPicker.pickSingleFileAsync().done(function (file) { - if (file) { - // setAccountPictureAsync() accepts 3 storageFile objects for setting the small image, large image, and video. - // More than one type can be set in the same call, but small image must be accompanied by a large image and/or video. - // If only a large image is passed, the small image will be autogenerated. - // If only a video is passed, the large image and small will be autogenerated. - // Videos must be convertable to mp4, <=5MB, and height and width >= 448 pixels. - Windows.System.UserProfile.UserInformation.setAccountPicturesAsync(null, file, null).done(function (result) { - // A user might turn off access to the Account Picture in PC Settings, therefore we need to check the result for success. - if (result === Windows.System.UserProfile.SetAccountPictureResult.success) { - WinJS.log && WinJS.log("Successfully updated account picture.", "sample", "status"); - } else { - // A user might turn off access to the account - WinJS.log && WinJS.log("Setting account picture failed.", "sample", "status"); - } - }); - } else { - WinJS.log && WinJS.log("No image was selected.", "sample", "status"); - } - }); - } - - function setVideo() { - hideVisibleHolders(); - var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); - openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail; - openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary; - openPicker.fileTypeFilter.replaceAll([".mov", ".mp4", ".wmv"]); - - openPicker.pickSingleFileAsync().done(function (file) { - if (file) { - // setAccountPictureAsync() accepts 3 storageFile objects for setting the small image, large image, and video. - // More than one type can be set in the same call, but small image must be accompanied by a large image and/or video. - // If only a large image is passed, the small image will be autogenerated. - // If only a video is passed, the large image and small will be autogenerated. - // Videos must be convertable to mp4, <=5MB, and height and width >= 448 pixels. - Windows.System.UserProfile.UserInformation.setAccountPicturesAsync(null, null, file).done(function (result) { - // A user might turn off access to the Account Picture in PC Settings, therefore we need to check the result for success. - if (result === Windows.System.UserProfile.SetAccountPictureResult.success) { - WinJS.log && WinJS.log("Successfully updated account picture.", "sample", "status"); - } else { - // A user might turn off access to the account - WinJS.log && WinJS.log("Setting account picture failed.", "sample", "status"); - } - }); - } else { - WinJS.log && WinJS.log("No video was selected.", "sample", "status"); - } - }); - } - - // This function is the handler for the AccountPictureChangedEvent, the event listener is added in initialize() below. - function accountPictureChanged() { - hideVisibleHolders(); - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - var smallImage = Windows.System.UserProfile.UserInformation.getAccountPicture(Windows.System.UserProfile.AccountPictureKind.smallImage); - if (smallImage) { - document.getElementById("smallImageHolder").src = URL.createObjectURL(smallImage, { oneTimeOnly: true }); - document.getElementById("smallImageHolder").style.visibility = "visible"; - } - var largeImage = Windows.System.UserProfile.UserInformation.getAccountPicture(Windows.System.UserProfile.AccountPictureKind.largeImage); - if (largeImage) { - document.getElementById("largeImageHolder").src = URL.createObjectURL(largeImage, { oneTimeOnly: true }); - document.getElementById("largeImageHolder").style.visibility = "visible"; - } - var video = Windows.System.UserProfile.UserInformation.getAccountPicture(Windows.System.UserProfile.AccountPictureKind.video); - if (video) { - document.getElementById("videoHolder").src = URL.createObjectURL(video, { oneTimeOnly: true }); - document.getElementById("videoHolder").style.visibility = "visible"; - } - } else { - WinJS.log && WinJS.log("Access to account picture disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } - - function hideVisibleHolders() { - document.getElementById("smallImageHolder").style.visibility = "hidden"; - document.getElementById("largeImageHolder").style.visibility = "hidden"; - document.getElementById("videoHolder").style.visibility = "hidden"; - WinJS.log && WinJS.log(" ", "sample", "status"); - } -})(); diff --git a/Samples/AccountPictureName/js/js/userDisplayName.js b/Samples/AccountPictureName/js/js/userDisplayName.js deleted file mode 100644 index 040dbdfd..00000000 --- a/Samples/AccountPictureName/js/js/userDisplayName.js +++ /dev/null @@ -1,24 +0,0 @@ -//// Copyright (c) Microsoft Corporation. All rights reserved - -(function () { - "use strict"; - var page = WinJS.UI.Pages.define("/html/userDisplayName.html", { - ready: function (element, options) { - document.getElementById("getDisplayName").addEventListener("click", getDisplayName, false); - } - }); - - function getDisplayName() { - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - Windows.System.UserProfile.UserInformation.getDisplayNameAsync().done(function (result) { - if (result) { - WinJS.log && WinJS.log("Display name = " + result, "sample", "status"); - } else { - WinJS.log && WinJS.log("No display name was returned.", "sample", "status"); - } - }); - } else { - WinJS.log && WinJS.log("Access to name disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } -})(); diff --git a/Samples/AccountPictureName/js/js/userFirstAndLastName.js b/Samples/AccountPictureName/js/js/userFirstAndLastName.js deleted file mode 100644 index b2e2e66d..00000000 --- a/Samples/AccountPictureName/js/js/userFirstAndLastName.js +++ /dev/null @@ -1,39 +0,0 @@ -//// Copyright (c) Microsoft Corporation. All rights reserved - -(function () { - "use strict"; - var page = WinJS.UI.Pages.define("/html/userFirstAndLastName.html", { - ready: function (element, options) { - document.getElementById("getFirstName").addEventListener("click", getFirstName, false); - document.getElementById("getLastName").addEventListener("click", getLastName, false); - } - }); - - function getFirstName() { - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - Windows.System.UserProfile.UserInformation.getFirstNameAsync().done(function (result) { - if (result) { - WinJS.log && WinJS.log("First name = " + result, "sample", "status"); - } else { - WinJS.log && WinJS.log("No first name was returned.", "sample", "status"); - } - }); - } else { - WinJS.log && WinJS.log("Access to name disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } - - function getLastName() { - if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) { - Windows.System.UserProfile.UserInformation.getLastNameAsync().done(function (result) { - if (result) { - WinJS.log && WinJS.log("Last name = " + result, "sample", "status"); - } else { - WinJS.log && WinJS.log("No last name was returned.", "sample", "status"); - } - }); - } else { - WinJS.log && WinJS.log("Access to name disabled by Privacy Setting or Group Policy.", "sample", "error"); - } - } -})(); diff --git a/Samples/AccountPictureName/shared/GetAccountPicture.xaml b/Samples/AccountPictureName/shared/GetAccountPicture.xaml deleted file mode 100644 index 96bd210c..00000000 --- a/Samples/AccountPictureName/shared/GetAccountPicture.xaml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - Get the Account Picture for the current user. - - - - - - - You can request three different types: small, large and video (dynamic image). If the type that is requested is not available, an empty file is returned. - - - + +
+
+ +
+ + + + + \ No newline at end of file diff --git a/Samples/AccountPictureName/js/html/userDisplayName.html b/Samples/UserInfo/js/html/scenario2-watchUsers.html similarity index 51% rename from Samples/AccountPictureName/js/html/userDisplayName.html rename to Samples/UserInfo/js/html/scenario2-watchUsers.html index b04d02ff..50587545 100644 --- a/Samples/AccountPictureName/js/html/userDisplayName.html +++ b/Samples/UserInfo/js/html/scenario2-watchUsers.html @@ -7,7 +7,7 @@ Copyright (c) Microsoft Corporation. All rights reserved - + @@ -15,13 +15,15 @@ Copyright (c) Microsoft Corporation. All rights reserved

Description:

-

Get the DisplayName for the current user.

+ Maintain a list of users with a UserWatcher
- +
+ + +
+
diff --git a/Samples/AccountPictureName/js/images/placeholder.txt b/Samples/UserInfo/js/images/placeholder.txt similarity index 100% rename from Samples/AccountPictureName/js/images/placeholder.txt rename to Samples/UserInfo/js/images/placeholder.txt diff --git a/Samples/UserInfo/js/js/sample-configuration.js b/Samples/UserInfo/js/js/sample-configuration.js new file mode 100644 index 00000000..02578298 --- /dev/null +++ b/Samples/UserInfo/js/js/sample-configuration.js @@ -0,0 +1,17 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var sampleTitle = "Account picture name JS sample"; + + var scenarios = [ + { url: "/html/scenario1-findUsers.html", title: "Find users" }, + { url: "/html/scenario2-watchUsers.html", title: "Watch users" }, + ]; + + WinJS.Namespace.define("SdkSample", { + sampleTitle: sampleTitle, + scenarios: new WinJS.Binding.List(scenarios) + }); +})(); diff --git a/Samples/UserInfo/js/js/scenario1-findUsers.js b/Samples/UserInfo/js/js/scenario1-findUsers.js new file mode 100644 index 00000000..7b3e000c --- /dev/null +++ b/Samples/UserInfo/js/js/scenario1-findUsers.js @@ -0,0 +1,131 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var System = Windows.System; + var User = System.User; + var KnownUserProperties = System.KnownUserProperties; + var UserPictureSize = System.UserPictureSize; + + var userTypeNames = [ "LocalUser", "RemoteUser", "LocalGuest", "RemoteGuest" ]; + var authenticationStatusNames = [ "Unauthenticated", "LocallyAuthenticated", "RemotelyAuthenticated" ]; + + var nextUserNumber = 1; + var userList; + var resultsText; + var profileImage; + + var page = WinJS.UI.Pages.define("/html/scenario1-findUsers.html", { + ready: function (element, options) { + userList = document.getElementById("userList"); + resultsText = document.getElementById("resultsText"); + profileImage = document.getElementById("profileImage"); + + document.getElementById("showPropertiesButton").addEventListener("click", showProperties, false); + + return fillUsersAsync(); + } + }); + + function fillUsersAsync() { + nextUserNumber = 1; + User.findAllAsync().then(function (users) { + return addNextUserAsync(0); + + function addNextUserAsync(i) { + if (i < users.length) { + var user = users[i]; + return user.getPropertyAsync(KnownUserProperties.displayName).then(function (displayName) { + // Choose a generic name if we do not have access to the actual name. + if (displayName == "") { + displayName = "User #" + nextUserNumber; + ++nextUserNumber; + } + + var newOption = document.createElement("option"); + newOption.text = displayName; + newOption.value = user.nonRoamableId; + newOption.selected = false; + userList.add(newOption); + + return addNextUser(i + 1); + }); + } + } + }); + } + + function showProperties() { + if (userList.selectedIndex >= 0) { + resultsText.innerText = ""; + profileImage.src = ""; + WinJS.log && WinJS.log("", "sample", "status"); + + var userId = userList[userList.selectedIndex].value; + try { + var user = User.getFromId(userId); + } catch (ex) { + WinJS.log && WinJS.log(ex.message, "sample", "error"); + return; + } + + // Build a list of all the properties we want. + var desiredProperties = [ + KnownUserProperties.firstName, + KnownUserProperties.lastName, + KnownUserProperties.providerName, + KnownUserProperties.accountName, + KnownUserProperties.guestHost, + KnownUserProperties.principalName, + KnownUserProperties.domainName, + KnownUserProperties.sessionInitiationProtocolUri + ]; + + // Issue a bulk query for all of the properties above. + // NOTE: Bulk queries do not work from JS right now. + // user.getPropertiesAsync(desiredProperties).then(function (values) { + simulateGetPropertiesAsync(user, desiredProperties).then(function (values) { + // Generate the results. + var result = "NonRoamableId: " + user.nonRoamableId + "\n"; + result += "Type: " + userTypeNames[user.type] + "\n"; + result += "AuthenticationStatus: " + authenticationStatusNames[user.authenticationStatus] + "\n"; + desiredProperties.forEach(function (propertyName) { + result += propertyName + ": "+ values[propertyName] + "\n"; + }); + + resultsText.innerText = result; + }).then(function () { + return user.getPictureAsync(UserPictureSize.size64x64); + }).then(function (streamReference) { + return streamReference && streamReference.openReadAsync(); + }).then(function (stream) { + if (stream) { + profileImage.src = URL.createObjectURL(stream, { oneTimeOnly: true }); + // Close the stream once the image is loaded. + profileImage.onload = function () { stream.close(); }; + } + }); + } + } + + // Bulk queries do not work from JS right now, so we simulate it by + // issuing a series of single-property queries. + function simulateGetPropertiesAsync(user, desiredProperties) { + var values = {}; + return addNextPropertyAsync(0); + + function addNextPropertyAsync(i) { + if (i < desiredProperties.length) { + var propertyName = desiredProperties[i]; + return user.getPropertyAsync(propertyName).then(function (result) { + values[propertyName] = result; + return addNextPropertyAsync(i + 1); + }); + } else { + return values; + } + } + } + +})(); diff --git a/Samples/UserInfo/js/js/scenario2-watchUsers.js b/Samples/UserInfo/js/js/scenario2-watchUsers.js new file mode 100644 index 00000000..0e01e27d --- /dev/null +++ b/Samples/UserInfo/js/js/scenario2-watchUsers.js @@ -0,0 +1,136 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var System = Windows.System; + var User = System.User; + var KnownUserProperties = System.KnownUserProperties; + + var startButton; + var stopButton; + var userList; + + var nextUserNumber = 1; + var userWatcher; + + var page = WinJS.UI.Pages.define("/html/scenario2-watchUsers.html", { + ready: function (element, options) { + startButton = document.getElementById("startButton"); + stopButton = document.getElementById("stopButton"); + userList = document.getElementById("userList"); + + startButton.addEventListener("click", startWatching, false); + stopButton.addEventListener("click", stopWatching, false); + }, + unload: stopWatching + }); + + function startWatching() { + WinJS.log && WinJS.log("", "sample", "status"); + + nextUserNumber = 1; + userList.innerHTML = ""; // remove all children + + userWatcher = User.createWatcher(); + userWatcher.addEventListener("added", onUserAdded); + userWatcher.addEventListener("updated", onUserUpdated); + userWatcher.addEventListener("removed", onUserRemoved); + userWatcher.addEventListener("enumerationcompleted", onEnumerationCompleted); + userWatcher.addEventListener("stopped", onWatcherStopped); + userWatcher.start(); + startButton.disabled = true; + stopButton.disabled = false; + } + + function stopWatching() { + if (userWatcher) { + userWatcher.removeEventListener("added", onUserAdded); + userWatcher.removeEventListener("updated", onUserUpdated); + userWatcher.removeEventListener("removed", onUserRemoved); + userWatcher.removeEventListener("enumerationCompleted", onEnumerationCompleted); + userWatcher.removeEventListener("stopped", onWatcherStopped); + userWatcher.stop(); + userWatcher = null; + userList.innerHTML = ""; // remove all children + startButton.disabled = false; + stopButton.disabled = true; + } + } + + function findOptionByUserId(userId) { + // make it safe to put inside "..." + var sanitized = userId.replace("\\", "\\\\").replace("'", "\\'"); + return userList.querySelector("option[value='" + sanitized + "']"); + } + + function getDisplayNameOrGenericNameAsync(user) { + return user.getPropertyAsync(KnownUserProperties.displayName).then(function (displayName) { + // Choose a generic name if we do not have access to the actual name. + if (displayName == "") { + displayName = "User #" + nextUserNumber; + ++nextUserNumber; + } + return displayName; + }); + } + + function onUserAdded(e) { + var user = e.user; + + // Create the user with "..." as the temporary display name. + // Add it right away, because it might get removed while the + // getDisplayNameOrGenericNameAsync is running. + + var newOption = document.createElement("option"); + newOption.text = "\u2026"; + newOption.value = user.nonRoamableId; + newOption.selected = false; + userList.add(newOption); + + // Uncomment this line, and the behavior in the TODO changes! + // Instead of setting only the first character, it sets only the first word. + //newOption.text = "Bogga"; + + // Try to get the display name. + getDisplayNameOrGenericNameAsync(user).then(function (displayName) { + // TODO: Figure out why only the first character gets set. + newOption.text = displayName; + }); + } + + function onUserUpdated(e) { + var user = e.user; + + // Look for the user in our collection and update the display name. + var option = findOptionByUserId(user.nonRoamableId); + + // Try to update the display name. + getDisplayNameOrGenericNameAsync(user).then(function (displayName) { + // TODO: Figure out why only the first character gets set. + option.text = displayName; + }); + } + + function onUserRemoved(e) { + var user = e.user; + + // Look for the user in our collection and remove it. + var option = findOptionByUserId(user.nonRoamableId); + + if (option) { + userList.remove(option); + } + } + + function onEnumerationCompleted() + { + WinJS.log && WinJS.log("Enumeration complete. Watching for changes...", "sample", "status"); + } + + function onWatcherStopped() + { + stopWatching(); + } + +})(); diff --git a/Samples/AccountPictureName/js/sample-utils/placeholder.txt b/Samples/UserInfo/js/sample-utils/placeholder.txt similarity index 100% rename from Samples/AccountPictureName/js/sample-utils/placeholder.txt rename to Samples/UserInfo/js/sample-utils/placeholder.txt diff --git a/Samples/AccountPictureName/shared/GetUserFirstAndLastName.xaml b/Samples/UserInfo/shared/Scenario1_FindUsers.xaml similarity index 61% rename from Samples/AccountPictureName/shared/GetUserFirstAndLastName.xaml rename to Samples/UserInfo/shared/Scenario1_FindUsers.xaml index 37cc636f..4a76dacf 100644 --- a/Samples/AccountPictureName/shared/GetUserFirstAndLastName.xaml +++ b/Samples/UserInfo/shared/Scenario1_FindUsers.xaml @@ -11,7 +11,7 @@ //********************************************************* --> - - + - Get the first and last name for the current user. This is only available for Microsoft Accounts. An empty string will be returned if not available. + Find users and display user properties + +