Skip to content

Commit

Permalink
whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Marasco committed Nov 24, 2011
1 parent f8307f0 commit 6214bee
Show file tree
Hide file tree
Showing 9 changed files with 469 additions and 445 deletions.
17 changes: 13 additions & 4 deletions Data/Data.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,6 +9,7 @@
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>Data</RootNamespace> <RootNamespace>Data</RootNamespace>
<AssemblyName>Data</AssemblyName> <AssemblyName>Data</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -61,14 +62,22 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="AForge">
<HintPath>..\MagicVision\AForge.NET\AForge.dll</HintPath>
</Reference>
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Data.SQLite.Linq, Version=2.0.38.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"> <Reference Include="System.Data.SQLite.Linq, Version=2.0.38.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139">
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="AForge, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c1db6ff4eaa06aeb">
<HintPath>..\MagicVision\AForge.NET\AForge.dll</HintPath>
</Reference>
<Reference Include="AForge.Imaging, Version=2.2.2.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\MagicVision\AForge.NET\AForge.Imaging.dll</HintPath>
</Reference>
<Reference Include="AForge.Math, Version=2.2.2.0, Culture=neutral, PublicKeyToken=abba2e25397ee8c9">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\MagicVision\AForge.NET\AForge.Math.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
</Project> </Project>
24 changes: 12 additions & 12 deletions Data/Database/CardStore.cs
@@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;


namespace Data namespace Data
{ {
public interface CardStore public interface CardStore
{ {
IEnumerable<ReferenceCard> GetCards(); IEnumerable<ReferenceCard> GetCards();
void UpdateHash(string id, ulong phash); void UpdateHash(string id, ulong phash);
} }
} }

226 changes: 113 additions & 113 deletions Data/Database/MySQL.cs
@@ -1,113 +1,113 @@
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Text; //using System.Text;
using System.Data; //using System.Data;
using System.Configuration; //using System.Configuration;
using MySql.Data.MySqlClient; ////using MySql.Data.MySqlClient;

//
namespace Data //namespace Data
{ //{
public class MySqlClient : CardStore // public class MySqlClient : CardStore
{ // {
private MySqlConnection sql; // private MySqlConnection sql;
private static string MySqlConnectionString = ConfigurationManager.AppSettings["MySqlConnectionString"]; // private static string MySqlConnectionString = ConfigurationManager.AppSettings["MySqlConnectionString"];

//
private DataRow dbRow(String query) // private DataRow dbRow(String query)
{ // {
MySqlCommand command = sql.CreateCommand(); // MySqlCommand command = sql.CreateCommand();
command.CommandText = query; // command.CommandText = query;

//
DataTable selectDT = new DataTable(); // DataTable selectDT = new DataTable();
MySqlDataAdapter dataAd = new MySqlDataAdapter(command); // MySqlDataAdapter dataAd = new MySqlDataAdapter(command);

//
dataAd.Fill(selectDT); // dataAd.Fill(selectDT);

//
if (selectDT.Rows.Count > 0) // if (selectDT.Rows.Count > 0)
return selectDT.Rows[0]; // return selectDT.Rows[0];
else // else
return null; // return null;
} // }

//
private int lastInsertId() // private int lastInsertId()
{ // {
DataRow r = dbRow("SELECT last_insert_id() as lid"); // DataRow r = dbRow("SELECT last_insert_id() as lid");

//
Int64 id = (Int64)r[0]; // Int64 id = (Int64)r[0];

//
return (int)id; // return (int)id;
} // }

//
private int affectedRows() // private int affectedRows()
{ // {
DataRow r = dbRow("SELECT ROW_COUNT()"); // DataRow r = dbRow("SELECT ROW_COUNT()");
int id = (int)r[0]; // int id = (int)r[0];

//
return id; // return id;
} // }

//
private DataTable dbResult(String query) // private DataTable dbResult(String query)
{ // {
MySqlCommand command = sql.CreateCommand(); // MySqlCommand command = sql.CreateCommand();
command.CommandText = query; // command.CommandText = query;

//
DataTable selectDT = new DataTable(); // DataTable selectDT = new DataTable();
MySqlDataAdapter dataAd = new MySqlDataAdapter(command); // MySqlDataAdapter dataAd = new MySqlDataAdapter(command);

//
dataAd.Fill(selectDT); // dataAd.Fill(selectDT);

//
return selectDT; // return selectDT;

//
} // }

//
internal int dbNone(string query) // internal int dbNone(string query)
{ // {
MySqlCommand command = sql.CreateCommand(); // MySqlCommand command = sql.CreateCommand();
command.CommandText = query; // command.CommandText = query;
return command.ExecuteNonQuery(); // return command.ExecuteNonQuery();
} // }

//
public MySqlClient() // public MySqlClient()
{ // {
sql = new MySqlConnection(MySqlConnectionString); // sql = new MySqlConnection(MySqlConnectionString);
sql.Open(); // sql.Open();
} // }

//
private DateTime ConvertFromUnixTimestamp(double timestamp) // private DateTime ConvertFromUnixTimestamp(double timestamp)
{ // {
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); // DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp); // return origin.AddSeconds(timestamp);
} // }

//
private double ConvertToUnixTimestamp(DateTime date) // private double ConvertToUnixTimestamp(DateTime date)
{ // {
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); // DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin; // TimeSpan diff = date - origin;
return Math.Floor(diff.TotalSeconds); // return Math.Floor(diff.TotalSeconds);
} // }

