Example #1
0
        public async void ProcessRequest(HttpContext context)
        {
            //validate query parameters
            QueryParams queryParams;
            try
            {
                queryParams = new QueryParams(context.Request);
            }
            catch
            {
                context.Response.StatusCode = 400; //bad request
                return;
            }

            //convert query parameters to entities            
            var ctx = new DiscCtx(ConfigManager.ConnStr);
            var reportParams = queryParams.Materialize(ctx);
            if (reportParams == null)
            {
                context.Response.StatusCode = 400;
                return;
            }

            var screenshotClient = new ReportingPhotonClient();
            var reportingTasks = screenshotClient.StartReportingActivities(reportParams.Topic,
                                                                           reportParams.Discussion,
                                                                           reportParams.Session);
            var complexReportTask = reportingTasks.Item2;

            //compute and set report parameters 
            var report = new Report
                {
                    QueryParams = queryParams,
                    ReportParams = reportParams,
                    Participants = Helpers.ParticipantsTuples(reportParams.Topic, reportParams.Session),
                    ComplexReport  = await complexReportTask,
                    ReportUrl = context.Request.Url.ToString(),
                    BaseUrl = Helpers.BaseUrl(context.Request)
                };

            var screenshotTask = reportingTasks.Item1;
            report.ReceiveScreenshots(await screenshotTask, context);

            var cleanupTimer = new Timer(10*60*1000); //10 minutes
            cleanupTimer.Elapsed += (sender, args) =>
                {
                    cleanupTimer.Dispose();
                    report.Dispose();
                    screenshotClient.Dispose();
                };   
           cleanupTimer.Start();

           context.Response.Write(report.TransformText());
        }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            //validate query parameters
            QueryParams queryParams;
            try
            {
                queryParams = new QueryParams(context.Request);
            }
            catch
            {
                context.Response.StatusCode = 400; //bad request
                return;
            }

            //convert query parameters to entities            
            _ctx = new DiscCtx(ConfigManager.ConnStr);
            var reportParams = queryParams.Materialize(_ctx);
            if (reportParams == null)
            {
                context.Response.StatusCode = 400;
                return;
            }

            _screenshotClient = new ReportingPhotonClient();
            var reportingTasks = _screenshotClient.StartReportingActivities(
                reportParams.Topic,
                reportParams.Discussion,
                reportParams.Session,
                _ctx);

            //blocking wait
            //var r1 = reportingTasks.ScreenshotsTask.Result;  
            //var r2 = reportingTasks.ReportTask.Result;  

            //compute and set report parameters 
            _report = new Report
            {
                QueryParams = queryParams,
                ReportParams = reportParams,
                Participants = Helpers.ParticipantsTuples(reportParams.Topic, reportParams.Session),
                ComplexReport = reportingTasks.ReportTask.Result,
                ReportUrl = context.Request.Url.ToString(),
                BaseUrl = Helpers.BaseUrl(context.Request)
            };

            _report.ReceiveScreenshots(reportingTasks.ScreenshotsTask.Result, context);

            _cleanupTimer = new Timer(5 * 60 * 1000); //5 minutes
            _cleanupTimer.Elapsed += CleanupTimerOnElapsed;
            _cleanupTimer.Start();

            context.Response.Write(_report.TransformText());
        }
Example #3
0
        private void CleanupTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            _cleanupTimer.Elapsed -= CleanupTimerOnElapsed;
            if (_report != null)
            {
                _report.Dispose();
                _report = null;
            }
            if (_screenshotClient != null)
            {
                _screenshotClient.Dispose();
                _screenshotClient = null;
            }
            if (_ctx != null)
            {
                _ctx.Dispose();
                _ctx = null;
            }

            _cleanupTimer.Dispose();
            _cleanupTimer = null;
        }