ganahrhr 3 роки тому
батько
коміт
c733fc6e88

+ 1 - 0
DocParse.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Text.RegularExpressions;
 using BitMiracle.Docotic.Pdf;
+using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube
 {

+ 1 - 0
HyperCube.csproj

@@ -18,6 +18,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <Folder Include="Utils\" />
     <Folder Include="wwwroot\images\" />
   </ItemGroup>
 

+ 62 - 61
Models/AccountModel.cs

@@ -1,61 +1,62 @@
-using System;
-using System.Numerics;
-using System.Threading.Tasks;
-using System.Collections.Generic;
-
-namespace HyperCube.Models
-{
-    public enum Role { Admin = 1, Verifier, User }
-
-    public class AccountModel
-    {
-        public static Dictionary<string, AccountModel> Loaded = new();
-        public static AccountModel Current;
-        public string eth_address { get; set; }
-        /// <summary>
-        /// ASP Identity ID
-        /// </summary>
-        public string UUID { get; set; }
-        public string Name { get; set; }
-        public string Email { get; set; }
-        public Role AccRole { get; set; }
-
-        public AccountModel()
-        {
-        }
-
-        public static AccountModel GetCurrent()
-        {
-            return Current;
-        }
-
-        public static AccountModel Find(string uuid)
-        {
-            if (uuid == null)
-                return null;
-            if (Loaded.ContainsKey(uuid))
-                return Loaded[uuid];
-            else
-                return null;
-        }
-
-        public static BigInteger ConvertBalance(string hex)
-        {
-            string newHex = hex.Remove(0, 2);
-            var balance = System.Numerics.BigInteger.Parse("0"+ newHex, System.Globalization.NumberStyles.HexNumber );
-            Console.WriteLine($"ConvertBalance {hex} {balance}");
-            return balance;
-        }
-
-        public static async void InitializeAccounts()
-        {
-            Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
-            Console.WriteLine("InitializeAccounts");
-        }
-
-        public async Task GetEthAddress()
-        {
-            var addr = await Blockchain.GetMain().CreateBlockchainAccount(this);
+using System;
+using System.Numerics;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using Console = HyperCube.Utils.AdvConsole;
+
+namespace HyperCube.Models
+{
+    public enum Role { Admin = 1, Verifier, User }
+
+    public class AccountModel
+    {
+        public static Dictionary<string, AccountModel> Loaded = new();
+        public static AccountModel Current;
+        public string eth_address { get; set; }
+        /// <summary>
+        /// ASP Identity ID
+        /// </summary>
+        public string UUID { get; set; }
+        public string Name { get; set; }
+        public string Email { get; set; }
+        public Role AccRole { get; set; }
+
+        public AccountModel()
+        {
+        }
+
+        public static AccountModel GetCurrent()
+        {
+            return Current;
+        }
+
+        public static AccountModel Find(string uuid)
+        {
+            if (uuid == null)
+                return null;
+            if (Loaded.ContainsKey(uuid))
+                return Loaded[uuid];
+            else
+                return null;
+        }
+
+        public static BigInteger ConvertBalance(string hex)
+        {
+            string newHex = hex.Remove(0, 2);
+            var balance = System.Numerics.BigInteger.Parse("0"+ newHex, System.Globalization.NumberStyles.HexNumber );
+            Console.WriteLine($"ConvertBalance {hex} {balance}");
+            return balance;
+        }
+
+        public static async void InitializeAccounts()
+        {
+            Loaded = await MySQLConnector.Instance().SQLSelectASPUsers();
+            Console.WriteLine("InitializeAccounts");
+        }
+
+        public async Task GetEthAddress()
+        {
+            var addr = await Blockchain.GetMain().CreateBlockchainAccount(this);
         }
 
         public async Task<string> GetBalance()
@@ -65,6 +66,6 @@ namespace HyperCube.Models
             string balance = balanceInt.ToString();
             //Console.WriteLine($"GetBalance {balance}");
             return balance;
-        }
-    }
-}
+        }
+    }
+}

