コード例 #1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                RobotCollection.Initialize();
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка инициализации коллекции роботов", ex);
                throw;
            }

            QuoteStorage.Instance.LoadQuotes(string.Format("{0}\\lastquote.txt", ExecutablePath.ExecPath));
            try
            {
                quoteReceiver = new TcpQuoteReceiver();
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка получения котировок", ex);
                throw;
            }

            Logger.InfoFormat("Старт сервиса - загрузка настроек");
            BL.RobotFarm.Instance.LoadSettings();
            quoteReceiver.OnQuotesReceived += BL.RobotFarm.Instance.OnQuotesReceived;
            StartWebServer();
        }
コード例 #2
0
        public void ReadRobotsSettings(string xmlPath)
        {
            if (!File.Exists(xmlPath))
            {
                return;
            }

            gridRobot.rows.Clear();
            try
            {
                var doc = new XmlDocument();
                doc.Load(xmlPath);
                var node  = doc.SelectSingleNode("RobotsPortfolio");
                var nodes = node.SelectNodes("robot");

                var robots = new List <RobotGridItem>();
                foreach (XmlElement item in nodes)
                {
                    var inodes = item.SelectNodes("Robot.TypeName");
                    var inode  = (XmlElement)inodes[0];
                    var title  = inode.Attributes["value"].Value;
                    var robot  = RobotCollection.MakeRobot(title);
                    PropertyXMLTagAttribute.InitObjectProperties(robot, item, false);
                    robots.Add(new RobotGridItem(robot, true));
                }
                gridRobot.DataBind(robots);
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка чтения файла настроек портфеля роботов: ", ex);
            }
        }
コード例 #3
0
        public static List <BaseRobot> LoadRobots()
        {
            var listRobots = new List <BaseRobot>();
            var fileName   = string.Format("{0}\\{1}", ExecutablePath.ExecPath, RobotFileName);

            if (!File.Exists(fileName))
            {
                return(listRobots);
            }

            try
            {
                var doc = new XmlDocument();
                doc.Load(fileName);
                var node  = doc.SelectSingleNode("RobotsPortfolio");
                var nodes = node.SelectNodes("robot");

                foreach (XmlElement item in nodes)
                {
                    var inodes = item.SelectNodes("Robot.TypeName");
                    var inode  = (XmlElement)inodes[0];
                    var title  = inode.Attributes["value"].Value;
                    var robot  = RobotCollection.MakeRobot(title);
                    PropertyXMLTagAttribute.InitObjectProperties(robot, item);
                    listRobots.Add(robot);
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Ошибка чтения файла \"{0}\": {1}", fileName, ex);
            }
            return(listRobots);
        }
コード例 #4
0
ファイル: CountTest.cs プロジェクト: iworm/marsexplorer
        public void TestRobotCount()
        {
            RobotCollection robots = new RobotCollection();
            robots.Add(new Robot(0, null, null, null, null));

            Assert.AreEqual(1, robots.Count);
        }
コード例 #5
0
 public void ListenReportedPosition()
 {
     RobotCollection robots = new RobotCollection();
     robots.ReportedPosition += (id, position, heading) => Assert.Pass();
     robots.Add(new Robot(0, new Position(1, 1), new HeadingEast(), new List<char>() { 'M' }, new Plateau(5, 5)));
     robots.StartExplore();
 }
コード例 #6
0
        private void AddRobotInPortfolio(string robotName)
        {
            var robot = RobotCollection.MakeRobot(robotName);

            robot.Magic = gridRobot.rows.Count + 1;
            var allRobots = grid.GetBoundValues().ToList();

            var robotInitialized = !LivePortfolioMode;

            allRobots.Add(new RobotGridItem(robot, robotInitialized));
            gridRobot.DataBind(allRobots);
            gridRobot.Invalidate();
        }
コード例 #7
0
        public MainForm()
        {
            InitializeComponent();
            workerQuote.WorkerSupportsCancellation = true;
            workerQuote.WorkerReportsProgress      = true;
            workerQuote.DoWork          += WorkerQuoteOnDoWork;
            workerQuote.ProgressChanged += (sender, args) =>
            {
                lblWorkerProgress.Text = "прогресс: " + args.ProgressPercentage;
            };
            workerQuote.RunWorkerCompleted += WorkerQuoteOnRunWorkerCompleted;

            RobotCollection.Initialize();
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: zhangjiayin/TradeSharp
        public MainForm()
        {
            InitializeComponent();
            SetupDaysOff();

            workerQuote.WorkerSupportsCancellation = true;
            workerQuote.WorkerReportsProgress      = true;
            workerQuote.DoWork          += WorkerQuoteOnDoWork;
            workerQuote.ProgressChanged += (sender, args) =>
            {
                lblWorkerProgress.Text = "прогресс: " + args.ProgressPercentage;
            };
            workerQuote.RunWorkerCompleted += WorkerQuoteOnRunWorkerCompleted;

            receiver = new TcpQuoteReceiver();
            receiver.OnQuotesReceived += (names, quotes) =>
            {
                LiveQuotes.Instance.UpdateQuotes(names, quotes);
            };

            RobotCollection.Initialize();
        }
コード例 #9
0
        private static List <BaseRobot> MakeRobots(XmlElement accountNode)
        {
            var robots = new List <BaseRobot>();

            try
            {
                foreach (XmlElement robotNode in accountNode.GetElementsByTagName("robot"))
                {
                    var inodes = robotNode.SelectNodes("Robot.TypeName");
                    var inode  = (XmlElement)inodes[0];
                    var title  = inode.Attributes["value"].Value;
                    var robot  = RobotCollection.MakeRobot(title);
                    PropertyXMLTagAttribute.InitObjectProperties(robot, robotNode, false);
                    robots.Add(robot);
                }
                return(robots);
            }
            catch (Exception ex)
            {
                Logger.Error("Error in MakeRobots()", ex);
                throw;
            }
        }
コード例 #10
0
 public int LoadRobots(XmlElement node)
 {
     robots.Clear();
     try
     {
         var nodes = node.SelectNodes("robot");
         // ReSharper disable PossibleNullReferenceException
         foreach (XmlElement item in nodes)
         {
             var inodes = item.SelectNodes("Robot.TypeName");
             var inode  = (XmlElement)inodes[0];
             // ReSharper restore PossibleNullReferenceException
             var title = inode.Attributes["value"].Value;
             var robot = RobotCollection.MakeRobot(title);
             PropertyXMLTagAttribute.InitObjectProperties(robot, item, false);
             robots.Add(robot);
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Ошибка чтения файла настроек портфеля роботов: ", ex);
     }
     return(robots.Count);
 }
コード例 #11
0
 public void NotListenReportedPosition()
 {
     RobotCollection robots = new RobotCollection();
     robots.Add(new Robot(0, new Position(1, 1), new HeadingEast(), new List<char>() { 'M' }, new Plateau(5, 5)));
     robots.StartExplore();
 }
コード例 #12
0
 public Engine()
 {
     citiPopulation  = new CitizenCollection();
     robotCollection = new RobotCollection();
 }