예제 #1
0
        public ActionResult ScriptCheck(string savedScript = null)
        {
            SavedScript script = null;
            Guid        id;

            if (!String.IsNullOrEmpty(savedScript) && Guid.TryParse(savedScript, out id))
            {
                try
                {
                    script = repo.GetScript(id);
                }
                catch
                {
                }
            }


            var model = new ScriptCheckModel()
            {
                ScriptPubKey = "OP_DUP OP_HASH160 <Alice.PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG",
                ScriptSig    = "<Alice.Signature> <Alice.Pubkey>",
            };

            if (script != null)
            {
                model.SavedScriptLink = GetScriptLink(script.Id);
                model.ScriptPubKey    = script.ScriptPubKey;
                model.ScriptSig       = script.ScriptSig;
            }
            return(ScriptCheck(model));
        }
예제 #2
0
        public void AtualizaBanco(string ibge, int?id_command)
        {
            try
            {
                //verifica se tabela de ver~soa existe
                var existetabelaversao = Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                                                 conn.QueryFirstOrDefault <int>(_command.VerificaTabelaVersaoExiste));
                if (existetabelaversao == 0)
                {
                    //cria tabela de versão
                    Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                            conn.Execute(_command.CriaTabelaVersao));

                    //cria constraint de tabela de versão
                    Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                            conn.Execute(_command.CriaContraintTabelaVersao));
                }

                //verifica se ja existe algum registro na tabela
                var existeregistrotabversao = Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                                                      conn.QueryFirstOrDefault <int>(_command.VerificaExisteRegistroTabelaVersao));

                //caso não exista, cria o primeiro = 0
                if (existeregistrotabversao == 0)
                {
                    Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                            conn.Execute(_command.InserePrimeiroRegTabVersao));
                }


                int ultimoComando = 0;
                if (id_command != null)
                {
                    ultimoComando = (int)id_command - 1; //usa o numero da versão passada via parametro
                }
                else
                {
                    ultimoComando = Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                                            conn.QueryFirstOrDefault <int>(_command.GetUltimoCodigoScript)); //recupera ultimo comando
                }
                var proximos = ScriptRepository.GetScript(ultimoComando);
                foreach (var item in proximos)
                {
                    try
                    {
                        Helpers.HelperConnection.ExecuteCommandBloco(ibge, item.script);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Erro ao Executar script de nº {item.codigo}. {ex.Message}");
                    }

                    ultimoComando = (int)item.codigo;
                    Helpers.HelperConnection.ExecuteCommand(ibge, conn =>
                                                            conn.Execute(_command.UpdateCodigoScript, new { @versao = ultimoComando }));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }