Example #1
0
        /// <summary>
        /// Model for accessing NOAA Solar Calculator
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <ITimeSeriesOutput> RunSolarCalculator(SolarCalculatorInput input)
        {
            Solar.SolarCalculator soCal = new SolarCalculator();
            soCal.Input = input;
            soCal.Model = input.Model.ToLower();
            Utilities.ErrorOutput error = new Utilities.ErrorOutput();
            //Validate unique solar calculator inputs
            if (String.IsNullOrWhiteSpace(input.DateTimeSpan.StartDate.ToString()) || input.DateTimeSpan.StartDate == DateTime.MinValue)
            {
                return(error.ReturnError("DateTimeSpan has no StartDate. StartDate is a required parameter."));
            }
            if (string.IsNullOrWhiteSpace(input.DateTimeSpan.EndDate.ToString()) || input.DateTimeSpan.EndDate == DateTime.MinValue)
            {
                soCal.Input.DateTimeSpan.EndDate = soCal.Input.DateTimeSpan.StartDate.AddYears(1);
            }
            if (String.IsNullOrWhiteSpace(input.Model))
            {
                return(error.ReturnError("Model parameter not defined in request."));
            }
            if (String.IsNullOrWhiteSpace(input.LocalTime) && input.Model.ToLower().Equals("year"))
            {
                soCal.LocalTime = "12:00:00";
            }
            else if (input.Model.ToLower().Equals("year"))
            {
                try
                {
                    DateTime testDate = DateTime.ParseExact(input.LocalTime, "hh:mm:ss", CultureInfo.InvariantCulture);
                }
                catch (FormatException fe) {
                    return(error.ReturnError("LocalTime parameter provided is a not a valid hour time. LocalTime format must be hh:mm:ss"));
                }
                soCal.LocalTime = input.LocalTime;
            }

            soCal.GetCalculatorData();
            return(soCal.Output);
        }