Пример #1
0
        /// <summary>
        /// Create the specified database
        /// </summary>
        public override ConnectionString CreateDatabase(ConnectionString connectionString, string databaseName, string databaseOwner)
        {
            // This is a little tricky as we have to get the FireBird ADO and call the function through reflection since ORM doesn't have it
            connectionString = connectionString.Clone();
            connectionString.SetComponent("server type", "Embedded");
            connectionString.SetComponent("client library", "fbclient.dll");
            var fbConnectionType = Type.GetType("FirebirdSql.Data.FirebirdClient.FbConnection, FirebirdSql.Data.FirebirdClient");

            if (fbConnectionType == null)
            {
                throw new InvalidOperationException("Cannot find FirebirdSQL provider");
            }

            var createDbMethod = fbConnectionType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).SingleOrDefault(o => o.Name == "CreateDatabase" && o.GetParameters().Length == 4);

            if (createDbMethod == null)
            {
                throw new InvalidOperationException("Cannot find FirebirdSQL CreateDatabase method. Perhaps this is an invalid version of ADO.NET provider");
            }
            var dbPath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), databaseName), "fdb");

            dbPath = dbPath.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString());
            connectionString.SetComponent("initial catalog", dbPath);
            createDbMethod.Invoke(null, new object[] { connectionString.ToString(), 4096, true, false });
            connectionString.SetComponent("initial catalog", Path.GetFileName(dbPath));

            return(connectionString);
        }
        // ReSharper disable once UnusedMember.Global
        public ReconnectingAlienReaderProtocol(ConnectionString cs)
        {
            connectionString = cs.Clone();
            endpoint         = connectionString.Network;
            keepAliveTimeout = AlienReaderProtocol.DefaultKeepaliveTimeout;
            receiveTimeout   = AlienReaderProtocol.DefaultReceiveTimeout;
            usePolling       = true;
            login            = connectionString.Login;
            password         = connectionString.Password;
            onConnected      = async api =>
            {
                await api.AcqG2AntennaCombine(true);

                await api.AcqTime(connectionString.InventoryDuration);

                await api.AcqG2Q(connectionString.QValue);

                await api.AcqG2Session(connectionString.Session);

                await api.RFModulation(RFModulation.DRM);

                await api.RFLevel(connectionString.RFPower);

                await api.AntennaSequence(connectionString.AntennaConfiguration.ToAlienAntennaSequence());
            };
        }
        /// <summary>
        /// Get databases
        /// </summary>
        public override IEnumerable <string> GetDatabases(ConnectionString connectionString)
        {
            var cstr = connectionString.Clone();

            cstr.SetComponent("database", "postgres");
            using (var conn = this.GetProvider(cstr).GetReadonlyConnection())
            {
                try
                {
                    conn.Open();
                    using (var cmd = conn.Connection.CreateCommand())
                    {
                        cmd.CommandText = "SELECT datname FROM pg_database;";
                        List <String> retVal = new List <string>(10);
                        using (var reader = cmd.ExecuteReader())
                            while (reader.Read())
                            {
                                retVal.Add(Convert.ToString(reader[0]));
                            }
                        return(retVal.ToArray());
                    }
                }
                catch
                {
                    throw;
                }
            }
        }
Пример #4
0
        public void Should_clone_connection_string()
        {
            var cs1 = new ConnectionString {
                Protocol = ReaderProtocolType.Alien, Network = new DnsEndPoint("host", 111)
            };
            var cs2 = cs1.Clone();

            cs2.Should().NotBeSameAs(cs1);
            cs2.Protocol.Should().Be(ReaderProtocolType.Alien);
            cs2.Network.Host.Should().Be("host");
            cs2.Network.Port.Should().Be(111);
        }
        /// <summary>
        /// Create the specified database
        /// </summary>
        public override ConnectionString CreateDatabase(ConnectionString connectionString, string databaseName, string databaseOwner)
        {
            connectionString = connectionString.Clone();
            connectionString.SetComponent("database", "postgres");
            var provider = this.GetProvider(connectionString);

            using (var conn = provider.GetWriteConnection())
            {
                try
                {
                    // Create the database
                    conn.Open();

                    String[] cmds =
                    {
                        $"CREATE DATABASE {databaseName} WITH OWNER {databaseOwner};",
                        $"REVOKE ALL ON DATABASE {databaseName} FROM public;",
                        $"GRANT ALL ON DATABASE {databaseName} TO {databaseOwner};",
                        $"CREATE OR REPLACE LANGUAGE plpgsql;"
                    };

                    foreach (var cmd in cmds)
                    {
                        using (var c = conn.Connection.CreateCommand())
                        {
                            c.CommandText = cmd;
                            c.CommandType = System.Data.CommandType.Text;
                            c.ExecuteNonQuery();
                        }
                    }

                    connectionString.SetComponent("database", databaseName);
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException($"Could not create database: {e.Message}", e);
                }
            }

            return(connectionString);
        }
Пример #6
0
 public ConnectionString GetConnectionString() => _connectionString.Clone();
Пример #7
0
 public SerialUnifiedTagStream(ConnectionString cs)
 {
     connectionString = cs.Clone();
     serialReaderSafe = new SerialReaderSafe(connectionString, connected, errors);
 }
Пример #8
0
 public SerialReaderSafe(ConnectionString connectionString, IObserver <bool> connected, IObserver <Exception> errors)
 {
     this.connected        = connected;
     this.errors           = errors;
     this.connectionString = connectionString.Clone();
 }