public static string GetPeriodFromWebService(TimePeriod timePeriod, int yearTypeId)
        {
            string period;
            string pholioWs = AppConfig.GetPholioWs();
            var serviceUrl = pholioWs + "api/time_period?quarter=" + timePeriod.Quarter +
                             "&month=" + timePeriod.Month +
                             "&year=" + timePeriod.Year +
                             "&year_range=" + timePeriod.YearRange +
                             "&year_type_id=" + yearTypeId;

            var httpWReq = (HttpWebRequest) WebRequest.Create(serviceUrl);
            HttpWebResponse httpWResp;
            try
            {
                httpWResp = (HttpWebResponse) httpWReq.GetResponse();
            }
            catch (WebException ex)
            {
                throw new FpmException("PholioVisualisationWS not started", ex);
            }

            using (var rd = new StreamReader(httpWResp.GetResponseStream()))
            {
                period = rd.ReadToEnd();
            }

            return period.Replace("\"", "");
        }
        public TimePeriod GetPeriodIfLaterThanDatapoint()
        {
            var reader = ReaderFactory.GetProfilesReader();
            var periods = reader.GetCoreDataSetTimePeriods(grouping);

            if (periods.Any())
            {
                IEnumerable<TimePeriod> relevantPeriods;
                if (datapoint.IsMonthly)
                {
                    relevantPeriods = periods.Where(x => x.Month != TimePeriod.Undefined);
                } else if (datapoint.IsQuarterly)
                {
                    relevantPeriods = periods.Where(x => x.Quarter != TimePeriod.Undefined);
                } else
                {
                    // Annual
                    relevantPeriods = periods.Where(x => 
                        x.Month == TimePeriod.Undefined &&
                        x.Quarter == TimePeriod.Undefined );
                }

                if (relevantPeriods.Any())
                {
                    var last = relevantPeriods.Last();
                    if (last.IsLaterThan(datapoint))
                    {
                        latestPeriod = last;
                        return last;
                    }
                }
            }

            return null;
        }
        public string GetPeriodString(TimePeriod timePeriod, int yearTypeId)
        {
            if (isWebServiceAvailable == false)
            {
                return "No Web Services";
            }

            string period;
            try
            {
                period = GetPeriodFromWebService(timePeriod, yearTypeId);
            }
            catch (Exception)
            {
                isWebServiceAvailable = false;
                return "No web services";
            }

            return period;
        }
 public TimePeriodHelper(GroupingPlusName grouping)
 {
     this.grouping = grouping;
     this.baseline = TimePeriod.GetBaseline(grouping);
     this.datapoint = TimePeriod.GetDataPoint(grouping);
 }