From 1aad371ece1dc43bae2e05c863465d2bb795e1ff Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Fri, 17 Sep 2010 01:43:00 +0000 Subject: [PATCH] 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 --- Nuclex.Support (xna-3.1-xbox360).csproj | 4 +- Nuclex.Support (xna-4.0-xbox360).csproj | 423 +++++++++++++++++++++ Source/Collections/ObservableDictionary.cs | 2 + Source/Collections/ReadOnlyDictionary.cs | 2 + Source/Plugins/PluginHost.cs | 10 +- Source/Plugins/PluginRepository.cs | 14 +- Source/Plugins/PrototypeFactory.cs | 4 + Source/Scheduling/AbortedException.cs | 2 + Source/Scheduling/GenericTimeSource.cs | 7 +- Source/Scheduling/Scheduler.cs | 12 +- Source/Scheduling/WindowsTimeSource.cs | 6 + Source/Semaphore.cs | 36 +- Source/StringSegment.cs | 2 + Source/Tracking/ProgressTracker.cs | 23 +- Source/Tracking/Transaction.cs | 6 + Source/WeakReference.cs | 2 + Source/XmlHelper.cs | 4 + 17 files changed, 533 insertions(+), 26 deletions(-) create mode 100644 Nuclex.Support (xna-4.0-xbox360).csproj diff --git a/Nuclex.Support (xna-3.1-xbox360).csproj b/Nuclex.Support (xna-3.1-xbox360).csproj index d343abe..9a94e18 100644 --- a/Nuclex.Support (xna-3.1-xbox360).csproj +++ b/Nuclex.Support (xna-3.1-xbox360).csproj @@ -18,7 +18,7 @@ full false bin\xna-3.1-xbox360\Debug\ - TRACE;DEBUG;XBOX;XBOX360;NO_SERIALIZATION + TRACE;DEBUG;XBOX;XBOX360;NO_SERIALIZATION;XNA_3 prompt 4 true @@ -30,7 +30,7 @@ pdbonly true bin\xna-3.1-xbox360\Release\ - TRACE;XBOX;XBOX360;NO_SERIALIZATION + TRACE;XBOX;XBOX360;NO_SERIALIZATION;XNA_3 prompt 4 true diff --git a/Nuclex.Support (xna-4.0-xbox360).csproj b/Nuclex.Support (xna-4.0-xbox360).csproj new file mode 100644 index 0000000..8c0952c --- /dev/null +++ b/Nuclex.Support (xna-4.0-xbox360).csproj @@ -0,0 +1,423 @@ + + + + {DCB169D9-417F-4FF1-848A-B00CF7C88B31} + {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Debug + Xbox 360 + Library + Properties + Nuclex.Support + Nuclex.Support + v4.0 + Client + v4.0 + Xbox 360 + HiDef + 228353e9-b10a-4191-b7a5-f7c152bfb818 + Library + + + true + full + false + bin\xna-4.0-xbox360\Debug\ + TRACE;DEBUG;XBOX;XBOX360;NO_CLONING;NO_SERIALIZATION;NO_XMLDOCUMENT + prompt + 4 + true + false + true + bin\xna-4.0-xbox360\Debug\Nuclex.Support.xml + + + pdbonly + true + bin\xna-4.0-xbox360\Release\ + TRACE;XBOX;XBOX360;NO_CLONING;NO_SERIALIZATION;NO_XMLDOCUMENT + prompt + 4 + true + false + true + bin\xna-4.0-xbox360\Release\Nuclex.Support.xml + + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + 4.0 + False + + + 4.0 + False + + + False + + + + + + AffineThreadPool.cs + + + + Deque.cs + + + Deque.cs + + + Deque.cs + + + Deque.cs + + + Deque.cs + + + + + + ItemEventArgs.cs + + + + ObservableCollection.cs + + + + ObservableDictionary.cs + + + + PairPriorityQueue.cs + + + + Parentable.cs + + + + ParentingCollection.cs + + + + Pool.cs + + + + PriorityItemPair.cs + + + + PriorityQueue.cs + + + + ReadOnlyCollection.cs + + + + ReadOnlyDictionary.cs + + + + ReadOnlyList.cs + + + + ReverseComparer.cs + + + + + EnumHelper.cs + + + + PrototypeFactory.cs + + + GenericTimeSource.cs + + + + + + + Scheduler.cs + + + Scheduler.cs + + + + WindowsTimeSource.cs + + + + Semaphore.cs + + + + AppDomainTypeLister.cs + + + + ExplicitTypeLister.cs + + + + + MultiAssemblyTypeLister.cs + + + + + + + + RepositoryTypeLister.cs + + + ServiceManager.cs + + + + ServiceManager.cs + + + + PartialStream.cs + + + + RingMemoryStream.cs + + + + TransformingReadOnlyCollection.cs + + + TransformingReadOnlyCollection.cs + + + + WeakCollection.cs + + + WeakCollection.cs + + + + FloatHelper.cs + + + + IntegerHelper.cs + + + + LicenseKey.cs + + + CommandLine.cs + + + CommandLine.cs + + + CommandLine.cs + + + + CommandLine.cs + + + + PathHelper.cs + + + + AssemblyLoadEventArgs.cs + + + + Employer.cs + + + FactoryEmployer.cs + + + + InstanceEmployer.cs + + + + + + + NoPluginAttribute.cs + + + + PluginHelper.cs + + + + PluginHost.cs + + + + PluginRepository.cs + + + + AbortedException.cs + + + + + Operation.cs + + + + OperationQueue.cs + + + + ThreadCallbackOperation.cs + + + + ThreadOperation.cs + + + ServiceManager.cs + + + + + Shared.cs + + + + ChainStream.cs + + + + StringBuilderHelper.cs + + + + StringHelper.cs + + + + StringSegment.cs + + + + IdleStateEventArgs.cs + + + + ObservedWeightedTransaction.cs + + + + WeightedTransactionWrapperCollection.cs + + + + + + ProgressReportEventArgs.cs + + + + ProgressTracker.cs + + + + Request.cs + + + StatusReportEventArgs.cs + + + Transaction.cs + + + + TransactionGroup.cs + + + + + + WeightedTransaction.cs + + + + WeakReference.cs + + + + XmlHelper.cs + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Collections/ObservableDictionary.cs b/Source/Collections/ObservableDictionary.cs index f7515f2..0bd86fe 100644 --- a/Source/Collections/ObservableDictionary.cs +++ b/Source/Collections/ObservableDictionary.cs @@ -29,7 +29,9 @@ namespace Nuclex.Support.Collections { /// A dictionary that sneds out change notifications /// Type of the keys used in the dictionary /// Type of the values used in the dictionary +#if !NO_SERIALIZATION [Serializable] +#endif public class ObservableDictionary : #if !NO_SERIALIZATION ISerializable, diff --git a/Source/Collections/ReadOnlyDictionary.cs b/Source/Collections/ReadOnlyDictionary.cs index f1e1dd6..4a84411 100644 --- a/Source/Collections/ReadOnlyDictionary.cs +++ b/Source/Collections/ReadOnlyDictionary.cs @@ -29,7 +29,9 @@ namespace Nuclex.Support.Collections { /// Wraps a dictionary and prevents users from modifying it /// Type of the keys used in the dictionary /// Type of the values used in the dictionary +#if !NO_SERIALIZATION [Serializable] +#endif public class ReadOnlyDictionary : #if !NO_SERIALIZATION ISerializable, diff --git a/Source/Plugins/PluginHost.cs b/Source/Plugins/PluginHost.cs index 2571f63..f9b3727 100644 --- a/Source/Plugins/PluginHost.cs +++ b/Source/Plugins/PluginHost.cs @@ -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; } + /// Reports an error to the debugging console + /// Error message that will be reported + private static void reportError(string error) { +#if !XBOX360 + Trace.WriteLine(error); +#endif + } + /// Employs and manages types in the loaded plugin assemblies private Employer employer; /// Repository containing all plugins loaded, shared with other hosts diff --git a/Source/Plugins/PluginRepository.cs b/Source/Plugins/PluginRepository.cs index dcbb68c..077efe8 100644 --- a/Source/Plugins/PluginRepository.cs +++ b/Source/Plugins/PluginRepository.cs @@ -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; } } + /// Reports an error to the debugging console + /// Error message that will be reported + private static void reportError(string error) { +#if !XBOX360 + Trace.WriteLine(error); +#endif + } + /// Loaded plugin assemblies private List assemblies; /// Takes care of loading assemblies for the repositories diff --git a/Source/Plugins/PrototypeFactory.cs b/Source/Plugins/PrototypeFactory.cs index d40dc8b..ce465c6 100644 --- a/Source/Plugins/PrototypeFactory.cs +++ b/Source/Plugins/PrototypeFactory.cs @@ -4,6 +4,8 @@ using System.Text; namespace Nuclex.Support.Plugins { +#if !NO_CLONING + /// Factory that creates instances by cloning a prototype /// Type of product created by the factory /// Type of the prototype that will be cloned @@ -51,4 +53,6 @@ namespace Nuclex.Support.Plugins { } +#endif // !NO_CLONING + } // namespace Nuclex.Support.Plugins diff --git a/Source/Scheduling/AbortedException.cs b/Source/Scheduling/AbortedException.cs index 6be35da..7e5f6ac 100644 --- a/Source/Scheduling/AbortedException.cs +++ b/Source/Scheduling/AbortedException.cs @@ -28,7 +28,9 @@ namespace Nuclex.Support.Scheduling { /// This exception is the typical result of using AsyncAbort() on a running /// background process. /// +#if !NO_SERIALIZATION [Serializable] +#endif public class AbortedException : Exception { /// Initializes the exception diff --git a/Source/Scheduling/GenericTimeSource.cs b/Source/Scheduling/GenericTimeSource.cs index cdea585..fbe27a9 100644 --- a/Source/Scheduling/GenericTimeSource.cs +++ b/Source/Scheduling/GenericTimeSource.cs @@ -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(); diff --git a/Source/Scheduling/Scheduler.cs b/Source/Scheduling/Scheduler.cs index caaeb41..57903c3 100644 --- a/Source/Scheduling/Scheduler.cs +++ b/Source/Scheduling/Scheduler.cs @@ -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) { diff --git a/Source/Scheduling/WindowsTimeSource.cs b/Source/Scheduling/WindowsTimeSource.cs index c696c92..96d8c4a 100644 --- a/Source/Scheduling/WindowsTimeSource.cs +++ b/Source/Scheduling/WindowsTimeSource.cs @@ -65,7 +65,13 @@ namespace Nuclex.Support.Scheduling { /// True if the WaitHandle was signalled, false if the timeout was reached /// 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 } /// diff --git a/Source/Semaphore.cs b/Source/Semaphore.cs index cbef9d2..6e3136d 100644 --- a/Source/Semaphore.cs +++ b/Source/Semaphore.cs @@ -97,7 +97,7 @@ namespace Nuclex.Support { /// 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. /// +#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 /// /// Waits for the resource to become available and locks it /// @@ -166,11 +177,16 @@ namespace Nuclex.Support { /// the timeout has been reached. /// 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) /// /// Waits for the resource to become available and locks it /// @@ -185,7 +201,11 @@ namespace Nuclex.Support { /// True if the resource was available and is now locked, false if /// the timeout has been reached. /// +#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) /// /// Releases a lock on the resource. Note that for a reverse counting semaphore, @@ -214,7 +238,7 @@ namespace Nuclex.Support { /// Creates the event used to make threads wait for the resource 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; diff --git a/Source/StringSegment.cs b/Source/StringSegment.cs index 56d9b76..7fbc869 100644 --- a/Source/StringSegment.cs +++ b/Source/StringSegment.cs @@ -39,7 +39,9 @@ namespace Nuclex.Support { /// in parsers, it can also prevent needless string copying and garbage generation. /// /// +#if !NO_SERIALIZATION [Serializable, StructLayout(LayoutKind.Sequential)] +#endif public struct StringSegment { /// diff --git a/Source/Tracking/ProgressTracker.cs b/Source/Tracking/ProgressTracker.cs index 00d0519..a0a49f3 100644 --- a/Source/Tracking/ProgressTracker.cs +++ b/Source/Tracking/ProgressTracker.cs @@ -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>( - 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 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; diff --git a/Source/Tracking/Transaction.cs b/Source/Tracking/Transaction.cs index 130b1e8..65d291f 100644 --- a/Source/Tracking/Transaction.cs +++ b/Source/Tracking/Transaction.cs @@ -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 } /// Whether the transaction has ended already diff --git a/Source/WeakReference.cs b/Source/WeakReference.cs index 9656766..a815313 100644 --- a/Source/WeakReference.cs +++ b/Source/WeakReference.cs @@ -28,7 +28,9 @@ namespace Nuclex.Support { /// Type-safe weak reference, referencing an object while still allowing /// that object to be garbage collected. /// +#if !NO_SERIALIZATION [Serializable] +#endif public class WeakReference : WeakReference where ReferencedType : class { diff --git a/Source/XmlHelper.cs b/Source/XmlHelper.cs index ffa4c51..64e83d6 100644 --- a/Source/XmlHelper.cs +++ b/Source/XmlHelper.cs @@ -30,6 +30,8 @@ namespace Nuclex.Support { /// Helper routines for handling XML code public static class XmlHelper { +#if !NO_XMLDOCUMENT + #region class ValidationEventProcessor /// Handles any events occurring when an XML schema is loaded @@ -207,6 +209,8 @@ namespace Nuclex.Support { return false; } +#endif // !NO_XMLDOCUMENT + } } // namespace Nuclex.Support