public static void StartListening(string pipeName, DelegateMessage eventHandler) { var server = new PipeServer(); server.PipeData += eventHandler; server.Listen(pipeName); }
public static DelegateMessage EventField(string label, DelegateMessage evt, GameObject dynParamSource) { EditorGUILayout.BeginVertical(); if (label != null) { EditorGUILayout.PrefixLabel(label); } EditorGUILayout.BeginHorizontal(); DelegateMessage newEvt = (DelegateMessage)evt.Clone(); EventField_ContextPicker(newEvt); // SELECT EVENT TYPES GameObject target = (evt.targetId == -1) ? evt.overrideTarget:dynParamSource; DelegateDescriptor[] eventTypes = EditorDelegateUtil.FindEventsForObject(target); // SELECT EVENT & PARAMS DelegateDescriptor ed = EventField_EventDescriptorPopup(eventTypes, newEvt); EditorGUILayout.EndHorizontal(); EventField_Parameters(ed, newEvt, dynParamSource); EditorGUILayout.EndVertical(); return(newEvt); }
public void DoFinishDelegate() { if (null != m_delegateMessage) { m_delegateMessage(); m_delegateMessage = null; } }
private void EventHandlers() { mydelMessage = new DelegateMessage(RefreshMessageControl); this.Load += Broker_Load; this.btn_subscribe.Click += Btn_subscribe_Click; this.btn_publish.Click += Btn_publish_Click; this.btn_openFile.Click += Btn_openFile_Click; this.mqttNetClient.deleteSendMsgEvent += MqttNetClient_deleteSendMsgEvent; }
public void Add(Object obj, DelegateMessage msgDelegate) { if (m_delegateDic.ContainsKey(obj)) { SSDebug.Log("add delegate repeatedly:" + m_msgName); return; } m_delegateDic.Add(obj, msgDelegate); }
/* * delegate can invoke multiple method across multiple object * events makes them safe to expose from a class * events allow you to add or remove yourself from invocation list */ public DelegateDemo() { DebugWindowLogger log1 = new DebugWindowLogger(); BetterDebugWindowLogger log2 = new BetterDebugWindowLogger(); _writer = new DelegateMessage(log2.SendMessage); _writer += log1.SendMessage; _writer += log2.SendMessage; _writer += log1.SendMessage; }
public void UF_RemoveListener(int eventID, DelegateMessage method) { if (m_DicListeners.ContainsKey(eventID)) { if (m_DicListeners [eventID] != null) { m_DicListeners [eventID] -= method; } } }
//删除监听事件 //messageType:字符串形式的消息类型。例如"collision" //delegateMessage:处理该消息的函数。该函数的格式为:void process(KeyValues kv)。 public static void DeleteListener(string messageType, DelegateMessage delegateMessage) { if (messages.ContainsKey(messageType)) { messages[messageType] -= delegateMessage; } else { Debug.LogError("ERROR: message center does not contain the message type: " + messageType); } }
public MainWindow () { InitializeComponent (); _this = this; Client = new Client (); dMessage = new DelegateMessage (Message); dUpdateGUI = new DelegateUpdateGUI (UpdateGUI); dAddLogger = new DelegateAddLogger (AddLogger); dSetStatus = new DelegateSetStatus (SetStatus); }
public object Clone() { DelegateMessage newEvt = (DelegateMessage)MemberwiseClone(); if (parameter != null) { newEvt.parameter = (EventParameter)parameter.Clone(); } return(newEvt); }
public MainWindow() { InitializeComponent(); _this = this; Client = new Client(); dMessage = new DelegateMessage(Message); dUpdateGUI = new DelegateUpdateGUI(UpdateGUI); dAddLogger = new DelegateAddLogger(AddLogger); dSetStatus = new DelegateSetStatus(SetStatus); }
private void ShowSetResult(object sender, string message) { if (this.InvokeRequired) { DelegateMessage df = new DelegateMessage(ShowSetResult); this.BeginInvoke(df, sender, message); } else { stalabMBIsOffline.Text = message; } }
public virtual IAsyncResult BeginInvoke(Delegate method, params object[] args) { IsRunning(); DelegateMessage methodMessage = new DelegateMessage(method, args, true); lock (FMethodQueue) { FMethodQueue.Enqueue(methodMessage); FQueueSignal.Set(); } return(methodMessage); }
private void ShowMessage(object sender, string message) { if (this.InvokeRequired) { DelegateMessage df = new DelegateMessage(ShowMessage); this.BeginInvoke(df, sender, message); } else { stalabMBStatus.Text = message; } }
private void MethodMessage_OnAfterEvent(object sender, EventArgs e) { try { DelegateMessage lMethodMessage = sender as DelegateMessage; if (lMethodMessage.ExceptionObject != null) // do not try reconnect if the logon method is called { /// if we cant connet to the server because its down if (lMethodMessage.ExceptionObject is System.ServiceModel.EndpointNotFoundException) { Log.Write(LogLevel.Error, lMethodMessage.ExceptionObject.Message); lMethodMessage.ExceptionObject = new PandoraServiceError("Internet connection error occured while connecting to the remote server."); if (FServer != null) { FServer.Disconnected = true; } } var lName = lMethodMessage.ToString(); // an exception occured // Now test if the error is because of a communication issue or // if the error is because the server sent the error to be thrown if (!(lMethodMessage.ExceptionObject is PandoraServerException) && lName != "ThreadLogon") { // if there is a comunication faild we need to reconnect int lCounter = 0; PandoraWalletWebService lServer = null; do { Log.Write(LogLevel.Debug, "MethodMessage_OnAfterEvent: try reconnect to server {0}", lCounter); try { lServer = CreatePandoraWalletServer(); FServer = lServer; } catch { System.Threading.Thread.Sleep(1000); lCounter++; } } while (lServer == null && lCounter < 2); } } } catch (Exception ex) { Log.Write(LogLevel.Error, "Connection to Pandora Server failed with: " + ex.Message); throw; } }
/// <summary> /// Gets a Delgate Message from the message queue /// </summary> /// <remarks> /// GetMethodMessage Looks on the message queue if no message is available /// the call is blocked until a message is found /// The MethodJet uses the return value to determine whether to end the main /// message loop and stop running. /// The GetMethodMessage function retrieves messages associated with the /// object located on an enternal queue. /// During this call, the object delivers pending messages that were sent /// to the object using the Invoke, BeginInvoke, or Terminate. /// </remarks> /// <returns>Returns true if the "Method Message" is not an end "Method Message".</returns> protected virtual bool GetMethodMessage(out DelegateMessage aMethodMessage) { FQueueSignal.WaitOne(); // wait for a message lock (FMethodQueue) { aMethodMessage = FMethodQueue.Dequeue(); if (FMethodQueue.Count == 0) { FQueueSignal.Reset(); } } return(!aMethodMessage.TerminateMessage); }
//在需要接受消息的game object的脚本上使用此函数,来增加监听事件 //messageType:字符串形式的消息类型。例如"collision" //delegateMessage:处理该消息的函数。该函数的格式为:void process(KeyValues kv)。 public static void AddListener(string messageType, DelegateMessage delegateMessage) { if (messages.ContainsKey(messageType)) { Debug.Log("message center contains the message type: " + messageType); messages[messageType] += delegateMessage; } else { Debug.Log("message center does not contain the message type: " + messageType + ", and now add the message type"); messages.Add(messageType, null); messages[messageType] += delegateMessage; } }
/// <summary> /// Executes the method message. /// </summary> protected virtual bool InvokeMethodMessage(DelegateMessage aMethodMessage) { try { aMethodMessage.MethodInvoke(); return(true); } catch (Exception e) { if ((e.GetBaseException() is ThreadAbortException) || (!aMethodMessage.CompletedSynchronously && !DoErrorHandler(e))) { throw; } return(false); } }
private void show_device_offline(object sender, string message) { if (this.InvokeRequired) { DelegateMessage df = new DelegateMessage(show_device_offline); this.BeginInvoke(df, sender, message); } else { stalabMBStatus.Text = message; stalabMBIsOffline.Text = "QKM3L已断开"; cmbFullload.SelectedIndex = -1; gbxCurrent.Enabled = false; gbxProtect.Enabled = false; gbxIdentity.Enabled = false; } }
//Для инициализации потока вывода в файл private void InitStream(string way = "log.txt") { try { this.logStream = new StreamWriter(way); } catch (IOException ex) { writer = this.WriteWithoutFile; writer.Invoke(String.Format("Не удалось создать лог-файл: {0}", ex.Message)); } finally { writer = this.WriteWithFile; writer.Invoke("Файл с логами создан."); } }
public void UF_AddListener(int eventID, DelegateMessage method) { if (m_DicListeners.ContainsKey(eventID)) { if (m_DicListeners [eventID] != null) { m_DicListeners [eventID] += method; } else { m_DicListeners[eventID] = method; } } else { m_DicListeners.Add(eventID, method); } }
public static DelegateMessage[] EventArrayField(string label, DelegateMessage[] events, GameObject dynParamSource) { List <DelegateMessage> eventList = events == null ? new List <DelegateMessage>():new List <DelegateMessage>(events); if (events == null) { events = new DelegateMessage[0]; } EditorGUILayout.PrefixLabel(label); EditorGUILayout.BeginVertical(); DelegateMessage removeItem = null; for (int i = 0; i < eventList.Count; i++) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("-", GUILayout.Width(20))) { removeItem = eventList[i]; } else { eventList[i] = EventField(null, eventList[i], dynParamSource); } EditorGUILayout.EndHorizontal(); } if (removeItem != null) { eventList.Remove(removeItem); } if (GUILayout.Button("+", GUILayout.Width(20))) { eventList.Add(new DelegateMessage()); } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); return(eventList.ToArray()); }
private static void EventField_ContextPicker(DelegateMessage newEvt) { List <string> contextList = new List <string>(); contextList.Add("Self (Default)"); contextList.Add(""); contextList.Add("override..."); // SELECT TARGET if (newEvt.targetId == -1) { newEvt.targetId = contextList.Count - 1; } newEvt.targetId = EditorGUILayout.Popup(newEvt.targetId, contextList.ToArray(), "popup", GUILayout.Width(80)); if (newEvt.targetId == contextList.Count - 1) { newEvt.targetId = -1; newEvt.overrideTarget = (GameObject)EditorGUILayout.ObjectField(newEvt.overrideTarget, typeof(GameObject), true, GUILayout.Width(80)); } }
private void show_device_online(object sender, string message) { if (this.InvokeRequired) { DelegateMessage df = new DelegateMessage(show_device_online); this.BeginInvoke(df, sender, message); } else { CKM55LC_M ck = (CKM55LC_M)ComHelper.GetComLines()[0].Devices[0]; stalabMBStatus.Text = message; stalabMBIsOffline.Text = "CKM55LC_M已连接"; gbxCurrent.Enabled = true; gbxProtect.Enabled = true; gbxIdentity.Enabled = true; btnActivation.Enabled = true; try { int i = 0; while (ck.IdentityValues.In == 0) { Thread.Sleep(100); if (++i >= 50) { throw new Exception(); } } cmbFullload.Text = ck.IdentityValues.In.ToString() + "A"; } catch (System.Exception) { MessageBox.Show("额定电流规格读取错误"); } } }
private void ShowIsOffine(object sender, string message) { if (this.InvokeRequired) { DelegateMessage df = new DelegateMessage(ShowIsOffine); this.BeginInvoke(df, sender, message); } else { stalabMBIsOffline.Text = message; if (_isOffline) { btnOpen.Enabled = btnClose.Enabled = btnTest.Enabled = false; btnWriteAssetCode.Enabled = btnWriteDeviceNum.Enabled = btnWriteProductDate.Enabled = false; btnReadFactoryValue.Enabled = false; btnReadAssetCode.Enabled = btnReadDeviceNum.Enabled = btnReadProductDate.Enabled = false; grdRunValue.Enabled = false; grdSmp.Enabled = false; grdRatedResidual.Enabled = false; grdTrip.Enabled = false; grdResidualLimit.Enabled = false; } else { btnOpen.Enabled = btnClose.Enabled = btnTest.Enabled = true; btnWriteAssetCode.Enabled = btnWriteDeviceNum.Enabled = btnWriteProductDate.Enabled = true; btnReadFactoryValue.Enabled = true; btnReadAssetCode.Enabled = btnReadDeviceNum.Enabled = btnReadProductDate.Enabled = true; grdRunValue.Enabled = true; grdSmp.Enabled = true; grdRatedResidual.Enabled = true; grdTrip.Enabled = true; grdResidualLimit.Enabled = true; } } }
public virtual object EndInvoke(IAsyncResult result, int aMillisecondsTimeout) { IsRunning(); DelegateMessage methodMessage = result as DelegateMessage; if (RunningThreadID == GetCurrentThreadId()) { throw new DevErrorException("MethodJet is running in the same thread calling EndInvoke will cause a dead lock!"); } if (aMillisecondsTimeout < 1) { methodMessage.AsyncWaitHandle.WaitOne(); } else { methodMessage.AsyncWaitHandle.WaitOne(aMillisecondsTimeout); } if (methodMessage.ExceptionObject != null) { throw methodMessage.ExceptionObject; } return(methodMessage.AsyncState); }
// This method is overrdden so that we can try reconnecting when ever the ThreadXXX method is called // so we can do what ever w can to recover from bad connections or if the one server // goes down for maintainane protected override bool InvokeMethodMessage(DelegateMessage aMethodMessage) { aMethodMessage.OnAfterEvent += MethodMessage_OnAfterEvent; if (FServer != null && FServer.Disconnected) { int lCounter = 0; PandoraWalletWebService lServer = null; do { Log.Write(LogLevel.Debug, "InvokeMethodMessage: try reconnect to server {0}", lCounter); try { lServer = CreatePandoraWalletServer(); FServer = lServer; } catch { lCounter++; } } while (lServer == null && lCounter < 2); } return(base.InvokeMethodMessage(aMethodMessage)); }
private static void EventField_Parameters(DelegateDescriptor ed, DelegateMessage newEvt, GameObject dynParamSource) { if (ed == null) { newEvt.name = ""; if (newEvt.parameter != null) { newEvt.parameter.SetVoid(); } return; } newEvt.name = ed.signature.methodName; if (ed.signature.parameterType == typeof(void)) { newEvt.parameter.SetVoid(); } else { EventField_ParameterField(ed, newEvt, dynParamSource); } }
private static DelegateDescriptor EventField_EventDescriptorPopup(DelegateDescriptor[] eventTypes, DelegateMessage oldEvent) { List <string> optionsList = new List <string>(); foreach (DelegateDescriptor item in eventTypes) { optionsList.Add(item.ToString()); } optionsList.Add("--NONE--"); string[] optionsStrings = optionsList.ToArray(); // loop through till we get a match, note that a value of eventTypes.Length IS valid here int eventId = 0; for (; eventId < eventTypes.Length; eventId++) { if (eventTypes[eventId].signature.methodName == oldEvent.name) { if (oldEvent.parameter.GetParameterType().IsAssignableFrom(eventTypes[eventId].signature.parameterType)) { break; } } } eventId = EditorGUILayout.Popup(eventId, optionsStrings, "popup"); if (eventId == optionsList.Count - 1) { return(null); } return(eventTypes[eventId]); }
private static void EventField_ParameterField(DelegateDescriptor ed, DelegateMessage newEvt, GameObject dynamicParamSource) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(ed.signature.parameterName, "box", GUILayout.Width(80)); // FIND DYNAMIC PARAMS List <string> dynParamNames = new List <string>(new string[] { "value...", "" }); List <string> memberNames = new List <string>(new string[] { "", "" }); List <Object> objects = new List <Object>(new Object[] { null, null }); bool prevFoundOne = false; foreach (Component comp in dynamicParamSource.GetComponents <Component>()) { if (prevFoundOne) { dynParamNames.Add(""); memberNames.Add(""); objects.Add(null); } prevFoundOne = false; foreach (MemberInfo item in comp.GetType().GetMembers()) { if (item.MemberType != MemberTypes.Field && item.MemberType != MemberTypes.Property) { continue; } if (item.DeclaringType.IsAssignableFrom(typeof(Component))) { continue; } System.Type itemType = null; if (item.MemberType == MemberTypes.Field) { itemType = (item as FieldInfo).FieldType; } else if (item.MemberType == MemberTypes.Property) { itemType = (item as PropertyInfo).PropertyType; } if (!ed.signature.parameterType.IsAssignableFrom(itemType)) { continue; } prevFoundOne = true; dynParamNames.Add(comp.GetType().Name + "." + item.Name); memberNames.Add(item.Name); objects.Add(comp); } } int dynParamId = memberNames.IndexOf(newEvt.parameter.objectMemberName); if (dynParamId == -1) { dynParamId = 0; } if (dynParamNames.Count > 1) { dynParamId = EditorGUILayout.Popup(dynParamId, dynParamNames.ToArray(), "popup", GUILayout.MinWidth(60)); } if (dynParamId > 1 && dynParamNames.Count > 1) { newEvt.parameter.SetDynamicValue(objects[dynParamId], memberNames[dynParamId], ed.signature.parameterType); } else { if (ed.signature.parameterType == typeof(string)) { newEvt.parameter.SetValue(EditorGUILayout.TextField(newEvt.parameter.stringParam), ed.signature.parameterType); } if (ed.signature.parameterType == typeof(int)) { newEvt.parameter.SetValue(EditorGUILayout.IntField(newEvt.parameter.intParam), ed.signature.parameterType); } if (ed.signature.parameterType == typeof(float)) { newEvt.parameter.SetValue(EditorGUILayout.FloatField(newEvt.parameter.floatParam), ed.signature.parameterType); } if (ed.signature.parameterType == typeof(Vector3)) { newEvt.parameter.SetValue(EditorGUILayout.Vector3Field("", newEvt.parameter.vectorParam), ed.signature.parameterType); } if (ed.signature.parameterType == typeof(bool)) { newEvt.parameter.SetValue(EditorGUILayout.Toggle(newEvt.parameter.boolParam), ed.signature.parameterType); } if (typeof(UnityEngine.Object).IsAssignableFrom(ed.signature.parameterType)) { newEvt.parameter.SetValue(EditorGUILayout.ObjectField(newEvt.parameter.objectParam, ed.signature.parameterType, true), ed.signature.parameterType); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(4); }
private static DelegateDescriptor EventField_EventDescriptorPopup(string label, DelegateDescriptor[] eventTypes, DelegateMessage oldEvent) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(label); DelegateDescriptor ed = EventField_EventDescriptorPopup(eventTypes, oldEvent); EditorGUILayout.EndHorizontal(); return(ed); }
public IAsyncResult BeginMessage(int messageOrdinal, AsyncCallback callback) { this._delegateMessage = this.Message; return this._delegateMessage.BeginInvoke(messageOrdinal, callback, this._delegateMessage); }