protected override RESULT Initial(StringBuilder messager)
 {
     Balancer        = new AverageBalancer();
     LinesController = new LinesController(60);
     InitialTimeLine();
     return(base.Initial(messager));
 }
 void Start()
 {
     _levelManager    = GameObject.Find("LevelManager").GetComponent <LevelManager>();
     _linesController = new LinesController(_defaultMaterial, _levelManager.LinesCount);
     _generateButton.onClick.AddListener(OnGenerateButtonClick);
     Generate(_levelManager.CharactersCount);
 }
示例#3
0
        private void Start()
        {
            _winWindow.SetActive(false);
            _timer          = GameObject.Find("Timer").GetComponent <Timer>();
            _levelManager   = GameObject.Find("LevelManager").GetComponent <LevelManager>();
            _travaGenerator = GameObject.Find("Background").GetComponent <TravaGenerator>();

            _linesController           = new LinesController(_defaultMaterial, _levelManager.LinesCount);
            _charactersGeneratorScript = gameObject.GetComponent <CharactersGenerator>();
            _clearAllButton.onClick.AddListener(ClearAll);
            _undoButton.onClick.AddListener(UndoLastAction);
            _linesCounter = new LinesCounter(_linesCount, _levelManager.LinesCount);
        }
示例#4
0
    /// <summary>
    /// 初始化
    /// </summary>
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }

        else if (instance != this)
        {
            Destroy(gameObject);
        }
        DontDestroyOnLoad(gameObject);
    }
示例#5
0
        public void Index()
        {
            var controller  = new LinesController(new LineBLL(new LineRepositoryStab()));
            var sessionMock = new TestControllerBuilder();

            sessionMock.InitializeController(controller);
            controller.Session["AuthenticatedUser"] = new DbUser
            {
                Username = "******",
                Password = null,
                Salt     = null
            };
            IStationRepository stationRepository = new StationRepositoryStab();
            var lines = new List <Line>();

            for (var i = 1; i <= 10; i++)
            {
                var line = new Line {
                    LineId = i, Name = "Line " + i, LineStations = new List <LineStation>()
                };
                var num = 1;
                foreach (var station in stationRepository.Get())
                {
                    line.LineStations.Add(new LineStation
                    {
                        LineStationId = num++ *i,
                        Line          = line,
                        Station       = station,
                        Minutes       = num * 10
                    });
                }
            }

            var actionResult = (ViewResult)controller.Index();
            var result       = (List <Line>)actionResult.Model;

            Assert.AreEqual(actionResult.ViewName, "");
            for (var i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(lines[i].LineId, result[i].LineId);
                Assert.AreEqual(lines[i].Name, result[i].Name);
                for (var j = 0; j < lines[i].LineStations.Count; j++)
                {
                    Assert.AreEqual(lines[i].LineStations[j].Station.StationId, result[i].LineStations[j].Station.StationId);
                    Assert.AreEqual(lines[i].LineStations[j].Line.LineId, result[i].LineStations[j].Line.LineId);
                }
            }
        }
        protected override RESULT Process(StringBuilder messager)
        {
            var data = this.GetData <TengxunStockInfoEntity>(CollectClient.ID);

            if (data != null)
            {
                Balancer.Add(new KeyValuePair <DateTime, decimal>(data.Time, data.Current)).ForEach(pair => LinesController.Add(pair));
                LinesController.Process();
                this.logger.Write(TYPE.INFO, LinesController.ToString());
            }

            ProcessCommand(this.GetData <SGCommand>(SocketClient.ID));

            //if (data != null) this.logger.Write(TYPE.INFO, data.ToString());
            return(RESULT.OK);
        }
示例#7
0
        public void Delete()
        {
            var controller  = new LinesController(new LineBLL(new LineRepositoryStab()));
            var sessionMock = new TestControllerBuilder();

            sessionMock.InitializeController(controller);
            controller.Session["AuthenticatedUser"] = new DbUser
            {
                Username = "******",
                Password = null,
                Salt     = null
            };
            var actionResult = (RedirectToRouteResult)controller.Delete(3);

            Assert.IsNotNull(actionResult, "Not a redirect result");
            Assert.IsFalse(actionResult.Permanent);
            Assert.AreEqual("Index", actionResult.RouteValues["Action"]);
        }
