Exemplo n.º 1
0
        /// <summary>
        /// Internal logic of object validation.
        /// </summary>
        /// <param name="obj">The object to validate.</param>
        /// <param name="fullPath">The full object path in its structure.</param>
        /// <returns>
        /// <see cref="FullReport"/> with <c>IsValid</c> flag is set to <c>true</c>
        /// if the <paramref name="obj"/> is acceptable. Otherwise, the flag is set to <c>false</c>
        /// and <see cref="FullReport"/> contains a report of all problems.
        /// </returns>
        public override FullReport Validate(object obj, string fullPath = "")
        {
            FullReport fullReport = new FullReport(isValid: true);

            if (obj == null)
            {
                return(fullReport);
            }

            foreach (PropertyInfo prop in obj.GetType().GetProperties())
            {
                object value = prop.GetValue(obj);

                foreach (ValidationAttribute attr in prop.GetCustomAttributes <ValidationAttribute>())
                {
                    // SingleReport singleReport = attr.Validate(value);
                    var singleReport = attr.Validate(value);
                    fullReport += new SingleReport(singleReport.IsValid,
                                                   singleReport.Details != null ? $"{fullPath}.{prop.Name} : {singleReport.Details}" : null);
                }
            }

            WriteReport(fullReport);

            return(fullReport);
        }
