Skip to content

Commit 299951f

Browse files
committed
DownloadData bug fix
Fixes the download data function, as it was passing a content-type instead of an accept header for application/xdr. Also fixed improper datetime calculation in DataPoint.
1 parent 27f7b56 commit 299951f

File tree

5 files changed

+304
-2
lines changed

5 files changed

+304
-2
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.gitignore

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
11+
[Dd]ebug/
12+
[Rr]elease/
13+
x64/
14+
build/
15+
[Bb]in/
16+
[Oo]bj/
17+
18+
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19+
!packages/*/build/
20+
21+
# MSTest test Results
22+
[Tt]est[Rr]esult*/
23+
[Bb]uild[Ll]og.*
24+
25+
*_i.c
26+
*_p.c
27+
*.ilk
28+
*.meta
29+
*.obj
30+
*.pch
31+
*.pdb
32+
*.pgc
33+
*.pgd
34+
*.rsp
35+
*.sbr
36+
*.tlb
37+
*.tli
38+
*.tlh
39+
*.tmp
40+
*.tmp_proj
41+
*.log
42+
*.vspscc
43+
*.vssscc
44+
.builds
45+
*.pidb
46+
*.log
47+
*.scc
48+
49+
# Visual C++ cache files
50+
ipch/
51+
*.aps
52+
*.ncb
53+
*.opensdf
54+
*.sdf
55+
*.cachefile
56+
57+
# Visual Studio profiler
58+
*.psess
59+
*.vsp
60+
*.vspx
61+
62+
# Guidance Automation Toolkit
63+
*.gpState
64+
65+
# ReSharper is a .NET coding add-in
66+
_ReSharper*/
67+
*.[Rr]e[Ss]harper
68+
69+
# TeamCity is a build add-in
70+
_TeamCity*
71+
72+
# DotCover is a Code Coverage Tool
73+
*.dotCover
74+
75+
# NCrunch
76+
*.ncrunch*
77+
.*crunch*.local.xml
78+
79+
# Installshield output folder
80+
[Ee]xpress/
81+
82+
# DocProject is a documentation generator add-in
83+
DocProject/buildhelp/
84+
DocProject/Help/*.HxT
85+
DocProject/Help/*.HxC
86+
DocProject/Help/*.hhc
87+
DocProject/Help/*.hhk
88+
DocProject/Help/*.hhp
89+
DocProject/Help/Html2
90+
DocProject/Help/html
91+
92+
# Click-Once directory
93+
publish/
94+
95+
# Publish Web Output
96+
*.Publish.xml
97+
98+
# NuGet Packages Directory
99+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100+
#packages/
101+
102+
# Windows Azure Build Output
103+
csx
104+
*.build.csdef
105+
106+
# Windows Store app package directory
107+
AppPackages/
108+
109+
# Others
110+
sql/
111+
*.Cache
112+
ClientBin/
113+
[Ss]tyle[Cc]op.*
114+
~$*
115+
*~
116+
*.dbmdl
117+
*.[Pp]ublish.xml
118+
*.pfx
119+
*.publishsettings
120+
121+
# RIA/Silverlight projects
122+
Generated_Code/
123+
124+
# Backup & report files from converting an old project file to a newer
125+
# Visual Studio version. Backup files are not needed, because we have git ;-)
126+
_UpgradeReport_Files/
127+
Backup*/
128+
UpgradeLog*.XML
129+
UpgradeLog*.htm
130+
131+
# SQL Server files
132+
App_Data/*.mdf
133+
App_Data/*.ldf
134+
135+
136+
#LightSwitch generated files
137+
GeneratedArtifacts/
138+
_Pvt_Extensions/
139+
ModelManifest.xml
140+
141+
# =========================
142+
# Windows detritus
143+
# =========================
144+
145+
# Windows image file caches
146+
Thumbs.db
147+
ehthumbs.db
148+
149+
# Folder config file
150+
Desktop.ini
151+
152+
# Recycle Bin used on file shares
153+
$RECYCLE.BIN/
154+
155+
# Mac desktop service store files
156+
.DS_Store

SDK/CSharp/DataPoint.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public DateTime Timestamp
3939
{
4040
get
4141
{
42-
return new DateTime((long)(UnixTimestamp / 100) + 116444736000000000);
42+
System.DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
43+
System.DateTime unixDT = epoch.AddTicks((long)(UnixTimestamp/ 100));
44+
return unixDT;
4345
}
4446
}
4547

SDK/CSharp/Device.cs

+81
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,87 @@ public Sensor GetSensor(string sensorName)
114114
return new Sensor(sensorName, _requests);
115115
}
116116

117+
/// <summary>
118+
/// Get a list of existing Sensors for this device.
119+
/// </summary>
120+
public List<Sensor> GetSensors()
121+
{
122+
List<Sensor> outputList = new List<Sensor>();
123+
//make a get request for channel attributes to determine if the channel exists
124+
var request = _requests.url("/sensors/")
125+
.Param("version", "1")
126+
.Accept("application/xdr")
127+
.Get();
128+
129+
// check the response code for success
130+
if (request.ResponseCode == HttpStatusCode.OK)
131+
{
132+
133+
var ms = new MemoryStream(request.Raw);
134+
var xdr = new XdrReader(ms);
135+
//The first value is the version. We expect this to be 1
136+
int version = xdr.ReadInt();
137+
if (version != 1)
138+
{
139+
throw new SensorCloudException("Unsupported xdr version");
140+
}
141+
142+
//The next value is an integer telling us how many sensors to unpack
143+
//Each sensor has its info packed a certain way, so this allows us to know how many sensors we must unpack
144+
int sensorCount = xdr.ReadInt();
145+
//loop through sensors
146+
for(var i=0; i < sensorCount; i++)
147+
{
148+
string sensorName = xdr.ReadString(1000);
149+
//for example's sake, I'm going to push a Sensor Object onto our output array
150+
//This object only needs the Sensor name, and will fetch the Sensor info on it's own
151+
//However, to get all sensor names we must still parse all of the stream. You can modify
152+
//this function to meet your own needs, and return a different set of information
153+
//tailored to what you need.
154+
outputList.Add(new Sensor(sensorName, _requests));
155+
156+
string sensortype = xdr.ReadString(1000);
157+
string sensorlabel = xdr.ReadString(1000); //a token is generally about 60 chars. Limit the read to at most 1000 chars as a precation so in their is a protocol error we don't try to allocate lots of memory
158+
string sensordescripiton = xdr.ReadString(1000);
159+
160+
//the next value is the number of channels this sensor has
161+
int channelCount = xdr.ReadInt();
162+
//loop all channels
163+
for (var j=0; j < channelCount; j++)
164+
{
165+
string channelName = xdr.ReadString(1000);
166+
string channelLabel = xdr.ReadString(1000);
167+
string channelDescription = xdr.ReadString(1000);
168+
169+
//This tells us how many datastreams the channel has
170+
//This should be one, as we only currently support TimeSeries, but could grow as more stream types are added
171+
int streamCount = xdr.ReadInt();
172+
//loop through streams
173+
for (var k=0; k < streamCount; k++)
174+
{
175+
//the first value in the stream is the type of stream. We expect this to be TS_V1, meaning timeseries version 1
176+
string streamType = xdr.ReadString(1000);
177+
//the second value of a stream is the number of bytes that describes the stream.
178+
//This is convenient as it allows us to just skip the stream if we are not interested in it.
179+
//For this example's purpose, we are uninterested and will simply skip ahead in the xdr. We do this by reading the number bytes, but doing anything
180+
//with the data
181+
int totalBytes = xdr.ReadInt();
182+
//just reading the bytes by previously parsed length advances the xdr reader forward in the data
183+
xdr.ReadBytes(totalBytes);
184+
}
185+
186+
}
187+
}
188+
189+
return outputList;
190+
191+
}
192+
else
193+
{
194+
throw SensorCloudException.GenerateSensorCloudException(request, "Get Sensors Failed");
195+
}
196+
}
197+
117198

118199
/// <summary>
119200
/// Delete's a Sensor from the device. All channels must be deleted before you can delete the Sensor.

SDK/CSharp/TimeSeriesStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private IList<Point> DownloadData(ulong startTime, ulong endTime)
117117
.Param("version", "1")
118118
.Param("starttime", startTime)
119119
.Param("endtime", endTime)
120-
.ContentType("application/xdr")
120+
.Accept("application/xdr")
121121
.Get();
122122

123123
// check the response code for success

0 commit comments

Comments
 (0)