Browse Source

Overworked form designer assembly loading a bit. Showing the custom components in the tools pad no longer causes the assembly to be loaded, it is loaded only when the component in the toolbox is activated.

TypeResolutionService now searches for types using the code completion cache and loads the correct assembly when it is required by the designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@964 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
4ac89b6905
  1. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
  2. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs
  3. 31
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs
  4. 24
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs
  5. 198
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs
  6. BIN
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.FormDesigner.Gui.AssemblyList.resources
  7. BIN
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ControlLibrariesPanel.resources
  8. 17
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabDesigner.cs
  9. 20
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabItemDesigner.cs
  10. 9
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs
  11. 165
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs
  12. 11
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs
  13. 12
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToCSharpConvertVisitor.cs
  14. 12
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToVBNetConvertVisitor.cs
  15. 2
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs
  16. 16
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  17. 20
      src/Main/Base/Project/Src/Services/ParserService/ProjectContentRegistry.cs
  18. 15
      src/Main/Base/Project/Src/Services/ParserService/ReflectionProjectContent.cs
  19. 12
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerationForm.cs

2
src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj

@ -90,8 +90,6 @@ @@ -90,8 +90,6 @@
<Compile Include="Src\Services\TypeResolutionService.cs" />
<Compile Include="Src\Services\UIService.cs" />
<Compile Include="Src\ToolboxProvider.cs" />
<EmbeddedResource Include="Src\Gui\ICSharpCode.SharpDevelop.FormDesigner.Gui.AssemblyList.resources" />
<EmbeddedResource Include="Src\Gui\ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ControlLibrariesPanel.resources" />
<None Include="FormsDesigner.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

