Added XNA 4.0 XBox 360 project; fixed compilation errors that would result from compiling Nuclex.Support on the XBox 360's special compact framework

git-svn-id: file:///srv/devel/repo-conversion/nusu@202 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2010-09-17 01:43:00 +00:00
parent 5f5b8b519b
commit 1aad371ece
17 changed files with 533 additions and 26 deletions

View file

@ -29,7 +29,9 @@ namespace Nuclex.Support.Collections {
/// <summary>A dictionary that sneds out change notifications</summary>
/// <typeparam name="KeyType">Type of the keys used in the dictionary</typeparam>
/// <typeparam name="ValueType">Type of the values used in the dictionary</typeparam>
#if !NO_SERIALIZATION
[Serializable]
#endif
public class ObservableDictionary<KeyType, ValueType> :
#if !NO_SERIALIZATION
ISerializable,

View file

@ -29,7 +29,9 @@ namespace Nuclex.Support.Collections {
/// <summary>Wraps a dictionary and prevents users from modifying it</summary>
/// <typeparam name="KeyType">Type of the keys used in the dictionary</typeparam>
/// <typeparam name="ValueType">Type of the values used in the dictionary</typeparam>
#if !NO_SERIALIZATION
[Serializable]
#endif
public class ReadOnlyDictionary<KeyType, ValueType> :
#if !NO_SERIALIZATION
ISerializable,

View file

@ -98,7 +98,7 @@ namespace Nuclex.Support.Plugins {
}
}
catch(Exception exception) {
Trace.WriteLine("Could not employ " + type.ToString() + ": " + exception.Message);
reportError("Could not employ " + type.ToString() + ": " + exception.Message);
}
}
@ -118,6 +118,14 @@ namespace Nuclex.Support.Plugins {
return false;
}
/// <summary>Reports an error to the debugging console</summary>
/// <param name="error">Error message that will be reported</param>
private static void reportError(string error) {
#if !XBOX360
Trace.WriteLine(error);
#endif
}
/// <summary>Employs and manages types in the loaded plugin assemblies</summary>
private Employer employer;
/// <summary>Repository containing all plugins loaded, shared with other hosts</summary>

View file

