mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add support for F# and set dotnet docket image to 1.0.1-projectjson (#409)
This commit is contained in:
committed by
C Cirello
parent
ad4d7ce8b9
commit
f815ab54c2
65
examples/hash/csharp/func.cs
Executable file
65
examples/hash/csharp/func.cs
Executable file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
using System.IO;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// if nothing is being piped in, then exit
|
||||
if (!IsPipedInput())
|
||||
return;
|
||||
|
||||
var input = Console.In.ReadToEnd();
|
||||
var stream = DownloadRemoteImageFile(input);
|
||||
var hash = CreateChecksum(stream);
|
||||
Console.WriteLine(hash);
|
||||
}
|
||||
|
||||
private static bool IsPipedInput()
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isKey = Console.KeyAvailable;
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static byte[] DownloadRemoteImageFile(string uri)
|
||||
{
|
||||
|
||||
var request = System.Net.WebRequest.CreateHttp(uri);
|
||||
var response = request.GetResponseAsync().Result;
|
||||
var stream = response.GetResponseStream();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
stream.CopyTo(ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
private static string CreateChecksum(byte[] stream)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
var hash = md5.ComputeHash(stream);
|
||||
var sBuilder = new StringBuilder();
|
||||
|
||||
// Loop through each byte of the hashed data
|
||||
// and format each one as a hexadecimal string.
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sBuilder.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
// Return the hexadecimal string.
|
||||
return sBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
examples/hash/csharp/project.json
Executable file
19
examples/hash/csharp/project.json
Executable file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.1": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.1.0"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user