protected override void OnStart(string[] args)
        {
            IDictionary <string, Object> paramMap = new Dictionary <string, Object>();

            paramMap[Constants.Context.PROVIDER_URL] =
                "t3://" + topicHost + ":" + topicPort;

            IContext context = ContextFactory.CreateContext(paramMap);


            IConnectionFactory cf = context.LookupConnectionFactory(connectionFactoryName);

            IQueue queue = (IQueue)context.LookupDestination(topicName);

            IConnection connection = cf.CreateConnection();

            connection.ClientID = "MetricService";

            connection.Start();
            ISession consumerSession = connection.CreateSession(
                Constants.SessionMode.AUTO_ACKNOWLEDGE);

            IMessageConsumer consumer = consumerSession.CreateConsumer(queue);


            consumer.Message += new MessageEventHandler(OnMessage);


            log.WriteEntry("Service started");
            var _context = new RawMetricsContext(true);

            dao = new RawMetricsDAO(_context);


            _thread              = new Thread(KeepAlive);
            _thread.Name         = "My Worker Thread";
            _thread.IsBackground = true;
            _thread.Start();
        }
Example #2
0
        public async Task <List <CalculatedMetricsModel> > generateCalculatedMetrics()
        {
            RawMetricsContext context       = new RawMetricsContext(true);
            RawMetricsDAO     rawMetricsDAO = new RawMetricsDAO(context);

            // If we are on monday, we look for the rawdata of the week
            List <RawMetric> rawMetrics = new List <RawMetric>();
            // Otherwise, we look for  the rawdata of the previous 24h
            DateTime dateOfTheDay = new DateTime();

            if (dateOfTheDay.DayOfWeek == DayOfWeek.Monday)
            {
                dateOfTheDay = DateTime.Now;
                rawMetrics   =
                    await rawMetricsDAO.GetMetricsInPeriodASC(DateTimeToUnixLong(dateOfTheDay.AddDays(-7)), DateTimeToUnixLong(dateOfTheDay));
            }
            else
            {
                rawMetrics =
                    await rawMetricsDAO.GetMetricsInPeriodASC(DateTimeToUnixLong(dateOfTheDay.AddDays(-1)), DateTimeToUnixLong(dateOfTheDay));
            }
            return(Calculation(rawMetrics));
        }
        public RawMetricsService()
        {
            var _context = new RawMetricsContext(true);

            _dao = new RawMetricsDAO(_context);
        }