/// <summary> /// Updates an instance of <see cref="IConfigLogicalDriver" /> in the system registry asynchronously /// </summary> /// <param name="driverInfo"> /// An instance of <see cref="LogicalDeviceInformation" /> to update /// </param> /// <param name="editingDriver"> /// An instance of <see cref="IConfigLogicalDriver" /> to update /// </param> /// <returns>An instance of System.Threading.Tasks.Task that represents current asynchronous operation</returns> /// Обновляет драйвер public async Task <IConfigLogicalDriver> UpdateDriverAsync(LogicalDriverInformation driverInfo, IConfigLogicalDriver editingDriver) { this.ThrowIfDisposed(); await this.Initialization; Guard.AgainstNullReference(driverInfo, "deviceInfo"); await this.RemoveDriverAsync(editingDriver.DriverId); var logicalDriver = await this.CreateDriverInternalAsync(driverInfo); try { var context = await this._persistanceService.GetDriverPersistableContextAsync(logicalDriver.DriverId); await context.SaveDriverMomentoAsync(logicalDriver.CreateMomento()); this._driversCache.Remove(logicalDriver.DriverId); this._driversCache.Add(logicalDriver.DriverId, logicalDriver); } catch (Exception) { throw new LogicalDeviceException(); } return(logicalDriver); }
/// <summary> /// создаёт контекст драйвера и инициализирует его /// </summary> /// <param name="driverInfo"></param> /// <returns></returns> private IDriverContext MapDriverInfoToDriverContext(LogicalDriverInformation driverInfo) { //TODO: When more than one driver type exists this builder should be refactored!!!! var contextBuilder = new AomTcpDriverContextEntityBuilder(); contextBuilder.SetDriverType(driverInfo.DriverType); contextBuilder.SetTcpAddress(driverInfo.DriverTcpAddress); contextBuilder.SetTcpPortNumber(driverInfo.DriverTcpPort); return(contextBuilder.Build()); }
/// <summary> /// Creates an instance of <see cref="IConfigLogicalDriver" /> asynchronously /// </summary> /// <param name="logicalDriverInformation"> /// An instance of <see cref="LogicalDriverInformation" /> to obtain all information about deviceViewModel to create /// Инфа о драйвере /// </param> /// <returns>An instance of System.Threading.Tasks.Task that represents current asynchronous operation /// Таска с драйвером</returns> /// Созданёт драйвер устройства и сохраняет его в xml public async Task <IConfigLogicalDriver> CreateDriverAsync(LogicalDriverInformation logicalDriverInformation) { this.ThrowIfDisposed(); await this.Initialization; Guard.AgainstNullReference(logicalDriverInformation, "deviceInfo"); var driver = await this.CreateDriverInternalAsync(logicalDriverInformation); try { var driverContext = await this._persistanceService.GetDriverPersistableContextAsync(driver.DriverId); await driverContext.SaveDriverMomentoAsync(driver.CreateMomento()); this._driversCache.Add(driver.DriverId, driver); return(driver); } catch (Exception error) { throw new LogicalDriverCreationException(logicalDriverInformation, innerException: error); } }
//Создаёт драйвер объект драйвера из информации о нем private async Task <IConfigLogicalDriver> CreateDriverInternalAsync(LogicalDriverInformation driverInfo) { var context = this.MapDriverInfoToDriverContext(driverInfo); if ((await this.GetAllDriversAsync()).Any(a => a.Equals(context))) { throw new LogicalDriverAlreadyExistsExcetpion(driverInfo); } var driverFactory = _container.Resolve <ILogicalDriverFactory>(driverInfo.DriverType); if (driverFactory == null) { throw new UnknownLogicalDriverTypeException(driverInfo.DriverType); } var logicalDriver = driverFactory.CreateConfigLogicalDriver(); if (logicalDriver == null) { throw new LogicalDriverCreationException(driverInfo); } try { await logicalDriver.InitializeAsync(context); ((IConfigLogicalDriver)logicalDriver).DriverId = Guid.NewGuid(); } catch (Exception error) { throw new LogicalDriverCreationException(driverInfo, innerException: error); } return(logicalDriver); }
/// <summary> /// Creates an instance of <see cref="LogicalDriverCreationException" /> /// </summary> /// <param name="driverInfo"> /// An instance of <see cref="LogicalDriverInformation" /> that failed to be createde /// </param> /// <param name="message">n optional parameter that represents the message of the exception</param> /// <param name="innerException"> An instance of <see cref="Exception" /> that represents inner exception information</param> public LogicalDriverCreationException(LogicalDriverInformation driverInfo, string message = null, Exception innerException = null) : base(message, innerException) { this.DriverInfo = driverInfo; }
/// <summary> /// Creates an instance of <see cref="LogicalDriverAlreadyExistsExcetpion" /> /// </summary> /// <param name="logicalDriverInformation"> /// An instance of <see cref="LogicalDriverInformation" /> that represents failed driver /// </param> public LogicalDriverAlreadyExistsExcetpion(LogicalDriverInformation logicalDriverInformation) { this.LogicalDriverInformation = logicalDriverInformation; }