Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ obj/
_ReSharper*/
[Tt]est[Rr]esult*
*.orig
LoveSeat.IntegrationTest/LoveSeat.IntegrationTest.pidb
LoveSeat.IntegrationTest/LoveSeat.IntegrationTest.pidb
/LoveSeat.Core.ConsoleApp
/.vs
19 changes: 19 additions & 0 deletions LoveSeat.Core.DocUpdater/DesignDoc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using LoveSeat.Core.Interfaces;

namespace LoveSeat.Core.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"; } }
}
}
54 changes: 54 additions & 0 deletions LoveSeat.Core.DocUpdater/DesignDocUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.IO;
using Newtonsoft.Json.Linq;
using LoveSeat.Core.Repositories;

namespace LoveSeat.Core.DocUpdater
{
public class DesignDocUpdater
{
private readonly CouchDatabase _db;
private readonly string _directoryPath;

public DesignDocUpdater(CouchDatabase db, string directoryPath)
{
_db = db;
_directoryPath = directoryPath;
}

public void UpdateIfNecessary()
{
var repo = new CouchRepository<DesignDoc>(_db);

foreach (var file in Directory.GetFiles(_directoryPath, "*.json"))
{
// 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)
{
var newDoc = new DesignDoc
{
Id = designId,
Hash = hash,
Views = obj
};

repo.Save(newDoc);
return;
}

var designDoc = doc.Item;

designDoc.Views = obj;
designDoc.Hash = hash;
repo.Save(designDoc);
}
}
}
}
21 changes: 21 additions & 0 deletions LoveSeat.Core.DocUpdater/LoveSeat.Core.DocUpdater.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>07e711c8-3fd3-470f-ada6-bcb3f0e0e819</ProjectGuid>
<RootNamespace>LoveSeat.Core.DocUpdater</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
19 changes: 19 additions & 0 deletions LoveSeat.Core.DocUpdater/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoveSeat.Core.DocUpdater")]
[assembly: AssemblyTrademark("")]

// 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("07e711c8-3fd3-470f-ada6-bcb3f0e0e819")]
14 changes: 14 additions & 0 deletions LoveSeat.Core.DocUpdater/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "1.0.0-*",

"dependencies": {
"LoveSeat.Core": "1.0.0-*",
"NETStandard.Library": "1.6.1"
},

"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
Loading