Selector: cachedfileupdater (cached file update)
Introduced
Re-imagine the Windows 8 Store Apps Selector
Cachedfileupdater-Cache file Update
Example
First, create a new Windows application store project to update the program as a cached file
1. Open a file and associate it with the Cachedfileupdater
Cachedfileupdaterprovider/myopenpicker.xaml
<page x:class= "Cachedfileupdaterprovider.myopenpicker" xmlns= "HTTP://SCHEMAS.MICROSOFT.COM/WINFX/2006/XAML/PR
Esentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" Using:cachedfileupdaterprovider " Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008" xmlns:mc= "http://schemas.openxmlformats.org/ markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0 0 0" > <textblock name= "lblmsg" fontsize= "14.667"/> <button Na Me= "Btnpickcachedfilelocal" content= provides a cachedfile (updated cachedfileupdater by cachedfile) "click=" by the local update Btnpickcachedfilelocal_click_1 "margin=" 0 0 0 "/> <button name=" Btnpickcachedfileremote "Conte
Nt= "provides a Remote updated Cachedfile (updated by app Cachedfile)" click= "Btnpickcachedfileremote_click_1" margin= "0 0 0"/> </StackPanel> </Grid> ≪/page>
Cachedfileupdaterprovider/myopenpicker.xaml.cs
* * Open a file and associate it with Cachedfileupdater * * 1, add a "File Open picker" declaration in Package.appxmanifest, and make a related configuration * 2, in App.xaml.cs override void onfileopenpickeractivated (Fileopenpickeractivatedeventargs args), if the app is activated by a file open selector, you can get information about it here */using Sys
Tem
Using Windows.ApplicationModel.Activation;
Using Windows.storage;
Using Windows.Storage.Pickers.Provider;
Using Windows.Storage.Provider;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation; Namespace Cachedfileupdaterprovider {public sealed partial class Myopenpicker:page {private FILEOPENPI
Ckerui _fileopenpickerui; Public Myopenpicker () {this.
InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {var args = (Fileopenpick
Eractivatedeventargs) E.parameter; _fileopenpickerui = args.
Fileopenpickerui;
_fileopenpickerui.title = "Custom File open selector"; }//This CacheDfile is used to update private async void Btnpickcachedfilelocal_click_1 from local (object sender, Windows.UI.Xaml.RoutedEventArg S e) {storagefile file = await ApplicationData.Current.LocalFolder.CreateFileAsync (@ "Webabcdcachedfil
EUpdaterLocal.txt ", creationcollisionoption.replaceexisting);
String textcontent = "I am WEBABCD";
Await Fileio.writetextasync (file, textcontent); /* Set Cachedfile to associate the file with the Cachedfileupdater * setupdateinformation (istoragefile file, String Co
Ntentid, Readactivationmode ReadMode, Writeactivationmode writemode, cachedfileoptions options);
* file-Files associated with Cachedfileupdater * ContentID-File identification associated with Cachedfileupdater * * Cachedfileupdater.setupdateinformation (file, "cachedfilelocal", Readactivationmode.beforeaccess,
writeactivationmode.notneeded, cachedfileoptions.requireupdateonaccess); Lblmsg.text = "SelectedFile: "+ file.
Name;
Addfileresult result = _fileopenpickerui.addfile ("myFile", file); }//This cachedfile is used to update private async void Btnpickcachedfileremote_click_1 from Remote (object sender, Win Dows. Ui. Xaml.routedeventargs e) {storagefile file = await ApplicationData.Current.LocalFolder.CreateFileAsync
(@ "WebabcdCachedFileUpdaterRemote.txt", creationcollisionoption.replaceexisting);
String textcontent = "I am WEBABCD";
Await Fileio.writetextasync (file, textcontent); /* Set Cachedfile to associate the file with the Cachedfileupdater * setupdateinformation (istoragefile file, String Co
Ntentid, Readactivationmode ReadMode, Writeactivationmode writemode, cachedfileoptions options);
* file-Files associated with Cachedfileupdater * ContentID-File identification associated with Cachedfileupdater * * Cachedfileupdater.setupdateinformation (file, "Cachedfileremote", readactivationmode.notneeded, Writeactivationmode.afterwrite, cachedfileoptions.requireupdateonaccess); Lblmsg.text = "Selected files:" + file.
Name;
Addfileresult result = _fileopenpickerui.addfile ("myFile", file); }
}
}
2, development of custom cache file update program
Cachedfileupdaterprovider/mycachedfileupdater.xaml
<page
x:class= "Cachedfileupdaterprovider.mycachedfileupdater"
xmlns= "http://schemas.microsoft.com/ Winfx/2006/xaml/presentation "
xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:local=" Using:cachedfileupdaterprovider "
xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
XMLNS:MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:ignorable= "D" >
<grid Background = "Transparent" >
<stackpanel margin= "0 0 0" >
<textblock name= "lblmsg" fontsize= "14.667"/>
<button name= "btnupdate" content= update cachedfile (updated cachedfileupdater by cachedfile) "click=" BtnUpdate_Click_1 "margin=" 0 0 0 "/>
</StackPanel>
</Grid>
</Page>
Cachedfileupdaterprovider/mycachedfileupdater.xaml.cs
* * Demonstrates how to develop a custom cache file update * * 1, add a "cached file update" declaration in Package.appxmanifest, and do the related configuration * 2, override void ONCAC in App.xaml.cs Hedfileupdateractivated (Cachedfileupdateractivatedeventargs args), if the app is activated by a file open selector, you can get information about it here * * Cachedfileupdateractivatedeventargs-Event parameters when activating an application via cache file Update * Cachedfileupdaterui-Get Cachedfileupdaterui Object * Previousexecutionstate, Kind, SplashScreen-Event parameter base * * Cachedfileupdaterui-cache file updates for various ways of activating the app * Title -The title * Uistatus that will be displayed on the cache file update-the UI state of the cached file update (unavailable, Hidden, Visible, Complete) * Updatetarget-loc Al representative is updated by Cachedfileupdater; Remote Rep updates by app * Uirequested-event that triggers when the UI for cached file updates is displayed * fileupdaterequested-triggers the fileup when the app activates the cached file update program Daterequested Event (event parameter: Cachedfileupdateractivatedeventargs) * * Cachedfileupdateractivatedeventargs * Request- Returns objects of type Fileupdaterequest * * fileupdaterequest * FILE-associated files * ContentID-associated File identities * Status-Files Update status (FileuPdatestatus enumeration. Incomplete, Complete, userinputneeded, currentlyunavailable, Failed, completeandrenamed) * getdeferral ()-Gets the asynchronous Operation object, the same
Begins the asynchronous operation, and then completes the asynchronous operation via Complete () notification/using System;
Using Windows.ApplicationModel.Activation;
Using Windows.storage;
Using Windows.Storage.Provider;
Using Windows.UI.Core;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation; Namespace Cachedfileupdaterprovider {public sealed partial class Mycachedfileupdater:page {private Cac
Hedfileupdaterui _cachedfileupdaterui;
Private Fileupdaterequest _fileupdaterequest;
Private Coredispatcher _dispatcher = Windows.UI.Xaml.Window.Current.Dispatcher; Public Mycachedfileupdater () {this.
InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {//Get Cachedfileupdateru I object var args = (Cachedfileupdateractivatedeventargs) e.Parameter; _cachedfileupdaterui = args.
Cachedfileupdaterui;
_cachedfileupdaterui.title = "cache file Update";
_cachedfileupdaterui.fileupdaterequested + = _cachedfileupdaterui_fileupdaterequested;
_cachedfileupdaterui.uirequested + = _cachedfileupdaterui_uirequested; This event handler is called when the Cachedfileupdater UI needs to be displayed (that is, when Fileupdaterequest.status equals userinputneeded) Async void _cachedfileupdaterui_uirequested (Cachedfileupdaterui sender, Object args) {await _dispatcher. Runasync (Coredispatcherpriority.normal, () => {Windows.UI.Xaml.Window.Current.Content = th
is;
Lblmsg.text = "Fileupdatestatus:" + _fileupdaterequest.status.tostring ();
}); } void _cachedfileupdaterui_fileupdaterequested (Cachedfileupdaterui sender, Fileupdaterequestedeventargs args ) {_fileupdaterequest = args.
Request; FiLeupdaterequestdeferral fileupdaterequestdeferral = _fileupdaterequest.getdeferral (); if (_cachedfileupdaterui.updatetarget = = cachedfiletarget.local)//updated by Cachedfileupdater Cachedfile (cachedfiletarget.local) {//Display cachedfileupdater UI if (_cach Edfileupdaterui.uistatus = = Uistatus.hidden) {_fileupdaterequest.status = Fileupdates Tatus.
userinputneeded;
Fileupdaterequestdeferral.complete (); } else if (_cachedfileupdaterui.updatetarget = cachedfiletarget.remote)//Update Cachedfile by app (
Cachedfiletarget.remote mode) {//Cachedfileupdater return to app for a fileupdatestatus state
_fileupdaterequest.status = Fileupdatestatus.complete;
Fileupdaterequestdeferral.complete ();
} private Async void Btnupdate_click_1 (object sender, RoutedEventArgs e) {Fileupdaterequestdeferral fileupdaterequestdeferral = _fileupdaterequest.getdeferral (); Update Cachedfile by Cachedfileupdater, then return to app a fileupdatestatus status await Fileio.appendtextasync (_file
Updaterequest.file, Environment.NewLine + "updated by Cachedfileupdater:" + DateTime.Now.ToString ());
String filecontent = await fileio.readtextasync (_fileupdaterequest.file);
Lblmsg.text = "FileName:" + _fileupdaterequest.file.name;
Lblmsg.text + = Environment.NewLine;
Lblmsg.text + = "File content:" + filecontent;
_fileupdaterequest.status = Fileupdatestatus.complete;
Fileupdaterequestdeferral.complete ();
btnupdate.isenabled = false; }
}
}