private void OpenRemoteConnectionButton_Click(object sender, RoutedEventArgs e) { ConnectionDialog connectionDialog = CreateConnectionDialog(); connectionDialog.DataContext = Vm.Settings.RemoteConnection; connectionDialog.ShowAsync(); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var editorService = (IWindowsFormsEditorService)provider.GetService( typeof(IWindowsFormsEditorService) ); if (editorService != null) { ConnectionDialog dialog = new ConnectionDialog(); if (value != null) { dialog.ConnectionString = value.ToString(); } bool?connected = dialog.ShowDialog(); if (connected.HasValue && connected.Value) { value = dialog.ConnectionString; } } return(value); }
private static ConnectionDialog CreateConnectionDialog() { ConnectionDialog connectionDialog = new ConnectionDialog(); connectionDialog.DefaultButton = ContentDialogButton.Primary; return(connectionDialog); }
public static void Main() { if (Environment.OSVersion.Version.Major >= 6) { SetProcessDPIAware(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); directDeviceInitialized = false; mainWindow = new MainWindow(); directDevice = new BaseNode(); radioDevices = new List <RadioNode>(); radioDevices.Add(new RadioNode(1)); SettingHandler.Load(); logger = new Logger("log_", "txt"); connectionDialog = new ConnectionDialog(); mainWindow.FlowLayout.Controls.Add(directDevice.GroupBox); mainWindow.FlowLayout.Controls.Add(radioDevices[0].GroupBox); directDevice.GroupBox.Enabled = false; mainWindow.AddControl(logger.Interface); SetBigChartData(radioDevices[0].GroupBox.PowerChart); connectionDialog.Show(); Application.Run(mainWindow); }
public void AddCeDatabase(object sender, ExecutedRoutedEventArgs e) { try { string connectionString = string.Empty; #if V35 var dialog = new Connection35Dialog(); #else var dialog = new ConnectionDialog(); #endif dialog.Owner = Application.Current.MainWindow; bool?result = dialog.ShowDialog(); if (result.HasValue && result.Value == true) { if (!string.IsNullOrWhiteSpace(dialog.ConnectionString)) { Helpers.DataConnectionHelper.SaveDataConnection(dialog.ConnectionString); _parentWindow.BuildDatabaseTree(); } } } catch (Exception ex) { MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex)); } }
public static ConsoleProfile ShowConnectionDialog(Form owner) { using (var connectConsole = new ConnectionDialog()) { return(connectConsole.ShowDialog(owner) == DialogResult.OK ? connectConsole.ConsoleProfile : null); } }
public void TestDialog() { using (var dialog = new ConnectionDialog(null, true)) { dialog.ShowDialog(); } }
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 async void OpenLocalConnectionButton_Click(object sender, RoutedEventArgs e) { ConnectionDialog connectionDialog = CreateConnectionDialog(); connectionDialog.DataContext = Vm.Settings.LocalConnection; await connectionDialog.ShowAsync(); }
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { if (isNewConnection) { new TabularProperties(cxInfo); } bool?result = new ConnectionDialog(cxInfo).ShowDialog(); return(result == true); }
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { var win = new ConnectionDialog(cxInfo); var result = win.ShowDialog() == true; if (result) { cxInfo.CustomTypeInfo.CustomAssemblyPath = Assembly.GetAssembly(typeof(AzureDevOpsDataContext)).Location; cxInfo.CustomTypeInfo.CustomTypeName = "AzureDevOpsDataContextDriver.External.AzureDevOpsDataContext"; } return(result); }
public MainPresenter(MainForm mainForm, ServiceConnector serviceConnector, ConnectionDialog connectionDialog, ILogger logger) { _logger = logger; MainForm = mainForm; _serviceManager = serviceConnector; _ConnectionDialog = connectionDialog; // Подготовка столбцов DataGrid для списка сотрудников mainForm.EmployeeDataGridView.SetUpGrid(); mainForm.Presenter = this; mainForm.Load += new EventHandler(MainForm_Load); }
private void connectButton_Click(object sender, EventArgs e) { ConnectionDialog cd = new ConnectionDialog(); DialogResult result = cd.ShowDialog(); if (result == DialogResult.OK) { SetSourceContext(cd.CreateClientContext()); statusLabel.Text = "Connected to " + getSourceAddress() + "."; hintLabel.Visible = false; EnableNext = true; } }
private void TestConnClick(object sender, RoutedEventArgs e) { ConvertModelToString tmp = new ConvertModelToString(); String UserName = tmp.ConvertModelItem(ModelItem.Properties["UserName"].ComputedValue); String Password = tmp.ConvertModelItem(ModelItem.Properties["Password"].ComputedValue); String SecurityToken = tmp.ConvertModelItem(ModelItem.Properties["SecurityToken"].ComputedValue); String ConsumerKey = tmp.ConvertModelItem(ModelItem.Properties["ConsumerKey"].ComputedValue); String ConsumerSecret = tmp.ConvertModelItem(ModelItem.Properties["ConsumerSecret"].ComputedValue); Int32 Server_Type = Convert.ToInt32(ModelItem.Properties["Server_Type"].ComputedValue); ConnectionDialog buildDataTableWnd = new ConnectionDialog(UserName, Password, SecurityToken, ConsumerKey, ConsumerSecret, Server_Type == 0?true:false); buildDataTableWnd.ShowDialog(); }
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { var ConnectionData = new ConnectionData(cxInfo); // Prompt the user for connection string var dialog = new ConnectionDialog(cxInfo); var connectionDialogViewModel = new ConnectionDialogViewModel(); connectionDialogViewModel.ConnectionData = ConnectionData; dialog.DataContext = connectionDialogViewModel; var dialogResult = dialog.ShowDialog(); cxInfo.DisplayName = $"{ConnectionData.Username} @ {ConnectionData.OrganizationUrl}"; return(dialogResult == true); }
private void testConnection(object sauce, EventArgs args) { TreeIter i; TreeModel m; if (projectsTreeview.Selection.GetSelected(out m, out i)) { int val = (int)m.GetValue(i, 2); Project p = (Project)this.projects.ToArray()[val]; string errormessage = p.TestConnection(); if (errormessage == null) { ConnectionDialog cd = new ConnectionDialog("Connection OK", "All connection settings are OK."); } else { ConnectionDialog cd = new ConnectionDialog("Connection failed", "Could not establish connection: " + errormessage); } } }
private void _CreateConnection(bool initial) { ConnectData conn = null; // release the old connection _ReleaseConnection(); try { ConnectionDialog dlg = new ConnectionDialog(); dlg.NoAutoLogon = !initial; if (dlg.ShowDialog(this) == DialogResult.OK) { BringToFront(); // assign as current connection clsMain.Instance.CurrentConnection = dlg.ConnectData; _ShowAllDocuments(); } else { if (initial) { Close(); } } } catch (VI.DB.ViLoginCancelException) { conn.Connection.Dispose(); } catch (Exception ex) { ExceptionDialog.Show(this, ex); } }
public void SetCxSettingsWithEmptyObjectsForAdvancedSettings() { var mockCxInfo = new Mock <IConnectionInfo>(); var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]); mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element); var cxSettings = new SitecoreConnectionSettings(); var mapper = new DriverDataCxSettingsMapper(); mapper.Read(mockCxInfo.Object, cxSettings); var view = new ConnectionDialog(); view.InitializeComponent(); var driverSettings = new SitecoreDriverSettings() { CxInfo = mockCxInfo.Object, CxSettings = cxSettings, SettingsMapper = new DriverDataCxSettingsMapper() }; view.Model = driverSettings; var controller = new DriverSettingsController(view); controller.LoadView(driverSettings); view.SaveViewToModelCallback = controller.SaveView; // //basic settings view.ClientUrl = "http://localhost"; view.Username = "******"; view.Password = "******"; view.WebRootPath = @"C:\Windows\Temp"; view.ContextDatabaseName = "master"; // //advanced settings view.NamespacesToAdd = new HashSet <string>(); view.SearchResultType = new SelectedType(); view.AppConfigReaderType = new SelectedType(); view.SchemaBuilderType = new SelectedType(); view.DriverInitializerType = new SelectedType(); }
public void SetCxSettingsNull() { var mockCxInfo = new Mock <IConnectionInfo>(); var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]); mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element); var cxSettings = new SitecoreConnectionSettings(); var mapper = new DriverDataCxSettingsMapper(); mapper.Read(mockCxInfo.Object, cxSettings); var view = new ConnectionDialog(); view.InitializeComponent(); var driverSettings = new SitecoreDriverSettings() { CxInfo = mockCxInfo.Object, CxSettings = cxSettings, SettingsMapper = new DriverDataCxSettingsMapper() }; view.Model = driverSettings; var controller = new DriverSettingsController(view); controller.LoadView(driverSettings); view.SaveViewToModelCallback = controller.SaveView; // //basic settings view.ClientUrl = null; view.Username = null; view.Password = null; view.WebRootPath = null; view.ContextDatabaseName = null; // //advanced settings view.NamespacesToAdd = null; view.SearchResultType = null; view.AppConfigReaderType = null; view.SchemaBuilderType = null; view.DriverInitializerType = null; }
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { var view = new ConnectionDialog(); if (!view.IsInitialized) { view.InitializeComponent(); } try { var settings = GetCxSettings(cxInfo); var driverSettings = new SitecoreDriverSettings() { CxInfo = cxInfo, CxSettings = settings, SettingsMapper = new DriverDataCxSettingsMapper() }; view.Model = driverSettings; var controller = new DriverSettingsController(view); controller.LoadView(driverSettings); view.SaveViewToModelCallback = controller.SaveView; var result = view.ShowDialog(); return(result == true); } catch (Exception ex) { var message = string.Format("An exception was thrown when trying to load the dialog.\n\n" + "You might need to manually edit the connections file located in {0}.\n\n" + "=====================================\n" + "{1}\n{2}", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "LINQPad"), ex.Message, ex.StackTrace); MessageBox.Show(view, message, "Connection Dialog", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
private void HandleConnectionPreference([NotNull] object sender, [NotNull] RoutedEventArgs e) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(e, "e"); var connectionDialogViewModel = new ConnectionDialogViewModel { HostName = SettingsHolder.Instance.Settings.ConnectHostName, Port = SettingsHolder.Instance.Settings.ConnectPort }; var dialog = new ConnectionDialog { DataContext = connectionDialogViewModel, Owner = this }; var result = dialog.ShowDialog(); if (result.HasValue && result.Value) { SettingsHolder.Instance.Settings.ConnectHostName = connectionDialogViewModel.HostName; SettingsHolder.Instance.Settings.ConnectPort = connectionDialogViewModel.Port; } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ShutdownMode = ShutdownMode.OnExplicitShutdown; var provider = BuildProvider(); var connectionDialog = new ConnectionDialog { DataContext = provider.GetRequiredService <ConnectionDialogViewModel>() }; if (connectionDialog.ShowDialog() != true) { Shutdown(); return; } StartupUri = new Uri("/ID.SupportDatabase;component/Views/RootWindow.xaml", UriKind.Relative); ShutdownMode = ShutdownMode.OnMainWindowClose; }
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); } }
/////////////////////////////////////////////// private void DaxStudioWindowLoaded(object sender, RoutedEventArgs e) { var wb = _app.ActiveWorkbook; if (_xlHelper.HasPowerPivotData()) { // if current workbook has PowerPivot data ensure it is loaded into memory _xlHelper.EnsurePowerPivotDataIsLoaded(); _conn = new ADOTabularConnection(BuildPowerPivotConnection(), AdomdType.Excel, true); RefreshDatabaseList(); //RefreshTabularMetadata(); } else { var connDialog = new ConnectionDialog(wb, "", _xlHelper); if (connDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _conn = new ADOTabularConnection(connDialog.ConnectionString, AdomdType.AnalysisServices, true); RefreshDatabaseList(); //cboDatabase.SelectedIndex = 0; //RefreshTabularMetadata(); } } }
private void ConfigureButton_Click(object sender, System.Windows.RoutedEventArgs e) { ConnectionDialog connDialog = new ConnectionDialog(ModelItem); connDialog.Show(); }
private async void Button_Click(object sender, RoutedEventArgs e) { var previousStatus = status; Status = "Connecting"; var dialog = new ConnectionDialog(); var result = await dialog.ShowAsync(); // User Cancelled if (result == ContentDialogResult.None) { Status = previousStatus; return; } var connectionString = dialog.ConnectionString; var builder = new SqlConnectionStringBuilder(connectionString); Status = string.Format("You are connected to {0} on {1} as {2}.", builder.InitialCatalog, builder.DataSource, builder.UserID); var query = @" SELECT SCHEMA_NAME(t.schema_id) AS [Schema] ,t.name AS [Table] ,(SELECT [rows] FROM sys.sysindexes i WHERE (i.id = t.object_id) AND (i.indid < 2) AND (OBJECTPROPERTY(i.id, 'IsUserTable') = 1)) AS [Rows] FROM sys.tables t ORDER BY 2"; var newTables = new List <SqlTable>(); try { using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = query; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { newTables.Add(new SqlTable { Schema = reader.GetString(0), Name = reader.GetString(1), NumberOfRows = reader.GetInt32(2) }); } } } } Tables = newTables; } catch (Exception ex) { var msg = new MessageDialog(ex.Message) { Title = "Error" }; await msg.ShowAsync(); } }
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 void EditConnection() { Node node = (Node)dataTree.SelectedNode; ConnectionDialog dlg = new ConnectionDialog(); dlg.Owner = System.Windows.Application.Current.MainWindow; dlg.Connection = node.Connection; if (dlg.ShowDialog() == true) { node.Connection = dlg.Connection; node.Text = node.Connection.ToString(); node.Nodes.Clear(); node.Nodes.Add(new TreeNode()); node.HasExpand = false; if (dlg.Connection.Default) SetDefaultConnection(node.Connection); else node.ImageIndex = node.SelectedImageIndex = 1; SaveConnections(); Modified = true; } }
public void AddConnection() { ConnectionDialog dlg = new ConnectionDialog(); dlg.Owner = System.Windows.Application.Current.MainWindow; if (dlg.ShowDialog() == true) { Connection conn = dlg.Connection; Node node = new DatabaseNode(conn); if (conn.Default) SetDefaultConnection(conn); Container.Add(conn); SaveConnections(); dataTree.Nodes.Add(node); Modified = true; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RequestWindowFeature(WindowFeatures.ActionBar); dialog = ConnectionDialog.NewInstance(); SetContentView(Resource.Layout.main_activity_layout); canvas_view = FindViewById <RelativeLayout>(Tutorial.Android.Resource.Id.canvas_container); //menu and toolbar V7Toolbar toolbar = FindViewById <V7Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(false); SupportActionBar.SetDisplayShowTitleEnabled(false); SupportActionBar.SetTitle(Resource.String.actionbar_title); SupportActionBar.SetHomeButtonEnabled(false); toolbar.SetNavigationIcon(Resource.Drawable.icon); toolbar.InflateMenu(Resource.Menu.menu_main); //FrameRateLogger frl = new FrameRateLogger(); if (SupportedOpenGLVersion() >= 3) { // SetContentView(new LibPaintingView(ApplicationContext, null)); // Inject Fusee.Engine.Base InjectMe dependencies IO.IOImp = new IOImp(ApplicationContext); var fap = new Fusee.Base.Imp.Android.ApkAssetProvider(ApplicationContext); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(Font), Decoder = delegate(string id, object storage) { if (Path.GetExtension(id).ToLower().Contains("ttf")) { return new Font { _fontImp = new FontImp((Stream)storage) } } ; return(null); }, Checker = delegate(string id) { return(Path.GetExtension(id).ToLower().Contains("ttf")); } });
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); } }
static void Main(string[] args) { ConsoleColor old = Console.ForegroundColor; try{ var props = new ConnectionProperties(); using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom)) { var result = frm.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } } var cxi = new FakeConnection(); new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props); var driver = new MongoDynamicDataContextDriver(); List <Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList(); var code = driver.GetStaticCodeFiles() .Concat(new string[] { driver.GenerateDynamicCode(props, assemblies, "", "driver") }); if (props.InitializationQuery != null) { code = code.Concat(new string[] { driver.GenerateCustomInitQuery(props.InitializationQuery, "driver") }); } Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("------------------------------------------------"); foreach (string s in code) { Console.WriteLine(s); Console.WriteLine("------------------------------------------------"); } Console.ForegroundColor = old; using (var frm = new SaveFileDialog()) { var result = frm.ShowDialog(); if (result == DialogResult.OK) { using (StreamWriter writer = new StreamWriter(frm.OpenFile())) { foreach (string s in code) { writer.WriteLine(s); writer.WriteLine("---------------------------------------------------"); } writer.Flush(); } } } }catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); } finally{ Console.ForegroundColor = old; } }