コード例 #1
0
        public UnitOfWork(MongoUrl connectionUrl, IMessageBroker broker, IMapper mapper)
        {
            Broker = broker;
            var client = new MongoClient(connectionUrl);

            Database = client.GetDatabase(connectionUrl.DatabaseName);

            ScriptRepository = new ScriptRepository(Database);
            ConnectionPropertiesRepository = new ConnectionPropertiesRepository(Database);
            JobRepository       = new JobRepository(Database);
            JobLogRepository    = new JobLogRepository(Database, mapper);
            DashboardRepository = new DashboardRepository(Database);
            FolderRepository    = new FolderRepository(Database);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: csbernath/DataCommander
        private async void Open()
        {
            try
            {
                var fileDialog = new OpenFileDialog();
                fileDialog.Filter =
                    "SQL script files(*.sql)|*.sql|Access Files(*.mdb)|*.mdb|Access 2007 Files(*.accdb)|*.accdb|Excel files (*.xls;*.xlsx)|*.xls;*.xlsx|MSI files (*.msi)|*.msi|SQLite files (*.*)|*.*|SQL Server Compact files (*.sdf)|*.sdf|SQL Server Compact 4.0 files (*.sdf)|*.sdf";
                fileDialog.RestoreDirectory = true;
                var currentDirectory = Environment.CurrentDirectory;

                if (fileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    if (Environment.CurrentDirectory != currentDirectory)
                    {
                        Environment.CurrentDirectory = currentDirectory;
                    }

                    var       fileName         = fileDialog.FileName;
                    var       extension        = Path.GetExtension(fileName).ToLower();
                    string    connectionString = null;
                    IProvider provider         = null;

                    switch (fileDialog.FilterIndex)
                    {
                    case 1:
                        LoadFiles(fileDialog.FileNames);
                        break;

                    case 2:
                        connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName;
                        provider         = ProviderFactory.CreateProvider(ProviderName.OleDb);
                        break;

                    case 3:
                        connectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={fileName};Persist Security Info=False";
                        provider         = ProviderFactory.CreateProvider(ProviderName.OleDb);
                        break;

                    case 4:
                        if (extension == ".xls")
                        {
                            connectionString = Environment.Is64BitProcess
                                    ? $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={fileName};Extended Properties=Excel 8.0"
                                    : $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={fileName};Extended Properties=Excel 8.0";
                        }
                        else
                        {
                            connectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={fileName};Extended Properties=Excel 12.0";
                        }

                        provider = ProviderFactory.CreateProvider(ProviderName.OleDb);
                        break;

                    case 5:
                        connectionString = $"{ConnectionStringKeyword.DataSource}={fileName}";
                        provider         = ProviderFactory.CreateProvider("Msi");
                        break;

                    case 6:
                        connectionString = $"{ConnectionStringKeyword.DataSource}={fileName}";
                        provider         = ProviderFactory.CreateProvider(ProviderName.SqLite);
                        break;

                    case 7:
                        connectionString = $"{ConnectionStringKeyword.DataSource}={fileName}";
                        provider         = ProviderFactory.CreateProvider("SqlServerCe");
                        break;

                    case 8:
                        connectionString = $"{ConnectionStringKeyword.DataSource}={fileName}";
                        provider         = ProviderFactory.CreateProvider(ProviderName.SqlServerCe40);
                        break;

                    default:
                        throw new NotSupportedException();
                    }

                    if (provider != null)
                    {
                        var connection = provider.CreateConnection(connectionString);
                        await connection.OpenAsync(CancellationToken.None);

                        var connectionProperties = new ConnectionProperties
                        {
                            ConnectionName   = null,
                            ProviderName     = provider.Name,
                            ConnectionString = connectionString
                        };

                        var node    = DataCommanderApplication.Instance.ConnectionsConfigurationNode;
                        var subNode = new ConfigurationNode(null);
                        node.AddChildNode(subNode);
                        ConnectionPropertiesRepository.Save(connectionProperties, subNode);

                        var queryForm = new QueryForm(this, MdiChildren.Length, provider, connectionString, connection, _statusBar, _colorTheme);

                        queryForm.MdiParent = this;
                        queryForm.Font      = SelectedFont;
                        queryForm.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogLevel.Error, ex.ToLogString());
                MessageBox.Show(this, ex.ToString());
            }
        }