Exemplo n.º 2
0
 private void WriteReport(FullReport fullReport)
 {
     if (fullReport != null)
     {
         foreach (string msg in fullReport.Details)
         {
             logger.Log(msg);
         }
     }
 }
        public async Task <FullReport> GetReport()
        {
            var dirPath = Path.Combine(Directory.GetCurrentDirectory(), "Report");

            if (!Directory.Exists(dirPath))
            {
                return(null);
            }

            var latestFile = new DirectoryInfo(dirPath).GetFiles().OrderByDescending(f => f.LastWriteTime).First();

            if (!System.IO.File.Exists(latestFile.FullName))
            {
                return(null);
            }

            var rawReport = await System.IO.File.ReadAllTextAsync(latestFile.FullName);

            var allValues = rawReport.Split(',');

            var result  = new FullReport();
            var reports = new List <ReportItem>();

            foreach (var a in allValues)
            {
                int   intValue   = 0;
                float floatValue = 0;

                var isInt   = int.TryParse(a, out intValue);
                var isFloat = float.TryParse(a, out floatValue);

                if (isInt)
                {
                    reports.Add(new ReportItem {
                        type = "numeric", value = a
                    });
                }
                else if (isFloat)
                {
                    reports.Add(new ReportItem {
                        type = "float", value = a
                    });
                }
                else
                {
                    reports.Add(new ReportItem {
                        type = "alphanumeric", value = a.Trim()
                    });
                }
            }

            result.fullReport = reports;

            return(result);
        }
        public IActionResult Reports(string username)
        {
            ViewData["username"] = username;
            UserManager um = new UserManager();
            long        id = um.getId(username);

            AbstractReportFactory rf = new ConcreteReportFactory();
            FullReport            fr = new FullReport(rf.createWeeklyReport(id), rf.createMonthlyReport(id));

            return(View(fr));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Get45DayBuoyData(string nbdcId)
        {
            // find requested buoy
            Buoy buoy = _context.Buoy.Single(b => b.NbdcId == nbdcId);

            // get report data for buoy
            FullReport fullReport = await Make45DayReport.GetAsync(buoy);

            // return report data
            return(Ok(fullReport));
        }
        public async Task <IActionResult> GetClosestFullReports(string lat, string lon, int spotCount)
        {
            SpotFinder spotFinder = new SpotFinder();
            BuoyFinder buoyFinder = new BuoyFinder();

            List <Buoy>            matchedBuoys       = new List <Buoy>();
            List <FullBeachReport> fullBeachReport    = new List <FullBeachReport>();
            List <FullReport>      matchedBuoyReports = new List <FullReport>();

            List <SpotDistanceFromUser> spotsWithUserDistance = spotFinder.FindSpots(lat, lon, spotCount);

            foreach (SpotDistanceFromUser obj in spotsWithUserDistance)
            {
                string      beachLat      = obj.Beach.Latitude;
                string      beachLon      = obj.Beach.Longtitude;
                List <Buoy> matchingBuoys = buoyFinder.MatchBuoys(beachLat, beachLon);
                foreach (Buoy b in matchingBuoys)
                {
                    matchedBuoys.Add(b);
                }
            }

            matchedBuoys = matchedBuoys.GroupBy(mb => mb.BuoyId).Select(mb => mb.First()).ToList();

            foreach (Buoy b in matchedBuoys)
            {
                Console.WriteLine("hello");
                FullReport fullReport = await Make45DayReport.GetAsync(b);

                Console.WriteLine("done");
                matchedBuoyReports.Add(fullReport);
            }

            foreach (SpotDistanceFromUser obj in spotsWithUserDistance)
            {
                string      beachLat      = obj.Beach.Latitude;
                string      beachLon      = obj.Beach.Longtitude;
                List <Buoy> matchingBuoys = buoyFinder.MatchBuoys(beachLat, beachLon);
                foreach (FullReport r in matchedBuoyReports)
                {
                    foreach (Buoy b in matchingBuoys)
                    {
                        if (r.NbdcId == b.NbdcId)
                        {
                            FullBeachReport report = new FullBeachReport(obj.Beach, r);
                            fullBeachReport.Add(report);
                        }
                    }
                }
            }
            return(Ok(fullBeachReport));
        }
        public void CheckIfLoggerIsWorking()
        {
            Mock <ILogger> loggerMock = new Mock <ILogger>();

            ValidationService valService = new ValidationService(loggerMock.Object);

            ValidationServiceTestEntity invalidObject = new ValidationServiceTestEntity(
                digit: -1, negativeInteger: 5, moreOneCharString: "",
                requiredObject: null, notEmptyString: "");

            FullReport result = valService.Validate(invalidObject);

            loggerMock.Verify(validator => validator.Log(It.IsAny <string>()),
                              Times.Exactly(result.Details.Count));
        }
        public void AllPropertiesAreWrong()
        {
            const int MSG_COUNT = 5;

            var logger     = new ValidationLogger();
            var valService = new ValidationService(logger);

            ValidationServiceTestEntity obj = new ValidationServiceTestEntity(
                digit: -1, negativeInteger: 5, moreOneCharString: "",
                requiredObject: null, notEmptyString: "");

            FullReport result = valService.Validate(obj);

            Assert.AreEqual(MSG_COUNT, result.Details.Count);
        }
        public async Task <IActionResult> GetClosestFullReport(string lat, string lon)
        {
            BuoyFinder             buoyFinder       = new BuoyFinder();
            SpotFinder             spotFinder       = new SpotFinder();
            Beach                  closestSpot      = spotFinder.FindSpot(lat, lon);
            List <Buoy>            matchingBuoys    = buoyFinder.MatchBuoys(closestSpot.Latitude, closestSpot.Longtitude);
            List <FullBeachReport> fullBeachReports = new List <FullBeachReport>();

            foreach (Buoy b in matchingBuoys)
            {
                FullReport fullReport = await Make45DayReport.GetAsync(b);

                FullBeachReport fullBeachReport = new FullBeachReport(closestSpot, fullReport);
                fullBeachReports.Add(fullBeachReport);
            }
            return(Ok(fullBeachReports));
        }
Exemplo n.º 10
0
        private void FullReport()
        {
            if (this.SelectedTemplate != null)
            {
                Report report = new FullReport();
                var    source = new ObjectDataSource();
                source.DataSource = typeof(MainViewModel);
                source.DataMember = "GetDataSourceReport";
                report.DataSource = source;
                var reportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };

                var reportWindow = new I_ReportViewer(this.SelectedTemplate.Name + " Full Report", reportSource, true, false, false);
                reportWindow.ShowDialog();
            }
        }
        public async Task <IActionResult> GetSingleFullReport(int spotId)
        {
            BuoyFinder  buoyFinder    = new BuoyFinder();
            Beach       beach         = _context.Beach.Single(b => b.BeachId == spotId);
            List <Buoy> matchingBuoys = buoyFinder.MatchBuoys(beach.Latitude, beach.Longtitude);

            List <FullBeachReport> fullBeachReports = new List <FullBeachReport>();

            foreach (Buoy b in matchingBuoys)
            {
                FullReport fullReport = await Make45DayReport.GetAsync(b);

                FullBeachReport fullBeachReport = new FullBeachReport(beach, fullReport);
                fullBeachReports.Add(fullBeachReport);
            }

            return(Ok(fullBeachReports));
        }
