Exemple #1
0
        //Get direction to file contract
        public static string GetPathFileContract(string fileName)
        {
            string pathFile = Path.Combine(mRoot, SMARTCONTRACT, fileName);

            SanitaLog.Log("Path file", pathFile);
            return(pathFile);
        }
Exemple #2
0
 private async void txtStatusWeb_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
 {
     if (UtilityWebServer.mInstance.WebServerRunnning)
     {
         try
         {
             await UtilityWebServer.mInstance.StopWebServer();
         }
         catch (Exception ex)
         {
             SanitaLog.e(TAG, ex);
         }
     }
     else
     {
         try
         {
             int num = await UtilityWebServer.mInstance.StartWebServer();
         }
         catch (Exception ex)
         {
             SanitaLog.e(TAG, ex);
         }
     }
 }
Exemple #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            MyVar.mMediboxSetting.DB_SERVER       = local_txtServer.Text;
            MyVar.mMediboxSetting.DB_NAME         = local_txtDatabase.Text;
            MyVar.mMediboxSetting.DB_USERID       = local_txtUser.Text;
            MyVar.mMediboxSetting.DB_USERPASSWORD = local_txtPassword.Text;

            //Save
            try
            {
                MediboxSetting mMediboxSetting = ObjectCopier.Clone(MyVar.mMediboxSetting);

                if (!mMediboxSetting.DB_ENCRIPT)
                {
                    mMediboxSetting.DB_ENCRIPT      = true;
                    mMediboxSetting.DB_SERVER       = CryptorEngine.Encrypt(mMediboxSetting.DB_SERVER, true);
                    mMediboxSetting.DB_USERID       = CryptorEngine.Encrypt(mMediboxSetting.DB_USERID, true);
                    mMediboxSetting.DB_PORT         = CryptorEngine.Encrypt(mMediboxSetting.DB_PORT, true);
                    mMediboxSetting.DB_USERPASSWORD = CryptorEngine.Encrypt(mMediboxSetting.DB_USERPASSWORD, true);
                    mMediboxSetting.DB_NAME         = CryptorEngine.Encrypt(mMediboxSetting.DB_NAME, true);
                }

                File.WriteAllText(MyVar.SettingsFileName, JsonConvert.SerializeObject(mMediboxSetting));
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }

            SoftUpdatePresenter.SetConnectionConfig(local_txtServer.Text, local_txtUser.Text, local_txtPassword.Text, local_txtDatabase.Text, MyVar.DEFAULT_PORT);

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        //Mine the transaction of deployment and Get a receipt for that transaction
        public static async Task <TransactionReceipt> WaitMiner(string transactionHash)
        {
            TransactionReceipt receipt = null;

            // If receipt is null it means the Contract creation transaction is not minded yet.
            while (receipt == null)
            {
                receipt = await mWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);

                SanitaLog.Log("Minner", "It will take some seconds for the transaction to be approved by the network minders.");
                Thread.Sleep(4000);
            }

            SanitaLog.LogObject("Contract", receipt);
            SanitaLog.Log("Contract address", receipt.ContractAddress);

            //string contractAddress = receipt.ContractAddress;
            //var EthGetTransactionReceipt = Web3Api.mWeb3.Eth.Transactions.GetTransactionReceipt;
            //var EthCall = Web3Api.mWeb3.Eth.Transactions.Call;
            //var EthEstimateGas = Web3Api.mWeb3.Eth.Transactions.EstimateGas;
            //var EthGetTransactionByBlockHashAndIndex = Web3Api.mWeb3.Eth.Transactions.GetTransactionByBlockHashAndIndex;
            //var NetPeerCount = Web3Api.mWeb3.Net.PeerCount;
            //var EthGetBalance = Web3Api.mWeb3.Eth.GetBalance;
            //var EthMining = Web3Api.mWeb3.Eth.Mining.IsMining;
            //var EthAccounts = Web3Api.mWeb3.Eth.Accounts;

            return(receipt);
        }
 public DataRow GetDataRow(string sql)
 {
     try
     {
         DataRow   row       = null;
         DataTable dataTable = this.GetDataTable(sql);
         if (dataTable != null)
         {
             if (dataTable.Rows.Count > 0)
             {
                 row = dataTable.Rows[0];
             }
             else
             {
                 dataTable.Rows.Add(new object[] { 0 });
                 row = dataTable.Rows[0];
             }
         }
         return(row);
     }
     catch (Exception exception)
     {
         SanitaLog.Exception(exception);
         return(null);
     }
 }
        public int Insert(string _sql)
        {
            int    num;
            string sql = _sql;

            try
            {
                using (NpgsqlConnection connection = this.CreateConnection())
                {
                    using (NpgsqlCommand command = new NpgsqlCommand())
                    {
                        command.Connection     = connection;
                        command.CommandText    = sql;
                        command.CommandTimeout = 30;
                        connection.Open();
                        num = command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception exception)
            {
                SanitaLog.Error("NpgsqlBaseDao", "Insert('" + sql + "') error !");
                SanitaLog.Exception(exception);
                num = -100;
            }
            return(num);
        }
        public DataSet GetDataSet(string sql)
        {
            DataSet set2;

            try
            {
                using (NpgsqlConnection connection = this.CreateConnection())
                {
                    using (NpgsqlCommand command = new NpgsqlCommand())
                    {
                        command.Connection     = connection;
                        command.CommandType    = CommandType.Text;
                        command.CommandText    = sql;
                        command.CommandTimeout = 0x3e8;
                        using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter())
                        {
                            adapter.SelectCommand = command;
                            DataSet dataSet = new DataSet();
                            connection.Open();
                            adapter.Fill(dataSet);
                            connection.Close();
                            set2 = dataSet;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                SanitaLog.Error("NpgsqlBaseDao", "GetDataSet error !");
                SanitaLog.Exception(exception);
                set2 = null;
            }
            return(set2);
        }
        public int UpdateContract(NpgsqlConnection connection, IDbTransaction trans, ContractInfo mContractInfo)
        {
            try
            {
                lock (lockObject)
                {
                    if (mContractInfo == null)
                    {
                        return(DataTypeModel.RESULT_NG);
                    }

                    StringBuilder builder = new StringBuilder();
                    builder.Append(" UPDATE Contract ");
                    builder.Append("  SET  ");
                    builder.Append("      Id        = " + DatabaseUtility.Escape(mContractInfo.Id) + ", ");
                    builder.Append("      Name      = " + DatabaseUtility.Escape(mContractInfo.Name) + ", ");
                    builder.Append("      Address   = " + DatabaseUtility.Escape(mContractInfo.Address) + ", ");
                    builder.Append("      Abi       = " + DatabaseUtility.Escape(mContractInfo.Abi) + ", ");
                    builder.Append("      ByteCode  = " + DatabaseUtility.Escape(mContractInfo.ByteCode) + ", ");
                    builder.Append("      Active    = " + DatabaseUtility.Escape(mContractInfo.Active) + " ");
                    builder.Append("  WHERE Id = " + DatabaseUtility.Escape(mContractInfo.Id));

                    return(base.baseDAO.DoUpdate(connection, trans, builder.ToString()));
                }
            }
            catch (Exception ex)
            {
                SanitaLog.Exception(ex);
                throw ex;
            }
        }
        public override bool isDatabaseOK()
        {
            //Get database name
            String DatabaseName = myBaseDao.GetDatabaseName();
            String file_name    = "Database\\" + DatabaseName + ".db";

            SanitaLog.d(TAG, "isDatabaseOK");

            //If have no database -> create datbase
            if (!File.Exists(file_name))
            {
                SanitaLog.d(TAG, "Create database : " + file_name);
                CreateDatabase(DatabaseName);
            }

            System.Threading.Thread.Sleep(1000);

            //If have no database -> create datbase
            if (!File.Exists(file_name))
            {
                SanitaLog.d(TAG, "false");
                return(false);
            }
            else
            {
                SanitaLog.d(TAG, "true");
                return(true);
            }
        }
Exemple #10
0
        public bool CheckConnection(String host, String user, String password, String database, String port)
        {
            try
            {
                GetDatabaseDAO().SetConnectionConfig(host, user, password, database, port);

                if (GetDatabaseType() == DATABASE_TYPE.POSTGRESQL)
                {
                    StringBuilder sql = new StringBuilder();
                    sql.Append(" SELECT NOW() AS TIME_NOW ");
                    DataRow row = GetDatabaseDAO().DoGetDataRow(sql.ToString());
                    if (row != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GetDatabaseType() == DATABASE_TYPE.SQLITE)
                {
                    return(File.Exists("Database\\" + database + ".db"));
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, "Check connection error !", ex);
                return(false);
            }
        }
        // Retrieve the total number of transactions of your sender address

        public static Nethereum.Contracts.Contract GetContract(string abi, string contractAddress)
        {
            Nethereum.Contracts.Contract contract = mWeb3.Eth.GetContract(abi, contractAddress);
            SanitaLog.Log("abi", abi);
            SanitaLog.Log("contract address", contractAddress);
            SanitaLog.LogObject("contract", contract);
            return(contract);
        }
        public DataTable GetDataTable(string sql)
        {
            Exception exception;
            DataTable table2;

            try
            {
                bool      flag;
                int       num       = 0;
                DataTable dataTable = new DataTable();
                goto Label_0118;
Label_0010:
                using (NpgsqlConnection connection = this.CreateConnection())
                {
                    using (NpgsqlCommand command = new NpgsqlCommand())
                    {
                        command.Connection     = connection;
                        command.CommandType    = CommandType.Text;
                        command.CommandText    = "SET enable_seqscan = off; " + sql;
                        command.CommandTimeout = 0x3e8;
                        try
                        {
                            using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter())
                            {
                                adapter.SelectCommand = command;
                                connection.Open();
                                adapter.Fill(dataTable);
                                connection.Close();
                                return(dataTable);
                            }
                        }
                        catch (Exception exception1)
                        {
                            exception = exception1;
                            SanitaLog.Error("NpgsqlBaseDao" + "GetDataTable 1 error !");
                            SanitaLog.Exception(exception1);
                        }
                        num++;
                        if (num > 5)
                        {
                            SanitaLog.Error("NpgsqlBaseDao" + "GetDataTable 2 error ! TryMax > 5");
                            return(null);
                        }
                    }
                }
Label_0118:
                flag = true;
                goto Label_0010;
            }
            catch (Exception exception2)
            {
                exception = exception2;
                SanitaLog.Exception(exception2);
                table2 = null;
            }
            return(table2);
        }
        public int Update(string _sql)
        {
            int num3;

            lock (this.lockDBObject)
            {
                Exception exception;
                string    str = _sql;
                try
                {
                    bool flag2;
                    int  num = 0;
                    goto Label_0108;
Label_0020:
                    using (NpgsqlConnection connection = this.CreateConnection())
                    {
                        using (NpgsqlCommand command = new NpgsqlCommand())
                        {
                            try
                            {
                                command.Connection     = connection;
                                command.CommandText    = str;
                                command.CommandTimeout = 0x3e8;
                                connection.Open();
                                return(command.ExecuteNonQuery());
                            }
                            catch (Exception exception1)
                            {
                                exception = exception1;
                                SanitaLog.Exception(exception);
                            }
                            num++;
                            if (num > 3)
                            {
                                SanitaLog.Error("NpgsqlBaseDao" + "Update('" + str + "') error !");
                                return(-100);
                            }
                            SanitaLog.Error("NpgsqlBaseDao", "Try Update N = " + num.ToString());
                        }
                    }
Label_0108:
                    flag2 = true;
                    goto Label_0020;
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    SanitaLog.Error("NpgsqlBaseDao", "Update('" + str + "') error !");
                    SanitaLog.Exception(exception);
                    num3 = -100;
                }
            }
            return(num3);
        }
        public DataTable GetDataTable(IDbConnection connection, IDbTransaction trans, string sql)
        {
            Exception exception;
            DataTable table2;

            try
            {
                bool      flag;
                int       num       = 0;
                DataTable dataTable = new DataTable();
                goto Label_00EF;
Label_0010:
                using (NpgsqlCommand command = new NpgsqlCommand())
                {
                    command.Connection     = connection as NpgsqlConnection;
                    command.Transaction    = trans as NpgsqlTransaction;
                    command.CommandType    = CommandType.Text;
                    command.CommandText    = sql;
                    command.CommandTimeout = 0x3e8;
                    try
                    {
                        using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter())
                        {
                            adapter.SelectCommand = command;
                            adapter.Fill(dataTable);
                            return(dataTable);
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        SanitaLog.Exception(exception1);
                    }
                    num++;
                    if (num > 5)
                    {
                        SanitaLog.Error("NpgsqlBaseDao" + "GetDataTable 2 error ! TryMax > 5");
                        return(null);
                    }
                }
Label_00EF:
                flag = true;
                goto Label_0010;
            }
            catch (Exception exception2)
            {
                exception = exception2;
                SanitaLog.Error("NpgsqlBaseDao" + "GetDataTable 3 error");
                SanitaLog.Exception(exception2);
                table2 = null;
            }
            return(table2);
        }
Exemple #15
0
        void mWeb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SanitaLog.d("Form_ThoCa_BaiTho", "mWeb_DocumentCompleted");

            String data_group_tacgia = mWeb.DocumentText;

            if (!String.IsNullOrEmpty(data_group_tacgia))
            {
                data_group_tacgia = System.Net.WebUtility.HtmlDecode(data_group_tacgia);
                if (!data_group_tacgia.ToLower().Contains("Nước:".ToLower()) && !data_group_tacgia.ToLower().Contains("poem - group - list".ToLower()))
                {
                    return;
                }

                //Lấy danh sách tác phẩm
                {
                    String          pattern    = "<a href=\"(?<Link1>[^\"]+)(/poem-)(?<Link2>[^\"]+)\">(?<Name>[^<]+)<";
                    MatchCollection list_match = new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase).Matches(data_group_tacgia);

                    foreach (Match match in list_match)
                    {
                        String link = match.Groups["Link1"].Value + "/poem-" + match.Groups["Link2"].Value;
                        String name = match.Groups["Name"].Value;

                        name = name.Replace("?", "");
                        name = name.Replace("<", "");
                        name = name.Replace(">", "");
                        name = name.Replace("/", "");
                        name = name.Replace("\\", "");
                        name = name.Replace("#", "");
                        name = name.Replace(":", "");

                        SanitaLog.d("Form_ThoCa_BaiTho", "ten_tac_gia = " + ten_tac_gia);
                        SanitaLog.d("Form_ThoCa_BaiTho", "ten_tac_pham = " + name);

                        try
                        {
                            String path_file = "D:\\ThiVien.Net\\TacPham\\" + ten_tac_gia + "+++" + name + ".txt";
                            File.WriteAllText(path_file, "https://www.thivien.net/" + link);
                        }
                        catch (Exception ex)
                        {
                            SanitaLog.d("Form_ThoCa_BaiTho", ex.Message);
                            IsNext = false;
                            return;
                        }
                    }
                }

                IsNext = true;
            }
        }
Exemple #16
0
        public Byte[] GetDataRaw(String url)
        {
            try
            {
                return(mWebClient.DownloadData(url));
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }

            return(null);
        }
        void mWeb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            String data_group_tacgia = mWeb.DocumentText;

            if (!String.IsNullOrEmpty(data_group_tacgia))
            {
                data_group_tacgia = System.Net.WebUtility.HtmlDecode(data_group_tacgia);
                if (!data_group_tacgia.ToLower().Contains("poem-content".ToLower()))
                {
                    return;
                }

                //Lấy danh sách tác phẩm
                {
                    IList <String> list_pattern = new List <String>();
                    list_pattern.Add("<h4><strong>" + ten_tac_pham + "</strong></h4>(?<NoiDung>.*?)</div>");
                    list_pattern.Add("<div class=\"poem-content\">(?<NoiDung>.*?)</div>");

                    bool IsOk = false;
                    foreach (String pattern in list_pattern)
                    {
                        Match match = new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase).Match(data_group_tacgia);
                        if (match != null && match.Success)
                        {
                            String name = match.Groups["NoiDung"].Value;

                            try
                            {
                                String path_file = "D:\\ThiVien.Net\\TacPhamChiTiet\\" + ten_tac_gia_tac_pham + ".txt";
                                File.WriteAllText(path_file, name);
                                IsOk = true;
                                break;
                            }
                            catch (Exception ex)
                            {
                                SanitaLog.d("Form_ThoCa_BaiThoChiTiet", ex.Message);
                                return;
                            }
                        }
                    }
                    if (!IsOk)
                    {
                        SanitaLog.d("Form_ThoCa_BaiThoChiTiet", "Parse failed : " + mWeb.Url);
                        MessageBox.Show("Lỗi không xử lý được data, index = " + index_group);
                        return;
                    }
                }

                IsNext = true;
            }
        }