2
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.FormsDesigner @@ -115,7 +115,7 @@ namespace ICSharpCode.FormsDesigner
if (pd.Name == "Name" && nameInserted) {
continue;
}
if (pd.Name == "DataBindings" ||
if (pd.Name == "DataBindings" || pd.Name == "FlatAppearance" ||
// TabControl duplicate TabPages Workaround (TabPages got inserted twice : In Controls and in TabPages)
(o.GetType().FullName == "System.Windows.Forms.TabControl" && pd.Name == "Controls")) {
continue;

31
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs

@ -134,6 +134,8 @@ namespace ICSharpCode.FormsDesigner @@ -134,6 +134,8 @@ namespace ICSharpCode.FormsDesigner
}
}
if (lastAssembly != null) {
if (!TypeResolutionService.DesignerAssemblies.Contains(lastAssembly))
TypeResolutionService.DesignerAssemblies.Add(lastAssembly);
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name);
return lastAssembly;
}
@ -156,7 +158,7 @@ namespace ICSharpCode.FormsDesigner @@ -156,7 +158,7 @@ namespace ICSharpCode.FormsDesigner
serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService);
AmbientProperties ambientProperties = new AmbientProperties();
serviceContainer.AddService(typeof(AmbientProperties), ambientProperties);
serviceContainer.AddService(typeof(ITypeResolutionService), ToolboxProvider.TypeResolutionService);
serviceContainer.AddService(typeof(ITypeResolutionService), new TypeResolutionService(viewContent.FileName));
serviceContainer.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService());
serviceContainer.AddService(typeof(System.ComponentModel.Design.DesignerOptionService), new ICSharpCode.FormsDesigner.Services.DesignerOptionService());
serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
@ -264,29 +266,24 @@ namespace ICSharpCode.FormsDesigner @@ -264,29 +266,24 @@ namespace ICSharpCode.FormsDesigner
failedDesignerInitialize = true;
TextBox errorText = new TextBox();
errorText.Multiline = true;
if (e.InnerException is FormsDesignerLoadException)
if (e.InnerException is FormsDesignerLoadException) {
errorText.Text = e.InnerException.Message;
else if (e is FormsDesignerLoadException)
} else if (e is FormsDesignerLoadException) {
errorText.Text = e.Message;
else
errorText.Text = e.ToString();
//output loaderrors too
if(!designSurface.IsLoaded) {
errorText.Text += "\r\nDesignSurface not loaded :";
if(designSurface.LoadErrors != null) {
foreach(Exception le in designSurface.LoadErrors) {
errorText.Text += "\r\n";
errorText.Text += le.ToString();
errorText.Text += "\r\n";
errorText.Text += le.StackTrace;
}
} else if (!designSurface.IsLoaded && designSurface.LoadErrors != null) {
errorText.Text = "Error loading designer:\r\n\r\n";
foreach(Exception le in designSurface.LoadErrors) {
errorText.Text += le.ToString();
errorText.Text += "\r\n";
}
} else {
errorText.Text = e.ToString();
}
errorText.Dock = DockStyle.Fill;
p.Controls.Add(errorText);
Control title = new Label();
title.Text = "Failed to load designer. Check the source code for syntax errors.";
title.Text = "Failed to load designer. Check the source code for syntax errors and check if all references are available.";
title.Dock = DockStyle.Top;
p.Controls.Add(title);
}
@ -577,6 +574,8 @@ namespace ICSharpCode.FormsDesigner @@ -577,6 +574,8 @@ namespace ICSharpCode.FormsDesigner
/// </summary>
void PropertyValueChanged(object source, PropertyValueChangedEventArgs e)
{
if (e.ChangedItem == null || e.OldValue == null)
return;
if (e.ChangedItem.GridItemType == GridItemType.Property) {
if (e.ChangedItem.PropertyDescriptor.Name == "Language") {
if (!e.OldValue.Equals(e.ChangedItem.Value)) {

24
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs

@ -104,10 +104,16 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -104,10 +104,16 @@ namespace ICSharpCode.FormsDesigner.Gui
public Assembly LoadAssembly()
{
//ICSharpCode.Core.LoggingService.Debug("ToolComponent.LoadAssembly(): " + AssemblyName);
Assembly assembly;
if (HintPath != null) {
return Assembly.LoadFrom(FileName);
}
return Assembly.Load(AssemblyName);
assembly = Assembly.LoadFrom(FileName);
} else {
assembly = Assembly.Load(AssemblyName);
}
if (!ICSharpCode.FormsDesigner.Services.TypeResolutionService.DesignerAssemblies.Contains(assembly))
ICSharpCode.FormsDesigner.Services.TypeResolutionService.DesignerAssemblies.Add(assembly);
return assembly;
}
public object Clone()
@ -120,7 +126,7 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -120,7 +126,7 @@ namespace ICSharpCode.FormsDesigner.Gui
}
}
public class Category
public class Category
{
string name;
bool isEnabled = true;
@ -266,7 +272,7 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -266,7 +272,7 @@ namespace ICSharpCode.FormsDesigner.Gui
string name = node.Attributes["name"].InnerText;
Category newCategory = new Category(name);
foreach (XmlNode componentNode in node.ChildNodes) {
ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText,
ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText,
(ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)]);
newCategory.ToolComponents.Add(newToolComponent);
}
@ -298,11 +304,11 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -298,11 +304,11 @@ namespace ICSharpCode.FormsDesigner.Gui
}
if (b == null) {
try {
Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp");
if (imageStream != null) {
b = new Bitmap(Image.FromStream(imageStream));
Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp");
if (imageStream != null) {
b = new Bitmap(Image.FromStream(imageStream));
b.MakeTransparent();
}
}
} catch (Exception e) {
ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message);
}

198
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs

