Esempio n. 1
0
        /// Two different bots must not have the same
        /// class name and strategy name <see cref="BotPanel.GetNameStrategyType"/> at the same time
        /// У двух разных роботов не должны одновременно совпадать
        /// имя класса и название стратегии <see cref="BotPanel.GetNameStrategyType"/> >
        public HotUpdateResult <BotPanel> Update(BotPanel bot)
        {
            try
            {
                if (bot.GetType().IsNested)
                {
                    return(ErrorResult);
                }

                List <string> sourceFiles = SeekForSourceFiles(bot);

                HotUpdateResult <BotPanel>?result = null;
                string botClassPath = default;
                foreach (string sourceFile in sourceFiles)
                {
                    HotUpdateResult <BotPanel> updatedBotResult = Execute(() =>
                                                                          Instantiate <BotPanel>(sourceFile, bot.NameStrategyUniq, bot.StartProgram));
                    BotPanel updatedBot = updatedBotResult.UpdatedObject;
                    if (updatedBot != null && updatedBot.GetNameStrategyType().Equals(bot.GetNameStrategyType()))
                    {
                        // Two bot classes with the same class name and strategy name
                        if (result?.UpdatedObject != null)
                        {
                            string errorMessage =
                                $"Duplicated classes with a name = \"{bot.GetType().Name}\" and strategy = \"{bot.GetNameStrategyType()}\" ";
                            return(new HotUpdateResult <BotPanel>(null, HotUpdateResultStatus.Error, errorMessage));
                        }

                        botClassPath = sourceFile;
                    }
                    result = updatedBotResult;
                }

                if (result != null)
                {
                    _classPathCache.Remove(GetBotUniqName(bot));
                    _classPathCache[GetBotUniqName(bot)] = botClassPath;
                }

                return(result ?? ErrorResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(ErrorResult);
            }
        }
Esempio n. 2
0
        public void HotUpdateActiveBot()
        {
            SendNewLogMessage(OsLocalization.Trader.Label161, LogMessageType.System);

            HotUpdateResult <BotPanel> result = HotUpdateManager.Instance.Update(_activPanel);

            if (HotUpdateResultStatus.Success == result.Status)
            {
                ReloadActivBot(result.UpdatedObject);
                Save();
                ReloadRiskJournals();
                SendNewLogMessage(OsLocalization.Trader.Label162, LogMessageType.System);
            }
            else
            {
                SendNewLogMessage(OsLocalization.Trader.Label163 + $". {result.ErrorMessage}.", LogMessageType.System);
            }
        }