private void ReceiveCallback(IAsyncResult asyncResult) { var operation = (IOperation)asyncResult.AsyncState; try { var bytesRead = _networkStream.EndRead(asyncResult); if (bytesRead == 0) { SendEvent.Set(); return; } operation.Read(operation.Buffer, 0, bytesRead); BufferManager.ReturnBuffer(operation.Buffer); if (operation.LengthReceived < operation.TotalLength) { operation.Buffer = BufferManager.TakeBuffer(512); _networkStream.BeginRead(operation.Buffer, 0, operation.Buffer.Length, ReceiveCallback, operation); } else { SendEvent.Set(); } } catch (Exception e) { HandleException(e, operation); } }
private void button1_Click(object sender, EventArgs e) { SendEvent?.Invoke(textBox1.Text.Trim()); pictureBox1.Image = null; textBox1.Text = string.Empty; this.Close(); }
public override void Process(string scene, UnityEngine.Object changeObj) { if (scene != _sceneName || !(changeObj is PlayMakerFSM fsm) || fsm.FsmName != _fsmName || fsm.gameObject.name != _objectName) { return; } SendEvent sender = new SendEvent { eventTarget = new FsmEventTarget { target = FsmEventTarget.EventTarget.BroadcastAll, excludeSelf = true }, sendEvent = FsmEvent.FindEvent(_eventName) ?? new FsmEvent(_eventName), delay = 0, everyFrame = false }; foreach (string stateName in _stateNames) { if (fsm.GetState(stateName) is FsmState state) { state.AddFirstAction(sender); } } }
private void pictureBox1_Click(object sender, EventArgs e) { var mouse = (MouseEventArgs)e; //label1.Text=mouse.Location.ToString(); var x = mouse.Location.X / width; var y = (mouse.Location.Y - yoffset) / height; const string bs = "000"; var str = bs + x + bs + y; vcode += str; pick[ClickCount] = new System.Drawing.Bitmap(width - xoffset, height); var pickedG = System.Drawing.Graphics.FromImage(pick[ClickCount]); Rectangle from = new Rectangle(x * width + xoffset, y * height + yoffset, width - xoffset, height); Rectangle to = new Rectangle(0, 0, width - xoffset, height); pickedG.DrawImage(pictureBox1.Image, to, from, GraphicsUnit.Pixel); picture[ClickCount].Image = pick[ClickCount]; CanClick = picture[ClickCount]; ClickCount++; if (ClickCount == 4) { /*for(int i=0;i<4;i++) * { * string s = i + ".png"; * pick[i].Save(s); * }*/ SendEvent?.Invoke(vcode); vcode = string.Empty; pictureBox1.Image = null; this.Close(); } }
public void Dispose() { if (isDisposed_) { return; } lock (ThreadLock) { if (sendingTaskAwaiter_ != null) { ThreadCancellationTokenSource.Cancel(); SendEvent.Set(); sendingTaskAwaiter_.Value.GetAwaiter().OnCompleted(() => { SendEvent.Dispose(); ThreadCancellationTokenSource.Dispose(); }); } else { SendEvent.Dispose(); ThreadCancellationTokenSource.Dispose(); } } DataSender.Dispose(); GC.SuppressFinalize(this); isDisposed_ = true; }
private void button2_Click(object sender, EventArgs e) { SendEvent?.Invoke(ContentBox.Text); ContentBox.Text = string.Empty; label1.Text = string.Empty; this.Close(); }
/// <summary> /// 断开连接 /// </summary> public void Disconnect() { if (isConnect) { OnClosed(); SyncCall.Add(() => { if (OnDisconnect == null) { return; } OnDisconnect(this, new EventArgs()); }); try { this._socket.Shutdown(SocketShutdown.Both); } catch (Exception e) { Debuger.Log(e.ToString()); } isConnect = false; if (this.ProcessThread != null && this.ProcessThread.IsAlive) { SendEvent.Set(); ProcessThread.Join(1000); } Close(); } }
public int PingDurtion = 3000; // /// <summary> /// 发送一个消息 /// </summary> /// <param name="message"></param> public void SendMessage(Message message) { BufferMessage.AddMessage(message); if (UsedThread) { SendEvent.Set(); } }
private void Start() { if (sendEvent == null) { sendEvent = new SendEvent(); } sendEvent.Invoke("This is a message from sender"); }
//################################## Constructor ############################################# public void Initialize(GameObject gameObject) { this.gameObject = gameObject; eventManager = new EventManager(); compositeEventManager = new CompositeEventManager(); signalEvent = new SendEvent(); signalEvent.senderEvent = Animator.StringToHash("Signal"); }
public static void Broadcast(this GameObject go, SendEvent eventID) { GameObjectState msg = go.GetComponent <GameObjectState>(); if (msg != null) { msg.Messenger.Broadcast(eventID); } }
public static void Broadcast <T>(this GameObject go, SendEvent eventID, T messageData) { GameObjectState msg = go.GetComponent <GameObjectState>(); if (msg != null) { msg.Messenger.Broadcast <T>(eventID, messageData); } }
public async Task SendAsync(DeviceAgent sender, byte[] contents) { var interval = TimeSpan.FromMilliseconds(SimulationBluetoothConstants.SEND_TICK_INTERVAL); var completionBox = new AsyncBox <bool>(); var sendEvent = new SendEvent(DateTime.Now + interval, interval, sender, completionBox, contents, 0); await ChannelsExtensions.WriteAsync(adapterEventQueueChannel, sendEvent).ConfigureAwait(false); await completionBox.GetResultAsync().ConfigureAwait(false); }
private void rbFirstSelect_CheckedChanged(object sender, EventArgs e) { if (rbFirstSelect.Checked) { SendEvent?.Invoke(this, new SendEventArgs() { TypeEvent = SendEventArgs.TypeEventE.RbtnClick }); } }
void Start() { CurrentVehicle = PlayMakerGlobals.Instance.Variables.FindFsmString("PlayerCurrentVehicle"); // SET UP ACTIONS hitchHiker = GameObject.Find("KILJUGUY").transform.Find("HikerPivot/Hitchhiker").GetComponents <PlayMakerFSM>().FirstOrDefault(fsm => fsm.FsmName == "Logic"); openDoor1 = hitchHiker.FsmStates.FirstOrDefault(x => x.Name == "Open door").Actions[6] as SendEvent; openDoor2 = hitchHiker.FsmStates.FirstOrDefault(x => x.Name == "Get out").Actions[4] as SendEvent; StartCoroutine(Delay()); }
/// <summary> /// 绑定的数据源数据变化触发 /// </summary> /// <param name="value"></param> /// <param name="index"></param> public void ValueUpdate(T value, int index) { if (index < _length) { if (!_value[index].Equals(value)) { _value[index] = value; SendEvent?.Invoke(this, index, false); } } }
// BeginSend callback private void HandleSend(IAsyncResult ar) { try { _clientsock.EndSend(ar); SendEvent?.Invoke(this, new IPCSendEventArgs(_clientsock, _buffer.OriginalData)); } catch (Exception ex) { _ex = ex; } signal_write.Set(); //return ar; }
/// <summary> /// 接收到消息 /// </summary> /// <param name="message"></param> public virtual void OnReceived(Message message) { if (message.Class == MessageClass.Ping) { #region Ping var tickNow = DateTime.Now.Ticks; long tickSend = 0; using (var mem = new MemoryStream(message.Content)) { using (var br = new BinaryReader(mem)) { tickSend = br.ReadInt64(); } } Delay = (tickNow - tickSend); SyncCall.Add(() => { if (OnPingCompleted != null) { OnPingCompleted(this, new PingCompletedArgs { DelayTicks = Delay }); } }); #endregion } else if (message.Class == MessageClass.Package) { var bufferPackage = MessageBufferPackage.ParseFromMessage(message); foreach (var m in bufferPackage.Messages) { OnReceived(m); } } else if (message.Class == MessageClass.Close) { this.Disconnect(); } else { ReceivedBufferMessage(message); } if (UsedThread) { SendEvent.Set(); } }
public override void Send <T>(IOperation <T> operation) { try { _sslStream.BeginWrite(operation.WriteBuffer, 0, operation.WriteBuffer.Length, SendCallback, operation); if (!SendEvent.WaitOne(Configuration.SendTimeout)) { var msg = ExceptionUtil.GetMessage(ExceptionUtil.RemoteHostTimeoutMsg, Configuration.SendTimeout); operation.HandleClientError(msg, ResponseStatus.ClientFailure); IsDead = true; } } catch (Exception e) { HandleException(e, operation); } }
public bool SetValue(T value, byte index) { if (index < _length) { if (!_value[index].Vaule.Equals(value)) { _value[index].Vaule = value; OnValueChange(index); SendEvent?.Invoke(this, index, false); } return(true); } else { return(false); } }
public bool SetValue(T[] value) { if (value.Length <= _value.Length) { for (int i = 0; i < value.Length; i++) { if (!_value[i].Vaule.Equals(value)) { _value[i].Vaule = value[i]; OnValueChange(i); SendEvent?.Invoke(this, i, false); } } return(true); } return(false); }
protected virtual void _chartControl_ViewChanged(object sender, ChartArea e) { if (e == null) { SendEvent?.Invoke(this, new SendEventArgs() { TypeEvent = SendEventArgs.TypeEventE.ResetZoom }); } else { SendEvent?.Invoke(this, new SendEventArgs() { Rect = new ChartRect(e), TypeEvent = SendEventArgs.TypeEventE.ChangeZoom }); } }
public override void Send <T>(IOperation <T> operation) { try { _sslStream.BeginWrite(operation.WriteBuffer, 0, operation.WriteBuffer.Length, SendCallback, operation); if (!SendEvent.WaitOne(Configuration.ConnectionTimeout)) { const string msg = "The connection has timed out while an operation was in flight. The default is 15000ms."; operation.HandleClientError(msg, ResponseStatus.ClientFailure); IsDead = true; } } catch (Exception e) { HandleException(e, operation); } }
public override byte[] Send(byte[] buffer) { var state = new SocketAsyncState { Data = new MemoryStream(), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque) }; _sslStream.BeginWrite(buffer, 0, buffer.Length, SendCallback, state); if (!SendEvent.WaitOne(Configuration.SendTimeout)) { //TODO refactor logic IsDead = true; var msg = ExceptionUtil.GetMessage(ExceptionUtil.RemoteHostTimeoutMsg, Configuration.SendTimeout); throw new RemoteHostTimeoutException(msg); } return(state.Data.ToArray()); }
/// <summary> /// Spawn new instance of the given pickupable at given world position. /// </summary> /// <param name="position">The position where to spawn pickupable at.</param> /// <param name="rotation">The rotation to apply on spawned pickupable.</param> /// <returns>Newly spawned pickupable game object.</returns> public GameObject Spawn(Vector3 position, Quaternion rotation) { // HACK: Jonnez is already spawned and there can be only one of it. // TODO: Get rid of it, it's ugly hack. Perhaps JONNEZ should behave like // pickupable. if (gameObject.name.StartsWith("JONNEZ ES")) { return(GameObject.Find("JONNEZ ES(Clone)")); } GameObject pickupable = (GameObject)Object.Instantiate(gameObject, position, rotation); pickupable.SetActive(true); pickupable.transform.SetParent(null); // Disable loading code on all spawned pickupables. PlayMakerFSM fsm = Utils.GetPlaymakerScriptByName(pickupable, "Use"); if (fsm != null) { FsmState loadState = fsm.Fsm.GetState("Load"); if (loadState != null) { var action = new SendEvent(); action.eventTarget = new FsmEventTarget(); action.eventTarget.excludeSelf = false; action.eventTarget.target = FsmEventTarget.EventTarget.Self; action.sendEvent = fsm.Fsm.GetEvent("FINISHED"); PlayMakerUtils.AddNewAction(loadState, action); Logger.Log("Installed skip load hack for prefab " + pickupable.name); } else { Logger.Log("Failed to find state on " + pickupable.name); } } return(pickupable); }
protected virtual void Dispose(bool disposing) { if (m_disposed) { return; } if (disposing) { //释放托管资源 m_connectSocket = null; m_asyncReceiveBuffer = null; ReceiveEventArgs.UserToken = null; SendEventArgs.UserToken = null; } //释放非托管资源 ReceiveEventArgs.Dispose(); SendEventArgs.Dispose(); SendEvent.Dispose(); m_disposed = true; }
static void Main(string[] args) { Console.Write("Enter Input - send or receive \r\n"); var input = Console.ReadLine(); Console.Write("User Entered : " + input + "\r\n"); if (!String.IsNullOrEmpty(input) && input.ToLower().Equals("send")) { Console.Write("Sending \r\n"); SendEvent.SendAsync("Message ").GetAwaiter().GetResult(); } else { Console.Write("Receive \r\n"); ReceiveEvent.ReceiveAsync().GetAwaiter().GetResult(); } Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); }
public override byte[] Send(byte[] buffer) { var state = new SocketAsyncState { Data = new MemoryStream(), Opaque = Converter.ToUInt32(buffer, HeaderIndexFor.Opaque) }; _sslStream.BeginWrite(buffer, 0, buffer.Length, SendCallback, state); if (!SendEvent.WaitOne(Configuration.ConnectionTimeout)) { //TODO refactor logic IsDead = true; const string msg = "The connection has timed out while an operation was in flight. The default is 15000ms."; throw new IOException(msg); } return(state.Data.ToArray()); }
public void SetupActions() { openDoor1 = mover.FsmStates.FirstOrDefault(x => x.Name == "Open door 2").Actions[7] as SendEvent; openDoor2 = mover.FsmStates.FirstOrDefault(x => x.Name == "Get out").Actions[0] as SendEvent; InsertAction(mover, "Which car", new CarCheck { moveHandler = this }); InsertAction(mover, "Van", new SetCarVariables { moveHandler = this }, 0); InsertAction(mover, "Open door 2", new OpenCarDoor { moveHandler = this }, 7); InsertAction(mover, "Get out", new OpenCarDoor { moveHandler = this }, 0); InsertAction(mover, "Idle", new ResetCarLift { moveHandler = this }, 0); }
public override IOperationResult <T> Send <T>(IOperation <T> operation) { try { operation.Reset(); var buffer = operation.Write(); _sslStream.BeginWrite(buffer, 0, buffer.Length, SendCallback, operation); if (!SendEvent.WaitOne(Configuration.OperationTimeout)) { const string msg = "Operation timed out: the timeout can be configured by changing the PoolConfiguration.OperationTimeout property. The default is 2500ms."; operation.HandleClientError(msg); } } catch (Exception e) { HandleException(e, operation); } return(operation.GetResult()); }
static void Main(string[] args) { DeviceUplinkBuffer[] deviceUplinkBuffers = new DeviceUplinkBuffer[3]; deviceDownlinkBuffers = new DeviceDownlinkBuffer[3]; memories = new Memory[18]; satelliteUplinkBuffer = new SatelliteUplinkBuffer(1333344, 100); satelliteDownlinkBuffer = new SatelliteDownlinkBuffer(1333344, 150); sendEvents = new SendEvent[40]; requestEvents = new RequestEvent[40]; int[] csvTracker = new int[3]; int[,] latencies = new int[3,40]; int[] currentSendEvents = new int[3]; int[] currentRequestEvents = new int[3]; int tCurrentClock = 0; int[] wait = new int[3]; string[] currentEventOperations = new string[3]; int i; int finished; int j; int m; for (i = 0; i < 3; i++) { csvTracker[i] = 0; wait[i] = 0; deviceUplinkBuffers[i] = new DeviceUplinkBuffer(i,304); deviceDownlinkBuffers[i] = new DeviceDownlinkBuffer(i,304); } for(i = 0; i < 4; i++) { memories[i] = new Memory(128, 1); } for(i = 4; i < 8; i++) { memories[i] = new Memory(512, 8); } for(i = 8; i < 18; i++) { memories[i] = new Memory(1024, 15); } CsvObj[,] csvObjs = new CsvObj[3,15]; csvObjs[0,0] = new CsvObj(0,1,"SEND",128,1); csvObjs[0,1] = new CsvObj(150,1,"SEND",1024,4); csvObjs[0,2] = new CsvObj(210,1,"REQUEST",128,2); csvObjs[0,3] = new CsvObj(1000,1,"REQUEST",128,3); csvObjs[0,4] = new CsvObj(12000,1,"REQUEST",1024,10); csvObjs[1,0] = new CsvObj(50,2,"SEND",128,2); csvObjs[1,1] = new CsvObj(200,2,"REQUEST",128,1); csvObjs[1,2] = new CsvObj(1100,2,"REQUEST",128,3); csvObjs[1,3] = new CsvObj(11500,2,"REQUEST",1024,12); csvObjs[2,0] = new CsvObj(100,3,"SEND",128,3); csvObjs[2,1] = new CsvObj(300,3,"SEND",1024,5); csvObjs[2,2] = new CsvObj(400,3,"SEND",1024,6); csvObjs[2,3] = new CsvObj(500,3,"SEND",512,7); csvObjs[2,4] = new CsvObj(2000,3,"SEND",1024,8); csvObjs[2,5] = new CsvObj(3000,3,"SEND",1024,9); csvObjs[2,6] = new CsvObj(4000,3,"SEND",1024,10); csvObjs[2,7] = new CsvObj(5000,3,"SEND",1024,11); csvObjs[2,8] = new CsvObj(6000,3,"SEND",1024,12); csvObjs[2,9] = new CsvObj(7000,3,"SEND",1024,13); csvObjs[2,10] = new CsvObj(8000,3,"SEND",1024,14); csvObjs[2,11] = new CsvObj(9000,3,"SEND",1024,15); csvObjs[2,12] = new CsvObj(10000,3,"SEND",1024,16); csvObjs[2,13] = new CsvObj(11000,3,"SEND",1024,17); csvObjs[2,14] = new CsvObj(12100,3,"REQUEST",512,7); //foreach (CsvObj poop in csvObjs) //{ //if(poop._operation == "SEND") //{ // poop._device += 3; //} //} while (tCurrentClock < 50000000000) { if (csvTracker[0] == 5 && csvTracker[1] == 4 && csvTracker[2] == 15) { int count; System.Console.WriteLine("----Device 0 Latencies----"); for (count = 0; count < 5; count++) { System.Console.WriteLine(latencies[0,count]); } System.Console.WriteLine("----Device 1 Latencies----"); for (count = 0; count < 4; count++) { System.Console.WriteLine(latencies[1,count]); } System.Console.WriteLine("----Device 2 Latencies----"); for (count = 0; count < 15; count++) { System.Console.WriteLine(latencies[2,count]); } break; } for(i = 0; i < 3; i++) { if (i == 0 && csvTracker[i] == 5) { continue; } if (i == 1 && csvTracker[i] == 4) { continue; } if (i == 2 && csvTracker[i] == 15) { continue; } finished = 0; if (tCurrentClock == 0) { currentEventOperations[i] = csvObjs[i,0]._operation; j = whichMemoryToSend (csvObjs[i,0]._size, memories); sendEvents[i] = new SendEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, false, j); memories[j].startUsing(); } if (wait[i] == 1) { if (satelliteUplinkBuffer._inUse == 0) { if (csvObjs[i,csvTracker[i]]._operation == "SEND") { currentEventOperations[i] = "SEND"; j = whichMemoryToEvict(csvObjs[i,csvTracker[i]]._size); sendEvents[i] = new SendEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, true, j); memories[j].startUsing(); satelliteUplinkBuffer.startUsing(); } else { currentEventOperations[i] = "REQUEST"; requestEvents[i] = new RequestEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, false, -1); satelliteUplinkBuffer.startUsing(); satelliteDownlinkBuffer.startUsing(); } wait[i] = 0; continue; } else { continue; } } if (currentEventOperations[i] == "SEND") { if (sendEvents[i]._evicting == true) { finished = sendEvents[i].updateSendEvent(tCurrentClock, deviceUplinkBuffers[i], memories[sendEvents[i]._memoryDestination], satelliteUplinkBuffer); } else { finished = sendEvents[i].updateSendEvent(tCurrentClock, deviceUplinkBuffers[i], memories[sendEvents[i]._memoryDestination]); } } else { if(requestEvents[i]._inMemory) { finished = requestEvents[i].updateRequestEvent(tCurrentClock, deviceDownlinkBuffers[i], memories[requestEvents[i]._memoryDesignation]); } else { finished = requestEvents[i].updateRequestEvent(tCurrentClock, deviceDownlinkBuffers[i], satelliteUplinkBuffer, satelliteDownlinkBuffer); } } if (finished == 1) { if (currentEventOperations[i] == "SEND") { if (sendEvents[i]._evicting == true) { satelliteUplinkBuffer.stopUsing(); } memories[sendEvents[i]._memoryDestination].stopUsing(); } else { if (requestEvents[i]._inMemory) { memories[requestEvents[i]._memoryDesignation].stopUsing(); } else { satelliteUplinkBuffer.stopUsing(); satelliteDownlinkBuffer.stopUsing(); } } latencies[i,csvTracker[i]] = tCurrentClock - csvObjs[i,csvTracker[i]]._csvTime; //System.Console.WriteLine(tCurrentClock); //System.Console.WriteLine("-----------"); csvTracker[i] += 1; if (i == 0 && csvTracker[i] == 5) { continue; } if (i == 1 && csvTracker[i] == 4) { continue; } if (i == 2 && csvTracker[i] == 15) { continue; } if (csvObjs[i,csvTracker[i]]._operation == "SEND") { currentEventOperations[i] = "SEND"; j = whichMemoryToSend(csvObjs[i,csvTracker[i]]._size, memories); if (j == -1) { j = whichMemoryToEvict(csvObjs[i,csvTracker[i]]._size); wait[i] = satelliteUplinkBuffer._inUse; if (wait[i] == 0) { sendEvents[i] = new SendEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, true, j); memories[j].startUsing(); satelliteUplinkBuffer.startUsing(); } else { continue; } } else { sendEvents[i] = new SendEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, false, j); memories[j].startUsing(); } } else { currentEventOperations[i] = "REQUEST"; m = checkTags(csvObjs[i,csvTracker[i]]._trDataTag, memories); if (m == -1) { wait[i] = satelliteUplinkBuffer._inUse; if (wait[i] == 0) { requestEvents[i] = new RequestEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, false, -1); satelliteUplinkBuffer.startUsing(); satelliteDownlinkBuffer.startUsing(); } } else { requestEvents[i] = new RequestEvent(csvObjs[i,csvTracker[i]]._csvTime, csvObjs[i,csvTracker[i]]._size, csvObjs[i,csvTracker[i]]._trDataTag, i, true, m); memories[m].startUsing(); } } } } tCurrentClock++; } }