[MonoDevelop] [Fwd: Re: patch for 4 minor files (gpl -> mit)]

Lluis Sanchez Gual lluis at novell.com
Thu Jun 5 11:12:06 EDT 2008


El dj 05 de 06 del 2008 a les 16:55 +0200, en/na Carlo Kok va escriure:
> Lluis Sanchez Gual wrote:
> > El dv 30 de 05 del 2008 a les 09:46 +0200, en/na Carlo Kok va escriure:
> >> Carlo Kok wrote:
> >>> Rewrote them from scratch while keeping the public/protected interface 
> >>> compatible.
> >> fixed spacing and layout according to the guidelines.
> >>
> >> * Dropped IService & all references to it replacing them with a base
> >> "AbstractService" class.
> > 
> > Please use just 'Service'. The 'Abstract' prefix does not convey any
> > useful information here.
> 
> Fixed.
> 
> > 
> > Also, InitializeService and UnloadService should be 'internal
> > protected', since they are not meant to be called by classes other than
> > the ServiceManager.
> 
> Hm. GuiService (.Core.Gui) seems to call them too for the platform 
> services, so internal/prot won't work.

PlatformService doesn't need to be a Service subclass, since it is not
created through the ServiceManager.

> 
> > 
> >> * dropped IDocumentationService
> > 
> > Why drop it? just remove the ISevice inheritance, which never should
> > have been there anyway.
> > 
> >> * created a new AbstractDocumentationService class that descends from
> >> AbstractService
> 
> Of course, undid that change.
> 
> >>
> >> * Fixed all references to IDocumentationService and replaced them with
> >> the AbstractDocumentationService
> >> * Dropped GuiSyncAbstractService as nothing was using it
> >> * Introduced a new static ServiceManager class
> > 
> > With the above changes, it looks good. Thanks!

I will commit after branching for 1.9. Thanks!

