-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cs
More file actions
87 lines (77 loc) · 3.07 KB
/
Copy pathEngine.cs
File metadata and controls
87 lines (77 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#region Copyright
// *******************************************************************************
// Copyright (c) 2000-2011 Paul Stancer.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// Paul Stancer - initial implementation
// *******************************************************************************
#endregion
#region using
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Stancer.GTFSEngine.Entities;
using Ximura;
#endregion
namespace Stancer.GTFSEngine
{
public partial class Engine
{
#region Declarations
private object mSyncLock = new object();
private ISourceDataCollection mData;
#endregion
#region Constructor
/// <summary>
/// This is the default constructor.
/// </summary>
/// <param name="data">The data source collection.</param>
public Engine(ISourceDataCollection data)
{
mData = data;
}
#endregion
#region HasTransitData(TransitFileType tType)
/// <summary>
/// This function checks whether there is valid data for the specific transit type.
/// </summary>
/// <param name="tType">The transit type.</param>
/// <returns>Returns true if there is valid data.</returns>
private bool HasTransitData(TransitFileType tType)
{
return mData.HasStream(tType);
}
#endregion
#region TransitEntityEnum(TransitFileType tType, IEnumerable<KeyValuePair<string,bool>> headers, Func<CSVRowItem,T> conv)
/// <summary>
/// This method returns the entity items from the CSV data file collection.
/// </summary>
/// <typeparam name="T">The transit entity type.</typeparam>
/// <param name="tType">The transit file type.</param>
/// <param name="headersRequired">The required headers.</param>
/// <param name="conv">The conversion function.</param>
/// <returns>Returns an amalgamated collection of entities.</returns>
private IEnumerable<T> TransitEntityEnum<T>(
TransitFileType tType, IEnumerable<KeyValuePair<string,bool>> headers, Func<CSVRowItem,T> conv)
{
if (!HasTransitData(tType))
yield break;
using (Stream data = mData.GetStream(tType))
{
if (data == null)
throw new ArgumentNullException();
CSVStreamOptions opts = new CSVStreamOptions(Encoding.UTF8, ',', true, false, null, null);
CSVStreamEnumerator<T> item = new CSVStreamEnumerator<T>(data, conv, opts);
foreach (var entity in item)
yield return entity;
}
}
#endregion
}
}