Example #1
0
        /// <summary>
        /// Конструктор класса. Объект создается со ссылкой на реальный объект.
        /// </summary>
        /// <param name="computer">Какой-то компьютер.</param>
        /// <param name="device">Родительский объект класса-заместителя.</param>
        /// <param name="partition">Реальный удаленный объект.</param>
        public PartitionProxy(IComputer computer, DeviceProxy device, IPartition partition)
            : base()
        {
            if (computer == null)
                throw new ArgumentNullException("computer");

            if (device == null)
                throw new ArgumentNullException("device");

            _computer = computer;
            _device = device;

            _computer.ConnectionChanged += new EventHandler(_computer_ConnectionChanged);

            Bind(partition);
        }
Example #2
0
        /// <summary>
        /// Обновление кеша.
        /// </summary>
        protected internal void UpdateData(bool updateDevices)
        {
            bool isDriverLoaded;
            long driverVersion;
            LicenseInfo license;

            List<IDevice> devices = null;
            List<DeviceProxy> addedDevices = null;
            List<DeviceProxy> removedDevices = null;

            // Получаем новые данные
            try
            {
                _computer.Context.PushContext();

                lock (_hostSync)
                {
                    if (_host == null)
                        return;
                    isDriverLoaded = _host.IsDriverLoaded;
                    driverVersion = _host.DriverVersion;
                    license = _host.License;

                    if (updateDevices)
                    {
                        devices = new List<IDevice>(_host.GetDevices());
                        addedDevices = new List<DeviceProxy>();
                        removedDevices = new List<DeviceProxy>();
                    }
                }

                bool propertyChanged = false;

                lock (this)
                {
                    // Проверяем, изменились ли свойства.
                    if (_cachedIsDriverLoaded != isDriverLoaded ||
                        _cachedDriverVersion != driverVersion ||
                        _cachedLicense != license)
                    {
                        propertyChanged = true;

                        //Обновляем данные кеша.
                        _cachedIsDriverLoaded = isDriverLoaded;
                        _cachedDriverVersion = driverVersion;
                        _cachedLicense = license;
                    }

                    if (updateDevices)
                    {
                        #region Определение списков новых и старых устройств

                        // Добавляем новые устройства, которых нет в старом списке.
                        foreach (IDevice device in devices)
                            if (!_deviceProxies.Exists(
                                delegate(DeviceProxy devProxy)
                                {
                                    return devProxy.IsBoundTo(device);
                                }))
                            {
                                DeviceProxy devProxy = new DeviceProxy(_computer, this, device);
                                _deviceProxies.Add(devProxy);
                                addedDevices.Add(devProxy);
                            }

                        // Удаляем исчезнувшие устройства.
                        _deviceProxies.RemoveAll(
                            delegate(DeviceProxy devProxy)
                            {
                                if( !devices.Exists(
                                    delegate(IDevice device)
                                    {
                                        return devProxy.IsBoundTo(device);
                                    })
                                    )
                                {
                                    removedDevices.Add(devProxy);
                                    return true;
                                }

                                return false;
                            }
                            );

                        #endregion
                    }
                } // lock

                // Оповещаем слушателей об изменениях.
                if (propertyChanged)
                    OnPropertyChanged(new HostEventArgs());

                if (updateDevices)
                {
                    foreach (DeviceProxy devProxy in addedDevices)
                        OnDeviceAdded(new HostEventArgs(devProxy));

                    foreach (DeviceProxy devProxy in removedDevices)
                        OnDeviceRemoved(new HostEventArgs(devProxy));

                    // Обновляем данные устройств.
                    List<DeviceProxy> deviceProxies = new List<DeviceProxy>();
                    lock (this)
                    {
                        deviceProxies.AddRange(_deviceProxies);
                    }
                    foreach (DeviceProxy devProxy in deviceProxies)
                        devProxy.UpdateData();
                }
            }
            catch (System.Security.SecurityException)
            {
            }
            catch (System.Runtime.Remoting.RemotingException)
            {

                _computer.OnDisconnect();
                return;
            }
            catch (System.Net.Sockets.SocketException)
            {

                _computer.OnDisconnect();
                return;
            }
            finally
            {
                _computer.Context.PopContext();
            }
        }