//
public IEnumerable<ReferenceCard> GetCards() // public IEnumerable<ReferenceCard> GetCards()
{ // {
var ret = new List<ReferenceCard>(); // var ret = new List<ReferenceCard>();

//
var reader = this.dbResult("SELECT * FROM cards"); // var reader = this.dbResult("SELECT * FROM cards");
foreach (DataRow r in reader.Rows) // foreach (DataRow r in reader.Rows)
{ // {
ReferenceCard card = new ReferenceCard(); // ReferenceCard card = new ReferenceCard();
card.cardId = (String)r["id"]; // card.cardId = (String)r["id"];
card.name = (String)r["Name"]; // card.name = (String)r["Name"];
card.pHash = (UInt64)r["pHash"]; // card.pHash = (UInt64)r["pHash"];
card.dataRow = r; // card.dataRow = r;

//
ret.Add(card); // ret.Add(card);
} // }

//
return ret; // return ret;
} // }

//
public void UpdateHash(string id, ulong phash) // public void UpdateHash(string id, ulong phash)
{ // {
this.dbNone("UPDATE cards SET pHash=" + phash.ToString() + " WHERE id=" + id); // this.dbNone("UPDATE cards SET pHash=" + phash.ToString() + " WHERE id=" + id);
} // }
} // }
} //}
28 changes: 14 additions & 14 deletions Data/Models/ReferenceCard.cs
@@ -1,14 +1,14 @@
using System; using System;
using System.Data; using System.Data;


namespace Data namespace Data
{ {
public class ReferenceCard public class ReferenceCard
{ {
public string cardId; public string cardId;
public string name; public string name;
public UInt64 pHash; public UInt64 pHash;
public DataRow dataRow; public DataRow dataRow;
} }
} }

64 changes: 32 additions & 32 deletions Data/PHash/Phash.cs
@@ -1,32 +1,32 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;


namespace Data namespace Data
{ {
public class Phash public class Phash
{ {


[DllImport("pHash.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("pHash.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ph_dct_imagehash(string file_name, ref UInt64 Hash); public static extern int ph_dct_imagehash(string file_name, ref UInt64 Hash);


private static UInt64 m1 = 0x5555555555555555; private static UInt64 m1 = 0x5555555555555555;
private static UInt64 m2 = 0x3333333333333333; private static UInt64 m2 = 0x3333333333333333;
private static UInt64 h01 = 0x0101010101010101; private static UInt64 h01 = 0x0101010101010101;
private static UInt64 m4 = 0x0f0f0f0f0f0f0f0f; private static UInt64 m4 = 0x0f0f0f0f0f0f0f0f;


// Calculate the similarity between two hashes // Calculate the similarity between two hashes
public static int HammingDistance(UInt64 hash1, UInt64 hash2) public static int HammingDistance(UInt64 hash1, UInt64 hash2)
{ {
UInt64 x = hash1 ^ hash2; UInt64 x = hash1 ^ hash2;




x -= (x >> 1) & m1; x -= (x >> 1) & m1;
x = (x & m2) + ((x >> 2) & m2); x = (x & m2) + ((x >> 2) & m2);
x = (x + (x >> 4)) & m4; x = (x + (x >> 4)) & m4;
UInt64 res = (x * h01) >> 56; UInt64 res = (x * h01) >> 56;


return (int)res; return (int)res;
} }
} }
} }

0 comments on commit 6214bee

Please sign in to comment.