diff --git a/README.md b/README.md index 3da77f4f28..ca448d5ac4 100644 --- a/README.md +++ b/README.md @@ -141,56 +141,57 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github. + - + - + - + - + - + - + - + - + - + - + @@ -422,6 +423,7 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github. +
3D Printing from Unity AutoSuggestBox migration ClipboardCommanding
Commanding Context menu Context menu (XAML)Data virtualization
Data virtualization Disabling selection Display orientationDownloadable fonts (DirectWrite)
Downloadable fonts (DirectWrite) Downloadable fonts (XAML) Drag and dropFocus visuals
Focus visuals Full screen mode Line spacing (DirectWrite)ListView and GridView
ListView and GridView Lock screen apps Message dialogMultiple views
Multiple views OCR PrintingPull-to-refresh
Pull-to-refresh Responsiveness techniques Scaling according to DPISplash screen
Splash screen State triggers Tailored multiple viewsTitle bar
Title bar UI basics (XAML) User interaction modeWebView control (HTML)
WebView control (HTML) WebView control (XAML) Window resizing
Association launching Background taskExtended execution
diff --git a/Samples/3DPrintingFromUnity/Assets/Script/Print.cs b/Samples/3DPrintingFromUnity/Assets/Script/Print.cs new file mode 100644 index 0000000000..5afdbc1e2c --- /dev/null +++ b/Samples/3DPrintingFromUnity/Assets/Script/Print.cs @@ -0,0 +1,465 @@ +using UnityEngine; +using System.Collections; +using System; +using System.IO; +#if UNITY_WSA && !UNITY_EDITOR +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; +using System.Text; +using Windows.ApplicationModel.Core; +using Windows.Graphics.Printing3D; +using Windows.UI.Core; +using System.Numerics; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading.Tasks; +using Windows.Devices.Geolocation; +using Windows.Foundation; +using Windows.Storage; +using Windows.Storage.Streams; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Navigation; +#endif + +public class Print : MonoBehaviour +{ + private static string Step1 = "Get mesh/texture from Game Object"; + private static string Step2 = "Store into Printing3d API"; + private static string Step3 = "Launch printing dialog"; + private static string labelText = "Status for printing"; + + private static bool enableButton = true; + + private static UInt32[] indicesPrint; + private static double[] verticesPrint; + private static UInt32[] indicesMaterialPrint; + + private static UInt32 groupId; + private static double[] uvPrint; + + private static byte[] pngBytes; + + private static uint indicesCount; + private static uint verticesCount; + private static uint verticesMaterialCount; + + // Use this for adding GUI + void OnGUI() + { + GUI.Label(new UnityEngine.Rect(20, 60, 300, 40), labelText); + if (GUI.Button(new UnityEngine.Rect(20, 20, 70, 25), "3D Print")) + { + // ignore button click until launch print dialog + if (enableButton) + { + enableButton = false; + } + else + { + return; + } + + labelText = Step1; + // get texture bytes from Unity + var texture = transform.GetComponent().material.GetTexture("_MainTex") as Texture2D; + pngBytes = texture.EncodeToPNG(); + + // get mesh information from Unity + var mesh = transform.GetComponent().sharedMesh; + indicesCount = (uint)mesh.triangles.Length / 3; + verticesCount = (uint)mesh.vertices.Length; + verticesMaterialCount = (uint)mesh.triangles.Length / 3; + + indicesPrint = new UInt32[mesh.triangles.Length]; + verticesPrint = new double[mesh.vertices.Length * 3]; + indicesMaterialPrint = new UInt32[mesh.triangles.Length / 3 * 4]; + uvPrint = new double[mesh.uv.Length * 2]; + + groupId = 1; + + int j = 0; + + // get indices and indices for material + for (int i = 0; i < mesh.triangles.Length; i++) + { + indicesPrint[i] = (UInt32)mesh.triangles[i]; + + // vertex corresponding to uv + if (i % 3 == 0) + { + indicesMaterialPrint[j] = groupId; + j++; + } + + indicesMaterialPrint[j] = (UInt32)mesh.triangles[i]; + j++; + } + + // get vertices + for (int i = 0; i < mesh.vertices.Length; i++) + { + verticesPrint[i * 3] = (double)mesh.vertices[i].x; + verticesPrint[i * 3 + 1] = (double)mesh.vertices[i].y; + verticesPrint[i * 3 + 2] = (double)mesh.vertices[i].z; + } + + // get UVs + for (int i = 0; i < mesh.uv.Length; i++) + { + uvPrint[i * 2] = (double)mesh.uv[i].x; + uvPrint[i * 2 + 1] = (double)mesh.uv[i].y; + } + +#if UNITY_WSA && !UNITY_EDITOR + // start to pass the mesh/texture into Printing3D API + // launch the print dialog + UIThread(); +#endif + } + } + + // Use this for initialization + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + +#if UNITY_WSA && !UNITY_EDITOR + private static async void UIThread() + { + // convert to UI thread and then launch the printing dialog + // print dialog only works in UI thread + await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { + var print = new Print(); + print.LaunchPrintDialog(); + }); + } + + private Print3DTask printTask; + private Printing3D3MFPackage package; + + private async void LaunchPrintDialog() + { + labelText = Step2; + // use CreateData to create 3MFPackage from a string stream + await CreateData(); + + labelText = Step3; + // register the PrintTaskRequest callback to get the Printing3D3MFPackage + Print3DManager.GetForCurrentView().TaskRequested += MainPage_TaskRequested; + + // show the PrintUI + await Print3DManager.ShowPrintUIAsync(); + + // remove the print task request after dialog is shown + Print3DManager.GetForCurrentView().TaskRequested -= MainPage_TaskRequested; + + // set back + enableButton = true; + } + + private void MainPage_TaskRequested(Print3DManager sender, Print3DTaskRequestedEventArgs args) + { + Print3DTask printTaskRef = null; + + Print3DTaskSourceRequestedHandler sourceHandler = delegate (Print3DTaskSourceRequestedArgs sourceRequestedArgs) + { + sourceRequestedArgs.SetSource(package); + }; + printTaskRef = args.Request.CreateTask("Model", "Default", sourceHandler); + + this.printTask = printTaskRef; + + printTaskRef.Completed += Task_Completed; + printTaskRef.Submitting += Task_Submitting; + } + + private async Task CreateData() + { + package = new Printing3D3MFPackage(); + + var model = new Printing3DModel(); + + model.Unit = Printing3DModelUnit.Millimeter; + + var mesh = new Printing3DMesh(); + + // save vertices + await GetVerticesAsync(mesh); + + // save indices + await GetIndicesAsync(mesh); + + // save material indices + await GetMaterialIndicesAsync(mesh); + + // texture2Coord Group + var tex2CoordGroup = new Printing3DTexture2CoordMaterialGroup(groupId); + + // save texture coords + for (int i = 0; i < uvPrint.Length / 2; i++) + { + var tex2CoordMaterial = new Printing3DTexture2CoordMaterial(); + tex2CoordMaterial.U = uvPrint[i * 2]; + tex2CoordMaterial.V = uvPrint[i * 2 + 1]; + tex2CoordGroup.Texture2Coords.Add(tex2CoordMaterial); + } + + // to make sure we don't use the same byte array from Unity + var copyPngBytes = new byte[pngBytes.Length]; + pngBytes.CopyTo(copyPngBytes, 0); + + var randomAccessStream = new InMemoryRandomAccessStream(); + await randomAccessStream.WriteAsync(copyPngBytes.AsBuffer()); + randomAccessStream.Seek(0); + + var texture = new Printing3DModelTexture(); + Printing3DTextureResource texResource = new Printing3DTextureResource(); + texResource.Name = "/3D/Texture/skeleton.png"; + texResource.TextureData = new MyRandomAccessStream(randomAccessStream); + package.Textures.Add(texResource); + + // add metadata about the texture + model.Metadata.Add("tex" + groupId, "/3D/Texture/skeleton.png"); + model.Material.Texture2CoordGroups.Add(tex2CoordGroup); + + model.Meshes.Add(mesh); + + Printing3DComponent component = new Printing3DComponent(); + + component.Mesh = mesh; + + model.Components.Add(component); + + var componentWithMatrix = new Printing3DComponentWithMatrix(); + + componentWithMatrix.Component = component; + + componentWithMatrix.Matrix = System.Numerics.Matrix4x4.Identity; + + model.Build.Components.Add(componentWithMatrix); + + await package.SaveModelToPackageAsync(model); + + var modelStream = package.ModelPart; + package.ModelPart = await FixTextureContentType(modelStream); + + // save to file and easy to debug + // var stream = await package.SaveAsync(); + // await SaveStreamTo3MF(stream); + } + + private async Task FixTextureContentType(IRandomAccessStream modelStream) + { + XDocument xmldoc = XDocument.Load(modelStream.AsStreamForRead()); + + var outputStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); + var writer = new Windows.Storage.Streams.DataWriter(outputStream); + writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; + writer.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian; + + var text = xmldoc.ToString(); + + var replacedText = text.Replace("contenttype=\"\"", "contenttype=\"image/png\""); + writer.WriteString(replacedText); + + await writer.StoreAsync(); + await writer.FlushAsync(); + writer.DetachStream(); + return outputStream; + } + + private async static Task SaveStreamTo3MF(Windows.Storage.Streams.IRandomAccessStream stream) + { + // set back + stream.Seek(0); + using (var dataReader = new Windows.Storage.Streams.DataReader(stream)) + { + + var dataLoad = await dataReader.LoadAsync((uint)stream.Size); + if (dataLoad > 0) + { + var buffer = dataReader.ReadBuffer((uint)stream.Size); + + StorageFolder localFolder = ApplicationData.Current.LocalFolder; + var outputfile = await localFolder.CreateFileAsync("output.3mf", CreationCollisionOption.ReplaceExisting); + await Windows.Storage.FileIO.WriteBufferAsync(outputfile, buffer); + var options = new Windows.System.LauncherOptions(); + options.TargetApplicationPackageFamilyName = "Microsoft.3DBuilder_8wekyb3d8bbwe"; + } + } + + return true; + } + + private void Task_Submitting(Print3DTask sender, object args) + { + // notify user if required + } + + private void Task_Completed(Print3DTask sender, Print3DTaskCompletedEventArgs args) + { + // notify user if required + } + + private async Task GetVerticesAsync(Printing3DMesh mesh) + { + Printing3DBufferDescription description; + + description.Format = Printing3DBufferFormat.Printing3DDouble; + description.Stride = 3; + mesh.VertexCount = verticesCount; + mesh.CreateVertexPositions(sizeof(double) * 3 * mesh.VertexCount); + mesh.VertexPositionsDescription = description; + + using (var stream = mesh.GetVertexPositions().AsStream()) + { + var data = verticesPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); + await stream.WriteAsync(data, 0, data.Length); + } + } + + private static async Task GetIndicesAsync(Printing3DMesh mesh) + { + Printing3DBufferDescription description; + + description.Format = Printing3DBufferFormat.Printing3DUInt; + description.Stride = 3; + mesh.IndexCount = indicesCount; + mesh.TriangleIndicesDescription = description; + + mesh.CreateTriangleIndices(sizeof(UInt32) * 3 * mesh.IndexCount); + + var stream = mesh.GetTriangleIndices().AsStream(); + { + var data = indicesPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); + await stream.WriteAsync(data, 0, data.Length); + } + + } + + private static async Task GetMaterialIndicesAsync(Printing3DMesh mesh) + { + Printing3DBufferDescription description; + + description.Format = Printing3DBufferFormat.Printing3DUInt; + description.Stride = 4; + mesh.IndexCount = verticesMaterialCount; + mesh.TriangleMaterialIndicesDescription = description; + + mesh.CreateTriangleMaterialIndices(sizeof(UInt32) * 4 * mesh.IndexCount); + + var stream = mesh.GetTriangleMaterialIndices().AsStream(); + { + var data = indicesMaterialPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); + await stream.WriteAsync(data, 0, data.Length); + } + } + + // create one IRandomAccessStreamWithContentType class + // in WinRT API, there is no instance for IRandomAccessStreamWithContentType + // for the user, you just need to copy this class, change the value for "ContentType" + public class MyRandomAccessStream : IRandomAccessStreamWithContentType + { + private IRandomAccessStream _stream; + + public bool CanRead + { + get + { + return _stream.CanRead; + } + } + + public bool CanWrite + { + get + { + return _stream.CanWrite; + } + } + + public ulong Position + { + get + { + return _stream.Position; + } + } + + public ulong Size + { + get + { + return _stream.Size; + } + + set + { + _stream.Size = value; + } + } + + public string ContentType + { + get + { + // depending on the real data type + return "image/png"; + } + } + + public MyRandomAccessStream(IRandomAccessStream stream) + { + _stream = stream; + } + + public IRandomAccessStream CloneStream() + { + return _stream.CloneStream(); + } + + public void Dispose() + { + _stream.Dispose(); + } + + public IAsyncOperation FlushAsync() + { + return _stream.FlushAsync(); + } + + public IInputStream GetInputStreamAt(ulong position) + { + return _stream.GetInputStreamAt(position); + } + + public IOutputStream GetOutputStreamAt(ulong position) + { + return _stream.GetOutputStreamAt(position); + } + + public IAsyncOperationWithProgress ReadAsync(IBuffer buffer, uint count, InputStreamOptions options) + { + return _stream.ReadAsync(buffer, count, options); + } + + public void Seek(ulong position) + { + _stream.Seek(position); + } + + public IAsyncOperationWithProgress WriteAsync(IBuffer buffer) + { + return _stream.WriteAsync(buffer); + } + } +#endif +} diff --git a/Samples/3DPrintingFromUnity/Assets/Script/Turn.cs b/Samples/3DPrintingFromUnity/Assets/Script/Turn.cs new file mode 100644 index 0000000000..9a1d9bbc84 --- /dev/null +++ b/Samples/3DPrintingFromUnity/Assets/Script/Turn.cs @@ -0,0 +1,17 @@ +using UnityEngine; +using System.Collections; + +public class Turn : MonoBehaviour { + public float turningSpeed = 60; + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + float horizontal = Input.GetAxis("Horizontal") * turningSpeed * Time.deltaTime; + transform.Rotate(0, horizontal, 0); + } +} diff --git a/Samples/3DPrintingFromUnity/README.md b/Samples/3DPrintingFromUnity/README.md new file mode 100644 index 0000000000..c706ea3f59 --- /dev/null +++ b/Samples/3DPrintingFromUnity/README.md @@ -0,0 +1,140 @@ + + +# 3D Printing from Unity sample + +This sample demonstrates loading a Unity 3D asset +into the Windows 10 3D print dialog. +From there, +the user can repair the model, +make simple modifications, +and send it to a local 3D printer or an online 3D print service. + +**Note** that this is not a traditional sample +that you can simply load into Visual Studio. +Follow the instructions below to create and run the sample. + +# Prerequisites + +In addition to Visual Studio and the Windows SDK, you need the following: + +* Unity version + [5.2.1p2](https://unity3d.com/unity/qa/patch-releases "Unity") or later. + +* The Unity plugin for Visual Studio. + This can be installed as part of installing Unity, + or you can + [download it](https://visualstudiogallery.msdn.microsoft.com/8d26236e-4a64-4d64-8486-7df95156aba9 "Visual Studio 2015 Tools for Unity") + manually. + +* The 3D Builder app. + This application comes preinstalled with Windows 10. + If you have uninstalled it, + you can + [reinstall it from the Store](https://www.microsoft.com/en-us/store/apps/3d-builder/9wzdncrfj3t6 "3D Builder"). + +A basic understanding of Unity is assumed. +Learn how to get started with Unity +[here](https://unity3d.com/learn/tutorials "Unity tutorials") + +# Create the sample + +We provide only the scripts `Print.cs` and `Turn.cs`. +You will create the scene and the model (fbx model, material, and texture) +yourself. + +1. Start Unity and create a new 3D project. + +2. Import an asset from the + [Unity store](https://www.assetstore.unity3d.com/en/ "Unity Store"). + For this sample, we will use [Cartoon crucian carp](https://www.assetstore.unity3d.com/en/#!/content/46132 "Fish"). + +3. Create an empty GameObject and drag the FBX asset from the All Models folder + into the newly-created GameObject. + +4. In the Assets\nnj3de_cruscarp folder of the project, click cruscarp.png. + This will show "cruscarp Import Settings" in the Inspector pane. + +5. In the Inspector pane for "cruscarp Import Settings", + set the Texture Type to **Advanced**, + and then check the **Read/Write Enabled** checkbox, + and then set the Format to **RGBA 32 bit**. + +6. Click Apply at the bottom of the Inspector pane to apply the changes. + +7. Go to the All Scripts folder, right-click an empty space, + and select **Import New Asset**. + Select the `Print.js` and (optionally) `Turn.js` files from this sample. + The `Turn.js` script lets the user rotate the object and inspect + it within the Unity editor. + +8. Expand the GameObject you created in step 3 + to reveal the **cruscarp** node. + Expand the **cruscarp** node to reveal a second + **cruscarp** node. This is the rendering mesh. + +9. Drag the `Print.js` file (and optionally `Turn.js` file) + from the All Scripts folder onto the rendering mesh node + you revealed in step 8. + +10. From the File menu, select **Build Settings**, and set + the Platform to **Windows Store**, SDK to **Universal 10**, + and Build Type to **XAML**. + Click **Build** and choose a folder that will receive the + generated C# project. + +11. Open the generated csproj file in a text editor to fix an error + in Unity's code generation: Search for + the lines + + 10.0.N.0.0 + + and + + + + (The value of N will depend on the SDK you are using.) + Delete the extra `.0`: + + 10.0.N.0 + + + +# Build and run the sample + +You can now open the .sln file in Visual Studio +and build the sample. +When you run the sample, +click the **3D Print** button to launch the Windows 10 +3D Print dialog. +From this dialog, you can order your model online or send +it to a local printer. + +# Debugging the sample + +From the Modules window, +choose Assembly-CSharp.dll. +Find the symbol from your solution folder and load it. +Within your script, set your breakpoints. + +Additionally, you can inspect the [3MF file](http://3mf.io/ "3MF") +that has been generated using the commented function in Print.cs. + + +## Related topics + +### Reference + +* [3D Printing in Windows](https://www.microsoft.com/3d) + +* [**Windows.Graphics.Printing3D** namespace](https://msdn.microsoft.com/library/windows/apps/windows.graphics.printing3d.aspx) +* [**Print3DManager** class](https://msdn.microsoft.com/library/windows/apps/windows.graphics.printing3d.print3dmanager.aspx) launches the print dialog +* [**Printing3D3MFPackage** class](https://msdn.microsoft.com/library/windows/apps/windows.graphics.printing3d.printing3d3mfpackage.aspx). + +## System requirements + +**Client:** Windows 10 Version 1511 + +**Phone:** Windows 10 Version 1511 diff --git a/Samples/BasicInput/cs/3-DeviceCapabilities.xaml.cs b/Samples/BasicInput/cs/3-DeviceCapabilities.xaml.cs index 597bd66085..d67813d861 100644 --- a/Samples/BasicInput/cs/3-DeviceCapabilities.xaml.cs +++ b/Samples/BasicInput/cs/3-DeviceCapabilities.xaml.cs @@ -35,7 +35,7 @@ public Scenario3() System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("Mouse present = " + mouseCapabilities.MousePresent.ToString() + "\n"); sb.Append("Number of buttons = " + mouseCapabilities.NumberOfButtons.ToString() + "\n"); - sb.Append("Vertical wheel present present = " + mouseCapabilities.VerticalWheelPresent.ToString() + "\n"); + sb.Append("Vertical wheel present = " + mouseCapabilities.VerticalWheelPresent.ToString() + "\n"); sb.Append("Horizontal wheel present = " + mouseCapabilities.HorizontalWheelPresent.ToString() + "\n"); sb.Append("Buttons swapped = " + mouseCapabilities.SwapButtons.ToString()); mouseText.Text = sb.ToString(); diff --git a/Samples/BluetoothRfcommChat/README.md b/Samples/BluetoothRfcommChat/README.md index c2594a3a7e..c267bedb1e 100644 --- a/Samples/BluetoothRfcommChat/README.md +++ b/Samples/BluetoothRfcommChat/README.md @@ -32,7 +32,7 @@ To obtain information about Microsoft Visual Studio 2015 and the tools for devel [DataReaderWriter sample](../DataReaderWriter) -[DeviceEnumeration sample](../DeviceEnumeration) +[DeviceEnumeration sample](../DeviceEnumerationAndPairing) [StreamSocket sample](../StreamSocket) diff --git a/Samples/ExtendedExecution/README.md b/Samples/ExtendedExecution/README.md new file mode 100644 index 0000000000..b5b61015f5 --- /dev/null +++ b/Samples/ExtendedExecution/README.md @@ -0,0 +1,117 @@ + + +# Extended execution sample + +This sample shows you how to create extended execution sessions using the Windows Runtime extended execution API. + +**Note** The Universal Windows app samples require Visual Studio 2015 to build and Windows 10 to execute. + +An app requests an extended execution session when a task requires time to complete before the application is suspended or terminated. +Different types of extended execution can be requested during the Suspending state or the Resumed state of the application. + +This sample demonstrates the following: + +- Creating an extended execution session to extend suspending time and complete saving data. +- Creating an extended execution session to extend foreground time and continue location tracking. +- Creating an extended execution session to extend foreground time and continue an unspecified task. +- Handling a denied request for extended execution. +- Handling the revocation of an extended execution session. + +See **Deploying and running the sample** below for instructions on using the sample. + +## Related topics + +### Samples + +* [Background audio](/Samples/BackgroundAudio) +* [Geolocation](/Samples/Geolocation) + +### Other resources + +[Background Tasks and Extended Execution](https://msdn.microsoft.com/en-us/magazine/mt590969) + +[Launching, resuming, and background tasks](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/mt227652.aspx) + +[Support your app with background tasks](https://msdn.microsoft.com/library/windows/apps/mt299103) + +### Reference + +[**Windows.ApplicationModel.ExtendedExecution**](https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.extendedexecution.aspx) + +### Related technologies + +[**Windows.ApplicationModel.Background**](http://msdn.microsoft.com/library/windows/apps/br224847) + +## Operating system requirements + +**Client:** Windows 10 + +**Server:** Windows Server 2016 Technical Preview + +**Phone:** Windows 10 + +## Build the sample + +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 + +**Deploying the sample** + +1. Select **Build** \> **Deploy Solution**. + +**Deploying and running the sample** + +1. 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**. +Since the system will not suspend an app that is being debugged, +some scenarios require you to run the sample without debugging. + +**Unspecified Extended Execution**: + +1. Run the sample without debugging and go to the **Unspecified Reason** scenario. +2. Click **Begin Extended Execution**. +3. Send the program to the background: + On Phone, switch to another app. + On PC, minimize the app. +4. The app continues to display toast notifications. +5. Bring the app back to the foreground to cause a revoke due to Resume. +6. Run the sample with debugging. +7. Repeat steps 2 through 4 above. +8. Use the Lifecycle events menu in the debugger to suspend the app. + This simulates a revoke due to SystemPolicy. + +**Saving Data Extended Execution**: + +1. Run the sample without debugging and go to the **Saving Data Reason** scenario. +2. Send the program to the background: + On Phone, switch to another app. + On PC, minimize the app. +3. The app displays toast notifications while the save operation proceeds, + demonstrating that the app was given a longer period of time to save data while suspending. + +**Location Tracking Extended Execution**: + +1. Run the sample without debugging and go to the **Location Tracking Reason** scenario. +2. Click **Begin Extended Execution**. +3. Send the program to the background: + On Phone, switch to another app. + On PC, minimize the app. +4. The app continues to report your location every 10 seconds. +5. Bring the app back to the foreground to cause a revoke due to Resume. +6. Run the sample with debugging. +7. Repeat steps 2 through 4 above. +8. Use the Lifecycle events menu in the debugger to suspend the app. + This simulates a revoke due to SystemPolicy. + +## Read more + +See the following topics for step-by-step information about using extended execution: + +- [Background Tasks and Extended Execution](https://msdn.microsoft.com/en-us/magazine/mt590969) + diff --git a/Samples/ExtendedExecution/cs/ExtendedExecution.csproj b/Samples/ExtendedExecution/cs/ExtendedExecution.csproj new file mode 100644 index 0000000000..f8ae5523b6 --- /dev/null +++ b/Samples/ExtendedExecution/cs/ExtendedExecution.csproj @@ -0,0 +1,181 @@ + + + + + Debug + x86 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F} + AppContainerExe + Properties + SDKTemplate + ExtendedExecution + en-US + UAP + 10.0.10586.0 + 10.0.10240.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x86 + false + prompt + true + + + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x86 + false + prompt + true + true + + + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM + false + prompt + true + + + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM + false + prompt + true + true + + + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x64 + false + prompt + true + + + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x64 + false + prompt + true + true + + + + + + + + App.xaml.cs + App.xaml + + + MainPage.xaml.cs + MainPage.xaml + + + Properties\AssemblyInfo.cs + + + + + + + + + Designer + + + + + Assets\microsoft-sdk.png + + + Assets\smalltile-sdk.png + + + Assets\splash-sdk.png + + + Assets\squaretile-sdk.png + + + Assets\storelogo-sdk.png + + + Assets\tile-sdk.png + + + Assets\windows-sdk.png + + + Properties\Default.rd.xml + + + + + App.xaml + MSBuild:Compile + Designer + + + MainPage.xaml + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Styles\Styles.xaml + Designer + MSBuild:Compile + + + + 14.0 + + + + \ No newline at end of file diff --git a/Samples/ExtendedExecution/cs/ExtendedExecution.sln b/Samples/ExtendedExecution/cs/ExtendedExecution.sln new file mode 100644 index 0000000000..427869a37d --- /dev/null +++ b/Samples/ExtendedExecution/cs/ExtendedExecution.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtendedExecution", "ExtendedExecution.csproj", "{3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}" +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 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|ARM.ActiveCfg = Debug|ARM + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|ARM.Build.0 = Debug|ARM + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|ARM.Deploy.0 = Debug|ARM + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|x64.ActiveCfg = Debug|x64 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|x64.Build.0 = Debug|x64 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|x64.Deploy.0 = Debug|x64 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|x86.ActiveCfg = Debug|x86 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|x86.Build.0 = Debug|x86 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Debug|x86.Deploy.0 = Debug|x86 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|ARM.ActiveCfg = Release|ARM + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|ARM.Build.0 = Release|ARM + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|ARM.Deploy.0 = Release|ARM + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|x64.ActiveCfg = Release|x64 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|x64.Build.0 = Release|x64 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|x64.Deploy.0 = Release|x64 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|x86.ActiveCfg = Release|x86 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|x86.Build.0 = Release|x86 + {3DE0BD30-8F0D-4835-91C5-9EC6133B7B0F}.Release|x86.Deploy.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples/ExtendedExecution/cs/Package.appxmanifest b/Samples/ExtendedExecution/cs/Package.appxmanifest new file mode 100644 index 0000000000..60a9047d04 --- /dev/null +++ b/Samples/ExtendedExecution/cs/Package.appxmanifest @@ -0,0 +1,43 @@ + + + + + + Extended Execution C# Sample + Microsoft Corporation + Assets\StoreLogo-sdk.png + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/ExtendedExecution/cs/SampleConfiguration.cs b/Samples/ExtendedExecution/cs/SampleConfiguration.cs new file mode 100644 index 0000000000..0118d44c5f --- /dev/null +++ b/Samples/ExtendedExecution/cs/SampleConfiguration.cs @@ -0,0 +1,64 @@ +//********************************************************* +// +// 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.Data.Xml.Dom; +using Windows.UI.Notifications; +using Windows.UI.Xaml.Controls; + + +namespace SDKTemplate +{ + public partial class MainPage : Page + { + public const string FEATURE_NAME = "Extended Execution"; + + List scenarios = new List + { + new Scenario() { Title="Unspecified Reason", ClassType=typeof(UnspecifiedReason)}, + new Scenario() { Title="Saving Data Reason", ClassType=typeof(SavingDataReason)}, + new Scenario() { Title="Location Tracking Reason", ClassType=typeof(LocationTrackingReason)}, + }; + + public static ToastNotification DisplayToast(string content) + { + string xml = $@" + + + Extended Execution + + + "; + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + + var binding = doc.SelectSingleNode("//binding"); + + var el = doc.CreateElement("text"); + el.InnerText = content; + binding.AppendChild(el); //Add content to notification + + var toast = new ToastNotification(doc); + + ToastNotificationManager.CreateToastNotifier().Show(toast); //Show the toast + + return toast; + } + } + + public class Scenario + { + public string Title { get; set; } + public Type ClassType { get; set; } + } +} \ No newline at end of file diff --git a/Samples/ExtendedExecution/cs/Scenario1_UnspecifiedReason.xaml b/Samples/ExtendedExecution/cs/Scenario1_UnspecifiedReason.xaml new file mode 100644 index 0000000000..fd8c3cf214 --- /dev/null +++ b/Samples/ExtendedExecution/cs/Scenario1_UnspecifiedReason.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + Requests for extended execution using the "Unspecified" reason + are allowed only during the Resumed lifecycle stage. + The app raises a toast every ten seconds to demonstrate that it is still running. + +