public void Add(string function, Operand destination = null, Operand source = null) { var item = new Instruct(function, destination, source); _insts.Add(item); length += item.Length; }
/// <summary> /// Loads the instructions from the instructions text file. /// </summary> /// <remarks> /// The format is /// # of instructs /// NNN /// Where NNN is the name /// </remarks> private static void LoadInstruct() { string filename = null; filename = SwinGame.PathToResource("instructions.txt"); StreamReader input = default(StreamReader); input = new StreamReader(filename); //Read in the # of instructs int numInstructs = 0; numInstructs = Convert.ToInt32(input.ReadLine()); _Instruct.Clear(); int i = 0; for (i = 1; i <= numInstructs; i++) { Instruct s = default(Instruct); string line = null; line = input.ReadLine(); s.Name = line.Substring(0); _Instruct.Add(s); } input.Close(); }
/// <summary> /// 呼叫字典中的方法以取得FrameObject /// </summary> /// <param name="userId">用戶id</param> /// <param name="instruct">按鈕功能組合</param> /// <returns>FrameObject</returns> public static FrameObject GetFrameObject(int userId, Instruct instruct) { if (!ActionDic.Keys.Contains(instruct.Feature)) { throw new Exception("無此Feature"); } return(ActionDic[instruct.Feature].Invoke(instruct.Content, userId)); }
/// <param name="Identifiers">标识</param> /// <param name="Server">服务器 IP 或名称</param> /// <param name="Port">端口</param> /// <param name="UserName">用户名</param> /// <param name="Password">密码</param> /// <param name="UseBinary">二进制传输</param> /// <param name="UsePassive">使用被动模式,注意:一般此变量设置为 false, 用主动模式</param> /// <param name="EnableSsl">使用 SSL 加密传输</param> /// <param name="TransferBufferSize">每次传输的缓冲区大小</param> /// <param name="LocalFileName">本地文件名</param> /// <param name="RemoteFileName">远程文件名</param> /// <param name="TransferDirection">传输方向</param> /// <param name="InitializationInstruct">初始化时的默认指令</param> public TaskItem(string Identifiers, string Server, int Port, string UserName, string Password, bool UseBinary, bool UsePassive, bool EnableSsl, int TransferBufferSize, string LocalFileName, string RemoteFileName, Direction TransferDirection, Instruct InitializationInstruct) { this._Identifiers = Identifiers; this._LocalFileName = LocalFileName; this._RemoteFileName = RemoteFileName; this._TransferDirection = TransferDirection; this._TransferInstruct = InitializationInstruct; ftp = new FtpClient(Server, Port, UserName, Password, UseBinary, UsePassive, EnableSsl, TransferBufferSize); ftp.OnTransfering += new FtpClient.TransferEventHandler(On_Transfering); }
/// <param name="identifiers">标识</param> /// <param name="server">服务器 IP 或名称</param> /// <param name="Port">端口</param> /// <param name="userName">用户名</param> /// <param name="password">密码</param> /// <param name="UseBinary">二进制传输</param> /// <param name="UsePassive">使用被动模式,注意:一般此变量设置为 false, 用主动模式</param> /// <param name="EnableSsl">使用 SSL 加密传输</param> /// <param name="TransferBufferSize">每次传输的缓冲区大小</param> /// <param name="localFileName">本地文件名</param> /// <param name="remoteFileName">远程文件名</param> /// <param name="transferDirection">传输方向</param> /// <param name="initializationInstruct">初始化时的默认指令</param> public TaskItem(string identifiers, string server, int Port, string userName, string password, bool UseBinary, bool UsePassive, bool EnableSsl, int TransferBufferSize, string localFileName, string remoteFileName, Direction transferDirection, Instruct initializationInstruct) { this._Identifiers = identifiers; this._LocalFileName = localFileName; this._RemoteFileName = remoteFileName; this._TransferDirection = transferDirection; this._TransferInstruct = initializationInstruct; ftp = new FtpClient(server, Port, userName, password, UseBinary, UsePassive, EnableSsl, TransferBufferSize); ftp.OnTransfering += new FtpClient.TransferEventHandler(On_Transfering); }
/// <summary> /// 呼叫字典中的方法以取得FrameObject /// </summary> /// <param name="userId">用戶id</param> /// <param name="instruct">按鈕功能組合</param> /// <returns>FrameObject</returns> public static FrameObject GetFrameObject(int userId, Instruct instruct) { if (!FeatureDic.Keys.Contains(instruct.Feature)) { throw new Exception("無此Feature"); } var featureConstructor = FeatureDic[instruct.Feature]; var feature = featureConstructor.Invoke(instruct.Content); var userinfo = Users.GetUserInfo(userId); return(feature.GetAnswer(userinfo)); }
public void Execute(InitialProcessData iPD) { iPD.Upload(MRT.Registers); do { int c = MRT.Registers[12]; MRT.Cache.Stream.Seek(c); b = Instruct.Pop(MRT.Cache.Stream); c += b.NCLength(); MRT.Registers[12] = c; UAL.BasicInstructions[b.Function](b.Desdestination, b.Source); } while (b.Function != 0); }
/// <summary> /// 拿取(Feature, Content)的api接口。回傳Panel與SubPanel的物件 /// </summary> /// <param name="userId">用戶ID</param> /// <returns>FrameResponse物件的JSON: 帶有Panel和SubPanel的字串</returns> public IHttpActionResult PostIntegrate(int userId) { //拿body中的Feature與Content。並存為Instruct物件 Instruct instruct = Request.Content.ReadAsAsync <Instruct>().Result; //向Feature類別索取FrameObject FrameObject frameObject = FeatureReactor.GetFrameObject(userId, instruct); //將response包成Json格式 JObject json = frameObject.ToJson <FrameObject>(); return(Ok(json)); }
private static void Exmp() { const string c = "mov [ebp+0x0000000],12;mov [ebp+0x0000004],11;mov [ebp+0x0000008],1;mov [ebp+0x000000c],1;mov [ebp+0x0000010],2;mov [ebp+0x0000014],6;add [ebp+0x0000000],[ebp+0x0000004];mov [ebp+0x0000018],eax;mul [ebp+0x0000008],[ebp+0x000000c];mov [ebp+0x000001c],eax;add [ebp+0x0000018],[ebp+0x000001c];mov [ebp+0x0000018],eax;sub [ebp+0x0000018],2;mov [ebp+0x0000018],eax;mul [ebp+0x0000010],[ebp+0x0000014];mov [ebp+0x000001c],eax;add [ebp+0x0000018],[ebp+0x000001c];mov [ebp+0x0000018],eax;add 0,1;mov [ebp+0x0000020],eax;add [ebp+0x0000020],2;mov [ebp+0x0000020],eax;add [ebp+0x0000020],3;mov [ebp+0x0000020],eax;add [ebp+0x0000020],4;mov [ebp+0x0000020],eax;add [ebp+0x0000020],5;mov [ebp+0x0000020],eax;add [ebp+0x0000020],6;mov [ebp+0x0000020],eax;add [ebp+0x0000020],7;mov [ebp+0x0000020],eax;add [ebp+0x0000020],8;mov [ebp+0x0000020],eax;add [ebp+0x0000020],9;mov [ebp+0x0000020],eax;inf [ebp+0x0000020],0;mov eax,eax;jmp [ebp+0x0000024];neg [ebp+0x0000028];mov [ebp+0x000002c],eax;mov [ebp+0x0000030],[ebp+0x000002c]"; var cc = c.Split(";\r\n".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); var MRT = new Component.Component(0xFFFFF); foreach (var d in cc) { Instruct.Parse(d).Push(MRT.Cache.Stream); } var e = 65635; MRT.Process.Execute(new VM.Global.InitialProcessData(0, e, e * 3, e * 2, e * 4, 0)); }
/// <summary> /// 发送指令 /// </summary> /// <param name="instruct"></param> public void AppendInstruct(Instruct instruct) { if (IsStop) { return; //完全终止 } instruct.ClientID = this.Client.ClientID; if (!instruct.IsSync) { SendInstructAsync(instruct); } else { SendInstruct(new Instruct[] { instruct }, true); } }
public void Execute(int instructionsPointer, int dataPointer, int stackPointer) { MRT.Registers["cs"] = instructionsPointer; MRT.Registers["sp"] = dataPointer; MRT.Registers["ss"] = stackPointer; Instruct b; do { int c = MRT.Registers[12]; MRT.Cache.Stream.Seek(instructionsPointer + c); b = Instruct.Pop(MRT.Cache.Stream); c += b.NCLength(); MRT.Registers[12] = c; UAL.BasicInstructions[b.Function](b.Desdestination, b.Source); } while (b.Function != 0); }
private static void ExtractMethode(StreamWriter c, MethodInfo method, ref string s) { var ee = new StreamReader(c); var a = new StringBuilder(method.MethodSize); ee.Seek(method.Offset); a.Append(s + "\r\n----------------" + method + "-----------------"); var end = method.MethodSize + method.Offset; do { var s1 = "\r\n" + ee.Offset.ToString("D4") + " :"; Instruct g = Instruct.Pop(ee); a.Append(s1 + g); } while (ee.Offset < end); a.Append("\r\n----------------" + "************************" + "-----------------"); s = a.ToString(); }
public void Call(MethodInfo t) { if (IsFromCurrentAssembly(t)) { /* Value: shifset of method from Current address of instruction (><)0 * call 0xXXXXXX todo: Becarful 0xXXXXXX Is the Offset */ var instruct = new Instruct(); instruct.Function = (byte)UAL.NameInstructions.IndexOf(Const.call); this.CurrentMethod.Calls.Add(new Label <MethodInfo> { index = this.StreamWriter.Offset, Value = t }); instruct.Desdestination.OperandType = OperandType.imm; instruct.Desdestination.DataType = DataType.Word; instruct.Desdestination.Value = t.Offset - this.StreamWriter.Offset; instruct.Push(this.StreamWriter); } else { #region /* <loc_Assembly> contain the address of assembly by afect it by the variable assembly * Offset:Point shifset of method in assembly >=0 * * eax=<loc_Assembly>+Offset * Value= eax * * mov eax,[assI] * add eax,offset * call eax */ #endregion Instruct.Parse("mov eax,[esi+" + AssemblyList.IndexOf(t.Return.Space.FullName) + "]").Push(this.StreamWriter); this.CurrentMethod.Calls.Add(new Label <MethodInfo> { index = this.StreamWriter.Offset, Value = t }); Instruct.Parse("add eax,0x" + t.Offset.ToString("x4")).Push(this.StreamWriter); Instruct.Parse("call eax").Push(this.StreamWriter); } }
private void CallManager(Assembler t, ref Instruct instruct) { instruct.Desdestination.OperandType = OperandType.Mem; Type Class; MethodInfo mi = GetInfoInvokation(t, out Class); this.CurrentMethod.Calls.Add(new Label <MethodInfo> { index = this.StreamWriter.Offset, Value = mi }); if (IsFromCurrentAssembly(mi)) { /* Value: shifset of method from Current address of instruction (><)0 * call 0xXXXXXX todo: Becarful 0xXXXXXX Is the Offset */ instruct.Desdestination.OperandType = OperandType.imm; instruct.Desdestination.DataType = DataType.Word; } else { #region /* <loc_Assembly> contain the address of assembly by afect it by the variable assembly * Offset:Point shifset of method in assembly >=0 * * eax=<loc_Assembly>+Offset * Value= eax * * mov eax,[assI] * add eax,offset * call eax */ #endregion Instruct.Parse("mov eax,[esi+" + AssemblyList.IndexOf(Class.Space.FullName) + "]").Push(this.StreamWriter); Instruct.Parse("add eax,0x0000"); Instruct.Parse("call eax"); instruct.Desdestination.OperandType = OperandType.Reg; instruct.Desdestination.Value = 0; /*eax*/ } }
/// <summary> /// Draws the help page to the screen. /// </summary> public static void DrawInstruct() { const int INST_HEADING = 40; const int INST_TOP = 80; const int INST_GAP = 30; const int WELC_HEADING = 500; const int WELC_LEFT = 350; if (_Instruct.Count == 0) { LoadInstruct(); } SwinGame.DrawText(" Instructions ", Color.White, GameResources.GameFont("Courier"), INST_LEFT, INST_HEADING); //Greating SwinGame.DrawText(" WELCOME! ", Color.White, GameResources.GameFont("Courier"), WELC_LEFT, WELC_HEADING); SwinGame.DrawText(" Dear user, thank you for playing our product! ", Color.White, GameResources.GameFont("Courier"), WELC_LEFT - 150, WELC_HEADING + INST_GAP); SwinGame.DrawText(" Hope you enjoy BattleShips! ", Color.White, GameResources.GameFont("Courier"), WELC_LEFT - 70, WELC_HEADING + (INST_GAP * 2)); //For all of the instructs int i = 0; for (i = 0; i <= _Instruct.Count - 1; i++) { Instruct s = default(Instruct); s = _Instruct[i]; if (i < 8) { SwinGame.DrawText(s.Name, Color.White, GameResources.GameFont("Courier"), INST_LEFT, INST_TOP + i * INST_GAP); } else { SwinGame.DrawText(s.Name, Color.White, GameResources.GameFont("Courier"), INST_LEFT, INST_TOP + i * INST_GAP); } } }
public static void _Test() { while (true) { __test(); var parse = new BasicParse { Pile = new Pile(Prg_Example) }; var parent = new Tree(parse.Pile, null, Kind.Program); var glob = CurrentScop.Initialize("globe"); Update(parse); var s = new Space(parse); if (s.Parse(parent)) { var byteCode = new ByteCodeMapper(glob); var load = new LoadClasses(byteCode); load.Add(parent[0]); load.Compile(); var inst = load.Optimum.Instructs; var sw = new IO.Stream.StreamWriter(true); for (int i = 0; i < inst.Count; i++) { inst[i].Push(sw); } var tt = inst[0].Length; var sr = new IO.Stream.StreamReader(sw); for (int i = 0; i < inst.Count; i++) { var x = Instruct.Pop(sr); var isieq = x.Equals(inst[i]); if (!isieq) { } } } } }
/// <summary> /// 从队列取一条指令, 并发送 /// </summary> /// <param name="ins"></param> private void SendInstruct() { Instruct ins = this.InstructList.Peek(); //取指令 ins.SendTimes++; //尝试次数+1 if (SendInstruct(new Instruct[] { ins }, false)) //执行, 是否成功 { this.InstructList.Dequeue(); DeleteFromDB(ins); //吧这条指令从数据库删除 if (InstructList.Count == 0) { if (HasDbData) //如果数据库还有指令, 取数据库指令来发送 { LoadDbInstruct(); } else { IsOpenQueue = true; } } LastSuccessTime = DateTime.Now; SustaineLostInstructCount = 0; } else { if ((DateTime.Now - LastSuccessTime).TotalSeconds > Timeout && SustaineLostInstructCount > 10) //判断最后成功时间和当前时间是否超过规定值,并且连续发送失败的次数是否达到10次 { this.Dispose(); //客户端严重超时,关闭 } else { Thread.Sleep(ins.SendTimes); } SustaineLostInstructCount++; } }
public void CreateInstruct(int userID, InstructType type, object datas, bool isSync) { ///检查是否开放Passport服务器 if (!AllSettings.Current.PassportServerSettings.EnablePassportService) { return; } Instruct ins = new Instruct(); string tempData = string.Empty; if (Serializer.IsSimpleDataTypes(datas)) { tempData = datas.ToString(); } else { tempData = Serializer.GetXML(datas); } ins.Datas = tempData; ins.InstructType = type; ins.TargetID = userID; ins.IsSync = isSync; InstructDriver driver; foreach (KeyValuePair <int, InstructDriver> item in this.DriverList) { driver = item.Value; if (driver.Client.InstructTypes.Count == 0 || driver.Client.InstructTypes.Contains(type)) { driver.AppendInstruct(ins); } } }
/// <summary> /// 发送异步指令 /// </summary> /// <param name="instruct"></param> private void SendInstructAsync(Instruct instruct) { instruct.InstructID = WriteToDB(instruct); //先入库 if (IsDisposed) { return; //对象已经销毁 } if (!IsOpenQueue || HasDbData) { HasDbData = true; return; } if (this.InstructList.Count < this.QueueSize) { this.InstructList.Enqueue(instruct); //入列 if (thread == null || !thread.IsAlive) { lock (locker) { if (thread == null || !thread.IsAlive) { this.thread = new Thread(ThreadStart); thread.IsBackground = true; thread.Start(); } } } } else { this.IsOpenQueue = false; HasDbData = true; } }
/// <summary> /// 构造 /// </summary> /// <param name="identifiers">标识</param> /// <param name="server">服务器 IP 或名称</param> /// <param name="Port">端口</param> /// <param name="userName">用户名</param> /// <param name="password">密码</param> /// <param name="localFileName">本地文件名</param> /// <param name="remoteFileName">远程文件名</param> /// <param name="transferDirection">传输方向</param> /// <param name="initializationInstruct">初始化时的默认指令</param> public TaskItem(string identifiers, string server, int Port, string userName, string password, string localFileName, string remoteFileName, Direction transferDirection, Instruct initializationInstruct) : this(identifiers, server, Port, userName, password, true, true, false, 4096, localFileName, remoteFileName, transferDirection, initializationInstruct) { }
/// <summary> /// 日志记录 /// </summary> /// <param name="ins"></param> /// <param name="error"></param> private long WriteToDB(Instruct ins) { return(PassportBO.Instance.WriteInstruct(this.Client.ClientID, ins.TargetID, ins.CreateDate, ins.InstructType, ins.Datas)); }
private void DeleteFromDB(Instruct ins) { PassportBO.Instance.DeleteFromDB(new long[] { ins.InstructID }); }
/// <summary> /// 构造 /// </summary> /// <param name="identifiers">标识</param> /// <param name="server">服务器 IP 或名称</param> /// <param name="Port">端口</param> /// <param name="userName">用户名</param> /// <param name="password">密码</param> /// <param name="UseBinary">二进制传输</param> /// <param name="UsePassive">使用被动模式,注意:一般此变量设置为 false, 用主动模式</param> /// <param name="EnableSsl">使用 SSL 加密传输</param> /// <param name="localFileName">本地文件名</param> /// <param name="remoteFileName">远程文件名</param> /// <param name="transferDirection">传输方向</param> /// <param name="initializationInstruct">初始化时的默认指令</param> public TaskItem(string identifiers, string server, int Port, string userName, string password, bool UseBinary, bool UsePassive, bool EnableSsl, string localFileName, string remoteFileName, Direction transferDirection, Instruct initializationInstruct) : this(identifiers, server, Port, userName, password, UseBinary, UsePassive, EnableSsl, 4096, localFileName, remoteFileName, transferDirection, initializationInstruct) { }
public void Add(Instruct instruct) { Instructs.Add(instruct); }
/// <summary> /// 构造 /// </summary> /// <param name="Identifiers">标识</param> /// <param name="Server">服务器 IP 或名称</param> /// <param name="Port">端口</param> /// <param name="UserName">用户名</param> /// <param name="Password">密码</param> /// <param name="LocalFileName">本地文件名</param> /// <param name="RemoteFileName">远程文件名</param> /// <param name="TransferDirection">传输方向</param> /// <param name="InitializationInstruct">初始化时的默认指令</param> public TaskItem(string Identifiers, string Server, int Port, string UserName, string Password, string LocalFileName, string RemoteFileName, Direction TransferDirection, Instruct InitializationInstruct) : this(Identifiers, Server, Port, UserName, Password, true, true, false, 4096, LocalFileName, RemoteFileName, TransferDirection, InitializationInstruct) { }
/// <summary> /// 构造 /// </summary> /// <param name="Identifiers">标识</param> /// <param name="Server">服务器 IP 或名称</param> /// <param name="Port">端口</param> /// <param name="UserName">用户名</param> /// <param name="Password">密码</param> /// <param name="UseBinary">二进制传输</param> /// <param name="UsePassive">使用被动模式,注意:一般此变量设置为 false, 用主动模式</param> /// <param name="EnableSsl">使用 SSL 加密传输</param> /// <param name="LocalFileName">本地文件名</param> /// <param name="RemoteFileName">远程文件名</param> /// <param name="TransferDirection">传输方向</param> /// <param name="InitializationInstruct">初始化时的默认指令</param> public TaskItem(string Identifiers, string Server, int Port, string UserName, string Password, bool UseBinary, bool UsePassive, bool EnableSsl, string LocalFileName, string RemoteFileName, Direction TransferDirection, Instruct InitializationInstruct) : this(Identifiers, Server, Port, UserName, Password, UseBinary, UsePassive, EnableSsl, 4096, LocalFileName, RemoteFileName, TransferDirection, InitializationInstruct) { }