@ -78,7 +78,7 @@ namespace Nuclex.Support.Plugins {
// Unauthorized acccess - Either the assembly is not trusted because it contains
// code that imposes a security risk on the system or a user rights problem
catch(UnauthorizedAccessException) {
Trace.WriteLine(
reportError(
"Not authorized to load assembly '" + path + "', " +
"possible rights problem"
);
@ -86,14 +86,14 @@ namespace Nuclex.Support.Plugins {
// Bad image format - This exception is often thrown when the assembly we
// attempted to load requires a different version of the .NET framework
catch(BadImageFormatException) {
Trace.WriteLine(
reportError(
"'" + path + "' is not a .NET assembly, requires a different version " +
"of the .NET Runtime or does not support the current instruction set (x86/x64)"
);
}
// Unknown error - Our last resort is to show a default error message
catch(Exception exception) {
Trace.WriteLine(
reportError(
"Failed to load plugin assembly '" + path + "': " + exception.Message
);
}
@ -175,6 +175,14 @@ namespace Nuclex.Support.Plugins {
get { return this.assemblies; }
}
/// <summary>Reports an error to the debugging console</summary>
/// <param name="error">Error message that will be reported</param>
private static void reportError(string error) {
#if !XBOX360
Trace.WriteLine(error);
#endif
}
/// <summary>Loaded plugin assemblies</summary>
private List<Assembly> assemblies;
/// <summary>Takes care of loading assemblies for the repositories</summary>

View file

@ -4,6 +4,8 @@ using System.Text;
namespace Nuclex.Support.Plugins {
#if !NO_CLONING
/// <summary>Factory that creates instances by cloning a prototype</summary>
/// <typeparam name="ProductType">Type of product created by the factory</typeparam>
/// <typeparam name="ConcreteType">Type of the prototype that will be cloned</typeparam>
@ -51,4 +53,6 @@ namespace Nuclex.Support.Plugins {
}
#endif // !NO_CLONING
} // namespace Nuclex.Support.Plugins

View file

@ -28,7 +28,9 @@ namespace Nuclex.Support.Scheduling {
/// This exception is the typical result of using AsyncAbort() on a running
/// background process.
/// </remarks>
#if !NO_SERIALIZATION
[Serializable]
#endif
public class AbortedException : Exception {
/// <summary>Initializes the exception</summary>

View file

@ -92,8 +92,13 @@ namespace Nuclex.Support.Scheduling {
// Force a timeout at least each second so the caller can check the system time
// since we're not able to provide the DateTimeAdjusted notification
int milliseconds = (int)(ticks / TicksPerMillisecond);
#if XNA_3
bool signalled = waitHandle.WaitOne(Math.Min(1000, milliseconds), false);
#elif XBOX360
bool signalled = waitHandle.WaitOne(Math.Min(1000, milliseconds));
#else
bool signalled = waitHandle.WaitOne(Math.Min(1000, milliseconds), false);
#endif
// See whether the system date/time have been adjusted while we were asleep.
checkForTimeAdjustment();

View file

@ -128,7 +128,11 @@ namespace Nuclex.Support.Scheduling {
this.timerThread = new Thread(new ThreadStart(runTimerThread));
this.timerThread.Name = "Nuclex.Support.Scheduling.Scheduler";
#if XNA_3
this.timerThread.Priority = ThreadPriority.Highest;
#elif !XBOX360
this.timerThread.Priority = ThreadPriority.Highest;
#endif
this.timerThread.IsBackground = true;
this.timerThread.Start();
}
@ -142,10 +146,10 @@ namespace Nuclex.Support.Scheduling {
// Wait for the timer thread to exit. If it doesn't exit in 10 seconds (which is
// a lot of time given that it doesn't do any real work), forcefully abort
// the thread. This may risk some leaks, but it's the only thing we can do.
Trace.Assert(
this.timerThread.Join(2500), "Scheduler timer thread did not exit in time"
);
bool success = this.timerThread.Join(2500);
#if !XBOX360
Trace.Assert(success, "Scheduler timer thread did not exit in time");
#endif
// Unsubscribe from the time source to avoid surprise events during or
// after shutdown
if(this.timeSource != null) {

View file

@ -65,7 +65,13 @@ namespace Nuclex.Support.Scheduling {
/// True if the WaitHandle was signalled, false if the timeout was reached
/// </returns>
public override bool WaitOne(AutoResetEvent waitHandle, long ticks) {
#if XNA_3
return waitHandle.WaitOne((int)(ticks / TicksPerMillisecond), false);
#elif XBOX360
return waitHandle.WaitOne((int)(ticks / TicksPerMillisecond));
#else
return waitHandle.WaitOne((int)(ticks / TicksPerMillisecond), false);
#endif
}
/// <summary>

View file

@ -97,7 +97,7 @@ namespace Nuclex.Support {
/// </param>
protected override void Dispose(bool explicitDisposing) {
if(this.manualResetEvent != null) {
#if XBOX360
#if XBOX360 && XNA_3
base.Handle = IntPtr.Zero;
#else
base.SafeWaitHandle = null;
@ -124,7 +124,13 @@ namespace Nuclex.Support {
/// True if the resource was available and is now locked, false if
/// the timeout has been reached.
/// </returns>
#if XNA_3 // XNA 3.0 for XBox 360 had an exitContext parameter
public override bool WaitOne(int millisecondsTimeout, bool exitContext) {
#elif XBOX360 // XNA 4.0 for XBox 360 has no exitContext parameter
public override bool WaitOne(int millisecondsTimeout) {
#else
public override bool WaitOne(int millisecondsTimeout, bool exitContext) {
#endif
for(; ; ) {
// Lock the resource - even if it is full. We will correct out mistake later
@ -149,7 +155,13 @@ namespace Nuclex.Support {
// Unless we have been preempted by a Release(), we now have to wait for the
// resource to become available.
if(newFree >= 0) {
#if XNA_3 // XNA 3.0 for XBox 360 had an exitContext parameter
if(!this.manualResetEvent.WaitOne(millisecondsTimeout, exitContext)) {
#elif XBOX360 // XNA 4.0 for XBox 360 has no exitContext parameter
if (!this.manualResetEvent.WaitOne(millisecondsTimeout)) {
#else
if(!this.manualResetEvent.WaitOne(millisecondsTimeout, exitContext)) {
#endif
return false;
}
}
@ -157,7 +169,6 @@ namespace Nuclex.Support {
} // for(; ; )
}
#if XBOX360
/// <summary>
/// Waits for the resource to become available and locks it
/// </summary>
@ -166,11 +177,16 @@ namespace Nuclex.Support {
/// the timeout has been reached.
/// </returns>
public override bool WaitOne() {
#if XNA_3 // XNA 3.0 for XBox 360 had an exitContext parameter
return WaitOne(-1, false);
#elif XBOX360 // XNA 4.0 for XBox 360 has no exitContext parameter
return WaitOne(-1);
#else
return WaitOne(-1, false);
}
#endif
}
#if !XBOX360
#if !(XNA_3 && XBOX360)
/// <summary>
/// Waits for the resource to become available and locks it
/// </summary>
@ -185,7 +201,11 @@ namespace Nuclex.Support {
/// True if the resource was available and is now locked, false if
/// the timeout has been reached.
/// </returns>
#if XBOX360
public override bool WaitOne(TimeSpan timeout) {
#else
public override bool WaitOne(TimeSpan timeout, bool exitContext) {
#endif
long totalMilliseconds = (long)timeout.TotalMilliseconds;
if((totalMilliseconds < -1) || (totalMilliseconds > int.MaxValue)) {
throw new ArgumentOutOfRangeException(
@ -193,9 +213,13 @@ namespace Nuclex.Support {
);
}
#if XBOX360
return WaitOne((int)totalMilliseconds);
#else
return WaitOne((int)totalMilliseconds, exitContext);
}
#endif
}
#endif // !(XNA_3 && XBOX360)
/// <summary>
/// Releases a lock on the resource. Note that for a reverse counting semaphore,
@ -214,7 +238,7 @@ namespace Nuclex.Support {
/// <summary>Creates the event used to make threads wait for the resource</summary>
private void createEvent() {
this.manualResetEvent = new ManualResetEvent(false);
#if XBOX360
#if XBOX360 && XNA_3
base.Handle = this.manualResetEvent.Handle;
#else
base.SafeWaitHandle = this.manualResetEvent.SafeWaitHandle;

View file

@ -39,7 +39,9 @@ namespace Nuclex.Support {
/// in parsers, it can also prevent needless string copying and garbage generation.
/// </para>
/// </remarks>
#if !NO_SERIALIZATION
[Serializable, StructLayout(LayoutKind.Sequential)]
#endif
public struct StringSegment {
/// <summary>

View file

@ -196,21 +196,26 @@ namespace Nuclex.Support.Tracking {
lock(this.trackedTransactions) {
// Locate the object to be untracked in our collection
int removeIndex = this.trackedTransactions.FindIndex(
new Predicate<ObservedWeightedTransaction<Transaction>>(
new TransactionMatcher(transaction).Matches
)
);
if(removeIndex == -1) {
int index;
for(index = 0; index < this.trackedTransactions.Count; ++index) {
bool same = ReferenceEquals(
transaction,
this.trackedTransactions[index].WeightedTransaction.Transaction
);
if(same) {
break;
}
}
if(index == this.trackedTransactions.Count) {
throw new ArgumentException("Specified transaction is not being tracked");
}
// Remove and dispose the transaction the user wants to untrack
{
ObservedWeightedTransaction<Transaction> wrappedTransaction =
this.trackedTransactions[removeIndex];
this.trackedTransactions[index];
this.trackedTransactions.RemoveAt(removeIndex);
this.trackedTransactions.RemoveAt(index);
wrappedTransaction.Dispose();
}
@ -228,7 +233,7 @@ namespace Nuclex.Support.Tracking {
// weight would work, too, but we might accumulate rounding errors making the sum
// drift slowly away from the actual value.
float newTotalWeight = 0.0f;
for(int index = 0; index < this.trackedTransactions.Count; ++index)
for(index = 0; index < this.trackedTransactions.Count; ++index)
newTotalWeight += this.trackedTransactions[index].WeightedTransaction.Weight;
this.totalWeight = newTotalWeight;

View file

@ -164,7 +164,13 @@ namespace Nuclex.Support.Tracking {
return true;
}
#if XNA_3
return WaitHandle.WaitOne(timeoutMilliseconds, false);
#elif XBOX360
return WaitHandle.WaitOne(timeoutMilliseconds);
#else
return WaitHandle.WaitOne(timeoutMilliseconds, false);
#endif
}
/// <summary>Whether the transaction has ended already</summary>

View file

@ -28,7 +28,9 @@ namespace Nuclex.Support {
/// Type-safe weak reference, referencing an object while still allowing
/// that object to be garbage collected.
/// </summary>
#if !NO_SERIALIZATION
[Serializable]
#endif
public class WeakReference<ReferencedType> : WeakReference
where ReferencedType : class {

View file

@ -30,6 +30,8 @@ namespace Nuclex.Support {
/// <summary>Helper routines for handling XML code</summary>
public static class XmlHelper {
#if !NO_XMLDOCUMENT
#region class ValidationEventProcessor
/// <summary>Handles any events occurring when an XML schema is loaded</summary>
@ -207,6 +209,8 @@ namespace Nuclex.Support {
return false;
}
#endif // !NO_XMLDOCUMENT
}
} // namespace Nuclex.Support