Example #1
0
        /// <summary>
        /// Inserts new record into db
        /// </summary>
        public bool InsertNewRecord()
        {
            CanonDataContext db = Cdb.Instance;

            //check if name is not started with stop words from FeedProductExceptions
            List <FeedProductException> flist = db.FeedProductExceptions.ToList();

            foreach (FeedProductException fpe in flist)
            {
                if (this.ProductName.ToUpper().StartsWith(fpe.StopWord))
                {
                    return(false);
                }
            }

            ChannelMonitor rec = new ChannelMonitor();

            rec.ChannelId   = this.ChannelId;
            rec.ImportDate  = DateTime.Now;
            rec.Price       = this.Price;
            rec.PriceVat    = this.PriceVat;
            rec.ProductDesc = Utilities.TruncateString(this.ProductDesc, 1000);
            rec.ProductName = Utilities.TruncateString(this.ProductName, 1000);
            rec.ProductUrl  = Utilities.TruncateString(this.ProductUrl, 1000);
            rec.Vat         = this.Vat;

            //Check price is changed !!! BEFORE submit
            this.CheckIfPriceIsChanged(this.ChannelId, rec.ProductName, rec.ProductUrl, rec.PriceVat);

            db.ChannelMonitors.InsertOnSubmit(rec);
            db.SubmitChanges();
            return(true);
        }
Example #2
0
        /// <summary>
        /// Inserts new record into db
        /// </summary>
        public bool InsertNewRecord()
        {
            CanonDataContext db = Cdb.Instance;

            //check if name is not started with stop words from FeedProductExceptions
            List<FeedProductException> flist = db.FeedProductExceptions.ToList();
            foreach(FeedProductException fpe in flist)
                if (this.ProductName.ToUpper().StartsWith(fpe.StopWord))
                    return false;

            ChannelMonitor rec = new ChannelMonitor();
            rec.ChannelId = this.ChannelId;
            rec.ImportDate = DateTime.Now;
            rec.Price = this.Price;
            rec.PriceVat = this.PriceVat;
            rec.ProductDesc = Utilities.TruncateString(this.ProductDesc, 1000);
            rec.ProductName = Utilities.TruncateString(this.ProductName, 1000);
            rec.ProductUrl = Utilities.TruncateString(this.ProductUrl, 1000);
            rec.Vat = this.Vat;

            //Check price is changed !!! BEFORE submit
            this.CheckIfPriceIsChanged(this.ChannelId, rec.ProductName, rec.ProductUrl, rec.PriceVat);

            db.ChannelMonitors.InsertOnSubmit(rec);
            db.SubmitChanges();
            return true;
        }
Example #3
0
 /// <summary>
 /// 在IO监视器上显示byte[]数据
 /// </summary>
 /// <param name="dataOrientation"></param>
 /// <param name="data"></param>
 public void ChannelMonitorData(DataOrientation dataOrientation, byte[] data)
 {
     if (IsChannelMonitor)
     {
         if (ChannelMonitor != null)
         {
             ChannelMonitor.DataMonitor(dataOrientation, data);
         }
     }
 }
Example #4
0
        public static decimal?GetCurrentMapPrice(int channelId, string monitoredName, string monitoredUrl)
        {
            CanonDataContext db = Cdb.Instance;
            ChannelMonitor   cm = db.ChannelMonitors.Where(c => c.ChannelId == channelId &&
                                                           c.ProductName == monitoredName &&
                                                           c.ProductUrl == monitoredUrl).OrderByDescending(
                m => m.ImportDate).FirstOrDefault();

            if (cm != null)
            {
                return(cm.PriceVat);
            }
            return(null);
        }
Example #5
0
        public bool Start(HostControl hostControl)
        {
            var runtime = _config.GetConfigSection("HareShowRuntimeSettings/EventTrigger");

            // TODO: get start datetime from app.config
            DateTime startDateTime;

            if (string.IsNullOrWhiteSpace(runtime.Get("startDateTime")))
            {
                startDateTime = DateTime.Now;
            }
            else
            {
                if (!DateTime.TryParse(runtime.Get("startDateTime"), out startDateTime))
                {
                    // TODO: if the start datetime is bad then throw an exception here
                }
            }

            // TODO: get interval from app.config
            TimeSpan interval;

            if (!TimeSpan.TryParse(runtime.Get("runInterval"), out interval))
            {
                // TODO: if the interval time is bad then throw an exception here
            }

            // TODO: get username and password from app.config
            var hareDuCredentials = _config.GetConfigSection("HareDuSettings/Login");

            if (string.IsNullOrWhiteSpace(hareDuCredentials.Get("username")) ||
                string.IsNullOrWhiteSpace(hareDuCredentials.Get("password")))
            {
                throw new UserCredentialsInvalidException("Not able to connect to RabbitMQ because username or password is invalid.");
            }

            string username = hareDuCredentials.Get("username");
            string password = hareDuCredentials.Get("password");

            _scheduler.Schedule <ChannelMonitorJob>(Guid.NewGuid(), new DateTimeOffset(startDateTime), interval, username, password);
            var monitor  = new ChannelMonitor(_client);
            var security = new SecurityImpl();

            _scheduler.JobFactory = new HareShowJobFactory <IChannelMonitor, ISecurity, ChannelMonitorJob>(monitor, security);
            _scheduler.Start();

            return(true);
        }
Example #6
0
        public void CleanNotExistingProducts()
        {
            CanonDataContext   db    = Cdb.Instance;
            List <MappingRule> rules = db.MappingRules.Where(c => c.ChannelId == this._channelId).ToList();

            foreach (MappingRule rule in rules)
            {
                ChannelMonitor cm = db.ChannelMonitors.FirstOrDefault(c => c.ProductName == rule.MonitoredName &&
                                                                      c.ProductUrl == rule.MonitoredUrl);
                if (cm == null)
                {
                    db.MappingRules.DeleteOnSubmit(rule);
                    db.SubmitChanges();
                }
            }
        }
Example #7
0
        private static void Main()
        {
            var appSettings = GetAppStore(APP_PREFIX).Load();
            var userStore   = GetUserStore(FILENAME);

            var loader     = new DefaultTokenLoader(appSettings, userStore);
            var authorizer = new ConsoleAuthorizer(appSettings);

            var safeLoader     = new AuthorizingTokenLoader(loader, authorizer, userStore);
            var tokens         = safeLoader.Load();
            var channel        = new TwitterChannel(tokens);
            var channelAdapter = new TwitterChannelAdapter(channel, new NullAccountRepository());

            var interpreter = new Interpreter(new FakeCommandParser());
            var monitor     = new ChannelMonitor(interpreter);

            Console.WriteLine("Monitoring...");
            monitor.Monitor(channelAdapter);
            Console.ReadLine();
        }
        public void SetUp()
        {
            interpreter = new Mock <Executable>();

            sut = new ChannelMonitor(interpreter.Object);
        }