public void AddPeripheral(IPeripheral peripheral) { if (this.peripherals.Any(x => x.GetType().Name == peripheral.GetType().Name)) { throw new ArgumentException($"Peripheral {peripheral.GetType().Name} already exists in {this.GetType().Name} with Id {this.Id}."); } this.peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Any(p => p.GetType().Name == peripheral.GetType().Name)) { throw new ArgumentException($"Peripheral {peripheral.GetType().Name } already exists in {GetType().Name} with Id {Id}."); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (this.periphrals.Any(p => p.GetType().Name == peripheral.GetType().Name)) { var msg = string.Format(ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id); throw new ArgumentException(msg); } this.periphrals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (Peripherals.Any(x => x.GetType() == peripheral.GetType())) { throw new ArgumentException($"Peripheral {peripheral.GetType().Name} already exists in {GetType().Name} with Id {Id}."); } ((ICollection <IPeripheral>)Peripherals).Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (this.peripherals.Any(x => x.GetType() == peripheral.GetType())) { string excMsg = string.Format(ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id); throw new ArgumentException(excMsg); } this.peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Any(p => p.GetType() == peripheral.GetType())) { throw new ArgumentException(String.Join(ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, Id)); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Any(x => x.GetType().Name == peripheral.GetType().Name)) { throw new ArgumentException (String.Format (ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, base.GetType().Name, Id)); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { foreach (var item in Peripherals) { if (item.GetType() == peripheral.GetType()) { throw new ArgumentException (String.Format(ExceptionMessages.ExistingPeripheral, peripheral.GetType(), this.GetType(), this.Id)); } } peripherals.Add(peripheral); }
public string RemovePeripheral(string peripheralType, int computerId) { if (DoesComputerExist(computerId)) { throw new ArgumentException(COMPUTER_DOESNT_EXIST); } //IPeripheral peripheral = computers // .Where(x => x.Id == computerId) // .FirstOrDefault() // .RemovePeripheral(peripheralType); IPeripheral peripheral = peripherals.FirstOrDefault(c => c.GetType().Name == peripheralType); IComputer computer = computers.First(c => c.Id == computerId); if (peripheral == null || peripherals.Count == 0) { return(null); } peripherals.Remove(peripheral); computer.RemovePeripheral(peripheralType); return($"Successfully removed {peripheral.GetType().Name} with id { peripheral.Id}."); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Contains(peripheral)) { throw new ArgumentException($"Component {peripheral.GetType()} already exists in {this.GetType()} with Id {this.Id}."); } peripherals.Add(peripheral); }
public void AttachGPIO(IPeripheral source, string connectorName, IGPIOReceiver destination, int destinationNumber, int?localReceiverNumber = null) { var connectors = source.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.Name == connectorName && typeof(GPIO).IsAssignableFrom(x.PropertyType)).ToArray(); var actualDestination = GetActualReceiver(destination, localReceiverNumber); DoAttachGPIO(source, connectors, actualDestination, destinationNumber); }
public void AddPeripheral(IPeripheral peripheral) { if (this.peripherals.Contains(peripheral)) { throw new ArgumentException(String.Format(ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id)); } this.peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (Peripherals.Any(p => p.GetType().Name == peripheral.GetType().Name)) { throw new ArgumentException(string.Format(ExceptionMessages.NotExistingPeripheral, peripheral.GetType().Name, GetType().Name, Id)); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Any(c => c.GetType().Name == peripheral.GetType().Name)) { throw new ArgumentException(string.Format (ExceptionMessages.ExistingComponent, peripheral.GetType().Name, this.GetType().Name, Id)); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Any(x => x.GetType() == peripheral.GetType())) { string err = String.Format(ExceptionMessages.ExistingPeripheral, peripheral, GetType().Name, Id); throw new ArgumentException(err); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { if (peripherals.Any(x => x.GetType().Name == peripheral.GetType().Name)) { //TODO: It is very possible this is not the correct ID !!!! throw new ArgumentException(String.Format(ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id)); } this.peripherals.Add(peripheral); }
public string GetAnyNameOrTypeName(IPeripheral peripheral) { string name; if (!TryGetAnyName(peripheral, out name)) { var managedThread = peripheral as IManagedThread; return(managedThread != null?managedThread.ToString() : peripheral.GetType().Name); } return(name); }
public string RemovePeripheral(string peripheralType, int computerId) { IPeripheral currentPeripheral = null; IComputer currentComp = computers.Where(x => x.Id == computerId).FirstOrDefault(); if (currentComp == null) { throw new ArgumentException(ExceptionMessages.NotExistingComputerId); } currentPeripheral = currentComp.RemovePeripheral(peripheralType); return(string.Format(SuccessMessages.RemovedPeripheral, currentPeripheral.GetType().Name, currentPeripheral.Id)); }
/// <summary> /// This method returns connected GPIO endpoints of a given peripheral. /// </summary> /// <returns>Collection of tuples: local GPIO name maped on endpoint to which it is connected. In case of INumberedGPIOOutput name is local number</returns> /// <param name="peripheral">Peripheral.</param> public static IEnumerable <Tuple <string, IGPIO> > GetGPIOs(this IPeripheral peripheral) { IEnumerable <Tuple <string, IGPIO> > result = null; var numberGPIOOuput = peripheral as INumberedGPIOOutput; if (numberGPIOOuput != null) { result = numberGPIOOuput.Connections.Select(x => Tuple.Create(x.Key.ToString(), x.Value)); } var local = peripheral.GetType().GetProperties().Where(x => x.PropertyType == typeof(GPIO)).Select(x => Tuple.Create(x.Name, (IGPIO)((GPIO)x.GetValue(peripheral)))); return(result == null ? local : result.Union(local)); }
public void AddPeripheral(IPeripheral peripheral) { IPeripheral currPeripherals = peripherals.FirstOrDefault(c => c.GetType().Name == peripheral.GetType().Name); if (currPeripherals != null) { throw new ArgumentException(string.Format(ExceptionMessages.ExistingPeripheral, currPeripherals.GetType().Name, this.GetType().Name, this.Id)); } peripherals.Add(peripheral); }
public void AddPeripheral(IPeripheral peripheral) { string peripheralType = peripheral.GetType().Name; if (peripherals.Any(x => x.GetType().Name == peripheralType)) { throw new ArgumentException(string.Format (ExceptionMessages .ExistingPeripheral, peripheralType, this.GetType().Name, this.Id)); } peripherals.Add(peripheral); }
public string RemovePeripheral(string peripheralType, int computerId) { if (IsComputerExistInCollection(computerId)) { throw new ArgumentException(COMPUTER_DOESNT_EXIST); } IPeripheral peripheral = this.computers.Where(x => x.Id == computerId).FirstOrDefault().RemovePeripheral(peripheralType); if (peripheral == null) { return(null); } return($"Successfully removed {peripheral.GetType().Name} with id { peripheral.Id}."); }
public string RemovePeripheral(string peripheralType, int computerId) { if (!IsComputerExist(computerId)) { throw new ArgumentException("Computer with this id does not exist."); } var computer = computers.FirstOrDefault(c => c.Id == computerId); IPeripheral peripheral = computer.RemovePeripheral(peripheralType); peripherals.Remove(peripheral); return($"Successfully removed {peripheral.GetType().Name} with id {peripheral.Id}."); }
public static Endianess GetEndianness(this IPeripheral @this, Endianess?defaultEndianness = null) { var endianessAttributes = @this.GetType().GetCustomAttributes(typeof(EndianessAttribute), true); if (endianessAttributes.Length != 0) { return(((EndianessAttribute)endianessAttributes[0]).Endianess); } else if (defaultEndianness == null) { return(@this.GetMachine().SystemBus.Endianess); } else { return(defaultEndianness.Value); } }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { CheckIfPeripheralAlreadyExist(id); IPeripheral peripheral = CreatePeripheral(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType); CheckIfComputerExist(computerId); IComputer computer = GetComputerById(computerId); computer.AddPeripheral(peripheral); peripherals.Add(peripheral); return(string.Format(SuccessMessages .AddedPeripheral, peripheral.GetType().Name, peripheral.Id, computerId)); }
void InitializeGPIO(IPeripheral device, string deviceName, IGPIOReceiver receiver, IList <object> irqEntry, PropertyInfo defaultConnector) { if (!(irqEntry[0] is string && irqEntry[1] is int)) { throw new ArgumentException(); } //May throw AmbiguousMatchException - then use BindingFlags.DeclaredOnly or sth var connector = device.GetType().GetProperty(irqEntry[0] as string); if (connector == null) { throw new ArgumentException(); } var gpio = connector.GetValue(device, null) as GPIO; if (gpio == null) { FailDevice(deviceName); } gpio.Connect(receiver, (int)irqEntry[1]); }
public InterruptManager(IPeripheral master, IGPIO irq = null, string gpioName = null, int subvector = -1) { if (!typeof(TInterrupt).IsEnum) { throw new ArgumentException("TInterrupt must be an enum"); } this.master = master; activeInterrupts = new HashSet <TInterrupt>(); enabledInterrupts = new HashSet <TInterrupt>(); subvectors = new Dictionary <IGPIO, HashSet <TInterrupt> >(); gpioNames = new Dictionary <IGPIO, string>(); nonsettableInterrupts = new HashSet <TInterrupt>(); enabledOnResetInterrupts = new HashSet <TInterrupt>(); var subvectorIdToGpio = new Dictionary <int, IGPIO>(); if (irq != null) { subvectorIdToGpio.Add(subvector, irq); gpioNames[irq] = gpioName ?? string.Empty; } else { // scan for irq providers foreach (var member in master.GetType().GetProperties()) { var irqProviderAttribute = (IrqProviderAttribute)member.GetCustomAttributes(typeof(IrqProviderAttribute), false).SingleOrDefault(); if (irqProviderAttribute == null) { continue; } var field = member.GetMethod.Invoke(master, new object[0]); if (field == null) { throw new ArgumentException("Trying to create the InterruptManager instance, but the IrqProvider object is not initialized"); } var gpioField = field as IGPIO; if (gpioField == null) { throw new ArgumentException("IrqProviderAttribute can only be used on properties of type IGPIO."); } subvectorIdToGpio.Add(irqProviderAttribute.SubvectorId, gpioField); gpioNames[gpioField] = irqProviderAttribute.Name ?? member.Name; } } // this iterates over all values of an enum (SpecialName here is to filter out non-value members of enum type) foreach (var member in typeof(TInterrupt).GetFields().Where(x => !x.Attributes.HasFlag(FieldAttributes.SpecialName))) { var subvectorId = 0; var subvectorAttribute = member.GetCustomAttributes(false).OfType <SubvectorAttribute>().SingleOrDefault(); var nonsettableAttribute = member.GetCustomAttributes(false).OfType <NotSettableAttribute>().SingleOrDefault(); var enabledOnResetAttribute = member.GetCustomAttributes(false).OfType <EnabledOnResetAttribute>().SingleOrDefault(); if (subvectorAttribute != null) { if (!subvectorIdToGpio.ContainsKey(subvectorAttribute.SubvectorId)) { throw new ArgumentException(string.Format("There is no gpio defined for subvector {0}", subvectorAttribute.SubvectorId)); } subvectorId = subvectorAttribute.SubvectorId; } else { if (!subvectorIdToGpio.ContainsKey(-1)) { throw new ArgumentException("There is no default gpio defined"); } subvectorId = -1; } var gpio = subvectorIdToGpio[subvectorId]; if (!subvectors.TryGetValue(gpio, out HashSet <TInterrupt> interrupts)) { interrupts = new HashSet <TInterrupt>(); subvectors.Add(gpio, interrupts); } var interrupt = (TInterrupt)Enum.Parse(typeof(TInterrupt), member.Name); interrupts.Add(interrupt); if (nonsettableAttribute != null) { nonsettableInterrupts.Add(interrupt); } if (enabledOnResetAttribute != null) { enabledOnResetInterrupts.Add(interrupt); } } Reset(); }
void InitializeGPIO(IPeripheral device, IGPIOReceiver receiver, IList<object> irqEntry, PropertyInfo defaultConnector) { if(!(irqEntry[0] is string && irqEntry[1] is int)) { throw new ArgumentException(); } //May throw AmbiguousMatchException - then use BindingFlags.DeclaredOnly or sth var connector = device.GetType().GetProperty(irqEntry[0] as string); if(connector == null) { throw new ArgumentException(); } var gpio = connector.GetValue(device, null) as GPIO; if(gpio == null) { connector.SetValue(device, new GPIO(), null); gpio = connector.GetValue(device, null) as GPIO; } gpio.Connect(receiver, (int)irqEntry[1]); }
public void AddPeripheral(IPeripheral peripheral) { var existingPerpheral = this.peripherals.FirstOrDefault(x => x.GetType().Name == peripheral.GetType().Name); if (existingPerpheral != null) { throw new ArgumentException(string.Format(ExceptionMessages.ExistingPeripheral, existingPerpheral.GetType().Name, this.GetType().Name, this.Id)); } this.peripherals.Add(peripheral); }
public static Machine GetMachine(this IPeripheral @this) { if ([email protected](out var machine)) { throw new ArgumentException($"Couldn't find machine for given peripheral of type {@this.GetType().FullName}."); } return(machine); }
public void AddPeripheral(IPeripheral peripheral) { if (Peripherals.Contains(peripheral)) { // public const string ExistingPeripheral = "Peripheral {0} already exists in {1} with Id {2}."; throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.ExistingPeripheral, peripheral.GetType().Name, this.GetType().Name, this.Id)); } else { peripherals.Add(peripheral); //public const string AddedPeripheral = "Peripheral {0} with id {1} added successfully in computer with id {2}."; //Console.WriteLine(string.Format(Common.Constants.SuccessMessages.AddedComponent, peripheral.GetType(), peripheral.Id, this.Id)); } }