Skip to content
Browse files

Merge branch 'master' of github.com:soitgoes/LoveSeat

  • Loading branch information...
2 parents 8666624 + aa266be commit 30af0908d30ed8d742c5ba7d3a6a8f6b44f0ccd8 @soitgoes committed Mar 29, 2016
View
59 LoveSeat.DesignDoc/LoveSeat.DesignDoc.csproj
@@ -0,0 +1,59 @@
+<?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>ff55f864-6fe9-492a-9433-ac93b19c99dc</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>LoveSeat.DesignDoc</RootNamespace>
+ <AssemblyName>LoveSeat.DesignDoc</AssemblyName>
+ <TargetFrameworkVersion>v4.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="System"/>
+
+ <Reference Include="System.Core"/>
+ <Reference Include="System.Xml.Linq"/>
+ <Reference Include="System.Data.DataSetExtensions"/>
+
+
+ <Reference Include="Microsoft.CSharp"/>
+
+ <Reference Include="System.Data"/>
+ <Reference Include="System.Xml"/>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Class1.cs" />
+
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </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>
View
36 LoveSeat.DesignDoc/Properties/AssemblyInfo.cs
@@ -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("LoveSeat.DesignDoc")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("LoveSeat.DesignDoc")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[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("ff55f864-6fe9-492a-9433-ac93b19c99dc")]
+
+// 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")]
View
28 LoveSeat.DocUpdater/DesignDoc.cs
@@ -0,0 +1,28 @@
+using System.Collections.Generic;
+using LoveSeat.Interfaces;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace LoveSeat.DocUpdater
+{
+ public class DesignDoc : IBaseObject
+ {
+
+ [JsonProperty("hash")]
+ public string Hash { get; set; }
+ [JsonProperty("language")]
+ public string Language { get; set; }
+
+ [JsonProperty("views")]
+ public JObject Views { get; set; }
+
+ public string Id { get; set; }
+
+ public string Rev { get; set; }
+
+ public string Type
+ {
+ get { return "designdoc"; }
+ }
+ }
+}
View
49 LoveSeat.DocUpdater/DesignDocUpdater.cs
@@ -0,0 +1,49 @@
+using System.IO;
+using LoveSeat.Repositories;
+using Newtonsoft.Json.Linq;
+
+namespace LoveSeat.DocUpdater
+{
+ public class DesignDocUpdater
+ {
+ private readonly CouchDatabase db;
+ private readonly string filePath;
+
+ public DesignDocUpdater(CouchDatabase db, string filePath)
+ {
+ this.db = db;
+ this.filePath = filePath;
+ }
+
+ public void UpdateIfNecessary()
+ {
+ var repo = new CouchRepository<DesignDoc>(db);
+ foreach (var file in Directory.GetFiles(this.filePath))
+ {
+ //get the hash of the file. Compare against the hash on the design doc. If they don't match then update.
+ string designId = "_design/" + Path.GetFileNameWithoutExtension(file);
+ string contents = File.ReadAllText(file);
+
+ JObject obj = JObject.Parse(contents);
+ string hash = Sha1Util.Sha1HashStringForUtf8String(contents);
+ var doc = db.GetDocument<DesignDoc>(designId);
+ if (doc == null )
+ {
+ doc = new DesignDoc
+ {
+ Id = designId,
+ Hash = hash,
+ Views = obj
+ };
+ repo.Save(doc);
+ }
+ else if( hash != doc.Hash)
+ {
+ doc.Views = obj;
+ doc.Hash = hash;
+ repo.Save(doc);
+ }
+ }
+ }
+ }
+}
View
73 LoveSeat.DocUpdater/LoveSeat.DocUpdater.csproj
@@ -0,0 +1,73 @@
+<?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>{D257B3DA-3C5B-4F55-8129-E279F993EDA4}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>LoveSeat.DocUpdater</RootNamespace>
+ <AssemblyName>LoveSeat.DocUpdater</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </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>..\LoveSeat.IntegrationTest\bin\Release\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="DesignDoc.cs" />
+ <Compile Include="DesignDocUpdater.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Sha1Util.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\LoveSeat.Interfaces\LoveSeat.Interfaces.csproj">
+ <Project>{18833FC5-9145-451D-82D4-41A1886B0BE7}</Project>
+ <Name>LoveSeat.Interfaces</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\LoveSeat.Repository\LoveSeat.Repositories.csproj">
+ <Project>{95a18b36-b97a-4a39-8920-b245acd12aad}</Project>
+ <Name>LoveSeat.Repositories</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\LoveSeat\LoveSeat.csproj">
+ <Project>{C28D615C-BBAD-499C-9AFA-8DE1089BD977}</Project>
+ <Name>LoveSeat</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>
View
36 LoveSeat.DocUpdater/Properties/AssemblyInfo.cs
@@ -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("LoveSeat.DesignDocUpdater")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("LoveSeat.DesignDocUpdater")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[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("a3a80eef-913b-4e89-84ff-a19fdcb7d1aa")]
+
+// 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")]
View
39 LoveSeat.DocUpdater/Sha1Util.cs
@@ -0,0 +1,39 @@
+using System.Security.Cryptography;
+using System.Text;
+
+namespace LoveSeat.DocUpdater
+{
+ public static class Sha1Util
+ {
+ /// <summary>
+ /// Compute hash for string encoded as UTF8
+ /// </summary>
+ /// <param name="s">String to be hashed</param>
+ /// <returns>40-character hex string</returns>
+ public static string Sha1HashStringForUtf8String(string s)
+ {
+ byte[] bytes = Encoding.UTF8.GetBytes(s);
+
+ var sha1 = SHA1.Create();
+ byte[] hashBytes = sha1.ComputeHash(bytes);
+
+ return HexStringFromBytes(hashBytes);
+ }
+
+ /// <summary>
+ /// Convert an array of bytes to a string of hex digits
+ /// </summary>
+ /// <param name="bytes">array of bytes</param>
+ /// <returns>String of hex digits</returns>
+ public static string HexStringFromBytes(byte[] bytes)
+ {
+ var sb = new StringBuilder();
+ foreach (byte b in bytes)
+ {
+ var hex = b.ToString("x2");
+ sb.Append(hex);
+ }
+ return sb.ToString();
+ }
+ }
+}
View
19 LoveSeat.IntegrationTest/DocUpdaterTest.cs
@@ -0,0 +1,19 @@
+using System;
+using NUnit.Framework;
+using LoveSeat.DocUpdater;
+
+namespace LoveSeat.IntegrationTest
+{
+ [TestFixture]
+ public class DocUpdaterTest
+ {
+ [Test]
+ public void RunUpdate()
+ {
+ var db = new CouchDatabase(new Uri("http://localhost:5984/tmp"));
+ var updater = new DesignDocUpdater(db, "couch_views");
+ updater.UpdateIfNecessary();
+
+ }
+ }
+}
View
8 LoveSeat.IntegrationTest/LoveSeat.IntegrationTest.csproj
@@ -55,11 +55,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CouchClientTest.cs" />
+ <Compile Include="DocUpdaterTest.cs" />
<Compile Include="NewtonSoftTests.cs" />
<Compile Include="PagingHelperTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\LoveSeat.DocUpdater\LoveSeat.DocUpdater.csproj">
+ <Project>{d257b3da-3c5b-4f55-8129-e279f993eda4}</Project>
+ <Name>LoveSeat.DocUpdater</Name>
+ </ProjectReference>
<ProjectReference Include="..\LoveSeat.Interfaces\LoveSeat.Interfaces.csproj">
<Project>{18833FC5-9145-451D-82D4-41A1886B0BE7}</Project>
<Name>LoveSeat.Interfaces</Name>
@@ -73,6 +78,9 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
+ <None Include="couch_views\test.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
View
5 LoveSeat.IntegrationTest/couch_views/test.json
@@ -0,0 +1,5 @@
+{
+ "byName":{
+ "map": "function(doc){emit(doc.name, doc);}"
+ }
+}
View
10 LoveSeat.sln
@@ -1,8 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.31101.0
-MinimumVisualStudioVersion = 10.0.40219.1
+# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat.IntegrationTest", "LoveSeat.IntegrationTest\LoveSeat.IntegrationTest.csproj", "{7496CEA9-442C-4468-8350-54F34693F64A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat.Repositories", "LoveSeat.Repository\LoveSeat.Repositories.csproj", "{95A18B36-B97A-4A39-8920-B245ACD12AAD}"
@@ -11,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat.Interfaces", "Love
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat", "LoveSeat\LoveSeat.csproj", "{C28D615C-BBAD-499C-9AFA-8DE1089BD977}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoveSeat.DocUpdater", "LoveSeat.DocUpdater\LoveSeat.DocUpdater.csproj", "{D257B3DA-3C5B-4F55-8129-E279F993EDA4}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +33,10 @@ Global
{C28D615C-BBAD-499C-9AFA-8DE1089BD977}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C28D615C-BBAD-499C-9AFA-8DE1089BD977}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C28D615C-BBAD-499C-9AFA-8DE1089BD977}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D257B3DA-3C5B-4F55-8129-E279F993EDA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D257B3DA-3C5B-4F55-8129-E279F993EDA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D257B3DA-3C5B-4F55-8129-E279F993EDA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D257B3DA-3C5B-4F55-8129-E279F993EDA4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
10 LoveSeat/CouchClient.cs
@@ -15,6 +15,7 @@ public enum AuthenticationType
/// </summary>
public class CouchClient : CouchBase
{
+ private readonly string baseUri;
// Authentication type used in request to CouchDB
protected readonly AuthenticationType authType;
@@ -58,6 +59,15 @@ public CouchClient(string host, int port, string username, string password, bool
authType = aT;
}
+ /// <summary>
+ /// The full uri for the couch constructor
+ /// </summary>
+ /// <param name="baseUri">Base Url with authentication to couch. Should NOT include database</param>
+ public CouchClient(string baseUri)
+ {
+ this.baseUri = baseUri.EndsWith("/") ? baseUri : baseUri + "/"; //Ensure trailing slash
+ authType = AuthenticationType.Basic;
+ }
/// <summary>
View
10 LoveSeat/CouchDatabase.cs
@@ -25,6 +25,16 @@ internal CouchDatabase(string baseUri, string databaseName, string username, str
}
/// <summary>
+ /// Full uri including database
+ /// </summary>
+ /// <param name="uri"></param>
+ public CouchDatabase(Uri uri)
+ {
+ this.baseUri = uri.AbsoluteUri.Replace(uri.AbsolutePath, "");
+ this.databaseBaseUri = uri.AbsoluteUri;
+ }
+
+ /// <summary>
/// Creates a document using the json provided.
/// No validation or smarts attempted here by design for simplicities sake
/// </summary>
View
1 LoveSeat/Support/CouchBase.cs
@@ -14,7 +14,6 @@ public abstract class CouchBase
protected CouchBase()
{
- throw new Exception("Should not be used.");
}
protected CouchBase(string username, string password, AuthenticationType aT)
{

0 comments on commit 30af090

Please sign in to comment.
Something went wrong with that request. Please try again.