public void SyncFxProvisionScope(object sender, ExecutedRoutedEventArgs e) { var databaseInfo = ValidateMenuInfo(sender); if (databaseInfo == null) { return; } if (databaseInfo.DatabaseInfo.DatabaseType != DatabaseType.SQLCE35) { EnvDteHelper.ShowError("Sorry, only version 3.5 databases are supported for now"); return; } try { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(databaseInfo.DatabaseInfo.Caption); if (fileNameWithoutExtension == null) { return; } var model = fileNameWithoutExtension.Replace(" ", string.Empty).Replace("#", string.Empty).Replace(".", string.Empty).Replace("-", string.Empty); var sfd = new SyncFxDialog { ModelName = model }; var res = sfd.ShowModal(); if (!res.HasValue || res.Value != true || (sfd.Tables.Count <= 0)) { return; } if (SyncFxHelper.SqlCeScopeExists(databaseInfo.DatabaseInfo.ConnectionString, model)) { EnvDteHelper.ShowError("Scope name is already in use. Please enter a different scope name."); return; } model = sfd.ModelName; new SyncFxHelper().ProvisionScope(databaseInfo.DatabaseInfo.ConnectionString, model, sfd.Columns.Where(c => sfd.Tables.Contains(c.TableName)).ToList()); EnvDteHelper.ShowMessage("Scope: " + model + " has been provisioned."); DataConnectionHelper.LogUsage("DatabaseSyncProvision"); } catch (Exception ex) { DataConnectionHelper.SendError(ex, databaseInfo.DatabaseInfo.DatabaseType, false); } }
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 void SyncFxGenerateSyncCodeInProject(object sender, ExecutedRoutedEventArgs e) { var databaseInfo = ValidateMenuInfo(sender); if (databaseInfo == null) { return; } if (package == null) { return; } var dte = package.GetServiceHelper(typeof(DTE)) as DTE; var dteH = new 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); return; } if (databaseInfo.DatabaseInfo.DatabaseType != DatabaseType.SQLCE35) { EnvDteHelper.ShowError("Sorry, only version 3.5 databases are supported for now"); return; } try { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(databaseInfo.DatabaseInfo.Caption); if (fileNameWithoutExtension != null) { var model = fileNameWithoutExtension.Replace(" ", string.Empty).Replace("#", string.Empty).Replace(".", string.Empty).Replace("-", string.Empty); var sfd = new SyncFxDialog { ModelName = model }; var res = sfd.ShowModal(); if (!res.HasValue || res.Value != true || (sfd.Tables.Count <= 0)) { return; } model = sfd.ModelName; var defaultNamespace = project.Properties.Item("DefaultNamespace").Value.ToString(); var classes = new SyncFxHelper().GenerateCodeForScope(string.Empty, databaseInfo.DatabaseInfo.ConnectionString, "SQLCE", model, sfd.Columns.Where(c => sfd.Tables.Contains(c.TableName)).ToList(), defaultNamespace); var projectPath = project.Properties.Item("FullPath").Value.ToString(); 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); 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."); DataConnectionHelper.LogUsage("DatabaseSyncCodegen"); } } catch (Exception ex) { DataConnectionHelper.SendError(ex, databaseInfo.DatabaseInfo.DatabaseType, false); } }
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); } }
public async void SyncFxGenerateSyncCodeInProject(object sender, ExecutedRoutedEventArgs e) { var databaseInfo = ValidateMenuInfo(sender); if (databaseInfo == null) { return; } if (package == 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; } if (databaseInfo.DatabaseInfo.DatabaseType != DatabaseType.SQLCE35) { EnvDteHelper.ShowError("Sorry, only version 3.5 databases are supported for now"); return; } try { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(databaseInfo.DatabaseInfo.Caption); if (fileNameWithoutExtension != null) { var model = fileNameWithoutExtension.Replace(" ", string.Empty).Replace("#", string.Empty).Replace(".", string.Empty).Replace("-", string.Empty); var sfd = new SyncFxDialog { ModelName = model }; var res = sfd.ShowModal(); if (!res.HasValue || res.Value != true || (sfd.Tables.Count <= 0)) { return; } model = sfd.ModelName; var defaultNamespace = ThreadHelper.JoinableTaskFactory.Run(() => project.GetAttributeAsync("DefaultNamespace")); var classes = new SyncFxHelper().GenerateCodeForScope(string.Empty, databaseInfo.DatabaseInfo.ConnectionString, "SQLCE", model, sfd.Columns.Where(c => sfd.Tables.Contains(c.TableName)).ToList(), 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("DatabaseSyncCodegen"); } } catch (Exception ex) { DataConnectionHelper.SendError(ex, databaseInfo.DatabaseInfo.DatabaseType, false); } }