-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from twsouthwick/hash-provider
Replace string.GetHashCode() usage with IFileNameHasher
- Loading branch information
Showing
13 changed files
with
116 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,6 @@ | ||
<%@ Page Language="C#" ContentType="image/png" %> | ||
<%@ Import Namespace="System.IO" %> | ||
<%@ Import Namespace="System.Net" %> | ||
<%@ Import Namespace="WWTWebservices" %> | ||
<% | ||
string returnString = "Erorr: No URL Specified"; | ||
string url = ""; | ||
string path = Server.MapPath(@"TourCache"); | ||
try | ||
{ | ||
if (Request.Params["targeturl"] != null && Request.Params["filename"] != null) | ||
{ | ||
url = Request.Params["targeturl"]; | ||
string targetfile = Request.Params["filename"]; | ||
string filename = path + "\\" + Math.Abs(url.GetHashCode()) + ".wtt"; | ||
if (!File.Exists(filename)) | ||
{ | ||
if (url.ToLower().StartsWith("http")) | ||
{ | ||
using (WebClient wc = new WebClient()) | ||
{ | ||
byte[] data = wc.DownloadData(url); | ||
<%@ Page Language="C#" ContentType="image/png" %> | ||
|
||
//Response.ContentType = wc.ResponseHeaders["Content-type"].ToString(); | ||
int length = data.Length; | ||
File.WriteAllBytes(filename, data); | ||
//Response.OutputStream.Write(data, 0, length); | ||
} | ||
} | ||
} | ||
FileCabinet.Extract(filename, targetfile, Response); | ||
} | ||
} | ||
catch (System.Exception e) | ||
{ | ||
returnString = e.Message; | ||
Response.Write(returnString); | ||
} | ||
%> | ||
<%@ Import Namespace="WWT.Providers" %> | ||
<% | ||
RequestProvider.Get<GetTourFileProvider>().Run(this); | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,6 @@ | ||
<%@ Page Language="C#" ContentType="image/png" %> | ||
<%@ Page Language="C#" ContentType="image/png" %> | ||
|
||
<%@ Import Namespace="System.IO" %> | ||
<%@ Import Namespace="System.Net" %> | ||
<%@ Import Namespace="WWTWebservices" %> | ||
<%@ Import Namespace="WWT.Providers" %> | ||
<% | ||
string returnString = "Error: No URL Specified"; | ||
string url = ""; | ||
string path = Server.MapPath(@"TourCache"); | ||
try | ||
{ | ||
if (Request.Params["targeturl"] != null && Request.Params["filename"] != null) | ||
{ | ||
url = Request.Params["targeturl"]; | ||
string targetfile = Request.Params["filename"]; | ||
string filename = path + "\\" + Math.Abs(url.GetHashCode()) + ".wtt"; | ||
if (!File.Exists(filename)) | ||
{ | ||
if (url.ToLower().StartsWith("http")) | ||
{ | ||
using (WebClient wc = new WebClient()) | ||
{ | ||
byte[] data = wc.DownloadData(url); | ||
//Response.ContentType = wc.ResponseHeaders["Content-type"].ToString(); | ||
int length = data.Length; | ||
File.WriteAllBytes(filename, data); | ||
//Response.OutputStream.Write(data, 0, length); | ||
} | ||
} | ||
} | ||
FileCabinet.Extract(filename, targetfile, Response); | ||
} | ||
} | ||
catch (System.Exception e) | ||
{ | ||
returnString = e.Message; | ||
Response.Write(returnString); | ||
} | ||
%> | ||
RequestProvider.Get<GetTourFileProvider>().Run(this); | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace WWTWebservices | ||
{ | ||
public interface IFileNameHasher | ||
{ | ||
int HashName(string s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
|
||
namespace WWTWebservices | ||
{ | ||
public class Net4x32BitFileNameHasher : IFileNameHasher | ||
{ | ||
/// <summary> | ||
/// Implementation to mimix string.GetHashCode() of 32-bit .NET 4.x. Was used originally for hashing to get id | ||
/// </summary> | ||
/// <param name="s">Input string</param> | ||
/// <returns>Stable hash</returns> | ||
public int HashName(string s) | ||
=> Math.Abs(GetHashCode32BitNet4x(s)); | ||
|
||
private static unsafe int GetHashCode32BitNet4x(string s) | ||
{ | ||
fixed (char* str = s.ToCharArray()) | ||
{ | ||
char* chPtr = str; | ||
int num = 0x15051505; | ||
int num2 = num; | ||
int* numPtr = (int*)chPtr; | ||
|
||
for (int i = s.Length; i > 0; i -= 4) | ||
{ | ||
num = (((num << 5) + num) + (num >> 0x1b)) ^ numPtr[0]; | ||
if (i <= 2) | ||
{ | ||
break; | ||
} | ||
num2 = (((num2 << 5) + num2) + (num2 >> 0x1b)) ^ numPtr[1]; | ||
numPtr += 2; | ||
} | ||
|
||
return (num + (num2 * 0x5d588b65)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ namespace WWTWebservices | |
{ | ||
|
||
|
||
|
||
public class WWTUtil | ||
{ | ||
public WWTUtil() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters