private void Convert_Button_Click(object sender, RoutedEventArgs e)
        {
            if (ComboBox_IntialNumericSystem.SelectedItem == null ||
                string.IsNullOrEmpty(TextBox_InitialNumber.Text))
            {
                MessageBox.Show("Missing data in fields!");
            }
            else
            {
                NumericSystems intialNumericSystem = (NumericSystems)ComboBox_IntialNumericSystem.SelectedItem;
                Validator      validator           = new Validator(intialNumericSystem, TextBox_InitialNumber.Text);

                if (validator.isValidate())
                {
                    FloatingNumberConvertor convertor = validator.GetFloatingNumberConvertor();

                    var(str, MachineCode) = convertor.Convert();
                    (MachineCode_TextBlock.Text, NumberResult_TextBlock.Text) = (MachineCode.ToString(), str);
                }
                else
                {
                    MessageBox.Show("Number is not validate to specified numeric system!");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 保存登录的cookies到文件
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static bool SaveLoginInfoCookies(string url)
        {
            string          tempFile        = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N");
            CookieContainer cookieContainer = ObjectHelper.ParseCookie(url);

            bool isSucceed = ObjectHelper.WriteCookiesToDisk(tempFile, cookieContainer);

            if (isSucceed)
            {
                // 加密密钥,增加机器码
                string password = SecretKey + MachineCode.GetMachineCodeString();

                try
                {
                    Encryptor.EncryptFile(tempFile, LOCAL_LOGIN_INFO, password);
                }
                catch (Exception e)
                {
                    Utils.Debugging.Console.PrintLine("SaveLoginInfoCookies()发生异常: {0}", e);
                    Logging.LogManager.Error(e);
                    return(false);
                }
            }

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
            return(isSucceed);
        }
        public void TestParseOp()
        {
            MachineCode mc = new MachineCode();

            ParseOpElement[] ops = new ParseOpElement[]
            {
                new ParseOpElement("2#0", 0, op_type.OP_CONB),
                new ParseOpElement("2#1", 1, op_type.OP_CONB),
                new ParseOpElement("false", 0, op_type.OP_CONB),
                new ParseOpElement("fAlSe", 0, op_type.OP_CONB),
                new ParseOpElement("true", 1, op_type.OP_CONB),
                new ParseOpElement("tRuE", 1, op_type.OP_CONB),
                new ParseOpElement("-5", -5, op_type.OP_CONW),
                new ParseOpElement("2#0110", 6, op_type.OP_CONW),
                new ParseOpElement("8#770", 504, op_type.OP_CONW),
                new ParseOpElement("16#AEAE", 44718, op_type.OP_CONW),
                new ParseOpElement("2", 2, op_type.OP_CONW),
                new ParseOpElement("0", 0, op_type.OP_CONW),
                new ParseOpElement("8#0", 0, op_type.OP_CONW),
                new ParseOpElement("16#0", 0, op_type.OP_CONW),
            };
            for (int i = 0; i < ops.Length; i++)
            {
                Assert.AreEqual(ops[i].typ, mc.decodeOpType(ops[i].op));
                Assert.AreEqual(ops[i].expected, mc.parseOperand(ops[i].typ, ops[i].op));
            }
        }
Beispiel #4
0
        public AuthController()
        {
            string machineCode = MachineCode.GetMachineCode(false, false);

            machineCode         = DESEncrypt.Encrypt(machineCode);
            ViewBag.MachineCode = "机器码:" + machineCode;
        }
Beispiel #5
0
        /// <summary>
        /// 保存登录的cookies到文件
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public bool SaveLoginInfoCookies(string url)
        {
            if (!Directory.Exists(Common.ConfigPath))
            {
                Directory.CreateDirectory(Common.ConfigPath);
            }

            string          tempFile        = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N");
            CookieContainer cookieContainer = Utils.ParseCookie(url);

            bool isSucceed = Utils.WriteCookiesToDisk(tempFile, cookieContainer);

            if (isSucceed)
            {
                // 加密密钥,增加机器码
                string password = SecretKey + MachineCode.GetMachineCodeString();

                try
                {
                    Encryptor.EncryptFile(tempFile, LOCAL_LOGIN_INFO, password);
                }
                catch (Exception e)
                {
                    Console.WriteLine("SaveLoginInfoCookies()发生异常: {0}", e);
                    return(false);
                }
            }

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
            return(isSucceed);
        }
Beispiel #6
0
        /// <summary>
        /// Register Button Click
        /// </summary>
        protected void RegisterBtn_Click(object sender, DirectEventArgs e)
        {
            try {
                MachineCode.Clear();
                UserLimitLbl.Text = String.Empty;
                ExpiredLbl.Text   = String.Empty;
                RemarkLbl.Text    = String.Empty;
                LicenseCode.Clear();
                var sp = new BUser().GetSysParams(20000001);
                if (sp != null && sp.Count > 0)
                {
                    var mcode = sp[0].ParaDisplay;
                    var lcode = sp[0].Note;
                    if (!String.IsNullOrEmpty(mcode))
                    {
                        MachineCode.Text = mcode;
                        if (Regex.IsMatch(mcode, @"^[a-fA-F0-9]{32}$"))
                        {
                            if (!String.IsNullOrEmpty(lcode))
                            {
                                var dl = WebUtility.GetDecryptLicense(lcode, mcode);
                                if (dl != null)
                                {
                                    UserLimitLbl.Text = String.Format("最多允许{0}个用户同时在线", dl.MaxUsers);
                                    ExpiredLbl.Text   = new DateTime(dl.Expiration) == new DateTime(2099, 12, 31) ? "永不过期" : WebUtility.GetDateString(new DateTime(dl.Expiration));
                                    RemarkLbl.Text    = new DateTime(dl.Expiration) >= DateTime.Today ? String.Format("产品已注册给: {0} - {1}", dl.Name, dl.Company) : "产品注册已过期";
                                }
                                else
                                {
                                    RemarkLbl.Text = "注册码无效";
                                }
                            }
                            else
                            {
                                RemarkLbl.Text = "产品未注册";
                            }
                        }
                        else
                        {
                            RemarkLbl.Text = "机器标识码格式错误";
                        }
                    }
                    else
                    {
                        RemarkLbl.Text = "未获得机器标识码";
                    }
                }
                else
                {
                    RemarkLbl.Text = "未获得注册信息";
                }

                RegisterFormPanel.ClearInvalid();
                RegisterWnd.Show();
            } catch (Exception err) {
                WebUtility.WriteLog(EnmSysLogLevel.Error, EnmSysLogType.Exception, err.ToString(), Page.User.Identity.Name);
                WebUtility.ShowMessage(EnmErrType.Error, err.Message);
            }
        }
Beispiel #7
0
        public void Plus_1()
        {
            MachineCode code_1 = new MachineCode("0 1111000 11001");
            MachineCode code_2 = new MachineCode("0 1111000 110100");

            var result_code = MachineCalculator.Plus(code_1, code_2);

            Assert.AreEqual("0 1111000 1001101", result_code.ToString());
        }
Beispiel #8
0
    private void SetMemoryIndex(MachineCode mc, string input, bool isSource)
    {
        int    val      = 0;
        string sval     = "";
        bool   isNumber = false;

        Char[] subChar   = input.ToCharArray();
        string subString = "";

        for (int i = 0; i < subChar.Length; i++)
        {
            if (subChar[i] != 'm' && subChar[i] != 'M' && subChar[i] != ']' && subChar[i] != '[')
            {
                subString += subChar[i];
            }
        }

        CompileType type = GetType(subString);

        if (type == CompileType.Number)
        {
            int.TryParse(subString, out val);
            isNumber = true;
        }

        if (type == CompileType.Register)
        {
            sval     = subString;
            isNumber = false;
        }

        if (isNumber)
        {
            if (isSource)
            {
                mc.sourceMemoryIndex = val;
            }
            else
            {
                mc.destMemoryIndex = val;
            }
        }
        else
        {
            if (isSource)
            {
                mc.isSourceMemoryIndexIsRegister = true;
                mc.sourceRegister = GetRegisterIndex(sval);
            }
            else
            {
                mc.isDestMemoryIndexIsRegister = true;
                mc.destRegister = GetRegisterIndex(sval);
            }
        }
    }
        public void TestCompileLines()
        {
            MachineCode mc = new MachineCode();

            CodeList[] lines = new CodeList[]
            {
                new CodeList("RTRIG", "MW0.0", 0x2400000080),
            };
            for (int i = 0; i < lines.Length; i++)
            {
                Assert.AreEqual(lines[i].excepted, mc.decodeLine(lines[i].linia), string.Format("Błąd kompilacji, oczekiwano: {0}, \notrzymano: {1}", lines[i].excepted.ToString("X"), mc.decodeLine(lines[i].linia).ToString("X")));
            }
        }
        public static string BackConvert(MachineCode code)
        {
            var binary_code = code.binary_code;
            var count       = binary_code.Length - 1 - (MatrixTransformations.GetNumberFromBinary(code.displace) - 127);

            if (count > 0)
            {
                return(Displace(MatrixTransformations.GetStringNumberFromMatrix(binary_code.Reverse()), -count));
            }
            else
            {
                return(Displace("0." + MatrixTransformations.GetStringNumberFromMatrix(binary_code.Reverse()), count));
            }
        }
Beispiel #11
0
    /// <summary>
    /// 重新登陆
    /// </summary>
    void reLogin()
    {
        //已经登陆需要重新登陆
        Debug.Print("发送重新登陆请求...");
        LoginDTO dto = new LoginDTO();

        dto.email    = PlayerPrefs.GetString("account");  // GameInfo.ACC_ID;
        dto.passWord = PlayerPrefs.GetString("passWord"); // GameInfo.ACC_PSD;
        dto.uniq     = MachineCode.GetMachineCodeString();
        string message = Coding <LoginDTO> .encode(dto);

        // Debug.Print(message);
        sendMessage(Protocol.LOGIN, 0, LoginProtocol.RELOGIN_CREQ, message);
    }
 protected void Application_Start()
 {
     RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     AreaRegistrationOrder.RegisterAllAreasOrder();
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     XmlConfigurator.Configure();
     //定时任务
     //JobScheduler.Start();
     //简单机器码
     JeasuHelper.ThisMachineCode = Common.SecureHelper.MD5(MachineCode.GetMachineCodeString());
 }
Beispiel #13
0
        public void DisplaceMachineCode()
        {
            MachineCode code_1 = new MachineCode("0 1111000 110110");
            MachineCode code_2 = new MachineCode("0 1111010 110110");

            var(new_code_1, new_code_2) = MachineCodeFormatter.SetCommonDisplace(code_1, code_2);

            Assert.AreEqual("00011011",
                            string.Join("", new_code_1.binary_code.Select(x => x ? 1 : 0)));

            Assert.AreEqual("0101111",
                            string.Join("", new_code_1.displace.Select(x => x ? 1 : 0)));

            Assert.AreEqual("011011",
                            string.Join("", new_code_2.binary_code.Select(x => x ? 1 : 0)));
        }
        public void TestDecodeOp()
        {
            MemoryMap   map = new MemoryMap();
            MachineCode mc  = new MachineCode();

            for (int i = 0; i < 256; i++)
            {
                if (map.cells[i].address > 0x7F)
                {
                    Assert.AreEqual(op_type.OP_MEMB, mc.decodeOpType(map.cells[i].name), string.Format("Błąd dekodowania operandu {0}", map.cells[i].name));
                }
                else
                {
                    Assert.AreEqual(op_type.OP_MEMW, mc.decodeOpType(map.cells[i].name), string.Format("Błąd dekodowania operandu {0}", map.cells[i].name));
                }
            }
            Assert.AreEqual(op_type.OP_OV, mc.decodeOpType("OV"), "Błąd dekodowania operandu OV");
        }
        public void SaveLog(string _adminid, string _type, string _name, Decimal _money, string _remark)
        {
            string clientIp = IPHelp.ClientIP;
            string mnum     = MachineCode.getMNum();

            using (DbOperHandler dbOperHandler = new ComData().Doh())
            {
                dbOperHandler.Reset();
                dbOperHandler.AddFieldItem("UserId", (object)_adminid);
                dbOperHandler.AddFieldItem("ActiveType", (object)_type);
                dbOperHandler.AddFieldItem("ActiveName", (object)_name);
                dbOperHandler.AddFieldItem("InMoney", (object)_money);
                dbOperHandler.AddFieldItem("Remark", (object)_remark);
                dbOperHandler.AddFieldItem("STime", (object)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                dbOperHandler.AddFieldItem("CheckIp", (object)clientIp);
                dbOperHandler.AddFieldItem("CheckMachine", (object)mnum);
                dbOperHandler.Insert("Act_ActiveRecord");
            }
        }
Beispiel #16
0
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Label != null)
            {
                stringBuilder.Append(Label);
                stringBuilder.Append(":\r\n");
            }
            stringBuilder.Append("    ");
            stringBuilder.Append(Address);
            stringBuilder.Append(" ");
            stringBuilder.Append(MachineCode.PadRight(12, ' '));
            stringBuilder.Append(" ");
            stringBuilder.Append(Source.PadRight(11, ' '));
            if (Remarks != null && Remarks.Trim() != "")
            {
                stringBuilder.Append(" ; ");
                stringBuilder.Append(Remarks);
            }

            return(stringBuilder.ToString());
        }
Beispiel #17
0
        /// <summary>
        /// 获得登录的cookies
        /// </summary>
        /// <returns></returns>
        public static CookieContainer GetLoginInfoCookies()
        {
            string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N");

            if (File.Exists(LOCAL_LOGIN_INFO))
            {
                try
                {
                    // 加密密钥,增加机器码
                    string password = SecretKey + MachineCode.GetMachineCodeString();
                    Encryptor.DecryptFile(LOCAL_LOGIN_INFO, tempFile, password);
                }
                catch (Exception e)
                {
                    Utils.Debugging.Console.PrintLine("GetLoginInfoCookies()发生异常: {0}", e);
                    Logging.LogManager.Error(e);
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            CookieContainer cookies = ObjectHelper.ReadCookiesFromDisk(tempFile);

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
            return(cookies);
        }
Beispiel #18
0
        public bool Login(string UserName, string PassWord)
        {
            CommClient.Employee login = new CommClient.Employee();

            try
            {
                var tem = login.Authenticate(UserName, PassWord, MachineCode.GetMachineCodeString());
                if (tem == null)
                {
                    return(false);
                }
                else
                {
                    this.CurrentUser = tem;
                    return(true);
                }
            }
#pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过
            {
                return(false);
            }
        }
Beispiel #19
0
    public void InstructionPerClock()
    {
        int source = 1, dest = 1, result = 1;

        if (machineCodes == null)
        {
            Debug.Log("CPU Error");
            error.cpuError = CPUError.NotDefinedMachineCode;
            return;
        }

        if (machineCodes.Count <= register.ip)
        {
            Debug.Log("CPU Error");
            error.cpuError = CPUError.IndexOutOfRangeFromInstructions;
            isRun          = false;
            return;
        }

        //fetch Machine Code
        currentCode  = machineCodes[register.ip];
        register.ip += 1;

        Debug.Log("-----------------------");
        Debug.Log("Instruction:" + currentCode.instruction + " Mode:" + currentCode.mode);
        Debug.Log("AX:" + register.ax + " BX:" + register.bx);
        Debug.Log("SP:" + register.sp + " IP:" + register.ip);

        //decoding the instructions and execute
        switch (currentCode.instruction)
        {
        case Instructions.MOV:
            GetDataSource(ref source);
            SetData(source);
            break;

        case Instructions.PUSH:
            memory.SetData(register.sp, currentCode.value, error);
            register.sp += 1;
            break;

        case Instructions.POP:
            result = memory.GetData(register.sp, error);
            SetData(result);
            register.sp--;
            break;

        case Instructions.INC:
            GetDataDest(ref source);
            result = source + 1;
            SetData(result);
            break;

        case Instructions.DEC:
            GetDataDest(ref source);
            result = source - 1;
            SetData(result);
            break;

        case Instructions.ADD:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source + dest;
            SetData(result);
            break;

        case Instructions.SUB:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            source = -source;
            result = source + dest;
            SetData(result);
            break;

        case Instructions.MUL:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source * dest;
            SetData(result);
            break;

        case Instructions.XOR:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source ^ dest;
            SetData(result);
            break;

        case Instructions.OR:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source | dest;
            SetData(result);
            break;

        case Instructions.AND:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source & dest;
            SetData(result);
            break;

        case Instructions.SAL:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source << dest;
            SetData(result);
            break;

        case Instructions.SAR:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source >> dest;
            SetData(result);
            break;

        case Instructions.CMP:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            source = -source;
            result = source + dest;
            break;

        case Instructions.TEST:
            GetDataSource(ref source);
            GetDataDest(ref dest);
            result = source & dest;
            break;

        case Instructions.JMP:
            GetDataSource(ref result);
            register.ip = result;
            break;

        case Instructions.JE:
            if (register.zf)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JNE:
            if (!register.zf)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JS:
            if (register.sf)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JNS:
            if (!register.sf)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JG:
            if (!(register.sf ^ register.of) & !register.zf)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JGE:
            if (!(register.sf ^ register.of))
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JL:
            if (register.sf ^ register.of)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.JLE:
            if ((register.sf ^ register.of) | register.zf)
            {
                GetDataSource(ref result);
                register.ip = result;
            }
            break;

        case Instructions.END:
            isRun = false;
            break;

        default:
            error.cpuError = CPUError.NotDefinedMachineCode;
            isRun          = false;
            break;
        }

        register.SetCarryFlag(result, dest, source);
    }
Beispiel #20
0
        /// <summary>
        /// 获得登录的cookies
        /// </summary>
        /// <returns></returns>
        public CookieContainer GetLoginInfoCookies()
        {
            string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N");

            if (File.Exists(LOCAL_LOGIN_INFO))
            {
                try
                {
                    // 加密密钥,增加机器码
                    string password = SecretKey + MachineCode.GetMachineCodeString();
                    Encryptor.DecryptFile(LOCAL_LOGIN_INFO, tempFile, password);
                }
                catch (CryptoHelpException e)
                {
                    Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e);
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    return(null);
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e);
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    return(null);
                }
                catch (DirectoryNotFoundException e)
                {
                    Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e);
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    return(null);
                }
                catch (Exception e)
                {
                    Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e);
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            CookieContainer cookies = Utils.ReadCookiesFromDisk(tempFile);

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
            return(cookies);
        }
Beispiel #21
0
    private void SetMachineCode(MachineCode mc, string instruction, string input1, string input2)
    {
        //setting instruction
        error.NotDefinedInstruction |= !Enum.TryParse(instruction.ToUpper(), out mc.instruction);

        //setting mode and following settings
        CompileType type1 = GetType(input1);
        CompileType type2 = GetType(input2);

        if (type1 == CompileType.Register && type2 == CompileType.Register)
        {
            mc.mode           = CPUMode.RegisterToRegister;
            mc.sourceRegister = GetRegisterIndex(input1);
            mc.destRegister   = GetRegisterIndex(input2);
        }
        else if (type1 == CompileType.Register && type2 == CompileType.Memory)
        {
            mc.mode           = CPUMode.RegisterToMemory;
            mc.sourceRegister = GetRegisterIndex(input1);
            SetMemoryIndex(mc, input2, false);
        }
        else if (type1 == CompileType.Register && type2 == CompileType.Number)
        {
            mc.mode           = CPUMode.RegisterToNumber;
            mc.sourceRegister = GetRegisterIndex(input1);
            mc.value          = GetValue(input2);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Number)
        {
            mc.mode = CPUMode.MemoryToNumber;
            SetMemoryIndex(mc, input1, true);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Register)
        {
            mc.mode         = CPUMode.MemoryToRegister;
            mc.destRegister = GetRegisterIndex(input2);
            SetMemoryIndex(mc, input1, true);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Memory)
        {
            mc.mode = CPUMode.MemoryToMemory;
            SetMemoryIndex(mc, input1, true);
            SetMemoryIndex(mc, input2, false);
        }
        else if (type1 == CompileType.Memory && type2 == CompileType.Noting)
        {
            mc.mode = CPUMode.MemoryOnly;
            SetMemoryIndex(mc, input1, true);
        }
        else if (type1 == CompileType.Register && type2 == CompileType.Noting)
        {
            mc.mode           = CPUMode.RegisterOnly;
            mc.sourceRegister = GetRegisterIndex(input1);
        }
        else if (type1 == CompileType.Number && type2 == CompileType.Register)
        {
            mc.mode         = CPUMode.NumberToRegister;
            mc.value        = GetValue(input1);
            mc.destRegister = GetRegisterIndex(input2);
        }
        else if (type1 == CompileType.Number && type2 == CompileType.Memory)
        {
            mc.mode  = CPUMode.NumberToMemory;
            mc.value = GetValue(input1);
            SetMemoryIndex(mc, input2, false);
        }
        else if (type1 == CompileType.Number && type2 == CompileType.Noting)
        {
            mc.mode  = CPUMode.NumberOnly;
            mc.value = GetValue(input1);
        }
        else if (type1 == CompileType.Noting && type2 == CompileType.Noting)
        {
            mc.mode = CPUMode.Noting;
        }
        else
        {
            error.SetModeError = true;
            mc.mode            = CPUMode.Noting;
        }
    }
Beispiel #22
0
        public void CodeFormat()
        {
            MachineCode code_1 = new MachineCode("0 1111000 11001");

            Assert.AreEqual("10011", string.Join("", code_1.binary_code.Select(x => x ? 1 : 0)));
        }
 public Part1()
 {
     machineCodeRepository = new MachineCodeRepository();
     machineCode           = new MachineCode();
 }
Beispiel #24
0
 private void btnGet_Click(object sender, EventArgs e)
 {
     textBox1.Text =
         MachineCode.getInstance().Hash;
 }
Beispiel #25
0
        public void ParserTest()
        {
            var parser = new MachineCodeParser();
            var mc     = new MachineCode();

            parser.Process("G0 F4800 E-1.0000", mc);

            Assert.AreEqual(mc.Linenumber, 0);

            Assert.AreEqual(mc.Command.Code, "G");
            Assert.AreEqual(mc.Command.Value, 0);

            Assert.AreEqual(mc.Parameters.Count, 2);

            Assert.AreEqual(mc.Parameters[0].Code, "F");
            Assert.AreEqual(mc.Parameters[0].Value, 4800);
            Assert.AreEqual(mc.Parameters[1].Code, "E");
            Assert.AreEqual(mc.Parameters[1].Value, -1.0);

            parser.Process("G0 F4800 E+1.00", mc);

            Assert.AreEqual(mc.Parameters[1].Code, "E");
            Assert.AreEqual(mc.Parameters[1].Value, 1.0);

            parser.Process("K1 X107.256 Y119.925 E 5.6946", mc);

            Assert.AreEqual(mc.Command.Code, "K");
            Assert.AreEqual(mc.Command.Value, 1);

            Assert.AreEqual(mc.Parameters.Count, 3);

            Assert.AreEqual(mc.Parameters[0].Code, "X");
            Assert.AreEqual(mc.Parameters[0].Value, 107.256);
            Assert.AreEqual(mc.Parameters[1].Code, "Y");
            Assert.AreEqual(mc.Parameters[1].Value, 119.925);
            Assert.AreEqual(mc.Parameters[2].Code, "E");
            Assert.AreEqual(mc.Parameters[2].Value, 5.6946);

            parser.Process("N2999   M55   F480 f ; E7.6855", mc);

            Assert.AreEqual(mc.Linenumber, 2999);

            Assert.AreEqual(mc.Command.Code, "M");
            Assert.AreEqual(mc.Command.Value, 55);

            Assert.AreEqual(mc.Parameters.Count, 1);

            Assert.AreEqual(mc.Parameters[0].Code, "F");
            Assert.AreEqual(mc.Parameters[0].Value, 480);

            parser.Process(";  G0 X109.762 Y122.431 F7800", mc);

            Assert.AreEqual(mc.Linenumber, 0);

            Assert.AreEqual(mc.Command.Code, null);
            Assert.AreEqual(mc.Command.Value, 0);

            Assert.AreEqual(mc.Parameters.Count, 0);

            parser.Process("G0 X109.762 X109.762 X109.762 X109.762 X109.762 Y122.431 F7800", mc);

            Assert.AreEqual(mc.Parameters.Count, 7);
        }