Browse Source

Создан класс для работы с БД #EBT-5

GandonKur 4 years ago
parent
commit
da329cd620

+ 15 - 4
EthermineBotTelegram/App.config

@@ -1,10 +1,21 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
+  <configSections>
+        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+        <section name="entityFramework"
+          type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+          requirePermission="false"/>
+    </configSections>
     <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+        <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" />
+        <add key="poolApiUrl" value="https://api.ethermine.org"/>
+        <add key="dbIp" value="192.168.2.2"/>
     </appSettings>
+    <entityFramework>
+        <providers>
+            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
+        </providers>
+    </entityFramework>
 </configuration>

+ 51 - 0
EthermineBotTelegram/EFDatabase.cs

@@ -0,0 +1,51 @@
+using System.Data.Common;
+using System.Data.Entity;
+
+namespace EFDatabase
+{
+    public class botdb : DbContext
+    {
+        public botdb(string connectionStringToDB)
+            : base(connectionStringToDB)
+        { }
+        
+        public DbSet<users> users { get; set; }
+        public DbSet<miners> miners { get; set; }
+        public DbSet<workers> workers { get; set; }
+
+    }
+
+    public class users
+    {
+        public int chat_id { get; set; }
+        public string wallet { get; set; }
+        public long last_message { get; set; }
+        public long timer { get; set; } //unused
+    }
+
+    public class miners
+    {
+        public string wallet { get; set; }
+        public long time { get; set; }
+        public long reported_hashrate { get; set; }
+        public long current_hashrate { get; set; }
+        public int valid_shares { get; set; }
+        public int stale_shares { get; set; }
+        public int incorrect_shares { get; set; }
+        public int workers { get; set; }
+        public long unpaid { get; set; }
+    }
+
+    public class workers
+    {
+        public string wallet { get; set; }
+        public long time { get; set; }
+        public string worker { get; set; }
+        public long reported_hashrate { get; set; }
+        public long current_hashrate { get; set; }
+        public int valid_shares { get; set; }
+        public int stale_shares { get; set; }
+        public int incorrect_shares { get; set; }
+        public long worker_unpaid { get; set; }
+    }
+}

+ 19 - 0
EthermineBotTelegram/EthermineBotTelegram.csproj

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -33,11 +34,20 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+      <HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+      <HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
       <HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
       <Private>True</Private>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -53,6 +63,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AppSettings.cs" />
+    <Compile Include="EFDatabase.cs" />
     <Compile Include="JsonCurrentStats.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
@@ -62,4 +73,12 @@
     <None Include="packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
+    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
+  </Target>
+  <Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
 </Project>

+ 1 - 0
EthermineBotTelegram/packages.config

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="EntityFramework" version="6.4.4" targetFramework="net472" />
   <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net472" />
   <package id="System.Net.Requests" version="4.3.0" targetFramework="net472" />
   <package id="Telegram.Bot" version="15.7.1" targetFramework="net472" />