예제 #1
0
 void Show(DateTime? dateStart) {
   var ticks = ForexStorage.UseForexContext(c => {
     var period = BarPeriod;
     var pair = PairCurrent;
     if (string.IsNullOrWhiteSpace(PairCurrent)) throw new Exception("Piar is empty.");
     var q = c.t_Bar.Where(b => b.Period == period && b.Pair == pair && b.StartDateLocal < DateStart.Value).OrderByDescending(b => b.StartDate).Take(DateLength / 2);
     if( !dateStart.HasValue)dateStart = q.Min(b => b.StartDateLocal);
     return c.t_Bar.Where(b => b.Period == period && b.Pair == pair && b.StartDateLocal >= dateStart)
       .Take(DateLength).OrderBy(b => b.StartDate)
       .Select(b => new DatePoint() { X = b.StartDateLocal.Value, Y = (b.AskClose + b.AskOpen) / 2 })
       .ToArray();
   }, (c, e) => LogMessage.Send(e));
   AddTicks(ticks);
   var newsStart = ticks[0].X;
   var newsEnd = ticks.Last().X;
   var news = ForexStorage.UseForexContext(
     c => c.Event__News.Where(ne => ne.Time >= newsStart && ne.Time <= newsEnd).ToArray(),
     (c, exc) => LogMessage.Send(exc));
   NewsEvents.Except(news, _newsEventComparer).ToList().ForEach(ne => NewsEvents.Remove(ne));
   NewsEvents.AddRange(news.Except(NewsEvents, _newsEventComparer));
   NewsEvents.Sort(new Comparison<Event__News>(_newsEventComparicon));
   //NewsEventCurrent = NewsEvents.FirstOrDefault(CompareNewsEvents);
   DrawVertivalLines(new DateTime[0]);
   DrawVertivalLines(news.Select(ne => ne.Time.DateTime).ToArray());
 }
예제 #2
0
        public void loadText()
        {
            newsEvents = new NewsEvents();

            List <string> newsEventsID         = new List <string>();
            List <string> newsEventsTitle      = new List <string>();
            List <string> newsEventsDesc       = new List <string>();
            List <string> newsEventsDatePosted = new List <string>();

            string sqlCommand = "SELECT newsEventsID, newsEventsTitle, newsEventsDesc, newsEventsDatePosted FROM NewsEvents;";

            using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionString"].ConnectionString))
            {
                SqlCommand command = new SqlCommand(sqlCommand, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    newsEventsID.Add(reader["newsEventsID"].ToString());
                    newsEventsTitle.Add(reader["newsEventsTitle"].ToString());
                    newsEventsDesc.Add(reader["newsEventsDesc"].ToString());
                    newsEventsDatePosted.Add(reader["newsEventsDatePosted"].ToString());
                }
                newsEvents.newsEventsID         = newsEventsID;
                newsEvents.newsEventsTitle      = newsEventsTitle;
                newsEvents.newsEventsDesc       = newsEventsDesc;
                newsEvents.newsEventsDatePosted = newsEventsDatePosted;
            }
        }
예제 #3
0
        public void CanChangeNewsEventDate()
        {
            //Arrange
            var n = new NewsEvents();

            //Act
            n.Date = new DateTime(2016, 1, 3);

            //Assert
            Assert.Equal(new DateTime(2016, 1, 3), n.Date);
        }
예제 #4
0
        public void NewsEventDateIsValid()
        {
            //Arrange
            var n = new NewsEvents();

            //Act
            //n.Date = new DateTime(2018, 12, 12);

            //Assert
            Exception ex = Assert.Throws <Exception>(() => n.Date = new DateTime(2018, 1, 1));

            Assert.Equal("Can not set to future date.", ex.Message);
        }
예제 #5
0
        public void CanChangeNewsEventStory()
        {
            //Arrange
            var n = new NewsEvents {
                Story = "Test"
            };

            //Act
            n.Story = "New Name";

            //Assert
            Assert.Equal("New Name", n.Story);
        }
예제 #6
0
        public void CanChangeNewsEventTitle()
        {
            //Arrange
            var n = new NewsEvents {
                Title = "Test"
            };

            //Act
            n.Title = "New Name";

            //Assert
            Assert.Equal("New Name", n.Title);
        }
