public void DeviceUpdated( IDeviceMonitor monitor, IList<DevicePropertyChange> deviceChanges, IList<LinePropertyChange> lineChanges, IList<CallPropertyChange> callChanges) { // FIXME this is very inefficient List<PropertyChange> changes = new List<PropertyChange>(); foreach( PropertyChange change in deviceChanges ) changes.Add( change ); foreach( PropertyChange change in lineChanges ) changes.Add( change ); foreach( PropertyChange change in callChanges ) changes.Add( change ); foreach( PropertyChange change in changes ) // Note that we log changing to or from any given logging criteria if( LookupPropertyChangeBehaviour( change.Underlying, change.Property, change.ChangedTo ).Log || LookupPropertyChangeBehaviour( change.Underlying, change.Property, change.ChangedFrom ).Log ) Logger.Instance().Log( change.Underlying.GetType().Name + " property " + change.Property + " has changed from " + change.ChangedFrom + " to " + change.ChangedTo ); // Logging happens here: foreach( CallPropertyChange change in callChanges ) { if( change.Property == DeviceMonitor.PROPERTY_CALL_ACTIVITY ) { if ( change.ChangedTo == Activity.Connected.ToString() ) { CallRecord call = new CallRecord( monitor.GetDeviceState(), GetLine( change.Call ), change.Call, DateTime.Now, new DateTime() ); // Sanity check in case somehow call is already there if ( mCalls.ContainsKey( change.Call ) ) { mCalls.Remove( change.Call ); Logger.Instance().Log("Call #" + change.Call.Name + " had to be removed from the call list - did the previous call fail?"); } mCalls.Add( change.Call, call ); } else if ( change.ChangedFrom == Activity.Connected.ToString() ) { CallRecord call = mCalls[change.Call]; call.EndTime = DateTime.Now; CallLogger.Instance().Log(call); mCalls.Remove( change.Call ); } } if (change.Call.Activity != Activity.IdleDisconnected) { if ( mCalls.ContainsKey( change.Call ) ) { CallRecord call = mCalls[change.Call]; call.Call = change.Call; call.Line = GetLine(change.Call); mCalls[change.Call] = call; } } } if( StateUpdate != null ) StateUpdate( monitor, new StateUpdateEventArgs( deviceChanges, lineChanges, callChanges ) ); }
private void AddMonitorToTree( IDeviceMonitor monitor ) { // Use each node's key as a property name. Use each node's tag object as a state. Device deviceState = monitor.GetDeviceState(); TreeNode deviceNode = TreeStates.Nodes.Add( DeviceMonitor.PROPERTY_NAME, deviceState.Name ); deviceNode.Tag = deviceState; for( int i = 0; i < deviceState.Lines.Length; i++ ) { TreeNode lineNode = deviceNode.Nodes.Add( DeviceMonitor.PROPERTY_NAME, deviceState.Lines[ i ].Name ); lineNode.Tag = deviceState.Lines[ i ]; EnsureNodeContains( lineNode, deviceState.Lines[ i ], DeviceMonitor.PROPERTY_LINE_LASTCALLEDNUMBER, "", deviceState.Lines[ i ].LastCalledNumber ); EnsureNodeContains( lineNode, deviceState.Lines[ i ], DeviceMonitor.PROPERTY_LINE_LASTCALLERNUMBER, "", deviceState.Lines[ i ].LastCallerNumber ); EnsureNodeContains( lineNode, deviceState.Lines[ i ], DeviceMonitor.PROPERTY_LINE_MESSAGEWAITING, "", deviceState.Lines[ i ].MessageWaiting.ToString() ); EnsureNodeContains( lineNode, deviceState.Lines[ i ], DeviceMonitor.PROPERTY_LINE_REGISTRATIONSTATE, "", deviceState.Lines[ i ].RegistrationState.ToString() ); for( int j = 0; j < deviceState.Lines[ i ].Calls.Length; j++ ) { TreeNode callNode = lineNode.Nodes.Add( DeviceMonitor.PROPERTY_NAME, deviceState.Lines[ i ].Calls[ j ].Name ); callNode.Tag = deviceState.Lines[ i ].Calls[ j ]; EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_ACTIVITY, "", deviceState.Lines[ i ].Calls[ j ].Activity.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_BYTESRECEIVED, "", deviceState.Lines[ i ].Calls[ j ].BytesReceived.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_BYTESSENT, "", deviceState.Lines[ i ].Calls[ j ].BytesSent.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_DECODELATENCY, "", deviceState.Lines[ i ].Calls[ j ].DecodeLatency.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_DECODER, "", deviceState.Lines[ i ].Calls[ j ].Decoder ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_DURATION, "", deviceState.Lines[ i ].Calls[ j ].Duration ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_ENCODER, "", deviceState.Lines[ i ].Calls[ j ].Encoder ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_JITTER, "", deviceState.Lines[ i ].Calls[ j ].Jitter.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_PACKETERROR, "", deviceState.Lines[ i ].Calls[ j ].PacketError.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_PACKETLOSS, "", deviceState.Lines[ i ].Calls[ j ].PacketLoss.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_ROUNDTRIPDELAY, "", deviceState.Lines[ i ].Calls[ j ].RoundTripDelay.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_TONE, "", deviceState.Lines[ i ].Calls[ j ].Tone.ToString() ); EnsureNodeContains( callNode, deviceState.Lines[ i ].Calls[ j ], DeviceMonitor.PROPERTY_CALL_TYPE, "", deviceState.Lines[ i ].Calls[ j ].Type.ToString() ); } } deviceNode.ExpandAll(); }