public void EventStubDelegatesHaveSameTypesAsTheirOriginals() { var eventStub = new EventStub(typeof(ISampleInterface)); AssertType <EventHandler>(eventStub["SimpleEvent"]); AssertType <EventHandler <CancelEventArgs> >(eventStub["CancelEvent"]); AssertType <Action>(eventStub["ActionDelegate"]); AssertType <Func <int, string> >(eventStub["FuncDelegate"]); }
public void EventStubContainsEventsAndDelegates() { var eventStub = new EventStub(typeof(ISampleInterface)); Assert.IsNotNull(eventStub["SimpleEvent"]); Assert.IsNotNull(eventStub["CancelEvent"]); Assert.IsNotNull(eventStub["ActionDelegate"]); Assert.IsNotNull(eventStub["FuncDelegate"]); }
public void EventStubContainsInheritedEventsAndDelegates() { var eventStub = new EventStub(typeof(ISampleDescendant2)); Assert.IsNotNull(eventStub["NewCancelEvent"]); Assert.IsNotNull(eventStub["NewEvent"]); Assert.IsNotNull(eventStub["NewDelegate"]); Assert.IsNotNull(eventStub["SimpleEvent"]); Assert.IsNotNull(eventStub["CancelEvent"]); Assert.IsNotNull(eventStub["ActionDelegate"]); Assert.IsNotNull(eventStub["FuncDelegate"]); }
public void Can_serialize_and_deserialize_an_event() { var eventStub = new EventStub(1); var streamMessage = new NewStreamMessage(Guid.NewGuid(), eventStub.GetType().AssemblyQualifiedName, SimpleJson.SerializeObject(eventStub), "\"metadata\""); var jsonData = streamMessage.JsonData; var data = SimpleJson.DeserializeObject <EventStub>(jsonData); Assert.Equal(eventStub.Value, data.Value); }
/// <summary> /// Creates a new Texturizer for the given event. /// </summary> /// <param name="evnt">Event to create a Texturizer for.</param> public Texturizer(EventStub evnt) { this.Event = evnt; Material mat = Resources.Load<Material>( EventFolderName(evnt) + "/Mat"); TextAsset offsetsFile = Resources.Load<TextAsset>( EventFolderName(evnt) + "/Offsets"); //only if we have a material and an offsets file can we create a texture. if (mat != null && offsetsFile != null) { //set up the camera at a fixed 16:9 aspect ratio camera = new GameObject().AddComponent<Camera>(); camera.transform.position = new Vector3(0, -100, 0 + zOffset); camera.backgroundColor = Color.black; camera.aspect = 16.0f / 9.0f; camera.orthographic = true; //create a render texture to which the camera renders currentTex = new RenderTexture(800, 450, 24); currentTex.Create(); camera.targetTexture = currentTex; //create a single cube to hold the event image's material imageCube = GameObject.CreatePrimitive(PrimitiveType.Cube); imageCube.transform.localScale = new Vector3(IMG_CUBE_WIDTH, IMG_CUBE_HEIGHT, 0.01f); imageCube.transform.position = new Vector3(0, -100, 0.7f + zOffset); imageCube.transform.Rotate(Vector3.forward, 180.0f); imageCube.GetComponent<MeshRenderer>().material = mat; emptySlotMat = Resources.Load<Material>("EventThumbnails/ObjMat_Default/Mat_Empty"); defaultSlotMat = Resources.Load<Material>("EventThumbnails/ObjMat_Default/Mat_Default"); //create param cubes at the correct offset offsets = LitJson.JsonMapper.ToObject<ImageOffsets>(offsetsFile.text); if (offsets.Offsets.Length < evnt.NrOfNeededRoles) { //do nothing, else we crash as we don't have enough offsets } else { //use the offsets to place the param cubes at the correct position for (int i = 0; i < evnt.NrOfNeededRoles; i++) { int index = i; evnt.GetSelectorForIndex(i).OnObjectChanged += (SmartObject o, SmartObject n) => SetCube(index); paramCubes.Add(CreateParamCube(offsets.Offsets[i])); SetCube(i); } } } this.hasTexture = mat != null && offsetsFile != null && offsets.Offsets.Length >= evnt.NrOfNeededRoles; zOffset += 1.0f; }
public void EventStubHandlerCountTests() { var eventStub = new EventStub(typeof(ISampleInterface)); var sampleService = new SampleService(); eventStub.WireTo(sampleService); Assert.AreEqual(0, sampleService.SimpleEventHandlerCount); eventStub.AddHandler("SimpleEvent", new EventHandler((s, e) => { })); Assert.AreEqual(1, sampleService.SimpleEventHandlerCount); eventStub.AddHandler("SimpleEvent", new EventHandler((s, e) => { })); Assert.AreEqual(2, sampleService.SimpleEventHandlerCount); }
public void AbortFirstEvent_AbortsFirstOfMultipleTypes() { var em = new EventManager(); em.Initialize(); em.PostInitialize(); var @event = new EventStub(); em.QueueEvent(@event); em.QueueEvent(new EventStub2()); var result = em.AbortFirstEvent <EventStub2>(); Assert.IsTrue(result); Assert.AreEqual(1, em.PendingEvents.Count); Assert.AreSame(@event, em.PendingEvents.First()); }
/// <summary> /// Removes wires between server and client components (as defined in correlation set). /// </summary> /// <param name="type">Type of the server component</param> /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param> /// <param name="delegateCorrelationSet">Correlation set with wiring information</param> /// <param name="wiringList">List with known wirings</param> private void RemoveClientServerWires(Type type, EventStub eventStub, List <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList) { if (delegateCorrelationSet == null) { return; } foreach (var correlationInfo in delegateCorrelationSet) { if (wiringList.ContainsKey(correlationInfo.CorrelationID)) { var dynamicWireDelegate = wiringList[correlationInfo.CorrelationID]; eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicWireDelegate); wiringList.Remove(correlationInfo.CorrelationID); } } }
/// <summary> /// Removes wires between server and client components (as defined in correlation set). /// </summary> /// <param name="type">Type of the server component</param> /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param> /// <param name="delegateCorrelationSet">Correlation set with wiring information</param> /// <param name="wiringList">List with known wirings</param> private void RemoveClientServerWires(Type type, EventStub eventStub, IEnumerable <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList) { if (delegateCorrelationSet == null) { return; } var currentSession = ServerSession.CurrentSession; foreach (var correlationInfo in delegateCorrelationSet) { if (wiringList.ContainsKey(correlationInfo.CorrelationID)) { lock (wiringList) { if (!wiringList.ContainsKey(correlationInfo.CorrelationID)) { continue; } var dynamicWireDelegate = wiringList[correlationInfo.CorrelationID]; eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicWireDelegate); wiringList.Remove(correlationInfo.CorrelationID); var dynamicWire = DynamicWireFactory.GetDynamicWire(dynamicWireDelegate); if (dynamicWire != null) { dynamicWire.Dispose(); } } _host.OnSubscriptionRemoved(new SubscriptionEventArgs { ComponentType = type, DelegateMemberName = correlationInfo.DelegateMemberName, CorrelationID = correlationInfo.CorrelationID, }); } } if (currentSession != null) { currentSession.UntrackRemoteSubscriptions(delegateCorrelationSet); } }
public void EventStub_WireUnwireTests() { var eventStub = new EventStub(typeof(ISampleInterface)); var simpleEventFired = false; var cancelEventFired = false; var actionFired = false; var funcFired = false; // add event handlers eventStub.AddHandler("SimpleEvent", new EventHandler((sender, args) => simpleEventFired = true)); eventStub.AddHandler("CancelEvent", new EventHandler <CancelEventArgs>((sender, args) => cancelEventFired = true)); eventStub.AddHandler("ActionDelegate", new Action(() => actionFired = true)); eventStub.AddHandler("FuncDelegate", new Func <int, string>(a => { funcFired = true; return(a.ToString()); })); eventStub.AddHandler("FuncDelegate", new Func <int, string>(a => { return((a * 2).ToString()); })); // wire up events var component = new SampleService(); eventStub.WireTo(component); // test if it works var result = component.FireHandlers(102030); Assert.AreEqual("204060", result); Assert.IsTrue(simpleEventFired); Assert.IsTrue(cancelEventFired); Assert.IsTrue(actionFired); Assert.IsTrue(funcFired); // unwire simpleEventFired = false; cancelEventFired = false; actionFired = false; funcFired = false; eventStub.UnwireFrom(component); // test if it works result = component.FireHandlers(123); Assert.IsNull(result); Assert.IsFalse(simpleEventFired); Assert.IsFalse(cancelEventFired); Assert.IsFalse(actionFired); Assert.IsFalse(funcFired); }
/// <summary> /// Creates wires between client component and server component. /// </summary> /// <param name="type">Implementation type of the server component.</param> /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param> /// <param name="delegateCorrelationSet">Correlation set (say how to wire)</param> /// <param name="wiringList">Collection of built wires</param> private void CreateClientServerWires(Type type, EventStub eventStub, List <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList) { if (delegateCorrelationSet == null) { return; } foreach (var correlationInfo in delegateCorrelationSet) { if (wiringList.ContainsKey(correlationInfo.CorrelationID)) { continue; } if (ServerSession.CurrentSession == null) { throw new InvalidSessionException(string.Format(LanguageResource.InvalidSessionException_SessionIDInvalid, "(null)")); } var dynamicWire = DynamicWireFactory.CreateDynamicWire(type, correlationInfo.DelegateMemberName, correlationInfo.IsEvent); dynamicWire.Interceptor = correlationInfo.ClientDelegateInterceptor; if (correlationInfo.IsEvent) { var dynamicEventWire = (DynamicEventWireBase)dynamicWire; dynamicEventWire.EventFilter = correlationInfo.EventFilter; // add session validation handler and unsubscription callback var sessionId = ServerSession.CurrentSession.SessionID; var sessionManager = _host.SessionManager; dynamicEventWire.ValidateSession = () => sessionManager.ExistSession(sessionId); dynamicEventWire.CancelSubscription = () => eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate); eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate); wiringList.Add(correlationInfo.CorrelationID, dynamicEventWire.InDelegate); } else { eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicWire.InDelegate); wiringList.Add(correlationInfo.CorrelationID, dynamicWire.InDelegate); } } }
public void EventStub_FuncDelegateTests() { // add the first handler var eventStub = new EventStub(typeof(ISampleInterface)); var fired = false; eventStub.AddHandler("FuncDelegate", new Func <int, string>(a => { fired = true; return(a.ToString()); })); // check if it is called var handler = (Func <int, string>)eventStub["FuncDelegate"]; var result = handler(123); Assert.IsTrue(fired); Assert.AreEqual("123", result); // add the second handler fired = false; var firedAgain = false; var tempHandler = new Func <int, string>(a => { firedAgain = true; return(a.ToString()); }); eventStub.AddHandler("FuncDelegate", tempHandler); // check if it is called result = handler(321); Assert.IsTrue(fired); Assert.IsTrue(firedAgain); Assert.AreEqual("321", result); // remove the second handler fired = false; firedAgain = false; eventStub.RemoveHandler("FuncDelegate", tempHandler); // check if it is not called result = handler(0); Assert.IsTrue(fired); Assert.IsFalse(firedAgain); Assert.AreEqual("0", result); }
public void EventStub_CancelEventTests() { // add the first handler var eventStub = new EventStub(typeof(ISampleInterface)); var fired = false; eventStub.AddHandler("CancelEvent", new EventHandler <CancelEventArgs>((sender, args) => fired = true)); // check if it is called var handler = (EventHandler <CancelEventArgs>)eventStub["CancelEvent"]; handler(this, new CancelEventArgs()); Assert.IsTrue(fired); // add the second handler fired = false; var firedAgain = false; var tempHandler = new EventHandler <CancelEventArgs>((sender, args) => firedAgain = true); eventStub.AddHandler("CancelEvent", tempHandler); // check if it is called handler(this, new CancelEventArgs()); Assert.IsTrue(fired); Assert.IsTrue(firedAgain); // remove the second handler fired = false; firedAgain = false; eventStub.RemoveHandler("CancelEvent", tempHandler); // check if it is not called handler(this, new CancelEventArgs()); Assert.IsTrue(fired); Assert.IsFalse(firedAgain); }
public void EventStub_ActionDelegateTests() { // add the first handler var eventStub = new EventStub(typeof(ISampleInterface)); var fired = false; eventStub.AddHandler("ActionDelegate", new Action(() => fired = true)); // check if it is called var handler = (Action)eventStub["ActionDelegate"]; handler(); Assert.IsTrue(fired); // add the second handler fired = false; var firedAgain = false; var tempHandler = new Action(() => firedAgain = true); eventStub.AddHandler("ActionDelegate", tempHandler); // check if it is called handler(); Assert.IsTrue(fired); Assert.IsTrue(firedAgain); // remove the second handler fired = false; firedAgain = false; eventStub.RemoveHandler("ActionDelegate", tempHandler); // check if it is not called handler(); Assert.IsTrue(fired); Assert.IsFalse(firedAgain); }
/// <summary> /// Fill in the participants for the current event stub based on the set of rules defined. /// </summary> public void FillIn(EventStub evnt) { EventPopulation selected = new RoleFiller( manager.ToStoryArc(), manager.GetLevelForEvent(evnt) - 1, evnt.ToStoryEvent(), FillInOptionsSerializer.ActiveRules, stateSpaceManager).FillInRoles(); //if we found a match, try setting the params. Success here is guaranteed. if (selected != null) { evnt.TrySetParams(selected.AsParams().Cast<SmartObject>()); } }
/// <summary> /// Start dragging an event to position it within a new beat. /// </summary> private void StartDragEvent(EventStub current) { eventDragRect = rectangleForEvent[current]; draggingEvent = true; }
/// <summary> /// Adds the given authored event to the list of events for the given object. /// </summary> private void AddAuthoredEventToObject(EventStub authoredEvent, SmartObject obj) { if (authoredEvent.Participants.Contains(obj)) { GetParticipatingEvents(obj).Add(authoredEvent); } GetInvolvedInEvents(obj).Add(authoredEvent); }
/// <summary> /// Calculates the level of the given event stub. /// </summary> private void CalculateLevel(EventStub eventStub) { int max = DEFAULT_LEVEL + 1; foreach (EventStub evnt in eventStub.Predecessors) { max = Mathf.Max(max, GetLevelForEvent(evnt) + 1); } levelsForEvents[eventStub] = max; }
/// <summary> /// Adds the predecessor event to the given event stub. /// </summary> public void AddPredecessor(EventStub eventStub, EventStub predecessor) { eventStub.AddPredecessor(predecessor); CalculateLevelRecursively(eventStub); }
/// <summary> /// Adds a termination dependency, so that toTerminate temrinates as soon as dependentOn does. /// </summary> public void AddTerminationDependency(EventStub dependentOn, EventStub toTerminate) { AddTerminationDependency(dependentOn.ID, toTerminate.ID); }
/// <summary> /// Updates an existing event after new objects were added to its participants. /// </summary> private void UpdateAuthoredEvent(EventStub authoredEvent) { foreach (SmartObject obj in authoredEvent.InvolvedObjects) { AddAuthoredEventToObject(authoredEvent, obj); } ComputePredecessors(authoredEvent); }
/// <summary> /// Gets the level of the given event. If the event has no level (i.e. /// it is not in the manager), returns 0. /// </summary> public int GetLevelForEvent(EventStub evnt) { if (!levelsForEvents.ContainsKey(evnt)) { return DEFAULT_LEVEL; } return levelsForEvents[evnt]; }
/// <summary> /// Adds a predecessor to the given event and recalculates its level. /// </summary> public void AddPredecessorToEvent(EventStub currentEvent, EventStub predecessor) { manager.AddPredecessor(currentEvent, predecessor); CalculateEventAndObjectPositions(); }
/// <summary> /// Adds a new empty event to the window. /// </summary> public void AddEmptyEvent(EventStub currentEvent) { currentEventStub = currentEvent; AddEvent(currentEvent, true); }
/// <summary> /// Removes the given event from the GUI and the manager. /// </summary> private void RemoveEvent(EventStub evnt, bool removeFromManager = true) { if (evnt == currentEventStub) { currentEventStub = null; } connectors.Remove(evnt); rectangleForEvent.Remove(evnt); foreach (int key in levels.Keys) { levels[key].eventsInLevel.Remove(evnt); } if (removeFromManager) { manager.RemoveEvent(evnt); } IEnumerable<Texturizer> eventTexturizers = texturizers.Where((Texturizer t) => t.Event == evnt); if (eventTexturizers.Count() > 0) { eventTexturizers.First().Destroy(); texturizers.Remove(eventTexturizers.First()); } }
/// <summary> /// Logic for adding an event that is used both in AddEmptyEvent and AddFinishedEvent. /// If addToManager is true, adds the event to the AuthoredEventManager.W /// </summary> private void AddEvent(EventStub currentEvent, bool addToManager) { if (addToManager) { AuthoredEventManager.Instance.AddAuthoredEvent(currentEvent); } for (int i = 0; i < currentEvent.NrOfNeededRoles; i++) { currentEvent.GetSelectorForIndex(i).OnObjectChanged += ((SmartObject o, SmartObject n) => UpdateEventParticipants(currentEvent, o, n)); } connectors.Add(currentEvent, new HashSet<ParticipantConnector>()); rectangleForEvent[currentEvent] = new ContentRectangle<EventStub>(currentEvent, false, new Rect(0, 0, 0, 0), true, EventStubContent); rectangleForEvent[currentEvent].Style = rectangleForEvent[currentEvent].GetContent().image == null ? GUI.skin.button : GUI.skin.GetStyle("ImageBackground"); rectangleForEvent[currentEvent].onRightClick = this.onEventRightClick; rectangleForEvent[currentEvent].onLeftClick = this.onEventLeftClick; rectangleForEvent[currentEvent].onMouseOver = this.onEventMouseOver; rectangleForEvent[currentEvent].onMouseOut = this.onEventMouseOut; rectangleForEvent[currentEvent].RegisterLeftClickAction(StartDragEvent); for (int i = 0; i < currentEvent.NrOfNeededRoles; i++) { connectors[currentEvent].Add(new ParticipantConnector(i, currentEvent, this)); } CalculateEventAndObjectPositions(); }
/// <summary> /// Returns whether toTerminate's termination depends on the one of dependentOn /// </summary> public bool HasDependency(EventStub dependentOn, EventStub toTerminate) { return dependencies[toTerminate.ID].Contains(dependentOn.ID); }
/// <summary> /// Adds a new event to the window, where this event already has all the required parameters set. /// addToManager specifies whether the given event should then be added to the manager. /// keepCurrentLevel specifies whether the current level should be kept in the manager. /// </summary> public void AddFinishedEvent(EventStub evnt, bool addToManager) { foreach (SmartObject obj in evnt.InvolvedObjects) { AddSmartObject(obj); } AddEvent(evnt, addToManager); }
bool Equals(EventStub @event) { return(!ReferenceEquals(@event, null) && Value.Equals(@event.Value)); }
/// <summary> /// Reflect an update of the given's event stubs in the GUI. /// </summary> private void UpdateEventParticipants(EventStub eventStub, SmartObject oldObj, SmartObject newObj) { CalculateEventAndObjectPositions(); }
/// <summary> /// Sets the rectangle for the given Event Stub to be of the given color. /// </summary> public void SetEventColor(EventStub evnt, Color color) { if (rectangleForEvent.ContainsKey(evnt)) { rectangleForEvent[evnt].Highlight(color); } }
/// <summary> /// Adds the given event to the event list. /// The event does not need to have all parameters set yet. /// keepCurrentLevel indicates whether the event should stay at its level /// and other events should change if necessary. If it is false, the event will /// be added at its last possible position, i.e. after any conflicting event. /// </summary> public void AddAuthoredEvent(EventStub authoredEvent) { CalculateLevel(authoredEvent); //registers the object selector's listeners to update the event stub when the involved objects change for (int i = 0; i < authoredEvent.NrOfNeededRoles; i++) { authoredEvent.GetSelectorForIndex(i).OnObjectChanged += (SmartObject o, SmartObject n) => UpdateAuthoredEvent(authoredEvent); authoredEvent.GetSelectorForIndex(i).OnObjectChanged += (SmartObject o, SmartObject n) => { if (o != null && o != n) { if (!authoredEvent.InvolvedObjects.Contains(o)) GetInvolvedInEvents(o).Remove(authoredEvent); if (!authoredEvent.Participants.Contains(o)) GetParticipatingEvents(o).Remove(authoredEvent); CalculateLevel(o); } }; } UpdateAuthoredEvent(authoredEvent); allEvents.Add(authoredEvent); dependencies.Add(authoredEvent.ID, new List<EventID>()); }
/// <summary> /// Resets any color previously set for the given Event Stub. /// </summary> public void ResetEventColor(EventStub evnt) { if (rectangleForEvent.ContainsKey(evnt)) { rectangleForEvent[evnt].Unhighlight(); } }
/// <summary> /// Removes the given event. Note that the event may not be predecessor /// of any other event, or the behavior is not defined. /// </summary> public void RemoveEvent(EventStub authoredEvent) { //Setting all to null actually makes cleanup easier, as all event handlers will be informed //that the old object was removed from the event for (int i = 0; i < authoredEvent.NrOfNeededRoles; i++) { authoredEvent.GetSelectorForIndex(i).TrySet(null); } //removes the event from any list/dictionary where it could be contained allEvents.Remove(authoredEvent); levelsForEvents.Remove(authoredEvent); //it is possible that the removed event is in a middle level, this makes sure that the predecessors are changed correctly, //i.e. any event that has a predecessor connection through the removed event, now has a direct connection foreach (EventStub evnt in allEvents.Where((EventStub e) => e.Predecessors.Contains(authoredEvent))) { evnt.RemovePredecessor(authoredEvent); foreach (EventStub e in authoredEvent.Predecessors) { evnt.AddPredecessor(e); } CalculateLevelRecursively(evnt); } dependencies.Remove(authoredEvent.ID); }
/// <summary> /// Get the GUIContent for an EventStub. /// </summary> private GUIContent EventStubContent(EventStub evnt) { Texturizer texturizer = new Texturizer(evnt); this.texturizers.Add(texturizer); if (texturizer.HasTexture()) { return new GUIContent(texturizer.GetTexture(), "Termination dependencies are highlighted"); } else { return new GUIContent(evnt.Name, "Termination dependencies are highlighted"); } }
/// <summary> /// Removes the termination dependency, so that toTerminate's termination no longer depends on /// dependentOn's termination. /// </summary> public void RemoveTerminationDependency(EventStub dependentOn, EventStub toTerminate) { dependencies[toTerminate.ID].Add(dependentOn.ID); }
/// <summary> /// Draws lines from the given rectangle to the contained object's predecessors' rectangles, as well as to the /// "life lines" of the event's involved objects. /// </summary> private void DrawLines(EventStub evnt) { foreach (Connector connector in connectors[evnt]) { connector.Render(); } }
/// <summary> /// Sets the level of the given event to the given level, also applying changes necessary to other events /// that might have an overlap in participants. /// </summary> public void SetLevel(EventStub evnt, int level, bool cascade = false) { int oldLevel = GetLevelForEvent(evnt); //if level does not change, don't need to do anyrhing if (oldLevel == level) { return; } //if we add it to a higher level, must adapt predecessors and make sure any event in the //same level with overlapping participants is recursively set to a higher level if (oldLevel > level) { for (int i = level; i <= oldLevel; i++) { foreach (EventStub other in GetEventsInLevel(i)) { evnt.RemovePredecessor(other); if (i == level + 1 && other != evnt) { other.AddPredecessor(evnt); } } } foreach(EventStub other in GetEventsInLevel(level - 1)) { evnt.AddPredecessor(other); } levelsForEvents[evnt] = level; foreach (EventStub other in new List<EventStub>( GetEventsInLevel(level).Except(new EventStub[] { evnt }))) { if (other.ParticipantsOverlap(evnt)) { SetLevel(other, level + 1); } } } //if we add it to a lower level, must essentially do the same as wehn adding to a higher level but //adapting the predecessors is different if (oldLevel < level) { for (int i = oldLevel; i < level; i++) { foreach (EventStub other in GetEventsInLevel(i)) { other.RemovePredecessor(evnt); if (i == level - 1 && other != evnt) { evnt.AddPredecessor(other); } } } levelsForEvents[evnt] = level; foreach (EventStub other in new List<EventStub>( GetEventsInLevel(level).Except(new EventStub[] { evnt }))) { if (other.ParticipantsOverlap(evnt) || (other.Predecessors.Contains(evnt) && cascade)) { SetLevel(other, level + 1, true); } else { other.RemovePredecessor(evnt); } } } //Clean up any level that may be empty. CleanupEmptyLevels(1); //Calculate the level for any object in the event, as it might change foreach (SmartObject obj in evnt.InvolvedObjects) { CalculateLevel(obj); } }
/// <summary> /// Action to execute when doing mouse over over events. /// </summary> private void OnEventMouseOver(EventStub evnt) { foreach (EventStub current in rectangleForEvent.Keys) { if (manager.HasDependency(current, evnt)) { SetEventColor(current, Color.yellow); } } }
/// <summary> /// Calculates the level of a given event by looking at the levels of its /// predecessors. Also recursively calculates the level of any event, which /// has this event as predecessor. /// </summary> private void CalculateLevelRecursively(EventStub eventStub) { CalculateLevel(eventStub); foreach (EventStub evnt in allEvents.Where((EventStub e) => e.Predecessors.Contains(eventStub))) { CalculateLevelRecursively(evnt); } eventStub.InvolvedObjects.ForEach((SmartObject o) => CalculateLevel(o)); }
/// <summary> /// Action to execute when doing mouse out over events. /// </summary> private void OnEventMouseOut(EventStub evnt) { foreach (EventStub current in rectangleForEvent.Keys) { if (manager.HasDependency(current, evnt)) { ResetEventColor(current); } } }
/// <summary> /// Computes the predecessors for the given event, checking only for objects of type /// in nonOverLappingTypes. Can be called multiple times for any given event without /// causing duplicate predecessors. /// Also calculates the event's level as well as the object's level. /// </summary> public void ComputePredecessors(EventStub authoredEvent) { foreach (SmartObject obj in authoredEvent.Participants) { foreach (EventStub evnt in GetParticipatingEvents(obj). Where((EventStub evnt) => evnt != authoredEvent)) { if (GetLevelForEvent(evnt) >= GetLevelForEvent(authoredEvent)) { AddPredecessor(evnt, authoredEvent); } } } //CalculateLevelRecursively(authoredEvent); }
/// <summary> /// Adds a new menu when right clicking an event, which offers some options /// for the given event. /// </summary> private void AddEventContextMenu(EventStub evnt) { contextMenu = new ActionBar(false); contextMenuArea = new Rect( Event.current.mousePosition.x + scrollPosition.x, Mathf.Min(Event.current.mousePosition.y + scrollPosition.y - parent.HEIGHT_BARS, height - 140 + scrollPosition.y), 250, 125); //Close the context menu on cancel contextMenu.AddButton("Cancel", () => contextMenu = null); //Clear the event's parameters on Clear Params contextMenu.AddButton("Clear Params", () => { for (int i = 0; i < evnt.NrOfNeededRoles; i++) { evnt.GetSelectorForIndex(i).TrySet(null); } contextMenu = null; }); //Remove the event from the manager and GUI contextMenu.AddButton("Remove", () => { RemoveEvent(evnt); CalculateEventAndObjectPositions(); contextMenu = null; }); //Fill in missing parameters contextMenu.AddButton("Fill In", () => { FillIn(evnt); contextMenu = null; }); //Fill in missing parameters after selecting rules contextMenu.AddButton("Fill In With", () => { CreateFillInWithContextMenU(contextMenu); }); //Highlight the event contextMenu.AddButton("Highlight", () => { SetEventColor(evnt, Color.cyan); contextMenu = null; }); //Configure the camera for the event contextMenu.AddButton("Camera", () => { SelectCameraArguments(evnt); contextMenu = null; }); }
/// <summary> /// Creates wires between client component and server component. /// </summary> /// <param name="type">Implementation type of the server component.</param> /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param> /// <param name="delegateCorrelationSet">Correlation set (say how to wire)</param> /// <param name="wiringList">Collection of built wires</param> private void CreateClientServerWires(Type type, EventStub eventStub, IEnumerable <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList) { if (delegateCorrelationSet == null) { return; } var currentSession = ServerSession.CurrentSession; if (currentSession == null) { throw new InvalidSessionException(string.Format(LanguageResource.InvalidSessionException_SessionIDInvalid, "(null)")); } foreach (var correlationInfo in delegateCorrelationSet) { if (wiringList.ContainsKey(correlationInfo.CorrelationID)) { continue; } var dynamicWire = DynamicWireFactory.CreateDynamicWire(type, correlationInfo.DelegateMemberName, correlationInfo.IsEvent); dynamicWire.Interceptor = correlationInfo.ClientDelegateInterceptor; lock (wiringList) { if (wiringList.ContainsKey(correlationInfo.CorrelationID)) { continue; } if (correlationInfo.IsEvent) { var dynamicEventWire = (DynamicEventWireBase)dynamicWire; dynamicEventWire.EventFilter = correlationInfo.EventFilter; // add session validation handler and unsubscription callback var sessionId = currentSession.SessionID; var sessionManager = _host.SessionManager; dynamicEventWire.ValidateSession = () => sessionManager.ExistSession(sessionId); dynamicEventWire.CancelSubscription = ex => { eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate); wiringList.Remove(correlationInfo.CorrelationID); currentSession.DecrementRemoteSubscriptionCounter(); _host.OnSubscriptionCanceled(new SubscriptionEventArgs { ComponentType = type, DelegateMemberName = correlationInfo.DelegateMemberName, CorrelationID = correlationInfo.CorrelationID, Exception = ex }); }; eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate); wiringList.Add(correlationInfo.CorrelationID, dynamicEventWire.InDelegate); } else { eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicWire.InDelegate); wiringList.Add(correlationInfo.CorrelationID, dynamicWire.InDelegate); } } currentSession.IncrementRemoteSubscriptionCounter(); _host.OnSubscriptionAdded(new SubscriptionEventArgs { ComponentType = type, DelegateMemberName = correlationInfo.DelegateMemberName, CorrelationID = correlationInfo.CorrelationID, }); } }
/// <summary> /// Code for opening a new window to select camera arguments. /// </summary> private void SelectCameraArguments(EventStub evnt) { CameraArgumentWindow window = new CameraArgumentWindow(evnt); parent.mainArea = window; parent.AddActionBar(new ActionBar(true)); parent.ActionBar.AddButton("Cancel", parent.Reset); parent.ActionBar.AddButton("Save", () => { window.Save(); parent.Reset(); }); }