private void USBInserted(object sender, EventArrivedEventArgs e) { Thread.Sleep(DELAY_TIME); // wait for a while Dictionary<string, DriveInfo> newConnectedDrives = RetrieveAllDrives(); foreach (KeyValuePair<string, DriveInfo> kvp in newConnectedDrives) // find new drive inserted { if (!connectedDrives.ContainsKey(kvp.Key)) { DriveInfo drive = kvp.Value; //ServiceLocator.GetLogger(ServiceLocator.DEVELOPER_LOG).Write(drive.Name + " inserted."); DriveChangeEvent dce = new DriveChangeEvent(DriveChangeType.DRIVE_IN, drive); ServiceLocator.MonitorI.HandleDriveChange(dce); } } connectedDrives = newConnectedDrives; }
/// <summary> /// Handling drive change ( plug in and plug out) /// </summary> /// <param name="dce">Drive Change Event with all the objects</param> public void HandleDriveChange(DriveChangeEvent dce) { try { if (dce.Type == DriveChangeType.DRIVE_IN) { ProfilingLayer.Instance.UpdateDrive(dce.Info); Merge(dce.Info); string logical = ProfilingLayer.Instance.GetLogicalIdFromDrive(dce.Info); List<Tag> tagList = TaggingLayer.Instance.RetrieveTagByLogicalId(logical); foreach (Tag t in tagList) { SwitchMonitorTag(t, t.IsSeamless); } } else { ProfilingLayer.Instance.RemoveDrive(dce.Info); MonitorLayer.Instance.UnMonitorDrive(dce.Info.Name); } _userInterface.DriveChanged(); _userInterface.PathChanged(); _userInterface.TagsChanged(); } catch (Exception e) { ServiceLocator.GetLogger(ServiceLocator.DEBUG_LOG).Write(e); } }
private void USBRemoved(object sender, EventArrivedEventArgs e) { Dictionary<string, DriveInfo> newConnectedDrives = RetrieveAllDrives(); foreach (KeyValuePair<string, DriveInfo> kvp in connectedDrives) { if (!newConnectedDrives.ContainsKey(kvp.Key)) // find new drive removed { DriveInfo drive = kvp.Value; //ServiceLocator.GetLogger(ServiceLocator.DEVELOPER_LOG).Write(drive.Name + " removed."); DriveChangeEvent dce = new DriveChangeEvent(DriveChangeType.DRIVE_OUT, drive); ServiceLocator.MonitorI.HandleDriveChange(dce); } } connectedDrives = newConnectedDrives; }