Exemplo n.º 12
0
        public static async Task <FullReport> GetAsync(Buoy buoy)
        {
            // create instance of report object, adding buoy name and id
            FullReport fullReport = new FullReport(buoy.Name, buoy.NbdcId);
            // create a list to hold the spectral report data
            List <SpecData> spectralReports = new List <SpecData>();
            // create strings that will be used to complete get request urls.
            string buoyStandardId = (buoy.NbdcId).ToUpper() + ".txt";
            string buoySpecId     = (buoy.NbdcId).ToUpper() + ".spec";
            // make async calls to retreive buoy data in string format
            string standardReportText = await GetBuoyData.FetchAsync(buoyStandardId);

            string spectralReportText = await GetBuoyData.FetchAsync(buoySpecId);

            // get first character from report strings to use as check for succesful request
            string firstCharSpec     = (spectralReportText[0]).ToString();
            string firstCharStandard = (standardReportText[0].ToString());

            // parse standard reports and store them in list
            List <StandardData> standardReports = Parse45DayStandard.Get(standardReportText, buoy.NbdcId);

            // if the first character of the string is an '<' that means the http
            // response resulted in an xml response stating no data found for url given

            // if neither request had xml...
            if (firstCharSpec != "<" && firstCharStandard != "<")
            {
                // parse spectral data make new object with entire report
                spectralReports = Parse45DaySpec.Get(spectralReportText, buoy.NbdcId);
                fullReport      = new FullReport(buoy.Name, buoy.NbdcId, standardReports, spectralReports);
            }
            // else, if the standard report contained no xml
            else if (firstCharStandard != "<")
            {
                // store parsed standard data in object with buoy name and id
                fullReport = new FullReport(buoy.Name, buoy.NbdcId, standardReports);
            }

            // return 45 day report
            return(fullReport);
        }
Exemplo n.º 13
0
        public ActionResult generate(long?userID, long?mosqueID, string from, string to, string state)
        {
            DateTime fromdate = DateTime.MinValue;
            DateTime todate   = DateTime.MaxValue;

            if (!string.IsNullOrEmpty(from))
            {
                fromdate = from.toMiladiDate();
            }
            if (!string.IsNullOrEmpty(to))
            {
                todate = to.toMiladiDate().AddDays(1);
            }
            var model = db.Clients.Where(c => c.registerDate >= fromdate && c.registerDate <= todate);

            if (userID.HasValue)
            {
                model = model.Where(c => c.userID == userID);
            }
            if (mosqueID.HasValue)
            {
                model = model.Where(c => c.mosqueID == mosqueID);
            }

            switch (state)
            {
            case "full":
                var s = model.DecodeClients();
                var m = new FullReport {
                    ClientsCount = s.Count(), ClinetMemberCount = s.Select(c => c.ClientMembers).Count()
                };
                return(PartialView("FullReport", m));

            case "detailed":
                return(PartialView("DetailedReport", model));

            default:
                return(View());
            }
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Index(AirportCode model)
        {
            var airportCode = model.code;

            var message  = new HttpRequestMessage();            // instantiate HttpRequestMessage object. Will eventually hold all parts of our GET request
            var message2 = new HttpRequestMessage();
            var message3 = new HttpRequestMessage();


            message.Method  = HttpMethod.Get;
            message2.Method = HttpMethod.Get;
            message3.Method = HttpMethod.Get;


            message.RequestUri  = new Uri($"{BASE_URL}metar/{airportCode}?token=Ee2dwfrB1XRnuxsGjByGWD9C3YIuZajZMRgfhluZzL0");
            message2.RequestUri = new Uri($"{BASE_URL}station/{airportCode}?token=Ee2dwfrB1XRnuxsGjByGWD9C3YIuZajZMRgfhluZzL0");
            message3.RequestUri = new Uri($"{BASE_URL}metar/{airportCode}?token=Ee2dwfrB1XRnuxsGjByGWD9C3YIuZajZMRgfhluZzL0");


            var client  = _clientFactory.CreateClient();        // Using injected clientFactory, create new local object
            var client2 = _clientFactory.CreateClient();
            var client3 = _clientFactory.CreateClient();


            var response = await client.SendAsync(message);     // Async sending of GET request with response stored in local object

            var response2 = await client2.SendAsync(message2);

            var response3 = await client3.SendAsync(message3);


            if (response.IsSuccessStatusCode)                                           // If 200-Range Response
            {
                using var responseStream = await response.Content.ReadAsStreamAsync();  // 'using' statement to preserve/garbage-collect resources. Read stream of JSON response into local object

                METARs = await JsonSerializer.DeserializeAsync <METAR>(responseStream); // Deserialize response stream into our METARs property of type METAR.
            }                                                                           // ..If this were more than 1 property on the response, use IEnumerable & for-loop through on the View
            else
            {
                METARs = null;                                                                  // Set Property to null if failed call
            }

            if (response2.IsSuccessStatusCode)
            {
                using var responseStream2 = await response2.Content.ReadAsStreamAsync();

                Name = await JsonSerializer.DeserializeAsync <AirportName>(responseStream2);
            }
            else
            {
                Name = null;
            }
            if (response3.IsSuccessStatusCode)
            {
                using var responseStream3 = await response3.Content.ReadAsStreamAsync();

                Sanitized = await JsonSerializer.DeserializeAsync <FullReport>(responseStream3);
            }

            ViewBag.metarRes    = METARs.flight_rules;
            ViewBag.airportName = Name.name;
            ViewBag.sanitized   = $"METAR: {Sanitized.sanitized}";



            return(View());
            // Return the view passing in the field parsed from response
        }