+ 1 - 0
Models/ArticleModel.cs

@@ -2,6 +2,7 @@
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
 using System.Threading.Tasks;
+using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube.Models
 {

+ 1 - 0
Models/Blockchain.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
+using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube.Models
 {

+ 1 - 0
Models/SmartContract.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Numerics;
+using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube.Models
 {

+ 2 - 1
MySQLConnector.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using HyperCube.Models;
 using MySql.Data.MySqlClient;
+using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube
 {
@@ -219,7 +220,7 @@ namespace HyperCube
                 }
                 catch (Exception e)
                 {
-                    Console.Write("SQL Exception 5.1 " + e.Message + " query " + request + "stack trace" + e.StackTrace);
+                    Console.WriteLine("SQL Exception 5.1 " + e.Message + " query " + request + "stack trace" + e.StackTrace);
                 }
                 return retval;
             }

+ 67 - 67
Pages/Account.razor

@@ -1,69 +1,69 @@
-@page "/account"
-@using HyperCube.Models;
-@using Microsoft.AspNetCore.Identity;
-@inject AuthenticationStateProvider AuthenticationStateProvider
-@inject UserManager<IdentityUser> UserManager;
-
-@attribute [Authorize]
-
-<h3>Личный кабинет</h3>
-
-<EditForm Model="@account">
-    <table class="table-bordered" cellspacing="5" cellpadding="5">
-        <tbody>
-            <tr>
-                <td>UUID:</td>
-                <td>@account.UUID</td>
-            </tr>
-            <tr>
-                <td>Name:</td>
-                <td>@account.Name</td>
-            </tr>
-            <tr>
-                <td>Email:</td>
-                <td>@account.Email</td>
-            </tr>
-            <tr>
-                <td>ETH Address:</td>
-                <td>@account.eth_address</td>
-            </tr>
-            <tr>
-                <td>Balance:</td>
-                <td>@myBalance WEI</td>
-            </tr>
-        </tbody>
-    </table>
-</EditForm>
-
-@code {
-    private AccountModel account = new();
-    string myBalance = "";
-
-    protected override async Task OnInitializedAsync()
-    {
+@page "/account"
+@using HyperCube.Models;
+@using Microsoft.AspNetCore.Identity;
+@inject AuthenticationStateProvider AuthenticationStateProvider
+@inject UserManager<IdentityUser> UserManager;
+
+@attribute [Authorize]
+
+<h3>Личный кабинет</h3>
+
+<EditForm Model="@account">
+    <table class="table-bordered" cellspacing="5" cellpadding="5">
+        <tbody>
+            <tr>
+                <td>UUID:</td>
+                <td>@account.UUID</td>
+            </tr>
+            <tr>
+                <td>Name:</td>
+                <td>@account.Name</td>
+            </tr>
+            <tr>
+                <td>Email:</td>
+                <td>@account.Email</td>
+            </tr>
+            <tr>
+                <td>ETH Address:</td>
+                <td>@account.eth_address</td>
+            </tr>
+            <tr>
+                <td>Balance:</td>
+                <td>@myBalance WEI</td>
+            </tr>
+        </tbody>
+    </table>
+</EditForm>
+
+@code {
+    private AccountModel account = new();
+    string myBalance = "";
+
+    protected override async Task OnInitializedAsync()
+    {
         account = await GetCurrentAcc();
         if (Blockchain.GetMain() != null)
-            myBalance = await account.GetBalance();
-    }
-
-    private async Task<AccountModel> GetCurrentAcc()
-    {
-        AccountModel account = new();
-
-        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
-        var user = authState.User;
-
-        if (user.Identity.IsAuthenticated)
-        {
-            var currentUser = await UserManager.GetUserAsync(user);
-            var acc = AccountModel.Find(currentUser.Id);
-            if (acc != null)
-                account = acc;
-
-            account.AccRole = Role.User;
-            return account;
-        }
-
-        return null;
-    }
-}
+            myBalance = await account.GetBalance();
+    }
+
+    private async Task<AccountModel> GetCurrentAcc()
+    {
+        AccountModel account = new();
+
+        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
+        var user = authState.User;
+
+        if (user.Identity.IsAuthenticated)
+        {
+            var currentUser = await UserManager.GetUserAsync(user);
+            var acc = AccountModel.Find(currentUser.Id);
+            if (acc != null)
+                account = acc;
+
+            account.AccRole = Role.User;
+            return account;
+        }
+
+        return null;
+    }
+}

+ 5 - 2
Pages/Blockchains.razor

@@ -1,10 +1,13 @@
 @page "/blockchains"
 @using System.Text.RegularExpressions;
-<h1>Blockchain</h1>
+@using Console = HyperCube.Utils.AdvConsole;
+
 @namespace HyperCube.Models
 
 @attribute [Authorize]
 
+    <h1>Blockchain</h1>
+
 @code
 {
     string hidecontr = "hidden";
@@ -58,7 +61,7 @@
 <p>
     Add blockchain connection:
     <input name="bcurl" @bind="bcURL" type="text" placeholder="URL" @bind:event="oninput">
-    <input name="bport" @bind="bcport" type="number" placeholder="port">    
+    <input name="bport" @bind="bcport" type="number" placeholder="port">
 </p>
 <p style="visibility:@hidecontr">
     Add smart contract:

+ 4 - 3
Pages/DocEdit.razor

@@ -2,6 +2,7 @@
 @page "/docedit/{docID:int}"
 @using System.Reflection;
 @using HyperCube.Models;
+@using Console = HyperCube.Utils.AdvConsole;
 @inject NavigationManager NavigationManager;
 @inject IJSRuntime JsRuntime;
 @attribute [Authorize]
@@ -35,7 +36,7 @@
         <p><InputTextArea rows="10" id="text" class="form-control" @bind-Value="articleModel.Text" placeholder="Текст" /></p>
 
         @if (docID < 1)
-        { 
+        {
             <p><button class="btn btn-primary" type="submit">Загрузить</button></p>
         }
         else
@@ -211,7 +212,7 @@
         {
             status = propDict.Count > 0 ? "All changes saved, article has veryfied." : "Article verifyed without any changes.";
             transactionId = await Verify();
-            Console.WriteLine("transactionId found "+ transactionId);
+            Console.WriteLine("transactionId found " + transactionId);
 
             ///tmp
             //editsCount = await articleModel.GetEditsCount(currentAcc.UUID);
@@ -269,7 +270,7 @@
     public async void InitializeAccount()
     {
         AccountModel.Current = await GetCurrentAcc();
-        Console.WriteLine("InitializeAccount in DocEdit "+ AccountModel.Current.Name);
+        Console.WriteLine("InitializeAccount in DocEdit " + AccountModel.Current.Name);
     }
 
     private async Task<AccountModel> GetCurrentAcc()

+ 1 - 0
Post.cs

@@ -4,6 +4,7 @@ using System.Net;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using Console = HyperCube.Utils.AdvConsole;
 
 namespace HyperCube
 {

+ 6 - 2
Shared/MainLayout.razor

@@ -1,4 +1,5 @@
 @inherits LayoutComponentBase
+@using Console = HyperCube.Utils.AdvConsole;
 
 <div class="page">
     <div class="sidebar">
@@ -50,12 +51,15 @@
                 connected = true;
                 Networks.Add(Blockchain.Connected);
             }
+            else
+            {
+                connected = false;
+                Networks.Add("Blockchain not connected");
+            }
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message + ", stack trace:" + e.StackTrace);
         }
-
-        //Networks.Add("dummy network");
     }
 }

+ 12 - 0
Utils/AdvConsole.cs

@@ -0,0 +1,12 @@
+using System;
+
+namespace HyperCube.Utils
+{
+    public static class AdvConsole
+    {
+        public static void WriteLine(string message)
+        {
+            Console.WriteLine($"{DateTime.Now:yyyy.MM.dd HH:mm:ss.fff}: {message}");            
+        }       
+    }
+}