Produced by Araxis Merge on 2/1/2017 2:56:48 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\ModernAndMobileApps\ModernOdataApp\Common | SuspensionManager.cs | Tue Dec 20 19:51:47 2016 UTC |
| 2 | Wed Feb 1 19:56:48 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 275 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 2 | // | |||||
| 3 | // This f ile is par t of the M icrosoft D ynamics CR M SDK Code Samples. | |||||
| 4 | // | |||||
| 5 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 6 | // | |||||
| 7 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 8 | // Develo pment Tool s and/or o nline docu mentation. See thes e other | |||||
| 9 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 10 | // | |||||
| 11 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 12 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 13 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 14 | // PARTIC ULAR PURPO SE. | |||||
| 15 | // | |||||
| 16 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 17 | ||||||
| 18 | using Syst em; | |||||
| 19 | using Syst em.Collect ions.Gener ic; | |||||
| 20 | using Syst em.IO; | |||||
| 21 | using Syst em.Linq; | |||||
| 22 | using Syst em.Runtime .Serializa tion; | |||||
| 23 | using Syst em.Text; | |||||
| 24 | using Syst em.Threadi ng.Tasks; | |||||
| 25 | using Wind ows.Applic ationModel ; | |||||
| 26 | using Wind ows.Storag e; | |||||
| 27 | using Wind ows.Storag e.Streams; | |||||
| 28 | using Wind ows.UI.Xam l; | |||||
| 29 | using Wind ows.UI.Xam l.Controls ; | |||||
| 30 | ||||||
| 31 | namespace ModernOdat aApp.Commo n | |||||
| 32 | { | |||||
| 33 | /// <s ummary> | |||||
| 34 | /// Su spensionMa nager capt ures globa l session state to s implify pr ocess life time manag ement | |||||
| 35 | /// fo r an appli cation. N ote that s ession sta te will be automatic ally clear ed under a variety | |||||
| 36 | /// of condition s and shou ld only be used to s tore infor mation tha t would be convenien t to | |||||
| 37 | /// ca rry across sessions, but that should be discarded when an ap plication crashes or is | |||||
| 38 | /// up graded. | |||||
| 39 | /// </ summary> | |||||
| 40 | intern al sealed class Susp ensionMana ger | |||||
| 41 | { | |||||
| 42 | pr ivate stat ic Diction ary<string , object> _sessionSt ate = new Dictionary <string, o bject>(); | |||||
| 43 | pr ivate stat ic List<Ty pe> _known Types = ne w List<Typ e>(); | |||||
| 44 | pr ivate cons t string s essionStat eFilename = "_sessio nState.xml "; | |||||
| 45 | ||||||
| 46 | // / <summary > | |||||
| 47 | // / Provides access to global se ssion stat e for the current se ssion. Th is state i s | |||||
| 48 | // / serializ ed by <see cref="Sav eAsync"/> and restor ed by | |||||
| 49 | // / <see cre f="Restore Async"/>, so values must be se rializable by | |||||
| 50 | // / <see cre f="DataCon tractSeria lizer"/> a nd should be as comp act as pos sible. St rings | |||||
| 51 | // / and othe r self-con tained dat a types ar e strongly recommend ed. | |||||
| 52 | // / </summar y> | |||||
| 53 | pu blic stati c Dictiona ry<string, object> S essionStat e | |||||
| 54 | { | |||||
| 55 | get { re turn _sess ionState; } | |||||
| 56 | } | |||||
| 57 | ||||||
| 58 | // / <summary > | |||||
| 59 | // / List of custom typ es provide d to the < see cref=" DataContra ctSerializ er"/> when | |||||
| 60 | // / reading and writin g session state. In itially em pty, addit ional type s may be | |||||
| 61 | // / added to customize the seria lization p rocess. | |||||
| 62 | // / </summar y> | |||||
| 63 | pu blic stati c List<Typ e> KnownTy pes | |||||
| 64 | { | |||||
| 65 | get { re turn _know nTypes; } | |||||
| 66 | } | |||||
| 67 | ||||||
| 68 | // / <summary > | |||||
| 69 | // / Save the current < see cref=" SessionSta te"/>. An y <see cre f="Frame"/ > instance s | |||||
| 70 | // / register ed with <s ee cref="R egisterFra me"/> will also pres erve their current | |||||
| 71 | // / navigati on stack, which in t urn gives their acti ve <see cr ef="Page"/ > an oppor tunity | |||||
| 72 | // / to save its state. | |||||
| 73 | // / </summar y> | |||||
| 74 | // / <returns >An asynch ronous tas k that ref lects when session s tate has b een saved. </returns> | |||||
| 75 | pu blic stati c async Ta sk SaveAsy nc() | |||||
| 76 | { | |||||
| 77 | try | |||||
| 78 | { | |||||
| 79 | // S ave the na vigation s tate for a ll registe red frames | |||||
| 80 | fore ach (var w eakFrameRe ference in _register edFrames) | |||||
| 81 | { | |||||
| 82 | Frame fram e; | |||||
| 83 | if (weakFr ameReferen ce.TryGetT arget(out frame)) | |||||
| 84 | { | |||||
| 85 | SaveFr ameNavigat ionState(f rame); | |||||
| 86 | } | |||||
| 87 | } | |||||
| 88 | ||||||
| 89 | // S erialize t he session state syn chronously to avoid asynchrono us access to shared | |||||
| 90 | // s tate | |||||
| 91 | Memo ryStream s essionData = new Mem oryStream( ); | |||||
| 92 | Data ContractSe rializer s erializer = new Data ContractSe rializer(t ypeof(Dict ionary<str ing, objec t>), _know nTypes); | |||||
| 93 | seri alizer.Wri teObject(s essionData , _session State); | |||||
| 94 | ||||||
| 95 | // G et an outp ut stream for the Se ssionState file and write the state asyn chronously | |||||
| 96 | Stor ageFile fi le = await Applicati onData.Cur rent.Local Folder.Cre ateFileAsy nc(session StateFilen ame, Creat ionCollisi onOption.R eplaceExis ting); | |||||
| 97 | usin g (Stream fileStream = await f ile.OpenSt reamForWri teAsync()) | |||||
| 98 | { | |||||
| 99 | sessionDat a.Seek(0, SeekOrigin .Begin); | |||||
| 100 | await sess ionData.Co pyToAsync( fileStream ); | |||||
| 101 | await file Stream.Flu shAsync(); | |||||
| 102 | } | |||||
| 103 | } | |||||
| 104 | catch (E xception e ) | |||||
| 105 | { | |||||
| 106 | thro w new Susp ensionMana gerExcepti on(e); | |||||
| 107 | } | |||||
| 108 | } | |||||
| 109 | ||||||
| 110 | // / <summary > | |||||
| 111 | // / Restores previousl y saved <s ee cref="S essionStat e"/>. Any <see cref ="Frame"/> instances | |||||
| 112 | // / register ed with <s ee cref="R egisterFra me"/> will also rest ore their prior navi gation | |||||
| 113 | // / state, w hich in tu rn gives t heir activ e <see cre f="Page"/> an opport unity rest ore its | |||||
| 114 | // / state. | |||||
| 115 | // / </summar y> | |||||
| 116 | // / <returns >An asynch ronous tas k that ref lects when session s tate has b een read. The | |||||
| 117 | // / content of <see cr ef="Sessio nState"/> should not be relied upon unti l this tas k | |||||
| 118 | // / complete s.</return s> | |||||
| 119 | pu blic stati c async Ta sk Restore Async() | |||||
| 120 | { | |||||
| 121 | _session State = ne w Dictiona ry<String, Object>() ; | |||||
| 122 | ||||||
| 123 | try | |||||
| 124 | { | |||||
| 125 | // G et the inp ut stream for the Se ssionState file | |||||
| 126 | Stor ageFile fi le = await Applicati onData.Cur rent.Local Folder.Get FileAsync( sessionSta teFilename ); | |||||
| 127 | usin g (IInputS tream inSt ream = awa it file.Op enSequenti alReadAsyn c()) | |||||
| 128 | { | |||||
| 129 | // Deseria lize the S ession Sta te | |||||
| 130 | DataContra ctSerializ er seriali zer = new DataContra ctSerializ er(typeof( Dictionary <string, o bject>), _ knownTypes ); | |||||
| 131 | _sessionSt ate = (Dic tionary<st ring, obje ct>)serial izer.ReadO bject(inSt ream.AsStr eamForRead ()); | |||||
| 132 | } | |||||
| 133 | ||||||
| 134 | // R estore any registere d frames t o their sa ved state | |||||
| 135 | fore ach (var w eakFrameRe ference in _register edFrames) | |||||
| 136 | { | |||||
| 137 | Frame fram e; | |||||
| 138 | if (weakFr ameReferen ce.TryGetT arget(out frame)) | |||||
| 139 | { | |||||
| 140 | frame. ClearValue (FrameSess ionStatePr operty); | |||||
| 141 | Restor eFrameNavi gationStat e(frame); | |||||
| 142 | } | |||||
| 143 | } | |||||
| 144 | } | |||||
| 145 | catch (E xception e ) | |||||
| 146 | { | |||||
| 147 | thro w new Susp ensionMana gerExcepti on(e); | |||||
| 148 | } | |||||
| 149 | } | |||||
| 150 | ||||||
| 151 | pr ivate stat ic Depende ncyPropert y FrameSes sionStateK eyProperty = | |||||
| 152 | Dependen cyProperty .RegisterA ttached("_ FrameSessi onStateKey ", typeof( String), t ypeof(Susp ensionMana ger), null ); | |||||
| 153 | pr ivate stat ic Depende ncyPropert y FrameSes sionStateP roperty = | |||||
| 154 | Dependen cyProperty .RegisterA ttached("_ FrameSessi onState", typeof(Dic tionary<St ring, Obje ct>), type of(Suspens ionManager ), null); | |||||
| 155 | pr ivate stat ic List<We akReferenc e<Frame>> _registere dFrames = new List<W eakReferen ce<Frame>> (); | |||||
| 156 | ||||||
| 157 | // / <summary > | |||||
| 158 | // / Register s a <see c ref="Frame "/> instan ce to allo w its navi gation his tory to be saved to | |||||
| 159 | // / and rest ored from <see cref= "SessionSt ate"/>. F rames shou ld be regi stered onc e | |||||
| 160 | // / immediat ely after creation i f they wil l particip ate in ses sion state managemen t. Upon | |||||
| 161 | // / registra tion if st ate has al ready been restored for the sp ecified ke y | |||||
| 162 | // / the navi gation his tory will immediatel y be resto red. Subs equent inv ocations o f | |||||
| 163 | // / <see cre f="Restore Async"/> w ill also r estore nav igation hi story. | |||||
| 164 | // / </summar y> | |||||
| 165 | // / <param n ame="frame ">An insta nce whose navigation history s hould be m anaged by | |||||
| 166 | // / <see cre f="Suspens ionManager "/></param > | |||||
| 167 | // / <param n ame="sessi onStateKey ">A unique key into <see cref= "SessionSt ate"/> use d to | |||||
| 168 | // / store na vigation-r elated inf ormation.< /param> | |||||
| 169 | pu blic stati c void Reg isterFrame (Frame fra me, String sessionSt ateKey) | |||||
| 170 | { | |||||
| 171 | if (fram e.GetValue (FrameSess ionStateKe yProperty) != null) | |||||
| 172 | { | |||||
| 173 | thro w new Inva lidOperati onExceptio n("Frames can only b e register ed to one session st ate key"); | |||||
| 174 | } | |||||
| 175 | ||||||
| 176 | if (fram e.GetValue (FrameSess ionStatePr operty) != null) | |||||
| 177 | { | |||||
| 178 | thro w new Inva lidOperati onExceptio n("Frames must be ei ther be re gistered b efore acce ssing fram e session state, or not regist ered at al l"); | |||||
| 179 | } | |||||
| 180 | ||||||
| 181 | // Use a dependenc y property to associ ate the se ssion key with a fra me, and ke ep a list of frames whose | |||||
| 182 | // navig ation stat e should b e managed | |||||
| 183 | frame.Se tValue(Fra meSessionS tateKeyPro perty, ses sionStateK ey); | |||||
| 184 | _registe redFrames. Add(new We akReferenc e<Frame>(f rame)); | |||||
| 185 | ||||||
| 186 | // Check to see if navigatio n state ca n be resto red | |||||
| 187 | RestoreF rameNaviga tionState( frame); | |||||
| 188 | } | |||||
| 189 | ||||||
| 190 | // / <summary > | |||||
| 191 | // / Disassoc iates a <s ee cref="F rame"/> pr eviously r egistered by <see cr ef="Regist erFrame"/> | |||||
| 192 | // / from <se e cref="Se ssionState "/>. Any navigation state pre viously ca ptured wil l be | |||||
| 193 | // / removed. | |||||
| 194 | // / </summar y> | |||||
| 195 | // / <param n ame="frame ">An insta nce whose navigation history s hould no l onger be | |||||
| 196 | // / managed. </param> | |||||
| 197 | pu blic stati c void Unr egisterFra me(Frame f rame) | |||||
| 198 | { | |||||
| 199 | // Remov e session state and remove the frame fro m the list of frames whose nav igation | |||||
| 200 | // state will be s aved (alon g with any weak refe rences tha t are no l onger reac hable) | |||||
| 201 | SessionS tate.Remov e((String) frame.GetV alue(Frame SessionSta teKeyPrope rty)); | |||||
| 202 | _registe redFrames. RemoveAll( (weakFrame Reference) => | |||||
| 203 | { | |||||
| 204 | Fram e testFram e; | |||||
| 205 | retu rn !weakFr ameReferen ce.TryGetT arget(out testFrame) || testFr ame == fra me; | |||||
| 206 | }); | |||||
| 207 | } | |||||
| 208 | ||||||
| 209 | // / <summary > | |||||
| 210 | // / Provides storage f or session state ass ociated wi th the spe cified <se e cref="Fr ame"/>. | |||||
| 211 | // / Frames t hat have b een previo usly regis tered with <see cref ="Register Frame"/> h ave | |||||
| 212 | // / their se ssion stat e saved an d restored automatic ally as a part of th e global | |||||
| 213 | // / <see cre f="Session State"/>. Frames th at are not registere d have tra nsient sta te | |||||
| 214 | // / that can still be useful whe n restorin g pages th at have be en discard ed from th e | |||||
| 215 | // / navigati on cache. | |||||
| 216 | // / </summar y> | |||||
| 217 | // / <remarks >Apps may choose to rely on <s ee cref="L ayoutAware Page"/> to manage | |||||
| 218 | // / page-spe cific stat e instead of working with fram e session state dire ctly.</rem arks> | |||||
| 219 | // / <param n ame="frame ">The inst ance for w hich sessi on state i s desired. </param> | |||||
| 220 | // / <returns >A collect ion of sta te subject to the sa me seriali zation mec hanism as | |||||
| 221 | // / <see cre f="Session State"/>.< /returns> | |||||
| 222 | pu blic stati c Dictiona ry<String, Object> S essionStat eForFrame( Frame fram e) | |||||
| 223 | { | |||||
| 224 | var fram eState = ( Dictionary <String, O bject>)fra me.GetValu e(FrameSes sionStateP roperty); | |||||
| 225 | ||||||
| 226 | if (fram eState == null) | |||||
| 227 | { | |||||
| 228 | var frameSessi onKey = (S tring)fram e.GetValue (FrameSess ionStateKe yProperty) ; | |||||
| 229 | if ( frameSessi onKey != n ull) | |||||
| 230 | { | |||||
| 231 | // Registe red frames reflect t he corresp onding ses sion state | |||||
| 232 | if (!_sess ionState.C ontainsKey (frameSess ionKey)) | |||||
| 233 | { | |||||
| 234 | _sessi onState[fr ameSession Key] = new Dictionar y<String, Object>(); | |||||
| 235 | } | |||||
| 236 | frameState = (Dictio nary<Strin g, Object> )_sessionS tate[frame SessionKey ]; | |||||
| 237 | } | |||||
| 238 | else | |||||
| 239 | { | |||||
| 240 | // Frames that aren' t register ed have tr ansient st ate | |||||
| 241 | frameState = new Dic tionary<St ring, Obje ct>(); | |||||
| 242 | } | |||||
| 243 | fram e.SetValue (FrameSess ionStatePr operty, fr ameState); | |||||
| 244 | } | |||||
| 245 | return f rameState; | |||||
| 246 | } | |||||
| 247 | ||||||
| 248 | pr ivate stat ic void Re storeFrame Navigation State(Fram e frame) | |||||
| 249 | { | |||||
| 250 | var fram eState = S essionStat eForFrame( frame); | |||||
| 251 | if (fram eState.Con tainsKey(" Navigation ")) | |||||
| 252 | { | |||||
| 253 | fram e.SetNavig ationState ((String)f rameState[ "Navigatio n"]); | |||||
| 254 | } | |||||
| 255 | } | |||||
| 256 | ||||||
| 257 | pr ivate stat ic void Sa veFrameNav igationSta te(Frame f rame) | |||||
| 258 | { | |||||
| 259 | var fram eState = S essionStat eForFrame( frame); | |||||
| 260 | frameSta te["Naviga tion"] = f rame.GetNa vigationSt ate(); | |||||
| 261 | } | |||||
| 262 | } | |||||
| 263 | public class Sus pensionMan agerExcept ion : Exce ption | |||||
| 264 | { | |||||
| 265 | pu blic Suspe nsionManag erExceptio n() | |||||
| 266 | { | |||||
| 267 | } | |||||
| 268 | ||||||
| 269 | pu blic Suspe nsionManag erExceptio n(Exceptio n e) | |||||
| 270 | : base(" Suspension Manager fa iled", e) | |||||
| 271 | { | |||||
| 272 | ||||||
| 273 | } | |||||
| 274 | } | |||||
| 275 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.