コード例 #1
0
        private DataTableResponse FetchDatabaseCheckGridData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var grid = svc.DatabaseDetails(viewModel.GridConditions, viewModel.DatabaseFilterConditions, viewModel.DatabaseFilterOperands);

            var aaDataRel = grid.Data.Select(d => new String[] {
                d.ServerName, d.SQLVersion, d.AdHocWorkLoad.ToString(), d.MaxServerMemory.ToString("f2"),
                d.MaxDegreeOfParallelism.ToString(), d.TempDBDataFiles.ToString(), d.LastSQLRestart.ToString("MMM dd, yyyy")
            }).ToArray();

            var data = new FilterResult()
            {
                Data = aaDataRel, TotalRecordCount = grid.Count
            };

            var dtResponse = new DataTableResponse()
            {
                sEcho = string.IsNullOrEmpty(viewModel.GridConditions.sEcho)
                                        ? "1"
                                        : viewModel.GridConditions.sEcho,
                aaData          = data.Data,
                recordsTotal    = data.Data.Count(),
                recordsFiltered = data.TotalRecordCount
            };

            return(dtResponse);
        }
コード例 #2
0
 public void SetUp()
 {
     this.environmentCheckRepository = new Mock <IEnvironmentCheckRepository>();
     this.sqlServerRepository        = new Mock <ISqlServerRepository>();
     this.sqlServerRepository.SetupGet(r => r.EnvironmentCheckRepository).Returns(this.environmentCheckRepository.Object);
     this.service = new EnvironmentCheckService(this.sqlServerRepository.Object);
 }
コード例 #3
0
        private string FetchFileDatabaseData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var grid = svc.DatabaseDetails(viewModel.GridConditions, viewModel.DatabaseFilterConditions, viewModel.DatabaseFilterOperands);

            var aaDataRel = grid.Data.Select(d => new String[] {
                d.ServerName, d.SQLVersion, d.AdHocWorkLoad.ToString(), d.MaxServerMemory.ToString("f2"),
                d.MaxDegreeOfParallelism.ToString(), d.TempDBDataFiles.ToString(), d.LastSQLRestart.ToString("MMM dd, yyyy")
            }).ToArray();

            var filterResult = new FilterResult()
            {
                Data = aaDataRel, TotalRecordCount = grid.Count
            };

            using (var sw = new System.IO.StringWriter())
            {
                var heaaderArr = new string[]
                {
                    "Server Name", "SQL Version", "Ad Hoc Workload", "Max Server Memory (GB)", "Max Degree of Parallelism", "TempDB Data Files", "Last SQL Restart",
                };
                sw.WriteLine(string.Join(",", heaaderArr));
                foreach (var row in filterResult.Data)
                {
                    sw.WriteCsvSafeLine(row);
                }
                return(sw.ToString());
            }
        }
コード例 #4
0
        private DataTableResponse FetchServerCheckGridData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var grid = svc.ServerDetails(viewModel.GridConditions, viewModel.ServerFilterConditions, viewModel.ServerFilterOperands);

            var aaDataRel = grid.Data.Select(d => new String[] {
                d.ServerName, d.OSName, d.OSVersion, d.LogicalProcessors.ToString(), d.Hyperthreaded.ToString(),
            }).ToArray();

            var data = new FilterResult()
            {
                Data = aaDataRel, TotalRecordCount = grid.Count
            };

            var dtResponse = new DataTableResponse()
            {
                sEcho = string.IsNullOrEmpty(viewModel.GridConditions.sEcho)
                                        ? "1"
                                        : viewModel.GridConditions.sEcho,
                aaData          = data.Data,
                recordsTotal    = data.Data.Count(),
                recordsFiltered = data.TotalRecordCount
            };

            return(dtResponse);
        }
コード例 #5
0
        private string FetchFileServerData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var grid = svc.ServerDetails(viewModel.GridConditions, viewModel.ServerFilterConditions, viewModel.ServerFilterOperands);

            var aaDataRel = grid.Data.Select(d => new String[] {
                d.ServerName, d.OSName, d.OSVersion, d.LogicalProcessors.ToString(), d.Hyperthreaded.ToString(),
            }).ToArray();

            var filterResult = new FilterResult()
            {
                Data = aaDataRel, TotalRecordCount = grid.Count
            };

            using (var sw = new System.IO.StringWriter())
            {
                var heaaderArr = new string[]
                {
                    "Server Name", "Operating System Name", "Operating System Version", "Logical Processors", "Hyperthreaded",
                };
                sw.WriteLine(string.Join(",", heaaderArr));
                foreach (var row in filterResult.Data)
                {
                    sw.WriteCsvSafeLine(row);
                }
                return(sw.ToString());
            }
        }