> > Lluis.
> 
> cool
> 
> attached again, without the internal protected change.
> 
> --
> Carlo Kok
> RemObjects Software
> fitxer adjunt document de text pla (patch04.txt)
> Index: main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/DesignerSupportService.cs
> ===================================================================
> --- main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/DesignerSupportService.cs	(revision 105032)
> +++ main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/DesignerSupportService.cs	(working copy)
> @@ -44,7 +44,7 @@
>  {
>  	
>  	
> -	public class DesignerSupportService : AbstractService
> +	public class DesignerSupportService : Service
>  	{
>  		PropertyPad propertyPad = null;
>  		ToolboxService toolboxService = null;
> Index: main/src/addins/NUnit/Services/NUnitService.cs
> ===================================================================
> --- main/src/addins/NUnit/Services/NUnitService.cs	(revision 105032)
> +++ main/src/addins/NUnit/Services/NUnitService.cs	(working copy)
> @@ -43,7 +43,7 @@
>  
>  namespace MonoDevelop.NUnit
>  {
> -	public class NUnitService : AbstractService
> +	public class NUnitService : Service
>  	{
>  		ArrayList providers = new ArrayList ();
>  		UnitTest[] rootTests;
> Index: main/src/core/MonoDevelop.Documentation/MonoDevelop.Documentation/DocumentationService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Documentation/MonoDevelop.Documentation/DocumentationService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Documentation/MonoDevelop.Documentation/DocumentationService.cs	(working copy)
> @@ -36,23 +36,20 @@
>  
>  namespace MonoDevelop.Documentation
>  {
> -	internal class DocumentationService : IDocumentationService
> +	internal class DocumentationService : Service, IDocumentationService
>  	{
>  
>  		RootTree helpTree;
>  
> -		public void InitializeService ()
> +		public override void InitializeService ()
>  		{
>  			helpTree = RootTree.LoadTree ();
>  		}
>  
> -		public void UnloadService()
> +		public override void UnloadService()
>  		{
>  		}
>  		
> -		public event EventHandler Initialize;
> -		public event EventHandler Unload;
> -		
>  		public RootTree HelpTree {
>  			get { return helpTree; }
>  		}
> Index: main/src/core/MonoDevelop.Projects/MonoDevelop.Projects.Ambience/AmbienceService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Projects/MonoDevelop.Projects.Ambience/AmbienceService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Projects/MonoDevelop.Projects.Ambience/AmbienceService.cs	(working copy)
> @@ -26,7 +26,7 @@
>  
>  namespace MonoDevelop.Projects.Ambience
>  {
> -	public class AmbienceService : AbstractService
> +	public class AmbienceService : Service
>  	{
>  		static readonly string ambienceProperty       = "SharpDevelop.UI.CurrentAmbience";
>  		static readonly string codeGenerationProperty = "SharpDevelop.UI.CodeGenerationOptions";
> Index: main/src/core/MonoDevelop.Projects/MonoDevelop.Projects.Documentation/IDocumentationService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Projects/MonoDevelop.Projects.Documentation/IDocumentationService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Projects/MonoDevelop.Projects.Documentation/IDocumentationService.cs	(working copy)
> @@ -25,7 +25,7 @@
>  
>  namespace MonoDevelop.Projects.Documentation
>  {
> -	public interface IDocumentationService : IService
> +	public interface IDocumentationService
>  	{
>  		XmlDocument GetHelpXml (string type);
>  		RootTree HelpTree { get; }
> Index: main/src/core/MonoDevelop.Core.Gui/MonoDevelop.Core.Gui/GuiSyncAbstractService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core.Gui/MonoDevelop.Core.Gui/GuiSyncAbstractService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core.Gui/MonoDevelop.Core.Gui/GuiSyncAbstractService.cs	(working copy)
> @@ -1,64 +0,0 @@
> -// GuiSyncAbstractService.cs
> -//
> -// Author:
> -//   Lluis Sanchez Gual <lluis at novell.com>
> -//
> -// Copyright (c) 2005 Novell, Inc (http://www.novell.com)
> -//
> -// Permission is hereby granted, free of charge, to any person obtaining a copy
> -// of this software and associated documentation files (the "Software"), to deal
> -// in the Software without restriction, including without limitation the rights
> -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> -// copies of the Software, and to permit persons to whom the Software is
> -// furnished to do so, subject to the following conditions:
> -//
> -// The above copyright notice and this permission notice shall be included in
> -// all copies or substantial portions of the Software.
> -//
> -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> -// THE SOFTWARE.
> -//
> -//
> -
> -using System;
> -using MonoDevelop.Core;
> -
> -namespace MonoDevelop.Core.Gui
> -{
> -	public class GuiSyncAbstractService : GuiSyncObject, IService
> -	{
> -		[FreeDispatch]
> -		public virtual void InitializeService()
> -		{
> -			OnInitialize(EventArgs.Empty);
> -		}
> -		
> -		
> -		public virtual void UnloadService()
> -		{
> -			OnUnload(EventArgs.Empty);
> -		}
> -		
> -		protected virtual void OnInitialize(EventArgs e)
> -		{
> -			if (Initialize != null) {
> -				Initialize(this, e);
> -			}
> -		}
> -		
> -		protected virtual void OnUnload(EventArgs e)
> -		{
> -			if (Unload != null) {
> -				Unload(this, e);
> -			}
> -		}
> -		
> -		public event EventHandler Initialize;
> -		public event EventHandler Unload;
> -	}
> -}
> Index: main/src/core/MonoDevelop.Core.Gui/MonoDevelop.Core.Gui/PlatformService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core.Gui/MonoDevelop.Core.Gui/PlatformService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core.Gui/MonoDevelop.Core.Gui/PlatformService.cs	(working copy)
> @@ -39,7 +39,7 @@
>  
>  namespace MonoDevelop.Core.Gui
>  {
> -	public abstract class PlatformService : AbstractService
> +	public abstract class PlatformService : Service
>  	{
>  		Gdk.Pixbuf defaultIcon;
>  		Hashtable iconHash = new Hashtable ();
> Index: main/src/core/MonoDevelop.Core.Gui/Makefile.am
> ===================================================================
> --- main/src/core/MonoDevelop.Core.Gui/Makefile.am	(revision 105032)
> +++ main/src/core/MonoDevelop.Core.Gui/Makefile.am	(working copy)
> @@ -59,7 +59,6 @@
>  	MonoDevelop.Core.Gui/FreeDispatchAttribute.cs \
>  	MonoDevelop.Core.Gui/GLibLogging.cs \
>  	MonoDevelop.Core.Gui/GuiService.cs \
> -	MonoDevelop.Core.Gui/GuiSyncAbstractService.cs \
>  	MonoDevelop.Core.Gui/GuiSyncContext.cs \
>  	MonoDevelop.Core.Gui/GuiSyncObject.cs \
>  	MonoDevelop.Core.Gui/IMementoCapable.cs \
> Index: main/src/core/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui/IconService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui/IconService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui/IconService.cs	(working copy)
> @@ -34,7 +34,7 @@
>  
>  namespace MonoDevelop.Projects.Gui
>  {
> -	public class IconService : AbstractService {
> +	public class IconService : Service {
>  		Hashtable extensionHashtable   = new Hashtable ();
>  		Hashtable projectFileHashtable = new Hashtable ();
>  		
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core.AddIns/ServiceExtensionNode.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core.AddIns/ServiceExtensionNode.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core.AddIns/ServiceExtensionNode.cs	(working copy)
> @@ -35,7 +35,7 @@
>  	{
>  		protected override void OnAddinLoaded ()
>  		{
> -			ServiceManager.AddService ((IService) base.CreateInstance ());
> +			ServiceManager.AddService ((Service) base.CreateInstance ());
>  		}
>  	}
>  }
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs	(working copy)
> @@ -44,7 +44,7 @@
>  
>  namespace MonoDevelop.Core.Execution
>  {
> -	public class ProcessService : AbstractService
> +	public class ProcessService : Service
>  	{
>  		ProcessHostController externalProcess;
>  		List<ExtensionNode> executionHandlers;
> Index: main/src/core/MonoDevelop.Core/Makefile.am
> ===================================================================
> --- main/src/core/MonoDevelop.Core/Makefile.am	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/Makefile.am	(working copy)
> @@ -47,7 +47,7 @@
>  	MonoDevelop.Core.ProgressMonitoring/NullProgressMonitor.cs \
>  	MonoDevelop.Core.ProgressMonitoring/ProgressTracker.cs \
>  	MonoDevelop.Core.ProgressMonitoring/SynchronizedProgressMonitor.cs \
> -	MonoDevelop.Core/AbstractService.cs \
> +	MonoDevelop.Core/Service.cs \
>  	MonoDevelop.Core/ClrVersion.cs \
>  	MonoDevelop.Core/DefaultAddinLocalizer.cs \
>  	MonoDevelop.Core/FileEventArgs.cs \
> @@ -56,7 +56,6 @@
>  	MonoDevelop.Core/IAsyncOperation.cs \
>  	MonoDevelop.Core/ICustomXmlSerializer.cs \
>  	MonoDevelop.Core/IProgressMonitor.cs \
> -	MonoDevelop.Core/IService.cs \
>  	MonoDevelop.Core/LoggingService.cs \
>  	MonoDevelop.Core/Properties.cs \
>  	MonoDevelop.Core/PropertyChangedEventArgs.cs \
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core/GettextCatalog.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/GettextCatalog.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core/GettextCatalog.cs	(working copy)
> @@ -1,88 +1,91 @@
> -/*
> - * Copyright (C) 2004 Jorn Baayen <jorn at nl.linux.org>
> - * 
> - * Modified by Todd Berman <tberman at sevenl.net> to fit with MonoDevelop.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of the
> - * License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> - * General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public
> - * License along with this program; if not, write to the
> - * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> - * Boston, MA 02111-1307, USA.
> - *
> - * !!! Note that this class has to have the same API as the one
> - *     from GNU.Gettext.dll, because otherwise the strings won't
> - *     be picked up by update-po.
> - */
> -
> -using System;
> -using System.IO;
> -using System.Runtime.InteropServices;
> -
> -using MonoDevelop.Core;
> -
> -using Mono.Unix;
> -
> -namespace MonoDevelop.Core
> -{
> -
> -	public class GettextCatalog
> -	{
> -		static GettextCatalog ()
> -		{
> -			//variable can be used to override where Gettext looks for the catalogues
> -			string catalog = System.Environment.GetEnvironmentVariable ("MONODEVELOP_LOCALE_PATH");
> -			
> -			if (string.IsNullOrEmpty (catalog)) {
> -				string location = System.Reflection.Assembly.GetExecutingAssembly ().Location;
> -				location = Path.GetDirectoryName (location);
> -				// MD is located at $prefix/lib/monodevelop/bin
> -				// adding "../../.." should give us $prefix
> -				string prefix = Path.Combine (Path.Combine (Path.Combine (location, ".."), ".."), "..");
> -				//normalise it
> -				prefix = Path.GetFullPath (prefix);
> -				//catalogue is installed to "$prefix/share/locale" by default
> -				catalog = Path.Combine (Path.Combine (prefix, "share"), "locale");
> -			}
> -			Catalog.Init ("monodevelop", catalog);
> -		}
> -	
> -		private GettextCatalog ()
> -		{
> -		}
> -
> -		public static string GetString (string str)
> -		{
> -			return str != null ? Catalog.GetString (str) : null;
> -		}
> -	
> -		public static string GetString (string str, params object[] arguments)
> -		{
> -			return string.Format (GetString (str), arguments);
> -		}
> -	
> -		public static string GetPluralString (string singular,
> -			    	 	              string plural,
> -					              int n)
> -		{
> -			return Catalog.GetPluralString (singular, plural, n);
> -		}
> -
> -		public static string GetPluralString (string singular,
> -			    	 	              string plural,
> -					              int n,
> -						      params object[] arguments)
> -		{
> -			return string.Format(GetPluralString (singular, plural, n), arguments);
> -		}
> -
> -	}
> -}
> +//
> +// GettextCatalog.cs
> +//
> +// Author:
> +//   Michael Hutchinson <m.j.hutchinson at gmail.com>
> +//   Carlo Kok <ck at carlo-kok.com>
> +//
> +// Copyright (C) 2008
> +//
> +// Permission is hereby granted, free of charge, to any person obtaining
> +// a copy of this software and associated documentation files (the
> +// "Software"), to deal in the Software without restriction, including
> +// without limitation the rights to use, copy, modify, merge, publish,
> +// distribute, sublicense, and/or sell copies of the Software, and to
> +// permit persons to whom the Software is furnished to do so, subject to
> +// the following conditions:
> +// 
> +// The above copyright notice and this permission notice shall be
> +// included in all copies or substantial portions of the Software.
> +// 
> +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> +//
> +using System;
> +using System.IO;
> +using Mono.Unix;
> +
> +namespace MonoDevelop.Core
> +{
> +	public static class GettextCatalog
> +	{
> +        
> +		// function by mhutch from the original source
> +               static GettextCatalog ()
> +               {
> +                       //variable can be used to override where Gettext looks for the catalogues
> +                       string catalog = System.Environment.GetEnvironmentVariable ("MONODEVELOP_LOCALE_PATH");
> +
> +                       if (string.IsNullOrEmpty (catalog)) {
> +                               string location = System.Reflection.Assembly.GetExecutingAssembly ().Location;
> +                               location = Path.GetDirectoryName (location);
> +                               // MD is located at $prefix/lib/monodevelop/bin
> +                               // adding "../../.." should give us $prefix
> +                               string prefix = Path.Combine (Path.Combine (Path.Combine (location, ".."), ".."), "..");
> +                               //normalise it
> +                               prefix = Path.GetFullPath (prefix);
> +                               //catalogue is installed to "$prefix/share/locale" by default
> +                               catalog = Path.Combine (Path.Combine (prefix, "share"), "locale");
> +                       }
> +                       Catalog.Init ("monodevelop", catalog);
> +               }
> +
> +		public static string GetString (string s, params object[] args)
> +		{
> +			string val = GetString (s);
> +			
> +			if (val == null) 
> +				return null;
> +
> +			return String.Format (val, args);
> +		}
> +
> +		public static string GetString(string s)
> +		{
> +			if (s == null) 
> +				return null;
> +
> +			return Catalog.GetString (s);
> +		}
> +
> +		public static string GetPluralString (string singular, string plural, int n, params object[] args)
> +		{
> +			string val = GetPluralString (singular, plural, n);
> +
> +			if (val == null)
> +				return null;
> +
> +			return String.Format (val, args);
> +		}
> +
> +		public static string GetPluralString (string singular, string plural, int n)
> +		{
> +			return Catalog.GetPluralString (singular, plural, n); 
> +		}
> +	}
> +}
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core/AbstractService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/AbstractService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core/AbstractService.cs	(working copy)
> @@ -1,58 +0,0 @@
> -//  AbstractService.cs
> -//
> -//  This file was derived from a file from #Develop. 
> -//
> -//  Copyright (C) 2001-2007 Mike Krüger <mkrueger at novell.com>
> -// 
> -//  This program is free software; you can redistribute it and/or modify
> -//  it under the terms of the GNU General Public License as published by
> -//  the Free Software Foundation; either version 2 of the License, or
> -//  (at your option) any later version.
> -// 
> -//  This program is distributed in the hope that it will be useful,
> -//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> -//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -//  GNU General Public License for more details.
> -//  
> -//  You should have received a copy of the GNU General Public License
> -//  along with this program; if not, write to the Free Software
> -//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> -
> -using System;
> -
> -using Mono.Addins;
> -using MonoDevelop.Core;
> -
> -namespace MonoDevelop.Core
> -{
> -	public class AbstractService : IService
> -	{
> -		public virtual void InitializeService()
> -		{
> -			OnInitialize(EventArgs.Empty);
> -		}
> -		
> -		
> -		public virtual void UnloadService()
> -		{
> -			OnUnload(EventArgs.Empty);
> -		}
> -		
> -		protected virtual void OnInitialize(EventArgs e)
> -		{
> -			if (Initialize != null) {
> -				Initialize(this, e);
> -			}
> -		}
> -		
> -		protected virtual void OnUnload(EventArgs e)
> -		{
> -			if (Unload != null) {
> -				Unload(this, e);
> -			}
> -		}
> -		
> -		public event EventHandler Initialize;
> -		public event EventHandler Unload;
> -	}
> -}
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core/ServiceManager.cs	(working copy)
> @@ -1,132 +1,104 @@
> -//  ServiceManager.cs
> -//
> -//  This file was derived from a file from #Develop. 
> -//
> -//  Copyright (C) 2001-2007 Mike Krüger <mkrueger at novell.com>
> -// 
> -//  This program is free software; you can redistribute it and/or modify
> -//  it under the terms of the GNU General Public License as published by
> -//  the Free Software Foundation; either version 2 of the License, or
> -//  (at your option) any later version.
> -// 
> -//  This program is distributed in the hope that it will be useful,
> -//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> -//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -//  GNU General Public License for more details.
> -//  
> -//  You should have received a copy of the GNU General Public License
> -//  along with this program; if not, write to the Free Software
> -//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> -
> -using System;
> -using System.Collections.Generic;
> -
> -using Mono.Addins;
> -using MonoDevelop.Core;
> -
> -namespace MonoDevelop.Core
> -{
> -	/// <summary>
> -	/// This class does basic service handling for you.
> -	/// </summary>
> -	public class ServiceManager
> -	{
> -		List<IService>             serviceList         = new List<IService> ();
> -		Dictionary<Type, IService> servicesHashtable   = new Dictionary<Type, IService> ();
> -		List<IService>             initializedServices = new List<IService> ();
> -		
> -		static ServiceManager defaultServiceManager = new ServiceManager ();
> -
> -		protected ServiceManager ()
> -		{
> -		}
> -		
> -		public static void Initialize ()
> -		{
> -			// Ensure service extension nodes are created
> -			AddinManager.GetExtensionNodes ("/MonoDevelop/Core/Services");
> -		}
> -		
> -		public static IService GetService (Type serviceType) {
> -			return defaultServiceManager.FetchService (serviceType);
> -		}
> -			
> -
> -		public IService this [Type index] {
> -			get {
> -				return FetchService (index);
> -			}
> -		}		
> -		
> -		/// <summary>
> -		/// Don't create ServiceManager objects, only have ONE per application.
> -		/// </summary>
> -		static ServiceManager()
> -		{
> -		}
> -		
> -		/// <remarks>
> -		/// Calls UnloadService on all services. This method must be called ONCE.
> -		/// </remarks>
> -		public static void UnloadAllServices()
> -		{
> -			foreach (IService service in defaultServiceManager.serviceList) 
> -				service.UnloadService();
> -		}
> -		
> -		public static void AddService(IService service)
> -		{
> -			defaultServiceManager.serviceList.Add(service);
> -		}
> -		
> -		public static void AddServices(IService[] services)
> -		{
> -			foreach (IService service in services) 
> -				AddService(service);
> -		}
> -
> -		// HACK: MONO BUGFIX
> -		// this doesn't work on mono:serviceType.IsInstanceOfType(service)
> -		bool IsInstanceOfType(Type type, IService service)
> -		{
> -			Type serviceType = service.GetType();
> -
> -			foreach (Type iface in serviceType.GetInterfaces()) {
> -				if (iface == type) {
> -					return true;
> -				}
> -			}
> -			
> -			while (serviceType != typeof(System.Object)) {
> -				if (type == serviceType) {
> -					return true;
> -				}
> -				serviceType = serviceType.BaseType;
> -			}
> -			return false;
> -		}
> -		
> -		/// <remarks>
> -		/// Requestes a specific service, may return null if this service is not found.
> -		/// </remarks>
> -		IService FetchService(Type serviceType)
> -		{
> -			if (servicesHashtable.ContainsKey (serviceType)) 
> -				return servicesHashtable[serviceType];
> -			
> -			foreach (IService service in serviceList) {
> -				if (IsInstanceOfType(serviceType, service)) {
> -					servicesHashtable[serviceType] = service;
> -					if (!initializedServices.Contains (service)) {
> -						LoggingService.LogInfo (GettextCatalog.GetString ("Initializing service: ") + serviceType);
> -						service.InitializeService();
> -						initializedServices.Add (service);
> -					}
> -					return service;
> -				}
> -			}
> -			
> -			return null;
> -		}
> -	}
> -}
> +//
> +// ServiceManager.cs
> +//
> +// Author:
> +//   Carlo Kok <ck at carlo-kok.com>
> +//
> +// Copyright (C) 2008
> +//
> +// Permission is hereby granted, free of charge, to any person obtaining
> +// a copy of this software and associated documentation files (the
> +// "Software"), to deal in the Software without restriction, including
> +// without limitation the rights to use, copy, modify, merge, publish,
> +// distribute, sublicense, and/or sell copies of the Software, and to
> +// permit persons to whom the Software is furnished to do so, subject to
> +// the following conditions:
> +// 
> +// The above copyright notice and this permission notice shall be
> +// included in all copies or substantial portions of the Software.
> +// 
> +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> +//
> +
> +using System;
> +using System.Collections.Generic;
> +using Mono.Addins;
> +
> +namespace MonoDevelop.Core
> +{
> +	public sealed class ServiceManager {
> +
> +		static Dictionary<Type, Service> servicecache = new Dictionary<Type, Service> ();
> +		static List<Service> allservices = new List<Service> ();
> +		static List<Service> initializedservices = new List<Service> ();
> +
> +		ServiceManager ()
> +		{
> +		} 
> +
> +		public static void Initialize ()
> +		{
> +			AddinManager.GetExtensionNodes ("/MonoDevelop/Core/Services");
> +		}
> +	
> +		public static void AddService (Service service)
> +		{
> +			if (service != null)
> +				allservices.Add (service);
> +		}
> +        
> +		public static void AddServices (params Service[] services)
> +		{
> +			if (services == null) 
> +				return;
> +
> +			for (int i = 0; i < services.Length; i++)
> +			{
> +				if (services[i] != null)
> +					allservices.Add (services [i]);
> +			}
> +		}
> +        
> +		public static Service GetService (Type type)
> +		{
> +			if (type == null) 
> +				return null;
> +
> +			Service res;
> +			if (servicecache.TryGetValue (type, out res)) 
> +				return res;
> +
> +			for (int i = 0; i < allservices.Count; i++)
> +			{
> +				res = allservices[i];
> +				if (type.IsInstanceOfType (res))
> +				{
> +					servicecache.Add (type, res);
> +					if (!initializedservices.Contains (res))
> +					{
> +						LoggingService.LogInfo (GettextCatalog.GetString ("Initializing service: ") + type);
> +						initializedservices.Add	(res);
> +						res.InitializeService ();
> +					}
> +					return res;
> +				}
> +			}
> +			return null;
> +		}
> +
> +		public static void UnloadAllServices ()
> +		{
> +			for (int i = 0; i < initializedservices.Count; i++)
> +				initializedservices[i].UnloadService();
> +
> +			initializedservices.Clear();
> +			servicecache.Clear();
> +		}
> +	}
> +}
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core/Service.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/Service.cs	(revision 104437)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core/Service.cs	(working copy)
> @@ -1,58 +1,47 @@
> -//  AbstractService.cs
> -//
> -//  This file was derived from a file from #Develop. 
> -//
> -//  Copyright (C) 2001-2007 Mike Krüger <mkrueger at novell.com>
> -// 
> -//  This program is free software; you can redistribute it and/or modify
> -//  it under the terms of the GNU General Public License as published by
> -//  the Free Software Foundation; either version 2 of the License, or
> -//  (at your option) any later version.
> -// 
> -//  This program is distributed in the hope that it will be useful,
> -//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> -//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -//  GNU General Public License for more details.
> -//  
> -//  You should have received a copy of the GNU General Public License
> -//  along with this program; if not, write to the Free Software
> -//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> -
> -using System;
> -
> -using Mono.Addins;
> -using MonoDevelop.Core;
> -
> -namespace MonoDevelop.Core
> -{
> -	public class AbstractService : IService
> -	{
> -		public virtual void InitializeService()
> -		{
> -			OnInitialize(EventArgs.Empty);
> -		}
> -		
> -		
> -		public virtual void UnloadService()
> -		{
> -			OnUnload(EventArgs.Empty);
> -		}
> -		
> -		protected virtual void OnInitialize(EventArgs e)
> -		{
> -			if (Initialize != null) {
> -				Initialize(this, e);
> -			}
> -		}
> -		
> -		protected virtual void OnUnload(EventArgs e)
> -		{
> -			if (Unload != null) {
> -				Unload(this, e);
> -			}
> -		}
> -		
> -		public event EventHandler Initialize;
> -		public event EventHandler Unload;
> -	}
> -}
> +//
> +// Service.cs
> +//
> +// Author:
> +//   Carlo Kok <ck at carlo-kok.com>
> +//
> +// Copyright (C) 2008
> +//
> +// Permission is hereby granted, free of charge, to any person obtaining
> +// a copy of this software and associated documentation files (the
> +// "Software"), to deal in the Software without restriction, including
> +// without limitation the rights to use, copy, modify, merge, publish,
> +// distribute, sublicense, and/or sell copies of the Software, and to
> +// permit persons to whom the Software is furnished to do so, subject to
> +// the following conditions:
> +// 
> +// The above copyright notice and this permission notice shall be
> +// included in all copies or substantial portions of the Software.
> +// 
> +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> +//
> +
> +using System;
> +
> +namespace MonoDevelop.Core
> +{
> +	// base class for all services
> +	public class Service
> +	{
> +	
> +		// called when the service is first used; called by ServiceManager
> +		public virtual void InitializeService ()
> +		{
> +		}
> +
> +		// called when the service manager unloads the service
> +		public virtual void UnloadService ()
> +		{
> +		}
> +	}
> +}
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core/SystemAssemblyService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/SystemAssemblyService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core/SystemAssemblyService.cs	(working copy)
> @@ -41,7 +41,7 @@
>  
>  namespace MonoDevelop.Core
>  {
> -	public class SystemAssemblyService : AbstractService
> +	public class SystemAssemblyService : Service
>  	{
>  		Dictionary<string, SystemPackage> assemblyPathToPackage = new Dictionary<string, SystemPackage> ();
>  		Dictionary<string, string> assemblyFullNameToPath = new Dictionary<string, string> ();
> Index: main/src/core/MonoDevelop.Core/MonoDevelop.Core/IService.cs
> ===================================================================
> --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/IService.cs	(revision 105032)
> +++ main/src/core/MonoDevelop.Core/MonoDevelop.Core/IService.cs	(working copy)
> @@ -1,46 +0,0 @@
> -//  IService.cs
> -//
> -//  This file was derived from a file from #Develop. 
> -//
> -//  Copyright (C) 2001-2007 Mike Krüger <mkrueger at novell.com>
> -// 
> -//  This program is free software; you can redistribute it and/or modify
> -//  it under the terms of the GNU General Public License as published by
> -//  the Free Software Foundation; either version 2 of the License, or
> -//  (at your option) any later version.
> -// 
> -//  This program is distributed in the hope that it will be useful,
> -//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> -//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -//  GNU General Public License for more details.
> -//  
> -//  You should have received a copy of the GNU General Public License
> -//  along with this program; if not, write to the Free Software
> -//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> -
> -using System;
> -
> -using Mono.Addins;
> -using MonoDevelop.Core;
> -
> -namespace MonoDevelop.Core
> -{
> -	/// <summary>
> -	/// This interface must be implemented by all services.
> -	/// </summary>
> -	public interface IService
> -	{
> -		/// <summary>
> -		/// This method is called after the services are loaded.
> -		/// </summary>
> -		void InitializeService();
> -		
> -		/// <summary>
> -		/// This method is called before the service is unloaded.
> -		/// </summary>
> -		void UnloadService();
> -		
> -		event EventHandler Initialize;
> -		event EventHandler Unload;
> -	}
> -}



More information about the Monodevelop-list mailing list