public override void doIt(MArgList args) { parseArgs(args); // Allocate an array of indices. events[n] is a user provided // event name. Look it up in the static eventNames array // and set indices[n] to the index of the entry in eventNames. // // This maps the user specified events to the global events // so we can track callback adds and removes globally. int [] indics = new int[events.Length]; for (int j = 0; j < events.Length; ++j) { string userEvt = events[j]; indics[j] = -1; // Search event names for a match. // for (int i = 0; i < eventNames.Length; ++i) { if (userEvt == eventNames[i]) { indics[j] = i; if (addMessage && eventsFlag[i] == -1) { try { cbArray[i] = new eventCB(i); MEventMessage.Event[userEvt] += cbArray[i].eventCallback; eventsFlag[i] = j; } catch (System.Exception) { MGlobal.displayError("failed to add callback for" + userEvt); } } else if (delMessage && eventsFlag[i] != -1) { try { MEventMessage.Event[userEvt] -= cbArray[i].eventCallback; cbArray[i] = null; eventsFlag[i] = -1; } catch (System.Exception) { MGlobal.displayError("failed to remove callback for" + userEvt); } } // Found a match. Store the index and stop looking for break; } } } // Ok, we've made all the necessary changes. Now show the status. MGlobal.displayInfo("Event Name Msgs On"); MGlobal.displayInfo("----------------------------------- -------"); for (int i = 0; i < events.Length; i++) { bool invalid = indics[i] == -1; bool msgs = invalid ? false : (eventsFlag[indics[i]] != -1); //- "%-35s %s\n" MGlobal.displayInfo(string.Format("{0, -35} {1}", events[i], (invalid ? "invalid" : msgs ? "yes" : "no"))); } return; }
public override void doIt(MArgList args) { parseArgs(args); // Allocate an array of indices. events[n] is a user provided // event name. Look it up in the static eventNames array // and set indices[n] to the index of the entry in eventNames. // // This maps the user specified events to the global events // so we can track callback adds and removes globally. int [] indics = new int[events.Length]; for (int j = 0; j < events.Length; ++j) { string userEvt = events[j]; indics[j] = -1; // Search event names for a match. // for (int i = 0; i < eventNames.Length; ++i) { if(userEvt == eventNames[i]) { indics[j] = i; if(addMessage && eventsFlag[i] == -1) { try { cbArray[i] = new eventCB(i); MEventMessage.Event[userEvt] += cbArray[i].eventCallback; eventsFlag[i] = j; } catch (System.Exception) { MGlobal.displayError("failed to add callback for" + userEvt); } } else if(delMessage && eventsFlag[i] != -1) { try { MEventMessage.Event[userEvt] -= cbArray[i].eventCallback; cbArray[i] = null; eventsFlag[i] = -1; } catch (System.Exception) { MGlobal.displayError("failed to remove callback for" + userEvt); } } // Found a match. Store the index and stop looking for break; } } } // Ok, we've made all the necessary changes. Now show the status. MGlobal.displayInfo ("Event Name Msgs On") ; MGlobal.displayInfo ("----------------------------------- -------") ; for ( int i = 0 ; i < events.Length ; i++ ) { bool invalid = indics[i] == -1; bool msgs = invalid ? false : (eventsFlag[indics[i]] != -1); //- "%-35s %s\n" MGlobal.displayInfo(string.Format("{0, -35} {1}", events[i], (invalid ? "invalid" : msgs ? "yes" : "no"))); } return; }