public void CarDateInvalidTest(int d, int m, int y, int price, string brandName) { var cars = new[] { new CarEntityWithoutConstraits() { BrandName = "TestBrand", Price = 200, Day = 2, Month = 2, Year = 2017 }, new CarEntityWithoutConstraits() { BrandName = brandName, Price = price, Day = d, Month = m, Year = y }, }; var stream = MakeTestStream(cars); var converter = new BinConverter(); Assert.That(() => converter.ConvertFromStream(stream), Throws.Exception.With.Message.EqualTo("Date is incorrect")); }
public string OutputRegister() { StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); int unsigned_ouput = BinConverter.Bin8ToInt(OPort1); int signed_output = 0; if (OPort1 != null) { if (OPort1.StartsWith('1')) { signed_output = -1 * (255 - unsigned_ouput + 1); } else { signed_output = unsigned_ouput; } } if (string.IsNullOrEmpty(OPort1)) { OPort1 = "00000000"; } tw.WriteLine($"************************************************************");//60 tw.WriteLine($"* Output: {OPort1}".PadRight(47) + "*"); tw.WriteLine("************************************************************"); tw.Flush(); return(sb.ToString()); }
public void Exec(TicTok tictok) { var cw = SEQ.Instance().ControlWord; // Active Hi, Count on Tic if (string.Equals(cw["CP"], "1", StringComparison.Ordinal) && tictok.ClockState == TicTok.State.Tic) { int count = BinConverter.Bin8ToInt(RegContent); count++; RegContent = BinConverter.IntToBin16(count); } // Active Hi, Push on Tic if (string.Equals(cw["EP"], "1", StringComparison.Ordinal) && tictok.ClockState == TicTok.State.Tic) { // Send PC to the WBus Wbus.Instance().Value = RegContent; } // Active Low - Broadside Load, Pull if (string.Equals(cw["LP_"], "0", StringComparison.Ordinal) && tictok.ClockState == TicTok.State.Tok) { RegContent = Wbus.Instance().Value; } }
public void SkipByte() { // Add one to skip the other byte because it does and i dont wanna deal with it any other way int count = BinConverter.Bin8ToInt(RegContent); count++; RegContent = BinConverter.IntToBin16(count); }
private void ButtonFinish(object sender, EventArgs e) { string ip = ((Content as StackLayout).Children[2] as Entry).Text; int port = Convert.ToInt32(((Content as StackLayout).Children[4] as Entry).Text); TcpClient client = null; try { client = new TcpClient(ip, port); NetworkStream stream = client.GetStream(); string message = "Hello"; // преобразуем сообщение в массив байтов byte[] data = Encoding.Unicode.GetBytes(message); // отправка сообщения stream.Write(data, 0, data.Length); // получаем ответ List <byte> fulldata = new List <byte>(); data = new byte[64]; // буфер для получаемых данных int bytes = 0; do { bytes = stream.Read(data, 0, data.Length); for (int i = 0; i < bytes; i++) { fulldata.Add(data[i]); } }while (stream.DataAvailable); publicKey = (RSAParameters)BinConverter.ByteArrayToObject(fulldata.ToArray()); byte[] res = Save(); stream.Write(res, 0, res.Length); stream.Write(cryptKey, 0, cryptKey.Length); DisplayAlert("Успех", "Данные успешно отправлены", "ОK"); } catch (Exception ex) { DisplayAlert("ОШИБКА", ex.Message, "ОK"); InitStartScreen(); } finally { client.Close(); InitStartScreen(); } }
//************************************************************************************************************************ //************************************************************************************************************************ public static string Compute(string AReg, string BReg, bool Add = true) { const int MAX_RESULT = 255; const int MIN_RESULT = 0; int ia = BinConverter.Bin8ToInt(AReg); int ib = BinConverter.Bin8ToInt(BReg); int result; if (Add) { result = ia + ib; // Set Flags if (result > MAX_RESULT && FlagEnable) { Flags.Instance().Clear(); Flags.Instance().Overflow = 1; } else if (result == 0 && FlagEnable) { Flags.Instance().Clear(); Flags.Instance().Zero = 1; } } else // SUB { result = ia - ib; // Set Flags if (result < MIN_RESULT && FlagEnable) { Flags.Instance().Clear(); Flags.Instance().Underflow = 1; } else if (result == 0 && FlagEnable) { Flags.Instance().Clear(); Flags.Instance().Zero = 1; } } string val = BinConverter.IntToBin8(result); return(val); }
// TODO - Repleace with something in the LIB OpCodeLoader // TODO - is the still used? I think I replaced this somewhere else in the code private string InstuctionDecode(string BinInstruction, int TState) { List <string> KnownInstructions = new List <string> { "LDA", "ADD", "SUB", "STA", "JMP", "JEQ", "", "", "", "JIC", "", "", "", "", "OUT", "HLT" }; string temp = KnownInstructions[BinConverter.Bin4ToInt(BinInstruction)]; if (TState < 4) { return("???"); } if (!string.IsNullOrEmpty(temp)) { return(temp); } else { return(BinInstruction); } }
public override string ToString() { StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); int unsigned_ouput = BinConverter.Bin8ToInt(OPort1); int signed_output = 0; if (OPort1 != null) { if (OPort1.StartsWith('1')) { signed_output = -1 * (255 - unsigned_ouput + 1); } else { signed_output = unsigned_ouput; } } tw.WriteLine($"***********************************************************************************");//82 tw.WriteLine($"* Instruction: {InstructionData.OpCode} TState: {TState}".PadRight(82) + "*"); tw.WriteLine($"***********************************************************************************"); tw.WriteLine($"* Input 1: {IPort1}".PadRight(35) + $"A Register: {AReg}".PadRight(47) + "*"); tw.WriteLine($"* Input 2: {IPort2}".PadRight(35) + $"ALU: {ALU} Flags: {Flags}".PadRight(47) + "*"); tw.WriteLine($"* PC: {PC}".PadRight(35) + $"Temp Register: {TReg}".PadRight(47) + "*"); tw.WriteLine($"* MAR: {MAR}".PadRight(35) + $"B Register: {BReg}".PadRight(47) + "*"); tw.WriteLine($"* RAM: {RAM_Reg}".PadRight(35) + $"C Register: {CReg}".PadRight(47) + "*"); tw.WriteLine($"* MDR: {MDR}".PadRight(35) + $"Output 3: {OPort1} Display: 0x{HexadecimalDisplay}".PadRight(47) + "*"); tw.WriteLine($"* I Register: {IReg}".PadRight(35) + $"Output 4: {OPort2}".PadRight(47) + "*"); tw.WriteLine($"* Sequencer: {SEQ} ".PadRight(82) + "*"); tw.WriteLine($"* BUS: {WBus} ".PadRight(82) + "*"); tw.WriteLine($"***********************************************************************************"); tw.WriteLine($"* Output Unsigned: {unsigned_ouput}".PadRight(82) + "*"); tw.WriteLine($"* Output Signed: {signed_output}".PadRight(82) + "*"); tw.WriteLine($"***********************************************************************************"); tw.Flush(); return(sb.ToString()); }
//************************************************************************************************************************ //************************************************************************************************************************ public string Compute(string AReg, string TReg, ALUOPType action = ALUOPType.ADD) { const int MAX_RESULT = 255; const int MIN_RESULT = 0; int ia = BinConverter.Bin8ToInt(AReg); int ib = BinConverter.Bin8ToInt(TReg); int result = 0; FlagContent = (int)FlagResult.None; switch (action) { case ALUOPType.ADD: result = ia + ib; break; case ALUOPType.SUB: result = ia - ib; break; case ALUOPType.AND: result = ia & ib; break; case ALUOPType.OR: result = ia | ib; break; case ALUOPType.XOR: result = ia ^ ib; break; case ALUOPType.CMA: result = ~ia; break; case ALUOPType.RAL: AReg = AReg[1..] + AReg[0];
public override string ToString() { StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); int unsigned_ouput = BinConverter.Bin8ToInt(OReg); int signed_output = 0; if (OReg != null) { if (OReg[0] == '1') { signed_output = -1 * (255 - unsigned_ouput + 1); } else { signed_output = unsigned_ouput; } } tw.WriteLine($"************************************************************");//60 tw.WriteLine($"* Instruction: {InstuctionDecode(IRegShort, TState)} TState: {TState} *"); tw.WriteLine("************************************************************"); tw.WriteLine($"* PC: {PC} A Register: {AReg}".PadRight(59) + "*"); tw.WriteLine($"* MAR: {MReg} B Register: {BReg}".PadRight(59) + "*"); tw.WriteLine($"* RAM: {RAM_Reg} ALU: {ALU}".PadRight(59) + "*"); tw.WriteLine($"* I Register: {IReg} Output Register: {OReg}".PadRight(59) + "*"); tw.WriteLine($"* Sequencer: {SEQ} ".PadRight(59) + "*"); tw.WriteLine($"************************************************************"); tw.WriteLine($"* Output Unsigned: {unsigned_ouput}".PadRight(59) + "*"); tw.WriteLine($"* Output Signed: {signed_output}".PadRight(59) + "*"); tw.WriteLine($"************************************************************"); tw.Flush(); return(sb.ToString()); }
public void Exec(TicTok tictok) { string cw = SEQ.Instance().ControlWord; // Active Hi, Count on Tic if (cw[0] == '1' && tictok.ClockState == TicTok.State.Tic) { int count = BinConverter.Bin8ToInt(RegContent); count++; RegContent = BinConverter.IntToBin8(count); } // Active Hi, Push on Tic if (cw[1] == '1' & tictok.ClockState == TicTok.State.Tic) { // Send A to the WBus Wbus.Instance().Value = RegContent; } // Active Low - Broadside Load, Pull if (cw[13] == '0' & tictok.ClockState == TicTok.State.Tok) { string count = Wbus.Instance().Value; if (count.Length >= 8) { count = "0000" + count.Substring(4, 4); } // The cw[14-16] is a 3-bit jump code that tells the PC which jump code to preform. // JMP == 000 // JEQ == 001 // JNQ == 010 // JLT == 011 // JGT == 100 // JIC == 101 string jump_code = cw.Substring(14, 3); // JMP if (jump_code == "000") { this.RegContent = count; } // JEQ else if (jump_code == "001") { if (areg.ToString() == "00000000") { this.RegContent = count; } } // JNQ else if (jump_code == "010") { if (areg.ToString() != "00000000") { this.RegContent = count; } } // JLT else if (jump_code == "011") { if (areg.ToString()[0] == '1') { this.RegContent = count; } } // JGT else if (jump_code == "100") { if (areg.ToString() != "00000000" && areg.ToString()[0] == '0') { this.RegContent = count; } } // JIC else if (jump_code == "101") { if (Flags.Instance().Overflow == 1) { this.RegContent = count; } } } }
private void GetData(NetworkStream stream) { RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); Aes aes = null; RSAParameters publicKey; RSAParameters privateKey; rsa.PersistKeyInCsp = false; publicKey = rsa.ExportParameters(false); privateKey = rsa.ExportParameters(true); byte[] data = BinConverter.ObjectToByteArray(publicKey); stream.Write(data, 0, data.Length); List <byte> fulldata = new List <byte>(); int bytes = 0; do { bytes = stream.Read(data, 0, data.Length); //builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); for (int i = 0; i < bytes; i++) { fulldata.Add(data[i]); } }while (stream.DataAvailable); List <byte> fullkey = new List <byte>(); bytes = 0; do { bytes = stream.Read(data, 0, data.Length); //builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); for (int i = 0; i < bytes; i++) { fullkey.Add(data[i]); } }while (stream.DataAvailable); byte[] key; rsa.PersistKeyInCsp = false; rsa.ImportParameters(privateKey); key = rsa.Decrypt(fullkey.ToArray(), true); string result = FromAes256(fulldata.ToArray(), key); Dictionary <string, string> ansver = JsonConvert.DeserializeObject <Dictionary <string, string> >(result); //рабоата с Excel Excel.Range Rng; Excel.Workbook xlWB; Excel.Worksheet xlSht; int iLastRow, iLastCol; Excel.Application xlApp = new Excel.Application(); //создаём приложение Excel xlWB = xlApp.Workbooks.Open(workingExcelFile); //открываем наш файл xlSht = xlWB.Worksheets["Лист1"]; //или так xlSht = xlWB.ActiveSheet //активный лист iLastRow = xlSht.Cells[xlSht.Rows.Count, "A"].End[Excel.XlDirection.xlUp].Row; //последняя заполненная строка в столбце А if (iLastRow == 1) { int j = 1; foreach (var col in ansver) { xlSht.Cells[1, j] = col.Key; xlSht.Cells[2, j] = col.Value; j++; } } else { int j = 1; foreach (var col in ansver) { xlSht.Cells[iLastRow + 1, j] = col.Value; j++; } } //закрытие Excel xlWB.Close(true); //сохраняем и закрываем файл xlApp.Quit(); }
private void InitDbSet() { // Select converter IConverter converter; switch (Type) { case DataTypeEnum.BIN: converter = new BinConverter(); break; case DataTypeEnum.CSV: converter = new CsvConverter(); break; //case DataTypeEnum.JSON: // converter = new JsonConverter(); // break; case DataTypeEnum.XML: converter = new XmlConverter(); break; default: converter = new XmlConverter(); break; } var props = GetType().GetProperties(); //var props = GetType().GetRuntimeProperties(); foreach (var prop in props) { if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(DbSet <>)) //if (prop.PropertyType.IsConstructedGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>)) { var value = prop.GetValue(this); if (value == null) { Type itemType = prop.PropertyType.GetGenericArguments()[0]; //Type itemType = prop.PropertyType.GenericTypeArguments[0]; var genericType = typeof(DbSet <>).MakeGenericType(new Type[] { itemType }); var instance = Activator.CreateInstance(genericType, new object[] { FilePath, FileType, converter, IsReadOnly }); prop.SetValue(this, instance); } //prop.PropertyType // Set db path with data for collection //value.GetType().GetMethod("SetDbPath").Invoke(value, new object[] { FilePath, FileType }); //// Set db converter for collection //value.GetType().GetMethod("SetDbConverter").Invoke(value, new object[] { converter }); //// Set db parameter IsReadOnly //value.GetType().GetMethod("SetIsReadOnly").Invoke(value, new object[] { IsReadOnly }); //value.GetType().GetMethod("SetAttributes").Invoke(value, new object[] {}); } } }
public static List <string> Parse(List <string> unchecked_assembly, string InstructionSetName = DefaultInstructionSetName) { // Get Instruction Set InstructionSet iset = OpCodeLoader.GetSet(InstructionSetName); // ********************************************************************* // Sanitize * // ********************************************************************* // Remove Blank Lines unchecked_assembly.RemoveAll(s => s == null); unchecked_assembly.RemoveAll(s => Regex.IsMatch(s, "^\\s*$")); // Remove Newline Comments unchecked_assembly.RemoveAll(s => s[0] == '#'); for (int i = 0; i < unchecked_assembly.Count; i++) { // ******************************* // Trim Whitespace * // ******************************* // Outter Whitespace unchecked_assembly[i] = unchecked_assembly[i].Trim(); // Inner Whitspace unchecked_assembly[i] = Regex.Replace(unchecked_assembly[i], "\\s{2,}", " "); // ******************************* // ******************************* // Remove Inline Comments // ******************************* unchecked_assembly[i] = Regex.Replace(unchecked_assembly[i], "\\s*#.*$", ""); // ******************************* } // ********************************************************************* // ********************************************************************* // Validate // ********************************************************************* //if is not valid, will throw execptions for CLI to catch and display to user _ = IsValid(unchecked_assembly, iset); // ********************************************************************* // ********************************************************************* // Assemble // ********************************************************************* List <string> binary = new List <string>(); int lines_of_asm = unchecked_assembly.Count; int current_line_number = 0; foreach (string line in unchecked_assembly) { if (line == "...") { int nop_count = 16 - lines_of_asm + 1; for (int i = 0; i < nop_count; i++) { binary.Add("00000000"); } } else { string upper_nibble_asm = line.Split(" ", 2)[0]; string lower_nibble_asm = line.Split(" ", 2)[1]; string upper_nibble_bin = ""; string lower_nibble_bin = ""; // Convert Upper Nibble if (InstructionValidator.IsValidInstruction(upper_nibble_asm, iset)) // Is instruction { upper_nibble_bin = InstructionValidator.GetUpperNibble(line.Substring(0, 3), iset); } else if (Regex.IsMatch(upper_nibble_asm, "^0[xX][0-9a-fA-F]$")) // Is Data { int value_upper = (int)(Convert.ToUInt32(upper_nibble_asm, 16)); upper_nibble_bin = BinConverter.IntToBin4(value_upper); } // Convert Lower Nibble int value_lower = (int)(Convert.ToUInt32(lower_nibble_asm, 16)); lower_nibble_bin = BinConverter.IntToBin4(value_lower); binary.Add(upper_nibble_bin + lower_nibble_bin); } current_line_number++; } // ********************************************************************* //If a program was executed, but didnt fill in every line of RAM then throw an exception. Must have 16 elements! if (binary.Count != 16) { throw new ParseException($"SAP1ASM: Program must have 16 lines.", new ParseException("Use \"NOP 0x0\" for a no-operation command or the \"...\" macro to fill in the rest with NOP 0x0.")); } return(binary); }