Exemple #18
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            IsNext = false;

            String group_tacgia     = list_group_tacgia[index_group - 1];
            String url_group_tacgia = File.ReadAllText(group_tacgia);

            String file_name_simple = new FileInfo(list_group_tacgia[index_group - 1]).Name;

            ten_tac_gia = file_name_simple.Replace(".txt", "");

            SanitaLog.d("Form_ThoCa_BaiTho", "index_group = " + index_group);

            mWeb.Url = new Uri(url_group_tacgia);
        }
Exemple #19
0
        public void StopTask()
        {
            SanitaLogEx.e(TAG, "Stop task...");

            try
            {
                if (m_BackgroundWorker.CurrentThread != null)
                {
                    m_BackgroundWorker.CurrentThread.Suspend();
                    m_BackgroundWorker.StopImmediately();
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }
        }
Exemple #20
0
        public String GetData(String url)
        {
            try
            {
                var buf = mWebClient.DownloadData(url);
                if (buf != null)
                {
                    return(System.Text.Encoding.UTF8.GetString(buf));
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }

            return("");
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            IsNext = false;

            String group_tac_pham   = list_danh_sach_tac_pham[index_group - 1];
            String url_group_tacgia = File.ReadAllText(group_tac_pham);

            String file_name_simple = new FileInfo(group_tac_pham).Name;

            ten_tac_gia_tac_pham = file_name_simple.Replace(".txt", "");
            IList <String> list_ten_tac_pham = ten_tac_gia_tac_pham.Split(new string[] { "+++" }, StringSplitOptions.None);

            ten_tac_pham = list_ten_tac_pham[1];

            SanitaLog.d("Form_ThoCa_BaiThoChiTiet", "index_group = " + index_group);

            mWeb.Url = new Uri(url_group_tacgia);
        }
        public int Insert(IDbConnection connection, IDbTransaction trans, string _sql)
        {
            int    num;
            string sql = _sql;

            try
            {
                using (NpgsqlCommand command = new NpgsqlCommand())
                {
                    command.Connection     = connection as NpgsqlConnection;
                    command.Transaction    = trans as NpgsqlTransaction;
                    command.CommandText    = sql;
                    command.CommandTimeout = 30;
                    num = command.ExecuteNonQuery();
                }
            }
            catch (Exception exception)
            {
                SanitaLog.Error("NpgsqlBaseDao", "Insert('" + sql + "') error !");
                SanitaLog.Exception(exception);
                SanitaLog.Error("NpgsqlBaseDao", "=>Do rollback: --START");
                try
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                        SanitaLog.Error("NpgsqlBaseDao", "=>Do rollback OK");
                    }
                    if (connection != null)
                    {
                        connection.Close();
                        SanitaLog.Error("NpgsqlBaseDao", "=>Do close connection OK");
                    }
                }
                catch (Exception exception2)
                {
                    SanitaLog.Error("NpgsqlBaseDao", "=>Do rollback NG");
                    SanitaLog.Exception(exception2);
                }
                SanitaLog.Error("NpgsqlBaseDao", "=>Do rollback: --END");
                num = -100;
            }
            return(num);
        }
 public DataRow GetDataRow(IDbConnection connection, IDbTransaction trans, string sql)
 {
     try
     {
         DataRow   row   = null;
         DataTable table = this.GetDataTable(connection, trans, sql);
         if ((table != null) && (table.Rows.Count > 0))
         {
             row = table.Rows[0];
         }
         return(row);
     }
     catch (Exception exception)
     {
         SanitaLog.Error("NpgsqlBaseDao" + "GetDataRow 1 error !");
         SanitaLog.Exception(exception);
         return(null);
     }
 }
