예제 #1
0
        /// <summary>
        /// Apply settings to the <see cref="IrbisConnection" />.
        /// </summary>
        public void ApplyToConnection
        (
            [NotNull] IrbisConnection connection
        )
        {
            Sure.NotNull(connection, nameof(connection));

            connection.Host        = _Select(Host, connection.Host);
            connection.Port        = _Select(Port, connection.Port);
            connection.Username    = _Select(Username, connection.Username);
            connection.Password    = _Select(Password, connection.Password);
            connection.Database    = _Select(Database, connection.Database);
            connection.Workstation = (IrbisWorkstation)_Select
                                     (
                (int)Workstation,
                (int)connection.Workstation
                                     );

            if (!string.IsNullOrEmpty(EngineTypeName))
            {
                connection.SetEngine(EngineTypeName);
            }

            if (!string.IsNullOrEmpty(SocketTypeName))
            {
                ClientSocketUtility.CreateSocket
                (
                    connection,
                    SocketTypeName
                );
            }

            if (!string.IsNullOrEmpty(NetworkLogging))
            {
                connection.SetNetworkLogging(NetworkLogging);
            }

            if (!string.IsNullOrEmpty(FactoryTypeName))
            {
                connection.SetCommandFactory(FactoryTypeName);
            }

            if (!string.IsNullOrEmpty(Smart))
            {
                SmartClientSocket smartSocket
                    = new SmartClientSocket(connection);
                connection.SetSocket(smartSocket);
            }

            if (!string.IsNullOrEmpty(Slow))
            {
                SlowSocket slowSocket = new SlowSocket
                                        (
                    connection,
                    connection.Socket
                                        );
                int delay;
                if (NumericUtility.TryParseInt32(Slow, out delay) &&
                    delay > 0)
                {
                    slowSocket.Delay = delay;
                }
                connection.SetSocket(slowSocket);
            }

            if (!string.IsNullOrEmpty(Broken))
            {
                BrokenSocket brokenSocket = new BrokenSocket
                                            (
                    connection,
                    connection.Socket
                                            );
                double probability;
                if (NumericUtility.TryParseDouble(Broken, out probability) &&
                    probability > 0.0 &&
                    probability < 1.0)
                {
                    brokenSocket.Probability = probability;
                }
                connection.SetSocket(brokenSocket);
            }

            if (RetryLimit != 0)
            {
                connection.SetRetry(RetryLimit, null);
            }

            if (!string.IsNullOrEmpty(UserData))
            {
                connection.UserData = UserData;
            }

            connection._connected = Connected;
        }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Length < 1 ||
                args.Length > 2)
            {
                Console.WriteLine
                (
                    "Usage: ReaderKiller <readerList>"
                );

                return;
            }

            string fileName = args[0];

            doDelete = ConfigurationUtility.GetBoolean
                       (
                "delete",
                false
                       );
            databases = ConfigurationUtility.GetString
                        (
                "databases",
                null
                        )
                        .ThrowIfNull("Databases not specified")
                        .Split
                        (
                new[] { ';', ',', ' ' },
                StringSplitOptions.RemoveEmptyEntries
                        );
            if (databases.Length == 0)
            {
                throw new Exception("Empty database list");
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                string connectionString = args.Length > 1
                    ? args[2]
                    : CM.AppSettings["connectionString"];

                string[] tickets = File.ReadAllLines
                                   (
                    fileName,
                    Encoding.UTF8
                                   );
                Console.WriteLine
                (
                    "Tickets loaded: {0}",
                    tickets.Length
                );

                using (connection = new IrbisConnection())
                {
                    connection.SetRetry(10, ExceptionResolver);

                    connection.ParseConnectionString
                    (
                        connectionString
                    );
                    connection.Connect();

                    Console.WriteLine("Connected");

                    for (int i = 0; i < tickets.Length; i++)
                    {
                        string ticket = tickets[i];
                        ProcessReader(i, ticket);
                    }
                }

                Console.WriteLine("Disconnected");

                stopwatch.Stop();
                Console.WriteLine
                (
                    "Time elapsed: {0}",
                    stopwatch.Elapsed.ToAutoString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }