Exemplo n.º 1
0
 private bool TryGetMT4Manager(MT4ConnectOption key, out IRunThreadSafe <MT4Manager> value)
 {
     try
     {
         var hkey = Keys.First(p => p.login == key.login && p.password == key.password && p.server == key.server);
         value = this[hkey];
         return(true);
     }
     catch
     {
         value = default(IRunThreadSafe <MT4Manager>);
         return(false);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Производит реконнект к серверу
        /// Функция используется в асинхронном режиме
        /// </summary>
        public static void ReconnectOnServer(this MT4Manager mt4Service, MT4ConnectOption setting)
        {
            while (true)
            {
                try
                {
                    mt4Service.Connect(setting.server);
                    mt4Service.Login(setting.login, setting.password);

                    if (!mt4Service.CheckConnection())
                    {
                        continue;
                    }
                    break;
                }
                catch (MT4NetworkProblemExeption) { }
                catch (MT4NoConnectionExeption) { }
                catch (MT4CommonErrorExeption) { }
            }
        }
Exemplo n.º 3
0
        public void Run(MT4ConnectOption connect, Action <MT4Manager> actionWithObject)
        {
            var watch = new Stopwatch(); watch.Start();

            IRunThreadSafe <MT4Manager> manager;

            while (!TryGetMT4Manager(connect, out manager))
            {
                // создаем нового менеджера
                var threadSafeManager = new RunActionThreadSafe <MT4Manager>(
                    creator: () =>
                {
                    var newManager = creator.Invoke();
                    newManager.Communication(connect);
                    return(newManager);
                },
                    actionAfterInvoke: p => p.Dispose(),
                    leaveTheInTheQueue: runner => runner.Count <= 1);

                // проверка менеджера на работоспособность перед добавлением в очередь
                threadSafeManager.Run(p => p.Ping());

                // добавляем менеджера в словарь
                this.TryAdd(connect, threadSafeManager);
            }

            try
            {
                manager.Run(actionWithObject);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                watch.Stop();
            }
        }
Exemplo n.º 4
0
 public static void Communication(this MT4Manager manager, MT4ConnectOption connection)
 {
     manager.Connect(connection.server);
     manager.Login(connection.login, connection.password);
 }