Exemple #1
0
        public DeviceTreeViewModel(Device rootDevice, DeviceConfiguration deviceConfiguration)
        {
            Title = "Сравнение конфигураций";
            RootDevice = rootDevice;
            DeviceConfiguration = deviceConfiguration;
            DeviceConfiguration.Reorder();

            BuildTree(rootDevice);
            if (Devices.Count > 0)
            {
                //CollapseChild(Devices[0]);
                ExpandChild(Devices[0]);
                SelectedDevice = Devices[0];
            }
        }
        public DeviceConfigurationViewModel(Guid deviceUID, DeviceConfiguration remoteDeviceConfiguration)
        {
            Title = "Сравнение конфигураций";
            ReplaceCommand = new RelayCommand(OnReplace);
			if (remoteDeviceConfiguration == null)
			{
				MessageBoxService.ShowError("Ошибка при считывании конфигурации");
				return;
			}

            RemoteDeviceConfiguration = remoteDeviceConfiguration;
            RemoteDeviceConfiguration.Reorder();
            RemoteDeviceConfiguration.Update();
            RemoteDeviceConfiguration.InvalidateConfiguration();
            RemoteDeviceConfiguration.UpdateCrossReferences();

			//foreach (var device in RemoteDeviceConfiguration.Devices)
			//{
			//    device.Driver = FiresecManager.Drivers.FirstOrDefault(x => x.UID == device.Driver.UID);
			//}

            LocalRootDevice = FiresecManager.Devices.FirstOrDefault(x => x.UID == deviceUID);
            RemoteRootDevice = RemoteDeviceConfiguration.Devices.FirstOrDefault(x => x.UID == deviceUID);
        	RemoteRootDevice.Driver = LocalRootDevice.Driver;

            LocalRootClone = (Device)FiresecManager.Devices.FirstOrDefault(x => x.UID == deviceUID).Clone();
            RemoteRootClone = (Device)RemoteDeviceConfiguration.Devices.FirstOrDefault(x => x.UID == deviceUID).Clone();

            LocalRootClone.Children = new List<Device>();
            if (LocalRootDevice.Children != null)
                foreach (var children in LocalRootDevice.Children)
                {
                    var childrenClone = (Device)children.Clone();
                    childrenClone.DeviceConfiguration = FiresecManager.FiresecConfiguration.DeviceConfiguration;
                    LocalRootClone.Children.Add(childrenClone);
                    if (children.Children != null)
                    {
                        var localchch =
                            LocalRootClone.Children.FirstOrDefault(
                                x =>
                                ((x.PresentationName == children.PresentationName) &&
                                 (x.AddressFullPath == children.AddressFullPath)));
                        localchch.Children = new List<Device>();
                        foreach (var chch in children.Children)
                        {
                            var chchClone = (Device)chch.Clone();
                            chchClone.DeviceConfiguration = FiresecManager.FiresecConfiguration.DeviceConfiguration;
                            localchch.Children.Add(chchClone);
                        }
                    }
                }

            RemoteRootClone.Children = new List<Device>();
            if (RemoteRootDevice.Children != null)
                foreach (var children in RemoteRootDevice.Children)
                {
                    var childrenClone = (Device)children.Clone();
                    childrenClone.DeviceConfiguration = RemoteDeviceConfiguration;
                    RemoteRootClone.Children.Add(childrenClone);
                    if (children.Children != null)
                    {
                        var remotechch =
                            RemoteRootClone.Children.FirstOrDefault(
                                x =>
                                ((x.PresentationName == children.PresentationName) &&
                                 (x.AddressFullPath == children.AddressFullPath)));
                        remotechch.Children = new List<Device>();
                        foreach (var chch in children.Children)
                        {
                            var chchClone = (Device)chch.Clone();
                            chchClone.DeviceConfiguration = RemoteDeviceConfiguration;
                            remotechch.Children.Add(chchClone);
                        }
                    }
                }
            IntoLocalDevice(LocalRootDevice, RemoteRootClone);
            IntoRemoteDevice(RemoteRootDevice, LocalRootClone);

            Sort(LocalRootClone);
            Sort(RemoteRootClone);

            LocalDevices = new DeviceTreeViewModel(LocalRootClone);
            RemoteDevices = new DeviceTreeViewModel(RemoteRootClone);
        }