예제 #7
0
        public void NewsEventStoryCantBeBlank()
        {
            //Arrange
            NewsEvents n = new NewsEvents {
                Story = "Test"
            };

            //Act
            // n.Story = "";

            //Assert
            Exception ex = Assert.Throws <Exception>(() => n.Story = "");

            Assert.Equal("Can't post empty story.", ex.Message);
        }
        // GET: /<controller>/
        public IActionResult Index()
        {
            List <NewsEvents> leads = new List <NewsEvents>();

            NewsEvents bigfoot = new NewsEvents();

            bigfoot.Title = "Another Bigfoot Sighting!";
            bigfoot.Date  = new DateTime(2017, 1, 15);
            bigfoot.Story = "Mrs. Fletcher was walking her dog pickles on the river side path when pickles stopped in her tracks and began urinating.  Mrs. Fletcher looked down in bewilderment.  Pickles on a normal day has great control of her blatter.  It was then that a crack of a branch in distance stirred Mrs. Fletcher's attention.  A large animal was walking on it's hind legs!";
            leads.Add(bigfoot);
            NewsEvents chickens = new NewsEvents();

            chickens.Title = "Only One Remains";
            chickens.Date  = new DateTime(2017, 1, 16);
            chickens.Story = "Little Billy Briggs entered the chicken coop yesterday morning only to find one chicken.  The rest have mysteriously disappered.  Billy checked each of the hens sleeping quarters finding no chicken or egg.  The family would have to split the one egg Billy did find under Bertha their only ckicken.  The Briggs were all a little grouchy by the afternoon.";
            leads.Add(chickens);

            return(View(leads.ToList()));
        }
        public ActionResult Edit(NewsEvents ne)
        {
            if (ModelState.IsValid)
            {
                var dao = new NewsEventDAO();

                var result = dao.Update(ne);
                if (result)
                {
                    ModelState.AddModelError("Cập nhật thành công", "success");
                    return(RedirectToAction("Index", "NewsEvent"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật không thành công");
                }
            }
            SetViewBag(ne.TypeCourseID);
            return(View());
        }
        public ActionResult Create(NewsEvents ne)
        {
            if (ModelState.IsValid)
            {
                var dao = new NewsEventDAO();

                long id = dao.Insert(ne);
                if (id > 0)
                {
                    ModelState.AddModelError("Thêm thành công", "success");
                    return(RedirectToAction("Index", "NewsEvent"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm không thành công");
                }
            }
            SetViewBag();
            return(View());
        }
예제 #11
0
        public bool Update(NewsEvents entity)
        {
            try
            {
                var ne = db.NewsEvents.Find(entity.NewsEventsID);
                ne.Type         = entity.Type;
                ne.Title        = entity.Title;
                ne.Content      = entity.Content;
                ne.TypeCourseID = entity.TypeCourseID;
                ne.UrlImg       = entity.UrlImg;
                ne.CreatedDate  = entity.CreatedDate;
                ne.MetaKeywords = entity.MetaKeywords;

                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                //logging
                return(false);
            }
        }
예제 #12
0
    public CharterSnapshotControl() {
      InitializeComponent();

      this.SizeChanged += (s, e) => FitToView();

      MessageBus.Current.Listen<HedgeHog.NewsCaster.NewsEvent>("Snapshot")
        .Throttle(1.FromSeconds(),DispatcherScheduler.Current)
        .Where(ne => VisualParent != null)
        .Subscribe(ne => {
          try {
            var monthOffset = 3;
            var dateStart = ne.Time.AddMonths(-monthOffset*2);
            var dateEnd = ne.Time.AddDays(-1);
            ReadNewsEventsHistoryFromDB(ne.Country, ne.Name, dateStart, dateEnd);
            NewsHistoryCurrent = NewsEventHistory.First();
            NewsEventCurrent = NewsEvents.FirstOrDefault(n => n.Country == ne.Country && n.Name == ne.Name);
            DateStart = NewsEventHistory.First().Time.DateTime;
            Show();
          } catch (Exception exc) { LogMessage.Send(exc); }
        });

      Pairs.AddRange(ForexStorage.UseForexContext(c => c.v_Pair.ToArray(), (c, ex) => LogMessage.Send(ex)));
      otherVLines.Changing.ObserveOnDispatcher()
        .Subscribe(ev => {
          switch (ev.Action) {
            case NotifyCollectionChangedAction.Reset:
            case NotifyCollectionChangedAction.Remove:
              try {
                ev.OldItems.Cast<IPlotterElement>().ToList().ForEach(vl => plotter.Children.Remove(vl));
              } catch (Exception exc) {
                LogMessage.Send(exc);
              }
              return;
            case NotifyCollectionChangedAction.Add:
              ev.NewItems.Cast<VerticalLine>().ForEach(vl => plotter.Children.Add(vl));
              return;
          }
        });
      DispatcherScheduler.Current.Schedule(1.FromSeconds(), () => {
        Event__News newsEventPrev = null;
        this.ObservableForProperty(me => me.NewsEventCurrent, ne => ne).Subscribe(ne => {
          try {
            if (ne == null || CompareNewsEvents(ne, newsEventPrev)) return;
            newsEventPrev = ne;
            DateStart = ne.Time.DateTime;
            Show();
            var monthOffset = 3;
            var dateStart = ne.Time.AddMonths(-monthOffset);
            var dateEnd = ne.Time.AddMonths(monthOffset);
            ReadNewsEventsHistoryFromDB(ne.Country, ne.Name, dateStart, dateEnd);
            NewsHistoryCurrent = NewsEventHistory.FirstOrDefault(n =>
              n.Country == NewsEventCurrent.Country && n.Name == NewsHistoryCurrent.Name && n.Time == NewsEventCurrent.Time);
          } catch (Exception ex) { LogMessage.Send(ex); }
        }, ex => LogMessage.Send(ex), () => LogMessage.Send("Done with NewsEventCurrent."));

        this.ObservableForProperty(me => me.NewsHistoryCurrent, nh => nh).Subscribe(nh => {
          try {
            if (nh == null || CompareNewsEvents(NewsEventCurrent, nh)) return;
            DateStart = nh.Time.DateTime;
            Show();
            var newsEvent = NewsEvents.SingleOrDefault(ne => ne.Country == nh.Country && ne.Name == nh.Name);
            if (newsEvent != null)
              NewsEventCurrent = newsEventPrev = newsEvent;
          } catch (Exception ex) { LogMessage.Send(ex); }
        });

        this.ObservableForProperty(me => me.PairCurrent).Subscribe(oc => Show());
      });
    }
예제 #13
0
 public long Insert(NewsEvents entity)
 {
     db.NewsEvents.Add(entity);
     db.SaveChanges();
     return(entity.NewsEventsID);
 }