Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ Generated_Code #added for RIA/Silverlight projects
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML

.DS_Store
*.swp
tmp/
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
TinCanCSharp
============
A C#/.NET library for implementing Tin Can API.

C#/.NET library for Tin Can API
For hosted API documentation, basic usage instructions, supported version listing, etc. visit the main project website at:

http://rusticisoftware.github.io/TinCanCSharp/

For more information about the Tin Can API visit:

http://tincanapi.com/

Requires .NET 3.5 or later.
26 changes: 26 additions & 0 deletions TinCan.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinCan", "TinCan\TinCan.csproj", "{27D0FCA1-E869-440C-9D16-F62D7A068C53}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinCanTests", "TinCanTests\TinCanTests.csproj", "{854413C2-2F81-4A82-9949-DE2868A10078}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{27D0FCA1-E869-440C-9D16-F62D7A068C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27D0FCA1-E869-440C-9D16-F62D7A068C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27D0FCA1-E869-440C-9D16-F62D7A068C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27D0FCA1-E869-440C-9D16-F62D7A068C53}.Release|Any CPU.Build.0 = Release|Any CPU
{854413C2-2F81-4A82-9949-DE2868A10078}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{854413C2-2F81-4A82-9949-DE2868A10078}.Debug|Any CPU.Build.0 = Debug|Any CPU
{854413C2-2F81-4A82-9949-DE2868A10078}.Release|Any CPU.ActiveCfg = Release|Any CPU
{854413C2-2F81-4A82-9949-DE2868A10078}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
47 changes: 47 additions & 0 deletions TinCan/LanguageMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2014 Rustici Software

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using TinCan.json;

namespace TinCan
{
public class LanguageMap : JSONBase
{
private Dictionary<String, String> _map;

public LanguageMap() {
_map = new Dictionary<string,string>();
}

public override JObject toJObject(TCAPIVersion version)
{
JObject result = new JObject();
foreach (KeyValuePair<String, String> entry in this._map)
{
result.Add(entry.Key, entry.Value);
}

return result;
}

public bool isEmpty()
{
return _map.Count > 0 ? true : false;
}
}
}
36 changes: 36 additions & 0 deletions TinCan/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TinCan")]
[assembly: AssemblyDescription("Library for implementing Tin Can API")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Rustici Software")]
[assembly: AssemblyProduct("TinCan")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6b7c12d3-32ea-4cb2-9399-3004963d2340")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1.0")]
[assembly: AssemblyFileVersion("0.0.1.0")]
37 changes: 37 additions & 0 deletions TinCan/TCAPIVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2014 Rustici Software

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;

namespace TinCan
{
public sealed class TCAPIVersion
{
public static readonly TCAPIVersion V101 = new TCAPIVersion("1.0.1");
public static readonly TCAPIVersion V100 = new TCAPIVersion("1.0.0");

public static TCAPIVersion latest()
{
return V101;
}

private string text;

private TCAPIVersion(String value)
{
text = value;
}
}
}
63 changes: 63 additions & 0 deletions TinCan/TinCan.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{27D0FCA1-E869-440C-9D16-F62D7A068C53}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TinCan</RootNamespace>
<AssemblyName>TinCan</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="json\JSONBase.cs" />
<Compile Include="json\JSON.cs" />
<Compile Include="json\StringOfJSON.cs" />
<Compile Include="LanguageMap.cs" />
<Compile Include="Verb.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCAPIVersion.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
64 changes: 64 additions & 0 deletions TinCan/Verb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2014 Rustici Software

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using Newtonsoft.Json.Linq;
using TinCan.json;

namespace TinCan
{
public class Verb : JSONBase
{
public Uri id { get; set; }
public LanguageMap display { get; set; }

public Verb() {}

public Verb(StringOfJSON json): this(json.toJObject()) {}

public Verb(JObject jobj)
{
if (jobj["id"] != null)
{
id = jobj.Value<Uri>("id");
}
}

public Verb(Uri uri)
{
id = uri;
}

public Verb(string str)
{
id = new Uri (str);
}

public override JObject toJObject(TCAPIVersion version) {
JObject result = new JObject();
if (id != null)
{
result.Add("id", id);
}

if (display != null && ! display.isEmpty())
{
result.Add("display", display.toJObject(version));
}

return result;
}
}
}
30 changes: 30 additions & 0 deletions TinCan/json/JSON.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2014 Rustici Software

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using Newtonsoft.Json.Linq;

namespace TinCan.json
{
interface JSON
{
JObject toJObject(TCAPIVersion version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only have to support C# here, let's clean this up by using default parameters. eg:

JObject toObject(TCAPIVersion version = TCAPIVersion.latest());
toJSON(TCAPIVersion version = TCAPIVersion.latest(), bool pretty = false);

JObject toJObject();

string toJSON(TCAPIVersion version, bool pretty);
string toJSON(TCAPIVersion version);
string toJSON(bool pretty);
string toJSON();
}
}
56 changes: 56 additions & 0 deletions TinCan/json/JSONBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2014 Rustici Software
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this abstract class can pretty much become blank if we're using defaults


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace TinCan.json
{
public abstract class JSONBase : JSON
{
public abstract JObject toJObject(TCAPIVersion version);

public JObject toJObject()
{
return toJObject(TCAPIVersion.latest());
}

public string toJSON(TCAPIVersion version, bool pretty)
{
Formatting formatting = Formatting.None;
if (pretty)
{
formatting = Formatting.Indented;
}

return JsonConvert.SerializeObject(toJObject(version), formatting);
}

public string toJSON(TCAPIVersion version)
{
return toJSON(version, false);
}

public string toJSON(bool pretty)
{
return toJSON(TCAPIVersion.latest(), pretty);
}

public string toJSON()
{
return toJSON(TCAPIVersion.latest(), false);
}
}
}
Loading