Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ftgp committed Aug 11, 2009
0 parents commit acfb937
Show file tree
Hide file tree
Showing 33 changed files with 3,582 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
obj
bin
_ReSharper.*
*.csproj.user
*.resharper.user
*.resharper
*.suo
*.cache
*~
*.swp
.svn
26 changes: 26 additions & 0 deletions Divan.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Divan", "src\Divan.csproj", "{37AC0B66-5340-4B81-BC62-3EE80233A011}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trivial", "samples\Trivial\Trivial.csproj", "{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37AC0B66-5340-4B81-BC62-3EE80233A011}.Release|Any CPU.Build.0 = Release|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
92 changes: 92 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
= Divan, a C# library for CouchDB

Divan is a C# library for using CouchDB (http://www.couchdb.org). It should be more or less API complete
including bulk operations, attachments, views and design documents etc. It is quite fast and designed
to be flexible but not bloated.

Divan has been developed in-house at Foretagsplatsen AB (www.foretagsplatsen.se) and is being used in
the new core system at Foretagsplatsen. It has unit tests (although could benefit from more) and at least
one sample console project included.

== Does it work under Mono?

You bet. Foretagsplatsen uses mainly windows (Visual Studio 2008 and .Net 3.5) but Divan is meant to
work fine in Mono too.

== What about documentation?

At the moment documentation is... this file! :) But there are unit tests in CouchTest.cs and there
is at least one sample project showing basic usage. One more sample with more advanced usage is coming soon.

== Dependencies

The only dependencies and their tested versions are:

* Newtonsoft.JSON (3.5 Beta 4), MIT-licensed fast library for JSON reading and writing, see: http://json.codeplex.com
* NUnit (2.4.8). Unit testing framework, see: http://www.nunit.org
* CouchDB (0.9.1, 0.9). Running on a server somewhere, see: http://www.couchdb.org

The two neeed dlls are included in the lib directory.

== Getting started

Well... it goes something like this:

1. First get CouchDB up and running on some box.

2. Clone Divan and build it.

3. Run the "Trivial" sample console app by pointing it at a running CouchDB server getting output similar to this:

C:\Divan\samples\Trivial>bin\Debug\Trivial.exe 192.168.9.205 5984
Using 192.168.9.205:5984
Created a CouchServer
Request: http://192.168.9.205:5984/trivial Method: HEAD
Request: http://192.168.9.205:5984/trivial Method: PUT
Created database 'trivial'
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Request: http://192.168.9.205:5984/trivial/ Method: POST
Saved 10 Cars with 170 hps each.
Request: http://192.168.9.205:5984/trivial/86a9d1ad306e204a037940c4fb0cbbe7 Method: PUT
Modified last Car with id 86a9d1ad306e204a037940c4fb0cbbe7
Request: http://192.168.9.205:5984/trivial/86a9d1ad306e204a037940c4fb0cbbe7 Method: GET
Loaded last Car Saab 93 now with 400hps.
Request: http://192.168.9.205:5984/trivial/_all_docs?include_docs=true Method: GET
Loaded all Cars: 10
Request: http://192.168.9.205:5984/trivial/1f6de464ae8034eb952b93105807f22c?rev1-208231211 Method: DELETE
Deleted car with id 1f6de464ae8034eb952b93105807f22c
Request: http://192.168.9.205:5984/trivial/44f9638877fc09e07bda6504a5bfd40d?rev1-345884075 Method: DELETE
Deleted car with id 44f9638877fc09e07bda6504a5bfd40d
Request: http://192.168.9.205:5984/trivial/591e0ef170154311aafa8a2a5fcbb310?rev1-2891194419 Method: DELETE
Deleted car with id 591e0ef170154311aafa8a2a5fcbb310
Request: http://192.168.9.205:5984/trivial/7124fada0f90ed93f88168dc6c1c8b4f?rev1-2479256166 Method: DELETE
Deleted car with id 7124fada0f90ed93f88168dc6c1c8b4f
Request: http://192.168.9.205:5984/trivial/73115c4dd3b2bcd512412813dd04b901?rev1-3993011972 Method: DELETE
Deleted car with id 73115c4dd3b2bcd512412813dd04b901
Request: http://192.168.9.205:5984/trivial/78a305543bff2f474cbcfe2ac667cc6d?rev1-1583012745 Method: DELETE
Deleted car with id 78a305543bff2f474cbcfe2ac667cc6d
Request: http://192.168.9.205:5984/trivial/86a9d1ad306e204a037940c4fb0cbbe7?rev2-1402499148 Method: DELETE
Deleted car with id 86a9d1ad306e204a037940c4fb0cbbe7
Request: http://192.168.9.205:5984/trivial/9e647b114b9ba1c8a170ed1c1951260c?rev1-30425501 Method: DELETE
Deleted car with id 9e647b114b9ba1c8a170ed1c1951260c
Request: http://192.168.9.205:5984/trivial/bad56664dec8f3d1fd30db70510f7ff2?rev1-1765374009 Method: DELETE
Deleted car with id bad56664dec8f3d1fd30db70510f7ff2
Request: http://192.168.9.205:5984/trivial/cbf0bb7f8ebc4aad02a2c90228d1076f?rev1-2425501185 Method: DELETE
Deleted car with id cbf0bb7f8ebc4aad02a2c90228d1076f
Request: http://192.168.9.205:5984/trivial Method: HEAD
Request: http://192.168.9.205:5984/trivial Method: DELETE
Deleted database


