Skip to content

Commit

Permalink
Initial Comit with completed code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgulick-pa committed Jan 19, 2018
0 parents commit cb5360f
Show file tree
Hide file tree
Showing 19 changed files with 79,074 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NiceHashBalanceIFTTT/NiceHashBalanceIFTTT/obj/
NiceHashBalanceIFTTT/NiceHashBalanceIFTTT/bin/
Binary file not shown.
25 changes: 25 additions & 0 deletions NiceHashBalanceIFTTT/NiceHashBalanceIFTTT.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NiceHashBalanceIFTTT", "NiceHashBalanceIFTTT\NiceHashBalanceIFTTT.csproj", "{02FF55C7-ECB8-42A9-98C2-91C8DEC8E222}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{02FF55C7-ECB8-42A9-98C2-91C8DEC8E222}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02FF55C7-ECB8-42A9-98C2-91C8DEC8E222}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02FF55C7-ECB8-42A9-98C2-91C8DEC8E222}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02FF55C7-ECB8-42A9-98C2-91C8DEC8E222}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A474F007-C29C-4E62-B8BF-1F299EA85E51}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions NiceHashBalanceIFTTT/NiceHashBalanceIFTTT/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{02FF55C7-ECB8-42A9-98C2-91C8DEC8E222}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>NiceHashBalanceIFTTT</RootNamespace>
<AssemblyName>NiceHashBalanceIFTTT</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\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.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
98 changes: 98 additions & 0 deletions NiceHashBalanceIFTTT/NiceHashBalanceIFTTT/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Globalization;

namespace NiceHashBalanceIFTTT
{
class Program
{
static void Main(string[] args)
{
if(args.Count() != 3)
{
Console.WriteLine("Usage: <WalletAddress> <Event> <Key>");
}
float pendingBalance = UpdateBalance(args);
PushResultToIFTTT(args, pendingBalance);
Console.ReadLine();

}
private static float UpdateBalance(string[] args)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.nicehash.com/api?method=stats.provider&addr=" + args[0]);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";
try
{
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
dynamic returnData = JsonConvert.DeserializeObject(result);
if (returnData != null)
{
return getBalanceFromResults(returnData.result.stats);
}
return 0f;
}
}
catch (Exception ex)
{
return 0f;
}
}
private static float getBalanceFromResults(dynamic stats)
{
float total = 0;
foreach (dynamic stat in stats)
{
float balance = 0;
if (float.TryParse(stat.balance.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out balance))
{
total += balance;
}
else
{

}
}
return total;
}
private static void PushResultToIFTTT(string[] args, float balance)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(string.Format("https://maker.ifttt.com/trigger/{0}/with/key/{1}",args[1],args[2]));
JObject payload = new JObject(
new JProperty("value1", args[0]),
new JProperty("value2", balance.ToString(
)));
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "Post";
httpWebRequest.ContentLength = payload.ToString().Length;
StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream(), System.Text.Encoding.ASCII);
requestWriter.Write(payload.ToString());
requestWriter.Close();

try
{
WebResponse webResponse = httpWebRequest.GetResponse();
Stream webStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
Console.Out.WriteLine(response);
responseReader.Close();
}
catch (Exception e)
{
Console.Out.WriteLine("-----------------");
Console.Out.WriteLine(e.Message);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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("NiceHashBalanceIFTTT")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NiceHashBalanceIFTTT")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("02ff55c7-ecb8-42a9-98c2-91c8dec8e222")]

// 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")]
4 changes: 4 additions & 0 deletions NiceHashBalanceIFTTT/NiceHashBalanceIFTTT/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
</packages>
20 changes: 20 additions & 0 deletions NiceHashBalanceIFTTT/packages/Newtonsoft.Json.10.0.3/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2007 James Newton-King

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file not shown.
Loading

0 comments on commit cb5360f

Please sign in to comment.