diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-22 21:56:37 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-22 21:56:37 +0300 |
commit | a4443477006772ca7399e6beb25540c09a0fb1c6 (patch) | |
tree | 82b92629d833c78aca61e8b76a2ba34a96f50522 | |
parent | 3e56bf63d1a883513ac1add2ef1c819d363d8327 (diff) |
[Core] Added new WorkspaceObjectReader class
WorkspaceObjectReader replaces ProjectServiceExtension as extension proint
for providing custom project and solution loaders.
8 files changed, 141 insertions, 241 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml index 14f7acfa0c..bf74bb84c8 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.addin.xml @@ -84,10 +84,10 @@ </ExtensionNode> </ExtensionPoint> - <ExtensionPoint path = "/MonoDevelop/ProjectModel/ProjectServiceExtensions" name = "Project service extensions"> - <Description>Project service extensions. Specified classes must be a subclass of ProjectServiceExtension</Description> + <ExtensionPoint path = "/MonoDevelop/ProjectModel/WorkspaceObjectReaders" name = "Project service extensions"> + <Description>WorkspaceObject readers. Specified classes must be a subclass of WorkspaceObjectReader</Description> <ExtensionNode name="Class"> - <Description>A subclass of ProjectServiceExtension.</Description> + <Description>A subclass of WorkspaceObjectReader.</Description> </ExtensionNode> </ExtensionPoint> @@ -202,13 +202,13 @@ <Application id = "project-export" class = "MonoDevelop.Projects.ProjectConvertTool" description = "Project conversion tool"/> </Extension> - <Extension path = "/MonoDevelop/ProjectModel/ProjectServiceExtensions"> - <Class id="InitialStep" class = "MonoDevelop.Projects.ProjectServiceExtension" /> - <Class class = "MonoDevelop.Projects.CompiledAssemblyExtension" /> - <Class class = "MonoDevelop.Projects.WorkspaceSerializationExtension" /> - <Class class = "MonoDevelop.Projects.MSBuildSerializationExtension" /> - <Class id="MidStep" class = "MonoDevelop.Projects.ProjectServiceExtension" /> - <Class id="FinalStep" class = "MonoDevelop.Projects.ProjectServiceExtension" /> + <Extension path = "/MonoDevelop/ProjectModel/WorkspaceObjectReaders"> + <Class id="InitialStep" class = "MonoDevelop.Projects.DummyWorkspaceObjectReader" /> + <Class id="CompiledAssembly" class = "MonoDevelop.Projects.CompiledAssemblyExtension" /> + <Class id="Workspace" class = "MonoDevelop.Projects.WorkspaceSerializationExtension" /> + <Class id="MSBuild" class = "MonoDevelop.Projects.MSBuildSerializationExtension" /> + <Class id="MidStep" class = "MonoDevelop.Projects.DummyWorkspaceObjectReader" /> + <Class id="FinalStep" class = "MonoDevelop.Projects.DummyWorkspaceObjectReader" /> </Extension> <Extension path = "/MonoDevelop/Core/FileSystemExtensions"> diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.csproj b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.csproj index 2802a7a5cb..80bb13fa04 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.csproj +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.csproj @@ -113,9 +113,6 @@ <Reference Include="System.ServiceModel" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.Build.Engine" /> - <Reference Include="System.Collections.Immutable"> - <HintPath>..\..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> - </Reference> <Reference Include="Microsoft.Build" /> </ItemGroup> <ItemGroup> @@ -274,7 +271,6 @@ <Compile Include="MonoDevelop.Projects\ExecutionContext.cs" /> <Compile Include="MonoDevelop.Projects\BuildTool.cs" /> <Compile Include="MonoDevelop.Projects\BuildEventHandler.cs" /> - <Compile Include="MonoDevelop.Projects\ProjectServiceExtension.cs" /> <Compile Include="MonoDevelop.Projects\CustomCommandCollection.cs" /> <Compile Include="MonoDevelop.Projects\CustomCommand.cs" /> <Compile Include="MonoDevelop.Projects\CustomCommandType.cs" /> @@ -523,6 +519,7 @@ <Compile Include="MonoDevelop.Projects.Formats.MSBuild\DefaultMSBuildEngine.cs" /> <Compile Include="MonoDevelop.Projects\SolutionDataSectionAttribute.cs" /> <Compile Include="MonoDevelop.Core.Serialization\DataDeletedValue.cs" /> + <Compile Include="MonoDevelop.Projects\WorkspaceObjectReader.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/CompiledAssemblyProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/CompiledAssemblyProject.cs index a74c61e9a0..4809bf5bb5 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/CompiledAssemblyProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/CompiledAssemblyProject.cs @@ -204,25 +204,20 @@ namespace MonoDevelop.Projects } } - public class CompiledAssemblyExtension: ProjectServiceExtension + public class CompiledAssemblyExtension: WorkspaceObjectReader { - public override bool FileIsObjectOfType (string fileName, Type type) + public override bool CanRead (FilePath file, Type expectedType) { - if ((type.IsAssignableFrom (typeof(SolutionItem))|| type.IsAssignableFrom (typeof(Solution))) && (fileName.ToLower().EndsWith (".exe") || fileName.ToLower().EndsWith (".dll"))) - return true; - return base.FileIsObjectOfType (fileName, type); + return (expectedType.IsAssignableFrom (typeof(SolutionItem)) || expectedType.IsAssignableFrom (typeof(Solution))) && (file.Extension.ToLower() == ".exe" || file.Extension.ToLower() == ".dll"); } public override Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) { - if (fileName.ToLower().EndsWith (".exe") || fileName.ToLower().EndsWith (".dll")) { - return Task<SolutionItem>.Factory.StartNew (delegate { - CompiledAssemblyProject p = new CompiledAssemblyProject (); - p.LoadFrom (fileName); - return p; - }); - } - return base.LoadSolutionItem (monitor, ctx, fileName, expectedFormat, typeGuid, itemGuid); + return Task<SolutionItem>.Factory.StartNew (delegate { + CompiledAssemblyProject p = new CompiledAssemblyProject (); + p.LoadFrom (fileName); + return p; + }); } } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/MSBuildSerializationExtension.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/MSBuildSerializationExtension.cs index 9afec767d9..d6f22edcc4 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/MSBuildSerializationExtension.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/MSBuildSerializationExtension.cs @@ -30,15 +30,15 @@ using System.Threading.Tasks; namespace MonoDevelop.Projects { - class MSBuildSerializationExtension: ProjectServiceExtension + class MSBuildSerializationExtension: WorkspaceObjectReader { - public override bool FileIsObjectOfType (string file, Type type) + public override bool CanRead (FilePath file, Type expectedType) { foreach (var f in MSBuildFileFormat.GetSupportedFormats ()) { - if (f.CanReadFile (file, type)) + if (f.CanReadFile (file, expectedType)) return true; } - return base.FileIsObjectOfType (file, type); + return false; } public override async Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) @@ -47,7 +47,7 @@ namespace MonoDevelop.Projects if (f.CanReadFile (fileName, typeof(SolutionItem))) return await MSBuildProjectService.LoadItem (monitor, fileName, f, typeGuid, itemGuid, ctx); } - return await base.LoadSolutionItem (monitor, ctx, fileName, expectedFormat, typeGuid, itemGuid); + throw new NotSupportedException (); } public override async Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) @@ -56,7 +56,7 @@ namespace MonoDevelop.Projects if (f.CanReadFile (fileName, typeof(WorkspaceItem))) return (WorkspaceItem) await f.ReadFile (fileName, typeof(WorkspaceItem), monitor); } - return await base.LoadWorkspaceItem (monitor, fileName); + throw new NotSupportedException (); } } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs index 12ce44ff8c..0928b90361 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs @@ -50,9 +50,8 @@ namespace MonoDevelop.Projects public class ProjectService { DataContext dataContext = new DataContext (); - ProjectServiceExtension defaultExtensionChain; - DefaultProjectServiceExtension extensionChainTerminator = new DefaultProjectServiceExtension (); - + WorkspaceObjectReader defaultExtensionChain; + TargetFramework defaultTargetFramework; string defaultPlatformTarget = "x86"; @@ -63,6 +62,7 @@ namespace MonoDevelop.Projects const string SerializableClassesExtensionPath = "/MonoDevelop/ProjectModel/SerializableClasses"; const string ProjectBindingsExtensionPath = "/MonoDevelop/ProjectModel/ProjectBindings"; + const string WorkspaceObjectReadersPath = "/MonoDevelop/ProjectModel/WorkspaceObjectReaders"; internal const string ProjectModelExtensionsPath = "/MonoDevelop/ProjectModel/ProjectModelExtensions"; @@ -78,27 +78,19 @@ namespace MonoDevelop.Projects get { return dataContext; } } - internal ProjectServiceExtension GetExtensionChain () + IEnumerable<WorkspaceObjectReader> GetObjectReaders () { - if (defaultExtensionChain == null) { - ProjectServiceExtension[] extensions = AddinManager.GetExtensionObjects<ProjectServiceExtension> ("/MonoDevelop/ProjectModel/ProjectServiceExtensions"); - defaultExtensionChain = CreateExtensionChain (extensions); - } - return defaultExtensionChain; + return AddinManager.GetExtensionObjects<WorkspaceObjectReader> (WorkspaceObjectReadersPath); } - - ProjectServiceExtension CreateExtensionChain (ProjectServiceExtension[] extensions) + + WorkspaceObjectReader GetObjectReaderForFile (FilePath file, Type type) { - if (extensions.Length > 0) { - for (int n=0; n<extensions.Length - 1; n++) - extensions [n].Next = extensions [n + 1]; - extensions [extensions.Length - 1].Next = extensionChainTerminator; - return extensions [0]; - } else { - return extensionChainTerminator; - } + foreach (var r in GetObjectReaders ()) + if (r.CanRead (file, type)) + return r; + return null; } - + public string DefaultPlatformTarget { get { return defaultPlatformTarget; } set { defaultPlatformTarget = value; } @@ -129,7 +121,10 @@ namespace MonoDevelop.Projects file = Path.GetFullPath (file); using (Counters.ReadSolutionItem.BeginTiming ("Read project " + file)) { file = GetTargetFile (file); - SolutionItem loadedItem = await GetExtensionChain ().LoadSolutionItem (monitor, ctx, file, format, typeGuid, itemGuid); + var r = GetObjectReaderForFile (file, typeof(SolutionItem)); + if (r == null) + throw new UnknownSolutionItemTypeException (); + SolutionItem loadedItem = await r.LoadSolutionItem (monitor, ctx, file, format, typeGuid, itemGuid); if (loadedItem != null) loadedItem.NeedsReload = false; return loadedItem; @@ -182,7 +177,10 @@ namespace MonoDevelop.Projects string fullpath = file.ResolveLinks ().FullPath; using (Counters.ReadWorkspaceItem.BeginTiming ("Read solution " + file)) { fullpath = GetTargetFile (fullpath); - WorkspaceItem item = await GetExtensionChain ().LoadWorkspaceItem (monitor, fullpath) as WorkspaceItem; + var r = GetObjectReaderForFile (file, typeof(WorkspaceItem)); + if (r == null) + throw new InvalidOperationException ("Invalid file format: " + file); + WorkspaceItem item = await r.LoadWorkspaceItem (monitor, fullpath); if (item != null) item.NeedsReload = false; else @@ -381,19 +379,17 @@ namespace MonoDevelop.Projects public bool FileIsObjectOfType (FilePath file, Type type) { var filename = GetTargetFile (file); - return GetExtensionChain ().FileIsObjectOfType (filename, type); + return GetObjectReaderForFile (filename, type) != null; } public bool IsSolutionItemFile (FilePath file) { - var filename = GetTargetFile (file); - return GetExtensionChain ().FileIsObjectOfType (filename, typeof(SolutionItem)); + return FileIsObjectOfType (file, typeof(SolutionItem)); } public bool IsWorkspaceItemFile (FilePath file) { - var filename = GetTargetFile (file); - return GetExtensionChain ().FileIsObjectOfType (filename, typeof(WorkspaceItem)); + return FileIsObjectOfType (file, typeof(WorkspaceItem)); } internal void InitializeDataContext (DataContext ctx) @@ -435,24 +431,6 @@ namespace MonoDevelop.Projects } } - internal class DefaultProjectServiceExtension: ProjectServiceExtension - { - public override bool FileIsObjectOfType (string file, Type type) - { - return false; - } - - public override Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) - { - return Task.FromResult ((SolutionItem)null); - } - - public override Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) - { - return Task.FromResult ((WorkspaceItem)null); - } - } - internal static class Counters { public static Counter ItemsInMemory = InstrumentationService.CreateCounter ("Projects in memory", "Project Model"); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs deleted file mode 100644 index 60788b9ee5..0000000000 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs +++ /dev/null @@ -1,133 +0,0 @@ -// ProjectServiceExtension.cs -// -// Author: -// Lluis Sanchez Gual <lluis@novell.com> -// -// Copyright (c) 2007 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 System.Collections.Generic; -using MonoDevelop.Core; -using MonoDevelop.Projects.Extensions; -using MonoDevelop.Core.Execution; -using System.Threading.Tasks; -using MonoDevelop.Projects.Formats.MSBuild; - -namespace MonoDevelop.Projects -{ - public class ProjectServiceExtension - { - internal ProjectServiceExtension Next; - - internal ProjectServiceExtension GetNext (WorkspaceObject item) - { - if (Next.SupportsItem (item)) - return Next; - else - return Next.GetNext (item); - } - - public virtual bool SupportsItem (WorkspaceObject item) - { - return true; - } - - public virtual bool FileIsObjectOfType (string file, Type type) - { - return GetNext (UnknownItem.Instance).FileIsObjectOfType (file, type); - } - - public virtual Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) - { - return GetNext (UnknownItem.Instance).LoadSolutionItem (monitor, ctx, fileName, expectedFormat, typeGuid, itemGuid); - } - - public virtual Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) - { - return GetNext (UnknownItem.Instance).LoadWorkspaceItem (monitor, fileName); - } - } - - public class BuildData - { - public ProjectItemCollection Items { get; internal set; } - public DotNetProjectConfiguration Configuration { get; internal set; } - public ConfigurationSelector ConfigurationSelector { get; internal set; } - } - - class UnknownItem: WorkspaceObject, IBuildTarget - { - public static UnknownItem Instance = new UnknownItem (); - - public Task<BuildResult> Build (ProgressMonitor monitor, ConfigurationSelector configuration, bool buildReferencedTargets = false) - { - return Task.FromResult (BuildResult.Success); - } - - public Task<BuildResult> Clean (ProgressMonitor monitor, ConfigurationSelector configuration) - { - return Task.FromResult (BuildResult.Success); - } - - public Task Execute (ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) - { - throw new System.NotImplementedException(); - } - - public bool CanExecute (ExecutionContext context, ConfigurationSelector configuration) - { - return false; - } - - public Task PrepareExecution (ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) - { - return Task.FromResult (true); - } - - public bool NeedsBuilding (ConfigurationSelector configuration) - { - return false; - } - - public IEnumerable<IBuildTarget> GetExecutionDependencies () - { - yield break; - } - - protected override string OnGetName () - { - return "Unknown"; - } - - protected override string OnGetBaseDirectory () - { - return FilePath.Empty; - } - - protected override string OnGetItemDirectory () - { - return FilePath.Empty; - } - } -} diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceObjectReader.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceObjectReader.cs new file mode 100644 index 0000000000..681dfa9362 --- /dev/null +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceObjectReader.cs @@ -0,0 +1,67 @@ +// ProjectServiceExtension.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2007 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; +using System.Threading.Tasks; +using MonoDevelop.Projects.Formats.MSBuild; + +namespace MonoDevelop.Projects +{ + public abstract class WorkspaceObjectReader + { + internal WorkspaceObjectReader Next; + + public abstract bool CanRead (FilePath file, Type expectedType); + + public virtual Task<SolutionItem> LoadSolutionItem (ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) + { + throw new NotSupportedException (); + } + + public virtual Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) + { + throw new NotSupportedException (); + } + } + + class DummyWorkspaceObjectReader: WorkspaceObjectReader + { + public override bool CanRead (FilePath file, Type expectedType) + { + return false; + } + } + + public class BuildData + { + public ProjectItemCollection Items { get; internal set; } + public DotNetProjectConfiguration Configuration { get; internal set; } + public ConfigurationSelector ConfigurationSelector { get; internal set; } + } +} diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceSerializationExtension.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceSerializationExtension.cs index 2c5d9063a1..ce455dd0e5 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceSerializationExtension.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceSerializationExtension.cs @@ -33,48 +33,44 @@ using MonoDevelop.Projects.Formats.MD1; namespace MonoDevelop.Projects { - class WorkspaceSerializationExtension: ProjectServiceExtension + class WorkspaceSerializationExtension: WorkspaceObjectReader { - public override bool FileIsObjectOfType (string file, Type type) + public override bool CanRead (FilePath file, Type expectedType) { - if (type.IsAssignableFrom (typeof(Workspace))) { + if (expectedType.IsAssignableFrom (typeof(Workspace))) { string ext = Path.GetExtension (file).ToLower (); if (ext == ".mdw") return true; } - return base.FileIsObjectOfType (file, type); + return false; } - public override async Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) + public override Task<WorkspaceItem> LoadWorkspaceItem (ProgressMonitor monitor, string fileName) { - string ext = Path.GetExtension (fileName).ToLower (); - if (ext == ".mdw") - return await ReadWorkspaceItemFile (fileName, monitor); - - return await base.LoadWorkspaceItem (monitor, fileName); + return Task<WorkspaceItem>.Factory.StartNew (delegate { + return ReadWorkspaceItemFile (fileName, monitor); + }); } - Task<WorkspaceItem> ReadWorkspaceItemFile (FilePath fileName, ProgressMonitor monitor) + WorkspaceItem ReadWorkspaceItemFile (FilePath fileName, ProgressMonitor monitor) { - return Task<WorkspaceItem>.Factory.StartNew (delegate { - XmlTextReader reader = new XmlTextReader (new StreamReader (fileName)); - try { - monitor.BeginTask (string.Format (GettextCatalog.GetString ("Loading workspace item: {0}"), fileName), 1); - reader.MoveToContent (); - XmlDataSerializer ser = new XmlDataSerializer (MD1ProjectService.DataContext); - ser.SerializationContext.BaseFile = fileName; - ser.SerializationContext.ProgressMonitor = monitor; - WorkspaceItem entry = (WorkspaceItem)ser.Deserialize (reader, typeof(WorkspaceItem)); - entry.FileName = fileName; - return entry; - } catch (Exception ex) { - monitor.ReportError (string.Format (GettextCatalog.GetString ("Could not load solution item: {0}"), fileName), ex); - throw; - } finally { - monitor.EndTask (); - reader.Close (); - } - }); + XmlTextReader reader = new XmlTextReader (new StreamReader (fileName)); + try { + monitor.BeginTask (string.Format (GettextCatalog.GetString ("Loading workspace item: {0}"), fileName), 1); + reader.MoveToContent (); + XmlDataSerializer ser = new XmlDataSerializer (MD1ProjectService.DataContext); + ser.SerializationContext.BaseFile = fileName; + ser.SerializationContext.ProgressMonitor = monitor; + WorkspaceItem entry = (WorkspaceItem)ser.Deserialize (reader, typeof(WorkspaceItem)); + entry.FileName = fileName; + return entry; + } catch (Exception ex) { + monitor.ReportError (string.Format (GettextCatalog.GetString ("Could not load solution item: {0}"), fileName), ex); + throw; + } finally { + monitor.EndTask (); + reader.Close (); + } } } } |