From 94d339bf97eb4f5c3b5dbcbcaf11b1280fc42d7a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 26 Feb 2006 14:57:00 +0000 Subject: [PATCH 1/7] Improved VB -> C# converter. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1187 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Visitors/VBNetConstructsConvertVisitor.cs | 89 +++++++++++++++++++ .../Output/CSharp/VBToCSharpConverterTest.cs | 42 +++++++++ .../ProjectBrowser/ProjectBrowserControl.cs | 8 +- .../Pads/ProjectBrowser/ProjectBrowserPad.cs | 12 +++ .../ProjectBrowser/ProjectBrowserPanel.cs | 6 ++ .../Project/Converter/LanguageConverter.cs | 3 + 6 files changed, 159 insertions(+), 1 deletion(-) diff --git a/src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs index 70e6e2fd81..a247735e61 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/Visitors/VBNetConstructsConvertVisitor.cs @@ -10,6 +10,7 @@ using System.Text; using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Reflection; using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Parser.VB; @@ -27,6 +28,8 @@ namespace ICSharpCode.NRefactory.Parser // MyBase.New() and MyClass.New() calls inside the constructor are converted to :base() and :this() // Add Public Modifier to methods and properties // Override Finalize => Destructor + // IIF(cond, true, false) => ConditionalExpression + // Built-in methods => Prefix with class name // The following conversions should be implemented in the future: // Function A() \n A = SomeValue \n End Function -> convert to return statement @@ -198,5 +201,91 @@ namespace ICSharpCode.NRefactory.Parser return base.Visit(propertyDeclaration, data); } + + static volatile Dictionary constantTable; + static volatile Dictionary methodTable; + + public static readonly string VBAssemblyName = "Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; + + static Dictionary CreateDictionary(params string[] classNames) + { + Dictionary d = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + Assembly asm = Assembly.Load(VBAssemblyName); + foreach (string className in classNames) { + Type type = asm.GetType("Microsoft.VisualBasic." + className); + Expression expr = new IdentifierExpression(className); + foreach (MemberInfo member in type.GetMembers()) { + if (member.DeclaringType == type) { // only direct members + d[member.Name] = expr; + } + } + } + return d; + } + + public override object Visit(IdentifierExpression identifierExpression, object data) + { + if (constantTable == null) { + constantTable = CreateDictionary("Constants"); + } + Expression expr; + if (constantTable.TryGetValue(identifierExpression.Identifier, out expr)) { + FieldReferenceExpression fre = new FieldReferenceExpression(expr, identifierExpression.Identifier); + ReplaceCurrentNode(fre); + return base.Visit(fre, data); + } + return base.Visit(identifierExpression, data); + } + + public override object Visit(InvocationExpression invocationExpression, object data) + { + IdentifierExpression ident = invocationExpression.TargetObject as IdentifierExpression; + if (ident != null) { + if ("IIF".Equals(ident.Identifier, StringComparison.InvariantCultureIgnoreCase) + && invocationExpression.Arguments.Count == 3) + { + ConditionalExpression ce = new ConditionalExpression(invocationExpression.Arguments[0], + invocationExpression.Arguments[1], + invocationExpression.Arguments[2]); + ReplaceCurrentNode(new ParenthesizedExpression(ce)); + return base.Visit(ce, data); + } + if ("IsNothing".Equals(ident.Identifier, StringComparison.InvariantCultureIgnoreCase) + && invocationExpression.Arguments.Count == 1) + { + BinaryOperatorExpression boe = new BinaryOperatorExpression(invocationExpression.Arguments[0], + BinaryOperatorType.ReferenceEquality, + new PrimitiveExpression(null, "null")); + ReplaceCurrentNode(new ParenthesizedExpression(boe)); + return base.Visit(boe, data); + } + if (methodTable == null) { + methodTable = CreateDictionary("Conversion", "FileSystem", "Financial", "Information", + "Interaction", "Strings", "VBMath"); + } + Expression expr; + if (methodTable.TryGetValue(ident.Identifier, out expr)) { + FieldReferenceExpression fre = new FieldReferenceExpression(expr, ident.Identifier); + invocationExpression.TargetObject = fre; + } + } + return base.Visit(invocationExpression, data); + } + + public override object Visit(UnaryOperatorExpression unaryOperatorExpression, object data) + { + base.Visit(unaryOperatorExpression, data); + if (unaryOperatorExpression.Op == UnaryOperatorType.Not) { + ParenthesizedExpression pe = unaryOperatorExpression.Expression as ParenthesizedExpression; + if (pe != null) { + BinaryOperatorExpression boe = pe.Expression as BinaryOperatorExpression; + if (boe != null && boe.Op == BinaryOperatorType.ReferenceEquality) { + boe.Op = BinaryOperatorType.ReferenceInequality; + ReplaceCurrentNode(pe); + } + } + } + return null; + } } } diff --git a/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs b/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs index 0448885f16..d910543fb1 100644 --- a/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs +++ b/src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs @@ -188,5 +188,47 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter "\tDead();\n" + "}"); } + + [Test] + public void IIFExpression() + { + TestStatement("a = iif(cond, trueEx, falseEx)", + "a = (cond ? trueEx : falseEx);"); + } + + [Test] + public void IsNothing() + { + TestStatement("a = IsNothing(ex)", + "a = (ex == null);"); + } + + [Test] + public void IsNotNothing() + { + TestStatement("a = Not IsNothing(ex)", + "a = (ex != null);"); + } + + [Test] + public void CompatibilityMethods() + { + TestStatement("Beep()", + "Interaction.Beep();"); + } + + [Test] + public void EqualsCall() + { + TestStatement("Equals(a, b)", + "Equals(a, b);"); + } + + [Test] + public void VBConstants() + { + TestStatement("a = vbYesNo", + "a = Constants.vbYesNo;"); + } } } diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs index 78472fa2cc..fbf40b329e 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs @@ -47,6 +47,12 @@ namespace ICSharpCode.SharpDevelop.Project } } + public AbstractProjectBrowserTreeNode RootNode { + get { + return treeView.Nodes[0] as AbstractProjectBrowserTreeNode; + } + } + public ExtTreeView TreeView { get { return treeView; @@ -140,7 +146,7 @@ namespace ICSharpCode.SharpDevelop.Project return FindFileNode(treeView.Nodes, fileName); } - // stores the fileName of the last selected target so + // stores the fileName of the last selected target so // that we can select it again on opening a folder string lastSelectionTarget; diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPad.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPad.cs index 44bc2b8a86..2051b9dd1e 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPad.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPad.cs @@ -20,6 +20,9 @@ namespace ICSharpCode.SharpDevelop.Project static ProjectBrowserPad instance; public static ProjectBrowserPad Instance { get { + if (instance == null) { + WorkbenchSingleton.Workbench.GetPad(typeof(ProjectBrowserPad)).CreatePad(); + } return instance; } } @@ -31,6 +34,15 @@ namespace ICSharpCode.SharpDevelop.Project } } + /// + /// Gets the root node of the project tree view. + /// + public AbstractProjectBrowserTreeNode SolutionNode { + get { + return projectBrowserPanel.RootNode; + } + } + public ProjectBrowserControl ProjectBrowserControl { get { return projectBrowserPanel.ProjectBrowserControl; diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPanel.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPanel.cs index 7b911c1a3f..10beeeddce 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPanel.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserPanel.cs @@ -29,6 +29,12 @@ namespace ICSharpCode.SharpDevelop.Project } } + public AbstractProjectBrowserTreeNode RootNode { + get { + return projectBrowserControl.RootNode; + } + } + public ProjectBrowserControl ProjectBrowserControl { get { return projectBrowserControl; diff --git a/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs b/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs index 1951183b76..afcc81c005 100644 --- a/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs +++ b/src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs @@ -140,6 +140,9 @@ namespace ICSharpCode.SharpDevelop.Project.Converter targetProject.Save(); targetProject.Dispose(); TreeNode node = ProjectBrowserPad.Instance.SelectedNode; + if (node == null) { + node = ProjectBrowserPad.Instance.SolutionNode; + } while (node != null) { if (node is ISolutionFolderNode) { AddExitingProjectToSolution.AddProject((ISolutionFolderNode)node, targetProject.FileName); From 099643ef8356d9377914a2957802a3d36ce3f854 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 27 Feb 2006 15:21:06 +0000 Subject: [PATCH 2/7] Fixed forum-5573: Error compiling projects created by VS 2005 for .NET 1.1. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1189 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Services/TypeDiscoveryService.cs | 36 +++++++++++-------- .../Project/SharpDevelop.Build.CSharp.targets | 1 + .../ProjectOptions/AbstractBuildOptions.cs | 19 +++++----- .../ProjectBrowser/TreeNodes/DirectoryNode.cs | 5 +++ .../Pads/ProjectBrowser/TreeNodes/FileNode.cs | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs index aca6c79988..8c6d7f9a28 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs @@ -34,22 +34,30 @@ namespace ICSharpCode.FormsDesigner.Services public ICollection GetTypes(Type baseType, bool excludeGlobalTypes) { List types = new List(); - if (baseType != null) { - LoggingService.Debug("TypeDiscoveryService.GetTypes for " + baseType.FullName - + "excludeGlobalTypes=" + excludeGlobalTypes.ToString()); - //seek in all assemblies - //allow to work designers like columns editor in datagridview - // Searching types can cause additional assemblies to be loaded, so we need to use - // ToArray to prevent an exception if the collection changes. - foreach (Assembly asm in TypeResolutionService.DesignerAssemblies.ToArray()) { - AddDerivedTypes(baseType, asm, types); + + if (baseType == null) { + baseType = typeof(object); + } + + LoggingService.Debug("TypeDiscoveryService.GetTypes for " + baseType.FullName + + "excludeGlobalTypes=" + excludeGlobalTypes.ToString()); + //seek in all assemblies + //allow to work designers like columns editor in datagridview + // Searching types can cause additional assemblies to be loaded, so we need to use + // ToArray to prevent an exception if the collection changes. + foreach (Assembly asm in TypeResolutionService.DesignerAssemblies.ToArray()) { + if (excludeGlobalTypes) { + if (FileUtility.IsBaseDirectory(ReflectionProjectContent.GacRootPath, asm.Location)) { + continue; + } } - LoggingService.Debug("TypeDiscoveryService returns " + types.Count + " types"); - - // TODO - Don't look in all assemblies. - // Should use the current project and its referenced assemblies - // as well as System.Windows.Forms. + AddDerivedTypes(baseType, asm, types); } + LoggingService.Debug("TypeDiscoveryService returns " + types.Count + " types"); + + // TODO - Don't look in all assemblies. + // Should use the current project and its referenced assemblies + // as well as System.Windows.Forms. return types; } diff --git a/src/Libraries/ICSharpCode.Build.Tasks/Project/SharpDevelop.Build.CSharp.targets b/src/Libraries/ICSharpCode.Build.Tasks/Project/SharpDevelop.Build.CSharp.targets index 47b0721a71..a267ea6285 100644 --- a/src/Libraries/ICSharpCode.Build.Tasks/Project/SharpDevelop.Build.CSharp.targets +++ b/src/Libraries/ICSharpCode.Build.Tasks/Project/SharpDevelop.Build.CSharp.targets @@ -17,6 +17,7 @@ false + diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs index 711563cbb5..f3f4d66143 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs @@ -180,15 +180,16 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels protected void InitTargetFramework(string defaultTargets, string extendedTargets) { const string TargetFrameworkProperty = "TargetFrameworkVersion"; - debugInfoBinding = helper.BindStringEnum("targetFrameworkComboBox", TargetFrameworkProperty, - "", - new StringPair("", "Default (.NET 2.0)"), - new StringPair("v1.0", ".NET 1.0"), - new StringPair("v1.1", ".NET 1.1"), - new StringPair("v2.0", ".NET 2.0"), - new StringPair("Mono v1.1", "Mono 1.1"), - new StringPair("Mono v2.0", "Mono 2.0")); - debugInfoBinding.CreateLocationButton("targetFrameworkLabel"); + ConfigurationGuiBinding targetFrameworkBinding; + targetFrameworkBinding = helper.BindStringEnum("targetFrameworkComboBox", TargetFrameworkProperty, + "", + new StringPair("", "Default (.NET 2.0)"), + new StringPair("v1.0", ".NET 1.0"), + new StringPair("v1.1", ".NET 1.1"), + new StringPair("v2.0", ".NET 2.0"), + new StringPair("Mono v1.1", "Mono 1.1"), + new StringPair("Mono v2.0", "Mono 2.0")); + targetFrameworkBinding.CreateLocationButton("targetFrameworkLabel"); helper.Saved += delegate { // Test if SharpDevelop-Build extensions are needed MSBuildProject project = helper.Project; diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs index 194886a2a3..b129b59f36 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs @@ -416,6 +416,11 @@ namespace ICSharpCode.SharpDevelop.Project } base.Initialize(); } + + protected void BaseInitialize() + { + base.Initialize(); + } void AddParentFolder(string virtualName, string relativeDirectoryPath, Dictionary directoryNodeList) { diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs index e86c19dac5..9f0c35a374 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.SharpDevelop.Project } } - public string FileName { + public virtual string FileName { get { return fileName; } From 17c49a84b41fcf962cad57e8ee4a20d9c11f4938 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 27 Feb 2006 15:42:40 +0000 Subject: [PATCH 3/7] Fixed forum-5561: Preferences not saving if path exceeds certain length git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1190 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Gui/Workbench/DefaultWorkbench.cs | 20 +++++++++++-------- .../Services/ProjectService/ProjectService.cs | 7 ++++--- .../Src/Services/FileUtility/FileUtility.cs | 4 +++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs index 7d15aacbae..d1f069e8bb 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs @@ -269,15 +269,20 @@ namespace ICSharpCode.SharpDevelop.Gui StatusBarService.RedrawStatusbar(); } + string GetMementoFileName(string contentName) + { + string directory = Path.Combine(PropertyService.ConfigDirectory, "temp"); + //string directoryName = Path.GetDirectoryName(contentName); + return Path.Combine(directory, + Path.GetFileName(contentName) + + "." + contentName.ToLowerInvariant().GetHashCode().ToString("x") + + ".xml"); + } + public Properties GetStoredMemento(IViewContent content) { if (content != null && content.FileName != null) { - string directory = Path.Combine(PropertyService.ConfigDirectory, "temp"); - if (!Directory.Exists(directory)) { - Directory.CreateDirectory(directory); - } - string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); - string fullFileName = Path.Combine(directory, fileName); + string fullFileName = GetMementoFileName(content.FileName); // check the file name length because it could be more than the maximum length of a file name if (FileUtility.IsValidFileName(fullFileName) && File.Exists(fullFileName)) { @@ -299,8 +304,7 @@ namespace ICSharpCode.SharpDevelop.Gui } Properties memento = ((IMementoCapable)content).CreateMemento(); - string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); - string fullFileName = Path.Combine(directory, fileName); + string fullFileName = GetMementoFileName(content.FileName); if (FileUtility.IsValidFileName(fullFileName)) { FileUtility.ObservedSave(new NamedFileOperationDelegate(memento.Save), fullFileName, FileErrorPolicy.Inform); diff --git a/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs b/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs index 54e8cf0d1f..f0a07ed47c 100644 --- a/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs +++ b/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs @@ -296,9 +296,10 @@ namespace ICSharpCode.SharpDevelop.Project static string GetPreferenceFileName(string projectFileName) { string directory = PropertyService.ConfigDirectory + "preferences"; - string fileName = projectFileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); - string fullFileName = Path.Combine(directory, fileName + ".xml"); - return fullFileName; + return Path.Combine(directory, + Path.GetFileName(projectFileName) + + "." + projectFileName.ToLowerInvariant().GetHashCode().ToString("x") + + ".xml"); } public static void SaveSolutionPreferences() diff --git a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs index 289d71447b..58db370b0f 100644 --- a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs +++ b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs @@ -265,6 +265,8 @@ namespace ICSharpCode.Core } } + public static int MaxPathLength = 260; + /// /// This method checks the file fileName if it is valid. /// @@ -273,7 +275,7 @@ namespace ICSharpCode.Core // Fixme: 260 is the hardcoded maximal length for a path on my Windows XP system // I can't find a .NET property or method for determining this variable. - if (fileName == null || fileName.Length == 0 || fileName.Length >= 260) { + if (fileName == null || fileName.Length == 0 || fileName.Length >= MaxPathLength) { return false; } From 3ae2408380fd9f54dc8b8cc32c0b8b0cbf4cd73b Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 27 Feb 2006 17:08:36 +0000 Subject: [PATCH 4/7] SD2-710 - Unable to add a web reference by browsing to a wsdl file when entering a file path (e.g. 'file:///C:/Projects/MyService.wsdl'). The web service discovery code no longer assumes the received response is a HttpWebResponse object. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1191 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Gui/Dialogs/ReferenceDialog/AddWebReferenceDialog.cs | 7 ++++++- .../ReferenceDialog/WebServiceDiscoveryClientProtocol.cs | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddWebReferenceDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddWebReferenceDialog.cs index 91b7b0bc5e..1470620c52 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddWebReferenceDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddWebReferenceDialog.cs @@ -589,7 +589,12 @@ namespace ICSharpCode.SharpDevelop.Gui if (discoveryClientProtocol != null) { try { discoveryClientProtocol.Abort(); - } catch (NotImplementedException) {}; + } catch (NotImplementedException) { + } catch (ObjectDisposedException) { + // Receive this error if the url pointed to a file. + // The discovery client will already have closed the file + // so the abort fails. + } discoveryClientProtocol.Dispose(); } discoveryClientProtocol = new WebServiceDiscoveryClientProtocol(); diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/WebServiceDiscoveryClientProtocol.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/WebServiceDiscoveryClientProtocol.cs index 4f671c56b8..67a28940ef 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/WebServiceDiscoveryClientProtocol.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/WebServiceDiscoveryClientProtocol.cs @@ -42,9 +42,9 @@ namespace ICSharpCode.SharpDevelop.Gui protected override WebResponse GetWebResponse(WebRequest request) { - lastResponseReceived = null; - lastResponseReceived = base.GetWebResponse(request) as HttpWebResponse; - return lastResponseReceived; + WebResponse response = base.GetWebResponse(request); + lastResponseReceived = response as HttpWebResponse; + return response; } } } From 1a5c72995e94ef7773449cbe20b01c954658e67b Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Wed, 1 Mar 2006 10:06:22 +0000 Subject: [PATCH 5/7] Add Grouping (only one Column)to SharpReport, made some fixes from FxCOp git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1193 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../SectionControls/BaseDesignerControl.cs | 14 +- .../SharpReport/SharpReportManager.cs | 52 +-- .../SharpReportDisplayBinding.cs | 1 - .../SharpReportAddin/SharpReportView.cs | 6 +- .../BaseItems/BaseReportItem.cs | 38 +- .../BaseItems/BaseReportObject.cs | 21 +- .../SharpReportCore/BaseItems/BaseSection.cs | 48 ++- .../BaseItems/Graphics/BaseImageItem.cs | 8 +- .../BaseItems/Graphics/BaseRectangleItem.cs | 16 +- .../SharpReportCore/ConnectionObject.cs | 28 +- .../DataManager/Comparer/BaseComparer.cs | 4 +- .../DataManager/Comparer/GroupComparer.cs | 103 ----- .../DataManager/Comparer/GroupSeperator.cs | 97 ++++- .../DataManager/Comparer/SortComparer.cs | 4 +- .../DataManager/DataManager.cs | 250 ++++++------ .../ExtendedPropertyDescriptor.cs | 56 ++- .../DataManager/ListHandling/IExtendedList.cs | 45 -- .../ListHandling/IHierarchicalArray.cs | 41 -- .../ListHandling/PropertyTypeHash.cs | 8 +- .../ListHandling/SharpArrayList.cs | 383 +++++++----------- .../ListStrategy/BaseListStrategy.cs | 263 ++++++------ .../ListStrategy/CollectionStrategy.cs | 228 +++++++---- .../DataManager/ListStrategy/TableStrategy.cs | 296 +++++--------- .../DataManager/SqlQueryChecker.cs | 4 +- .../Exceptions/MissingDataSourceException.cs | 4 +- .../SharpReportCore/Globals/FontSingleton.cs | 15 +- .../SharpReportCore/Globals/GlobalEnums.cs | 6 +- .../Interfaces/IDataContainer.cs | 7 +- .../Interfaces/IDataViewStrategy.cs | 27 +- .../Interfaces/IHierarchyInterfaces.cs | 15 +- .../Interfaces/IOutputStrategy.cs | 6 +- .../Printing/RenderDataReport.cs | 15 +- .../Printing/ReportDocument.cs | 2 +- .../SharpReportCore/ReportModel.cs | 26 +- .../SharpReportCore/ReportSettings.cs | 66 ++- .../SharpReportCore/SharpReportCore.csproj | 9 +- .../SharpReportCore/SharpReportEngine.cs | 61 +-- .../SharpReportCore/Xml/XmlHelper.cs | 30 +- 38 files changed, 1057 insertions(+), 1246 deletions(-) delete mode 100644 src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupComparer.cs delete mode 100644 src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IExtendedList.cs delete mode 100644 src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IHierarchicalArray.cs diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs index 3942ad0712..d209e33921 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs @@ -57,13 +57,10 @@ namespace SharpReport.Designer #region overrides protected override void Dispose(bool disposing ) { - if( disposing ) - { -// if( components != null ) -// components.Dispose(); + if( disposing ){ + this.reportControl = null; + this.ctrlRuler1 = null; } - this.reportControl = null; - this.ctrlRuler1 = null; base.Dispose( disposing ); } @@ -110,7 +107,10 @@ namespace SharpReport.Designer public ReportModel ReportModel { get { reportModel.ReportSettings = reportControl.ReportSettings; - reportModel.SectionCollection = reportControl.SectionCollection; + reportModel.SectionCollection.Clear(); + foreach (ReportSection section in reportControl.SectionCollection) { + reportModel.SectionCollection.Add (section); + } return this.reportModel; } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs b/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs index 5b894862ef..1bdb6b0d48 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs @@ -73,7 +73,6 @@ namespace SharpReport{ /// private ColumnCollection ReadColumnCollection() { - ColumnCollection columnCollecion = new ColumnCollection(); switch (baseDesignerControl.ReportModel.DataModel) { case GlobalEnums.enmPushPullModel.FormSheet: @@ -88,13 +87,20 @@ namespace SharpReport{ if (base.ConnectionObject == null) { base.ConnectionObject = this.BuildConnectionObject(baseDesignerControl.ReportModel.ReportSettings); } - + if (this.baseDesignerControl.ReportModel.DataModel.Equals(GlobalEnums.enmPushPullModel.PullData)){ - - using (DataManager dataManager = new DataManager(base.ConnectionObject, - baseDesignerControl.ReportModel.ReportSettings)) { - dataManager.DataBind(); - columnCollecion = dataManager.AvailableFields; + try { + using (DataManager dataManager = new DataManager(base.ConnectionObject, + baseDesignerControl.ReportModel.ReportSettings)) { + + dataManager.DataBind(); + columnCollecion = dataManager.AvailableFields; + } + + } catch (Exception e) { + throw e; + } finally { + System.Console.WriteLine("ReportManager:ReadColumnCollection in finally"); } } break; @@ -104,10 +110,7 @@ namespace SharpReport{ return columnCollecion; } - - - - + private void AddItemsToSection (BaseSection section,ReportItemCollection collection) { if ((section == null)|| (collection == null) ) { @@ -324,6 +327,7 @@ namespace SharpReport{ if (base.ConnectionObject == null) { base.ConnectionObject = this.BuildConnectionObject(model.ReportSettings); } + return base.AbstractRenderer(model); } @@ -478,20 +482,22 @@ namespace SharpReport{ } protected new void Dispose(bool disposing){ - if (disposing) { - // Free other state (managed objects). - if (this.baseDesignerControl != null) { - this.baseDesignerControl.Dispose(); - } - if (this.reportModel != null) { - this.reportModel.Dispose(); + try { + if (disposing) { + // Free other state (managed objects). + if (this.baseDesignerControl != null) { + this.baseDesignerControl.Dispose(); + } + if (this.reportModel != null) { + this.reportModel.Dispose(); + } } + } finally { + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. + base.Dispose(); } - - // Release unmanaged resources. - // Set large fields to null. - // Call Dispose on your base class. - base.Dispose(); } #endregion } diff --git a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs index 9a1c48d4c7..29bb7e0f9b 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs @@ -70,7 +70,6 @@ namespace SharpReportAddin { return GlobalValues.IsValidPrinter(); } - public virtual ICSharpCode.SharpDevelop.Gui.IViewContent CreateContentForFile(string fileName) { if (GlobalValues.IsValidPrinter() == true) { SharpReportView view = new SharpReportView(); diff --git a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs index 8cd3ab88f1..24b46d552d 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs @@ -502,7 +502,6 @@ namespace SharpReportAddin{ public override void Load(string fileName){ try { designerControl.ReportControl.ObjectSelected -= new EventHandler (OnObjectSelected); - reportManager.LoadFromFile (fileName); base.FileName = fileName; designerControl.ReportModel.ReportSettings.FileName = fileName; @@ -511,10 +510,9 @@ namespace SharpReportAddin{ PropertyPad.Grid.SelectedObject = designerControl.ReportModel.ReportSettings; PropertyPad.Grid.Refresh(); } - this.designerControl.ReportModel.ReportSettings.AvailableFieldsCollection = reportManager.AvailableFieldsCollection; - - } catch (Exception ) { + } catch (Exception e) { + MessageService.ShowError(e,"SharpReportView:Load"); throw ; } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs index a0d6c7f385..74aaafb188 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs @@ -98,15 +98,7 @@ namespace SharpReportCore { #endregion - - #region System.IDisposable interface implementation - public virtual void Dispose() { - if(Disposed != null){ - Disposed(this,EventArgs.Empty); - } - } - #endregion - + #region Properties @@ -169,5 +161,33 @@ namespace SharpReportCore { #endregion + #region IDisposeable + public override void Dispose () { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~BaseReportItem(){ + Dispose(false); + } + + protected override void Dispose(bool disposing) { + try { + if (disposing){ + if (this.font != null){ + this.font = null; + this.font.Dispose(); + } + } + } finally { + if (this.Disposed != null) { + this.Disposed (this,EventArgs.Empty); + } + base.Dispose(disposing); + } + } + + #endregion + } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs index 0ac1dffd35..11bc7995f0 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs @@ -25,7 +25,8 @@ using System.Drawing; /// namespace SharpReportCore { - public class BaseReportObject : IBaseRenderer,INotifyPropertyChanged { + public class BaseReportObject : IBaseRenderer,INotifyPropertyChanged, + IDisposable{ private string name; private object parent; @@ -212,5 +213,23 @@ namespace SharpReportCore { } #endregion + #region IDisposable + + public virtual void Dispose () { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~BaseReportObject(){ + Dispose(false); + } + + protected virtual void Dispose(bool disposing) { + if (disposing){ + + } + } + + #endregion } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs index cd8badb9a8..d453321857 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs @@ -3,7 +3,7 @@ // This code was generated by a tool. // Runtime Version: 1.1.4322.2032 // -// Changes to this file may cause incorrect behavior and will be lost if +// Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ @@ -16,32 +16,56 @@ using System.ComponentModel; /// created by - Forstmeier Helmut /// created on - 01.09.2005 13:12:32 /// -namespace SharpReportCore { +namespace SharpReportCore { public class BaseSection : SharpReportCore.BaseReportObject { - + private ReportItemCollection items; - public BaseSection(): this("") { + #region Constructors + public BaseSection(): base() { + this.Name = String.Empty; } + public BaseSection (string sectionName) :base(){ + this.Name = sectionName; + + } + #endregion #region System.IDisposable interface implementation - public void Dispose() { - for (int i = 0;i < items.Count ;i ++ ){ - ((BaseReportItem)items[i]).Dispose(); - } + public override void Dispose () { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~BaseSection(){ + Dispose(false); } + + protected override void Dispose(bool disposing) { + try { + if (disposing){ + if (this.items != null) { + this.items.Clear(); + this.items = null; + } + } + } finally { + base.Dispose(disposing); + } + } + #endregion #region properties - public BaseSection (string sectionName) :base(){ - this.Name = sectionName; - items = new ReportItemCollection(); - } + [Browsable(false)] public ReportItemCollection Items{ get { + if (this.items == null) { + items = new ReportItemCollection(); + } return items; } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs index 9f32e3a0eb..7f9e11bba4 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs @@ -75,10 +75,10 @@ namespace SharpReportCore { } } - public override void Dispose() { - base.Dispose(); - this.image = null; - } +// public override void Dispose() { +// base.Dispose(); +// this.image = null; +// } public override string ToString() { return "BaseImageItem"; diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseRectangleItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseRectangleItem.cs index 3f5da9ba9d..6f132c7a67 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseRectangleItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseRectangleItem.cs @@ -76,14 +76,14 @@ namespace SharpReportCore { #region System.IDisposable interface implementation - public override void Dispose() { - base.Dispose(); - for (int i = 0; i < arrayList.Count;i ++ ) { - IComponent curObj = (IComponent)arrayList[i]; - curObj.Dispose(); - } - arrayList = null; - } +// public override void Dispose() { +// base.Dispose(); +// for (int i = 0; i < arrayList.Count;i ++ ) { +// IComponent curObj = (IComponent)arrayList[i]; +// curObj.Dispose(); +// } +// arrayList = null; +// } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs index 2dd4217f4a..ed3296af4b 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs @@ -55,15 +55,33 @@ namespace SharpReportCore { } } + #region IDisposeable + public void Dispose () { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~ConnectionObject(){ + Dispose(false); + } - public void Dispose(){ - if (this.connection != null) { - if (this.connection.State == ConnectionState.Open) { - this.connection.Close(); + protected virtual void Dispose(bool disposing) { + try{ + if (disposing){ + if (this.connection != null){ + if (this.connection.State == ConnectionState.Open) { + this.connection.Close(); + } + this.connection.Dispose(); + } } - this.connection.Dispose(); + } + finally{ + connection = null; } } + + #endregion } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/BaseComparer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/BaseComparer.cs index f2fe342264..70355b393e 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/BaseComparer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/BaseComparer.cs @@ -33,13 +33,13 @@ namespace SharpReportCore { } /// - /// TODO - add method description + /// Interface method from IComparable /// /// /// Interface method from IComparable /// /// - /// TODO - add parameter description + /// a public virtual int CompareTo(object obj) { return 0; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupComparer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupComparer.cs deleted file mode 100644 index f775d5fec2..0000000000 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupComparer.cs +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 1.1.4322.2032 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -using System; -using System.Text; -using System.ComponentModel; -using SharpReportCore; - - -/// -/// TODO - Add class summary -/// -/// -/// created by - Forstmeier Helmut -/// created on - 27.11.2005 14:59:28 -/// -namespace SharpReportCore { - public class GroupComparer : SharpReportCore.BaseComparer{ - - public GroupComparer(ColumnCollection owner, int listIndex, object[] values): - base(owner,listIndex,values) { - } - - internal int CompareTo(GroupComparer value) - { - // we shouldn't get to this point - if (value == null) - throw new ArgumentNullException("value"); - - if (value.ObjectArray.Length != base.ObjectArray.Length) - throw new InvalidOperationException("Differnet size of compare data"); - - int compare = 0; - - for (int index = 0; index < base.ObjectArray.Length; index++) - { - object leftValue = base.ObjectArray[index]; - object rightValue = value.ObjectArray[index]; - // Indizes sind hier deckungsgleich - - GroupColumn groupColumn = (GroupColumn)base.ColumnCollection[index]; - - bool descending = (groupColumn.SortDirection == ListSortDirection.Descending); - - // null means equl - if (leftValue == null || leftValue == System.DBNull.Value) - { - if (rightValue != null && rightValue != System.DBNull.Value) - { - return (descending) ? 1 : -1; - } - - // Beide Null - continue; - } - - if (rightValue == null || rightValue == System.DBNull.Value) - { - return (descending) ? -1 : 1; - } - - - if (leftValue.GetType() != rightValue.GetType()) - throw new InvalidOperationException("Compare of different types is not supported"); - - if (leftValue.GetType() == typeof(string)) - { - compare = String.Compare((string)leftValue, (string)rightValue, - !groupColumn.CaseSensitive, base.ColumnCollection.Culture); - } - else - { - compare = ((IComparable)leftValue).CompareTo(rightValue); - } - - // Sind ungleich, tauschen je nach Richtung - if (compare != 0) - { - return (descending) ? -compare : compare; - } - } - - // Gleich Werte, dann Index bercksichtigen - return this.ListIndex.CompareTo(value.ListIndex); - } - - - - public override int CompareTo(object obj) { - base.CompareTo(obj); - return this.CompareTo((GroupComparer)obj); - } - - - - } -} diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupSeperator.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupSeperator.cs index dd71c34d35..a97dd4d8dc 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupSeperator.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupSeperator.cs @@ -22,11 +22,11 @@ using SharpReportCore; /// namespace SharpReportCore { - public class GroupSeperator : SharpReportCore.GroupComparer,IHierarchyData { + public class GroupSeperator : SharpReportCore.BaseComparer,IHierarchyData { private string typeName = "GroupSeperator"; int groupLevel; - IHierarchicalArray childs ; + SharpIndexCollection childs ; public GroupSeperator(ColumnCollection owner, int listIndex, object[] values,int groupLevel): base(owner,listIndex,values) { @@ -40,16 +40,89 @@ namespace SharpReportCore { } } - public IHierarchicalArray Childs { + public SharpIndexCollection GetChildren { get { + if (this.childs == null) { + this.childs = new SharpIndexCollection("ChildList"); + } return childs; + } - set { - childs = value; + } + + #region Comparer + internal int CompareTo(BaseComparer value) + { + // we shouldn't get to this point + if (value == null) + throw new ArgumentNullException("value"); + + if (value.ObjectArray.Length != base.ObjectArray.Length) + throw new InvalidOperationException("Differnet size of compare data"); + + int compare = 0; + + for (int index = 0; index < base.ObjectArray.Length; index++) + { + object leftValue = base.ObjectArray[index]; + object rightValue = value.ObjectArray[index]; + // Indizes sind hier deckungsgleich + + GroupColumn groupColumn = (GroupColumn)base.ColumnCollection[index]; + + bool descending = (groupColumn.SortDirection == ListSortDirection.Descending); + + // null means equl + if (leftValue == null || leftValue == System.DBNull.Value) + { + if (rightValue != null && rightValue != System.DBNull.Value) + { + return (descending) ? 1 : -1; + } + + // Beide Null + continue; + } + + if (rightValue == null || rightValue == System.DBNull.Value) + { + return (descending) ? -1 : 1; + } + + + if (leftValue.GetType() != rightValue.GetType()) + throw new InvalidOperationException("Compare of different types is not supported"); + + if (leftValue.GetType() == typeof(string)) + { + compare = String.Compare((string)leftValue, (string)rightValue, + !groupColumn.CaseSensitive, base.ColumnCollection.Culture); + } + else + { + compare = ((IComparable)leftValue).CompareTo(rightValue); + } + + // Sind ungleich, tauschen je nach Richtung + if (compare != 0) + { + return (descending) ? -compare : compare; + } } + + // Gleich Werte, dann Index bercksichtigen + return this.ListIndex.CompareTo(value.ListIndex); + } + + + + public override int CompareTo(object obj) { + base.CompareTo(obj); + return this.CompareTo((BaseComparer)obj); } + #endregion #region SharpReportCore.IHierarchyData interface implementation @@ -85,13 +158,13 @@ namespace SharpReportCore { } } - public IHierarchicalEnumerable GetChildren() { - return this.childs; - } - - public IHierarchyData GetParent() { - return null; - } +// public IHierarchicalEnumerable GetChildren() { +// return this.childs; +// } +// +// public IHierarchyData GetParent() { +// return null; +// } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/SortComparer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/SortComparer.cs index 987c150f77..696a2209ef 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/SortComparer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/SortComparer.cs @@ -28,7 +28,7 @@ namespace SharpReportCore { throw new ArgumentNullException("value"); if (value.ObjectArray.Length != base.ObjectArray.Length) - throw new InvalidOperationException("Differnet size of compare data"); + throw new InvalidOperationException(); int compare = 0; @@ -61,7 +61,7 @@ namespace SharpReportCore { if (leftValue.GetType() != rightValue.GetType()) - throw new InvalidOperationException("COmpare of different types is not supported"); + throw new InvalidOperationException("Compare of different types is not supported"); if (leftValue.GetType() == typeof(string)) { diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs index 57aef35032..955b0324eb 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs @@ -45,12 +45,11 @@ namespace SharpReportCore { ConnectionObject connectionObject; IDbConnection connection; IDataViewStrategy dataViewStrategy; - - -// private ListChangedEventArgs resetList = new ListChangedEventArgs(ListChangedType.Reset,-1,-1); + GroupSeperator groupSeperator; public event EventHandler ListChanged; public event EventHandler GroupChanged; + public event EventHandler GroupChanging; /// /// use this Constructor for PullDataReports @@ -60,34 +59,32 @@ namespace SharpReportCore { #region Constructores public DataManager(ConnectionObject connectionObject, ReportSettings reportSettings){ - CheckAndSetReportSettings(reportSettings); if (connectionObject == null) { throw new ArgumentNullException("DataManager:ConnectionObject"); } - this.connectionObject = connectionObject; - try { - CheckConnection (this.connectionObject); - CheckAndSetSource(this.FillDataSet().Tables[0]); - - this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, - reportSettings); - this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); - } catch (Exception) { - throw; + + if (reportSettings == null) { + throw new ArgumentNullException("reportSettings"); } + + this.connectionObject = connectionObject; + CheckConnection (this.connectionObject); + CheckReportSettings(reportSettings); + CheckDataSource(this.FillDataSet().Tables[0]); + + this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, + reportSettings); + this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); + this.dataViewStrategy.GroupChanged += new EventHandler (OnGroupChange); } - public DataManager(DataTable dataSource, ReportSettings reportSettings){ - try { - CheckAndSetReportSettings(reportSettings); - CheckAndSetSource(dataSource); - this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, - reportSettings); - this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); - } catch (Exception) { - throw ; - } + + this.InitDataManager(reportSettings,dataSource); + this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, + reportSettings); + this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); + } public DataManager(DataSet dataSource, ReportSettings reportSettings) @@ -97,54 +94,49 @@ namespace SharpReportCore { public DataManager(DataSet dataSource,string dataMember, ReportSettings reportSettings){ - try { - this.dataMember = dataMember; - CheckAndSetReportSettings(reportSettings); - CheckAndSetSource(dataSource); - this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, - reportSettings); - this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); - } catch (Exception ) { - throw ; - } + this.dataMember = dataMember; + this.InitDataManager(reportSettings,dataSource); + this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, + reportSettings); + this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); } public DataManager(IList dataSource, ReportSettings reportSettings){ + + this.InitDataManager(reportSettings,dataSource); + this.dataViewStrategy = new CollectionStrategy ((IList)this.dataSource, + this.dataMember, + reportSettings); + this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); + + } + + #endregion + + void InitDataManager (ReportSettings reportSettings,object dataSource) { try { - CheckAndSetReportSettings(reportSettings); - CheckAndSetSource(dataSource); - this.dataViewStrategy = new CollectionStrategy ((IList)this.dataSource, - this.dataMember, - reportSettings); - this.dataViewStrategy.ListChanged += new EventHandler (NotifyListChanged); + CheckReportSettings(reportSettings); + CheckDataSource(dataSource); } catch (Exception) { throw; } } - #endregion - - - - void CheckAndSetReportSettings(ReportSettings settings) { - if (settings == null) { - throw new ArgumentNullException("settings"); - } + void CheckReportSettings(ReportSettings settings) { try { if (settings.DataModel != GlobalEnums.enmPushPullModel.PushData) { - SqlQueryCkecker check = new SqlQueryCkecker(); - check.Check(settings.CommandText); + SqlQueryChecker checker = new SqlQueryChecker(); + checker.Check(settings.CommandText); } } catch (Exception) { throw; } - this.reportSettings = settings; } - void CheckAndSetSource(object source) { + void CheckDataSource(object source) { if (source == null) { throw new MissingDataSourceException(); } @@ -175,7 +167,7 @@ namespace SharpReportCore { } } }else { - throw new ArgumentException("DataManager:No Tables in DataSet"); + throw new MissingDataSourceException(); } return; } @@ -186,24 +178,13 @@ namespace SharpReportCore { this.dataSource = list; this.dataMember = source.ToString(); if (list.Count == 0) { - //System.Console.WriteLine("List mit {0} Rows",list.Count); - throw new ArgumentException("No empty IList allowed"); + throw new MissingDataSourceException(); } return; } -// if (source is IList) { -// IList list = source as IList; -// this.dataSource = list; -// this.dataMember = source.ToString(); -// if (list.Count == 0) { -// //System.Console.WriteLine("List mit {0} Rows",list.Count); -// throw new ArgumentException("No empty IList allowed"); -// } -// return; -// } } else { - throw new ArgumentException ("DataManager:Wrong DataSource"); + throw new MissingDataSourceException(); } } @@ -215,7 +196,7 @@ namespace SharpReportCore { } connection.Open(); connection.Close(); - } catch (Exception ) { + } catch (Exception) { throw; } } @@ -296,14 +277,25 @@ namespace SharpReportCore { this.ListChanged (this,e); } } + private void NotifyGroupChanging () { + if (this.GroupChanging!= null) { + this.GroupChanging (this,EventArgs.Empty); + } + } - private void NotifyGroupChange (object sender,GroupChangedEventArgs e) { - - if (this.GroupChanged != null) { - this.GroupChanged (this,e); + private void NotifyGroupChanged() { + if (this.IsGrouped) { + if (this.GroupChanged != null) { + this.GroupChanged (this,new GroupChangedEventArgs(this.groupSeperator)); + } } + } + private void OnGroupChange (object sender,GroupChangedEventArgs e) { + this.groupSeperator = e.GroupSeperator; + this.NotifyGroupChanging(); + } #endregion public string DataMember { @@ -319,59 +311,13 @@ namespace SharpReportCore { } - - public IHierarchicalArray IHierarchicalArray { - get { - return (IHierarchicalArray)this.dataViewStrategy.IHierarchicalEnumerable; - } - } - - - - - /* - - public void PerformHierarchy (IHierarchicalEnumerable list) { - - IEnumerator iter = list.GetEnumerator(); - System.Console.WriteLine("PerformHierarchy"); - if (iter != null) { - while (iter.MoveNext()){ - GroupSeperator g = (GroupSeperator)iter.Current; - System.Console.WriteLine("list {0} {1}",g.Path,g.ListIndex); - - CheckGroups (g); - } - } else { - throw new SystemException("PerformHierarchy: No valid IEnumerator"); - } - } - - private void CheckGroups(GroupSeperator sep) { - System.Console.WriteLine("CheckGroups"); - IEnumerator children = ((IHierarchicalEnumerable)sep.GetChildren()).GetEnumerator(); - while (children.MoveNext()) { - System.Console.WriteLine("children"); - } - } - - public IHierarchicalEnumerable HierarchicalList { - get { - return hierarchicalList; - } - } - */ - + #region SharpReportCore.IDataContainer interface implementation public object DataSource { get { return this.dataSource; } - set { - this.dataSource = value; - Reset(); - } } public int CurrentRow { @@ -399,9 +345,8 @@ namespace SharpReportCore { public bool DataBind() { - this.dataViewStrategy.Bind(); - this.dataViewStrategy.GroupChanged += new EventHandler (NotifyGroupChange); CheckReportColumns(); + this.dataViewStrategy.Bind(); return true; } @@ -411,11 +356,30 @@ namespace SharpReportCore { public void FetchData(ReportItemCollection collection) { - try { - foreach (IItemRenderer item in collection) { - this.dataViewStrategy.Fill(item); - } - } catch (Exception) { + foreach (IItemRenderer item in collection) { + this.dataViewStrategy.Fill(item); + } + this.NotifyGroupChanged(); + } + + /// + /// Indicate's if the current has ChildRows + /// + public bool HasChilds { + get { + return this.dataViewStrategy.HasChilds; + } + } + + /// + /// Returns a , be carefull, this list is only a Indexlist + /// to the actuall data + /// + + + public SharpIndexCollection ChildRows { + get { + return this.dataViewStrategy.ChildRows; } } @@ -436,7 +400,7 @@ namespace SharpReportCore { public object Current { get { - throw new NotImplementedException("DataManager.Current"); + throw new NotImplementedException(); } } @@ -463,10 +427,40 @@ namespace SharpReportCore { } } + public bool IsSorted { + get { + return this.dataViewStrategy.IsSorted; + } + } + + public bool IsFiltered { + get { + return this.dataViewStrategy.IsFiltered; + } + } #region System.IDisposable interface implementation public void Dispose() { - this.connectionObject = null; - this.dataViewStrategy = null; + this.Dispose(true); + GC.SuppressFinalize(this); + } + + ~DataManager(){ + Dispose(false); + } + + protected virtual void Dispose(bool disposing){ + try { + if (disposing) { + // Free other state (managed objects). + if (this.dataViewStrategy != null) { + this.dataViewStrategy.Dispose(); + } + } + } finally { + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. + } } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/ExtendedPropertyDescriptor.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/ExtendedPropertyDescriptor.cs index 8010f8b3b0..483fa7cf2f 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/ExtendedPropertyDescriptor.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/ExtendedPropertyDescriptor.cs @@ -8,7 +8,7 @@ namespace SharpReportCore { /// This class supports data binding /// public class SharpPropertyDescriptor : PropertyDescriptor{ - bool readOnly; + Type componentType; Type propertyType; PropertyInfo prop; @@ -18,65 +18,59 @@ namespace SharpReportCore { { this.componentType = componentType; this.propertyType = propertyType; - this.readOnly= false; } - public override object GetValue (object component) - { - if (!componentType.IsAssignableFrom(component.GetType())) - { + public override object GetValue (object component){ + if (!componentType.IsAssignableFrom(component.GetType())){ return null; } - if (prop == null) + if (prop == null) { prop = componentType.GetProperty (Name); - object o = prop.GetValue (component, null); - if (o is IList) - { - PropertyTypeHash.Instance[componentType, Name] = SharpArrayList.GetElementType((IList)o, componentType, Name); } - return o; + + object obj = prop.GetValue (component, null); + if (obj != null) { + if (obj is IList){ + PropertyTypeHash.Instance[componentType, Name] = SharpDataCollection.GetElementType((IList)obj, componentType, Name); + } + } + return obj; } - public override void SetValue(object component, object value) - { - if (IsReadOnly) + + public override void SetValue(object component, object value) { + if (IsReadOnly){ return; - - if (prop == null) + } + if (prop == null){ prop = componentType.GetProperty (Name); - + } prop.SetValue (component, value, null); } - public override void ResetValue(object component) - { + public override void ResetValue(object component) { return; } - public override bool CanResetValue(object component) - { + public override bool CanResetValue(object component) { return false; } - public override bool ShouldSerializeValue(object component) - { + public override bool ShouldSerializeValue(object component) { return false; } - public override Type ComponentType - { + public override Type ComponentType{ get { return componentType; } } - public override bool IsReadOnly - { - get { return readOnly; } + public override bool IsReadOnly{ + get { return false; } } - public override Type PropertyType - { + public override Type PropertyType{ get { return propertyType; } } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IExtendedList.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IExtendedList.cs deleted file mode 100644 index a0ebff1853..0000000000 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IExtendedList.cs +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Created by SharpDevelop. - * User: Forstmeier Helmut - * Date: 04.08.2005 - * Time: 09:06 - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ - using System; - using System.Collections; - - namespace SharpReportCore { - - - public interface IExtendedList{ - - /// - /// Build the Hash/IndexList we need for indexing the DataSource - /// - void BuildHashList (IList list); - - /// - /// This List is used as an Index to the DataSource - /// ListItems are added by derived Classes - /// - IList IndexList{ - get; - } - - /// - /// returns the Name of the - /// - string Name { - get; - } - - /// - /// CurrentPosition in - /// - int CurrentPosition { - get;set; - } - } - } - diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IHierarchicalArray.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IHierarchicalArray.cs deleted file mode 100644 index ed714733b4..0000000000 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IHierarchicalArray.cs +++ /dev/null @@ -1,41 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 1.1.4322.2032 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace SharpReportCore { - using System; - using SharpReportCore; - using System.Collections; - - /// - /// - /// - /// - /// created by - Forstmeier peter - /// created on - 02.12.2005 13:42:08 - /// - public class IHierarchicalArray : ArrayList,IHierarchicalEnumerable { - - /// - /// Default constructor - initializes all fields to default values - /// - public IHierarchicalArray(){ - } - - - #region SharpReportCore.IHierarchicalEnumerable interface implementation - public IHierarchyData GetHierarchyData(Object enumeratedItem) { - return enumeratedItem as IHierarchyData; - - } - #endregion - - - } -} diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/PropertyTypeHash.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/PropertyTypeHash.cs index 8a0a987c23..7dde193fb6 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/PropertyTypeHash.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/PropertyTypeHash.cs @@ -12,22 +12,22 @@ namespace SharpReportCore{ Hashtable types = new Hashtable(); - private string MakeIndex(Type t, string name) + private static string MakeIndex(Type t, string name) { return t.FullName + '.' + name; } - public object this[Type t, string fieldName] + public object this[Type type, string fieldName] { get { - return types[MakeIndex(t, fieldName)]; + return types[MakeIndex(type, fieldName)]; } set { if (value == null) return; - string key = MakeIndex(t, fieldName); + string key = MakeIndex(type, fieldName); if (!types.Contains(key)) types.Add(key, value); } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs index 2183f39bc2..15085c018b 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs @@ -1,306 +1,229 @@ using System; using System.Data; +using System.Diagnostics; using System.Reflection; using System.Collections; using System.ComponentModel; using System.Collections.Generic; +using System.Collections.ObjectModel; + namespace SharpReportCore { - + /// + /// This class act'S as a IndexList to + /// /// - public class SharpArrayList : ArrayList, IBindingList ,ITypedList,IExtendedList - { - Type elementType; + public class SharpIndexCollection :List { string name; int currentPosition; - bool allowNew = true; - bool allowEdit = true; - bool allowRemove = true; - bool supportsSearching ; - bool supportsSorting ; - bool isSorted; - - private ListChangedEventArgs resetEvent = new ListChangedEventArgs(ListChangedType.Reset, -1); - - public event ListChangedEventHandler ListChanged; - - - public SharpArrayList(Type elementType,string name){ - this.Clear(); - this.elementType = elementType; - this.name = name; - Reset(); + public SharpIndexCollection():this ("SharpIndexList"){ } - #region ITypedList Member - - public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){ - if (listAccessors != null && listAccessors.Length > 0){ - Type t = this.elementType; - for(int i = 0; i < listAccessors.Length; i++){ - PropertyDescriptor pd = listAccessors[i]; - // System.Diagnostics.Debug.WriteLine("*** " + t.FullName + ": " + pd.Name); - t = (Type) PropertyTypeHash.Instance[t, pd.Name]; - } - // System.Diagnostics.Debug.WriteLine("*** New Collection for " + t.FullName); - // if t is null an empty list will be generated - return SharpTypeDescriptor.GetProperties(t); - } - return SharpTypeDescriptor.GetProperties(elementType); - } - - public static Type GetElementType(IList list, - Type parentType, - string propertyName){ - SharpArrayList al = list as SharpArrayList; - if (al == null) - return null; - return al.elementType; - } -#if longVersion - public static Type GetElementType(IList list, - Type parentType, - string propertyName){ - SharpArrayList al = null; - object element = null; - al = CheckForArrayList(list); - if (al == null){ - if (list.Count > 0){ - element = list[0]; - } - } - if (al == null && element == null){ - PropertyInfo pi = parentType.GetProperty(propertyName); - if (pi != null){ - object parentObject = null; - try{ - parentObject = Activator.CreateInstance(parentType); - } - catch(Exception ex) {} - - if (parentObject != null){ - list = pi.GetValue(parentObject, null) as IList; - al = CheckForArrayList(list); - } - } - } - if (al != null){ - return al.elementType; - } - else if (element != null){ - return element.GetType(); - } - return null; - } - - - private static SharpArrayList CheckForArrayList(object l){ - IList list = l as IList; - if (list == null) - return null; - if (list.GetType().FullName == "System.Collections.ArrayList+ReadOnlyArrayList"){ - FieldInfo fi = list.GetType().GetField("_list", BindingFlags.NonPublic | BindingFlags.Instance); - if (fi != null){ - list = (IList) fi.GetValue(list); - } - } - return list as SharpArrayList; - } -#endif - - - - public string GetListName(PropertyDescriptor[] listAccessors){ - return elementType.Name; - } - - #endregion - - protected void Reset(){ - this.currentPosition = 0; - this.OnListChange (resetEvent); - } - - private void OnListChange (ListChangedEventArgs handler) { - if (this.ListChanged != null) { - this.ListChanged (this,handler); - } + public SharpIndexCollection(string name){ + this.name = name; } - #region System.ComponentModel.IBindingList interface implementation - public bool AllowNew { + #region properties + + public int CurrentPosition { get { - return this.allowNew; + return currentPosition; } - } - - public bool AllowEdit { - get { - return this.allowEdit; + set { + currentPosition = value; } } - public bool AllowRemove { + public string Name { get { - return this.allowRemove; + return name; } } - public bool SupportsChangeNotification { - get { - return true; - } - } - public bool SupportsSearching { - get { - return this.supportsSearching; - } - set { - this.supportsSearching = value; - } - } + #endregion + } + + /// + /// This class act's as a store of the original Data + /// + + public class SharpDataCollection : IList,ITypedList{ + Collection list = new Collection(); + Type elementType; - public bool SupportsSorting { - get { - return this.supportsSorting; - } - set { - this.supportsSorting = value; - } + public SharpDataCollection(Type elementType) + { + this.elementType = elementType; } - - public bool IsSorted { + + public T this[int index] { get { - return this.isSorted; + return list[index]; } set { - this.isSorted = value; + T oldValue = list[index]; + if (!object.Equals(oldValue, value)) { + list[index] = value; + } } } - public System.ComponentModel.PropertyDescriptor SortProperty { + public int Count { + [DebuggerStepThrough] get { - return null; + return list.Count; } } - public System.ComponentModel.ListSortDirection SortDirection { + public bool IsReadOnly { get { - return ListSortDirection.Ascending; + return false; } } - public void RemoveSort() { - throw new NotImplementedException("RemoveSort"); - } - //TODO Test fehlt - public void RemoveIndex(System.ComponentModel.PropertyDescriptor property) { - throw new NotImplementedException("RemoveIndex"); + public int IndexOf(T item) + { + return list.IndexOf(item); } - //TODO Test fehlt - public int Find(System.ComponentModel.PropertyDescriptor property, object key) { -// return 0; - throw new NotImplementedException("Find"); + public void Insert(int index, T item) + { + list.Insert(index, item); } - //TODO Test fehlt - public void ApplySort(System.ComponentModel.PropertyDescriptor property, System.ComponentModel.ListSortDirection direction) { - throw new NotImplementedException("ApplySort"); - } - //TODO Test fehlt - public void AddIndex(System.ComponentModel.PropertyDescriptor property) { - throw new NotImplementedException("AddIndex"); + + public void RemoveAt(int index) + { +// T item = list[index]; + list.RemoveAt(index); } - public object AddNew() { - throw new NotImplementedException("AddNew"); + public void Add(T item) + { + list.Add(item); } - #endregion - - #region overrides - public override int Add(object value) { - if (this.elementType.GetType().IsAssignableFrom (value.GetType())) { - System.Console.WriteLine("type ok"); - } - if ((value.GetType().IsSubclassOf(this.elementType))||( value.GetType() == this.elementType)){ - if (this.allowNew) { - int i = base.Add(value); - this.OnListChange (new ListChangedEventArgs(ListChangedType.ItemAdded,i)); - return i; - } else { - throw new NotSupportedException("SharpArrayList:Add(object)"); - } - } else { - string str = String.Format("Add:Wrong Type {0} {1}",this.elementType,value.GetType()); - throw new ArgumentException(str); + public void AddRange(IList range) + { + foreach(T t in range) { + Add(t); } } + - public override void AddRange(System.Collections.ICollection c) { - foreach (object o in c) { - this.Add (o); - } + public void Clear(){ + list = new Collection(); } - - public override void RemoveAt(int index) { - if (this.allowRemove) { - if (index > -1) { - base.RemoveAt(index); - this.OnListChange (new ListChangedEventArgs(ListChangedType.ItemDeleted,index)); - } - } else { - throw new NotSupportedException("SharpArrayList:RemoveAt (index)"); - } + public bool Contains(T item) + { + return list.Contains(item); } - - #endregion - - - #region SharpReport.Data.IExtendedList interface implementation - public string Name { - get { - return this.name; - } - + public void CopyTo(T[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); } - public int CurrentPosition { - get { - return currentPosition; + public bool Remove(T item) + { + if (list.Remove(item)) { + return true; } - set { - currentPosition = value; + return false; + } + #region ITypedList Member + + public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){ + if (listAccessors != null && listAccessors.Length > 0){ + Type t = this.elementType; + + for(int i = 0; i < listAccessors.Length; i++){ + PropertyDescriptor pd = listAccessors[i]; + t = (Type) PropertyTypeHash.Instance[t, pd.Name]; + } + // if t is null an empty list will be generated + return SharpTypeDescriptor.GetProperties(t); } + return SharpTypeDescriptor.GetProperties(elementType); + } + public string GetListName(PropertyDescriptor[] listAccessors){ + return elementType.Name; } - - public IList IndexList { - get { - return(IList)this; + public static Type GetElementType(IList list, Type parentType, string propertyName) + { + SharpDataCollection al = null; + object element = null; + al = CheckForArrayList(list); + if (al == null) + { + if (list.Count > 0) + { + element = list[0]; + } } + if (al == null && element == null) + { + PropertyInfo pi = parentType.GetProperty(propertyName); + if (pi != null) + { + object parentObject = null; + try + { + parentObject = Activator.CreateInstance(parentType); + } + catch(Exception) {} + if (parentObject != null) + { + list = pi.GetValue(parentObject, null) as IList; + al = CheckForArrayList(list); + } + } + } + if (al != null) + { + return al.elementType; + } + else if (element != null) + { + return element.GetType(); + } + return null; } - public void BuildHashList(IList list) { - throw new NotImplementedException("SharpArrayList:BuildHashList"); -/* - this.Clear(); - for (int i = 0;i < list.Count ;i++ ) { -// this.Add (new PlainIndexItem(i,"satz " + i.ToString())); + private static SharpDataCollection CheckForArrayList(object l) + { + IList list = l as IList; + if (list == null) + return null; + if (list.GetType().FullName == "System.Collections.ArrayList+ReadOnlyArrayList") + { + FieldInfo fi = list.GetType().GetField("_list", BindingFlags.NonPublic | BindingFlags.Instance); + if (fi != null) + { + list = (IList) fi.GetValue(list); + } } - this.OnListChange (new ListChangedEventArgs(ListChangedType.Reset,-1,-1)); - */ + return list as SharpDataCollection; } #endregion + [DebuggerStepThrough] + public IEnumerator GetEnumerator() + { + return list.GetEnumerator(); + } + [DebuggerStepThrough] + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return list.GetEnumerator(); + } } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs index 0210c1f82b..38209cf79b 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using SharpReportCore; /// -/// BaseClass for all datahandling Strategies +/// BaseClass for all Datahandling Strategies /// /// /// created by - Forstmeier Peter @@ -30,10 +30,9 @@ namespace SharpReportCore { private bool isGrouped; //Index to plain Datat - private SharpArrayList indexList; + private SharpIndexCollection indexList; private ReportSettings reportSettings; - private IHierarchicalArray hierarchicalList; - + private ListChangedEventArgs resetList = new ListChangedEventArgs(ListChangedType.Reset,-1,-1); @@ -43,20 +42,16 @@ namespace SharpReportCore { #region Constructor protected BaseListStrategy(ReportSettings reportSettings) { + if (reportSettings == null) { + throw new ArgumentNullException("reportSettings"); + } this.reportSettings = reportSettings; - this.indexList = new SharpArrayList(typeof(BaseComparer),"IndexList"); + this.indexList = new SharpIndexCollection("IndexList"); } #endregion #region Event's - protected void NotifyGroupChange (object source,GroupSeperator groupSeperator) { - - if (this.GroupChanged != null) { - this.GroupChanged (source,new GroupChangedEventArgs(groupSeperator)); - } - } - protected void NotifyResetList(){ if (this.ListChanged != null) { @@ -64,10 +59,18 @@ namespace SharpReportCore { } } + protected void NotifyGroupChanging (object source,GroupSeperator groupSeperator) { + + if (this.GroupChanged != null) { + this.GroupChanged (source,new GroupChangedEventArgs(groupSeperator)); + } + } + + #endregion - public SharpArrayList IndexList { + public SharpIndexCollection IndexList { get { return indexList; } @@ -79,21 +82,87 @@ namespace SharpReportCore { return reportSettings; } } + #region Building Groups + + private static void WriteToIndexFile (SharpIndexCollection destination,BaseComparer comparer) { + SortComparer sc = comparer as SortComparer; +// if (sc != null) { +// System.Console.WriteLine("\t {0} - <{1}>",comparer.ListIndex, comparer.ObjectArray[0].ToString()); +// } else { +// System.Console.WriteLine("Wrong comparer"); +// } + destination.Add(comparer); + } - protected void CheckSortArray (ArrayList arr,string text){ -// System.Console.WriteLine(""); + private static GroupSeperator BuildGroupSeperator (BaseComparer newGroup,int groupLevel) { + + GroupSeperator seperator = new GroupSeperator (newGroup.ColumnCollection, + newGroup.ListIndex, + newGroup.ObjectArray, + groupLevel); + +// System.Console.WriteLine("Add Parent <{0}>",seperator.ObjectArray[0].ToString()); + return seperator; + } + + + protected void MakeGroupedIndexList (SharpIndexCollection sourceList) { + if (sourceList == null) { + throw new ArgumentNullException("sourceList"); + } + int level = 0; + this.indexList.Clear(); + + + SortComparer compareComparer = null; + GroupSeperator parent = null; +// System.Console.WriteLine("MakeGroupedIndexList with {0} rows",sourceList.Count); + for (int i = 0;i < sourceList.Count ;i++ ) { + SortComparer currentComparer = (SortComparer)sourceList[i]; + /* + System.Console.WriteLine("\t\t\t performing nr {0}",i); + if (i == 68) { + System.Console.WriteLine("last"); + } + */ + if (compareComparer != null) { + string str1,str2; + str1 = currentComparer.ObjectArray[0].ToString(); + str2 = compareComparer.ObjectArray[0].ToString(); + int compareVal = str1.CompareTo(str2); + + if (compareVal != 0) { + BaseListStrategy.WriteToIndexFile(parent.GetChildren,compareComparer); + parent = BaseListStrategy.BuildGroupSeperator (currentComparer,level); + this.indexList.Add(parent); + BaseListStrategy.WriteToIndexFile(parent.GetChildren,currentComparer); + } else { + BaseListStrategy.WriteToIndexFile(parent.GetChildren,compareComparer); + + } + } + else { + parent = BaseListStrategy.BuildGroupSeperator (currentComparer,level); + this.indexList.Add(parent); + } + compareComparer = (SortComparer)sourceList[i]; + } + BaseListStrategy.WriteToIndexFile(parent.GetChildren,compareComparer); + } + + #endregion + + protected static void CheckSortArray (SharpIndexCollection arr,string text){ + System.Console.WriteLine("{0}",text); -// string tabs = String.Empty; if (arr != null) { int row = 0; foreach (BaseComparer bc in arr) { GroupSeperator sep = bc as GroupSeperator; if (sep != null) { - -// System.Console.WriteLine("\t Group change {0} level {1}",sep.ObjectArray[0].ToString(), -// sep.GroupLevel); + } else { object [] oarr = bc.ObjectArray; @@ -107,12 +176,10 @@ namespace SharpReportCore { } } - System.Console.WriteLine("----------------"); - System.Console.WriteLine(""); + System.Console.WriteLine("-----End of -----------"); + } - - #region SharpReportCore.IDataViewStrategy interface implementation public virtual ColumnCollection AvailableFields { @@ -133,8 +200,7 @@ namespace SharpReportCore { } set { if (value > this.indexList.Count){ - throw new IndexOutOfRangeException ("There is no row at " + - "currentRow: " + value + "."); + throw new IndexOutOfRangeException (); } this.indexList.CurrentPosition = value; } @@ -167,15 +233,10 @@ namespace SharpReportCore { get { return this.isGrouped; } - set { - this.isGrouped = true; - } } protected virtual void Group() { - if (this.indexList != null) { - this.BuildHierarchicalList (this.indexList); this.isGrouped = true; this.isSorted = true; } else { @@ -185,123 +246,77 @@ namespace SharpReportCore { } - protected IHierarchicalArray HierarchicalList { - get { - return hierarchicalList; - } - } - - + + public virtual void Sort() { + this.indexList.Clear(); + } + public virtual void Reset() { + this.NotifyResetList(); + } - private GroupSeperator MakeSeperator (BaseComparer newGroup,int groupLevel) { + public virtual void Bind() { - GroupSeperator seperator = new GroupSeperator (newGroup.ColumnCollection, - newGroup.ListIndex, - newGroup.ObjectArray, - groupLevel); -// System.Console.WriteLine(""); -// System.Console.WriteLine("\t Group change {0} level {1}",seperator.ObjectArray[0].ToString(), -// seperator.GroupLevel); -// System.Console.WriteLine(""); - return seperator; } + public virtual void Fill(IItemRenderer item) { - private IHierarchicalEnumerable BuildHierarchicalList(ArrayList sourceList) { - IHierarchicalArray destList = new IHierarchicalArray(); - IHierarchicalArray childList = new IHierarchicalArray(); - int level = 0; - -// System.Console.WriteLine(""); -// System.Console.WriteLine("BuildHierachicalList"); - -// ColumnCollection grBy =this.reportSettings.GroupColumnsCollection; -// string columnName = grBy[level].ColumnName; - - GroupComparer compareComparer = null; - GroupSeperator seperator = null; - - destList.Clear(); - childList.Clear(); - - for (int i = 0;i < sourceList.Count ;i++ ) { - GroupComparer currentComparer = (GroupComparer)sourceList[i]; - - if (compareComparer != null) { - string str1,str2; - str1 = currentComparer.ObjectArray[0].ToString(); - str2 = compareComparer.ObjectArray[0].ToString(); - int compareVal = str1.CompareTo(str2); - - if (compareVal != 0) { - -// System.Console.WriteLine("child list with {0} entries",childList.Count); - - seperator.Childs = childList; - /* - //testcode - if (childList != null) { - foreach (BaseComparer bc in seperator.Childs) { - System.Console.WriteLine("\t {0} {1}",bc.ListIndex, - bc.ObjectArray[0].ToString()); - } - } - // end testCode - */ - - childList = new IHierarchicalArray(); - seperator = MakeSeperator (currentComparer,level); - - childList.Clear(); - destList.Add (seperator); + } + + public bool HasChilds { + get { + if (this.IsGrouped == true) { + GroupSeperator gs = (GroupSeperator)this.indexList[this.CurrentRow] as GroupSeperator; + if (gs != null) { + return (gs.GetChildren.Count > 0); + } else { + return false; } + } else { + return false; } - else { -// System.Console.WriteLine("\t\t Start of List {0}",currentComparer.ObjectArray[0].ToString()); -// -// System.Console.WriteLine("Group change "); - seperator = MakeSeperator (currentComparer,level); - childList.Clear(); - destList.Add (seperator); - seperator.Childs = childList; - } -// System.Console.WriteLine("write {0} {1}",currentComparer.ListIndex,currentComparer.ObjectArray[0].ToString()); - - childList.Add (currentComparer); - compareComparer = (GroupComparer)sourceList[i]; - } - // Add the last list - seperator.Childs = childList; - this.hierarchicalList = destList; - return destList; } - public IHierarchicalEnumerable IHierarchicalEnumerable { + public SharpIndexCollection ChildRows { get { - return this.hierarchicalList; + if (this.IsGrouped == true) { + GroupSeperator gs = (GroupSeperator)this.indexList[this.CurrentRow] as GroupSeperator; + if (gs != null) { + return (gs.GetChildren); + } else { + return null; + } + } else { + return null; + } } } - public virtual void Sort() { - + public virtual void Dispose(){ + this.Dispose(true); + GC.SuppressFinalize(this); } - public virtual void Reset() { - this.NotifyResetList(); + ~BaseListStrategy(){ + Dispose(false); } - public virtual void Bind() { + protected virtual void Dispose(bool disposing){ + if (disposing) { + // Free other state (managed objects). + if (this.indexList != null) { + this.indexList.Clear(); + this.indexList = null; + } + } - } - - public virtual void Fill(IItemRenderer item) { + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. } #endregion } - - } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs index bf21af0726..f1a26a2a4b 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs @@ -23,29 +23,67 @@ namespace SharpReportCore { public class CollectionStrategy : BaseListStrategy { // Holds the plain Data - private SharpArrayList baseList; - + private Type itemType; private object firstItem; private object current; private PropertyDescriptorCollection listProperties; + private SharpDataCollection baseList; + + public CollectionStrategy(IList list,string dataMember,ReportSettings reportSettings):base(reportSettings) { + if (list.Count > 0) { firstItem = list[0]; itemType = firstItem.GetType(); - this.baseList = new SharpArrayList(itemType,dataMember); + + this.baseList = new SharpDataCollection (itemType); this.baseList.AddRange(list); - this.baseList.CurrentPosition = 0; - this.current = this.baseList[0]; } + + this.listProperties = this.baseList.GetItemProperties(null); } - + private void BuildGroup(){ -// throw new NotImplementedException("No grouping at the time"); - return; + + try { + SharpIndexCollection groupedArray = new SharpIndexCollection(); + + if (base.ReportSettings.GroupColumnsCollection != null) { + if (base.ReportSettings.GroupColumnsCollection.Count > 0) { + this.BuildSortIndex (groupedArray,base.ReportSettings.GroupColumnsCollection); + } + } + + base.MakeGroupedIndexList (groupedArray); + + + foreach (BaseComparer bc in this.IndexList) { + GroupSeperator gs = bc as GroupSeperator; + + if (gs != null) { + System.Console.WriteLine("Group Header <{0}> with <{1}> Childs ",gs.ObjectArray[0].ToString(),gs.GetChildren.Count); + if (gs.HasChildren) { + foreach (SortComparer sc in gs.GetChildren) { + + System.Console.WriteLine("\t {0} {1}",sc.ListIndex,sc.ObjectArray[0].ToString()); } + } + } else { + SortComparer sc = bc as SortComparer; + + if (sc != null) { + System.Console.WriteLine("\t Child {0}",sc.ObjectArray[0].ToString()); + } + } + + } + } catch (Exception e) { + System.Console.WriteLine("BuildGroup {0}",e.Message); + throw; + } } private PropertyDescriptor[] BuildSortProperties (ColumnCollection col){ @@ -66,69 +104,54 @@ namespace SharpReportCore { } #region Index Building - - //Sorted Indexlist - private ArrayList BuildSortIndex(ColumnCollection col) { - + private void BuildSortIndex(SharpIndexCollection arrayList,ColumnCollection col) { PropertyDescriptor[] sortProperties = BuildSortProperties (col); - - // Übertragen der zu sortierenden Werte in eine standartComparer Auflistung - ArrayList sortValues = new ArrayList(this.baseList.Count); - try { - for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){ - object rowItem = this.baseList[rowIndex]; - object[] values = new object[col.Count]; + for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){ + object rowItem = this.baseList[rowIndex]; + object[] values = new object[col.Count]; + + // Hier bereits Wertabruf um dies nicht während des Sortierens tun zu müssen. + for (int criteriaIndex = 0; criteriaIndex < sortProperties.Length; criteriaIndex++){ + object value = sortProperties[criteriaIndex].GetValue(rowItem); + // Hier auf Verträglichkeit testen um Vergleiche bei Sortierung zu vereinfachen. + // Muss IComparable und gleicher Typ sein. - // Hier bereits Wertabruf um dies nicht während des Sortierens tun zu müssen. - for (int criteriaIndex = 0; criteriaIndex < sortProperties.Length; criteriaIndex++){ - object value = sortProperties[criteriaIndex].GetValue(rowItem); - // Hier auf Verträglichkeit testen um Vergleiche bei Sortierung zu vereinfachen. - // Muss IComparable und gleicher Typ sein. - - if (value != null && value != DBNull.Value) - { - if (!(value is IComparable)){ - throw new InvalidOperationException("ReportDataSource:BuildSortArray - > This type doesn't support IComparable." + value.ToString()); - } - - values[criteriaIndex] = value; + if (value != null && value != DBNull.Value) + { + if (!(value is IComparable)){ + throw new InvalidOperationException("ReportDataSource:BuildSortArray - > This type doesn't support IComparable." + value.ToString()); } + + values[criteriaIndex] = value; } - sortValues.Add(new SortComparer(col, rowIndex, values)); } - } catch (Exception) { - throw ; + arrayList.Add(new SortComparer(col, rowIndex, values)); } - - sortValues.Sort(); - return sortValues; + arrayList.Sort(); } + + + // if we have no sorting, we build the indexlist as well, so we don't need to //check each time we reasd data if we have to go directly or by IndexList - - private ArrayList BuildPlainIndex(ColumnCollection col) { + private void BuildPlainIndex(SharpIndexCollection arrayList,ColumnCollection col) { PropertyDescriptor[] sortProperties = new PropertyDescriptor[1]; PropertyDescriptorCollection c = this.baseList.GetItemProperties(null); PropertyDescriptor descriptor = c[0]; sortProperties[0] = descriptor; - ArrayList sortValues = new ArrayList(this.baseList.Count); - try { - for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){ - object[] values = new object[1]; - - // We insert only the RowNr as a dummy value - values[0] = rowIndex; - sortValues.Add(new BaseComparer(col, rowIndex, values)); - } - } catch (Exception) { - throw ; + + for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){ + object[] values = new object[1]; + + // We insert only the RowNr as a dummy value + values[0] = rowIndex; + arrayList.Add(new BaseComparer(col, rowIndex, values)); } - return sortValues;; } - - + + #endregion #region SharpReportCore.IDataViewStrategy interface implementation @@ -156,7 +179,6 @@ namespace SharpReportCore { set { base.CurrentRow = value; - current = this.baseList[((BaseComparer)base.IndexList[value]).ListIndex]; } } @@ -164,28 +186,19 @@ namespace SharpReportCore { public override void Sort() { base.Sort(); - ArrayList sortedArray = new ArrayList(); - try { - ColumnCollection sortColumnCollection = base.ReportSettings.SortColumnCollection; - if (sortColumnCollection != null) { - if (sortColumnCollection.Count > 0) { - sortedArray = this.BuildSortIndex (sortColumnCollection); - base.IsSorted = true; - } else { - sortedArray = BuildPlainIndex (sortColumnCollection); - base.IsSorted = false; - } + if ((base.ReportSettings.SortColumnCollection != null)) { + if (base.ReportSettings.SortColumnCollection.Count > 0) { + this.BuildSortIndex (base.IndexList, + base.ReportSettings.SortColumnCollection); + + + base.IsSorted = true; +// BaseListStrategy.CheckSortArray (base.IndexList,"TableStrategy - CheckSortArray"); + } else { + this.BuildPlainIndex(base.IndexList, + base.ReportSettings.SortColumnCollection); + base.IsSorted = false; } - - base.IndexList.Clear(); - base.IndexList.AddRange (sortedArray); -// base.CheckSortArray (sortedArray,"CollectionStrategy - CheckSortArray"); - } catch (Exception) { - throw; - } - - if (base.IndexList == null){ - throw new NotSupportedException("Sortieren für die Liste nicht unterstützt."); } } @@ -200,24 +213,23 @@ namespace SharpReportCore { public override void Bind() { base.Bind(); - if (base.IndexList.Count > 0) { - base.IndexList.Clear(); - } - this.listProperties = this.baseList.GetItemProperties(null); if ((base.ReportSettings.GroupColumnsCollection != null) && (base.ReportSettings.GroupColumnsCollection.Count > 0)) { - BuildGroup (); + this.Group (); + Reset(); + return; } - this.Sort (); - this.Reset(); - base.NotifyResetList(); + if (base.ReportSettings.SortColumnCollection != null) { + this.Sort (); + } + Reset(); } public override void Fill(IItemRenderer item) { - base.Fill(item); - if (current != null) { - try { + try { + base.Fill(item); + if (current != null) { BaseDataItem baseDataItem = item as BaseDataItem; PropertyDescriptor p = this.listProperties.Find (baseDataItem.ColumnName,true); @@ -225,12 +237,50 @@ namespace SharpReportCore { baseDataItem.DbValue = ""; baseDataItem.DbValue = p.GetValue(this.current).ToString(); } - } catch (Exception) { - } + } catch (System.NullReferenceException) { + + } + + } + + protected override void Group() { + if (base.ReportSettings.GroupColumnsCollection.Count == 0) { + return; } + this.BuildGroup(); + base.Group(); } + + #endregion + #region IDisposable + + public override void Dispose(){ + this.Dispose(true); + GC.SuppressFinalize(this); + } + + ~CollectionStrategy(){ + Dispose(false); + } + + protected override void Dispose(bool disposing){ + try { + if (disposing) { + if (this.baseList != null) { + this.baseList.Clear(); + this.baseList = null; + } + } + } finally { + base.Dispose(disposing); + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. + } + } + #endregion } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs index 627e93d79d..b9faf19617 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs @@ -24,7 +24,7 @@ namespace SharpReportCore { /// created by - Forstmeier Peter /// created on - 23.10.2005 15:12:06 /// - public class TableStrategy : BaseListStrategy,IDisposable { + public class TableStrategy : BaseListStrategy { DataTable table; DataView view = new DataView(); @@ -32,44 +32,19 @@ namespace SharpReportCore { public TableStrategy(DataTable table,ReportSettings reportSettings):base(reportSettings) { + if (table == null) { + throw new ArgumentNullException("table"); + } this.table = table; -// view.ListChanged += new ListChangedEventHandler (OnListChange); + view = this.table.DefaultView; } -// private void OnListChange (object sender,ListChangedEventArgs e) { -// System.Console.WriteLine("called from view"); -// MessageBox.Show ("On List Change"); -// } - /* - private string a_BuildSort(ColumnCollection sortCollection){ - System.Console.WriteLine("BuildSort"); - StringBuilder sb = new StringBuilder(); - for (int i = 0;i < sortCollection.Count ;i++ ) { - SortColumn sc = (SortColumn)sortCollection[i]; - sb.Append(sc.ColumnName); - if (sc.SortDirection == ListSortDirection.Ascending) { - sb.Append (" ASC"); - } else { - sb.Append(" DESC"); - } - sb.Append (","); - } - if (sb.ToString().EndsWith (",")) { - sb.Remove(sb.Length -1,1); - } - System.Console.WriteLine("\tsort by {0}",sb.ToString()); - return sb.ToString(); - } - */ #region Building the Index list - // if we have no sorting, we build the indexlist as well, so we don't need to - //check each time we reasd data if we have to go directly or by IndexList - private ArrayList BuildSortIndex(ColumnCollection col) { + private void BuildSortIndex(SharpIndexCollection arrayList,ColumnCollection col) { - ArrayList sortValues = new ArrayList(this.view.Count); try { for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){ DataRowView rowItem = this.view[rowIndex]; @@ -88,171 +63,79 @@ namespace SharpReportCore { values[criteriaIndex] = DBNull.Value; } } - sortValues.Add(new SortComparer(col, rowIndex, values)); + arrayList.Add(new SortComparer(col, rowIndex, values)); } } catch (Exception) { - + throw; } - sortValues.Sort(); - return sortValues; - } - private ArrayList BuildPlainIndex(ColumnCollection col) { - ArrayList sortValues = new ArrayList(this.view.Count); + arrayList.Sort(); + } + + // if we have no sorting, we build the indexlist as well, so we don't need to + //check each time we reasd data if we have to go directly or by IndexList + private void BuildPlainIndex(SharpIndexCollection arrayList,ColumnCollection col) { try { for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){ object[] values = new object[1]; // We insert only the RowNr as a dummy value values[0] = rowIndex; - sortValues.Add(new BaseComparer(col, rowIndex, values)); + arrayList.Add(new BaseComparer(col, rowIndex, values)); } } catch (Exception) { throw ; } - return sortValues;; } - - private ArrayList BuildGroupIndex(ColumnCollection col) { - ArrayList groupValues = new ArrayList(this.view.Count); - System.Console.WriteLine("\tBuildGroupIndex"); - try { - for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){ - DataRowView rowItem = this.view[rowIndex]; - object[] values = new object[col.Count]; - for (int criteriaIndex = 0; criteriaIndex < col.Count; criteriaIndex++){ - AbstractColumn c = (AbstractColumn)col[criteriaIndex]; - object value = rowItem[c.ColumnName]; - - if (value != null && value != DBNull.Value){ - if (!(value is IComparable)){ - throw new InvalidOperationException("ReportDataSource:BuildSortArray - > This type doesn't support IComparable." + value.ToString()); - } - - values[criteriaIndex] = value; - } else { - values[criteriaIndex] = DBNull.Value; - } - } - groupValues.Add(new GroupComparer(col, rowIndex, values)); - } - } catch (Exception) { - - } - groupValues.Sort(); - - return groupValues; - } - - #endregion #region Grouping - private void WriteToIndexFile (ArrayList destination,int index,GroupComparer comparer) { - destination.Add(comparer); - } - private void BuildGroupSeperator (ArrayList destination,BaseComparer newGroup,int groupLevel) { - - GroupSeperator seperator = new GroupSeperator (newGroup.ColumnCollection, - newGroup.ListIndex, - newGroup.ObjectArray, - groupLevel); - - -// System.Console.WriteLine("\t Group change {0} level {1}",seperator.ObjectArray[0].ToString(), -// seperator.GroupLevel); -// System.Console.WriteLine("write group seperator"); - destination.Add(seperator); - } - - private ArrayList InsertGroupRows (ArrayList sourceList) { - ArrayList destList = new ArrayList(); - - int level = 0; - -// // only for testing -// ColumnCollection grBy = base.ReportSettings.GroupColumnsCollection; -// string columnName = grBy[level].ColumnName; -//// System.Console.WriteLine(""); -// System.Console.WriteLine("InsertGroupRows Grouping for {0}",columnName); - - GroupComparer compareComparer = null; - - for (int i = 0;i < sourceList.Count ;i++ ) { - GroupComparer currentComparer = (GroupComparer)sourceList[i]; - - if (compareComparer != null) { - string str1,str2; - str1 = currentComparer.ObjectArray[0].ToString(); - str2 = compareComparer.ObjectArray[0].ToString(); - int compareVal = str1.CompareTo(str2); - - if (compareVal != 0) { - this.BuildGroupSeperator (destList,currentComparer,level); - } - } - else { -// System.Console.WriteLine("\t\t Start of List {0}",currentComparer.ObjectArray[0].ToString()); - this.BuildGroupSeperator (destList,currentComparer,level); - } - this.WriteToIndexFile (destList,i,currentComparer); - compareComparer = (GroupComparer)sourceList[i]; - } - return destList; - } private void BuildGroup(){ try { - ArrayList groupedArray = new ArrayList(); + SharpIndexCollection groupedArray = new SharpIndexCollection(); if (base.ReportSettings.GroupColumnsCollection != null) { if (base.ReportSettings.GroupColumnsCollection.Count > 0) { - groupedArray = this.BuildGroupIndex (base.ReportSettings.GroupColumnsCollection); - System.Console.WriteLine("\t1"); - } else { - groupedArray = BuildPlainIndex (base.ReportSettings.GroupColumnsCollection); + this.BuildSortIndex (groupedArray,base.ReportSettings.GroupColumnsCollection); } } - - base.IndexList.Clear(); - base.IndexList.AddRange (InsertGroupRows(groupedArray)); - - if (base.IndexList == null){ - throw new NotSupportedException("Sortieren für die Liste nicht unterstützt."); + + base.MakeGroupedIndexList (groupedArray); + +// System.Console.WriteLine("GroupedList with {0} elements",base.IndexList.Count); + /* + foreach (BaseComparer bc in this.IndexList) { + GroupSeperator gs = bc as GroupSeperator; + + if (gs != null) { +// System.Console.WriteLine("Group Header <{0}> with <{1}> Childs ",gs.ObjectArray[0].ToString(),gs.GetChildren.Count); + if (gs.HasChildren) { + foreach (SortComparer sc in gs.GetChildren) { + + System.Console.WriteLine("\t {0} {1}",sc.ListIndex,sc.ObjectArray[0].ToString()); } + } + } else { + SortComparer sc = bc as SortComparer; + + if (sc != null) { + System.Console.WriteLine("\t Child {0}",sc.ObjectArray[0].ToString()); + } + } + } - - + */ } catch (Exception e) { System.Console.WriteLine("BuildGroup {0}",e.Message); throw; } } - - protected override void Group() { - if (base.ReportSettings.GroupColumnsCollection.Count == 0) { - return; - } - - try { - this.BuildGroup(); - base.Group(); - if (this.IsGrouped == false) { - throw new SharpReportException("TableStratregy:Group Error in grouping"); - } - - } catch (Exception e) { - System.Console.WriteLine("Group {0}",e.Message); - base.IsGrouped = false; - base.IsSorted = false; - throw; - } - } - + #endregion @@ -260,12 +143,10 @@ namespace SharpReportCore { public override void Bind() { base.Bind(); - view = this.table.DefaultView; - + if ((base.ReportSettings.GroupColumnsCollection != null) && (base.ReportSettings.GroupColumnsCollection.Count > 0)) { this.Group (); Reset(); - base.NotifyResetList(); return; } @@ -273,47 +154,44 @@ namespace SharpReportCore { this.Sort (); } Reset(); - base.NotifyResetList(); } - public override void Sort () { base.Sort(); - ArrayList sortedArray = new ArrayList(); - try { - if ((base.ReportSettings.SortColumnCollection != null)) { - if (base.ReportSettings.SortColumnCollection.Count > 0) { - SortColumn sc = (SortColumn)base.ReportSettings.SortColumnCollection[0]; - - sortedArray = this.BuildSortIndex (base.ReportSettings.SortColumnCollection); - base.IsSorted = true; - } else { - sortedArray = BuildPlainIndex (base.ReportSettings.SortColumnCollection); - base.IsSorted = false; - } + if ((base.ReportSettings.SortColumnCollection != null)) { + if (base.ReportSettings.SortColumnCollection.Count > 0) { + this.BuildSortIndex (base.IndexList, + base.ReportSettings.SortColumnCollection); + + base.IsSorted = true; + } else { + this.BuildPlainIndex(base.IndexList, + base.ReportSettings.SortColumnCollection); + base.IsSorted = false; } - - base.IndexList.Clear(); - base.IndexList.AddRange (sortedArray); - -// base.CheckSortArray (sortedArray,"TableStrategy - CheckSortArray"); - } catch (Exception) { - throw; } - - if (base.IndexList == null){ - throw new NotSupportedException("Sortieren für die Liste nicht unterstützt."); + } + + protected override void Group() { + if (base.ReportSettings.GroupColumnsCollection.Count == 0) { + return; } + this.BuildGroup(); + base.Group(); } public override void Fill (IItemRenderer item) { try { base.Fill(item); - BaseDataItem baseDataItem = item as BaseDataItem; - if (baseDataItem != null) { - baseDataItem.DbValue = row[baseDataItem.ColumnName].ToString(); + if (this.row != null) { + BaseDataItem baseDataItem = item as BaseDataItem; + if (baseDataItem != null) { + baseDataItem.DbValue = row[baseDataItem.ColumnName].ToString(); + } } - } catch (Exception ) { + + } catch (System.NullReferenceException) { + } } @@ -340,7 +218,7 @@ namespace SharpReportCore { public override int Count { get { - return this.table.Rows.Count; + return this.IndexList.Count; } } @@ -356,31 +234,41 @@ namespace SharpReportCore { GroupSeperator sep = bc as GroupSeperator; if (sep != null) { - base.NotifyGroupChange(this,sep); + base.NotifyGroupChanging(this,sep); } row = this.view[((BaseComparer)base.IndexList[value]).ListIndex]; } } } + #endregion + #region IDisposable - - - public override bool IsSorted { - get { - return (this.view.Sort.Length > 0); - } + public override void Dispose(){ + this.Dispose(true); + GC.SuppressFinalize(this); } - #endregion + ~TableStrategy(){ + Dispose(false); + } - #region IDisposable - public void Dispose(){ - if (this.view != null) { - this.view.Dispose(); + protected override void Dispose(bool disposing){ + try { + if (disposing) { + if (this.view != null) { + this.view.Dispose(); + this.view = null; + } + } + } finally { + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. + base.Dispose(disposing); } + } - #endregion } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs index fda414d547..73e49ff414 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs @@ -16,14 +16,14 @@ namespace SharpReportCore /// /// This Class checks for invalid SqlStatements /// - internal class SqlQueryCkecker{ + internal class SqlQueryChecker{ internal string UPDATE = "UPDATE"; internal string DELETE = "DELETE"; internal string INSERT = "INSERT"; internal string noValidMessage = "is no valid Member of SqlString"; - public SqlQueryCkecker(){ + public SqlQueryChecker(){ } public void Check (string queryString) { diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingDataSourceException.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingDataSourceException.cs index 2b3248b02c..05307dbe19 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingDataSourceException.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingDataSourceException.cs @@ -17,9 +17,7 @@ using System.Runtime.Serialization; /// created by - Forstmeier Peter /// created on - 05.07.2005 22:32:47 /// -/// -/// When porting to NET 2.0 use -/// + namespace SharpReportCore { [Serializable()] diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/FontSingleton.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/FontSingleton.cs index a2784af7a5..2072d45d33 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/FontSingleton.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/FontSingleton.cs @@ -31,7 +31,6 @@ namespace SharpReportCore { private FontSingleton() { - MessageBox.Show ("Should be commented out","FontSingleton"); hash = new Hashtable(); } public Hashtable Hash { @@ -54,14 +53,6 @@ namespace SharpReportCore { public Font GetFont(string family, float size, FontStyle style){ try { string s=family+size.ToString()+((int)style).ToString(); - MessageBox.Show (s); - //Remove when tested - if(hash.Contains(s)){ -MessageBox.Show ("font from hashtable","GetFont"); - } else { - - MessageBox.Show ("font created","getFont"); - } if(hash.Contains(s)){ return (Font)hash[s]; @@ -75,10 +66,6 @@ MessageBox.Show ("font from hashtable","GetFont"); } - public override string ToString() { - return base.ToString() + " FontSingleton / "; - } - /// /// Clear the Hashtable from all Fonts /// @@ -87,7 +74,7 @@ MessageBox.Show ("font from hashtable","GetFont"); /// /// public void Dispose() { - MessageBox.Show ("dispose fonts " + hash.Count.ToString()); + } } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/GlobalEnums.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/GlobalEnums.cs index 3bc2260590..c9f1cee56f 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/GlobalEnums.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Globals/GlobalEnums.cs @@ -97,15 +97,15 @@ namespace SharpReportCore { /// Convert any possible string-Value of a given enumeration /// type to its internal representation. - public static object StringToEnum( Type t, string value ) { - foreach ( FieldInfo fi in t.GetFields() ) + public static object StringToEnum( Type type, string value ) { + foreach ( FieldInfo fi in type.GetFields() ) if ( fi.Name == value ) return fi.GetValue( null ); // We use null because throw new Exception( string.Format(CultureInfo.CurrentCulture, "Can't convert {0} to {1}", value, - t.ToString()) ); + type.ToString()) ); } } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataContainer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataContainer.cs index f73b0e8ef8..19de9ee45d 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataContainer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataContainer.cs @@ -26,12 +26,7 @@ namespace SharpReportCore { /// Reads one row of data and fill the /// void FetchData (ReportItemCollection collection); -// /// -// /// set,get the SharpReportCore -// /// -// object SharpReportCore{ -// get;set; -// } + int Count { get; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataViewStrategy.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataViewStrategy.cs index 4dbeaead55..995aa65b98 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataViewStrategy.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataViewStrategy.cs @@ -5,7 +5,7 @@ using System.Collections; using System.ComponentModel; namespace SharpReportCore{ - public interface IDataViewStrategy { + public interface IDataViewStrategy:IDisposable{ /// /// Sort the DataSource @@ -33,15 +33,7 @@ namespace SharpReportCore{ get; } - /// - /// Build a Hierarchical List of grouped DataRows - /// - /// - /// - - IHierarchicalEnumerable IHierarchicalEnumerable{ - get; - } + int Count { get; @@ -78,8 +70,21 @@ namespace SharpReportCore{ bool IsGrouped { get; } -// event ListChangedEventHandler ListChanged; + + /// + /// Returns if the current Row has Child's + /// + + bool HasChilds { + get; + } + + SharpIndexCollection ChildRows { + get; + } + event EventHandler ListChanged; + /// /// Fired each tim the grouping will change, this means theGroupLevel changes up or down /// diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IHierarchyInterfaces.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IHierarchyInterfaces.cs index 9f6e852df3..42580e4744 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IHierarchyInterfaces.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IHierarchyInterfaces.cs @@ -13,19 +13,12 @@ using System.Collections; namespace SharpReportCore { - - public interface IHierarchicalEnumerable :IEnumerable { - IHierarchyData GetHierarchyData (Object enumeratedItem); - - } - - - - public interface IHierarchyData{ - IHierarchicalEnumerable GetChildren (); - IHierarchyData GetParent(); + SharpIndexCollection GetChildren { + get; + } + bool HasChildren { get; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IOutputStrategy.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IOutputStrategy.cs index 77ef3941ea..7010478de9 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IOutputStrategy.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IOutputStrategy.cs @@ -20,18 +20,18 @@ namespace SharpReportCore /// /// Measure the Size of the currnet Item /// - SizeF MeasureItem(System.Drawing.Graphics e); + SizeF MeasureItem(System.Drawing.Graphics graphics); /// /// Format the current (TextBased) /// /// /// - void FormatItem(System.Drawing.Graphics e ); + void FormatItem(System.Drawing.Graphics graphics ); /// /// Print them out to .... /// /// - void OutputItem (System.Drawing.Graphics e); + void OutputItem (System.Drawing.Graphics graphics); } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs index 77c52faf79..0f632c400a 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs @@ -47,12 +47,23 @@ namespace SharpReportCore { } public RenderDataReport(ReportModel model,DataManager dataManager):base (model){ -// System.Console.WriteLine("RenderDataReport".ToUpper()); this.dataManager = dataManager; + System.Console.WriteLine("ReenderDataReport"); + System.Console.WriteLine("connect to groupingevents"); + this.dataManager.GroupChanged += new EventHandler(OnGroupChanged); + this.dataManager.GroupChanging += new EventHandler (OnGroupChanging); } - + + void OnGroupChanged (object sender,GroupChangedEventArgs e) { + + System.Console.WriteLine("OnGroupChanged"); + } + void OnGroupChanging (object sender, EventArgs e) { + + System.Console.WriteLine("OnGroupChanging"); + } #region overrides diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs index 45ad4f5efc..6f490de6c5 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs @@ -80,7 +80,7 @@ namespace SharpReportCore { } public void ReportDocumentPrintPage (object sender, PrintPageEventArgs e) { -// System.Console.WriteLine("\tReportDocument PrintPage"); + System.Console.WriteLine("\tReportDocument PrintPage"); pageNr ++; ReportPageEventArgs pea = new ReportPageEventArgs (e,pageNr,false,new PointF (0,0)); diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/ReportModel.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/ReportModel.cs index e04525f42f..2b909a56ea 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/ReportModel.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/ReportModel.cs @@ -117,9 +117,6 @@ namespace SharpReportCore { get { return sectionCollection; } - set { - sectionCollection = value; - } } #endregion @@ -136,16 +133,23 @@ namespace SharpReportCore { } protected virtual void Dispose(bool disposing){ - if (disposing) { - // Free other state (managed objects). - if (this.reportSettings != null) { - this.reportSettings.Dispose(); - this.reportSettings = null; + try { + if (disposing) { + // Free other state (managed objects). + if (this.reportSettings != null) { + this.reportSettings.Dispose(); + this.reportSettings = null; + } + if (this.sectionCollection != null) { + this.sectionCollection.Clear(); + this.sectionCollection = null; + } } - } - // Free your own state (unmanaged objects). - // Set large fields to null. + } finally { + // Free your own state (unmanaged objects). + // Set large fields to null. + } } #endregion } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs index 1a9d20c831..2f41b59916 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs @@ -100,18 +100,15 @@ namespace SharpReportCore{ XmlElement ctrlElem, AbstractColumn item) { - try { - XmlNodeList nodeList = ctrlElem.ChildNodes; - foreach (XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement)node; - if (elem.HasAttribute("value")) { - reader.SetValue (item,elem.Name,elem.GetAttribute("value")); - } + + XmlNodeList nodeList = ctrlElem.ChildNodes; + foreach (XmlNode node in nodeList) { + XmlElement elem = node as XmlElement; + if (elem != null) { + if (elem.HasAttribute("value")) { + reader.SetValue (item,elem.Name,elem.GetAttribute("value")); } } - } catch (Exception ) { - throw ; } } @@ -124,18 +121,18 @@ namespace SharpReportCore{ private void BuildReportParameter(XmlFormReader reader, XmlElement parElement, SharpReportCore.AbstractParameter item) { - try { - XmlNodeList nodeList = parElement.ChildNodes; - foreach (XmlNode node in nodeList) { - XmlElement elem = (XmlElement)node; + + XmlNodeList nodeList = parElement.ChildNodes; + foreach (XmlNode node in nodeList) { + XmlElement elem = node as XmlElement; + if (elem != null) { if (elem.HasAttribute("value")) { reader.SetValue ((SqlParameter)item,elem.Name,elem.GetAttribute("value")); } } - } catch (Exception) { - } } + #endregion #region RestoreItems @@ -152,8 +149,8 @@ namespace SharpReportCore{ XmlNodeList nodeList = xmlCol.ChildNodes; this.availableFields.Clear(); foreach (XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement) node; + XmlElement elem = node as XmlElement; + if (elem != null) { AbstractColumn abstr = new AbstractColumn(); BuildAbstractColumn (xmlReader,elem,abstr); this.availableFields.Add(abstr); @@ -167,8 +164,8 @@ namespace SharpReportCore{ XmlNodeList nodeList = xmlCol.ChildNodes; this.sortingCollection.Clear(); foreach (XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement) node; + XmlElement elem = node as XmlElement; + if (elem != null) { SortColumn sc = new SortColumn(); BuildAbstractColumn (xmlReader,elem,sc); sortingCollection.Add(sc); @@ -181,8 +178,8 @@ namespace SharpReportCore{ XmlNodeList nodeList = xmlCol.ChildNodes; this.groupingsCollection.Clear(); foreach (XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement) node; + XmlElement elem = node as XmlElement; + if (elem != null) { GroupColumn gc = new GroupColumn(); BuildAbstractColumn (xmlReader,elem,gc); groupingsCollection.Add(gc); @@ -195,8 +192,8 @@ namespace SharpReportCore{ XmlNodeList nodeList = xmlCol.ChildNodes; this.reportParametersCollection.Clear(); foreach( XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement) node; + XmlElement elem = node as XmlElement; + if (elem != null) { SqlParameter parameter = new SqlParameter(); BuildReportParameter (xmlReader, elem, @@ -205,10 +202,7 @@ namespace SharpReportCore{ } } break; - } - - default: - throw new SharpReportException ("Invalid Collection found in ReportSettings:CheckForCollection"); + } } } @@ -218,8 +212,8 @@ namespace SharpReportCore{ XmlFormReader xmlFormReader = new XmlFormReader(); base.InitDone = false; foreach (XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement) node; + XmlElement elem = node as XmlElement; + if (elem != null) { CheckForCollection (xmlFormReader,elem); if (elem.Name == "PageSettings") { @@ -228,9 +222,7 @@ namespace SharpReportCore{ CultureInfo.InvariantCulture); } - else if (elem.Name == "DefaultFont") { - Font f = XmlFormReader.MakeFont (elem.GetAttribute("value")); - } + else if (elem.HasAttribute("value")) { xmlFormReader.SetValue (this,elem.Name,elem.GetAttribute("value")); } @@ -526,9 +518,9 @@ namespace SharpReportCore{ get { return sortingCollection; } - set { - sortingCollection = value; - } +// set { +// sortingCollection = value; +// } } [Browsable(false)] [XmlIgnoreAttribute] @@ -539,6 +531,7 @@ namespace SharpReportCore{ } return groupingsCollection; } + /* set { if (this.groupingsCollection == null) { groupingsCollection = new ColumnCollection(); @@ -548,6 +541,7 @@ namespace SharpReportCore{ this.NotifyPropertyChanged(); } } + */ } [Browsable(false)] diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj index ad0f054182..667da7b18e 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj @@ -32,12 +32,12 @@ False - - + + @@ -50,13 +50,10 @@ - - - @@ -85,7 +82,6 @@ - @@ -129,6 +125,7 @@ + diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs index dfcbf35cf9..b8eb8ce1b0 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs @@ -41,6 +41,7 @@ namespace SharpReportCore { private PreviewControl previewControl; private ConnectionObject connectionObject; + private DataManager dataManager; public event EventHandler NoData; public event EventHandler ParametersRequest; @@ -134,22 +135,18 @@ namespace SharpReportCore { } } - private DataManager SetupDataContainer (ReportSettings settings) { - + private void InitDataContainer (ReportSettings settings) { + if (settings.ReportType == GlobalEnums.enmReportType.DataReport) { if (settings.CommandText != null) { try { GrapSqlParameters (settings); if (this.connectionObject != null) { - DataManager container = new DataManager(this.connectionObject, + this.dataManager = new DataManager(this.connectionObject, settings); - if (container.DataBind() == true) { - return container; - } else { - return null; - } + this.dataManager.DataBind(); }else { throw new NullReferenceException("SetupContainer:connectionObject is missing"); } @@ -163,7 +160,6 @@ namespace SharpReportCore { } } } - return null; } @@ -187,6 +183,7 @@ namespace SharpReportCore { protected SharpReportCore.AbstractRenderer SetupStandartRenderer (ReportModel model) { + AbstractRenderer abstr = null; switch (model.ReportSettings.ReportType) { //FormSheets reports @@ -195,9 +192,10 @@ namespace SharpReportCore { break; //Databased reports case GlobalEnums.enmReportType.DataReport : - DataManager dataManager = SetupDataContainer (model.ReportSettings); - if (dataManager != null) { - if (dataManager.DataSource != null) { +// DataManager dataManager = SetupDataContainer (model.ReportSettings); + InitDataContainer (model.ReportSettings); + if (this.dataManager != null) { + if (this.dataManager.DataSource != null) { abstr = new RendererFactory().Create (model,dataManager); } @@ -239,11 +237,12 @@ namespace SharpReportCore { } AbstractRenderer abstr = null; - DataManager dataManager = new DataManager (dataTable,model.ReportSettings); - if (dataManager != null) { - dataManager.DataBind(); - if (dataManager.DataSource != null) { + this.dataManager = new DataManager (dataTable,model.ReportSettings); + + if (this.dataManager != null) { + this.dataManager.DataBind(); + if (this.dataManager.DataSource != null) { abstr = new RendererFactory().Create (model,dataManager); } @@ -475,7 +474,7 @@ namespace SharpReportCore { try { model = ModelFromFile (fileName); if (!CheckForPushModel(model)) { - throw new SharpReportException ("PrintPushdataReport: No valid ReportModel"); + throw new MissingModelException(); } renderer = this.SetupPushDataRenderer (model,dataTable); @@ -555,19 +554,25 @@ namespace SharpReportCore { } protected virtual void Dispose(bool disposing){ - if (disposing) { - // Free other state (managed objects). - if (this.connectionObject != null) { - this.connectionObject.Dispose(); - } - if (this.previewControl != null) { - this.previewControl.Dispose(); + try { + if (disposing) { + // Free other state (managed objects). + if (this.connectionObject != null) { + this.connectionObject.Dispose(); + } + if (this.dataManager != null) { + this.dataManager.Dispose(); + this.dataManager = null; + } + if (this.previewControl != null) { + this.previewControl.Dispose(); + } } + } finally { + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. } - - // Release unmanaged resources. - // Set large fields to null. - // Call Dispose on your base class. } #endregion } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs index a7a5d16347..4adb86f141 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs @@ -44,12 +44,8 @@ namespace SharpReportCore { /// public static bool IsSharpReport (XmlElement elem) { bool isOk = false; - try { - if (elem.Name.Equals (SharpReportCore.GlobalValues.SharpReportString)) { - isOk = true; - } - } catch (Exception) { - throw ; + if (elem.Name.Equals (SharpReportCore.GlobalValues.SharpReportString)) { + isOk = true; } return isOk; } @@ -75,13 +71,13 @@ namespace SharpReportCore { // Valid Document return xmlDoc; } else { - throw new SharpReportException ("XmlHelper.OpenSharpReport - > No SharpReport"); + throw new IllegalFileFormatException(); } } else { - throw new SharpReportException ("XmlHelper.OpenSharpReport - > No valid DocumentElement"); + throw new IllegalFileFormatException(); } } - catch (System.Xml.XmlException) { + catch (System.Xml.XmlException ) { IllegalFileFormatException wf = new IllegalFileFormatException("XmlHelper.OpenSharpReport - > Wrong File Format"); throw wf; } @@ -108,19 +104,13 @@ namespace SharpReportCore { XmlNodeList nodeList = element.ChildNodes; foreach (XmlNode node in nodeList) { - if (node is XmlElement) { - XmlElement elem = (XmlElement) node; + XmlElement elem = node as XmlElement; + if (elem != null) { if (elem.HasAttribute("value")) { - try { - reader.SetValue (section,elem.Name,elem.GetAttribute("value")); - } catch (Exception e) { - MessageBox.Show (elem.Name + " / " + elem.GetAttribute("value")); - MessageBox.Show (e.Message); - } - + reader.SetValue (section,elem.Name,elem.GetAttribute("value")); } - } else { - throw new System.Xml.XmlException ("Report : SetValues Wrong Node in Report"); + }else { + throw new System.Xml.XmlException (); } } } From e378b90e2e2cdbe6ac13a6c764a4eab80a94850d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 1 Mar 2006 15:46:28 +0000 Subject: [PATCH 6/7] Fixed exception when opening a solution containing web projects. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1194 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Gui/Workbench/DefaultWorkbench.cs | 7 +++- .../Project/Src/Project/AbstractProject.cs | 19 +++++++-- src/Main/Base/Project/Src/Project/IProject.cs | 7 ++++ .../Project/Src/Project/MSBuildProject.cs | 4 +- .../Project/Src/Project/MissingProject.cs | 4 +- .../Src/Project/Solution/ProjectSection.cs | 6 +-- .../Project/Src/Project/Solution/Solution.cs | 42 ++++++++++++------- .../Src/Project/Solution/SolutionFolder.cs | 17 ++++++-- .../Project/Src/Project/UnknownProject.cs | 4 +- .../LanguageBinding/LanguageBindingService.cs | 6 +-- .../Src/Services/FileUtility/FileUtility.cs | 15 ++++++- .../Core/Test/AddInTreeTests/ExtPathTests.cs | 3 ++ 12 files changed, 96 insertions(+), 38 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs index d1f069e8bb..2cff9bdcaa 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs @@ -563,7 +563,12 @@ namespace ICSharpCode.SharpDevelop.Gui foreach (string file in files) { if (File.Exists(file)) { - FileService.OpenFile(file); + IProjectLoader loader = ProjectService.GetProjectLoader(file); + if (loader != null) { + FileUtility.ObservedLoad(new NamedFileOperationDelegate(loader.Load), file); + } else { + FileService.OpenFile(file); + } } } } diff --git a/src/Main/Base/Project/Src/Project/AbstractProject.cs b/src/Main/Base/Project/Src/Project/AbstractProject.cs index ffa3b6c970..69dc09f414 100644 --- a/src/Main/Base/Project/Src/Project/AbstractProject.cs +++ b/src/Main/Base/Project/Src/Project/AbstractProject.cs @@ -29,9 +29,10 @@ namespace ICSharpCode.SharpDevelop.Project protected List items = new List(); protected List imports = new List(); + readonly List projectSections = new List(); - protected string fileName; - protected string language; + string fileName; + string language; [Browsable(false)] public Dictionary Configurations { @@ -153,6 +154,16 @@ namespace ICSharpCode.SharpDevelop.Project } } + /// + /// Gets a list of property sections stored in the solution file. + /// + [Browsable(false)] + public List ProjectSections { + get { + return projectSections; + } + } + /// /// Gets the list of MSBuild Imports. /// @@ -172,7 +183,7 @@ namespace ICSharpCode.SharpDevelop.Project if (fileName == null) { return String.Empty; } - return Path.GetFullPath(fileName); + return fileName; } set { fileName = value; @@ -188,7 +199,7 @@ namespace ICSharpCode.SharpDevelop.Project if (fileName == null) { return String.Empty; } - directoryName = Path.GetFullPath(Path.GetDirectoryName(fileName)); + directoryName = Path.GetDirectoryName(fileName); } return directoryName; } diff --git a/src/Main/Base/Project/Src/Project/IProject.cs b/src/Main/Base/Project/Src/Project/IProject.cs index 56f6ddb91b..9886818ded 100644 --- a/src/Main/Base/Project/Src/Project/IProject.cs +++ b/src/Main/Base/Project/Src/Project/IProject.cs @@ -30,6 +30,13 @@ namespace ICSharpCode.SharpDevelop.Project get; } + /// + /// Gets a list of property sections stored in the solution file. + /// + List ProjectSections { + get; + } + /// /// Marks a project for needing recompilation. /// diff --git a/src/Main/Base/Project/Src/Project/MSBuildProject.cs b/src/Main/Base/Project/Src/Project/MSBuildProject.cs index 78075ce767..a079437884 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildProject.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildProject.cs @@ -57,7 +57,7 @@ namespace ICSharpCode.SharpDevelop.Project configurations["Release|*"]["DebugSymbols"] = "False"; configurations["Release|*"]["DebugType"] = "None"; - fileName = information.OutputProjectFileName; + this.FileName = Path.GetFullPath(information.OutputProjectFileName); } public override bool CanCompile(string fileName) @@ -82,7 +82,7 @@ namespace ICSharpCode.SharpDevelop.Project protected void SetupProject(string projectFileName) { - this.fileName = projectFileName; + this.FileName = Path.GetFullPath(projectFileName); using (MSBuildFileReader reader = new MSBuildFileReader(projectFileName)) { reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists) diff --git a/src/Main/Base/Project/Src/Project/MissingProject.cs b/src/Main/Base/Project/Src/Project/MissingProject.cs index 7d6344a5e1..518f76a480 100644 --- a/src/Main/Base/Project/Src/Project/MissingProject.cs +++ b/src/Main/Base/Project/Src/Project/MissingProject.cs @@ -24,9 +24,9 @@ namespace ICSharpCode.SharpDevelop.Project } } - public MissingProject(string fileName) + public MissingProject(string fileName, string title) { - Name = Path.GetFileNameWithoutExtension(fileName); + Name = title; FileName = fileName; IdGuid = "{" + Guid.NewGuid().ToString() + "}"; } diff --git a/src/Main/Base/Project/Src/Project/Solution/ProjectSection.cs b/src/Main/Base/Project/Src/Project/Solution/ProjectSection.cs index 1ef1048f29..381fcbe781 100644 --- a/src/Main/Base/Project/Src/Project/Solution/ProjectSection.cs +++ b/src/Main/Base/Project/Src/Project/Solution/ProjectSection.cs @@ -55,17 +55,17 @@ namespace ICSharpCode.SharpDevelop.Project } static Regex sectionPattern = new Regex("\\s*(?.*\\S)\\s*=\\s*(?.*\\S)\\s*", RegexOptions.Compiled); - public static ProjectSection ReadGlobalSection(StreamReader sr, string name, string sectionType) + public static ProjectSection ReadGlobalSection(TextReader sr, string name, string sectionType) { return ReadSection(sr, name, sectionType, "EndGlobalSection"); } - public static ProjectSection ReadProjectSection(StreamReader sr, string name, string sectionType) + public static ProjectSection ReadProjectSection(TextReader sr, string name, string sectionType) { return ReadSection(sr, name, sectionType, "EndProjectSection"); } - static ProjectSection ReadSection(StreamReader sr, string name, string sectionType, string endTag) + static ProjectSection ReadSection(TextReader sr, string name, string sectionType, string endTag) { ProjectSection newFolder = new ProjectSection(name, sectionType); while (true) { diff --git a/src/Main/Base/Project/Src/Project/Solution/Solution.cs b/src/Main/Base/Project/Src/Project/Solution/Solution.cs index 48058dc6de..c2970b23db 100644 --- a/src/Main/Base/Project/Src/Project/Solution/Solution.cs +++ b/src/Main/Base/Project/Src/Project/Solution/Solution.cs @@ -271,23 +271,14 @@ namespace ICSharpCode.SharpDevelop.Project projectSection.AppendLine(); if (currentFolder is IProject) { - // IProject project = (IProject)currentFolder; - // currently nothing to do. (I don't know if projects may have sections). + IProject project = (IProject)currentFolder; + // Web projects can have sections + SaveProjectSections(project.ProjectSections, projectSection); + } else if (currentFolder is SolutionFolder) { SolutionFolder folder = (SolutionFolder)currentFolder; - foreach (ProjectSection section in folder.Sections) { - projectSection.Append("\tProjectSection("); - projectSection.Append(section.Name); - projectSection.Append(") = "); - projectSection.Append(section.SectionType); - projectSection.Append(Environment.NewLine); - - section.AppendSection(projectSection, "\t\t"); - - projectSection.Append("\tEndProjectSection"); - projectSection.Append(Environment.NewLine); - } + SaveProjectSections(folder.Sections, projectSection); foreach (ISolutionFolder subFolder in folder.Folders) { stack.Push(subFolder); @@ -339,6 +330,22 @@ namespace ICSharpCode.SharpDevelop.Project } } + static void SaveProjectSections(IEnumerable sections, StringBuilder projectSection) + { + foreach (ProjectSection section in sections) { + projectSection.Append("\tProjectSection("); + projectSection.Append(section.Name); + projectSection.Append(") = "); + projectSection.Append(section.SectionType); + projectSection.Append(Environment.NewLine); + + section.AppendSection(projectSection, "\t\t"); + + projectSection.Append("\tEndProjectSection"); + projectSection.Append(Environment.NewLine); + } + } + static Regex versionPattern = new Regex("Microsoft Visual Studio Solution File, Format Version\\s+(?.*)", RegexOptions.Compiled); static Regex projectLinePattern = new Regex("Project\\(\"(?.*)\"\\)\\s+=\\s+\"(?.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"", RegexOptions.Compiled); @@ -432,14 +439,19 @@ namespace ICSharpCode.SharpDevelop.Project if (match.Success) { string projectGuid = match.Result("${ProjectGuid}"); string title = match.Result("${Title}"); - string location = Path.Combine(solutionDirectory, match.Result("${Location}")); + string location = match.Result("${Location}"); string guid = match.Result("${Guid}"); + if (!FileUtility.IsUrl(location)) { + location = Path.Combine(solutionDirectory, location); + } + if (projectGuid == FolderGuid) { SolutionFolder newFolder = SolutionFolder.ReadFolder(sr, title, location, guid); newSolution.AddFolder(newFolder); } else { IProject newProject = LanguageBindingService.LoadProject(location, title, projectGuid); + ReadProjectSections(sr, newProject.ProjectSections); newProject.IdGuid = guid; newSolution.AddFolder(newProject); } diff --git a/src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs b/src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs index 339c57a3e0..5c0701973c 100644 --- a/src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs +++ b/src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs @@ -117,9 +117,20 @@ namespace ICSharpCode.SharpDevelop.Project #endregion static Regex sectionHeaderPattern = new Regex("\\s*ProjectSection\\((?<Name>.*)\\)\\s*=\\s*(?<Type>.*)", RegexOptions.Compiled); - public static SolutionFolder ReadFolder(StreamReader sr, string title, string location, string guid) + + public static SolutionFolder ReadFolder(TextReader sr, string title, string location, string guid) { SolutionFolder newFolder = new SolutionFolder(title, location, guid); + ReadProjectSections(sr, newFolder.Sections); + return newFolder; + } + + /// <summary> + /// Reads project sections from the TextReader until the line "EndProject" is found and saves + /// them into the specified sectionList. + /// </summary> + public static void ReadProjectSections(TextReader sr, ICollection<ProjectSection> sectionList) + { while (true) { string line = sr.ReadLine(); if (line == null || line.Trim() == "EndProject") { @@ -127,11 +138,9 @@ namespace ICSharpCode.SharpDevelop.Project } Match match = sectionHeaderPattern.Match(line); if (match.Success) { - newFolder.Sections.Add(ProjectSection.ReadProjectSection(sr, match.Result("${Name}"), match.Result("${Type}"))); + sectionList.Add(ProjectSection.ReadProjectSection(sr, match.Result("${Name}"), match.Result("${Type}"))); } } - return newFolder; } - } } diff --git a/src/Main/Base/Project/Src/Project/UnknownProject.cs b/src/Main/Base/Project/Src/Project/UnknownProject.cs index e69107177b..fe6a44fded 100644 --- a/src/Main/Base/Project/Src/Project/UnknownProject.cs +++ b/src/Main/Base/Project/Src/Project/UnknownProject.cs @@ -24,9 +24,9 @@ namespace ICSharpCode.SharpDevelop.Project } } - public UnknownProject(string fileName) + public UnknownProject(string fileName, string title) { - Name = Path.GetFileNameWithoutExtension(fileName); + Name = title; FileName = fileName; IdGuid = "{" + Guid.NewGuid().ToString() + "}"; } diff --git a/src/Main/Base/Project/Src/Services/LanguageBinding/LanguageBindingService.cs b/src/Main/Base/Project/Src/Services/LanguageBinding/LanguageBindingService.cs index 91bca7ed2a..a6ca2db6ab 100644 --- a/src/Main/Base/Project/Src/Services/LanguageBinding/LanguageBindingService.cs +++ b/src/Main/Base/Project/Src/Services/LanguageBinding/LanguageBindingService.cs @@ -84,7 +84,7 @@ namespace ICSharpCode.Core { IProject newProject; if (!File.Exists(location)) { - newProject = new MissingProject(location); + newProject = new MissingProject(location, title); newProject.TypeGuid = projectTypeGuid; } else { ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(location); @@ -93,11 +93,11 @@ namespace ICSharpCode.Core newProject = binding.LoadProject(location, title); } catch (XmlException ex) { MessageService.ShowError("Error loading " + location + ":\n" + ex.Message); - newProject = new UnknownProject(location); + newProject = new UnknownProject(location, title); newProject.TypeGuid = projectTypeGuid; } } else { - newProject = new UnknownProject(location); + newProject = new UnknownProject(location, title); newProject.TypeGuid = projectTypeGuid; } } diff --git a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs index 58db370b0f..d9611350db 100644 --- a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs +++ b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs @@ -103,6 +103,10 @@ namespace ICSharpCode.Core return result; } + public static bool IsUrl(string path) + { + return path.IndexOf(':') >= 2; + } /// <summary> /// Converts a given absolute path and a given base path to a path that leads @@ -110,8 +114,15 @@ namespace ICSharpCode.Core /// </summary> public static string GetRelativePath(string baseDirectoryPath, string absPath) { - baseDirectoryPath = Path.GetFullPath(baseDirectoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); - absPath = Path.GetFullPath(absPath); + if (IsUrl(absPath) || IsUrl(baseDirectoryPath)){ + return absPath; + } + try { + baseDirectoryPath = Path.GetFullPath(baseDirectoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); + absPath = Path.GetFullPath(absPath); + } catch (Exception ex) { + throw new ArgumentException("GetRelativePath error '" + baseDirectoryPath + "' -> '" + absPath + "'", ex); + } string[] bPath = baseDirectoryPath.Split(separators); string[] aPath = absPath.Split(separators); diff --git a/src/Main/Core/Test/AddInTreeTests/ExtPathTests.cs b/src/Main/Core/Test/AddInTreeTests/ExtPathTests.cs index 200decd755..ef8e2e3fc4 100644 --- a/src/Main/Core/Test/AddInTreeTests/ExtPathTests.cs +++ b/src/Main/Core/Test/AddInTreeTests/ExtPathTests.cs @@ -56,6 +56,9 @@ namespace ICSharpCode.Core.Tests.AddInTreeTests.Tests Assert.AreEqual(@"blub", FileUtility.GetRelativePath(@"C:\hello\.\..\A", @"C:\.\a\blub")); Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\HELlo", @"C:\.\blub\.\..\.\a\.\blub")); Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\heLLo\A\..", @"C:\.\blub\.\..\.\a\.\blub")); + + // Project filename could be an URL + Assert.AreEqual("http://example.com/vdir/", FileUtility.GetRelativePath("C:\\temp", "http://example.com/vdir/")); } [Test] From e9c13c09e199184a53b45ce0dc468445ec404c3b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald <daniel@danielgrunwald.de> Date: Wed, 1 Mar 2006 16:12:51 +0000 Subject: [PATCH 7/7] Fixed SD2-711: Clear all bookmarks menu option selected when bookmarks pad not visible git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1195 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Base/Project/Src/TextEditor/Bookmarks/Pad/BookmarkPad.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/BookmarkPad.cs b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/BookmarkPad.cs index 404db9fc61..36ce791076 100644 --- a/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/BookmarkPad.cs +++ b/src/Main/Base/Project/Src/TextEditor/Bookmarks/Pad/BookmarkPad.cs @@ -29,6 +29,9 @@ namespace ICSharpCode.SharpDevelop.Bookmarks public static BookmarkPad Instance { get { + if (instance == null) { + WorkbenchSingleton.Workbench.GetPad(typeof(BookmarkPad)).CreatePad(); + } return instance; } }