3. Look at couchTest.cs and make sure the tests are green, you may need to edit CochServer.cs with different default server ip.

4. Have fun!

Binary file added lib/Newtonsoft.Json.dll
Binary file not shown.
Binary file added lib/nunit.framework.dll
Binary file not shown.
136 changes: 136 additions & 0 deletions samples/Trivial/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Diagnostics;
using Divan;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Trivial
{
/// <summary>
/// A trivial example of using Divan. Requires a running CouchDB on localhost!
///
/// Run using:
///
/// Trivial.exe <host> <port>
///
/// </summary>
class Program
{
static void Main(string[] args) {
string host = "localhost";
int port = 5984;

// Lets you see all HTTP requests made by Divan
Trace.Listeners.Add(new ConsoleTraceListener());

// Trivial parse of args to get host and port
switch (args.Length) {
case 0:
Console.WriteLine("Using localhost:5984");
break;
case 1:
Console.WriteLine("Using " + args[0] + ":5984");
host = args[0];
break;
case 2:
Console.WriteLine("Using " + args[0] + ":" + args[1]);
host = args[0];
port = int.Parse(args[1]);
break;
}

// Get a server for default couch port 5984 on localhost
var server = new CouchServer(host, port);
Console.WriteLine("Created a CouchServer");

// Get (creates it if needed) a CouchDB database.
var db = server.GetDatabase("trivial");
Console.WriteLine("Created database 'trivial'");

// Create and save 10 Cars with automatically allocated Ids by Couch
Car car = null;
for (int i = 0; i < 10; i++)
{
car = new Car("Saab", "93", 170);
db.SaveDocument(car);
}
Console.WriteLine("Saved 10 Cars with 170 hps each.");

// Modify the last Car we saved...
car.HorsePowers = 400;

// ...and save the change.
// We could also have used WriteDocument if we knew it was an existing doc
db.SaveDocument(car);
Console.WriteLine("Modified last Car with id " + car.Id);

// Load a Car by known id, class to instantiate using generics
var sameCar = db.GetDocument<Car>(car.Id);
Console.WriteLine("Loaded last Car " + sameCar.Make + " " + sameCar.Model + " now with " + sameCar.HorsePowers + "hps.");

// Load all Cars, class to instantiate using generics
var cars = db.QueryAllDocuments().IncludeDocuments().GetResult().Documents<Car>();
Console.WriteLine("Loaded all Cars: " + cars.Count);

// Delete all Cars one by one
foreach (var eachCar in cars)
{
db.DeleteDocument(eachCar);
Console.WriteLine("Deleted car with id " + eachCar.Id);
}

// Delete the db itself
db.Delete();
Console.WriteLine("Deleted database");
}

/// <summary>
/// The simplest way to deal with domain objects is to subclass CouchDocument
/// and inherit members Id and Rev. You will need to implement WriteJson/ReadJson.
/// </summary>
private class Car : CouchDocument
{
public string Make;
public string Model;
public int HorsePowers;

public Car()
{
// This constructor is needed by Divan
}

public Car(string make, string model, int hps)
{
Make = make;
Model = model;
HorsePowers = hps;
}
#region CouchDocument Members

public override void WriteJson(JsonWriter writer)
{
// This will write id and rev
base.WriteJson(writer);

writer.WritePropertyName("Make");
writer.WriteValue(Make);
writer.WritePropertyName("Model");
writer.WriteValue(Model);
writer.WritePropertyName("Hps");
writer.WriteValue(HorsePowers);
}

public override void ReadJson(JObject obj)
{
// This will read id and rev
base.ReadJson(obj);

Make = obj["Make"].Value<string>();
Model = obj["Model"].Value<string>();
HorsePowers = obj["Hps"].Value<int>();
}

#endregion
}
}
}
36 changes: 36 additions & 0 deletions samples/Trivial/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("Trivial")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MSC Konsult AB")]
[assembly: AssemblyProduct("Trivial")]
[assembly: AssemblyCopyright("Copyright © MSC Konsult AB 2009")]
[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("05c213a1-cf72-45ce-8607-7827b32a1699")]

// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
69 changes: 69 additions & 0 deletions samples/Trivial/Trivial.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CDCC7924-F227-46DC-B2E6-2BBE06B84AF2}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Trivial</RootNamespace>
<AssemblyName>Trivial</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, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Divan.csproj">
<Project>{37AC0B66-5340-4B81-BC62-3EE80233A011}</Project>
<Name>Divan</Name>
</ProjectReference>
</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>
Loading

0 comments on commit acfb937

Please sign in to comment.