public MediaChangerEx(MediaChanger changer, int ChangerId) { this.Discs = new Collection <DiscDataEx>(); Collection <DiscData> slotDiscs = changer.GetSlotDiscData(); Collection <DiscData> driveDiscs = changer.GetDriveDiscData(); int slotId = -1;//is -1 because it is in the drive foreach (DiscData disc in driveDiscs) { if (disc.DiscType == DiscType.Empty) { //nothing to add here } else { this.Discs.Add(new DiscDataEx(disc, slotId, ChangerId)); } } slotId = 0; foreach (DiscData disc in slotDiscs) { if (disc.DiscType == DiscType.Empty) { //nothing to add here } else { this.Discs.Add(new DiscDataEx(disc, slotId, ChangerId)); } slotId++; } }
//eject the disc public static void EjectDisc(DiscDataEx Disc) { Collection <MediaChanger> changers = OMLApplication.Current.MediaCenterEnvironment.MediaChangers; if (changers != null && changers.Count > Disc.ChangerId) { //our changer is valid MediaChanger changer = changers[Disc.ChangerId]; Collection <DiscData> discs = changer.GetSlotDiscData(); //check the slot... if (Disc.SlotId != -1) { //the slot is not valid anymore if (Disc.SlotId >= discs.Count || Disc.DiscId != discs[Disc.SlotId].DiscId) { Disc.SlotId = -1; } } //disc was in a drive when we scanned if (Disc.SlotId == -1) { //see if it is still there int driveIdx = 0; foreach (DiscData disc in changer.GetDriveDiscData()) { if (disc.DiscId == Disc.DiscId) { //get it out of the drive Disc.SlotId = changer.UnloadDisc(driveIdx); //force a rescan OMLApplication.Current.MediaChangers.ReScan(); //GetChangers the discs AGAIN discs = changer.GetSlotDiscData(); } } } //our id still valid if (discs.Count > Disc.SlotId && Disc.SlotId != -1 && discs[Disc.SlotId].DiscId == Disc.DiscId) { changer.EjectDisc(Disc.SlotId); //force a rescan OMLApplication.Current.MediaChangers.ReScan(); } else { throw new Exception("Disc Not Found."); } } else { throw new Exception("Disc Not Found."); } }
public MediaChangerEx(MediaChanger changer, int ChangerId) { this.Discs = new Collection<DiscDataEx>(); Collection<DiscData> slotDiscs = changer.GetSlotDiscData(); Collection<DiscData> driveDiscs = changer.GetDriveDiscData(); int slotId = -1;//is -1 because it is in the drive foreach (DiscData disc in driveDiscs) { if (disc.DiscType == DiscType.Empty) { //nothing to add here } else this.Discs.Add(new DiscDataEx(disc, slotId, ChangerId )); } slotId = 0; foreach (DiscData disc in slotDiscs) { if (disc.DiscType == DiscType.Empty) { //nothing to add here } else this.Discs.Add(new DiscDataEx(disc, slotId, ChangerId)); slotId++; } }
/// <summary> /// This is somewhat awkward /// </summary> /// <param name="Disc"></param> /// <returns></returns> public static string LoadDisc(DiscDataEx Disc) { //the drive letter of our disc once we load it string discDrive = ""; Collection <MediaChanger> changers = OMLApplication.Current.MediaCenterEnvironment.MediaChangers; if (changers != null && changers.Count > Disc.ChangerId) { //our changer is valid MediaChanger changer = changers[Disc.ChangerId]; Collection <DiscData> discs = changer.GetSlotDiscData(); //disc was in a drive when we scanned if (Disc.SlotId == -1) { //see if it is still there foreach (DiscData disc in changer.GetDriveDiscData()) { if (disc.DiscId == Disc.DiscId) { //found it-lets get out of here discDrive = disc.DrivePath; return(discDrive); } } //if we are here the disc is not in the drive int intSlotId = 0; foreach (DiscData disc in changer.GetSlotDiscData()) { if (Disc.DiscId == disc.DiscId) { Disc.SlotId = intSlotId; } intSlotId++; } } //load from slot if (Disc.SlotId != -1 && Disc.SlotId < discs.Count && Disc.DiscId == discs[Disc.SlotId].DiscId) { try { changer.UnloadDisc(0); } finally { changer.LoadDisc(Disc.SlotId, 0);//we always load to the first drive } //force a rescan OMLApplication.Current.MediaChangers.ReScan(); foreach (DiscData disc in changer.GetDriveDiscData()) { if (disc.DiscId == Disc.DiscId) { //found it-lets get out of here discDrive = disc.DrivePath; return(discDrive); } } } //if we are here lets throw throw new Exception("Disc Not Found."); } else { throw new Exception("Disc Not Found."); } //return discDrive; }