Exemple #24
0
        //Public
        public Task <int> StartWebServer()
        {
            WebServerPort = 7001;
            ErrorMessage  = "";

            return(Task <int> .Factory.StartNew((Func <int>)(() =>
            {
                try
                {
                    if (mWebHost != null && mWebHost.Running)
                    {
                        if (mWebHost.Port == WebServerPort)
                        {
                            return 1;
                        }
                        this.StopWebServer().Wait();
                    }
                    if (this.mWebHost == null)
                    {
                        mWebHost = new WebHost();
                        mWebHost.Port = this.WebServerPort;
                        mWebHost.RootDirectoryPath = this.WebServerDirectoryPath;
                        mWebHost.Start();
                    }
                    this.WebServerRunnning = true;
                    return 0;
                }
                catch (Exception ex)
                {
                    if (mWebHost != null)
                    {
                        mWebHost.Dispose();
                        mWebHost = (WebHost)null;
                    }

                    SanitaLog.e(TAG, "StartWebServer error !", ex);

                    ErrorMessage = ex.ToString();
                    WebServerRunnning = false;
                    return -1;
                }
            })));
        }
        public int InsertContract(NpgsqlConnection connection, IDbTransaction trans, ContractInfo mContractInfo)
        {
            try
            {
                lock (lockObject)
                {
                    if (mContractInfo == null)
                    {
                        return(DataTypeModel.RESULT_NG);
                    }

                    StringBuilder builder = new StringBuilder();
                    builder.Append(" INSERT INTO Contract (");
                    builder.Append("            Id,");
                    builder.Append("            Name,");
                    builder.Append("            Address,");
                    builder.Append("            Abi,");
                    builder.Append("            ByteCode,");
                    builder.Append("            Active)");
                    builder.Append("  VALUES( ");
                    builder.Append("          " + DatabaseUtility.Escape(mContractInfo.Id) + ", ");
                    builder.Append("          " + DatabaseUtility.Escape(mContractInfo.Name) + ", ");
                    builder.Append("          " + DatabaseUtility.Escape(mContractInfo.Address) + ", ");
                    builder.Append("          " + DatabaseUtility.Escape(mContractInfo.Abi) + ", ");
                    builder.Append("          " + DatabaseUtility.Escape(mContractInfo.ByteCode) + ", ");
                    builder.Append("          " + DatabaseUtility.Escape(mContractInfo.Active) + ") ");

                    int num = base.baseDAO.DoInsert(connection, trans, builder.ToString());
                    if (num > 0)
                    {
                        return(DataTypeModel.RESULT_OK);
                    }

                    return(DataTypeModel.RESULT_NG);
                }
            }
            catch (Exception ex)
            {
                SanitaLog.Exception(ex);
                throw ex;
            }
        }
        public static async Task <TheContract> GetTheContract(string contractName)
        {
            string actionUrl = Utility.CombineUri(Link.HOST, "smart-contract/get-the-contract");
            string pathFile  = Utility.GetPathFileContract(contractName);

            if (!System.IO.File.Exists(pathFile))
            {
                SanitaLog.Error("Not find " + pathFile);
                return(null);
            }
            HttpContent fileStreamContent = new ByteArrayContent(System.IO.File.ReadAllBytes(pathFile));

            using (HttpClient client = new HttpClient())
                using (MultipartFormDataContent formData = new MultipartFormDataContent())
                {
                    formData.Add(fileStreamContent, "file", contractName);

                    var response = await client.PostAsync(actionUrl, formData);

                    response.EnsureSuccessStatusCode();

                    var contentString = await response.Content.ReadAsStringAsync();

                    var       contents = JObject.Parse(contentString);
                    ResultApi result   = JsonConvert.DeserializeObject <ResultApi>(contentString);

                    client.Dispose();

                    if (result.status == "success")
                    {
                        TheContract mTheContract = JsonConvert.DeserializeObject <TheContract>(result.data);
                        SanitaLog.Log("Abi", mTheContract.Abi);
                        SanitaLog.Log("ByteCode", mTheContract.Bytecode);
                        return(mTheContract);
                    }
                    else
                    {
                        return(null);
                    }
                }
        }
