fna-workbench

fna-workbench Commit Details


Date:2016-02-03 11:24:36 (9 years 7 months ago)
Author:Ethan Lee
Branch:master
Commit:f5c538c8e1dea357a0db67c1795cfc55903423ad
Parents: 0f2d4f50f9a46eda5c1277634cba49670b36e969
Message:StorageDevice is not actually asynchronous!

Changes:

File differences

src/Storage/StorageDevice.cs
1010
1111
1212
13
1314
1415
1516
......
8788
8889
8990
90
91
9291
9392
9493
......
116115
117116
118117
119
120
121
122
123
124
125118
126119
127120
128121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
129183
130184
131
132
133
134
135
136
137
185
138186
139187
140188
......
155203
156204
157205
158
159
160
161
162
163
206
207
164208
165
209
166210
211
167212
168213
169214
......
173218
174219
175220
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
221
222
223
224
225
226
203227
204228
205229
......
259283
260284
261285
262
263
286
287
288
289
290
291
264292
265293
266294
......
279307
280308
281309
282
283
310
311
312
313
314
315
284316
285317
286318
......
290322
291323
292324
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
325
316326
317327
318328
......
325335
326336
327337
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354338
355339
#region Using Statements
using System;
using System.IO;
using System.Threading;
using System.Runtime.Remoting.Messaging;
#endregion
private PlayerIndex? devicePlayer;
private StorageContainer deviceContainer;
#endregion
#region Private Static Variables
#region Private Delegates
private delegate StorageDevice ShowSelectorAsynchronous(
PlayerIndex? player,
int sizeInBytes,
int directoryCount
);
private delegate StorageContainer OpenContainerAsynchronous(string displayName);
#endregion
#region Private XNA Lies
private class NotAsyncLie : IAsyncResult
{
public object AsyncState
{
get;
private set;
}
public bool CompletedSynchronously
{
get
{
return true;
}
}
public bool IsCompleted
{
get
{
return true;
}
}
public WaitHandle AsyncWaitHandle
{
get;
private set;
}
public NotAsyncLie(object state)
{
AsyncState = state;
AsyncWaitHandle = new ManualResetEvent(true);
}
}
private class ShowSelectorLie : NotAsyncLie
{
public readonly PlayerIndex? PlayerIndex;
public ShowSelectorLie(object state, PlayerIndex? playerIndex) : base(state)
{
PlayerIndex = playerIndex;
}
}
private class OpenContainerLie : NotAsyncLie
{
public readonly string DisplayName;
public OpenContainerLie(object state, string displayName) : base(state)
{
DisplayName = displayName;
}
}
#endregion
#region Internal Constructors
/// <summary>
/// Creates a new <see cref="StorageDevice"/> instance.
/// </summary>
/// <param name="player">The playerIndex of the player.</param>
/// <param name="sizeInBytes">Size of the storage device.</param>
/// <param name="directoryCount"></param>
internal StorageDevice(PlayerIndex? player, int sizeInBytes, int directoryCount)
internal StorageDevice(PlayerIndex? player)
{
devicePlayer = player;
}
AsyncCallback callback,
object state
) {
try
{
OpenContainerAsynchronous AsynchronousOpen = new OpenContainerAsynchronous(Open);
return AsynchronousOpen.BeginInvoke(displayName, callback, state);
}
finally
IAsyncResult result = new OpenContainerLie(state, displayName);
if (callback != null)
{
// TODO: No resources to clean up? Remove this finally block?
callback(result);
}
return result;
}
/// <summary>
/// <param name="result">Result of BeginOpenContainer.</param>
public StorageContainer EndOpenContainer(IAsyncResult result)
{
StorageContainer returnValue = null;
try
{
// Retrieve the delegate.
AsyncResult asyncResult = result as AsyncResult;
if (asyncResult != null)
{
OpenContainerAsynchronous asyncDelegate = asyncResult.AsyncDelegate
as OpenContainerAsynchronous;
// Wait for the WaitHandle to become signaled.
result.AsyncWaitHandle.WaitOne();
// Call EndInvoke to retrieve the results.
if (asyncDelegate != null)
{
returnValue = asyncDelegate.EndInvoke(result);
}
}
}
finally
{
// Close the wait handle.
result.AsyncWaitHandle.Dispose();
}
return returnValue;
return new StorageContainer(
this,
(result as OpenContainerLie).DisplayName,
storageRoot,
devicePlayer
);
}
#endregion
AsyncCallback callback,
object state
) {
ShowSelectorAsynchronous del = new ShowSelectorAsynchronous(Show);
return del.BeginInvoke(null, sizeInBytes, directoryCount, callback, state);
IAsyncResult result = new ShowSelectorLie(state, null);
if (callback != null)
{
callback(result);
}
return result;
}
/// <summary>
AsyncCallback callback,
object state
) {
ShowSelectorAsynchronous del = new ShowSelectorAsynchronous(Show);
return del.BeginInvoke(player, sizeInBytes, directoryCount, callback, state);
IAsyncResult result = new ShowSelectorLie(state, player);
if (callback != null)
{
callback(result);
}
return result;
}
/// <summary>
/// <param name="result">The result of BeginShowSelector.</param>
public static StorageDevice EndShowSelector(IAsyncResult result)
{
if (!result.IsCompleted)
{
// Wait for the WaitHandle to become signaled.
try
{
result.AsyncWaitHandle.WaitOne();
}
finally
{
}
}
// Retrieve the delegate.
AsyncResult asyncResult = (AsyncResult) result;
ShowSelectorAsynchronous del = asyncResult.AsyncDelegate as ShowSelectorAsynchronous;
if (del != null)
{
return del.EndInvoke(result);
}
throw new ArgumentException("result");
return new StorageDevice((result as ShowSelectorLie).PlayerIndex);
}
#endregion
}
#endregion
#region Private OpenContainer Async Method
// Private method to handle the creation of the StorageDevice.
private StorageContainer Open(string displayName)
{
deviceContainer = new StorageContainer(
this,
displayName,
storageRoot,
devicePlayer
);
return deviceContainer;
}
#endregion
#region Private ShowSelector Async Method
// Private method to handle the creation of the StorageDevice.
private static StorageDevice Show(PlayerIndex? player, int sizeInBytes, int directoryCount)
{
return new StorageDevice(player, sizeInBytes, directoryCount);
}
#endregion
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.42994s using 13 queries.