-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b2dc557
Showing
7 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 10.00 | ||
# Visual Studio 2008 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FTP_To_Couch", "FTP_To_Couch\FTP_To_Couch.csproj", "{1106E643-CA3D-4FA0-BC35-CB6EF42EA705}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1106E643-CA3D-4FA0-BC35-CB6EF42EA705}.Debug|x86.ActiveCfg = Debug|x86 | ||
{1106E643-CA3D-4FA0-BC35-CB6EF42EA705}.Debug|x86.Build.0 = Debug|x86 | ||
{1106E643-CA3D-4FA0-BC35-CB6EF42EA705}.Release|x86.ActiveCfg = Release|x86 | ||
{1106E643-CA3D-4FA0-BC35-CB6EF42EA705}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(MonoDevelopProperties) = preSolution | ||
StartupItem = FTP_To_Couch\FTP_To_Couch.csproj | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle("FTP_To_Couch")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("")] | ||
[assembly: AssemblyCopyright("ben")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion("1.0.*")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
|
||
namespace FTP_To_Couch | ||
{ | ||
class BusDateTime | ||
{ | ||
public int Year { get; set; } | ||
public int Mon { get; set; } | ||
public int Day { get; set; } | ||
public int Hour { get; set; } | ||
public int Min { get; set; } | ||
public int Sec { get; set; } | ||
} | ||
|
||
class Location | ||
{ | ||
public string Lat { get; set; } | ||
public string Lon { get; set; } | ||
} | ||
|
||
class BusCheckin | ||
{ | ||
public BusDateTime CheckinTime { get; set; } | ||
public int BusId { get; set; } | ||
public Location Location { get; set; } | ||
public bool LocationValid { get; set; } | ||
public int Adherence { get; set; } | ||
public bool AdherenceValid { get; set; } | ||
public bool HasRoute { get; set; } | ||
public bool RouteLookedUp { get; set; } | ||
public int Route { get; set; } | ||
public int Direction { get; set; } | ||
public int StopId { get; set; } | ||
public string RawData { get; set; } | ||
|
||
private BusCheckin () | ||
{ | ||
} | ||
|
||
public static BusCheckin Create (string data) | ||
{ | ||
if (!String.IsNullOrEmpty (data)) | ||
{ | ||
BusCheckin checkin = new BusCheckin (); | ||
string[] parts = data.Split (','); | ||
DateTime checkinTime; | ||
int busId; | ||
|
||
if (DateTime.TryParse (parts [1] + "/" + DateTime.Today.Year.ToString () + " " + parts [0], out checkinTime) && | ||
Int32.TryParse (parts [2], out busId)) | ||
{ | ||
checkin.CheckinTime = new BusDateTime { | ||
Year = checkinTime.Year, | ||
Mon = checkinTime.Month, | ||
Day = checkinTime.Day, | ||
Hour = checkinTime.Hour, | ||
Min = checkinTime.Minute, | ||
Sec = checkinTime.Second | ||
}; | ||
checkin.RawData = data; | ||
checkin.RouteLookedUp = false; | ||
checkin.BusId = busId; | ||
string[] loc = parts [3].Split ('/'); | ||
string lat = loc [0]; | ||
string lon = loc [1]; | ||
checkin.Location = new Location { | ||
Lat = lat.Substring (0, lat.Length - 7) + "." + lat.Substring (lat.Length - 7), | ||
Lon = lon.Substring (0, lon.Length - 7) + "." + lon.Substring (lon.Length - 7) | ||
}; | ||
checkin.LocationValid = parts [4] == "V"; | ||
checkin.Adherence = Int32.Parse (parts [5]); | ||
checkin.AdherenceValid = parts [6] == "V"; | ||
|
||
int route; | ||
if (parts.Length > 7 && Int32.TryParse (parts [7], out route)) | ||
{ | ||
checkin.HasRoute = true; | ||
checkin.Route = route; | ||
checkin.Direction = Int32.Parse (parts [8]); | ||
int stopId; | ||
checkin.StopId = Int32.TryParse (parts [9], out stopId) ? stopId : -1; | ||
} | ||
else | ||
{ | ||
checkin.HasRoute = false; | ||
checkin.Route = -1; | ||
checkin.Direction = -1; | ||
checkin.StopId = -1; | ||
} | ||
|
||
return checkin; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>9.0.21022</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{1106E643-CA3D-4FA0-BC35-CB6EF42EA705}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>FTP_To_Couch</RootNamespace> | ||
<AssemblyName>FTP_To_Couch</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<Externalconsole>true</Externalconsole> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<Externalconsole>true</Externalconsole> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Web.Extensions" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="AssemblyInfo.cs" /> | ||
<Compile Include="BusCheckin.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Web.Script.Serialization; | ||
|
||
namespace FTP_To_Couch | ||
{ | ||
class MainClass | ||
{ | ||
public static void Main (string[] args) | ||
{ | ||
Console.WriteLine ("Hello World!"); | ||
|
||
string contents = GetFileFromServer (new Uri ("ftp://216.54.15.3/Anrd/hrtrtf.txt")); | ||
List<BusCheckin> checkins = GetBusCheckinsFromFile (contents); | ||
|
||
var serializer = new JavaScriptSerializer (); | ||
|
||
int count = 0; | ||
foreach (var checkin in checkins) | ||
{ | ||
Console.WriteLine ("working " + ++count); | ||
var json = serializer.Serialize (checkin); | ||
var guid = Guid.NewGuid (); | ||
|
||
var docUrl = "http://127.0.0.1:5984/hrt/" + guid; | ||
var request = WebRequest.Create (docUrl); | ||
request.Method = "PUT"; | ||
request.ContentType = "application/json"; | ||
request.ContentLength = json.Length; | ||
|
||
var dataStream = new StreamWriter (request.GetRequestStream ()); | ||
dataStream.Write (json); | ||
dataStream.Close (); | ||
|
||
request.GetResponse ().Close (); | ||
} | ||
} | ||
|
||
public static string GetFileFromServer (Uri serverUri) | ||
{ | ||
// The serverUri parameter should start with the ftp:// scheme. | ||
if (serverUri.Scheme != Uri.UriSchemeFtp) | ||
{ | ||
return null; | ||
} | ||
// Get the object used to communicate with the server. | ||
WebClient request = new WebClient (); | ||
|
||
try | ||
{ | ||
byte[] newFileData = request.DownloadData (serverUri.ToString ()); | ||
string fileString = System.Text.Encoding.UTF8.GetString (newFileData); | ||
return fileString; | ||
} catch (WebException e) | ||
{ | ||
Console.WriteLine (e.ToString ()); | ||
} | ||
return null; | ||
} | ||
|
||
public static List<BusCheckin> GetBusCheckinsFromFile (string file) | ||
{ | ||
List<BusCheckin> busCheckins = new List<BusCheckin> (); | ||
|
||
if (!String.IsNullOrEmpty (file)) | ||
{ | ||
foreach (string line in file.Split('\n', '\r')) | ||
{ | ||
BusCheckin checkin = BusCheckin.Create (line); | ||
if (checkin != null) | ||
busCheckins.Add (checkin); | ||
} | ||
} | ||
|
||
return busCheckins; | ||
} | ||
} | ||
} |