Index: SQLite.Designer/SQLite.Designer.csproj ================================================================== --- SQLite.Designer/SQLite.Designer.csproj +++ SQLite.Designer/SQLite.Designer.csproj @@ -15,11 +15,11 @@ true full false - ..\bin\ + ..\bin\designer\ DEBUG;TRACE prompt 4 1701;1702;1699 512 @@ -57,24 +57,23 @@ False - - False - False - + + + UserControl SQLiteConnectionUIControl.cs @@ -120,6 +119,9 @@ + + COPY $(TargetPath) $(DevEnvDir)PrivateAssemblies + ADDED SQLite.Designer/SQLiteAdapterDesigner.cs Index: SQLite.Designer/SQLiteAdapterDesigner.cs ================================================================== --- /dev/null +++ SQLite.Designer/SQLiteAdapterDesigner.cs @@ -0,0 +1,67 @@ +namespace SQLite.Designer +{ + using System; + using System.ComponentModel; + using System.ComponentModel.Design; + using System.Data.Common; + using System.Collections; + using System.Reflection; + + internal sealed class SQLiteAdapterDesigner : ComponentDesigner, IExtenderProvider + { + private ComponentDesigner _designer = null; + + public SQLiteAdapterDesigner() + { + } + + public override void Initialize(IComponent component) + { + base.Initialize(component); + + Assembly assm = Assembly.Load("Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + if (assm != null) + { + Type type = assm.GetType("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner"); + if (type != null) + { + _designer = (ComponentDesigner)Activator.CreateInstance(type); + _designer.Initialize(component); + } + } + } + + protected override void Dispose(bool disposing) + { + if (_designer != null) + ((IDisposable)_designer).Dispose(); + + base.Dispose(disposing); + } + + public override DesignerVerbCollection Verbs + { + get + { + return (_designer != null) ? _designer.Verbs : null; + } + } + + public override ICollection AssociatedComponents + { + get + { + return (_designer != null) ? _designer.AssociatedComponents : null; + } + } + + #region IExtenderProvider Members + + public bool CanExtend(object extendee) + { + return (extendee is DbDataAdapter); + } + + #endregion + } +} Index: SQLite.Designer/SQLiteCommandDesigner.cs ================================================================== --- SQLite.Designer/SQLiteCommandDesigner.cs +++ SQLite.Designer/SQLiteCommandDesigner.cs @@ -4,56 +4,28 @@ using System.ComponentModel; using System.ComponentModel.Design; using System.Data.Common; using System.Data; - [ProvideProperty("CommandDesignTimeVisible", typeof(IDbCommand))] internal sealed class SQLiteCommandDesigner : ComponentDesigner, IExtenderProvider { - private object _designer; - private Type _designerType; - private bool visible; - public SQLiteCommandDesigner() { - _designerType = SQLiteDataAdapterToolboxItem._vsdesigner.GetType("Microsoft.VSDesigner.Data.VS.DataCommandDesigner"); - _designer = Activator.CreateInstance(_designerType); } public override void Initialize(IComponent component) { - visible = ((DbCommand)component).DesignTimeVisible; - - ((ComponentDesigner)_designer).Initialize(component); base.Initialize(component); } - public bool GetCommandDesignTimeVisible(IDbCommand cmd) - { - return visible; - } - - public void SetCommandDesignTimeVisible(IDbCommand cmd, bool value) - { - visible = value; - TypeDescriptor.Refresh(cmd); - } - protected override void PreFilterAttributes(System.Collections.IDictionary attributes) { base.PreFilterAttributes(attributes); - DesignTimeVisibleAttribute att = new DesignTimeVisibleAttribute(visible); + DesignTimeVisibleAttribute att = new DesignTimeVisibleAttribute(((DbCommand)Component).DesignTimeVisible); attributes[att.TypeId] = att; } - public override DesignerVerbCollection Verbs - { - get - { - return ((ComponentDesigner)_designer).Verbs; - } - } #region IExtenderProvider Members public bool CanExtend(object extendee) { return (extendee is DbCommand); Index: SQLite.Designer/SQLiteCommandHandler.cs ================================================================== --- SQLite.Designer/SQLiteCommandHandler.cs +++ SQLite.Designer/SQLiteCommandHandler.cs @@ -263,12 +263,12 @@ DataViewHierarchyAccessor.Connection.Command.ExecuteWithoutResults("VACUUM", (int)System.Data.CommandType.Text, null, 0); } private void ChangePassword() { - System.Data.SQLite.SQLiteConnection cnn = DataViewHierarchyAccessor.Connection.ConnectionSupport.ProviderObject as System.Data.SQLite.SQLiteConnection; - if (cnn == null) return; + // System.Data.SQLite.SQLiteConnection cnn = DataViewHierarchyAccessor.Connection.ConnectionSupport.ProviderObject as System.Data.SQLite.SQLiteConnection; + // if (cnn == null) return; } private void Refresh(int itemId) { IVsUIHierarchy hier = DataViewHierarchyAccessor.Hierarchy as IVsUIHierarchy; Index: SQLite.Designer/SQLiteConnectionProperties.cs ================================================================== --- SQLite.Designer/SQLiteConnectionProperties.cs +++ SQLite.Designer/SQLiteConnectionProperties.cs @@ -12,29 +12,43 @@ using Microsoft.VisualStudio.Data; using Microsoft.Win32; internal class SQLiteConnectionProperties : AdoDotNetConnectionProperties { + private static System.Reflection.Assembly _sqlite = null; + static SQLiteConnectionProperties() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); } - static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { if (args.Name.StartsWith("System.Data.SQLite", StringComparison.InvariantCultureIgnoreCase)) { - using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\.NETFramework\\v2.0.50727\\AssemblyFoldersEx\\SQLite")) - { - if (key != null) - { - return System.Reflection.Assembly.LoadFrom(System.IO.Path.Combine(key.GetValue(null).ToString(), "System.Data.SQLite.DLL")); - } - } + return SQLiteAssembly; } return null; } + + internal static System.Reflection.Assembly SQLiteAssembly + { + get + { + if (_sqlite == null) + { + using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\.NETFramework\\v2.0.50727\\AssemblyFoldersEx\\SQLite")) + { + if (key != null) + { + _sqlite = System.Reflection.Assembly.LoadFrom(System.IO.Path.Combine(key.GetValue(null).ToString(), "System.Data.SQLite.DLL")); + } + } + } + return _sqlite; + } + } public SQLiteConnectionProperties() : base("System.Data.SQLite") { } ADDED SQLite.Designer/SQLiteConnectionStringEditor.cs Index: SQLite.Designer/SQLiteConnectionStringEditor.cs ================================================================== --- /dev/null +++ SQLite.Designer/SQLiteConnectionStringEditor.cs @@ -0,0 +1,99 @@ +namespace SQLite.Designer +{ + using System; + using System.Reflection; + using System.Data; + using System.Data.Common; + using System.ComponentModel.Design; + using System.ComponentModel; + + internal sealed class SQLiteConnectionStringEditor : ObjectSelectorEditor + { + private ObjectSelectorEditor.Selector _selector = null; + + private Type _managerType = null; + + public SQLiteConnectionStringEditor() + { + Assembly assm = Assembly.Load("Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + if (assm != null) + { + _managerType = assm.GetType("Microsoft.VSDesigner.Data.VS.VsConnectionManager"); + } + } + + public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) + { + if (provider == null || context == null) return value; + if (context.Instance == null) return value; + + try + { + context.OnComponentChanging(); + object newConnection = base.EditValue(provider, value); + string connectionString = newConnection as string; + int index = -1; + + if (connectionString == null && newConnection != null) + { + if (_managerType != null) + { + object manager = Activator.CreateInstance(_managerType, new object[] { provider }); + if (manager != null) + { + index = (int)_managerType.InvokeMember("AddNewConnection", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, new object[] { "System.Data.SQLite" }); + if (index > -1 && _selector != null) + { + connectionString = (string)_managerType.InvokeMember("GetConnectionString", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, new object[] { index }); + _selector.SelectedNode = _selector.AddNode((string)_managerType.InvokeMember("GetConnectionName", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, new object[] { index }), connectionString, null); + } + } + } + // VsConnectionManager manager1 = new VsConnectionManager(serviceProvider); + // manager1.AddNewConnection(this.ManagedProviderInvariantName); + } + + if (String.IsNullOrEmpty(connectionString) == false) + { + value = connectionString; + } + context.OnComponentChanged(); + } + catch + { + } + return value; + } + + protected override void FillTreeWithData(Selector selector, ITypeDescriptorContext context, IServiceProvider provider) + { + object manager = Activator.CreateInstance(_managerType, new object[] { provider }); + DbConnection connection = (DbConnection)context.Instance; + ObjectSelectorEditor.SelectorNode node; + + _selector = selector; + + if (manager != null) + { + int items = (int)_managerType.InvokeMember("GetConnectionCount", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, null); + string dataProvider; + string connectionString; + string connectionName; + + for (int n = 0; n < items; n++) + { + connectionString = (string)_managerType.InvokeMember("GetConnectionString", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, new object[] { n }); + connectionName = (string)_managerType.InvokeMember("GetConnectionName", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, new object[] { n }); + dataProvider = (string)_managerType.InvokeMember("GetProvider", BindingFlags.Instance | BindingFlags.InvokeMethod, null, manager, new object[] { n }); + if (String.Compare(dataProvider, "System.Data.SQLite", true) == 0) + { + node = selector.AddNode(connectionName, connectionString, null); + + if (String.Compare(connectionString, connection.ConnectionString, true) == 0) + selector.SelectedNode = node; + } + } + } + } + } +} Index: SQLite.Designer/SQLiteDataAdapterToolboxItem.cs ================================================================== --- SQLite.Designer/SQLiteDataAdapterToolboxItem.cs +++ SQLite.Designer/SQLiteDataAdapterToolboxItem.cs @@ -2,11 +2,10 @@ { using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing.Design; - using System.Data.SQLite; using System.Data.Common; using System.Reflection; using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; @@ -15,80 +14,78 @@ [Serializable] [ToolboxItem(typeof(SQLiteDataAdapterToolboxItem))] internal sealed class SQLiteDataAdapterToolboxItem : ToolboxItem { private static Type _wizard = null; + internal static Assembly _vsdesigner = null; - static SQLiteDataAdapterToolboxItem() { _vsdesigner = Assembly.Load("Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - _wizard = _vsdesigner.GetType("Microsoft.VSDesigner.Data.VS.DataAdapterWizard"); } public SQLiteDataAdapterToolboxItem(Type type) : this(type, (Bitmap)null) { } - - public SQLiteDataAdapterToolboxItem(Type type, Bitmap bmp) : base(typeof(SQLiteDataAdapter)) + public SQLiteDataAdapterToolboxItem(Type type, Bitmap bmp) : base(type) { DisplayName = "SQLiteDataAdapter"; } - private SQLiteDataAdapterToolboxItem(SerializationInfo info, StreamingContext context) : base(typeof(SQLiteDataAdapter)) + private SQLiteDataAdapterToolboxItem(SerializationInfo info, StreamingContext context) { Deserialize(info, context); } protected override IComponent[] CreateComponentsCore(IDesignerHost host) { - SQLiteDataAdapter adp = new SQLiteDataAdapter(); + DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite"); - if (adp == null) return null; - + DbDataAdapter dataAdapter = fact.CreateDataAdapter(); IContainer container = host.Container; - - adp.SelectCommand = new SQLiteCommand(); - adp.SelectCommand.DesignTimeVisible = false; - container.Add(adp.SelectCommand, GenerateName(container, "SelectCommand")); - - adp.InsertCommand = new SQLiteCommand(); - adp.InsertCommand.DesignTimeVisible = false; - container.Add(adp.InsertCommand, GenerateName(container, "InsertCommand")); - - adp.UpdateCommand = new SQLiteCommand(); - adp.UpdateCommand.DesignTimeVisible = false; - container.Add(adp.UpdateCommand, GenerateName(container, "UpdateCommand")); - - adp.DeleteCommand = new SQLiteCommand(); - adp.DeleteCommand.DesignTimeVisible = false; - container.Add(adp.DeleteCommand, GenerateName(container, "DeleteCommand")); - - ITypeResolutionService res = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); - if (res != null) - { - res.ReferenceAssembly(typeof(SQLiteDataAdapter).Assembly.GetName()); - } - container.Add(adp); + + using (DbCommand adapterCommand = fact.CreateCommand()) + { + adapterCommand.DesignTimeVisible = false; + dataAdapter.SelectCommand = (DbCommand)((ICloneable)adapterCommand).Clone(); + container.Add(dataAdapter.SelectCommand, GenerateName(container, "SelectCommand")); + + dataAdapter.InsertCommand = (DbCommand)((ICloneable)adapterCommand).Clone(); + container.Add(dataAdapter.InsertCommand, GenerateName(container, "InsertCommand")); + + dataAdapter.UpdateCommand = (DbCommand)((ICloneable)adapterCommand).Clone(); + container.Add(dataAdapter.UpdateCommand, GenerateName(container, "UpdateCommand")); + + dataAdapter.DeleteCommand = (DbCommand)((ICloneable)adapterCommand).Clone(); + container.Add(dataAdapter.DeleteCommand, GenerateName(container, "DeleteCommand")); + } + + ITypeResolutionService typeResService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); + if (typeResService != null) + { + typeResService.ReferenceAssembly(dataAdapter.GetType().Assembly.GetName()); + } + + container.Add(dataAdapter); List list = new List(); - list.Add(adp); + list.Add(dataAdapter); if (_wizard != null) { - using (Form wizard = (Form)Activator.CreateInstance(_wizard, new object[] { host, adp })) + using (Form wizard = (Form)Activator.CreateInstance(_wizard, new object[] { host, dataAdapter })) { wizard.ShowDialog(); } } - if (adp.SelectCommand != null) list.Add(adp.SelectCommand); - if (adp.InsertCommand != null) list.Add(adp.InsertCommand); - if (adp.DeleteCommand != null) list.Add(adp.DeleteCommand); - if (adp.UpdateCommand != null) list.Add(adp.UpdateCommand); + if (dataAdapter.SelectCommand != null) list.Add(dataAdapter.SelectCommand); + if (dataAdapter.InsertCommand != null) list.Add(dataAdapter.InsertCommand); + if (dataAdapter.DeleteCommand != null) list.Add(dataAdapter.DeleteCommand); + if (dataAdapter.UpdateCommand != null) list.Add(dataAdapter.UpdateCommand); return list.ToArray(); } private static string GenerateName(IContainer container, string baseName) Index: SQLite.Interop/SQLite.Interop.vcproj ================================================================== --- SQLite.Interop/SQLite.Interop.vcproj +++ SQLite.Interop/SQLite.Interop.vcproj @@ -109,11 +109,11 @@ Name="VCWebDeploymentTool" /> /// /// #if !PLATFORM_COMPACTFRAMEWORK [RefreshProperties(RefreshProperties.All), DefaultValue("")] + [Editor("SQLite.Designer.SQLiteConnectionStringEditor, SQLite.Designer, Version=1.0.26.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] #endif public override string ConnectionString { get { Index: System.Data.SQLite/SQLiteDataAdapter.cs ================================================================== --- System.Data.SQLite/SQLiteDataAdapter.cs +++ System.Data.SQLite/SQLiteDataAdapter.cs @@ -16,11 +16,11 @@ /// SQLite implementation of DbDataAdapter. /// #if !PLATFORM_COMPACTFRAMEWORK [DefaultEvent("RowUpdated")] [ToolboxItem("SQLite.Designer.SQLiteDataAdapterToolboxItem, SQLite.Designer, Version=1.0.26.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139")] - [Designer("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] + [Designer("SQLite.Designer.SQLiteAdapterDesigner, SQLite.Designer, Version=1.0.26.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139")] #endif public sealed class SQLiteDataAdapter : DbDataAdapter { private static object _updatingEventPH = new object(); private static object _updatedEventPH = new object();