private void AddCeDatabase(DatabaseType dbType) { try { var dialog = new ConnectionDialog(); string path; if (TryGetInitialPath(package, out path)) { dialog.InitialPath = path; } dialog.DbType = dbType; dialog.ShowDdexInfo = package.VSSupportsSimpleDDEX4Provider() || package.VSSupportsSimpleDDEX35Provider(); dialog.CouldSupportPrivateProvider = (dbType == DatabaseType.SQLCE40 && (SqlCeToolboxPackage.VisualStudioVersion == new Version(12, 0) || SqlCeToolboxPackage.VisualStudioVersion == new Version(14, 0))) || (dbType == DatabaseType.SQLCE35 && package.VSSupportsEF6()); bool?result = dialog.ShowModal(); if (result.HasValue && result.Value == true) { if (!string.IsNullOrWhiteSpace(dialog.ConnectionString)) { Helpers.DataConnectionHelper.SaveDataConnection(dialog.ConnectionString, dbType, package); ExplorerControl control = _parentWindow.Content as ExplorerControl; control.BuildDatabaseTree(); Helpers.DataConnectionHelper.LogUsage("DatabasesAddCeDatabase"); } } } catch (Exception ex) { Helpers.DataConnectionHelper.SendError(ex, dbType); } }
private void AddCeDatabase(DatabaseType dbType) { try { var dialog = new ConnectionDialog(); string path; if (TryGetInitialPath(_package, out path)) { dialog.InitialPath = path; } dialog.DbType = dbType; dialog.ShowDdexInfo = _package.VsSupportsSimpleDdex4Provider() || _package.VsSupportsSimpleDdex35Provider(); dialog.CouldSupportPrivateProvider = (dbType == DatabaseType.SQLCE40 && (SqlCeToolboxPackage.VisualStudioVersion >= new Version(12, 0))) || (dbType == DatabaseType.SQLCE35 && SqlCeToolboxPackage.VsSupportsEf6()); var result = dialog.ShowModal(); if (!result.HasValue || result.Value != true) { return; } if (string.IsNullOrWhiteSpace(dialog.ConnectionString)) { return; } DataConnectionHelper.SaveDataConnection(dialog.ConnectionString, dbType, _package); var control = _parentWindow.Content as ExplorerControl; if (control != null) { control.BuildDatabaseTree(); } DataConnectionHelper.LogUsage("DatabasesAddCeDatabase"); } catch (Exception ex) { DataConnectionHelper.SendError(ex, dbType); } }
public void SyncFxGenerateLocalDatabaseCacheCode(object sender, ExecutedRoutedEventArgs e) { // http://www.mztools.com/articles/2007/MZ2007011.aspx var menuItem = sender as MenuItem; if (menuItem == null) { return; } Scope scope = (Scope)menuItem.Tag; var dte = package.GetServiceHelper(typeof(EnvDTE.DTE)) as EnvDTE.DTE; var dteH = new Helpers.EnvDTEHelper(); var project = dteH.GetProject(dte); if (project == null) { EnvDTEHelper.ShowError("Please select a project in Solution Explorer, where you want the SyncFx classes to be placed"); return; } if (!dteH.AllowedProjectKinds.Contains(new Guid(project.Kind))) { EnvDTEHelper.ShowError("The selected project type does not support Sync Framework (please let me know if I am wrong)"); return; } if (project.CodeModel.Language != CodeModelLanguageConstants.vsCMLanguageCSharp) { EnvDTEHelper.ShowError("Unsupported code language, only C# is currently supported"); return; } if (project.Properties.Item("TargetFrameworkMoniker") == null) { EnvDTEHelper.ShowError("The selected project type does not support Sync Framework - missing TargetFrameworkMoniker"); return; } if (!project.Properties.Item("TargetFrameworkMoniker").Value.ToString().Contains(".NETFramework")) { EnvDTEHelper.ShowError("The selected project type does not support .NET Desktop - wrong TargetFrameworkMoniker: " + project.Properties.Item("TargetFrameworkMoniker").Value.ToString()); return; } try { string serverConnectionString = DataConnectionHelper.PromptForConnectionString(package); if (!string.IsNullOrEmpty(serverConnectionString)) { string clientConnectionString = string.Empty; //grab target SQL CE Database var dialog = new ConnectionDialog(); dialog.DbType = DatabaseType.SQLCE35; bool?result = dialog.ShowModal(); if (result.HasValue && result.Value == true && !string.IsNullOrWhiteSpace(dialog.ConnectionString)) { clientConnectionString = dialog.ConnectionString; } else { return; } string model = string.Empty; SyncFxDialog sfd = new SyncFxDialog(); int totalCount = 0; var databaseInfo = new DatabaseMenuCommandParameters { DatabaseInfo = new DatabaseInfo { ConnectionString = serverConnectionString, DatabaseType = DatabaseType.SQLServer } }; totalCount = SyncFxGetObjectsForSync(sfd, databaseInfo); sfd.ModelName = model; bool?res = sfd.ShowModal(); if (res.HasValue && res.Value == true && (sfd.Tables.Count > 0) && !string.IsNullOrWhiteSpace(sfd.ModelName)) { model = sfd.ModelName; var defaultNamespace = project.Properties.Item("DefaultNamespace").Value.ToString(); var columns = sfd.Columns.Where(c => sfd.Tables.Contains(c.TableName)).ToList(); var classes = new SyncFxHelper().GenerateCodeForScope(serverConnectionString, clientConnectionString, "SQL", model, columns, defaultNamespace); var projectPath = project.Properties.Item("FullPath").Value.ToString(); foreach (var item in classes) { string fileName = Path.Combine(projectPath, item.Key + ".cs"); if (File.Exists(fileName)) { File.Delete(fileName); } File.WriteAllText(fileName, item.Value); project.ProjectItems.AddFromFile(fileName); } //Adding references - http://blogs.msdn.com/b/murat/archive/2008/07/30/envdte-adding-a-refernce-to-a-project.aspx EnvDTEHelper.AddReference(project, "System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); EnvDTEHelper.AddReference(project, "Microsoft.Synchronization, Version=2.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); EnvDTEHelper.AddReference(project, "Microsoft.Synchronization.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); EnvDTEHelper.AddReference(project, "Microsoft.Synchronization.Data.SqlServer, Version=3.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); EnvDTEHelper.AddReference(project, "Microsoft.Synchronization.Data.SqlServerCe, Version=3.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); EnvDTEHelper.ShowMessage("Scope: " + model + " code generated."); Helpers.DataConnectionHelper.LogUsage("DatabasesSyncAddLocalDBCache"); } } } catch (Exception ex) { Helpers.DataConnectionHelper.SendError(ex, DatabaseType.SQLServer); } }
public async void SyncFxGenerateLocalDatabaseCacheCode(object sender, ExecutedRoutedEventArgs e) { // http://www.mztools.com/articles/2007/MZ2007011.aspx var menuItem = sender as MenuItem; if (menuItem == null) { return; } var dteH = new EnvDteHelper(); var project = dteH.GetProject(); if (project == null) { EnvDteHelper.ShowError("Please select a project in Solution Explorer, where you want the SyncFx classes to be placed"); return; } if (!dteH.ContainsAllowed(project)) { EnvDteHelper.ShowError("The selected project type does not support Sync Framework (please let me know if I am wrong)"); return; } var tfm = ThreadHelper.JoinableTaskFactory.Run(() => project.GetAttributeAsync("TargetFrameworkMoniker")); if (string.IsNullOrEmpty(tfm)) { EnvDteHelper.ShowError("The selected project type does not support Sync Framework - missing TargetFrameworkMoniker"); return; } if (!tfm.Contains(".NETFramework")) { EnvDteHelper.ShowError("The selected project type does not support .NET Desktop - wrong TargetFrameworkMoniker: " + tfm); return; } try { var serverConnectionString = DataConnectionHelper.PromptForConnectionString(_package); if (string.IsNullOrEmpty(serverConnectionString)) { return; } string clientConnectionString; //grab target SQL CE Database var dialog = new ConnectionDialog(); dialog.DbType = DatabaseType.SQLCE35; var result = dialog.ShowModal(); if (result.HasValue && result.Value && !string.IsNullOrWhiteSpace(dialog.ConnectionString)) { clientConnectionString = dialog.ConnectionString; } else { return; } var model = string.Empty; var sfd = new SyncFxDialog(); var databaseInfo = new DatabaseMenuCommandParameters { DatabaseInfo = new DatabaseInfo { ConnectionString = serverConnectionString, DatabaseType = DatabaseType.SQLServer } }; SyncFxGetObjectsForSync(sfd, databaseInfo); sfd.ModelName = model; var res = sfd.ShowModal(); if (res.HasValue && res.Value && (sfd.Tables.Count > 0) && !string.IsNullOrWhiteSpace(sfd.ModelName)) { model = sfd.ModelName; var defaultNamespace = ThreadHelper.JoinableTaskFactory.Run(() => project.GetAttributeAsync("DefaultNamespace")); var columns = sfd.Columns.Where(c => sfd.Tables.Contains(c.TableName)).ToList(); var classes = new SyncFxHelper().GenerateCodeForScope(serverConnectionString, clientConnectionString, "SQL", model, columns, defaultNamespace); var projectPath = Path.GetDirectoryName(project.FullPath); foreach (var item in classes) { var fileName = Path.Combine(projectPath, item.Key + ".cs"); if (File.Exists(fileName)) { File.Delete(fileName); } File.WriteAllText(fileName, item.Value); ThreadHelper.JoinableTaskFactory.Run(() => project.AddExistingFilesAsync(fileName)); } //Adding references - http://blogs.msdn.com/b/murat/archive/2008/07/30/envdte-adding-a-refernce-to-a-project.aspx await EnvDteHelper.AddReferenceAsync(project, "System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); await EnvDteHelper.AddReferenceAsync(project, "Microsoft.Synchronization, Version=2.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); await EnvDteHelper.AddReferenceAsync(project, "Microsoft.Synchronization.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); await EnvDteHelper.AddReferenceAsync(project, "Microsoft.Synchronization.Data.SqlServer, Version=3.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); await EnvDteHelper.AddReferenceAsync(project, "Microsoft.Synchronization.Data.SqlServerCe, Version=3.1.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"); EnvDteHelper.ShowMessage("Scope: " + model + " code generated."); DataConnectionHelper.LogUsage("DatabasesSyncAddLocalDBCache"); } } catch (Exception ex) { DataConnectionHelper.SendError(ex, DatabaseType.SQLServer); } }