Browse Source

Добавил конфигурационный файл #EBT-7 Состояние Проверена

Veloe 4 years ago
parent
commit
a02de1452e

+ 4 - 0
EthermineBotTelegram/App.config

@@ -3,4 +3,8 @@
     <startup> 
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
     </startup>
+    <appSettings>
+        <add key="poolApiUrl" value="https://api.ethermine.org" />
+        <add key="dbIp" value="192.168.2.2" />
+    </appSettings>
 </configuration>

+ 10 - 0
EthermineBotTelegram/AppSettings.cs

@@ -0,0 +1,10 @@
+
+
+namespace EthermineBotTelegram
+{
+    public class AppSettings
+    {
+        public static string poolApiUrl = System.Configuration.ConfigurationManager.AppSettings["poolApiUrl"];
+        public static string dbIp = System.Configuration.ConfigurationManager.AppSettings["dbIp"];
+    }
+}

+ 3 - 1
EthermineBotTelegram/EthermineBotTelegram.csproj

@@ -38,6 +38,7 @@
       <Private>True</Private>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
@@ -51,7 +52,8 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="jsonCurrentStats.cs" />
+    <Compile Include="AppSettings.cs" />
+    <Compile Include="JsonCurrentStats.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>

+ 1 - 1
EthermineBotTelegram/jsonCurrentStats.cs → EthermineBotTelegram/JsonCurrentStats.cs

@@ -18,7 +18,7 @@
         public double btcPerMin { get; set; }
     }
 
-    public class jsonCurrnentStats
+    public class JsonCurrnentStats
     {
         public string status { get; set; }
         public Root data { get; set; }

+ 8 - 2
EthermineBotTelegram/Program.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Configuration;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -15,6 +16,7 @@ namespace EthermineBotTelegram
     class  Program
     {
         static ITelegramBotClient botClient;
+        
         static void Main(string[] args)
         {
             botClient = new TelegramBotClient("1785154817:AAGhXD9yQVn9HPdWTcmGJUBeZ8nA50SzHbY");
@@ -22,6 +24,10 @@ namespace EthermineBotTelegram
             Console.WriteLine(
                 $"Hello, World! I am user {me.Id} and my name is {me.FirstName}."
             );
+            
+            //here will be enstablishing connection to DB
+            
+            //ask for username and password for db
 
             botClient.OnMessage += BotOnMessage;
             botClient.StartReceiving();
@@ -78,8 +84,8 @@ namespace EthermineBotTelegram
         {
             try
             {
-                var url = "https://api.ethermine.org/miner/" + e.Message.Text.Substring(8) + "/currentStats";
-                var currnentStats = _download_serialized_json_data<jsonCurrnentStats>(url);
+                var url = AppSettings.poolApiUrl + "/miner/" + e.Message.Text.Substring(8) + "/currentStats";
+                var currnentStats = _download_serialized_json_data<JsonCurrnentStats>(url);
                 await botClient.SendTextMessageAsync(
                     chatId: e.Message.Chat,
                     text: "Updated: " + DateTimeOffset.FromUnixTimeSeconds(currnentStats.data.time).LocalDateTime.ToString("f") + "\n"