@ -1,30 +1,23 @@ @@ -1,30 +1,23 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Design;
using System.Reflection;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Security.Policy;
using System.Runtime.Remoting;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Threading;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.FormsDesigner.Services;
@ -32,13 +25,6 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -32,13 +25,6 @@ namespace ICSharpCode.FormsDesigner.Gui
{
public class CustomComponentsSideTab : SideTabDesigner
{
ArrayList projectAssemblies = new ArrayList();
ArrayList referencedAssemblies = new ArrayList();
Dictionary<string, Assembly> loadedFiles = new Dictionary<string, Assembly>();
List<string> loadedProjects = new List<string>();
static bool loadReferencedAssemblies = true;
///<summary>Load an assembly's controls</summary>
public CustomComponentsSideTab(AxSideBar sideTab, string name, IToolboxService toolboxService) : base(sideTab,name, toolboxService)
{
@ -47,142 +33,88 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -47,142 +33,88 @@ namespace ICSharpCode.FormsDesigner.Gui
ProjectService.SolutionLoaded += RescanProjectAssemblies;
}
public static bool LoadReferencedAssemblies {
get {
return loadReferencedAssemblies;
}
set {
loadReferencedAssemblies = value;
}
}
string loadingPath = String.Empty;
byte[] GetBytes(string fileName)
void RescanProjectAssemblies(object sender, EventArgs e)
{
FileStream fs = File.OpenRead(fileName);
long size = fs.Length;
byte[] outArray = new byte[size];
fs.Read(outArray, 0, (int)size);
fs.Close();
return outArray;
Items.Clear();
AddDefaultItem();
ScanProjectAssemblies();
SharpDevelopSideBar.SideBar.Refresh();
}
Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
void ScanProjectAssemblies()
{
LoggingService.Debug("Form Designer: MyResolve: " + args.Name);
string file = args.Name;
int idx = file.IndexOf(',');
if (idx >= 0) {
file = file.Substring(0, idx);
}
//search in other assemblies, this also help to avoid doubling of loaded assms
if (ProjectService.OpenSolution != null) {
foreach (IProject project in ProjectService.OpenSolution.Projects) {
if (project.AssemblyName == file)
return LoadAssemblyFile(project.OutputAssemblyFullPath, true);
// custom user controls don't need custom images
loadImages = false;
foreach (IProjectContent pc in ParserService.AllProjectContentsWithReferences) {
if (pc.Project == null) {
ReflectionProjectContent rpc = pc as ReflectionProjectContent;
if (rpc == null || rpc.IsGacAssembly)
continue;
}
}
//skip already loaded
Assembly lastAssembly = null;
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
//LoggingService.Info("Assembly..." + asm.FullName);
if (asm.FullName == args.Name) {
lastAssembly = asm;
foreach (IClass c in pc.Classes) {
foreach (IClass subClass in c.ClassInheritanceTree) {
if (subClass.FullyQualifiedName == "System.Windows.Forms.Form") {
break; // is not a design component
}
if (subClass.FullyQualifiedName == "System.ComponentModel.IComponent") {
goto isDesignComponent;
}
foreach (IAttribute attr in subClass.Attributes) {
if (attr.Name == "DesignTimeVisibleAttribute"
|| attr.Name == "System.ComponentModel.DesignTimeVisibleAttribute")
{
// TODO: Check value of attribute (make IAttribute store at least simple values like bool's and typeof's)
goto isDesignComponent;
}
}
}
// is not a design component
continue;
isDesignComponent:
this.Items.Add(new SideTabItemDesigner(c.Name, new CustomComponentToolBoxItem(c)));
}
}
if (lastAssembly != null) {
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name);
return lastAssembly;
}
return null;
}
}
public class CustomComponentToolBoxItem : ToolboxItem
{
string className;
IProjectContent assemblyLocation;
bool initialized;
Assembly LoadAssemblyFile(string assemblyName, bool nonLocking)
public CustomComponentToolBoxItem(IClass c)
{
assemblyName = assemblyName.ToLower();
//skip already loaded over MyResolveEventHandler
if(loadedFiles.ContainsKey(assemblyName))
return loadedFiles[assemblyName];
if ((assemblyName.EndsWith("exe") || assemblyName.EndsWith("dll")) && File.Exists(assemblyName)) {
string fileAsmName = AssemblyName.GetAssemblyName(assemblyName).ToString();
Assembly asm;
//skip already loaded
Assembly lastAssembly = null;
foreach (Assembly asmLoaded in AppDomain.CurrentDomain.GetAssemblies()) {
if (asmLoaded.FullName == fileAsmName) {
lastAssembly = asmLoaded;
}
}
if (lastAssembly != null) {
asm = lastAssembly;
} else {
asm = nonLocking ? Assembly.Load(GetBytes(assemblyName)) : Assembly.LoadFrom(assemblyName); //Assembly.LoadFrom(assemblyName);
}
if (asm != null) {
loadedFiles[assemblyName] = asm;
BuildToolboxFromAssembly(asm);
}
return asm;
}
return null;
className = c.FullyQualifiedName;
assemblyLocation = c.ProjectContent;
this.Bitmap = new ToolboxItem(typeof(Component)).Bitmap;
this.IsTransient = true;
}
void LoadProject(IProject project)
void Init()
{
string assemblyName = project.OutputAssemblyFullPath;
if(loadedProjects.Contains(assemblyName))
if (initialized)
return;
loadedProjects.Add(assemblyName);
foreach (ProjectItem projectItem in project.Items) {
ProjectReferenceProjectItem projectReferenceProjectItem = projectItem as ProjectReferenceProjectItem;
if(projectReferenceProjectItem != null)
LoadProject(projectReferenceProjectItem.ReferencedProject);
initialized = true;
LoggingService.Debug("Initializing MyToolBoxItem: " + className);
if (assemblyLocation != null) {
Assembly asm = TypeResolutionService.LoadAssembly(assemblyLocation);
if (asm != null) {
Initialize(asm.GetType(className));
}
}
loadingPath = Path.GetDirectoryName(assemblyName) + Path.DirectorySeparatorChar;
LoadAssemblyFile(assemblyName, true);
}
void ScanProjectAssemblies()
protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
projectAssemblies.Clear();
referencedAssemblies.Clear();
loadedFiles.Clear();
loadedProjects.Clear();
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
try {
// custom user controls don't need custom images
loadImages = false;
ITypeResolutionService typeResolutionService = ToolboxProvider.TypeResolutionService;
if (ProjectService.OpenSolution != null) {
foreach (IProject project in ProjectService.OpenSolution.Projects) {
LoadProject(project);
projectAssemblies.Add(project.OutputAssemblyFullPath);
}
}
} catch (Exception e) {
LoggingService.Warn("Form Designer: ScanProjectAssemblies", e);
} finally {
AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(MyResolveEventHandler);
}
Init();
return base.CreateComponentsCore(host);
}
void RescanProjectAssemblies(object sender, EventArgs e)
protected override IComponent[] CreateComponentsCore(IDesignerHost host, System.Collections.IDictionary defaultValues)
{
projectAssemblies.Clear();
referencedAssemblies.Clear();
Items.Clear();
AddDefaultItem();
ScanProjectAssemblies();
SharpDevelopSideBar.SideBar.Refresh();
Init();
return base.CreateComponentsCore(host, defaultValues);
}
}
}

BIN
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.FormDesigner.Gui.AssemblyList.resources

Binary file not shown.

BIN
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ControlLibrariesPanel.resources

Binary file not shown.

17
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabDesigner.cs

@ -26,28 +26,18 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -26,28 +26,18 @@ namespace ICSharpCode.FormsDesigner.Gui
protected bool loadImages = true;
IToolboxService toolboxService;
public void CreatedUserControl()
{
InitializeComponents();
}
void InitializeComponents()
{
}
protected SideTabDesigner(AxSideBar sideBar, string name, IToolboxService toolboxService) : base(sideBar, name)
{
this.toolboxService = toolboxService;
this.CanSaved = false;
AddDefaultItem();
this.ChoosedItemChanged += SelectedTabItemChanged;
}
protected void AddDefaultItem()
{
this.Items.Add(new SideTabItemDesigner());
//Event the user click on an another "control" itemin the current tab
this.ChoosedItemChanged += new EventHandler(SelectedTabItemChanged);
}
///<summary>Load an assembly's controls</summary>
@ -67,6 +57,7 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -67,6 +57,7 @@ namespace ICSharpCode.FormsDesigner.Gui
}
}
/*
protected void LoadAssembly(string assemblyName)
{
Assembly assembly = FindAssembly(assemblyName);
@ -202,12 +193,14 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -202,12 +193,14 @@ namespace ICSharpCode.FormsDesigner.Gui
}
if (lastAssembly != null) {
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name);
if (!TypeResolutionService.DesignerAssemblies.Contains(lastAssembly))
TypeResolutionService.DesignerAssemblies.Add(lastAssembly);
return lastAssembly;
}
return null;
}
*/
void SelectedTabItemChanged(object sender, EventArgs e)
{

20
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabItemDesigner.cs

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
*
* Project : FormDesigner Loading Library Control.
*
* Source code altering : A1
* Source code altering : A1
*
* Description : création of the Tab item displayed into the AXSideTabDesigner control.
* the control's creator initialize the toolboxitem of the tab item
@ -35,33 +35,23 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -35,33 +35,23 @@ namespace ICSharpCode.FormsDesigner.Gui
{
public class SideTabItemDesigner : SharpDevelopSideTabItem
{
public void CreatedUserControl()
{
InitializeComponents();
}
void InitializeComponents()
{
}
///<summary>create a tabitem from a toolboxitem. It init Icon and name from the tag</summary>
public SideTabItemDesigner(ToolboxItem tag) : base(tag.DisplayName, tag)
{
this.Icon = tag.Bitmap;
this.Icon = tag.Bitmap;
ReloadToolBox();
}
///<summary>create a tabitem from a toolboxitem. It init Icon from the tag</summary>
public SideTabItemDesigner(string name, ToolboxItem tag) : base(name, tag)
{
this.Icon = tag.Bitmap;
this.Icon = tag.Bitmap;
ReloadToolBox();
}
///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary>
public SideTabItemDesigner() : base("Pointer")
{
{
@ -80,6 +70,6 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -80,6 +70,6 @@ namespace ICSharpCode.FormsDesigner.Gui
if (this.Name != "Pointer") {
ToolboxProvider.ToolboxService.AddToolboxItem(this.Tag as ToolboxItem);
}
}
}
}
}

9
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs

@ -35,13 +35,14 @@ namespace ICSharpCode.FormsDesigner.Services @@ -35,13 +35,14 @@ namespace ICSharpCode.FormsDesigner.Services
{
List<Type> types = new List<Type>();
if (baseType != null) {
LoggingService.Debug("TypeDiscoveryService.GetTypes baseType=" + baseType.FullName);
LoggingService.Debug("TypeDiscoveryService.GetTypes excludeGlobalTypes=" + excludeGlobalTypes.ToString());
LoggingService.Debug("TypeDiscoveryService.GetTypes for " + baseType.FullName
+ "excludeGlobalTypes=" + excludeGlobalTypes.ToString());
//seek in all assemblies
//allow to work designers like columns editor in datagridview
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
foreach (Assembly asm in TypeResolutionService.DesignerAssemblies) {
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
@ -58,7 +59,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -58,7 +59,7 @@ namespace ICSharpCode.FormsDesigner.Services
{
foreach (Type t in assembly.GetExportedTypes()) {
if (t.IsSubclassOf(baseType)) {
LoggingService.Debug("TypeDiscoveryService. Adding type=" + t.FullName);
//LoggingService.Debug("TypeDiscoveryService. Adding type=" + t.FullName);
list.Add(t);
}
}

165
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

@ -1,23 +1,119 @@ @@ -1,23 +1,119 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.Core;
using HashFunction = System.Security.Cryptography.SHA1Managed;
namespace ICSharpCode.FormsDesigner.Services
{
public class TypeResolutionService : ITypeResolutionService
{
readonly static List<Assembly> designerAssemblies = new List<Assembly>();
// hash of file content -> Assembly
readonly static Dictionary<string, Assembly> assemblyDict = new Dictionary<string, Assembly>();
/// <summary>
/// List of assemblies used by the form designer. This static list is not an optimal solution,
/// but better than using AppDomain.CurrentDomain.GetAssemblies(). See SD2-630.
/// </summary>
public static List<Assembly> DesignerAssemblies {
get {
return designerAssemblies;
}
}
static TypeResolutionService()
{
DesignerAssemblies.Add(ProjectContentRegistry.MscorlibAssembly);
DesignerAssemblies.Add(ProjectContentRegistry.SystemAssembly);
DesignerAssemblies.Add(typeof(System.Drawing.Point).Assembly);
}
string formSourceFileName;
IProjectContent callingProject;
/// <summary>
/// Gets the project content of the project that created this TypeResolutionService.
/// Returns null when no calling project was specified.
/// </summary>
public IProjectContent CallingProject {
get {
if (formSourceFileName != null) {
if (ProjectService.OpenSolution != null) {
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(formSourceFileName);
if (p != null) {
callingProject = ParserService.GetProjectContent(p);
}
}
formSourceFileName = null;
}
return callingProject;
}
}
public TypeResolutionService()
{
}
public TypeResolutionService(string formSourceFileName)
{
this.formSourceFileName = formSourceFileName;
}
/// <summary>
/// Loads the assembly represented by the project content. Returns null on failure.
/// </summary>
public static Assembly LoadAssembly(IProjectContent pc)
{
if (pc.Project != null) {
return LoadAssembly(pc.Project.OutputAssemblyFullPath);
} else if (pc is ReflectionProjectContent) {
return LoadAssembly((pc as ReflectionProjectContent).AssemblyLocation);
} else {
return null;
}
}
/// <summary>
/// Loads the file in none-locking mode. Returns null on failure.
/// </summary>
public static Assembly LoadAssembly(string fileName)
{
if (!File.Exists(fileName))
return null;
byte[] data = File.ReadAllBytes(fileName);
string hash;
using (HashFunction hashFunction = new HashFunction()) {
hash = Convert.ToBase64String(hashFunction.ComputeHash(data));
}
lock (assemblyDict) {
Assembly asm;
if (assemblyDict.TryGetValue(hash, out asm))
return asm;
asm = Assembly.Load(data);
lock (designerAssemblies) {
if (!designerAssemblies.Contains(asm))
designerAssemblies.Add(asm);
}
assemblyDict[hash] = asm;
return asm;
}
}
public Assembly GetAssembly(AssemblyName name)
{
return GetAssembly(name, false);
@ -25,9 +121,20 @@ namespace ICSharpCode.FormsDesigner.Services @@ -25,9 +121,20 @@ namespace ICSharpCode.FormsDesigner.Services
public Assembly GetAssembly(AssemblyName name, bool throwOnError)
{
return Assembly.Load(name);
try {
Assembly asm = Assembly.Load(name);
lock (designerAssemblies) {
if (!designerAssemblies.Contains(asm))
designerAssemblies.Add(asm);
}
return asm;
} catch (System.IO.FileLoadException) {
if (throwOnError)
throw;
return null;
}
}
public string GetPathOfAssembly(AssemblyName name)
{
Assembly assembly = GetAssembly(name);
@ -39,7 +146,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -39,7 +146,7 @@ namespace ICSharpCode.FormsDesigner.Services
public Type GetType(string name)
{
return GetType(name, false);
return GetType(name, false, false);
}
public Type GetType(string name, bool throwOnError)
@ -56,18 +163,29 @@ namespace ICSharpCode.FormsDesigner.Services @@ -56,18 +163,29 @@ namespace ICSharpCode.FormsDesigner.Services
return null;
}
try {
Assembly lastAssembly = null;
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
Type t = asm.GetType(name, throwOnError);
if (t != null) {
lastAssembly = asm;
lock (designerAssemblies) {
foreach (Assembly asm in DesignerAssemblies) {
Type t = asm.GetType(name, false);
if (t != null) {
return t;
}
}
}
if (lastAssembly != null) {
return lastAssembly.GetType(name, throwOnError, ignoreCase);
}
Type type = Type.GetType(name, throwOnError, ignoreCase);
Type type = Type.GetType(name, false, ignoreCase);
if (type == null) {
IProjectContent pc = this.CallingProject;
if (pc != null) {
IClass foundClass = pc.GetClass(name);
if (foundClass != null) {
Assembly assembly = LoadAssembly(foundClass.ProjectContent);
if (assembly != null) {
type = assembly.GetType(name, false, ignoreCase);
}
}
}
}
// type lookup for typename, assembly, xyz style lookups
if (type == null) {
@ -80,19 +198,26 @@ namespace ICSharpCode.FormsDesigner.Services @@ -80,19 +198,26 @@ namespace ICSharpCode.FormsDesigner.Services
try {
assembly = Assembly.Load(assemblyName);
} catch (Exception e) {
Console.WriteLine(e);
LoggingService.Error(e);
}
if (assembly != null) {
type = assembly.GetType(typeName, throwOnError, ignoreCase);
lock (designerAssemblies) {
if (!designerAssemblies.Contains(assembly))
designerAssemblies.Add(assembly);
}
type = assembly.GetType(typeName, false, ignoreCase);
} else {
type = Type.GetType(typeName, throwOnError, ignoreCase);
type = Type.GetType(typeName, false, ignoreCase);
}
}
}
if (throwOnError && type == null)
throw new TypeLoadException(name + " not found by TypeResolutionService");
return type;
} catch (Exception e) {
Console.WriteLine(e);
LoggingService.Error(e);
}
return null;
}
@ -104,7 +229,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -104,7 +229,7 @@ namespace ICSharpCode.FormsDesigner.Services
/// <summary>
/// HACK - Ignore any requests for types from the Microsoft.VSDesigner
/// assembly. There are smart tag problems if data adapter
/// assembly. There are smart tag problems if data adapter
/// designers are used from this assembly.
/// </summary>
bool IgnoreType(string name)

11
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs

@ -40,17 +40,10 @@ namespace ICSharpCode.FormsDesigner @@ -40,17 +40,10 @@ namespace ICSharpCode.FormsDesigner
public class ToolboxProvider
{
static ICSharpCode.FormsDesigner.Services.ToolboxService toolboxService = null;
static ITypeResolutionService typeResolutionService = new TypeResolutionService();
public static ArrayList SideTabs = new ArrayList();
static ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader();
public static ITypeResolutionService TypeResolutionService {
get {
return typeResolutionService;
}
}
public static ComponentLibraryLoader ComponentLibraryLoader {
get {
return componentLibraryLoader;
@ -210,7 +203,7 @@ namespace ICSharpCode.FormsDesigner @@ -210,7 +203,7 @@ namespace ICSharpCode.FormsDesigner
static void AddReferenceToProject(IProject project, AssemblyName referenceName)
{
LoggingService.Debug("Adding reference to project: " + referenceName.FullName);
LoggingService.Warn("Adding reference to project: " + referenceName.FullName);
ReferenceProjectItem reference = new ReferenceProjectItem(project, "Reference");
ToolComponent toolComponent = ToolboxProvider.ComponentLibraryLoader.GetToolComponent(referenceName.FullName);
if (toolComponent == null || toolComponent.HintPath == null) {
@ -250,7 +243,7 @@ namespace ICSharpCode.FormsDesigner @@ -250,7 +243,7 @@ namespace ICSharpCode.FormsDesigner
static void AddProjectReferenceToProject(IProject project, IProject referenceTo)
{
LoggingService.Debug("Adding project reference to project.");
LoggingService.Warn("Adding project reference to project.");
ProjectReferenceProjectItem reference = new ProjectReferenceProjectItem(project, referenceTo);
ProjectService.AddProjectItem(project, reference);
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();

12
src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToCSharpConvertVisitor.cs

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 02.01.2006
* Time: 18:15
*/
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Text;

12
src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToVBNetConvertVisitor.cs

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 02.01.2006
* Time: 18:18
*/
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Text;

2
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs

@ -331,7 +331,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -331,7 +331,7 @@ namespace ICSharpCode.SharpDevelop.Gui
// find start of current line
while (--start > 0 && fullText[start - 1] != '\n');
// find end of current line
while (++index < fullText.Length && fullText[index] != '\r');
while (++index < fullText.Length && fullText[index] != '\n');
string textLine = fullText.Substring(start, index - start);

16
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -57,12 +57,28 @@ namespace ICSharpCode.Core @@ -57,12 +57,28 @@ namespace ICSharpCode.Core
forcedContent = content;
}
/// <summary>
/// Gets the list of project contents of all open projects.
/// </summary>
public static IEnumerable<IProjectContent> AllProjectContents {
get {
return projectContents.Values;
}
}
/// <summary>
/// Gets the list of project contents of all open projects plus the referenced project contents.
/// </summary>
public static IEnumerable<IProjectContent> AllProjectContentsWithReferences {
get {
foreach (IProjectContent pc in AllProjectContents) {
yield return pc;
}
foreach (IProjectContent pc in ProjectContentRegistry.LoadedProjectContents) {
yield return pc;
}
}
}
static ParserService()
{

20
src/Main/Base/Project/Src/Services/ParserService/ProjectContentRegistry.cs

@ -57,6 +57,12 @@ namespace ICSharpCode.Core @@ -57,6 +57,12 @@ namespace ICSharpCode.Core
}
}
public static IEnumerable<IProjectContent> LoadedProjectContents {
get {
return contents.Values;
}
}
public static IProjectContent WinForms {
get {
lock (contents) {
@ -173,13 +179,25 @@ namespace ICSharpCode.Core @@ -173,13 +179,25 @@ namespace ICSharpCode.Core
}
}
public static Assembly MscorlibAssembly {
get {
return typeof(object).Assembly;
}
}
public static Assembly SystemAssembly {
get {
return typeof(Uri).Assembly;
}
}
static Assembly GetDefaultAssembly(string shortName)
{
// These assemblies are already loaded by SharpDevelop, so we don't need to load
// them in a separate AppDomain.
switch (shortName) {
case "System": // System != mscorlib !!!
return typeof(Uri).Assembly;
return SystemAssembly;
case "System.Data":
return typeof(System.Data.DataException).Assembly;
case "System.Design":

15
src/Main/Base/Project/Src/Services/ParserService/ReflectionProjectContent.cs

@ -25,13 +25,26 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -25,13 +25,26 @@ namespace ICSharpCode.SharpDevelop.Dom
AssemblyName[] referencedAssemblies;
ICompilationUnit assemblyCompilationUnit;
string assemblyLocation;
public string AssemblyLocation {
get {
return assemblyLocation;
}
}
public bool IsGacAssembly {
get {
return assemblyLocation == typeof(object).Assembly.Location
|| FileUtility.IsBaseDirectory(GacRootPath, assemblyLocation);
}
}
public static string GacRootPath {
get {
return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProjectContentRegistry.SystemAssembly.Location), "..\\..\\.."));
}
}
public string AssemblyFullName {
get {
return assemblyFullName;

12
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerationForm.cs

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 29.12.2005
* Time: 14:34
*/
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;

Loading…
Cancel
Save