Permalink
Browse files

Sources now enumerate Releases

  • Loading branch information...
1 parent a39c9bb commit 51e1ecb351f307015a182d4b6c00a438d5529a56 @cuda committed May 8, 2012
View
@@ -230,7 +230,7 @@ public void CanGetSeries()
Assert.AreEqual(new DateTime(2012, 4, 26), series.RealtimeEnd);
Assert.AreEqual(new DateTime(1913, 1, 1), series.ObservationStart);
Assert.AreEqual(new DateTime(2012, 3, 1), series.ObservationEnd);
- Assert.AreEqual(Frequency.Monthy, series.Frequency);
+ Assert.AreEqual(Frequency.Monthly, series.Frequency);
Assert.AreEqual("Index 1982-84=100", series.Units);
Assert.AreEqual(false, series.SeasonalAdjusted);
Assert.AreEqual(new DateTime(2012, 4, 13, 9, 53, 0), series.LastUpdated);
View
@@ -9,7 +9,6 @@ namespace Xaye.Fred
/// </summary>
public class Category : Item
{
- private readonly object _lok = new object();
private IEnumerable<Category> _childern;
private Category _parent;
private IEnumerable<Category> _related;
@@ -43,7 +42,7 @@ public Category Parent
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_parent == null)
{
@@ -61,7 +60,7 @@ public IEnumerable<Category> Childern
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_childern == null)
{
@@ -80,7 +79,7 @@ public IEnumerable<Category> Related
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_related == null)
{
@@ -99,19 +98,19 @@ public IEnumerable<Series> Series
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_series == null)
{
const int limit = 1000;
_series = (List<Series>)Fred.GetCategorySeries(Id, DateTime.Today, DateTime.Today, limit, 0);
- var count = _series.Count();
+ var count = _series.Count;
var call = 1;
while (count == limit)
{
var more = (List<Series>)Fred.GetCategorySeries(Id, DateTime.Today, DateTime.Today, limit, call * limit);
_series.AddRange(more);
- count = more.Count();
+ count = more.Count;
call++;
}
}
View
@@ -941,9 +941,9 @@ private XElement GetRoot(string url)
return root;
}
- private static Source CreateSource(XElement element)
+ private Source CreateSource(XElement element)
{
- return new Source
+ return new Source(this)
{
Id = int.Parse(element.Attribute("id").Value),
Name = element.Attribute("name").Value,
View
@@ -7,6 +7,13 @@
/// </summary>
public abstract class Item
{
+ private readonly object _lock = new object();
+
+ protected object Lock
+ {
+ get { return _lock; }
+ }
+
protected Item(Fred fred)
{
Fred = fred;
@@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-// [assembly: AssemblyVersion("2012.5.7.77")]
-[assembly: AssemblyVersion("2012.5.7.77")]
-[assembly: AssemblyFileVersion("2012.5.7.77")]
+// [assembly: AssemblyVersion("2012.5.8.78")]
+[assembly: AssemblyVersion("2012.5.8.78")]
+[assembly: AssemblyFileVersion("2012.5.8.78")]
View
@@ -25,8 +25,6 @@ public enum OrderBy
#endregion
- private readonly object _lok = new object();
-
private List<Series> _series;
internal Release(Fred fred) : base(fred)
@@ -71,19 +69,19 @@ public IEnumerable<Series> Series
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_series == null)
{
const int limit = 1000;
_series = (List<Series>)Fred.GetReleaseSeries(Id, RealtimeStart, RealtimeEnd, limit, 0);
- var count = _series.Count();
+ var count = _series.Count;
var call = 1;
while (count == limit)
{
var more = (List<Series>)Fred.GetReleaseSeries(Id, DateTime.Today, DateTime.Today, limit, call * limit);
_series.AddRange(more);
- count = more.Count();
+ count = more.Count;
call++;
}
}
View
@@ -73,7 +73,6 @@ public enum UpdateFilterBy
#endregion
- private readonly object _lok = new object();
private IEnumerable<Category> _categories;
private Release _release;
private List<Observation> _data;
@@ -144,7 +143,7 @@ public Release Release
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_release == null)
{
@@ -164,7 +163,7 @@ public IEnumerable<Category> Categories
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_categories == null)
{
@@ -183,19 +182,19 @@ public IEnumerable<Observation> Observations
{
get
{
- lock (_lok)
+ lock (Lock)
{
if (_data == null)
{
const int limit = 100000;
_data = (List<Observation>)Fred.GetSeriesObservations(Id, ObservationStart, ObservationEnd, RealtimeStart, RealtimeEnd, Enumerable.Empty<DateTime>(), limit, 0);
- var count = _data.Count();
+ var count = _data.Count;
var call = 1;
while (count == limit)
{
var more = (List<Observation>)Fred.GetSeriesObservations(Id, ObservationStart, ObservationEnd, RealtimeStart, RealtimeEnd, Enumerable.Empty<DateTime>(), limit, call * limit);
_data.AddRange(more);
- count = more.Count();
+ count = more.Count;
call++;
}
}
View
@@ -1,4 +1,6 @@
using System;
+using System.Collections;
+using System.Collections.Generic;
namespace Xaye.Fred
{
@@ -7,8 +9,10 @@ namespace Xaye.Fred
/// </summary>
/// <remarks>See http://api.stlouisfed.org/docs/fred/realtime_period.html for information
/// about real-time periods.</remarks>
- public class Source
+ public class Source : Item, IEnumerable<Release>
{
+ #region OrderBy enum
+
/// <summary>
/// When retrieving data, what to order the data by. Defaults to OrderBy.SeriesId.
/// </summary>
@@ -20,34 +24,81 @@ public enum OrderBy
RealtimeEnd
}
+ #endregion
+
+ private List<Release> _releases;
+
+ internal Source(Fred fred) : base(fred)
+ {
+ }
+
/// <summary>
/// The source's ID.
/// </summary>
public int Id { get; set; }
-
+
/// <summary>
/// The source's name.
/// </summary>
public string Name { get; set; }
-
+
/// <summary>
/// A link to information about the source.
/// </summary>
public string Link { get; set; }
-
+
/// <summary>
/// The start of the real-time period.
/// </summary>
public DateTime RealtimeStart { get; set; }
-
+
/// <summary>
/// The end of the real-time period.
/// </summary>
public DateTime RealtimeEnd { get; set; }
-
+
/// <summary>
- /// Notes about the source.
+ /// Provides an enumerator over the
+ /// <see cref="Release"/> by the source.
/// </summary>
- public string Notes { get; set; }
+ public IEnumerable<Release> Releases
+ {
+ get
+ {
+ lock (Lock)
+ {
+ if (_releases == null)
+ {
+ const int limit = 1000;
+ _releases = (List<Release>) Fred.GetSourceReleases(Id);
+ var count = _releases.Count;
+ var call = 1;
+ while (count == limit)
+ {
+ var more = (List<Release>)Fred.GetSourceReleases(Id, DateTime.Today, DateTime.Today, limit, call*limit);
+ _releases.AddRange(more);
+ count = more.Count;
+ call++;
+ }
+ }
+ }
+
+ return _releases;
+ }
+ }
+
+ #region IEnumerable<Release> Members
+
+ public IEnumerator<Release> GetEnumerator()
+ {
+ return Releases.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ #endregion
}
}

0 comments on commit 51e1ecb

Please sign in to comment.