From 3358edbaa0dcd612df107b93d3575d9596429be5 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 25 Mar 2012 18:47:54 +0100 Subject: [PATCH 01/94] Use SvcUtil to generate service proxy class. --- .../Project/ICSharpCode.SharpDevelop.csproj | 11 +- .../AddServiceReferenceViewModel.cs | 15 ++- .../IProjectWithServiceReferences.cs | 2 +- .../IServiceReferenceCodeDomBuilder.cs | 15 --- .../IServiceReferenceProxyGenerator.cs | 5 +- .../ProjectWithServiceReferences.cs | 10 +- .../ServiceReferenceCodeDomBuilder.cs | 53 --------- .../ServiceReferenceCodeDomProvider.cs | 42 ------- .../ServiceReferenceFileGenerator.cs | 13 +-- .../ServiceReferenceGenerator.cs | 21 ++-- .../ServiceReferenceGeneratorOptions.cs | 33 ++++++ .../ServiceReferenceProxyGenerator.cs | 34 ++---- .../ServiceReference/SvcUtilCommandLine.cs | 85 ++++++++++++++ .../ServiceReference/SvcUtilMessageView.cs | 31 +++++ ...{ICodeDomProvider.cs => SvcUtilOptions.cs} | 15 ++- .../ServiceReference/SvcUtilPath.cs | 63 +++++++++++ .../ServiceReference/SvcUtilRunner.cs | 65 +++++++++++ .../ServiceReference/WebServiceMetadataSet.cs | 50 --------- .../ICSharpCode.SharpDevelop.Tests.csproj | 2 - .../ProjectWithServiceReferencesTests.cs | 36 +++--- .../ServiceReferenceGeneratorTests.cs | 106 ++++++++++++++---- .../ServiceReferenceProxyGeneratorTests.cs | 64 ----------- .../WebServiceMetadataSetTests.cs | 97 ---------------- 23 files changed, 437 insertions(+), 431 deletions(-) delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceCodeDomBuilder.cs delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomBuilder.cs delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomProvider.cs create mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs create mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs create mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilMessageView.cs rename src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/{ICodeDomProvider.cs => SvcUtilOptions.cs} (57%) create mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs create mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/WebServiceMetadataSet.cs delete mode 100644 src/Main/Base/Test/ServiceReferences/ServiceReferenceProxyGeneratorTests.cs delete mode 100644 src/Main/Base/Test/ServiceReferences/WebServiceMetadataSetTests.cs diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 52dfddb00f..af6b00fdc0 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -272,28 +272,29 @@ - - - - + - + + + + + ToolNotFoundDialog.cs diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs index 560f9e1720..7aa21db32f 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs @@ -45,7 +45,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference ServiceDescriptionCollection serviceDescriptionCollection = new ServiceDescriptionCollection(); CredentialCache credentialCache = new CredentialCache(); WebServiceDiscoveryClientProtocol discoveryClientProtocol; - WebServiceMetadataSet serviceMetadata; delegate DiscoveryDocument DiscoverAnyAsync(string url); delegate void DiscoveredWebServicesHandler(DiscoveryClientProtocol protocol); @@ -225,11 +224,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { if (protocol != null) { serviceDescriptionCollection = ServiceReferenceHelper.GetServiceDescriptions(protocol); - serviceMetadata = new WebServiceMetadataSet(protocol); - - ServiceDescriptionMessage = String.Format("{0} service(s) found at address {1}", - serviceDescriptionCollection.Count, - discoveryUri); + ServiceDescriptionMessage = String.Format( + "{0} service(s) found at address {1}", + serviceDescriptionCollection.Count, + discoveryUri); DefaultNameSpace = GetDefaultNamespace(); FillItems(serviceDescriptionCollection); string referenceName = ServiceReferenceHelper.GetReferenceName(discoveryUri); @@ -379,8 +377,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public void AddServiceReference() { var serviceGenerator = new ServiceReferenceGenerator(project); - serviceGenerator.Namespace = defaultNameSpace; - serviceGenerator.AddServiceReference(serviceMetadata); + serviceGenerator.Options.Namespace = defaultNameSpace; + serviceGenerator.Options.Url = discoveryUri.ToString(); + serviceGenerator.AddServiceReference(); new RefreshProjectBrowser().Run(); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs index 26f041abb6..78b812838e 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs @@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public interface IProjectWithServiceReferences { string ServiceReferencesFolder { get; } - ICodeDomProvider CodeDomProvider { get; } + string Language { get; } ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName); ServiceReferenceMapFileName GetServiceReferenceMapFileName(string serviceReferenceName); diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceCodeDomBuilder.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceCodeDomBuilder.cs deleted file mode 100644 index 11d853cc4c..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceCodeDomBuilder.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.CodeDom; -using System.ServiceModel.Description; - -namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference -{ - public interface IServiceReferenceCodeDomBuilder - { - string Namespace { get; set; } - CodeCompileUnit GenerateCompileUnit(MetadataSet metadata); - } -} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs index 9b117b442e..c8aa3ea183 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs @@ -8,8 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public interface IServiceReferenceProxyGenerator { - string ServiceReferenceNamespace { get; set; } - - void GenerateProxyFile(MetadataSet metadata, string proxyFileName); + ServiceReferenceGeneratorOptions Options { get; } + void GenerateProxyFile(); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs index 16a155f91f..0fe2047258 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs @@ -18,14 +18,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public static readonly string DefaultServiceReferencesFolderName = "Service References"; public ProjectWithServiceReferences(IProject project) - : this(project, new ServiceReferenceCodeDomProvider(project)) - { - } - - public ProjectWithServiceReferences(IProject project, ICodeDomProvider codeDomProvider) { this.project = project; - this.CodeDomProvider = codeDomProvider; } public string ServiceReferencesFolder { @@ -42,7 +36,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference serviceReferencesFolder = Path.Combine(project.Directory, DefaultServiceReferencesFolderName); } - public ICodeDomProvider CodeDomProvider { get; private set; } + public string Language { + get { return project.Language; } + } public ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName) { diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomBuilder.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomBuilder.cs deleted file mode 100644 index c7b2bf89af..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomBuilder.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.CodeDom; -using System.Runtime.Serialization; -using System.ServiceModel.Channels; -using System.ServiceModel.Description; - -namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference -{ - public class ServiceReferenceCodeDomBuilder : IServiceReferenceCodeDomBuilder - { - public ServiceReferenceCodeDomBuilder() - { - this.Namespace = String.Empty; - } - - public string Namespace { get; set; } - - public CodeCompileUnit GenerateCompileUnit(MetadataSet metadata) - { - ServiceContractGenerator contractGenerator = CreateServiceContractGenerator(); - WsdlImporter importer = CreateWsdlImporter(metadata); - - foreach (ContractDescription contract in importer.ImportAllContracts()) { - contractGenerator.GenerateServiceContractType(contract); - } - - return contractGenerator.TargetCompileUnit; - } - - WsdlImporter CreateWsdlImporter(MetadataSet metadata) - { - var importer = new WsdlImporter(metadata); - var contractImporter = new XsdDataContractImporter(); - contractImporter.Options = new ImportOptions(); - contractImporter.Options.Namespaces.Add("*", Namespace); - importer.State.Add(typeof(XsdDataContractImporter), contractImporter); - return importer; - } - - ServiceContractGenerator CreateServiceContractGenerator() - { - var contractGenerator = new ServiceContractGenerator(); - contractGenerator.Options = - ServiceContractGenerationOptions.ClientClass | - ServiceContractGenerationOptions.ChannelInterface; - contractGenerator.NamespaceMappings.Add("*", Namespace); - return contractGenerator; - } - } -} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomProvider.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomProvider.cs deleted file mode 100644 index 953cff83b6..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomProvider.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.CodeDom; -using System.CodeDom.Compiler; -using System.IO; -using ICSharpCode.SharpDevelop.Project; - -namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference -{ - public class ServiceReferenceCodeDomProvider : ICodeDomProvider - { - IProject project; - CodeDomProvider codeDomProvider; - - public ServiceReferenceCodeDomProvider(IProject project) - { - this.project = project; - } - - public string FileExtension { - get { return CodeDomProvider.FileExtension; } - } - - CodeDomProvider CodeDomProvider { - get { - if (codeDomProvider == null) { - codeDomProvider = project.LanguageProperties.CodeDomProvider; - } - return codeDomProvider; - } - } - - public void GenerateCodeFromCompileUnit(CodeCompileUnit compileUnit, string fileName) - { - using (var writer = new StreamWriter(fileName)) { - CodeDomProvider.GenerateCodeFromCompileUnit(compileUnit, writer, null); - } - } - } -} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs index 93654abfdf..7dfcfbb36f 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs @@ -11,9 +11,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference IServiceReferenceProxyGenerator proxyGenerator; IServiceReferenceMapGenerator mapGenerator; - public ServiceReferenceFileGenerator(ICodeDomProvider codeDomProvider) + public ServiceReferenceFileGenerator() : this( - new ServiceReferenceProxyGenerator(codeDomProvider), + new ServiceReferenceProxyGenerator(), new ServiceReferenceMapGenerator()) { } @@ -26,14 +26,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference this.mapGenerator = mapGenerator; } - public string ServiceReferenceNamespace { - get { return proxyGenerator.ServiceReferenceNamespace; } - set { proxyGenerator.ServiceReferenceNamespace = value; } + public ServiceReferenceGeneratorOptions Options { + get { return proxyGenerator.Options; } } - public void GenerateProxyFile(MetadataSet metadata, string proxyFileName) + public void GenerateProxyFile() { - proxyGenerator.GenerateProxyFile(metadata, proxyFileName); + proxyGenerator.GenerateProxyFile(); } public void GenerateServiceReferenceMapFile(ServiceReferenceMapFile mapFile) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs index 16cbad416a..25fc6bacec 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public ServiceReferenceGenerator(IProjectWithServiceReferences project) : this( project, - new ServiceReferenceFileGenerator(project.CodeDomProvider), + new ServiceReferenceFileGenerator(), new ServiceReferenceFileSystem()) { } @@ -38,24 +38,27 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference this.fileSystem = fileSystem; } - public string Namespace { get; set; } + public ServiceReferenceGeneratorOptions Options { + get { return fileGenerator.Options; } + } - public void AddServiceReference(MetadataSet metadata) + public void AddServiceReference() { - GenerateServiceReferenceProxy(metadata); + GenerateServiceReferenceProxy(); project.AddAssemblyReference("System.ServiceModel"); project.Save(); } - void GenerateServiceReferenceProxy(MetadataSet metadata) + void GenerateServiceReferenceProxy() { - ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(Namespace); + ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(fileGenerator.Options.Namespace); CreateFolderForFileIfFolderMissing(referenceFileName.Path); - fileGenerator.ServiceReferenceNamespace = Namespace; - fileGenerator.GenerateProxyFile(metadata, referenceFileName.Path); + Options.OutputFileName = referenceFileName.Path; + Options.MapProjectLanguage(project.Language); + fileGenerator.GenerateProxyFile(); - ServiceReferenceMapFileName mapFileName = project.GetServiceReferenceMapFileName(Namespace); + ServiceReferenceMapFileName mapFileName = project.GetServiceReferenceMapFileName(fileGenerator.Options.Namespace); var mapFile = new ServiceReferenceMapFile(mapFileName); fileGenerator.GenerateServiceReferenceMapFile(mapFile); diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs new file mode 100644 index 0000000000..dc876a758a --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs @@ -0,0 +1,33 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference +{ + public class ServiceReferenceGeneratorOptions + { + public ServiceReferenceGeneratorOptions() + { + this.OutputFileName = String.Empty; + this.Namespace = String.Empty; + this.Language = "CS"; + this.NoAppConfig = true; + } + + public string Namespace { get; set; } + public string OutputFileName { get; set; } + public string Url { get; set; } + public string Language { get; set; } + public bool NoAppConfig { get; set; } + + public void MapProjectLanguage(string language) + { + if (language == "VBNet") { + Language = "VB"; + } else { + Language = "CS"; + } + } + } +} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs index 13df4ba05e..fd40cc9e3d 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs @@ -9,37 +9,17 @@ using System.ServiceModel.Description; namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public class ServiceReferenceProxyGenerator : IServiceReferenceProxyGenerator - { - IServiceReferenceCodeDomBuilder codeDomBuilder; - ICodeDomProvider codeDomProvider; + { + SvcUtilOptions options = new SvcUtilOptions(); - public ServiceReferenceProxyGenerator(ICodeDomProvider codeDomProvider) - : this(codeDomProvider, new ServiceReferenceCodeDomBuilder()) - { - } - - public ServiceReferenceProxyGenerator( - ICodeDomProvider codeDomProvider, - IServiceReferenceCodeDomBuilder codeDomBuilder) - { - this.codeDomProvider = codeDomProvider; - this.codeDomBuilder = codeDomBuilder; - } - - public string ServiceReferenceNamespace { - get { return codeDomBuilder.Namespace; } - set { codeDomBuilder.Namespace = value; } - } - - public void GenerateProxyFile(MetadataSet metadata, string proxyFileName) - { - CodeCompileUnit compileUnit = codeDomBuilder.GenerateCompileUnit(metadata); - GenerateProxy(compileUnit, proxyFileName); + public ServiceReferenceGeneratorOptions Options { + get { return options; } } - void GenerateProxy(CodeCompileUnit compileUnit, string fileName) + public void GenerateProxyFile() { - codeDomProvider.GenerateCodeFromCompileUnit(compileUnit, fileName); + var runner = new SvcUtilRunner(options); + runner.Run(); } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs new file mode 100644 index 0000000000..edc838d70d --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs @@ -0,0 +1,85 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Text; + +namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference +{ + public class SvcUtilCommandLine + { + StringBuilder argumentBuilder = new StringBuilder(); + + public SvcUtilCommandLine(SvcUtilOptions options) + { + GenerateCommandLine(options); + } + + public string Command { get; set; } + public string Arguments { get; private set; } + + void GenerateCommandLine(SvcUtilOptions options) + { + AppendIfTrue("/noconfig", options.NoAppConfig); + AppendIfNotEmpty("/out:", options.OutputFileName); + AppendIfNotEmpty("/namespace:", options.GetNamespaceMapping()); + AppendIfNotEmpty("/language:", options.Language); + AppendIfNotEmpty(options.Url); + + this.Arguments = argumentBuilder.ToString(); + } + + void AppendIfTrue(string argument, bool flag) + { + if (flag) { + Append(argument); + } + } + + void AppendIfNotEmpty(string argumentName, string argumentValue) + { + if (!String.IsNullOrEmpty(argumentValue)) { + Append(argumentName + GetQuotedArgument(argumentValue)); + } + } + + void AppendIfNotEmpty(string argument) + { + if (!String.IsNullOrEmpty(argument)) { + Append(argument); + } + } + + void Append(string argument) + { + argumentBuilder.Append(argument); + argumentBuilder.Append(' '); + } + + public override string ToString() + { + return String.Format( + "{0} {1}", + GetQuotedCommand(), + Arguments); + } + + string GetQuotedCommand() + { + return GetQuotedArgument(Command); + } + + string GetQuotedArgument(string argument) + { + if (ContainsSpaceCharacter(argument)) { + return String.Format("\"{0}\"", argument); + } + return argument; + } + + bool ContainsSpaceCharacter(string text) + { + return text.IndexOf(' ') >= 0; + } + } +} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilMessageView.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilMessageView.cs new file mode 100644 index 0000000000..8a85d853c3 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilMessageView.cs @@ -0,0 +1,31 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference +{ + public class SvcUtilMessageView + { + static MessageViewCategory category; + + public static MessageViewCategory Category { + get { + if (category == null) { + MessageViewCategory.Create(ref category, "SvcUtil"); + } + return category; + } + } + + public static void AppendLine(string text) + { + Category.AppendLine(text); + } + + public static void ClearText() + { + Category.ClearText(); + } + } +} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ICodeDomProvider.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs similarity index 57% rename from src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ICodeDomProvider.cs rename to src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs index 4400ed3f46..10a2b140ca 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ICodeDomProvider.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs @@ -2,14 +2,21 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.CodeDom; namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { - public interface ICodeDomProvider + public class SvcUtilOptions : ServiceReferenceGeneratorOptions { - string FileExtension { get; } + public SvcUtilOptions() + { + } - void GenerateCodeFromCompileUnit(CodeCompileUnit compileUnit, string fileName); + public string GetNamespaceMapping() + { + if (Namespace != null) { + return "*," + Namespace; + } + return null; + } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs new file mode 100644 index 0000000000..7561f8d7d5 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs @@ -0,0 +1,63 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.IO; +using Microsoft.Win32; + +namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference +{ + public class SvcUtilPath + { + string fileName = "svcutil.exe"; + bool exists = true; + + public SvcUtilPath() + { + FindSvcUtil(); + } + + public bool Exists { + get { return exists; } + } + + void FindSvcUtil() + { + string sdkPath = TryGetCurrentUserSdkInstallPath(); + if (sdkPath == null) { + sdkPath = TryGetLocalMachineSdkInstallPath(); + } + if (sdkPath != null) { + string fullPath = Path.Combine(sdkPath, @"bin\svcutil.exe"); + exists = File.Exists(fullPath); + if (exists) { + fileName = fullPath; + } + } + } + + string TryGetCurrentUserSdkInstallPath() + { + return TryGetSdkInstallPath("HKEY_CURRENT_USER"); + } + + string TryGetLocalMachineSdkInstallPath() + { + return TryGetSdkInstallPath("HKEY_LOCAL_MACHINE"); + } + + string TryGetSdkInstallPath(string root) + { + try { + string keyName = root + @"\SOFTWARE\Microsoft\Microsoft SDKs\Windows"; + return (string)Registry.GetValue(keyName, "CurrentInstallFolder", null); + } catch (Exception) { + } + return null; + } + + public string FileName { + get { return fileName; } + } + } +} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs new file mode 100644 index 0000000000..eb1e6b4a17 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs @@ -0,0 +1,65 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.SharpDevelop.Util; + +namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference +{ + public class SvcUtilRunner + { + public SvcUtilRunner(SvcUtilOptions options) + { + this.Options = options; + } + + public SvcUtilOptions Options { get; private set; } + + public void Run() + { + SvcUtilMessageView.ClearText(); + + var commandLine = new SvcUtilCommandLine(Options); + commandLine.Command = GetSvcUtilPath(); + SvcUtilMessageView.AppendLine(commandLine.ToString()); + ProcessRunner runner = CreateProcessRunner(); + runner.Start(commandLine.Command, commandLine.Arguments); + } + + string GetSvcUtilPath() + { + var path = new SvcUtilPath(); + if (!path.Exists) { + DisplaySvcUtilNotFoundMessage(); + } + return path.FileName; + } + + void DisplaySvcUtilNotFoundMessage() + { + string message = + "Unable to find svcutil.exe. Please install the Windows SDK"; + SvcUtilMessageView.AppendLine(message); + } + + ProcessRunner CreateProcessRunner() + { + var runner = new ProcessRunner(); + runner.LogStandardOutputAndError = false; + runner.OutputLineReceived += LineReceived; + runner.ErrorLineReceived += LineReceived; + runner.ProcessExited += ProcessExited; + return runner; + } + + void LineReceived(object sender, LineReceivedEventArgs e) + { + SvcUtilMessageView.AppendLine(e.Line); + } + + void ProcessExited(object sender, EventArgs e) + { + SvcUtilMessageView.AppendLine("SvcUtil finished."); + } + } +} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/WebServiceMetadataSet.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/WebServiceMetadataSet.cs deleted file mode 100644 index 8ecedfc9a1..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/WebServiceMetadataSet.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.ServiceModel.Description; -using System.Xml.Schema; - -using WSDescription = System.Web.Services.Description; -using WSDiscovery = System.Web.Services.Discovery; - -namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference -{ - public class WebServiceMetadataSet : MetadataSet - { - public static readonly string EmptyMetadataIdentifier = String.Empty; - - public WebServiceMetadataSet(WSDiscovery.DiscoveryClientProtocol discoveryClient) - { - AddToMetadata(discoveryClient.Documents); - } - - void AddToMetadata(WSDiscovery.DiscoveryClientDocumentCollection documents) - { - foreach (object document in documents.Values) { - AddToMetadataIfNotNull(document as WSDescription.ServiceDescription); - AddToMetadataIfNotNull(document as XmlSchema); - } - } - - void AddToMetadataIfNotNull(WSDescription.ServiceDescription serviceDescription) - { - if (serviceDescription != null) { - AddMetadataSection(MetadataSection.ServiceDescriptionDialect, serviceDescription); - } - } - - void AddMetadataSection(string dialect, object metadata) - { - var metadataSection = new MetadataSection(dialect, EmptyMetadataIdentifier, metadata); - MetadataSections.Add(metadataSection); - } - - void AddToMetadataIfNotNull(XmlSchema schema) - { - if (schema != null) { - AddMetadataSection(MetadataSection.XmlSchemaDialect, schema); - } - } - } -} \ No newline at end of file diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj index d57c014a27..30b472fc8b 100644 --- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj +++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj @@ -105,10 +105,8 @@ - - diff --git a/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs b/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs index 9d7766d088..09f687a568 100644 --- a/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs +++ b/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs @@ -37,6 +37,12 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences project = new ProjectWithServiceReferences(msbuildProject); } + void CreateProjectWithVisualBasicMSBuildProject() + { + msbuildProject = WebReferenceTestHelper.CreateTestProject("VBNet"); + project = new ProjectWithServiceReferences(msbuildProject); + } + void SetProjectDirectory(string directory) { fakeProject.Stub(p => p.Directory).Return(directory); @@ -97,18 +103,6 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences Assert.AreEqual(expectedFolder, folder); } - [Test] - public void CodeDomProvider_UnderlyingProjectUsesCSharpCodeDomProvider_ProjectUsesCSharpCodeDomProvider() - { - CreateProject(); - SetProjectCodeDomProvider(LanguageProperties.CSharp); - - ICodeDomProvider codeDomProvider = project.CodeDomProvider; - string fileExtension = codeDomProvider.FileExtension; - - Assert.AreEqual("cs", fileExtension); - } - [Test] public void GetServiceReferenceProxyFileName_ProjectHasNoServiceReferences_ReturnsFileNameInServiceReferencesFolderWithSubFolderNamedAfterServiceReference() { @@ -259,7 +253,7 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences } [Test] - public void AddAssemblyReference_SystemServiceModelAddedToProjectThatHasSystemServiceModelReferenceUsingFullAssemblyNa_AssemblyReferenceIsNotAdded() + public void AddAssemblyReference_SystemServiceModelAddedToProjectThatHasSystemServiceModelReferenceUsingFullAssemblyName_AssemblyReferenceIsNotAdded() { CreateProjectWithMSBuildProject(); AddAssemblyReferenceToMSBuildProject("System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); @@ -270,5 +264,21 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences Assert.AreEqual(1, count); } + + [Test] + public void Language_CSharpProject_CSharpLanguageReturned() + { + CreateProjectWithMSBuildProject(); + + Assert.AreEqual("C#", project.Language); + } + + [Test] + public void Language_VisualBasicProject_VisualBasicLanguageReturned() + { + CreateProjectWithVisualBasicMSBuildProject(); + + Assert.AreEqual("VBNet", project.Language); + } } } diff --git a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs index d81ce68960..5d9615f8b5 100644 --- a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs +++ b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs @@ -19,14 +19,16 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences ServiceReferenceGenerator generator; ServiceReferenceFileGenerator fileGenerator; IFileSystem fakeFileSystem; - MetadataSet metadata; + ServiceReferenceGeneratorOptions options; void CreateGenerator() { - metadata = new MetadataSet(); - + options = new ServiceReferenceGeneratorOptions(); fakeProject = MockRepository.GenerateStub(); fakeProxyGenerator = MockRepository.GenerateStub(); + fakeProxyGenerator + .Stub(p => p.Options) + .Return(options); fakeReferenceMapGenerator = MockRepository.GenerateStub(); fileGenerator = new ServiceReferenceFileGenerator(fakeProxyGenerator, fakeReferenceMapGenerator); fakeFileSystem = MockRepository.GenerateStub(); @@ -73,18 +75,46 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences fakeProject.Stub(p => p.GetServiceReferenceMapFileName(serviceName)).Return(fileName); } + void UseCSharpProject() + { + SetProjectLanguage("C#"); + } + + void UseVisualBasicProject() + { + SetProjectLanguage("VBNet"); + } + + void SetProjectLanguage(string language) + { + fakeProject.Stub(p => p.Language).Return(language); + } + + [Test] + public void AddServiceReference_GeneratesServiceReference_ProxyFileIsGenerated() + { + CreateGenerator(); + AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); + AddMapFileNameForServiceName("MyServiceRef"); + generator.Options.Namespace = "MyServiceRef"; + + generator.AddServiceReference(); + + fakeProxyGenerator.AssertWasCalled(p => p.GenerateProxyFile()); + } + [Test] - public void AddServiceReference_GeneratesServiceReference_MetadataPassedToProxyGenerator() + public void AddServiceReference_GeneratesServiceReference_ProxyFileNameTakenFromProject() { CreateGenerator(); AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); AddMapFileNameForServiceName("MyServiceRef"); - generator.Namespace = "MyServiceRef"; + generator.Options.Namespace = "MyServiceRef"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); string expectedProxyFileName = @"d:\projects\MyProject\Service References\MyServiceRef\Reference.cs"; - fakeProxyGenerator.AssertWasCalled(p => p.GenerateProxyFile(metadata, expectedProxyFileName)); + Assert.AreEqual(expectedProxyFileName, fakeProxyGenerator.Options.OutputFileName); } [Test] @@ -93,9 +123,9 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences CreateGenerator(); AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyService1"); AddMapFileNameForServiceName("MyService1"); - generator.Namespace = "MyService1"; + generator.Options.Namespace = "MyService1"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); string expectedDirectory = @"d:\projects\MyProject\Service References\MyService1"; @@ -109,9 +139,9 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences ServiceReferenceFileName expectedProxyFileName = AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); AddMapFileNameForServiceName("MyServiceRef"); - generator.Namespace = "MyServiceRef"; + generator.Options.Namespace = "MyServiceRef"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); fakeProject.AssertWasCalled(p => p.AddServiceReferenceProxyFile(expectedProxyFileName)); } @@ -122,9 +152,9 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences CreateGenerator(); AddProxyFileNameForServiceName("MyServiceRef"); AddMapFileNameForServiceName("MyServiceRef"); - generator.Namespace = "MyServiceRef"; + generator.Options.Namespace = "MyServiceRef"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); fakeProject.AssertWasCalled(p => p.Save()); } @@ -135,9 +165,9 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences CreateGenerator(); AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); AddMapFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); - generator.Namespace = "MyServiceRef"; + generator.Options.Namespace = "MyServiceRef"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); var expectedMapFile = new ServiceReferenceMapFile() { FileName = @"d:\projects\MyProject\Service References\MyServiceRef\Reference.svcmap" @@ -153,9 +183,9 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences AddProxyFileNameForServiceName("MyServiceRef"); ServiceReferenceMapFileName expectedMapFileName = AddMapFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); - generator.Namespace = "MyServiceRef"; + generator.Options.Namespace = "MyServiceRef"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); fakeProject.AssertWasCalled(p => p.AddServiceReferenceMapFile(expectedMapFileName)); } @@ -166,9 +196,9 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences CreateGenerator(); AddProxyFileNameForServiceName("MyService"); AddMapFileNameForServiceName("MyService"); - generator.Namespace = "MyService"; + generator.Options.Namespace = "MyService"; - generator.AddServiceReference(metadata); + generator.AddServiceReference(); fakeProject.AssertWasCalled(p => p.AddAssemblyReference("System.ServiceModel")); } @@ -179,14 +209,14 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences CreateGenerator(); AddProxyFileNameForServiceName("MyService"); AddMapFileNameForServiceName("MyService"); - generator.Namespace = "MyService"; + generator.Options.Namespace = "MyService"; fakeProject .Stub(p => p.Save()) .WhenCalled(new Action( mi => fakeProject.AssertWasCalled(p => p.AddAssemblyReference("System.ServiceModel")))); - generator.AddServiceReference(metadata); + generator.AddServiceReference(); } [Test] @@ -196,11 +226,39 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences AddProxyFileNameForServiceName("MyServiceRef"); ServiceReferenceMapFileName expectedMapFileName = AddMapFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef"); - generator.Namespace = "MyServiceRef"; + generator.Options.Namespace = "MyServiceRef"; + + generator.AddServiceReference(); + + Assert.AreEqual("MyServiceRef", fakeProxyGenerator.Options.Namespace); + } + + [Test] + public void AddServiceReference_CSharpProject_CSharpProxyGenerated() + { + CreateGenerator(); + AddProxyFileNameForServiceName("MyService"); + AddMapFileNameForServiceName("MyService"); + generator.Options.Namespace = "MyService"; + UseCSharpProject(); + + generator.AddServiceReference(); + + Assert.AreEqual("CS", fakeProxyGenerator.Options.Language); + } + + [Test] + public void AddServiceReference_VisualBasicProject_VisualBasicProxyGenerated() + { + CreateGenerator(); + AddProxyFileNameForServiceName("MyService"); + AddMapFileNameForServiceName("MyService"); + generator.Options.Namespace = "MyService"; + UseVisualBasicProject(); - generator.AddServiceReference(metadata); + generator.AddServiceReference(); - Assert.AreEqual("MyServiceRef", fakeProxyGenerator.ServiceReferenceNamespace); + Assert.AreEqual("VB", fakeProxyGenerator.Options.Language); } } } diff --git a/src/Main/Base/Test/ServiceReferences/ServiceReferenceProxyGeneratorTests.cs b/src/Main/Base/Test/ServiceReferences/ServiceReferenceProxyGeneratorTests.cs deleted file mode 100644 index 0201a7ce68..0000000000 --- a/src/Main/Base/Test/ServiceReferences/ServiceReferenceProxyGeneratorTests.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.CodeDom; -using System.ServiceModel.Description; -using ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference; -using NUnit.Framework; -using Rhino.Mocks; - -namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences -{ - [TestFixture] - public class ServiceReferenceProxyGeneratorTests - { - ServiceReferenceProxyGenerator proxyGenerator; - IProjectWithServiceReferences fakeProject; - IServiceReferenceCodeDomBuilder fakeCodeDomBuilder; - ICodeDomProvider fakeCodeDomProvider; - MetadataSet metadata; - - void CreateProxyGenerator() - { - metadata = new MetadataSet(); - - fakeCodeDomBuilder = MockRepository.GenerateStub(); - fakeProject = MockRepository.GenerateStub(); - fakeCodeDomProvider = MockRepository.GenerateStub(); - proxyGenerator = new ServiceReferenceProxyGenerator(fakeCodeDomProvider, fakeCodeDomBuilder); - } - - CodeCompileUnit CreateCompileUnitToReturnFromCodeDomBuilder(MetadataSet metadata) - { - var compileUnit = new CodeCompileUnit(); - fakeCodeDomBuilder.Stub(c => c.GenerateCompileUnit(metadata)).Return(compileUnit); - return compileUnit; - } - - [Test] - public void GenerateProxyFile_ProxyToBeGeneratedForMetadata_CodeGeneratedFromCodeDomForProxyFileInProjectSubFolder() - { - CreateProxyGenerator(); - CodeCompileUnit compileUnit = CreateCompileUnitToReturnFromCodeDomBuilder(metadata); - proxyGenerator.ServiceReferenceNamespace = "Test"; - string expectedProxyFileName = @"d:\projects\MyProject\Service References\Test\Service1\Reference.cs"; - - proxyGenerator.GenerateProxyFile(metadata, expectedProxyFileName); - - fakeCodeDomProvider.AssertWasCalled(p => p.GenerateCodeFromCompileUnit(compileUnit, expectedProxyFileName)); - } - - [Test] - public void GenerateProxyFile_ProxyToBeGeneratedForMetadata_NamespaceUsedWhenGeneratingCodeDom() - { - CreateProxyGenerator(); - CreateCompileUnitToReturnFromCodeDomBuilder(metadata); - proxyGenerator.ServiceReferenceNamespace = "Test"; - - proxyGenerator.GenerateProxyFile(metadata, "Reference.cs"); - - Assert.AreEqual("Test", fakeCodeDomBuilder.Namespace); - } - } -} diff --git a/src/Main/Base/Test/ServiceReferences/WebServiceMetadataSetTests.cs b/src/Main/Base/Test/ServiceReferences/WebServiceMetadataSetTests.cs deleted file mode 100644 index ab8695de2e..0000000000 --- a/src/Main/Base/Test/ServiceReferences/WebServiceMetadataSetTests.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.Linq; -using System.ServiceModel.Description; -using System.Web.Services.Discovery; -using System.Xml.Schema; -using ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference; -using NUnit.Framework; -using WSDescription = System.Web.Services.Description; -using WSDiscovery = System.Web.Services.Discovery; - -namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences -{ - [TestFixture] - public class WebServiceMetadataSetTests - { - DiscoveryClientProtocol discoveryProtocol; - WebServiceMetadataSet metadata; - - void CreateDiscoveryProtocol() - { - discoveryProtocol = new DiscoveryClientProtocol(); - } - - WSDescription.ServiceDescription AddServiceDescriptionToDiscoveryProtocol() - { - var serviceDescription = new WSDescription.ServiceDescription(); - discoveryProtocol.Documents.Add("http://ServiceDescription", serviceDescription); - return serviceDescription; - } - - void CreateMetadata() - { - metadata = new WebServiceMetadataSet(discoveryProtocol); - } - - XmlSchema AddXmlSchemaToDiscoveryProtocol() - { - var schema = new XmlSchema(); - discoveryProtocol.Documents.Add("http://XmlSchema", schema); - return schema; - } - - [Test] - public void Constructor_DiscoveryProtocolHasOneServiceDescription_ServiceDescriptionAddedToMetadata() - { - CreateDiscoveryProtocol(); - WSDescription.ServiceDescription serviceDescription = - AddServiceDescriptionToDiscoveryProtocol(); - CreateMetadata(); - - MetadataSection section = metadata.MetadataSections.First(); - - Assert.AreEqual(serviceDescription, section.Metadata); - } - - [Test] - public void Constructor_DiscoveryProtocolHasOneServiceDescription_ServiceDescriptionMetadataHasServiceDescriptionDialect() - { - CreateDiscoveryProtocol(); - WSDescription.ServiceDescription serviceDescription = - AddServiceDescriptionToDiscoveryProtocol(); - CreateMetadata(); - - MetadataSection section = metadata.MetadataSections.First(); - - Assert.AreEqual(MetadataSection.ServiceDescriptionDialect, section.Dialect); - } - - [Test] - public void Constructor_DiscoveryProtocolHasOneXmlSchema_XmlSchemaAddedToMetadata() - { - CreateDiscoveryProtocol(); - XmlSchema schema = AddXmlSchemaToDiscoveryProtocol(); - CreateMetadata(); - - MetadataSection section = metadata.MetadataSections.First(); - - Assert.AreEqual(schema, section.Metadata); - } - - [Test] - public void Constructor_DiscoveryProtocolHasOneXmlSchema_XmlSchemaAddedToMetadataHasXmlSchemaDialect() - { - CreateDiscoveryProtocol(); - XmlSchema schema = AddXmlSchemaToDiscoveryProtocol(); - CreateMetadata(); - - MetadataSection section = metadata.MetadataSections.First(); - - Assert.AreEqual(MetadataSection.XmlSchemaDialect, section.Dialect); - } - - } -} From 6373be8ba0025b2205e5f86a2a7d31fb7ce4006d Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 25 Mar 2012 20:23:34 +0100 Subject: [PATCH 02/94] Generate app.config with service reference information. --- .../IProjectWithServiceReferences.cs | 3 + .../ProjectWithServiceReferences.cs | 37 ++++++++ .../ServiceReferenceGenerator.cs | 23 ++++- .../ServiceReferenceGeneratorOptions.cs | 4 + .../ServiceReference/SvcUtilCommandLine.cs | 4 +- .../ProjectWithServiceReferencesTests.cs | 89 +++++++++++++++++++ .../ServiceReferenceGeneratorTests.cs | 60 +++++++++++++ 7 files changed, 216 insertions(+), 4 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs index 78b812838e..51aa9d7cc8 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs @@ -16,5 +16,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference void AddServiceReferenceMapFile(ServiceReferenceMapFileName fileName); void Save(); void AddAssemblyReference(string referenceName); + bool HasAppConfigFile(); + string GetAppConfigFileName(); + void AddAppConfigFile(); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs index 0fe2047258..8bda086abc 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs @@ -119,5 +119,42 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { return String.Equals(a, b, StringComparison.OrdinalIgnoreCase); } + + public bool HasAppConfigFile() + { + return GetAppConfigFile() != null; + } + + ProjectItem GetAppConfigFile() + { + return project.Items.SingleOrDefault(item => IsAppConfigFile(item)); + } + + bool IsAppConfigFile(ProjectItem item) + { + string fileNameWithoutPath = Path.GetFileName(item.FileName); + return String.Equals(fileNameWithoutPath, "app.config", StringComparison.OrdinalIgnoreCase); + } + + public string GetAppConfigFileName() + { + ProjectItem item = GetAppConfigFile(); + if (item != null) { + return item.FileName; + } + return GetDefaultAppConfigFileName(); + } + + public void AddAppConfigFile() + { + var item = new FileProjectItem(project, ItemType.None); + item.FileName = GetDefaultAppConfigFileName(); + AddProjectItemToProject(item); + } + + string GetDefaultAppConfigFileName() + { + return Path.Combine(project.Directory, "app.config"); + } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs index 25fc6bacec..6661cd87d0 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs @@ -50,20 +50,37 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference } void GenerateServiceReferenceProxy() + { + ServiceReferenceFileName referenceFileName = GenerateProxyFile(); + ServiceReferenceMapFileName mapFileName = CreateServiceReferenceMapFile(); + project.AddServiceReferenceProxyFile(referenceFileName); + project.AddServiceReferenceMapFile(mapFileName); + if (!project.HasAppConfigFile()) { + project.AddAppConfigFile(); + } + } + + ServiceReferenceFileName GenerateProxyFile() { ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(fileGenerator.Options.Namespace); CreateFolderForFileIfFolderMissing(referenceFileName.Path); Options.OutputFileName = referenceFileName.Path; + Options.AppConfigFileName = project.GetAppConfigFileName(); + Options.NoAppConfig = false; + Options.MergeAppConfig = project.HasAppConfigFile(); Options.MapProjectLanguage(project.Language); fileGenerator.GenerateProxyFile(); + return referenceFileName; + } + + ServiceReferenceMapFileName CreateServiceReferenceMapFile() + { ServiceReferenceMapFileName mapFileName = project.GetServiceReferenceMapFileName(fileGenerator.Options.Namespace); var mapFile = new ServiceReferenceMapFile(mapFileName); fileGenerator.GenerateServiceReferenceMapFile(mapFile); - - project.AddServiceReferenceProxyFile(referenceFileName); - project.AddServiceReferenceMapFile(mapFileName); + return mapFileName; } void CreateFolderForFileIfFolderMissing(string fileName) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs index dc876a758a..d473c8ef3a 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs @@ -9,6 +9,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public ServiceReferenceGeneratorOptions() { + this.AppConfigFileName = String.Empty; + this.MergeAppConfig = false; this.OutputFileName = String.Empty; this.Namespace = String.Empty; this.Language = "CS"; @@ -19,7 +21,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public string OutputFileName { get; set; } public string Url { get; set; } public string Language { get; set; } + public string AppConfigFileName { get; set; } public bool NoAppConfig { get; set; } + public bool MergeAppConfig { get; set; } public void MapProjectLanguage(string language) { diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs index edc838d70d..4b6ceca313 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs @@ -20,10 +20,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference void GenerateCommandLine(SvcUtilOptions options) { - AppendIfTrue("/noconfig", options.NoAppConfig); AppendIfNotEmpty("/out:", options.OutputFileName); AppendIfNotEmpty("/namespace:", options.GetNamespaceMapping()); AppendIfNotEmpty("/language:", options.Language); + AppendIfTrue("/noConfig", options.NoAppConfig); + AppendIfTrue("/mergeConfig", options.MergeAppConfig); + AppendIfNotEmpty("/config:", options.AppConfigFileName); AppendIfNotEmpty(options.Url); this.Arguments = argumentBuilder.ToString(); diff --git a/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs b/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs index 09f687a568..f3f7efe2fd 100644 --- a/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs +++ b/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs @@ -63,6 +63,11 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences return msbuildProject.GetItemsOfType(ItemType.ServiceReferences).SingleOrDefault() as ServiceReferencesProjectItem; } + ProjectItem GetFileProjectItemInMSBuildProject(string fileName) + { + return msbuildProject.Items.SingleOrDefault(item => item.FileName == fileName); + } + ServiceReferenceProjectItem GetFirstWCFMetadataStorageItemInMSBuildProject() { return msbuildProject.GetItemsOfType(ItemType.ServiceReference).SingleOrDefault() as ServiceReferenceProjectItem; @@ -86,6 +91,12 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences ProjectService.AddProjectItem(msbuildProject, item); } + void AddFileToMSBuildProject(string include) + { + var fileItem = new FileProjectItem(msbuildProject, ItemType.None, include); + ProjectService.AddProjectItem(msbuildProject, fileItem); + } + int CountAssemblyReferencesInMSBuildProject() { return msbuildProject.GetItemsOfType(ItemType.Reference).Count(); @@ -280,5 +291,83 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences Assert.AreEqual("VBNet", project.Language); } + + [Test] + public void AddAppConfigFile_ProjectHasNoAppConfig_ProjectItemAddedToProjectForAppConfig() + { + CreateProjectWithMSBuildProject(); + msbuildProject.FileName = @"d:\projects\MyProject\myproject.csproj"; + + project.AddAppConfigFile(); + + ProjectItem item = GetFileFromMSBuildProject(@"d:\projects\MyProject\app.config"); + + Assert.IsNotNull(item); + Assert.AreEqual(ItemType.None, item.ItemType); + } + + [Test] + public void HasAppConfigFile_ProjectHasNoAppConfig_ReturnsFalse() + { + CreateProjectWithMSBuildProject(); + bool result = project.HasAppConfigFile(); + + Assert.IsFalse(result); + } + + [Test] + public void HasAppConfigFile_ProjectHasAppConfig_ReturnsTrue() + { + CreateProjectWithMSBuildProject(); + project.AddAppConfigFile(); + + bool result = project.HasAppConfigFile(); + + Assert.IsTrue(result); + } + + [Test] + public void HasAppConfigFile_ProjectHasAppConfigInSubFolder_ReturnsTrue() + { + CreateProjectWithMSBuildProject(); + AddFileToMSBuildProject(@"SubFolder\app.config"); + + bool result = project.HasAppConfigFile(); + + Assert.IsTrue(result); + } + + [Test] + public void HasAppConfigFile_ProjectHasAppConfigInUpperCase_ReturnsTrue() + { + CreateProjectWithMSBuildProject(); + AddFileToMSBuildProject(@"APP.CONFIG"); + + bool result = project.HasAppConfigFile(); + + Assert.IsTrue(result); + } + + [Test] + public void GetAppConfigFileName_ProjectHasNoAppConfig_DefaultAppConfigFileNameReturned() + { + CreateProjectWithMSBuildProject(); + msbuildProject.FileName = @"d:\projects\MyProject\myproject.csproj"; + + string fileName = project.GetAppConfigFileName(); + + Assert.AreEqual(@"d:\projects\MyProject\app.config", fileName); + } + + [Test] + public void GetAppConfigFileName_ProjectHasAppConfigInSubFolder_AppConfigFileNameReturned() + { + CreateProjectWithMSBuildProject(); + msbuildProject.FileName = @"d:\projects\MyProject\myproject.csproj"; + AddFileToMSBuildProject(@"SubFolder\app.config"); + string fileName = project.GetAppConfigFileName(); + + Assert.AreEqual(@"d:\projects\MyProject\SubFolder\app.config", fileName); + } } } diff --git a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs index 5d9615f8b5..30b3c0420f 100644 --- a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs +++ b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs @@ -90,6 +90,26 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences fakeProject.Stub(p => p.Language).Return(language); } + void SetProjectAppConfigFileName(string fileName) + { + fakeProject.Stub(p => p.GetAppConfigFileName()).Return(fileName); + } + + void ProjectDoesNotHaveAppConfigFile() + { + ProjectHasAppConfigFile(false); + } + + void ProjectHasAppConfigFile() + { + ProjectHasAppConfigFile(true); + } + + void ProjectHasAppConfigFile(bool hasAppConfigFile) + { + fakeProject.Stub(p => p.HasAppConfigFile()).Return(hasAppConfigFile); + } + [Test] public void AddServiceReference_GeneratesServiceReference_ProxyFileIsGenerated() { @@ -260,5 +280,45 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences Assert.AreEqual("VB", fakeProxyGenerator.Options.Language); } + + [Test] + public void AddServiceReference_ProjectHasNoAppConfig_AppConfigFileNamePassedToGeneratorButNoFileMergeRequested() + { + CreateGenerator(); + AddProxyFileNameForServiceName("MyService"); + AddMapFileNameForServiceName("MyService"); + generator.Options.Namespace = "MyService"; + UseVisualBasicProject(); + string expectedAppConfigFileName = @"d:\projects\MyProject\app.config"; + SetProjectAppConfigFileName(expectedAppConfigFileName); + ProjectDoesNotHaveAppConfigFile(); + + generator.AddServiceReference(); + + Assert.AreEqual(expectedAppConfigFileName, fakeProxyGenerator.Options.AppConfigFileName); + Assert.IsFalse(fakeProxyGenerator.Options.NoAppConfig); + Assert.IsFalse(fakeProxyGenerator.Options.MergeAppConfig); + fakeProject.AssertWasCalled(p => p.AddAppConfigFile()); + } + + [Test] + public void AddServiceReference_ProjectHasAppConfig_MergeAppConfigFileRequested() + { + CreateGenerator(); + AddProxyFileNameForServiceName("MyService"); + AddMapFileNameForServiceName("MyService"); + generator.Options.Namespace = "MyService"; + UseVisualBasicProject(); + string expectedAppConfigFileName = @"d:\projects\MyProject\app.config"; + SetProjectAppConfigFileName(expectedAppConfigFileName); + ProjectHasAppConfigFile(); + + generator.AddServiceReference(); + + Assert.AreEqual(expectedAppConfigFileName, fakeProxyGenerator.Options.AppConfigFileName); + Assert.IsFalse(fakeProxyGenerator.Options.NoAppConfig); + Assert.IsTrue(fakeProxyGenerator.Options.MergeAppConfig); + fakeProject.AssertWasNotCalled(p => p.AddAppConfigFile()); + } } } From e1b0e5249eb21b9135a5b95cabd769611f56be6d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 27 Mar 2012 19:13:34 +0200 Subject: [PATCH 03/94] Save docking layout into memory stream first, then write the contents to file. This prevents corruption when there is an exception saving the layout. --- .../Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs index eb91c80553..14109b93fd 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs @@ -320,8 +320,14 @@ namespace ICSharpCode.SharpDevelop.Gui Directory.CreateDirectory(configPath); string fileName = Path.Combine(configPath, current.FileName); LoggingService.Info("Saving layout file: " + fileName); + // Save docking layout into memory stream first, then write the contents to file. + // This prevents corruption when there is an exception saving the layout. + var memoryStream = new MemoryStream(); + dockingManager.SaveLayout(memoryStream); + memoryStream.Position = 0; try { - dockingManager.SaveLayout(fileName); + using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite)) + memoryStream.CopyTo(stream); } catch (IOException ex) { // ignore IO errors (maybe switching layout in two SharpDevelop instances at once?) LoggingService.Warn(ex); From 954b991caf7ccc2c8c05dd138a68a195535a2059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Tue, 27 Mar 2012 22:21:35 +0100 Subject: [PATCH 04/94] Fixes for rare AvalonDock bugs: - Exception when closing tab by middle-clicking - Exception when hovering over auto-hide pad --- src/Libraries/AvalonDock/AvalonDock/DockingManager.cs | 9 +++++++++ src/Libraries/AvalonDock/AvalonDock/DocumentTabPanel.cs | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Libraries/AvalonDock/AvalonDock/DockingManager.cs b/src/Libraries/AvalonDock/AvalonDock/DockingManager.cs index 45a393e3fa..b65cdc147d 100644 --- a/src/Libraries/AvalonDock/AvalonDock/DockingManager.cs +++ b/src/Libraries/AvalonDock/AvalonDock/DockingManager.cs @@ -2636,6 +2636,15 @@ namespace AvalonDock //_flyoutWindow.KeepWindowOpen(); return; } + + // David: This sometimes seems to be null when hovering over auto-hide pad. + // It only seems to occur in specific circumstances - whether the pad is the + // "selected" one in the set seems important. Having no open document might have effect? + // I have only managed to reliablely reproduce it in stand-alone application. + if (content.ContainerPane == null) + { + return; + } //hide previous window HideFlyoutWindow(); diff --git a/src/Libraries/AvalonDock/AvalonDock/DocumentTabPanel.cs b/src/Libraries/AvalonDock/AvalonDock/DocumentTabPanel.cs index b4ed1cf282..86c963cc92 100644 --- a/src/Libraries/AvalonDock/AvalonDock/DocumentTabPanel.cs +++ b/src/Libraries/AvalonDock/AvalonDock/DocumentTabPanel.cs @@ -65,6 +65,10 @@ namespace AvalonDock foreach (ManagedContent child in Children) { + // David: Sometimes happened when closing document tab by middle clicking. Really difficult to reproduce. + if (child == null) + continue; + Panel.SetZIndex(child, Selector.GetIsSelected(child) ? 1 : -i); i++; child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); @@ -81,6 +85,10 @@ namespace AvalonDock bool skipAllOthers = false; foreach (ManagedContent doc in Children) { + // David: Sometimes happened when closing document tab by middle clicking. Really difficult to reproduce. + if (doc == null) + continue; + if (skipAllOthers || offset + doc.DesiredSize.Width > finalSize.Width) { SetIsHeaderVisible(doc, false); From b7863dc22a310787d101dccd9af41671153455e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Tue, 27 Mar 2012 22:31:11 +0100 Subject: [PATCH 05/94] SharpTreeView lines were sometimes incorrect due to recycling --- .../SharpTreeView/ICSharpCode.TreeView/SharpTreeView.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Libraries/SharpTreeView/ICSharpCode.TreeView/SharpTreeView.cs b/src/Libraries/SharpTreeView/ICSharpCode.TreeView/SharpTreeView.cs index 7d44e0744b..26f8bab069 100644 --- a/src/Libraries/SharpTreeView/ICSharpCode.TreeView/SharpTreeView.cs +++ b/src/Libraries/SharpTreeView/ICSharpCode.TreeView/SharpTreeView.cs @@ -174,6 +174,10 @@ namespace ICSharpCode.TreeView base.PrepareContainerForItemOverride(element, item); SharpTreeViewItem container = element as SharpTreeViewItem; container.ParentTreeView = this; + // Make sure that the line renderer takes into account the new bound data + if (container.NodeView != null) { + container.NodeView.LinesRenderer.InvalidateVisual(); + } } bool doNotScrollOnExpanding; From 06440c49d833cf88fe3804d3297cdc0a34bbdd24 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 28 Mar 2012 18:11:39 +0200 Subject: [PATCH 06/94] fix SD-1894 - ArgumentOutOfRangeException when indenting .xaml file --- .../XmlEditor/Project/Src/XmlFormattingStrategy.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs index 038ae9e753..af16946d5f 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs @@ -149,12 +149,7 @@ namespace ICSharpCode.XmlEditor else newText = currentIndentation + lineText.Trim(); - if (newText != lineText) { - int extraCharsToBeAddedAtStartedOfLine = newText.Length - lineText.Length; - document.Replace(line.Offset, line.Length, newText); - Location caretPosition = document.OffsetToPosition(line.Offset + extraCharsToBeAddedAtStartedOfLine); - editor.Caret.Position = caretPosition; - } + document.SmartReplaceLine(line, newText); nextLine++; } if (r.LineNumber > end) From 0fb7f129c80f7b35c146ae2e8c47d4f0075a90f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Wed, 28 Mar 2012 23:51:15 +0100 Subject: [PATCH 07/94] Fixed bug in node removal - the removed node was left in invalid state. This only caused problems if the node was later added back. --- .../SharpTreeView/ICSharpCode.TreeView/FlatListTreeNode.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Libraries/SharpTreeView/ICSharpCode.TreeView/FlatListTreeNode.cs b/src/Libraries/SharpTreeView/ICSharpCode.TreeView/FlatListTreeNode.cs index cf30a85e35..4f5a4d5448 100644 --- a/src/Libraries/SharpTreeView/ICSharpCode.TreeView/FlatListTreeNode.cs +++ b/src/Libraries/SharpTreeView/ICSharpCode.TreeView/FlatListTreeNode.cs @@ -364,6 +364,8 @@ namespace ICSharpCode.TreeView Debug.Assert(node.listParent == null); Debug.Assert(node.left == null); Debug.Assert(node.right == null); + node.height = 1; + node.totalListLength = -1; if (balancingNode != null) RebalanceUntilRoot(balancingNode); } From a7309fc6777539ab0ce170d58efcf8e002d549c4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 29 Mar 2012 19:07:59 +0200 Subject: [PATCH 08/94] fix SD-1726 - WPF loads assemblies by their unqualified name --- .../Src/Services/TypeResolutionService.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs index 7862e938c0..943c8c39aa 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs @@ -122,6 +122,10 @@ namespace ICSharpCode.FormsDesigner.Services if (!projectContentsCurrentlyLoadingAssembly.Add(pc)) return null; + Assembly sdAssembly; + if (IsSharpDevelopAssembly(pc, out sdAssembly)) + return sdAssembly; + try { // load dependencies of current assembly foreach (IProjectContent rpc in pc.ReferencedContents) { @@ -151,6 +155,20 @@ namespace ICSharpCode.FormsDesigner.Services } } + readonly string sharpDevelopRoot = Directory.GetParent(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).FullName; + + bool IsSharpDevelopAssembly(IProjectContent pc, out Assembly assembly) + { + assembly = null; + foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { + if (!asm.IsDynamic && asm.Location.StartsWith(sharpDevelopRoot, StringComparison.OrdinalIgnoreCase) && pc.AssemblyName == asm.GetName().Name) { + assembly = asm; + return true; + } + } + return false; + } + static string GetHash(string fileName) { return Path.GetFileName(fileName).ToLowerInvariant() + File.GetLastWriteTimeUtc(fileName).Ticks.ToString(); From bf23572925e89b9e5abb4b4fccbdbeebe37f086a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 29 Mar 2012 20:36:39 +0200 Subject: [PATCH 09/94] fix http://community.sharpdevelop.net/forums/t/15618.aspx - do not dispose change watcher in ChangeMarkerMargin - it could be used by two different margins (in two synchronized text editors, for ex. split view) --- .../DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs | 1 - src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs index 600cba254f..cbe6842867 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs @@ -39,7 +39,6 @@ namespace ICSharpCode.AvalonEdit.AddIn { if (!disposed) { changeWatcher.ChangeOccurred -= ChangeOccurred; - changeWatcher.Dispose(); disposed = true; } } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs index c821cccfa5..bbe07412da 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs @@ -610,6 +610,8 @@ namespace ICSharpCode.AvalonEdit.AddIn if (errorPainter != null) errorPainter.Dispose(); + if (changeWatcher != null) + changeWatcher.Dispose(); this.Document = null; DisposeTextEditor(primaryTextEditor); if (secondaryTextEditor != null) From 589598e3ac7cceebbacaa953c2ecfea992e62c2c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 29 Mar 2012 20:48:25 +0200 Subject: [PATCH 10/94] fix build --- ...dentChildElementEndTagAfterNewLineTypedTestFixture.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs index ed03ffc9f4..88cdd2f33f 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs @@ -71,14 +71,5 @@ namespace XmlEditor.Tests.Editor Assert.AreEqual(expectedText, textDocument.Text); } - - [Test] - public void CursorIsJustBeforeChildEndElementEndTagAfterIndent() - { - int line = 3; - int column = 2; - Location expectedLocation = new Location(column, line); - Assert.AreEqual(expectedLocation, textEditor.Caret.Position); - } } } From 6921b3ed90c087d7dcd2eddf31cc82553adbee16 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 31 Mar 2012 13:32:51 +0200 Subject: [PATCH 11/94] Fixed crash when overwriting binary files while creating a new project. http://community.sharpdevelop.net/forums/t/15626.aspx --- .../Project/Src/Internal/Templates/Project/ProjectDescriptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs index af4891a447..64480a27d6 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs @@ -369,7 +369,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates } if (!String.IsNullOrEmpty(file.BinaryFileName)) { // Binary content - File.Copy(file.BinaryFileName,fileName); + File.Copy(file.BinaryFileName, fileName, true); } else { // Textual content StreamWriter sr = new StreamWriter(File.Create(fileName), ParserService.DefaultFileEncoding); From b6d2d5a60d0e77530b1aeeb8539ad98dc53594e4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 12:35:59 +0200 Subject: [PATCH 12/94] fix SD-1594 - Windows Forms designer generates the wrong version of .resx files for .NET 3.5 projects and convert .resx on project upgrade/downgrade (as noted in a comment on the issue) --- .../Project/Src/Services/ResourceStore.cs | 8 +- .../Project/Src/ResourceEdit/ResourceList.cs | 4 +- .../Project/ICSharpCode.SharpDevelop.csproj | 1 + .../Project/Behaviors/DotNetStartBehavior.cs | 18 ++-- .../Src/Project/Behaviors/ResXConverter.cs | 85 +++++++++++++++++++ 5 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 src/Main/Base/Project/Src/Project/Behaviors/ResXConverter.cs diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ResourceStore.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ResourceStore.cs index 4e34fd61b8..91fd87aac6 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ResourceStore.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ResourceStore.cs @@ -204,7 +204,7 @@ namespace ICSharpCode.FormsDesigner.Services public IResourceWriter GetWriter() { this.stream = new MemoryStream(); - this.writer = CreateResourceWriter(this.stream, GetResourceType(OpenedFile.FileName)); + this.writer = CreateResourceWriter(this.stream, OpenedFile.FileName); return this.writer; } @@ -335,12 +335,12 @@ namespace ICSharpCode.FormsDesigner.Services return new ResXResourceReader(stream); } - internal static IResourceWriter CreateResourceWriter(Stream stream, ResourceType type) + internal static IResourceWriter CreateResourceWriter(Stream stream, string fileName) { - if (type == ResourceType.Resources) { + if (GetResourceType(fileName) == ResourceType.Resources) { return new ResourceWriter(stream); } - return new ResXResourceWriter(stream); + return new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, fileName)); } internal static ResourceType GetResourceType(string fileName) diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs index 738a5ebc85..7c6d199542 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs @@ -8,9 +8,9 @@ using System.Drawing.Printing; using System.IO; using System.Resources; using System.Windows.Forms; - using ICSharpCode.Core; using ICSharpCode.Core.WinForms; +using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Widgets.ListViewSorting; namespace ResourceEditor @@ -174,7 +174,7 @@ namespace ResourceEditor // write XML resource case ".resx": - ResXResourceWriter rxw = new ResXResourceWriter(stream); + ResXResourceWriter rxw = new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, filename)); foreach (KeyValuePair entry in resources) { if (entry.Value != null) { ResourceItem item = entry.Value; diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index af6b00fdc0..9d2970e0e6 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -345,6 +345,7 @@ + diff --git a/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs b/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs index 7e14a00052..f1c1c016f8 100644 --- a/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs +++ b/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs @@ -9,8 +9,6 @@ using System.Linq; using System.Xml.Linq; using ICSharpCode.Core; -using ICSharpCode.SharpDevelop.Debugging; -using ICSharpCode.SharpDevelop.Gui.OptionPanels; using ICSharpCode.SharpDevelop.Project.Converter; using ICSharpCode.SharpDevelop.Util; @@ -32,11 +30,15 @@ namespace ICSharpCode.SharpDevelop.Project } + new protected CompilableProject Project { + get { return (CompilableProject)base.Project; } + } + public override bool IsStartable { get { switch (StartAction) { case StartAction.Project: - return ((CompilableProject)Project).OutputType == OutputType.Exe || ((CompilableProject)Project).OutputType == OutputType.WinExe; + return Project.OutputType == OutputType.Exe || Project.OutputType == OutputType.WinExe; case StartAction.Program: return StartProgram.Length > 0; case StartAction.StartURL: @@ -102,7 +104,7 @@ namespace ICSharpCode.SharpDevelop.Project public override void ProjectCreationComplete() { - TargetFramework fx = ((CompilableProject)Project).CurrentTargetFramework; + TargetFramework fx = Project.CurrentTargetFramework; if (fx != null && (fx.IsBasedOn(TargetFramework.Net35) || fx.IsBasedOn(TargetFramework.Net35Client))) { AddDotnet35References(); } @@ -139,9 +141,9 @@ namespace ICSharpCode.SharpDevelop.Project { if (!Project.ReadOnly) { lock (Project.SyncRoot) { - TargetFramework oldFramework = ((CompilableProject)Project).CurrentTargetFramework; + TargetFramework oldFramework = Project.CurrentTargetFramework; if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { - ((CompilableProject)Project).SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor); + Project.SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor); } if (newFramework != null) { UpdateAppConfig(newFramework); @@ -170,6 +172,7 @@ namespace ICSharpCode.SharpDevelop.Project } AddOrRemoveExtensions(); Project.Save(); + ResXConverter.UpdateResourceFiles(Project); } } } @@ -227,7 +230,7 @@ namespace ICSharpCode.SharpDevelop.Project { // When changing the target framework, update any existing app.config // Also, for applications (not libraries), create an app.config is it is required for the target framework - bool createAppConfig = newFramework.RequiresAppConfigEntry && (((CompilableProject)Project).OutputType != OutputType.Library && ((CompilableProject)Project).OutputType != OutputType.Module); + bool createAppConfig = newFramework.RequiresAppConfigEntry && (Project.OutputType != OutputType.Library && Project.OutputType != OutputType.Module); string appConfigFileName = CompilableProject.GetAppConfigFile(Project, createAppConfig); if (appConfigFileName == null) @@ -368,3 +371,4 @@ namespace ICSharpCode.SharpDevelop.Project #endregion } } + diff --git a/src/Main/Base/Project/Src/Project/Behaviors/ResXConverter.cs b/src/Main/Base/Project/Src/Project/Behaviors/ResXConverter.cs new file mode 100644 index 0000000000..a3def5dedd --- /dev/null +++ b/src/Main/Base/Project/Src/Project/Behaviors/ResXConverter.cs @@ -0,0 +1,85 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections; +using System.IO; +using System.Linq; +using System.Resources; +using System.Text; + +namespace ICSharpCode.SharpDevelop.Project +{ + public static class ResXConverter + { + public static string ConvertTypeName(Type type, string fileName, CompilableProject project = null) + { + Version version; + if (project == null) + version = GetTargetFrameworkVersionFrom(fileName); + else + version = ScanVersion(project.TargetFrameworkVersion); + string name = type.AssemblyQualifiedName; + if (type.Assembly.GlobalAssemblyCache && IsFrameworkAssembly(type.Assembly.GetName().GetPublicKeyToken())) + name = type.AssemblyQualifiedName.Replace(", Version=4.0.0.0,", ", Version=" + PrintVersion(version) + ","); + return name; + } + + static readonly Version DotNet40 = new Version(4, 0); + static readonly Version DotNet20 = new Version(2, 0); + + static Version GetTargetFrameworkVersionFrom(string fileName) + { + if (ProjectService.OpenSolution == null) + return DotNet40; + var project = ProjectService.OpenSolution.FindProjectContainingFile(fileName) as CompilableProject; + if (project == null) + return DotNet40; + return ScanVersion(project.TargetFrameworkVersion); + } + + static Version ScanVersion(string versionString) + { + if (versionString == null) + return DotNet40; + Version version = new Version(versionString.TrimStart('v')); + if (version < DotNet40) + return DotNet20; + return DotNet40; + } + + static readonly string[] publicKeys = new[] { + "b77a5c561934e089", "b03f5f7f11d50a3a" + }; + + static bool IsFrameworkAssembly(byte[] publicKey) + { + string key = publicKey.Aggregate(new StringBuilder(), (sum, part) => sum.AppendFormat("{0:x2}", part)).ToString(); + return publicKeys.Contains(key); + } + + static string PrintVersion(Version version) + { + return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build > 0 ? version.Build : 0, version.Revision > 0 ? version.Revision : 0); + } + + /// + /// Update all .resx in a project. + /// + public static void UpdateResourceFiles(CompilableProject project) + { + foreach (var resXFile in project.Items.OfType().Where(f => ".resx".Equals(Path.GetExtension(f.FileName), StringComparison.OrdinalIgnoreCase))) { + using (var buffer = new MemoryStream()) { + using (var reader = new ResXResourceReader(resXFile.FileName) { UseResXDataNodes = true }) + using (var writer = new ResXResourceWriter(buffer, t => ConvertTypeName(t, resXFile.FileName, project))) { + foreach (DictionaryEntry entry in reader) { + writer.AddResource(entry.Key.ToString(), entry.Value); + } + } + File.WriteAllBytes(resXFile.FileName, buffer.ToArray()); + } + } + } + } +} + From c580b216975ae8136c96587ac1ea49f081250ce9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 16:40:01 +0200 Subject: [PATCH 13/94] fix leaked OpenedFile after creation of ViewContent fails, causes exceptions some later actions, see: http://community.sharpdevelop.net/forums/t/15625.aspx --- .../Src/AvalonEditViewContent.cs | 3 ++- .../Src/DefaultChangeWatcher.cs | 6 +++-- .../Project/Src/Services/File/FileService.cs | 16 ++++++----- .../Project/Src/Services/File/OpenedFile.cs | 27 ++++++++++--------- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs index 25b4989d99..c5be104c46 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs @@ -275,7 +275,8 @@ namespace ICSharpCode.AvalonEdit.AddIn { if (trackedFeature != null) trackedFeature.EndTracking(); - this.PrimaryFile.IsDirtyChanged -= PrimaryFile_IsDirtyChanged; + if (PrimaryFile != null) + this.PrimaryFile.IsDirtyChanged -= PrimaryFile_IsDirtyChanged; base.Dispose(); BookmarksDetach(); codeEditor.Dispose(); diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs index 8e139caac6..8529a90b53 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs @@ -197,8 +197,10 @@ namespace ICSharpCode.AvalonEdit.AddIn if (!disposed) { if (watcher != null) watcher.Dispose(); - this.textDocument.LineTrackers.Remove(this); - this.textDocument.UndoStack.PropertyChanged -= UndoStackPropertyChanged; + if (this.textDocument != null) { + this.textDocument.LineTrackers.Remove(this); + this.textDocument.UndoStack.PropertyChanged -= UndoStackPropertyChanged; + } disposed = true; } } diff --git a/src/Main/Base/Project/Src/Services/File/FileService.cs b/src/Main/Base/Project/Src/Services/File/FileService.cs index 9647d17919..f6cdf35023 100644 --- a/src/Main/Base/Project/Src/Services/File/FileService.cs +++ b/src/Main/Base/Project/Src/Services/File/FileService.cs @@ -161,7 +161,8 @@ namespace ICSharpCode.SharpDevelop /// Called by OpenedFile.UnregisterView to update the dictionary. internal static void OpenedFileClosed(OpenedFile file) { - if (openedFileDict[file.FileName] != file) + OpenedFile existing; + if (openedFileDict.TryGetValue(file.FileName, out existing) && existing != file) throw new ArgumentException("file must be registered"); openedFileDict.Remove(file.FileName); @@ -217,12 +218,15 @@ namespace ICSharpCode.SharpDevelop public void Invoke(string fileName) { OpenedFile file = FileService.GetOrCreateOpenedFile(FileName.Create(fileName)); - IViewContent newContent = binding.CreateContentForFile(file); - if (newContent != null) { - DisplayBindingService.AttachSubWindows(newContent, false); - WorkbenchSingleton.Workbench.ShowView(newContent, switchToOpenedView); + try { + IViewContent newContent = binding.CreateContentForFile(file); + if (newContent != null) { + DisplayBindingService.AttachSubWindows(newContent, false); + WorkbenchSingleton.Workbench.ShowView(newContent, switchToOpenedView); + } + } finally { + file.CloseIfAllViewsClosed(); } - file.CloseIfAllViewsClosed(); } } diff --git a/src/Main/Base/Project/Src/Services/File/OpenedFile.cs b/src/Main/Base/Project/Src/Services/File/OpenedFile.cs index fcb8832b79..e528435ac1 100644 --- a/src/Main/Base/Project/Src/Services/File/OpenedFile.cs +++ b/src/Main/Base/Project/Src/Services/File/OpenedFile.cs @@ -123,19 +123,24 @@ namespace ICSharpCode.SharpDevelop if (view == null) throw new ArgumentNullException("view"); - if (currentView != view) { - if (currentView == null) { - SwitchedToView(view); - } else { - try { - inLoadOperation = true; - using (Stream sourceStream = OpenRead()) { - view.Load(this, sourceStream); + try { + if (currentView != view) { + if (currentView == null) { + SwitchedToView(view); + } else { + try { + inLoadOperation = true; + using (Stream sourceStream = OpenRead()) { + view.Load(this, sourceStream); + } + } finally { + inLoadOperation = false; } - } finally { - inLoadOperation = false; } } + } catch (Exception) { + view.Dispose(); + throw; } } @@ -276,8 +281,6 @@ namespace ICSharpCode.SharpDevelop currentView = newView; return; } - } - if (currentView != null) { SaveCurrentView(); } try { From 2513d08f9f90c981e7fd599a3a705da978f32cf1 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 31 Mar 2012 16:46:36 +0100 Subject: [PATCH 14/94] Implement advanced options for generating service references. --- .../Project/ICSharpCode.SharpDevelop.csproj | 1 - .../AddServiceReferenceViewModel.cs | 9 +- .../AdvancedServiceViewModel.cs | 76 ++++++++---- .../IProjectWithServiceReferences.cs | 2 + .../IServiceReferenceProxyGenerator.cs | 2 +- .../ProjectWithServiceReferences.cs | 8 ++ .../ServiceReferenceFileGenerator.cs | 1 + .../ServiceReferenceGenerator.cs | 2 + .../ServiceReferenceGeneratorOptions.cs | 116 ++++++++++++++++++ .../ServiceReferenceProxyGenerator.cs | 3 +- .../ServiceReference/SvcUtilCommandLine.cs | 21 +++- .../ServiceReference/SvcUtilOptions.cs | 22 ---- .../ServiceReference/SvcUtilRunner.cs | 4 +- .../ICSharpCode.SharpDevelop.Tests.csproj | 1 + .../ProjectWithServiceReferencesTests.cs | 19 +++ .../ServiceReferenceGeneratorOptionsTests.cs | 75 +++++++++++ .../ServiceReferenceGeneratorTests.cs | 52 +++++++- 17 files changed, 355 insertions(+), 59 deletions(-) delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs create mode 100644 src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorOptionsTests.cs diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 9d2970e0e6..af0ef49e4b 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -292,7 +292,6 @@ - diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs index 7aa21db32f..da96e39ec0 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs @@ -37,6 +37,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference List mruServices = new List(); string selectedService; IProject project; + ServiceReferenceGenerator serviceGenerator; List items = new List (); ServiceItem myItem; @@ -53,6 +54,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public AddServiceReferenceViewModel(IProject project) { this.project = project; + this.serviceGenerator = new ServiceReferenceGenerator(project); discoverButtonContent = "Discover"; HeadLine = header1 + header2; @@ -114,10 +116,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference void ExecuteAdvancedDialogCommand() { - var vm = new AdvancedServiceViewModel(); + var vm = new AdvancedServiceViewModel(serviceGenerator.Options.Clone()); var view = new AdvancedServiceDialog(); view.DataContext = vm; - view.ShowDialog(); + if (view.ShowDialog() ?? false) { + serviceGenerator.Options = vm.Options; + } } #endregion @@ -376,7 +380,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public void AddServiceReference() { - var serviceGenerator = new ServiceReferenceGenerator(project); serviceGenerator.Options.Namespace = defaultNameSpace; serviceGenerator.Options.Url = discoveryUri.ToString(); serviceGenerator.AddServiceReference(); diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs index 7230ec09da..4f3162a960 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs @@ -39,14 +39,23 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public enum DictionaryCollectionTypes { + [Description("System.Collections.Generic.Dictionary")] Dictionary, + [Description("System.Collections.Generic.SortedList")] SortedList, + [Description("System.Collections.Generic.SortedDictionary")] SortedDictionary, + [Description("System.Collections.Hashtable")] HashTable, + [Description("System.Collections.ObjectModel.KeyedCollection")] KeyedCollection, + [Description("System.Collections.SortedList")] SortedList_2, + [Description("System.Collections.Specialized.HybridDictionary")] HybridDictionary, + [Description("System.Collections.Specialized.ListDictionary")] ListDictionary, + [Description("System.Collections.Specialized.OrderedDictionary")] OrderedDictionary } @@ -55,10 +64,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference string compatibilityText = "Add a Web Reference instead of a Service Reference. "; string c_2 = "This will generate code based on .NET Framework 2.0 Web Services technology."; string accesslevel = "Access level for generated classes:"; + ServiceReferenceGeneratorOptions options; - public AdvancedServiceViewModel() + public AdvancedServiceViewModel(ServiceReferenceGeneratorOptions options) { - Title ="Service Reference Settings"; + this.options = options; + UpdateSettingsFromOptions(); + Title = "Service Reference Settings"; UseReferencedAssemblies = true; BitmapSource image = PresentationResourceService.GetBitmapSource("Icons.16x16.Reference"); AssembliesToReference = new ObservableCollection(); @@ -73,6 +85,36 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference AssembliesToReference.Add(new CheckableImageAndDescription(image, "System.Xml.Linq")); } + public ServiceReferenceGeneratorOptions Options { + get { return options; } + } + + void UpdateSettingsFromOptions() + { + UpdateSelectedModifier(); + UpdateReferencedTypes(); + } + + void UpdateReferencedTypes() + { + if (options.UseTypesInProjectReferences) { + this.ReuseTypes = true; + this.UseReferencedAssemblies = true; + } else { + this.ReuseTypes = false; + this.UseReferencedAssemblies = false; + } + } + + void UpdateSelectedModifier() + { + if (options.GenerateInternalClasses) { + SelectedModifier = Modifiers.Internal; + } else { + SelectedModifier = Modifiers.Public; + } + } + public string Title { get; set; } public string AccessLevel { @@ -89,42 +131,34 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference } } - bool generateAsyncOperations; - public bool GenerateAsyncOperations { - get { return generateAsyncOperations; } + get { return options.GenerateAsyncOperations; } set { - generateAsyncOperations = value; + options.GenerateAsyncOperations = value; base.RaisePropertyChanged(() => GenerateAsyncOperations); } } - bool generateMessageContract; - public bool GenerateMessageContract { - get { return generateMessageContract; } + get { return options.GenerateMessageContract; } set { - generateMessageContract = value; + options.GenerateMessageContract = value; base.RaisePropertyChanged(() => GenerateMessageContract); } } - CollectionTypes collectionType; - public CollectionTypes CollectionType { - get { return collectionType; } + get { return options.ArrayCollectionType; } set { - collectionType = value; + options.ArrayCollectionType = value; base.RaisePropertyChanged(() => CollectionType); } } - DictionaryCollectionTypes dictionaryCollectionType; - public DictionaryCollectionTypes DictionaryCollectionType { - get { return dictionaryCollectionType; } + get { return options.DictionaryCollectionType; } set { - dictionaryCollectionType = value; + options.DictionaryCollectionType = value; base.RaisePropertyChanged(() => DictionaryCollectionType); } } @@ -140,12 +174,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference } } - bool reuseTypes; - public bool ReuseTypes { - get { return reuseTypes; } + get { return options.UseTypesInProjectReferences; } set { - reuseTypes = value; + options.UseTypesInProjectReferences = value; base.RaisePropertyChanged(() => ReuseTypes); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs index 51aa9d7cc8..0af41fb51c 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { @@ -19,5 +20,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference bool HasAppConfigFile(); string GetAppConfigFileName(); void AddAppConfigFile(); + IEnumerable GetReferences(); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs index c8aa3ea183..e5eab2f37b 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs @@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public interface IServiceReferenceProxyGenerator { - ServiceReferenceGeneratorOptions Options { get; } + ServiceReferenceGeneratorOptions Options { get; set; } void GenerateProxyFile(); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs index 8bda086abc..d01be3b39c 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs @@ -3,6 +3,7 @@ using System; using System.CodeDom.Compiler; +using System.Collections.Generic; using System.IO; using System.Linq; @@ -156,5 +157,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { return Path.Combine(project.Directory, "app.config"); } + + public IEnumerable GetReferences() + { + foreach (ProjectItem item in project.GetItemsOfType(ItemType.Reference)) { + yield return item.FileName; + } + } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs index 7dfcfbb36f..ba54756fca 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs @@ -28,6 +28,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public ServiceReferenceGeneratorOptions Options { get { return proxyGenerator.Options; } + set { proxyGenerator.Options = value; } } public void GenerateProxyFile() diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs index 6661cd87d0..e018ee48f7 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs @@ -40,6 +40,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public ServiceReferenceGeneratorOptions Options { get { return fileGenerator.Options; } + set { fileGenerator.Options = value; } } public void AddServiceReference() @@ -70,6 +71,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference Options.NoAppConfig = false; Options.MergeAppConfig = project.HasAppConfigFile(); Options.MapProjectLanguage(project.Language); + Options.AddProjectReferencesIfUsingTypesFromProjectReferences(project.GetReferences()); fileGenerator.GenerateProxyFile(); return referenceFileName; diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs index d473c8ef3a..756dc9e666 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs @@ -2,19 +2,33 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public class ServiceReferenceGeneratorOptions { + List assemblies = new List(); + public ServiceReferenceGeneratorOptions() + : this(new string[0]) { + } + + public ServiceReferenceGeneratorOptions(IEnumerable assemblies) + { + this.assemblies.AddRange(assemblies); this.AppConfigFileName = String.Empty; this.MergeAppConfig = false; this.OutputFileName = String.Empty; this.Namespace = String.Empty; this.Language = "CS"; this.NoAppConfig = true; + this.UseTypesInProjectReferences = true; + this.ArrayCollectionType = CollectionTypes.Array; + this.DictionaryCollectionType = DictionaryCollectionTypes.Dictionary; } public string Namespace { get; set; } @@ -24,6 +38,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public string AppConfigFileName { get; set; } public bool NoAppConfig { get; set; } public bool MergeAppConfig { get; set; } + public bool GenerateInternalClasses { get; set; } + public bool GenerateAsyncOperations { get; set; } + public bool GenerateMessageContract { get; set; } + public bool UseTypesInProjectReferences { get; set; } + public CollectionTypes ArrayCollectionType { get; set; } + public DictionaryCollectionTypes DictionaryCollectionType { get; set; } public void MapProjectLanguage(string language) { @@ -33,5 +53,101 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference Language = "CS"; } } + + public IList Assemblies { + get { return assemblies; } + } + + public ServiceReferenceGeneratorOptions Clone() + { + return new ServiceReferenceGeneratorOptions(this.assemblies) { + Namespace = this.Namespace, + OutputFileName = this.OutputFileName, + Url = this.Url, + Language = this.Language, + AppConfigFileName = this.AppConfigFileName, + NoAppConfig = this.NoAppConfig, + MergeAppConfig = this.MergeAppConfig, + + UseTypesInProjectReferences = this.UseTypesInProjectReferences, + ArrayCollectionType = this.ArrayCollectionType, + DictionaryCollectionType = this.DictionaryCollectionType, + GenerateInternalClasses = this.GenerateInternalClasses, + GenerateAsyncOperations = this.GenerateAsyncOperations, + GenerateMessageContract = this.GenerateMessageContract + }; + } + + public string GetNamespaceMapping() + { + if (Namespace != null) { + return "*," + Namespace; + } + return null; + } + + public string GetArrayCollectionTypeDescription() + { + string description = GetEnumTypeDescription(ArrayCollectionType.GetType(), ArrayCollectionType.ToString()); + return description + GetGenericTypeSuffix(ArrayCollectionType); + } + + string GetEnumTypeDescription(Type type, string name) + { + foreach (FieldInfo field in type.GetFields()) { + if (field.IsStatic) { + if (field.Name == name) { + return GetDescription(field); + } + } + } + return null; + } + + string GetDescription(FieldInfo field) + { + foreach (DescriptionAttribute attribute in field.GetCustomAttributes(typeof(DescriptionAttribute), false)) + return attribute.Description; + return field.Name; + } + + string GetGenericTypeSuffix(CollectionTypes type) + { + switch (type) { + case CollectionTypes.List: + case CollectionTypes.LinkedList: + case CollectionTypes.ObservableCollection: + case CollectionTypes.Collection: + case CollectionTypes.BindingList: + return "`1"; + } + return String.Empty; + } + + public string GetDictionaryCollectionTypeDescription() + { + string description = GetEnumTypeDescription(DictionaryCollectionType.GetType(), DictionaryCollectionType.ToString()); + return description + GetGenericTypeSuffix(DictionaryCollectionType); + } + + string GetGenericTypeSuffix(DictionaryCollectionTypes type) + { + switch (type) { + case DictionaryCollectionTypes.SortedList_2: + case DictionaryCollectionTypes.HashTable: + case DictionaryCollectionTypes.HybridDictionary: + case DictionaryCollectionTypes.ListDictionary: + case DictionaryCollectionTypes.OrderedDictionary: + return String.Empty; + } + return "`2"; + } + + public void AddProjectReferencesIfUsingTypesFromProjectReferences(IEnumerable assemblies) + { + if (UseTypesInProjectReferences) { + Assemblies.AddRange(assemblies); + } + } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs index fd40cc9e3d..c56892b146 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs @@ -10,10 +10,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public class ServiceReferenceProxyGenerator : IServiceReferenceProxyGenerator { - SvcUtilOptions options = new SvcUtilOptions(); + ServiceReferenceGeneratorOptions options = new ServiceReferenceGeneratorOptions(); public ServiceReferenceGeneratorOptions Options { get { return options; } + set { options = value; } } public void GenerateProxyFile() diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs index 4b6ceca313..dd53e8c2af 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; using System.Text; namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -10,7 +11,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { StringBuilder argumentBuilder = new StringBuilder(); - public SvcUtilCommandLine(SvcUtilOptions options) + public SvcUtilCommandLine(ServiceReferenceGeneratorOptions options) { GenerateCommandLine(options); } @@ -18,14 +19,19 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public string Command { get; set; } public string Arguments { get; private set; } - void GenerateCommandLine(SvcUtilOptions options) + void GenerateCommandLine(ServiceReferenceGeneratorOptions options) { - AppendIfNotEmpty("/out:", options.OutputFileName); - AppendIfNotEmpty("/namespace:", options.GetNamespaceMapping()); + AppendIfNotEmpty("/o:", options.OutputFileName); + AppendIfNotEmpty("/n:", options.GetNamespaceMapping()); AppendIfNotEmpty("/language:", options.Language); AppendIfTrue("/noConfig", options.NoAppConfig); + AppendIfTrue("/i", options.GenerateInternalClasses); + AppendIfTrue("/a", options.GenerateAsyncOperations); AppendIfTrue("/mergeConfig", options.MergeAppConfig); AppendIfNotEmpty("/config:", options.AppConfigFileName); + AppendIfNotEmpty("/ct:", options.GetArrayCollectionTypeDescription()); + AppendIfNotEmpty("/ct:", options.GetDictionaryCollectionTypeDescription()); + AppendAssemblyReferences(options.Assemblies); AppendIfNotEmpty(options.Url); this.Arguments = argumentBuilder.ToString(); @@ -83,5 +89,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { return text.IndexOf(' ') >= 0; } + + void AppendAssemblyReferences(IEnumerable assemblies) + { + foreach (string assembly in assemblies) { + AppendIfNotEmpty("/r:", assembly); + } + } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs deleted file mode 100644 index 10a2b140ca..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference -{ - public class SvcUtilOptions : ServiceReferenceGeneratorOptions - { - public SvcUtilOptions() - { - } - - public string GetNamespaceMapping() - { - if (Namespace != null) { - return "*," + Namespace; - } - return null; - } - } -} diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs index eb1e6b4a17..8218a9fb34 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs @@ -8,12 +8,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public class SvcUtilRunner { - public SvcUtilRunner(SvcUtilOptions options) + public SvcUtilRunner(ServiceReferenceGeneratorOptions options) { this.Options = options; } - public SvcUtilOptions Options { get; private set; } + public ServiceReferenceGeneratorOptions Options { get; private set; } public void Run() { diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj index 30b472fc8b..84bc3a0650 100644 --- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj +++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj @@ -101,6 +101,7 @@ + diff --git a/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs b/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs index f3f7efe2fd..06a3c15521 100644 --- a/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs +++ b/src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs @@ -97,6 +97,12 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences ProjectService.AddProjectItem(msbuildProject, fileItem); } + void AddGacReferenceToProject(string name) + { + var referenceItem = new ReferenceProjectItem(msbuildProject, name); + ProjectService.AddProjectItem(msbuildProject, referenceItem); + } + int CountAssemblyReferencesInMSBuildProject() { return msbuildProject.GetItemsOfType(ItemType.Reference).Count(); @@ -369,5 +375,18 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences Assert.AreEqual(@"d:\projects\MyProject\SubFolder\app.config", fileName); } + + [Test] + public void GetReferences_ProjectHasGacReference_ReturnsGacReference() + { + CreateProjectWithMSBuildProject(); + AddGacReferenceToProject("System.Xml"); + IEnumerable references = project.GetReferences(); + + string[] expectedReferences = new string[] { + "System.Xml" + }; + CollectionAssert.AreEqual(expectedReferences, references); + } } } diff --git a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorOptionsTests.cs b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorOptionsTests.cs new file mode 100644 index 0000000000..372ea5ec61 --- /dev/null +++ b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorOptionsTests.cs @@ -0,0 +1,75 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference; +using NUnit.Framework; + +namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences +{ + [TestFixture] + public class ServiceReferenceGeneratorOptionsTests + { + ServiceReferenceGeneratorOptions options; + + void CreateOptions() + { + options = new ServiceReferenceGeneratorOptions(); + } + + [Test] + public void GetArrayCollectionTypeDescription_List_ReturnsFullyQualifiedListName() + { + CreateOptions(); + options.ArrayCollectionType = CollectionTypes.List; + + string text = options.GetArrayCollectionTypeDescription(); + + Assert.AreEqual("System.Collections.Generic.List`1", text); + } + + [Test] + public void GetArrayCollectionTypeDescription_ArrayList_ReturnsFullyQualifiedArrayListName() + { + CreateOptions(); + options.ArrayCollectionType = CollectionTypes.ArrayList; + + string text = options.GetArrayCollectionTypeDescription(); + + Assert.AreEqual("System.Collections.ArrayList", text); + } + + [Test] + public void GetDictionaryCollectionTypeDescription_HashTable_ReturnsFullyQualifiedHashTableName() + { + CreateOptions(); + options.DictionaryCollectionType = DictionaryCollectionTypes.HashTable; + + string text = options.GetDictionaryCollectionTypeDescription(); + + Assert.AreEqual("System.Collections.Hashtable", text); + } + + [Test] + public void GetDictionaryCollectionTypeDescription_Dictionary_ReturnsFullyQualifiedDictionaryTypeName() + { + CreateOptions(); + options.DictionaryCollectionType = DictionaryCollectionTypes.Dictionary; + + string text = options.GetDictionaryCollectionTypeDescription(); + + Assert.AreEqual("System.Collections.Generic.Dictionary`2", text); + } + + [Test] + public void GetDictionaryCollectionTypeDescription_GenericSortedList_ReturnsFullyQualifiedGenericSortedListName() + { + CreateOptions(); + options.DictionaryCollectionType = DictionaryCollectionTypes.SortedList; + + string text = options.GetDictionaryCollectionTypeDescription(); + + Assert.AreEqual("System.Collections.Generic.SortedList`2", text); + } + } +} diff --git a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs index 30b3c0420f..232c6f67c6 100644 --- a/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs +++ b/src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; using System.ServiceModel.Description; using ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference; using ICSharpCode.SharpDevelop.Project; @@ -20,15 +21,16 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences ServiceReferenceFileGenerator fileGenerator; IFileSystem fakeFileSystem; ServiceReferenceGeneratorOptions options; + List projectReferences; void CreateGenerator() { options = new ServiceReferenceGeneratorOptions(); fakeProject = MockRepository.GenerateStub(); + projectReferences = new List(); + fakeProject.Stub(p => p.GetReferences()).Return(projectReferences); fakeProxyGenerator = MockRepository.GenerateStub(); - fakeProxyGenerator - .Stub(p => p.Options) - .Return(options); + fakeProxyGenerator.Options = options; fakeReferenceMapGenerator = MockRepository.GenerateStub(); fileGenerator = new ServiceReferenceFileGenerator(fakeProxyGenerator, fakeReferenceMapGenerator); fakeFileSystem = MockRepository.GenerateStub(); @@ -110,6 +112,11 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences fakeProject.Stub(p => p.HasAppConfigFile()).Return(hasAppConfigFile); } + void AddReferenceToProject(string reference) + { + projectReferences.Add(reference); + } + [Test] public void AddServiceReference_GeneratesServiceReference_ProxyFileIsGenerated() { @@ -320,5 +327,44 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences Assert.IsTrue(fakeProxyGenerator.Options.MergeAppConfig); fakeProject.AssertWasNotCalled(p => p.AddAppConfigFile()); } + + [Test] + public void AddServiceReference_UseTypesInProjectReferencesIsTrue_ProjectReferencesAddedToOptions() + { + CreateGenerator(); + AddProxyFileNameForServiceName("MyService"); + AddMapFileNameForServiceName("MyService"); + generator.Options.Namespace = "MyService"; + generator.Options.UseTypesInProjectReferences = true; + + AddReferenceToProject("System.Windows.Forms"); + AddReferenceToProject(@"d:\projects\MyProject\lib\MyLib.dll"); + + generator.AddServiceReference(); + + string[] expectedReferences = new string[] { + "System.Windows.Forms", + @"d:\projects\MyProject\lib\MyLib.dll" + }; + + CollectionAssert.AreEqual(expectedReferences, fakeProxyGenerator.Options.Assemblies); + } + + [Test] + public void AddServiceReference_UseTypesInProjectReferencesIsFalse_NoProjectReferencesAddedToOptions() + { + CreateGenerator(); + AddProxyFileNameForServiceName("MyService"); + AddMapFileNameForServiceName("MyService"); + generator.Options.Namespace = "MyService"; + generator.Options.UseTypesInProjectReferences = false; + + AddReferenceToProject("System.Windows.Forms"); + AddReferenceToProject(@"d:\projects\MyProject\lib\MyLib.dll"); + + generator.AddServiceReference(); + + Assert.AreEqual(0, fakeProxyGenerator.Options.Assemblies.Count); + } } } From 06df4bbea1cbed869a4706a0dfcf9feec0aa5916 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 31 Mar 2012 16:47:34 +0100 Subject: [PATCH 15/94] Use svcutil built against .NET 4.0 --- .../Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs index 7561f8d7d5..d4893eb6d1 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference sdkPath = TryGetLocalMachineSdkInstallPath(); } if (sdkPath != null) { - string fullPath = Path.Combine(sdkPath, @"bin\svcutil.exe"); + string fullPath = Path.Combine(sdkPath, @"bin\NETFX 4.0 Tools\svcutil.exe"); exists = File.Exists(fullPath); if (exists) { fileName = fullPath; From 482660ffe3360f2c95243daf4921e6a3a77f6643 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 31 Mar 2012 17:06:37 +0100 Subject: [PATCH 16/94] Remove Web Reference features from service reference dialog. --- .../AdvancedServiceDialog.xaml | 28 ++----------------- .../AdvancedServiceViewModel.cs | 9 +----- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml index dc8189f110..bf285b5794 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml @@ -1,4 +1,4 @@ - + @@ -175,30 +175,6 @@ --> - - - - - - - - - - - - AssembliesToReference { get; private set; } - - public string CompatibilityText - { - get { return compatibilityText + c_2; } - } + public ObservableCollection AssembliesToReference { get; private set; } } } From 6e0c1e194fc8b1cdbc072620935b2ff1c0186a29 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 19:50:45 +0200 Subject: [PATCH 17/94] fix exception 3396 --- .../Src/DesignerGenerator/AbstractDesignerGenerator.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs index c656b83996..cda90f1c2e 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs @@ -337,10 +337,10 @@ namespace ICSharpCode.FormsDesigner foreach (var stmt in initializeComponent.Statements.OfType().Where(ces => ces.Expression is CodeMethodInvokeExpression)) { CodeMethodInvokeExpression invocation = (CodeMethodInvokeExpression)stmt.Expression; - if (invocation.Method.TargetObject is CodeCastExpression) { - CodeCastExpression expr = (CodeCastExpression)invocation.Method.TargetObject; - CodeFieldReferenceExpression fieldRef = (CodeFieldReferenceExpression)expr.Expression; - if (!(fieldRef.TargetObject is CodeThisReferenceExpression)) + CodeCastExpression expr = invocation.Method.TargetObject as CodeCastExpression; + if (expr != null) { + CodeFieldReferenceExpression fieldRef = expr.Expression as CodeFieldReferenceExpression; + if (fieldRef == null || !(fieldRef.TargetObject is CodeThisReferenceExpression)) continue; if (expr.TargetType.BaseType != "System.ComponentModel.ISupportInitialize") continue; From 50fd5bc2421aeb4968ae8a28c7f320aacd36193a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 20:06:38 +0200 Subject: [PATCH 18/94] fix detection of UTF-16 BOM http://community.sharpdevelop.net/forums/p/15627/39925.aspx#39925 --- src/Main/Base/Project/Src/Services/MimeTypeDetection.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs b/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs index 4a2c97c7c3..826f071b03 100644 --- a/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs +++ b/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs @@ -25,7 +25,11 @@ namespace ICSharpCode.SharpDevelop static unsafe string FindMimeType(byte[] buffer, int offset, int length) { - if (buffer.Length == 0) + if (buffer.Length == 0 || + // UTF-16 Big Endian + (buffer.Length >= 2 && buffer[0] == 0xFE && buffer[1] == 0xFF) || + // UTF-16 Little Endian + (buffer.Length >= 2 && buffer[0] == 0xFF && buffer[1] == 0xFE)) return "text/plain"; fixed (byte *b = &buffer[offset]) { From cf5f9a1836b2e312f73da1a88c64b5d793dd901c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 21:45:30 +0200 Subject: [PATCH 19/94] fix detection of UTF-32 and add Unit Tests --- .../Project/Src/Services/MimeTypeDetection.cs | 14 ++------ .../ICSharpCode.SharpDevelop.Tests.csproj | 1 + src/Main/Base/Test/MimeDetectionTests.cs | 34 +++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/Main/Base/Test/MimeDetectionTests.cs diff --git a/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs b/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs index 826f071b03..56db790fdf 100644 --- a/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs +++ b/src/Main/Base/Project/Src/Services/MimeTypeDetection.cs @@ -29,7 +29,9 @@ namespace ICSharpCode.SharpDevelop // UTF-16 Big Endian (buffer.Length >= 2 && buffer[0] == 0xFE && buffer[1] == 0xFF) || // UTF-16 Little Endian - (buffer.Length >= 2 && buffer[0] == 0xFF && buffer[1] == 0xFE)) + (buffer.Length >= 2 && buffer[0] == 0xFF && buffer[1] == 0xFE) || + // UTF-32 Big Endian + (buffer.Length >= 4 && buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0xFE && buffer[3] == 0xFF)) return "text/plain"; fixed (byte *b = &buffer[offset]) { @@ -60,15 +62,5 @@ namespace ICSharpCode.SharpDevelop stream.Position = 0; return FindMimeType(buffer, 0, stream.Read(buffer, 0, buffer.Length)); } - - public static string FindMimeType(ITextBuffer buffer) - { - if (buffer == null) - throw new ArgumentNullException("buffer"); - // TODO USE PROPER ENCODING! - // Maybe use Encoding detection from AvalonEdit? - byte[] bytes = Encoding.Default.GetBytes(buffer.TextLength > BUFFER_SIZE ? buffer.GetText(0, BUFFER_SIZE) : buffer.Text); - return FindMimeType(bytes, 0, bytes.Length); - } } } diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj index 84bc3a0650..74270896eb 100644 --- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj +++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj @@ -81,6 +81,7 @@ + diff --git a/src/Main/Base/Test/MimeDetectionTests.cs b/src/Main/Base/Test/MimeDetectionTests.cs new file mode 100644 index 0000000000..d3b178e180 --- /dev/null +++ b/src/Main/Base/Test/MimeDetectionTests.cs @@ -0,0 +1,34 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using NUnit.Framework; + +namespace ICSharpCode.SharpDevelop.Tests +{ + [TestFixture] + public class MimeTypeDetectionTests + { + [Test] + public void TextPlain() + { + // always open empty files with text editor + TestMime(new byte[] {}, "text/plain"); + // UTF-8 + TestMime(new byte[] { 0xEF, 0xBB, 0xBF }, "text/plain"); + // UTF-16 Big Endian + TestMime(new byte[] { 0xFE, 0xFF }, "text/plain"); + // UTF-16 Little Endian + TestMime(new byte[] { 0xFF, 0xFE }, "text/plain"); + // UTF-32 Big Endian + TestMime(new byte[] { 0x00, 0x00, 0xFE, 0xFF }, "text/plain"); + // UTF-32 Little Endian + TestMime(new byte[] { 0xFF, 0xFE, 0x00, 0x00 }, "text/plain"); + } + + void TestMime(byte[] bytes, string expectedMime) + { + Assert.AreEqual(expectedMime, MimeTypeDetection.FindMimeType(bytes)); + } + } +} From 00edc9c069ab5db854ccfba962a2212e83e3974c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 21:47:58 +0200 Subject: [PATCH 20/94] use custom SearchableFileContentFinder to avoid possible loss of information due to wrong encoding detection --- .../Project/Engine/SearchManager.cs | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs index c687a855e0..aeb488b38a 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs @@ -5,9 +5,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; - using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Highlighting; @@ -31,21 +31,64 @@ namespace SearchAndReplace public static IObservable FindAllParallel(ISearchStrategy strategy, SearchLocation location, IProgressMonitor progressMonitor) { currentSearchRegion = null; - ParseableFileContentFinder fileFinder = new ParseableFileContentFinder(); + SearchableFileContentFinder fileFinder = new SearchableFileContentFinder(); return new SearchRun(strategy, fileFinder, location.GenerateFileList(), progressMonitor) { Target = location.Target, Selection = location.Selection }; } public static IEnumerable FindAll(ISearchStrategy strategy, SearchLocation location, IProgressMonitor progressMonitor) { currentSearchRegion = null; - ParseableFileContentFinder fileFinder = new ParseableFileContentFinder(); + SearchableFileContentFinder fileFinder = new SearchableFileContentFinder(); return new SearchRun(strategy, fileFinder, location.GenerateFileList(), progressMonitor) { Target = location.Target, Selection = location.Selection }.GetResults(); } + class SearchableFileContentFinder + { + FileName[] viewContentFileNamesCollection = WorkbenchSingleton.SafeThreadFunction(() => FileService.OpenedFiles.Select(f => f.FileName).ToArray()); + + static ITextBuffer ReadFile(FileName fileName) + { + OpenedFile openedFile = FileService.GetOpenedFile(fileName); + if (openedFile == null) + return null; + IFileDocumentProvider provider = FileService.GetOpenFile(fileName) as IFileDocumentProvider; + if (provider == null) + return null; + IDocument doc = provider.GetDocumentForFile(openedFile); + if (doc == null) + return null; + return doc.CreateSnapshot(); + } + + public ITextBuffer Create(FileName fileName) + { + foreach (FileName name in viewContentFileNamesCollection) { + if (FileUtility.IsEqualFileName(name, fileName)) { + ITextBuffer buffer = WorkbenchSingleton.SafeThreadFunction(ReadFile, fileName); + if (buffer != null) + return buffer; + } + } + try { + using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { + if (MimeTypeDetection.FindMimeType(stream).StartsWith("text/")) { + stream.Position = 0; + return new StringTextBuffer(ICSharpCode.AvalonEdit.Utils.FileReader.ReadFileContent(stream, Encoding.Default)); + } + } + return null; + } catch (IOException) { + return null; + } catch (UnauthorizedAccessException) { + return null; + } + } + } + class SearchRun : IObservable, IDisposable { ISearchStrategy strategy; - ParseableFileContentFinder fileFinder; + SearchableFileContentFinder fileFinder; IEnumerable fileList; IProgressMonitor monitor; CancellationTokenSource cts; @@ -54,7 +97,7 @@ namespace SearchAndReplace public ISegment Selection { get; set; } - public SearchRun(ISearchStrategy strategy, ParseableFileContentFinder fileFinder, IEnumerable fileList, IProgressMonitor monitor) + public SearchRun(ISearchStrategy strategy, SearchableFileContentFinder fileFinder, IEnumerable fileList, IProgressMonitor monitor) { this.strategy = strategy; this.fileFinder = fileFinder; @@ -151,8 +194,6 @@ namespace SearchAndReplace ThrowIfCancellationRequested(); - if (!MimeTypeDetection.FindMimeType(buffer).StartsWith("text/", StringComparison.Ordinal)) - return null; var source = DocumentUtilitites.GetTextSource(buffer); TextDocument document = null; DocumentHighlighter highlighter = null; @@ -213,7 +254,7 @@ namespace SearchAndReplace public SearchResultMatch FindNext() { // Setup search inside current or first file. - ParseableFileContentFinder finder = new ParseableFileContentFinder(); + SearchableFileContentFinder finder = new SearchableFileContentFinder(); int index = GetCurrentFileIndex(); int i = 0; int searchOffset = 0; From 405ef3fc0a3a472fac3b05785b36581f1ba145ba Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 31 Mar 2012 23:36:36 +0200 Subject: [PATCH 21/94] disable UDC if debugger is attached to avoid dead-locks --- .../UsageDataCollector.AddIn/AnalyticsMonitor.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.cs b/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.cs index dcd0637930..0d47ff46e0 100644 --- a/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.cs +++ b/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.cs @@ -50,6 +50,8 @@ namespace ICSharpCode.UsageDataCollector static void AsyncEnableDisable() { + if (System.Diagnostics.Debugger.IsAttached) + return; if (Enabled) { Instance.OpenSession(); } else { @@ -242,6 +244,8 @@ namespace ICSharpCode.UsageDataCollector { public override void Run() { + if (System.Diagnostics.Debugger.IsAttached) + return; if (AnalyticsMonitor.Enabled) AnalyticsMonitor.Instance.OpenSession(); } From dd1c8955f64791f2709183e7b5134b365be7d62b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 1 Apr 2012 11:02:36 +0200 Subject: [PATCH 22/94] fix exception 3265 again --- .../Debugger.AddIn/Pads/Controls/WatchList.xaml.cs | 7 ++++--- .../Pads/Controls/WatchListAutoCompleteCell.cs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchList.xaml.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchList.xaml.cs index 07ad0ec678..2809cb6adf 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchList.xaml.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchList.xaml.cs @@ -69,17 +69,18 @@ namespace Debugger.AddIn.Pads.Controls void WatchListAutoCompleteCellCommandEntered(object sender, EventArgs e) { - if (SelectedNode == null) return; + var selectedNode = SelectedNode; + if (selectedNode == null) return; if (WatchType != WatchListType.Watch) return; var cell = ((WatchListAutoCompleteCell)sender); - SelectedNode.Node.Name = cell.CommandText; + selectedNode.Node.Name = cell.CommandText; myList.UnselectAll(); if (WatchType == WatchListType.Watch && WatchPad.Instance != null) { WatchPad.Instance.InvalidatePad(); } - SelectedNode.IsEditing = false; + selectedNode.IsEditing = false; } void MyListPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchListAutoCompleteCell.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchListAutoCompleteCell.cs index 60e8147132..4b26e798e4 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchListAutoCompleteCell.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/WatchListAutoCompleteCell.cs @@ -121,9 +121,9 @@ namespace Debugger.AddIn.Pads.Controls // FIXME workaround the NRefactory issue that needs a ; at the end if (language == "C#" || language == "CSharp") { - if(!command.EndsWith(";")) + if (!command.EndsWith(";")) command += ";"; - // FIXME only one string should be available; highlighting expects C#, supproted language, CSharp + // FIXME only one string should be available; highlighting expects C#, supported language, CSharp language = "CSharp"; } From 3abf671f4d509e5e351e0541cf67f2e4fc85eec9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 1 Apr 2012 11:40:10 +0200 Subject: [PATCH 23/94] fix another side of SD-1846 - Changing debugger options during debug causes exception --- .../Options/DebuggingOptions.cs | 21 +++++++++++++++++++ .../Options/DebuggingOptionsPanel.xaml.cs | 14 +------------ .../Options/DebuggingSymbolsPanel.cs | 10 ++++----- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs index 216aab5df9..9632eb7b95 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs @@ -41,5 +41,26 @@ namespace ICSharpCode.SharpDevelop.Services // Properties for the DebuggeeExceptionForm public FormWindowState DebuggeeExceptionWindowState { get; set; } + + /// + /// Used to update status of some debugger properties while debugger is running. + /// + internal static void ResetStatus(Action resetStatus) + { + Process proc = WindowsDebugger.CurrentProcess; + // debug session is running + if (proc != null) { + bool wasPausedNow = false; + // if it is not paused, break execution + if (!proc.IsPaused) { + proc.Break(); + wasPausedNow = true; + } + resetStatus(proc); + // continue if it was not paused before + if (wasPausedNow) + proc.AsyncContinue(); + } + } } } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml.cs b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml.cs index f467805274..dd878773cf 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml.cs @@ -50,19 +50,7 @@ namespace Debugger.AddIn.Options public override bool SaveOptions() { bool result = base.SaveOptions(); - Process proc = WindowsDebugger.CurrentProcess; - // debug session is running - if (proc != null) { - bool wasPausedNow = false; - // if it is not paused, break execution - if (!proc.IsPaused) { - proc.Break(); - wasPausedNow = true; - } - proc.Debugger.ResetJustMyCodeStatus(); - // continue if it was not paused before - if (wasPausedNow) proc.AsyncContinue(); - } + DebuggingOptions.ResetStatus(proc => proc.Debugger.ResetJustMyCodeStatus()); return result; } } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.cs b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.cs index 8abeb8e487..2e0329b2a6 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.cs @@ -30,11 +30,11 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels public override bool StorePanelContents() { DebuggingOptions.Instance.SymbolsSearchPaths = pathList.GetList(); - Process proc = WindowsDebugger.CurrentProcess; - if (proc != null) { - proc.Debugger.ReloadModuleSymbols(); - proc.Debugger.ResetJustMyCodeStatus(); - } + DebuggingOptions.ResetStatus( + proc => { + proc.Debugger.ReloadModuleSymbols(); + proc.Debugger.ResetJustMyCodeStatus(); + }); return true; } } From 30d21da23e3dcabd1ab1de03720a9e3a27893812 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 1 Apr 2012 12:19:16 +0100 Subject: [PATCH 24/94] Fix items selected in Advanced service reference dialog changing on opening and closing dialog. --- .../AdvancedServiceDialog.xaml | 14 ++++++++------ .../AdvancedServiceViewModel.cs | 19 ++++++++++++++----- .../ServiceReferenceGeneratorOptions.cs | 11 ++++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml index bf285b5794..2c2710bf2f 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceDialog.xaml @@ -115,23 +115,25 @@ + Margin="80,0,0,0" + SelectionMode="Multiple" + ItemsSource="{Binding AssembliesToReference}" + IsEnabled="{Binding ListViewEnable}"> diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs index 3da433ab5b..305f8c4ffc 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs @@ -69,7 +69,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference this.options = options; UpdateSettingsFromOptions(); Title = "Service Reference Settings"; - UseReferencedAssemblies = true; BitmapSource image = PresentationResourceService.GetBitmapSource("Icons.16x16.Reference"); AssembliesToReference = new ObservableCollection(); AssembliesToReference.Add(new CheckableImageAndDescription(image, "Microsoft.CSharp")); @@ -98,7 +97,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference if (options.UseTypesInProjectReferences) { this.ReuseTypes = true; this.UseReferencedAssemblies = true; + } else if (options.UseTypesInSpecifiedAssemblies) { + this.ReuseReferencedTypes = true; + this.UseReferencedAssemblies = true; } else { + this.ReuseReferencedTypes = false; this.ReuseTypes = false; this.UseReferencedAssemblies = false; } @@ -125,10 +128,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference get { return selectedModifier; } set { selectedModifier = value; + UpdateClassGenerationModifier(); base.RaisePropertyChanged(() => SelectedModifier); } } + void UpdateClassGenerationModifier() + { + options.GenerateInternalClasses = (selectedModifier == Modifiers.Internal); + } + public bool GenerateAsyncOperations { get { return options.GenerateAsyncOperations; } set { @@ -168,6 +177,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference set { useReferencedAssemblies = value; ReuseTypes = useReferencedAssemblies; + if (!useReferencedAssemblies) + ReuseReferencedTypes = false; base.RaisePropertyChanged(() => UseReferencedAssemblies); } } @@ -180,12 +191,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference } } - bool reuseReferencedTypes; - public bool ReuseReferencedTypes { - get { return reuseReferencedTypes; } + get { return options.UseTypesInSpecifiedAssemblies; } set { - reuseReferencedTypes = value; + options.UseTypesInSpecifiedAssemblies = value; ListViewEnable = value; base.RaisePropertyChanged(() => ReuseReferencedTypes); } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs index 756dc9e666..e1f240b4d1 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.ComponentModel; using System.Reflection; +using ICSharpCode.SharpDevelop.Project; + namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference { public class ServiceReferenceGeneratorOptions @@ -42,6 +44,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference public bool GenerateAsyncOperations { get; set; } public bool GenerateMessageContract { get; set; } public bool UseTypesInProjectReferences { get; set; } + public bool UseTypesInSpecifiedAssemblies { get; set; } public CollectionTypes ArrayCollectionType { get; set; } public DictionaryCollectionTypes DictionaryCollectionType { get; set; } @@ -68,7 +71,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference AppConfigFileName = this.AppConfigFileName, NoAppConfig = this.NoAppConfig, MergeAppConfig = this.MergeAppConfig, - + UseTypesInSpecifiedAssemblies = this.UseTypesInSpecifiedAssemblies, UseTypesInProjectReferences = this.UseTypesInProjectReferences, ArrayCollectionType = this.ArrayCollectionType, DictionaryCollectionType = this.DictionaryCollectionType, @@ -143,10 +146,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference return "`2"; } - public void AddProjectReferencesIfUsingTypesFromProjectReferences(IEnumerable assemblies) + public void AddProjectReferencesIfUsingTypesFromProjectReferences(IEnumerable assemblies) { if (UseTypesInProjectReferences) { - Assemblies.AddRange(assemblies); + foreach (ReferenceProjectItem item in assemblies) { + Assemblies.Add(item.FileName); + } } } } From c78b7ad694059e10c0ad6744676bb6d22bbc7286 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 1 Apr 2012 12:54:51 +0100 Subject: [PATCH 25/94] Remove discover in projects button from service reference dialog. --- .../AddServiceReferenceDialog.xaml | 27 ++++------- .../AddServiceReferenceViewModel.cs | 47 +++++-------------- 2 files changed, 20 insertions(+), 54 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceDialog.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceDialog.xaml index fbb2a7c10c..eefd2344ef 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceDialog.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceDialog.xaml @@ -53,8 +53,8 @@ - + - -