예제 #1
0
        /// <summary>
        /// Opens Window to select signals from a device.
        /// </summary>
        public void FixDuplicates(Mapping mapping)
        {
            if (mapping.ChannelMappings.Count() == 0 || !mapping.ChannelMappings.ContainsValue(""))
            {
                return;
            }

            int targetId = mapping.ChannelMappings.First(item => item.Value == "").Key;

            TemplateInputSignal targetSignal;

            using (AdoDataConnection connection = new AdoDataConnection(ConnectionString, DataProviderString))
                targetSignal = new TableOperations <TemplateInputSignal>(connection).QueryRecordWhere("Id = {0}", targetId);

            string title = "Select a Signal for " + targetSignal?.Name ?? "";

            SelectSignal signalSelection = new SelectSignal();
            SelectSignalMappingVM <AdaptSignal> dateSelectionVM = new SelectSignalMappingVM <AdaptSignal>((d) => {
                mapping.ChannelMappings[targetId] = d.ID;
                mapping.IsValid = !mapping.ChannelMappings.ContainsValue("");
                DeviceMappings  = new ObservableCollection <Mapping>(DeviceMappings);
                OnPropertyChanged(nameof(DeviceMappings));
                OnPropertyChanged(nameof(Valid));
            }, (d, s) => d.Name.ToLower().Contains(s.ToLower()), (d) => d.Name, AdaptSignal.Get(DataSource, DataSourceModel.ID, ConnectionString, DataProviderString)
                                                                                                          .Where(s => s.ID == mapping.SourceDeviceID && s.Phase == targetSignal.Phase && s.Type == targetSignal.MeasurmentType), title);

            signalSelection.DataContext = dateSelectionVM;
            signalSelection.Show();
        }
예제 #2
0
        /// <summary>
        /// Opens the Select Device Window
        /// </summary>
        private void SelectDevice(Mapping mapping)
        {
            SelectSignal deviceSelection = new SelectSignal();
            SelectSignalMappingVM <AdaptDevice> deviceSelectionVM = new SelectSignalMappingVM <AdaptDevice>((d) => {
                mapping.SourceDeviceID   = d.ID;
                mapping.SourceDeviceName = d.Name;

                mapping.ChannelMappings = new Dictionary <int, string>();

                // Validate Signals on that device
                List <TemplateInputSignal> targetSignals;
                using (AdoDataConnection connection = new AdoDataConnection(ConnectionString, DataProviderString))
                    targetSignals = new TableOperations <TemplateInputSignal>(connection)
                                    .QueryRecordsWhere("DeviceID = {0}", mapping.TargetDeviceID).ToList();

                List <AdaptSignal> sourceSignals = AdaptSignal.Get(DataSource, DataSourceModel.ID, ConnectionString, DataProviderString)
                                                   .Where(s => s.Device == d.ID).ToList();

                mapping.IsValid = sourceSignals.Count() >= targetSignals.Count();

                for (int i = 0; i < targetSignals.Count(); i++)
                {
                    int index = sourceSignals.FindIndex(item => item.Phase == targetSignals[i].Phase && item.Type == targetSignals[i].MeasurmentType);
                    if (index == -1)
                    {
                        mapping.ChannelMappings.Add(targetSignals[i].ID, "");
                    }
                    else
                    {
                        mapping.ChannelMappings.Add(targetSignals[i].ID, sourceSignals[index].ID);
                    }
                }
                mapping.IsValid    = !mapping.ChannelMappings.Any(item => string.IsNullOrEmpty(item.Value));
                mapping.IsSelected = true;
                DeviceMappings     = new ObservableCollection <Mapping>(DeviceMappings);
                OnPropertyChanged(nameof(DeviceMappings));
                OnPropertyChanged(nameof(Valid));
            }, (d, s) => d.Name.ToLower().Contains(s.ToLower()), (d) => d.Name, AdaptDevice.Get(DataSource, DataSourceModel.ID, ConnectionString, DataProviderString));

            deviceSelection.DataContext = deviceSelectionVM;
            deviceSelection.Show();
        }