コード例 #6
0
        public HttpResponseMessage ResetTuningForkLastRun(Boolean config)
        {
            var connectionFactory = new HelperConnectionFactory(ConnectionHelper.Helper());
            var sqlRepo           = new SqlServerRepository(connectionFactory);
            var svc = new EnvironmentCheckService(sqlRepo);

            //get data
            DateTime lastRunTime;

            if (config)
            {
                lastRunTime = svc.ResetTuningForkLastRun(ProcessControlId.EnvironmentCheckRelativityConfig, ProcessControlId.EnvironmentCheckSqlConfig);
            }
            else
            {
                lastRunTime = svc.ResetTuningForkLastRun(ProcessControlId.EnvironmentCheckServerInfo);
            }

            //Serialize response
            var json     = lastRunTime.ToJson();
            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
            return(response);
        }
コード例 #7
0
        private FilterResult FilterRecommendationData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var grid = svc.Recommendations(viewModel.GridConditions, viewModel.RecommendationFilterConditions);

            var aaDataRel = grid.Data.Select(d => new String[] {
                d.Status, d.Scope, d.Section, d.Name, d.Description, d.Value, d.Recommendation
            }).ToArray();

            return(new FilterResult()
            {
                Data = aaDataRel, TotalRecordCount = grid.Count
            });
        }
コード例 #8
0
        public HttpResponseMessage GenerateCSV()
        {
            //Initialize service and model properties
            var connectionFactory = new HelperConnectionFactory(ConnectionHelper.Helper());
            var sqlRepo           = new SqlServerRepository(connectionFactory);
            var svc   = new EnvironmentCheckService(sqlRepo);
            var model = PopulateModelSettings();

            model.GridConditions.StartRow = 1;
            model.GridConditions.EndRow   = int.MaxValue;

            //Get the data
            String fileData;

            if (model.ReportType == EnvironmentCheckReportType.Recommendations)
            {
                model = PopulateRecommendationModelSettings();
                model.GridConditions.EndRow   = 0;
                model.GridConditions.StartRow = 0;
                fileData = FetchFileRecommendationData(svc, model);
            }
            else if (model.ReportType == EnvironmentCheckReportType.Server)
            {
                model = PopulateServerModelSettings();
                model.GridConditions.EndRow   = 0;
                model.GridConditions.StartRow = 0;
                fileData = FetchFileServerData(svc, model);
            }
            else if (model.ReportType == EnvironmentCheckReportType.Database)
            {
                model = PopulateDatabaseModelSettings();
                model.GridConditions.EndRow   = 0;
                model.GridConditions.StartRow = 0;
                fileData = FetchFileDatabaseData(svc, model);
            }
            else
            {
                throw new Exception("Invalid report type.");
            }

            //Serialize response
            HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

            message.Content = new StringContent(fileData);
            message.Content.Headers.ContentType                 = new System.Net.Http.Headers.MediaTypeHeaderValue("text/csv");
            message.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            message.Content.Headers.ContentDisposition.FileName = string.Format("EnvironmentCheck-{0}.csv", DateTime.Now.ToString("yyyyMMdd-HHmmss"));
            return(message);
        }
コード例 #9
0
        /// <summary>
        /// Translates a recommendation view into grid data
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private DataTableResponse FetchRecommendationCheckGridData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var data       = FilterRecommendationData(svc, viewModel);
            var dtResponse = new DataTableResponse()
            {
                sEcho = string.IsNullOrEmpty(viewModel.GridConditions.sEcho)
                                        ? "1"
                                        : viewModel.GridConditions.sEcho,
                aaData          = data.Data,
                recordsTotal    = data.Data.Count(),
                recordsFiltered = data.TotalRecordCount
            };

            return(dtResponse);
        }
コード例 #10
0
        private string FetchFileRecommendationData(EnvironmentCheckService svc, EnvironmentCheckViewModel viewModel)
        {
            var filterResult = FilterRecommendationData(svc, viewModel);

            using (var sw = new System.IO.StringWriter())
            {
                var heaaderArr = new string[]
                {
                    "Status", "Scope", "Section", "Name", "Description", "Value", "Recommendation",
                };
                sw.WriteLine(string.Join(",", heaaderArr));
                foreach (var row in filterResult.Data)
                {
                    sw.WriteCsvSafeLine(row);
                }
                return(sw.ToString());
            }
        }
コード例 #11
0
        public HttpResponseMessage DatabaseInfo()
        {
            //Initialize service and model properties
            var connectionFactory = new HelperConnectionFactory(ConnectionHelper.Helper());
            var sqlRepo           = new SqlServerRepository(connectionFactory);
            var svc   = new EnvironmentCheckService(sqlRepo);
            var model = PopulateDatabaseModelSettings();

            var session = (HttpSessionState)GetSession();

            session[DataTableSessionConstants.UptimeState] = model;

            //Get the data
            var dtResponse = FetchDatabaseCheckGridData(svc, model);

            //Serialize response
            var json     = dtResponse.ToJson();
            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
            return(response);
        }