Ejemplo n.º 1
0
        public SettingsPanel()
        {
            settingsPanel = new StackLayout();
            contentRoot   = new ArrayList();
            data          = new DataStore.DataStore();

            this.Margin            = 0;
            this.Padding           = 0;
            this.WidthRequest      = 300;
            this.HorizontalOptions = LayoutOptions.FillAndExpand;
            this.VerticalOptions   = LayoutOptions.FillAndExpand;
            this.Content           = settingsPanel;

            settingsPanel.Margin            = new Thickness(0, 15, 0, 0);
            settingsPanel.Padding           = 0;
            settingsPanel.HorizontalOptions = LayoutOptions.FillAndExpand;
            settingsPanel.VerticalOptions   = LayoutOptions.FillAndExpand;
        }
Ejemplo n.º 2
0
        /////////////////////////////////////////////////////////////
        /// <summary>
        /// Check current report queue and request and report data
        /// </summary>
        public void ProcessReportQueue()
        {
            using (var ctx = new Entities())
            {
                var process_status = RequestStatus.Pending.ToString();

                var tasks = ctx.REPORTPROJECTREQUESTs.Where(r => r.STATUS == process_status).ToList();

                foreach (var task in tasks)
                {
                    Audit.Log(ctx, AuditType.TaskManager, string.Format("Getting data for task {0}", task.ID), 0);

                    var task_id = task.ID;
                    task.STATUS = RequestStatus.InProgress.ToString();

                    // get report
                    var report = ctx.REPORTs.FirstOrDefault(r => r.ID == task.REPORTID);
                    report.REQUESTSTATUS = RequestStatus.InProgress.ToString();
                    ctx.SaveChanges();

                    var report_id = report.ID;

                    // get project
                    var project = ctx.PROJECTs.FirstOrDefault(p => p.ID == task.PROJECTID);

                    // get fields
                    var report_field_ids = ctx.VWREPORTFIELDs.Where(u => u.REPORTID == task.REPORTID).Select(u => u.ID).ToList();

                    var project_fields = ctx.PROJECTFIELDs.Where(f => f.PROJECTID == project.ID && report_field_ids.Contains(f.FIELDID.Value));

                    // get sites
                    var report_site_ids = ctx.VWREPORTSITEs.Where(u => u.REPORTID == task.REPORTID).Select(u => u.ID).ToList();

                    var project_sites = ctx.PROJECTSITEs.Where(s => s.PROJECTID == project.ID && report_site_ids.Contains(s.SITEID.Value));

                    // call API and get data
                    var client = new encoreSoapClient("encoreSoap", project.APIURL);

                    var data_store = new DataStore.DataStore(ConfigurationSettings.AppSettings["datastore_path"]);

                    try
                    {
                        var project_field_source_ids = project_fields.Select(f => f.SOURCEID).ToList();
                        var project_sites_source_ids = project_sites.Select(s => s.SOURCEID).ToList();

                        client.BeginGetData(
                            project_field_source_ids.Select(int.Parse).ToArray(),
                            project_sites_source_ids.Select(int.Parse).ToArray(),
                            report.REPORTDATEFROM,
                            report.REPORTDATETO,
                            result =>
                        {
                            var response = client.EndGetData(result);

                            //  populate data store
                            var data_rows = response.Rows.Select(row => new DataRow
                            {
                                ReportID    = report_id,
                                RowDateTime = row.RowDate,
                                SiteID      = row.SiteID,
                                Fields      = row.Values.Select(r => r.FieldID).ToList(),
                                Values      = row.Values.Select(r => r.Value).ToList()
                            }).ToList();

                            data_store.Store(data_rows);

                            using (var entities = new Entities())
                            {
                                var this_task    = entities.REPORTPROJECTREQUESTs.FirstOrDefault(r => r.ID == task_id);
                                this_task.STATUS = RequestStatus.Complete.ToString();

                                // send email
                                var rpt           = entities.REPORTs.FirstOrDefault(r => r.ID == task_id);
                                rpt.REQUESTSTATUS = RequestStatus.Complete.ToString();

                                var owner = entities.SYSTEMUSERs.FirstOrDefault(s => s.ID == rpt.SYSTEMUSERID);
                                if (owner != null && !string.IsNullOrEmpty(owner.EMAIL))
                                {
                                    // send email
                                    SendReportCompelted(owner, report_id);
                                }

                                // check tasks for report
                                var report_tasks =
                                    entities.REPORTPROJECTREQUESTs.Where(r => r.REPORTID == task.REPORTID).ToList();

                                if (report_tasks.All(r => r.STATUS == RequestStatus.Complete.ToString()))
                                {
                                    var this_report =
                                        entities.REPORTs.FirstOrDefault(r => r.ID == this_task.REPORTID);
                                    this_report.REQUESTSTATUS = RequestStatus.Complete.ToString();
                                }
                                entities.SaveChanges();
                            }
                        },
                            null
                            );
                    }
                    catch (Exception ex)
                    {
                        task.STATUS = RequestStatus.Failed.ToString();
                        Audit.Log(ctx, AuditType.TaskManager, string.Format("Get Data for task {0} failed with exception: {1}", task.ID, ex.Message), 0);
                        ctx.SaveChanges();
                    }
                }
            }
        }