Exemple #27
0
 public NpgsqlConnection GetConnection()
 {
     try
     {
         string host         = "localhost";
         string port         = "5432";
         string user         = "******";
         string password     = "******";
         string dataBaseName = "smartcontract";
         // PostgeSQL-style connection string
         string connstring = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};", host, port, user, password, dataBaseName);
         // Making connection with Npgsql provider
         NpgsqlConnection conn = new NpgsqlConnection(connstring);
         return(conn);
     }
     catch (Exception e)
     {
         // something went wrong, and you wanna know why
         SanitaLog.Exception(e);
         throw e;
     }
 }
Exemple #28
0
        private void bwAsync_Worker(object sender, DoWorkEventArgs e)
        {
            SanitaLogEx.e(TAG, "Start get timer...");

            try
            {
                using (IDbConnection connection = SoftUpdatePresenter.GetConnection())
                {
                    //Open connection
                    connection.Open();

                    //Get time
                    DateTime dt = SoftUpdatePresenter.GetCurrentTime(null, null);

                    //Close connection
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }
        }
Exemple #29
0
        public T GetData <T>(String url)
        {
            try
            {
                var buf = mWebClient.DownloadData(url);
                if (buf != null)
                {
                    string download = System.Text.Encoding.ASCII.GetString(buf);
                    SanitaLog.d(TAG, download);

                    return(JsonConvert.DeserializeObject <T>(download));
                }
                else
                {
                    SanitaLog.d(TAG, "buf=null");
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }

            return(default(T));
        }
Exemple #30
0
        public override bool SynchDatabase(IDbConnection connection, IDbTransaction trans, ExBackgroundWorker worker, int number_hosobenhan, bool IsCapNhatTrigger)
        {
            synch_worker = worker;

            //Get database name
            String DatabaseName = myBaseDao.GetDatabaseName();
            String file_name    = "Database\\" + DatabaseName + ".db";

            SanitaLogEx.d(TAG, "[SynchDatabase] Database = [" + DatabaseName + "]");

            //If have no database -> create datbase
            if (!File.Exists("Database\\" + DatabaseName + ".db"))
            {
                SanitaLog.e(TAG, "[SynchDatabase] Database chưa tồn tại");
                CreateDatabase(DatabaseName);
            }

            //Get all base table
            IList <ClassTable> listTable = GetListTable(connection, trans, DatabaseName);

            //Synch database
            if (synch_worker != null)
            {
                synch_worker.ReportProgress(0, listFixTable.Count);
            }
            for (int i = 0; i < listFixTable.Count; i++)
            {
                if (synch_worker != null)
                {
                    synch_worker.ReportProgress(i + 1, "Nâng cấp table '" + listFixTable[i].Table + "...");
                }

                //Convert mysql to sqlite
                for (int j = 0; j < listFixTable[i].listColumn.Count; j++)
                {
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(10) unsigned NOT NULL auto_increment", "INTEGER");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(10) unsigned", "INTEGER");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(10)", "INTEGER");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(11)", "INTEGER");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("text CHARACTER SET utf8 COLLATE utf8_unicode_ci", "text");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("longblob", "BLOB");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("double", "REAL");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("Datetime DEFAULT '1-1-1'", "TEXT");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("datetime DEFAULT '1-1-1'", "TEXT");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("Datetime", "TEXT");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("datetime", "TEXT");
                    listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP", "TEXT");
                }

                //Tim xem co table ton tai chua
                var foundTable = listTable.FirstOrDefault(p => p.Table.Equals(listFixTable[i].Table, StringComparison.CurrentCultureIgnoreCase));
                if (foundTable == null)
                {
                    //Create table
                    SanitaLogEx.d(TAG, "[SynchDatabase] Create table '" + listFixTable[i].Table + "'");
                    if (CreateTable(connection, trans, DatabaseName, listFixTable[i]) <= -100)
                    {
                        SanitaLogEx.e(TAG, "[SynchDatabase] Create table lỗi");
                        if (synch_worker != null)
                        {
                            synch_worker.ReportProgress(-1, "Tạo table '" + listFixTable[i].Table + "' lỗi !");
                        }
                        return(false);
                    }
                }
                else
                {
                    //Alter table
                    SanitaLogEx.e(TAG, "[SynchDatabase] Alter table '" + listFixTable[i].Table + "'");
                    if (AlterTableTable(connection, trans, DatabaseName, listFixTable[i], foundTable) <= -100)
                    {
                        SanitaLogEx.e(TAG, "[SynchDatabase] Alter table lỗi");
                        if (synch_worker != null)
                        {
                            synch_worker.ReportProgress(-1, "Update table '" + listFixTable[i].Table + "' lỗi !");
                        }
                        return(false);
                    }
                }

                if (synch_worker != null)
                {
                    synch_worker.ReportProgress(i + 1, "Nâng cấp table '" + listFixTable[i].Table + "' OK !");
                }
            }

            return(true);
        }