// Uso para personalizar os campos do sicred ou de qualquer outro que não seguem os padrão comum void r_onRegBoleto(CNAB cnab, IReg reg, BoletoInfo boleto) { // É sempre bom validar o nome do registro, principalmente em CNAB240 que tem 2 tipos de registros para cada boleto, e cada registro deve ser tratado individualmente if (reg.NameType == typeof(CNAB400Remessa1Sicredi)) { Reg<CNAB400Remessa1Sicredi> regBoleto = (Reg<CNAB400Remessa1Sicredi>)reg; // A rotina padrão define estas variáveis abaixo: /* regBoleto[CNAB400Remessa1Sicredi.NumeroDocumento] = cnab.Cedente.DocumentoNumeros; regBoleto[CNAB400Remessa1Sicredi.NossoNumero] = boleto.NossoNumero; regBoleto[CNAB400Remessa1Sicredi.NumeroDocumento] = boleto.NumeroDocumento; regBoleto[CNAB400Remessa1Sicredi.DataVencimento] = boleto.DataVencimento; regBoleto[CNAB400Remessa1Sicredi.ValorDocumento] = boleto.ValorDocumento; regBoleto[CNAB400Remessa1Sicredi.Especie] = CNAB400Sicredi.EspecieSicred(boleto.Especie); regBoleto[CNAB400Remessa1Sicredi.Aceite] = boleto.Aceite == "A" ? "S" : "N"; regBoleto[CNAB400Remessa1Sicredi.Data] = boleto.DataDocumento; regBoleto[CNAB400Remessa1Sicredi.DataEmissao] = boleto.DataDocumento; if (boleto.ParcelaTotal > 0) { regBoleto[CNAB400Remessa1Sicredi.TipoImpressao] = "B"; regBoleto[CNAB400Remessa1Sicredi.ParcelaNumero] = boleto.ParcelaNumero; regBoleto[CNAB400Remessa1Sicredi.ParcelaTotal] = boleto.ParcelaTotal; } regBoleto[CNAB400Remessa1Sicredi.Instrucao] = boleto.Instrucao1; regBoleto[CNAB400Remessa1Sicredi.Protesto] = boleto.DiasProtesto > 6 ? "06" : "00"; regBoleto[CNAB400Remessa1Sicredi.DiasProtesto] = boleto.DiasProtesto; regBoleto[CNAB400Remessa1Sicredi.PercentualMora] = boleto.PercentualMora; regBoleto[CNAB400Remessa1Sicredi.DataDesconto] = boleto.DataDesconto; regBoleto[CNAB400Remessa1Sicredi.ValorDesconto] = boleto.ValorDesconto; regBoleto[CNAB400Remessa1Sicredi.SacadoTipo] = boleto.Sacado.Tipo; regBoleto[CNAB400Remessa1Sicredi.SacadoDocumento] = boleto.Sacado.DocumentoNumeros; regBoleto[CNAB400Remessa1Sicredi.Endereco] = boleto.Sacado.Endereco; regBoleto[CNAB400Remessa1Sicredi.CEP] = boleto.Sacado.CepNumeros; */ // Campos com certa particulariade no sicred regBoleto[CNAB400Remessa1Sicredi.TipoCarteira] = "X"; // posição 3 regBoleto[CNAB400Remessa1Sicredi.TipoJuros] = "Y"; // posição 19 regBoleto[CNAB400Remessa1Sicredi.Alteracao] = "C"; // posição 71 // Desconto por dia de antecipação; regBoleto[CNAB400Remessa1Sicredi.Emissao] = "A"; // posição 74 // O padrão é que a emissão seja feito no cliente ("B") // Os valores definidos em 'SetRegEnumValue' ou 'SetRegKeyValue' são obtidos apos este evento, portanto tem sempre prioridade } }
public void TestToString() { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init();; int TState = 0; AReg areg = new AReg(); BReg breg = new BReg(); IReg ireg = new IReg(); OReg oreg = new OReg(); RAM ram = new RAM(); PC pc = new PC(ref areg); ALU alu = new ALU(ref areg, ref breg); MReg mreg = new MReg(ref ram); SEQ seq = SEQ.Instance(); Wbus.Instance().Value = "00000000"; Flags.Instance().Clear(); Frame frame = new Frame(ireg.ToString(), TState, areg, breg, ireg, mreg, oreg, pc, alu, ram.RAMDump(), ram, seq, Wbus.Instance().ToString(), Flags.Instance(), _decoder); _ = frame.ToString(); _ = frame.OutputRegister(); }
internal void BindReg(IReg ireg) { foreach (var r in Reg) { ireg.Set(r.Key, r.Value); } }
public IRegTree(string regname) { kind = DTKind.IREG; int index = Array.IndexOf(regnames, regname); System.Diagnostics.Debug.Assert(index >= 0); reg = (IReg)index; }
/// <summary> /// chama o evento de pré renderização antes de adicionar a linha /// </summary> public override void Add(IReg oReg) { if (this.onRegBoleto != null) { onRegBoleto(this, oReg, null); } base.Add(oReg); }
/// <summary> /// Renderiza a linha de um boleto, mas antes chama um evento proprio de customização /// </summary> protected void AddBoleto(IReg oReg, BoletoInfo boleto) { if (this.onRegBoleto != null) { onRegBoleto(this, oReg, boleto); } boleto.BindReg(oReg); Add(oReg); }
public void TestToString() { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init(); int TState = 0; AReg areg = new AReg(); TReg treg = new TReg(); BReg breg = new BReg(); CReg creg = new CReg(); IReg ireg = new IReg(); IPort1 port1 = new IPort1(); IPort2 port2 = new IPort2(); MDR mdr = new MDR(); RAM ram = new RAM(); mdr.SetRefToRAM(ref ram); ALU alu = new ALU(ref areg, ref treg); OReg3 oreg3 = new OReg3(ref alu); OReg4 oreg4 = new OReg4(ref alu); HexadecimalDisplay hexadecimalDisplay = new HexadecimalDisplay(ref oreg3); Flag flagReg = new Flag(ref alu); PC pc = new PC(ref flagReg); MAR mar = new MAR(ref ram); SEQ seq = SEQ.Instance(); Wbus.Instance().Value = string.Concat(Enumerable.Repeat('0', 16)); Instruction currentInstruction = new Instruction { OpCode = "ADD B", BinCode = "10000000", TStates = 4, AffectsFlags = true, AddressingMode = AddressingMode.Register, Bytes = 1 }; Frame frame = new Frame(currentInstruction, TState, port1, port2, pc, mar, ram, ram.RAMDump(), mdr, ireg, SEQ.Instance(), Wbus.Instance().Value, areg, alu, flagReg, treg, breg, creg, oreg3, oreg4, hexadecimalDisplay); _ = frame.ToString(); _ = frame.OutputRegister(); }
public void TestUnsubscribe() { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init();; AReg areg = new AReg(); BReg breg = new BReg(); IReg ireg = new IReg(); OReg oreg = new OReg(); RAM ram = new RAM(); PC pc = new PC(ref areg); ALU alu = new ALU(ref areg, ref breg); MReg mreg = new MReg(ref ram); SEQ seq = SEQ.Instance(); seq.Load(GetInstructionSet()); Wbus.Instance().Value = "00000000"; Flags.Instance().Clear(); areg.Subscribe(clock); breg.Subscribe(clock); ireg.Subscribe(clock); mreg.Subscribe(clock); oreg.Subscribe(clock); pc.Subscribe(clock); alu.Subscribe(clock); // ALU must come after A and B ram.Subscribe(clock); for (int i = 0; i < 500; i++) { clock.SendTicTok(tictok); tictok.ToggleClockState(); clock.SendTicTok(tictok); tictok.ToggleClockState(); } // UnSub all clock.EndTransmission(); for (int i = 0; i < 500; i++) { clock.SendTicTok(tictok); tictok.ToggleClockState(); clock.SendTicTok(tictok); tictok.ToggleClockState(); } }
public Frame(Instruction instruction, int TState, IPort1 ip1, IPort2 ip2, PC pc, MAR mar, RAM ram, List <string> ramContents, MDR mdr, IReg ireg, SEQ seq, string wbus_string, AReg areg, ALU alu, Flag flagReg, TReg treg, BReg breg, CReg creg, OReg3 oreg3, OReg4 oreg4, HexadecimalDisplay hexadecimalDisplay) { InstructionData = instruction; if (InstructionData.OpCode.Contains(',')) { InstructionData.OpCode = InstructionData.OpCode.Replace(",", string.Empty); } this.TState = TState; this.AReg = areg.ToString_Frame_Use(); this.BReg = breg.ToString_Frame_Use(); this.CReg = creg.ToString_Frame_Use(); this.TReg = treg.ToString_Frame_Use(); this.IReg = ireg.ToString_Frame_Use(); // The real ToString() is in use with a substring in it. This is needed for proper operation this.MAR = mar.ToString_Frame_Use(); this.MDR = mdr.RegContent; this.PC = pc.RegContent; this.ALU = alu.ToString(); this.WBus = wbus_string; this.OPort1 = oreg3.ToString_Frame_Use(); this.OPort2 = oreg4.ToString_Frame_Use(); this.HexadecimalDisplay = hexadecimalDisplay.RegContent; this.RAM = ramContents; this.SEQ = seq.ToString(); this.WBus = wbus_string; // I didnt want to mess with the Singleton in the frame, so the value will just be passed as a string this.RAM_Reg = ram.ToString_Frame_Use(); this.Flags = flagReg.RegContent; if (instruction == null) { this.IReg = "???"; } if (TState > 3) { Instruction = InstructionData.OpCode; } else { Instruction = "???"; } }
void CustomRegBoleto(CNAB cnab, IReg reg, BoletoInfo boleto) { // é possivel definir campos adicionais como descontos, jurus, protesto e quaisquer outros via evento // estes campos adicionais não estão na classe basica de emissão sem registro: BoletoInfo, e devem ser definidos via evento // veja a documentação de cada banco e atribua os campos necessários // o arqumento "reg" é um tipo de Registro baseado no enumerador do banco registro: Reg<T> (é um template cuidado) if (reg.GetType() == typeof(Reg <CNAB400Remessa1Bradesco>)) // Já como esse é um exemplo generico apenas valido o tipo { var regBoleto = reg as Reg <CNAB400Remessa1Bradesco>; regBoleto[CNAB400Remessa1Bradesco.Condicao] = 1; // Para bo banco imprimir e enviar o boleto regBoleto[CNAB400Remessa1Bradesco.Instrucao1] = 6; // Indica para Protestar regBoleto[CNAB400Remessa1Bradesco.Instrucao2] = 15; // Numero de dias apos o vencimento para o protesto regBoleto[CNAB400Remessa1Bradesco.Avalista] = "!Alterado!"; } }
public void TestUpdate() { try { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init(); AReg areg = new AReg(); BReg breg = new BReg(); IReg ireg = new IReg(); OReg oreg = new OReg(); RAM ram = new RAM(); PC pc = new PC(ref areg); ALU alu = new ALU(ref areg, ref breg); MReg mreg = new MReg(ref ram); SEQ seq = SEQ.Instance(); seq.Load(GetInstructionSet()); Wbus.Instance().Value = "00000000"; Flags.Instance().Clear(); areg.Subscribe(clock); breg.Subscribe(clock); ireg.Subscribe(clock); mreg.Subscribe(clock); oreg.Subscribe(clock); pc.Subscribe(clock); alu.Subscribe(clock); // ALU must come after A and B ram.Subscribe(clock); clock.IsEnabled = true; for (int i = 0; i < 500; i++) { clock.SendTicTok(tictok); tictok.ToggleClockState(); clock.SendTicTok(tictok); tictok.ToggleClockState(); } } catch (Exception e) { Assert.Fail(e.ToString()); } }
// Uso para personalizar os campos do sicred ou de qualquer outro que não seguem os padrão comum void r_onRegBoleto(CNAB cnab, IReg reg, BoletoInfo boleto) { // É sempre bom validar o nome do registro, principalmente em CNAB240 que tem 2 tipos de registros para cada boleto, e cada registro deve ser tratado individualmente if (reg.NameType == typeof(CNAB400Remessa1Sicredi)) { Reg <CNAB400Remessa1Sicredi> regBoleto = (Reg <CNAB400Remessa1Sicredi>)reg; // A rotina padrão define estas variáveis abaixo: /* * regBoleto[CNAB400Remessa1Sicredi.NumeroDocumento] = cnab.Cedente.DocumentoNumeros; * regBoleto[CNAB400Remessa1Sicredi.NossoNumero] = boleto.NossoNumero; * regBoleto[CNAB400Remessa1Sicredi.NumeroDocumento] = boleto.NumeroDocumento; * regBoleto[CNAB400Remessa1Sicredi.DataVencimento] = boleto.DataVencimento; * regBoleto[CNAB400Remessa1Sicredi.ValorDocumento] = boleto.ValorDocumento; * regBoleto[CNAB400Remessa1Sicredi.Especie] = CNAB400Sicredi.EspecieSicred(boleto.Especie); * regBoleto[CNAB400Remessa1Sicredi.Aceite] = boleto.Aceite == "A" ? "S" : "N"; * regBoleto[CNAB400Remessa1Sicredi.Data] = boleto.DataDocumento; * regBoleto[CNAB400Remessa1Sicredi.DataEmissao] = boleto.DataDocumento; * if (boleto.ParcelaTotal > 0) * { * regBoleto[CNAB400Remessa1Sicredi.TipoImpressao] = "B"; * regBoleto[CNAB400Remessa1Sicredi.ParcelaNumero] = boleto.ParcelaNumero; * regBoleto[CNAB400Remessa1Sicredi.ParcelaTotal] = boleto.ParcelaTotal; * } * regBoleto[CNAB400Remessa1Sicredi.Instrucao] = boleto.Instrucao1; * regBoleto[CNAB400Remessa1Sicredi.Protesto] = boleto.DiasProtesto > 6 ? "06" : "00"; * regBoleto[CNAB400Remessa1Sicredi.DiasProtesto] = boleto.DiasProtesto; * regBoleto[CNAB400Remessa1Sicredi.PercentualMora] = boleto.PercentualMora; * regBoleto[CNAB400Remessa1Sicredi.DataDesconto] = boleto.DataDesconto; * regBoleto[CNAB400Remessa1Sicredi.ValorDesconto] = boleto.ValorDesconto; * regBoleto[CNAB400Remessa1Sicredi.SacadoTipo] = boleto.Sacado.Tipo; * regBoleto[CNAB400Remessa1Sicredi.SacadoDocumento] = boleto.Sacado.DocumentoNumeros; * regBoleto[CNAB400Remessa1Sicredi.Endereco] = boleto.Sacado.Endereco; * regBoleto[CNAB400Remessa1Sicredi.CEP] = boleto.Sacado.CepNumeros; */ // Campos com certa particulariade no sicred regBoleto[CNAB400Remessa1Sicredi.TipoCarteira] = "X"; // posição 3 regBoleto[CNAB400Remessa1Sicredi.TipoJuros] = "Y"; // posição 19 regBoleto[CNAB400Remessa1Sicredi.Alteracao] = "C"; // posição 71 // Desconto por dia de antecipação; regBoleto[CNAB400Remessa1Sicredi.Emissao] = "A"; // posição 74 // O padrão é que a emissão seja feito no cliente ("B") // Os valores definidos em 'SetRegEnumValue' ou 'SetRegKeyValue' são obtidos apos este evento, portanto tem sempre prioridade } }
} // The reason this is here is that the RAM might change if a STA simular command is issued. public Frame(string instruction, int TState, AReg areg, BReg breg, IReg ireg, MReg mreg, OReg oreg, PC pc, ALU alu, List <string> ramContents, RAM ram, SEQ seq, string wbus_string, Flags flags, IDecoder decoder, string SetName = "SAP1EMU") { this.RAM = new List <string>(); this.TState = TState; this.AReg = areg.ToString_Frame_Use(); this.BReg = breg.ToString_Frame_Use(); this.IRegShort = ireg.ToString(); this.IReg = ireg.ToString_Frame_Use(); // The real ToString() is in use with a substring in it. This is needed for proper operation this.MReg = mreg.ToString_Frame_Use(); this.OReg = oreg.ToString_Frame_Use(); this.PC = pc.ToString().Substring(4, 4); this.ALU = alu.ToString(); this.WBus = wbus_string; this.Overflow_Flag = flags.Overflow.ToString(); this.Underflow_Flag = flags.Underflow.ToString(); this.Zero_Flag = flags.Zero.ToString(); foreach (string s in ramContents) { RAM.Add(s); } this.SEQ = seq.ToString(); this.WBus = wbus_string; // I didnt want to mess with the Singleton in the frame, so the value will just be passed as a string this.RAM_Reg = ram.ToString_Frame_Use(); if (instruction.Length == 0) { this.IReg = "???"; } if (TState > 3) { //Instruction = OpCodeLoader.DecodeInstruction(IReg.Substring(0, 4), SetName); // TODO this is really inifeciant. Should prob make a service and inject it Instruction = decoder.Decode(IReg.Substring(0, 4), SetName); } else { Instruction = "???"; } }
protected void btn_Click(object sender, EventArgs e) { // Assim juntando os 3 conceitos: Reflection, Attributs, e Generics a classe Reg<T> é criada // Veja aqui alguns breves exemplos de tradução de valores com a Reg<T> IReg ir = null; try { switch (rblTipo.SelectedValue) { case "0": // Traduz linhas de Header CNAB400 Reg <CNAB400Header1Bradesco> r0 = new Reg <CNAB400Header1Bradesco>(); ir = r0; r0.Line = txt.Text; break; case "1": // Traduz linhas de registro Bradesco Reg <CNAB400Remessa1Bradesco> r1 = new Reg <CNAB400Remessa1Bradesco>(); ir = r1; r1.Line = txt.Text; break; case "2": // Traduz linhas de registro Bradesco (tipo 2 apenas como sendo expemplo para simplificar) Reg <CNAB400Retorno1Bradesco> r2 = new Reg <CNAB400Retorno1Bradesco>(); ir = r2; r2.Line = txt.Text; break; case "9": // Traduz linhas de rodape CNAB400 Reg <CNAB400ArquivoTrailer> r9 = new Reg <CNAB400ArquivoTrailer>(); ir = r9; r9.Line = txt.Text; break; } lbl.Text = "OK"; } catch (Exception ex) { // Se o layout não estiver de acordo com o tipo de dado esperado pode haver erros de conversão. // Imagine por exemplo a conversão de textos em campo numericos de data ou valor lbl.Text = ex.Message; } lbl.Text += "<pre>" + ir.Dump + "</pre>"; }
/// <summary> /// Achar o tipo de registro de acordo com o tipo de linha /// </summary> protected bool FindReg(ref IReg reg, string cLine) { if (reg == null || !LastRegType.layout.IsThis(cLine)) { foreach (LayoutType lt in type) { if (lt.layout.IsThis(cLine)) { // Define o ultimo tipo, como o atual encontrado LastRegType = lt; reg = (IReg)Activator.CreateInstance(LastRegType.reg); return(true); } } // Não Achou return(false); } reg = reg.Copy(); // É igual ao ultimo tipo (LastRegType) return(true); }
// ************************************************************************* // ************************************************************************* // Engine Runtime // ************************************************************************* public void Run() { Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init(); AReg areg = new AReg(); TReg treg = new TReg(); BReg breg = new BReg(); CReg creg = new CReg(); IReg ireg = new IReg(); IPort1 iport1 = new IPort1(); IPort2 iport2 = new IPort2(); MDR mdr = new MDR(); RAM ram = new RAM(); mdr.SetRefToRAM(ref ram); ALU alu = new ALU(ref areg, ref treg); areg.SetALUReference(ref alu); breg.SetALUReference(ref alu); creg.SetALUReference(ref alu); OReg3 oreg3 = new OReg3(ref alu); OReg4 oreg4 = new OReg4(ref alu); HexadecimalDisplay hexadecimalDisplay = new HexadecimalDisplay(ref oreg3); Flag flagReg = new Flag(ref alu); PC pc = new PC(ref flagReg); MAR mar = new MAR(ref ram); SEQ seq = SEQ.Instance(); Wbus.Instance().Value = string.Concat(Enumerable.Repeat('0', 16)); areg.Subscribe(clock); treg.Subscribe(clock); breg.Subscribe(clock); creg.Subscribe(clock); ireg.Subscribe(clock); mar.Subscribe(clock); pc.Subscribe(clock); alu.Subscribe(clock); // ALU must come after A and T flagReg.Subscribe(clock); ram.Subscribe(clock); mdr.Subscribe(clock); oreg3.Subscribe(clock); hexadecimalDisplay.Subscribe(clock); oreg4.Subscribe(clock); // Load the program into the RAM ram.LoadProgram(Program); // Load the intsructionSet into the SEQ seq.Load(InstructionSet); Frame tempFrame; #region Program_Exec // Since T1-T3 for all of the Intruction is the same, // LDA or "0000" will be used as the intruction for all T1-T3's clock.IsEnabled = true; int max_loop_count = 10_000; int loop_counter = 0; int TState = 1; // A basic empty instruction state with 3 TStates since on the 4th the instruction // will be known and set to a new object reference. Instruction currentInstruction = new Instruction() { OpCode = "???", TStates = 4 // Since by 4 TStates it should know what instruction it is on }; List <string> controlWords = new List <string>(); bool? didntJump = null; while (clock.IsEnabled) { // Log the Instruction if (TState == 4) { currentInstruction = InstructionSet.Instructions.FirstOrDefault(i => i.BinCode.Equals(ireg.RegContent)); seq.LoadBackupControlWords(currentInstruction.MicroCode); string iname = currentInstruction.OpCode; int operandVal = Convert.ToInt32(ireg.RegContent, 2); string hexOperand = "0x" + operandVal.ToString("X"); } if (TState <= 3) { seq.UpdateControlWordReg(TState, "00000000", didntJump); if (didntJump ?? false) { pc.SkipByte(); didntJump = null; } } else { seq.UpdateControlWordReg(TState, ireg.RegContent); } clock.SendTicTok(tictok); tictok.ToggleClockState(); clock.SendTicTok(tictok); tictok.ToggleClockState(); tempFrame = new Frame(currentInstruction, TState, iport1, iport2, pc, mar, ram, ram.RAMDump(), mdr, ireg, SEQ.Instance(), Wbus.Instance().Value, areg, alu, flagReg, treg, breg, creg, oreg3, oreg4, hexadecimalDisplay); _FrameStack.Add(tempFrame); // HLT if (ireg.RegContent.Equals("01110110", StringComparison.Ordinal) && TState == 5) { clock.IsEnabled = false; _RAMDump = ram.RAMDump(); } if (loop_counter >= max_loop_count) { throw new EngineRuntimeException("Engine Error: Infinite Loop Detected"); } else { loop_counter++; } if (TState == 7 && currentInstruction.OpCode.StartsWith('J')) { pc.CheckForJumpCondition(); // PC is going to jump so do not let it fetch the next byte and immediately endx if (!pc.WontJump) { currentInstruction.TStates = 7; didntJump = true; } } if (TState < currentInstruction.TStates) { TState++; } else { TState = 1; currentInstruction = new Instruction() { OpCode = "???", TStates = 4 // Since by 4 TStates it should know what instruction it is on }; } } OutputReg = oreg3.ToString(); #endregion Program_Exec }
// Uso para personalizar os campos do sicred ou de qualquer outro que não seguem os padrão comum void r_onRegBoleto(CNAB cnab, IReg reg, BoletoInfo boleto) { // A verificação do tipo agora é obrigatporio poosi todos os registros, incluindo o header e footer podem ser personalizados // Logico que em certos registro o valor de BoletoInfo é null if (reg.NameType == typeof(CNAB400Remessa1Sicredi)) { Reg<CNAB400Remessa1Sicredi> regBoleto = (Reg<CNAB400Remessa1Sicredi>)reg; // A rotina padrão define estas variáveis comentadas abaixo: regBoleto[CNAB400Remessa1Sicredi.NumeroDocumento] = cnab.Cedente.DocumentoNumeros; regBoleto[CNAB400Remessa1Sicredi.NossoNumero] = boleto.NossoNumero; regBoleto[CNAB400Remessa1Sicredi.NumeroDocumento] = boleto.NumeroDocumento; regBoleto[CNAB400Remessa1Sicredi.DataVencimento] = boleto.DataVencimento; regBoleto[CNAB400Remessa1Sicredi.ValorDocumento] = boleto.ValorDocumento; regBoleto[CNAB400Remessa1Sicredi.Especie] = CNAB400Sicredi.EspecieSicred(boleto.Especie); regBoleto[CNAB400Remessa1Sicredi.Aceite] = boleto.Aceite == "A" ? "S" : "N"; regBoleto[CNAB400Remessa1Sicredi.Data] = boleto.DataDocumento; regBoleto[CNAB400Remessa1Sicredi.DataEmissao] = boleto.DataDocumento; if (boleto.ParcelaTotal > 0) { regBoleto[CNAB400Remessa1Sicredi.TipoImpressao] = "B"; regBoleto[CNAB400Remessa1Sicredi.ParcelaNumero] = boleto.ParcelaNumero; regBoleto[CNAB400Remessa1Sicredi.ParcelaTotal] = boleto.ParcelaTotal; } regBoleto[CNAB400Remessa1Sicredi.Instrucao] = boleto.Instrucao1; regBoleto[CNAB400Remessa1Sicredi.Protesto] = boleto.DiasProtesto > 6 ? "06" : "00"; regBoleto[CNAB400Remessa1Sicredi.DiasProtesto] = boleto.DiasProtesto; regBoleto[CNAB400Remessa1Sicredi.PercentualMora] = boleto.PercentualMora; regBoleto[CNAB400Remessa1Sicredi.DataDesconto] = boleto.DataDesconto; regBoleto[CNAB400Remessa1Sicredi.ValorDesconto] = boleto.ValorDesconto; regBoleto[CNAB400Remessa1Sicredi.SacadoTipo] = boleto.Sacado.Tipo; regBoleto[CNAB400Remessa1Sicredi.SacadoDocumento] = boleto.Sacado.DocumentoNumeros; regBoleto[CNAB400Remessa1Sicredi.Endereco] = boleto.Sacado.Endereco; regBoleto[CNAB400Remessa1Sicredi.CEP] = boleto.Sacado.CepNumeros; // Campos com certa particulariade no sicred regBoleto[CNAB400Remessa1Sicredi.Emissao] = "A"; // O padrão é que a emissão seja feito no cliente ("B") regBoleto[CNAB400Remessa1Sicredi.Alteracao] = "C"; // Desconto por dia de antecipação; // Para que o Sicred poste o boleto tem que mudar o padrão abaixo regBoleto[CNAB400Remessa1Sicredi.TipoPostagem] = "S"; regBoleto[CNAB400Remessa1Sicredi.Emissao] = "A"; } }
public bool Process(Stream stream) { int nErros = 0; Encoding enc = Encoding.GetEncoding(CobUtil.DefaultEncoding); string cLine; int n = 0; IReg reg = null; Dictionary <string, IReg> regCache = new Dictionary <string, IReg>(); try { using (StreamReader sr = new StreamReader(stream, enc)) { while ((cLine = sr.ReadLine()) != null) { n++; //#if !DEVELOPER // if (n % 100 == 0) // Thread.CurrentThread.MonitorStatus(100, "Conteudo {0}", (int)(100 * sr.BaseStream.Position / sr.BaseStream.Length)); //#endif //continue; if (!this.FindReg(ref reg, cLine)) { continue; } try { reg.Line = cLine; if (onAfterReadLine != null) { // Assim é possivel manipular o cada objeto lido onAfterReadLine(this, reg); } itens.Add(reg); } catch (ThreadAbortException) { } catch (Exception ex) { Exception e = ex; string cErro = string.Format("Erro no registro tipo '{0}' linha {1}: '{2}':\r\n", reg.NameType.Name, n, cLine); while (e != null) { cErro += e.Message + "\r\n"; e = e.InnerException; } if (nErros++ > 10) { break; } //if (ex.Data.Contains("Layout.Cancel")) // n = cLines.Length; if (onInvalidLine != null) { onInvalidLine(this, cErro, -1); //TODO: inserir a Exception! } else { throw new Exception(cErro, ex); } } } } return(true); } catch (Exception) { return(false); } }
/// <summary> /// Adiciona um item /// </summary> /// <param name="oReg">Objeto Reg[T]</param> public virtual void Add(IReg oReg) { itens.Add(oReg); }
// ************************************************************************* // ************************************************************************* // Engine Runtime // ************************************************************************* public void Run() { //Log.Information("SAP1Emu: Begin Engine Run"); //Log.Verbose("SAP1Emu: Initializing Registers"); Clock clock = new Clock(); TicTok tictok = new TicTok(); tictok.Init(); AReg areg = new AReg(); BReg breg = new BReg(); IReg ireg = new IReg(); OReg oreg = new OReg(); RAM ram = new RAM(); PC pc = new PC(ref areg); ALU alu = new ALU(ref areg, ref breg); MReg mreg = new MReg(ref ram); SEQ seq = SEQ.Instance(); Wbus.Instance().Value = "00000000"; Flags.Instance().Clear(); areg.Subscribe(clock); breg.Subscribe(clock); ireg.Subscribe(clock); mreg.Subscribe(clock); oreg.Subscribe(clock); pc.Subscribe(clock); alu.Subscribe(clock); // ALU must come after A and B ram.Subscribe(clock); // Log.Verbose("SAP1Emu: Initialized Registers"); // Log.Information("SAP1Emu: Loading Ram"); // Load the program into the RAM ram.LoadProgram(Program); // Log.Information("SAP1Emu: RAM:\n{RAM}", Program.RamContents); // Load the intsructionSet into the SEQ seq.Load(InstructionSet); // Log.Information($"SAP1Emu: Loaded Instruction Set: \"{InstructionSet.SetName}\""); Frame tempFrame; #region Program_Exec // Since T1-T3 for all of the Intruction is the same, // LDA or "0000" will be used as the intruction for all T1-T3's clock.IsEnabled = true; // TODO: Cleanup old code stubs // These vars will make sure that the engine will not hang if there is an infinite loop // int warning1_loop_counter = 3000; // int warning2_loop_counter = 5000; // int warning3_loop_counter = 7000; // int warning4_loop_counter = 9000; int max_loop_count = 10000; int loop_counter = 0; int TState = 1; // Log.Information("SAP1Emu: Start Program Execution"); while (clock.IsEnabled) { if (TState <= 3) { seq.UpdateControlWordReg(TState, "0000"); } else { seq.UpdateControlWordReg(TState, ireg.ToString()); } // Log the Instruction if (TState == 4) { string iname = InstructionSet.Instructions.Find(x => x.BinCode.Equals(ireg.ToString())).OpCode; int operandVal = Convert.ToInt32(ireg.ToString_Frame_Use().Substring(4, 4), 2); string hexOperand = "0x" + operandVal.ToString("X"); // Log.Information($"SAP1Emu: Instruction: {iname}, Operand: {hexOperand}"); } clock.SendTicTok(tictok); tictok.ToggleClockState(); clock.SendTicTok(tictok); tictok.ToggleClockState(); tempFrame = new Frame(ireg.ToString(), TState, areg, breg, ireg, mreg, oreg, pc, alu, ram.RAMDump(), ram, seq, Wbus.Instance().ToString(), Flags.Instance(), _decoder, InstructionSet.SetName); _FrameStack.Add(tempFrame); if (ireg.ToString() == "1111" && TState == 6) { // Log.Information("SAP1Emu: HLT Detected"); clock.IsEnabled = false; } // Infinite Loop Checks //if(loop_counter == warning1_loop_counter) //{ // Log.Warning($"SAP1Emu: Infinite Loop Warning: interations count: {warning1_loop_counter} "); //} //else if (loop_counter == warning2_loop_counter) //{ // Log.Warning($"SAP1Emu: Infinite Loop Warning: interations count: {warning2_loop_counter} "); //} //else if (loop_counter == warning3_loop_counter) //{ // Log.Warning($"SAP1Emu: Infinite Loop Warning: interations count: {warning3_loop_counter} "); //} //else if (loop_counter == warning4_loop_counter) //{ // Log.Warning($"SAP1Emu: Infinite Loop Warning: interations count: {warning4_loop_counter} "); //} if (loop_counter >= max_loop_count) { // Log.Fatal($"SAP1Emu: Infinite Loop Fatal Error: Infinite Loop Detected"); // Log.CloseAndFlush(); throw new EngineRuntimeException("Engine Error: Infinite Loop Detected"); } else { loop_counter++; } if (TState < 6) { TState++; } else { TState = 1; } } // Log.Information("SAP1Emu: End Program Execution"); OutPutRegContents = oreg.ToString(); // Log.Information("SAP1Emu: End Engine Run"); // Log.CloseAndFlush(); #endregion Program_Exec }