using System;
using System.Threading.Tasks;
using System.Net;
using System.IO;


using Microsoft.AspNetCore.Components;

namespace HyperCube.Pages
{
    public partial class Blockchains
    {
        [Parameter]
        public int Smart { get; set; }
        public string answer;
        public string myWallet;
        public string balanceHCB;
        //public partial class Blocchains
        //{
        //    [Parameter]
        //    public string Smart { get; set; }
        //}
        
        //public string mypath = @"Wallet";
        public string mypath = @"getfile";
        public string getFiles(string wallet)
        {
            mypath = @"c:\Users\Администратор\AppData\Local\Ethereum\rinkeby\keystore\";
            //string filepath = @"c:\Users\Администратор\AppData\Local\Ethereum\rinkeby\keystore\UTC--2021-04-21T07-20-25.392048000Z--1841462ee3e39af00de42b067853c58ab7e18876";
            //text = File.ReadAllText(filepath);
            string toprint = "";
            var files = Directory.GetFiles(mypath);

            foreach (var file in files)
            {
                string fileName = file.Substring(mypath.Length + 1);
                var name = fileName.Split("--");
                try
                {
                    var filepath = mypath + file;                    
                    if ("0x" + name[2] == wallet)
                    {
                        var content = File.ReadAllText(file);
                        Console.WriteLine($"fileName {name[2]} path {filepath} {"0x" + name[2] == wallet} first {content[0]}");
                        return content;
                    }                    
                    //uint fileTaskId = Convert.ToUInt32(name[0]);
                    //if (fileTaskId == taskid)
                    //{
                    //    toprint += fileName + ",";
                    //}
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Exception file {fileName}: {e.Message}");
                }
            }
            return toprint;
        }
    }
}
