void inputProvider_NewFrame(object sender, NewFrameEventArgs e) { applicationService.DispatchFrame(e); }
public void DispatchFrame(NewFrameEventArgs e) { if(sessions.Count == 0) return; // For each contact determinte it's target handle and group by this handle IEnumerable<IGrouping<IntPtr, Contact>> contactsGroupedByHandle = e.Contacts.GroupBy(contact => Utils.GetWindowFromPoint(contact.Position)); // Create a list with sessions and contacts that belong to this session Dictionary<SessionContext, List<ContactData>> sessionList = new Dictionary<SessionContext, List<ContactData>>(); foreach (IGrouping<IntPtr, Contact> handleWithContacts in contactsGroupedByHandle) { List<ContactData> contacts; foreach (SessionContext sessionContext in from map in sessionToHandlesMap where map.Value.Contains(handleWithContacts.Key) || map.Value.Contains(IntPtr.Zero) select map.Key) { if (!sessionList.TryGetValue(sessionContext, out contacts)) { contacts = new List<ContactData>(); sessionList.Add(sessionContext, contacts); } contacts.AddRange(handleWithContacts.Select(c => new ContactData(c, handleWithContacts.Key))); } } List<SessionContext> emptyFrameReceivers = new List<SessionContext>(sessions.Values); // Send contact data to session foreach (KeyValuePair<SessionContext, List<ContactData>> keyValuePair in sessionList) { SessionContext session = keyValuePair.Key; try { session.Callback.Frame(new FrameData(e.Timestamp, keyValuePair.Value, GetImages(session, e.Images))); } catch (Exception exc) { Trace.TraceError("Error during sending frame to application:\r\n" + exc.Message); RemoveSession(session); } emptyFrameReceivers.Remove(keyValuePair.Key); } // Send frame data to sessions that requested empty frames foreach (SessionContext session in emptyFrameReceivers.Where(s => s.SendEmptyFrames)) { try { session.Callback.Frame(new FrameData(e.Timestamp, Enumerable.Empty<ContactData>(), GetImages(session, e.Images))); } catch (Exception exc) { Trace.TraceError("Error during sending frame to application:\r\n" + exc.Message); RemoveSession(session); } } }
internal void OnNewFrame(NewFrameEventArgs e) { EventHandler<NewFrameEventArgs> handler = NewFrame; if (handler != null) handler(this, e); }