示例#8
0
        public void Edit()
        {
            var controller  = new LinesController(new LineBLL(new LineRepositoryStab()));
            var sessionMock = new TestControllerBuilder();

            sessionMock.InitializeController(controller);
            controller.Session["AuthenticatedUser"] = new DbUser
            {
                Username = "******",
                Password = null,
                Salt     = null
            };
            var actionResult = (ViewResult)controller.Edit(1);

            IStationRepository stationRepository = new StationRepositoryStab();

            var expectedResult = new Line {
                LineId = 1, Name = "Line " + 1, LineStations = new List <LineStation>()
            };
            var num = 1;

            foreach (var station in stationRepository.Get())
            {
                expectedResult.LineStations.Add(new LineStation
                {
                    LineStationId = num++ *1,
                    Line          = expectedResult,
                    Station       = station,
                    Minutes       = num * 10
                });
            }
            var result = (Line)actionResult.Model;

            Assert.AreEqual(actionResult.ViewName, "");
            Assert.AreEqual(result.LineId, expectedResult.LineId);
            Assert.AreEqual(result.Name, expectedResult.Name);
            for (var i = 0; i < expectedResult.LineStations.Count; i++)
            {
                Assert.AreEqual(expectedResult.LineStations[i].Station.StationId, result.LineStations[i].Station.StationId);
                Assert.AreEqual(expectedResult.LineStations[i].Line.LineId, result.LineStations[i].Line.LineId);
            }
        }
示例#9
0
        public void Add()
        {
            var controller  = new LinesController(new LineBLL(new LineRepositoryStab()));
            var sessionMock = new TestControllerBuilder();

            sessionMock.InitializeController(controller);
            controller.Session["AuthenticatedUser"] = new DbUser
            {
                Username = "******",
                Password = null,
                Salt     = null
            };
            var line         = new Line();
            var actionResult = (ViewResult)controller.Add();

            var result = (Line)actionResult.Model;

            Assert.AreEqual(actionResult.ViewName, "");
            Assert.AreEqual(result.LineId, line.LineId);
            Assert.AreEqual(result.Name, line.Name);
            Assert.AreEqual(result.LineStations, line.LineStations);
        }
示例#10
0
        private void InitialTimeLine()
        {
            var HourLine = new HourLine <KeyValuePair <DateTime, decimal> >((pair) => { return(pair.Key); }, (pair) => { return(pair.Value); }, null);

            HourLine.AddLine(new AverageLine(LINE.HOUR5, (int)AverageType.AT5, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            HourLine.AddLine(new AverageLine(LINE.HOUR10, (int)AverageType.AT10, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            HourLine.AddLine(new AverageLine(LINE.HOUR30, (int)AverageType.AT30, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            var DailyLine = new DailyLine <KeyValuePair <DateTime, decimal> >((pair) => { return(pair.Key); }, (pair) => { return(pair.Value); }, null);

            DailyLine.AddLine(new AverageLine(LINE.DAILY5, (int)AverageType.AT5, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            DailyLine.AddLine(new AverageLine(LINE.DAILY10, (int)AverageType.AT10, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            DailyLine.AddLine(new AverageLine(LINE.DAILY30, (int)AverageType.AT30, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            var WeeklyLine = new WeeklyLine <KeyValuePair <DateTime, decimal> >((pair) => { return(pair.Key); }, (pair) => { return(pair.Value); }, null);

            WeeklyLine.AddLine(new AverageLine(LINE.WEEKLY5, (int)AverageType.AT5, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            WeeklyLine.AddLine(new AverageLine(LINE.WEEKLY10, (int)AverageType.AT10, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));
            WeeklyLine.AddLine(new AverageLine(LINE.WEEKLY30, (int)AverageType.AT30, 2).BindEvent("BreakIn", BreakIn).BindEvent("BreakBack", BreakBack).BindEvent("BreakOut", BreakOut).BindEvent("Touched", Touched));

            var date = (GENTableEntity.Count <DBTStkDailyEntity>(accessor) > 0) ? GENTableEntity.MaxValue <DBTStkDailyEntity, DateTime?>(accessor, "Date") : null;
            var time = (GENTableEntity.Count <DBTStkMinuteEntity>(accessor) > 0) ? GENTableEntity.MaxValue <DBTStkMinuteEntity, DateTime?>(accessor, "Time") : null;

            // Initialize DailyLine and WeeklyLine
            if (date.HasValue)
            {
                using (var page = new EntityPage <DBTStkDailyEntity>(
                           new Clause("Code = {Code} AND Date >= {Date}").AddParam("Code", this.id).AddParam("Date", date.Value.Date.AddMonths(-8)),
                           new Sort().Add("Date", Sort.Orientation.asc), 100,
                           accessor
                           ))
                {
                    int pageno = 0;
                    List <DBTStkDailyEntity> lst_data = null;
                    while ((lst_data = page.Retrieve(++pageno)).Count > 0)
                    {
                        lst_data.ForEach(data =>
                        {
                            if (!DailyLine.IsReady)
                            {
                                DailyLine.Initialize(data.Date);
                            }
                            if (!WeeklyLine.IsReady)
                            {
                                WeeklyLine.Initialize(data.Date);
                            }

                            DailyLine.Add(new KeyValuePair <DateTime, decimal>(data.Date, data.Close));
                            WeeklyLine.Add(new KeyValuePair <DateTime, decimal>(data.Date, data.Close));
                        });
                    }
                }
            }
            if (!DailyLine.IsReady)
            {
                DailyLine.Initialize(DateTime.Today);
            }
            if (!WeeklyLine.IsReady)
            {
                WeeklyLine.Initialize(DateTime.Today);
            }

            // Initialize HourLine
            if (time.HasValue)
            {
                using (var page = new EntityPage <DBTStkMinuteEntity>(
                           new Clause("Code = {Code} AND Time >= {Time}").AddParam("Code", this.id).AddParam("Time", time.Value.Date.AddDays(-20)),
                           new Sort().Add("Time", Sort.Orientation.asc), 1000,
                           accessor
                           ))
                {
                    int pageno = 0;
                    List <DBTStkMinuteEntity> lst_data = null;
                    while ((lst_data = page.Retrieve(++pageno)).Count > 0)
                    {
                        lst_data.ForEach(data =>
                        {
                            if (!HourLine.IsReady)
                            {
                                HourLine.Initialize(data.Time);
                            }

                            HourLine.Add(new KeyValuePair <DateTime, decimal>(data.Time, data.Close));
                        });
                    }
                }
            }
            if (!HourLine.IsReady)
            {
                HourLine.Initialize(DateTime.Now);
            }

            LinesController.AddTimeLine(LineType.HOUR, HourLine);
            LinesController.AddTimeLine(LineType.DAILY, DailyLine);
            LinesController.AddTimeLine(LineType.WEEKLY, WeeklyLine);

            logger.Write(TYPE.INFO, string.Format("HL5:{0}, HL10:{1}, HL30:{2}", HourLine.Lines.Find(l => l.ID == LINE.HOUR5).Value, HourLine.Lines.Find(l => l.ID == LINE.HOUR10).Value, HourLine.Lines.Find(l => l.ID == LINE.HOUR30).Value));
            logger.Write(TYPE.INFO, string.Format("DL5:{0}, DL10:{1}, DL30:{2}", DailyLine.Lines.Find(l => l.ID == LINE.DAILY5).Value, DailyLine.Lines.Find(l => l.ID == LINE.DAILY10).Value, DailyLine.Lines.Find(l => l.ID == LINE.DAILY30).Value));
            logger.Write(TYPE.INFO, string.Format("WL5:{0}, WL10:{1}, WL30:{2}", WeeklyLine.Lines.Find(l => l.ID == LINE.WEEKLY5).Value, WeeklyLine.Lines.Find(l => l.ID == LINE.WEEKLY10).Value, WeeklyLine.Lines.Find(l => l.ID == LINE.WEEKLY30).Value));

            return;
        }
示例#11
0
 protected override void Stopped(RESULT status, string message)
 {
     LinesController.ClearLines();
     Balancer.Reset();
     base.Stopped(status, message);
 }
示例#12
0
 private void BreakOut(EventArg evnt)
 {
     this.logger.Write(TYPE.INFO, string.Format("BreakOut:({0})", evnt.ToString()));
     Need2Trade(evnt);
     LinesController.Reset();
 }