Example #1
0
        /// <summary>
        /// Erzeugt eine neue Verwaltungsinstanz.
        /// </summary>
        /// <param name="location">Die zu verwaltende Liste.</param>
        public LocationItem( ScanLocation location )
        {
            // Remember
            Location = location;

            // Check names
            if (Equals( location.DisplayName, location.UniqueName ))
                Text = location.DisplayName;
            else
                Text = string.Format( "{0} ({1})", location.DisplayName, location.UniqueName );

            // See if this is optimized
            if (!location.AutoConvert)
                BackColor = Color.LightGreen;
        }
 /// <summary>
 /// Show a folder browser dialog to allow the user to select a location, and add it to Locations. Any exceptions would be fatal.
 /// </summary>
 private void AddLocation()
 {
     using (CommonDialog dialog = _folderBrowserDialog.GetNewFolderBrowserDialog())
     {
         DialogResult result = _folderBrowserDialog.ShowDialogWrapper(dialog);
         if (result == DialogResult.OK)
         {
             string       resultString       = _folderBrowserDialog.GetSelectedPathFromDialog(dialog);
             ScanLocation resultScanLocation = new ScanLocation(resultString);
             if (!Locations.Contains(resultScanLocation))
             {
                 Locations.Add(resultScanLocation);
             }
         }
     }
     ToggleButtons();
 }
        public void Remove_NoLocationSelected_DoesNothing()
        {
            // ARRANGE
            ScanLocation      location  = new ScanLocation("C:\\foobar");
            HomePageViewModel viewModel = new HomePageViewModel(
                GetMockFolderBrowserDialogWrapper(string.Empty).Object,
                GetMockScannedFileStore().Object,
                "C:\\user");

            viewModel.Locations.Add(location);

            // ACT
            viewModel.SelectedLocation = null;
            viewModel.Remove.Execute(null);

            // ASSERT
            Assert.AreEqual(1, viewModel.Locations.Count, "Item was removed from the Model.");
        }
        public void Remove_RemovesLocationFromPageAndModel()
        {
            // ARRANGE
            ScanLocation      location  = new ScanLocation("C:\\foobar");
            HomePageViewModel viewModel = new HomePageViewModel(
                GetMockFolderBrowserDialogWrapper(string.Empty).Object,
                GetMockScannedFileStore().Object,
                "C:\\user");

            viewModel.Locations.Add(location);

            // ACT
            viewModel.SelectedLocation = location;
            viewModel.Remove.Execute(null);

            // ASSERT
            Assert.AreEqual(0, viewModel.Locations.Count, "Location was still in the Model.");
        }
        public void Remove_TogglesButtonsWhenLocationRemoved()
        {
            // ARRANGE
            ScanLocation      location  = new ScanLocation("C:\\foobar");
            HomePageViewModel viewModel = new HomePageViewModel(
                GetMockFolderBrowserDialogWrapper(string.Empty).Object,
                GetMockScannedFileStore().Object,
                "C:\\user");

            viewModel.Locations.Add(location);

            // ACT
            viewModel.SelectedLocation = location;
            viewModel.Remove.Execute(null);

            // ASSERT
            Assert.IsFalse(viewModel.Remove.CanExecute(null), "The RemoveButton is enabled.");
            Assert.IsFalse(viewModel.Scan.CanExecute(null), "The ScanButton is enabled.");
        }
        /// <summary>
        /// Erzeugt eine neue Verwaltungsinstanz.
        /// </summary>
        /// <param name="location">Die zu verwaltende Liste.</param>
        public LocationItem(ScanLocation location)
        {
            // Remember
            Location = location;

            // Check names
            if (Equals(location.DisplayName, location.UniqueName))
            {
                Text = location.DisplayName;
            }
            else
            {
                Text = string.Format("{0} ({1})", location.DisplayName, location.UniqueName);
            }

            // See if this is optimized
            if (!location.AutoConvert)
            {
                BackColor = Color.LightGreen;
            }
        }
Example #7
0
        public ImportViewModel(MediaFileWatcher mediaFileWatcher)
        {
            Title = "Import Media";
            
            OkCommand = new Command(async () =>
            {
                CancellableOperationProgressView progress = new CancellableOperationProgressView();
                ImportProgressViewModel vm = new ImportProgressViewModel(mediaFileWatcher.MediaFileState);
                progress.DataContext = vm;
                progress.Show();
                Task t = vm.importAsync(IncludeLocations, ExcludeLocations);
                OnClosingRequest();
                await t;
            });
          
            CancelCommand = new Command(() =>
                {
                    OnClosingRequest();
                });
          
            IncludeLocations = new ObservableCollection<ScanLocation>();

            IncludeLocations.Add(new ScanLocation(mediaFileWatcher.Path));

            AddIncludeLocationCommand = new Command(new Action(() =>
            {
                DirectoryPickerView directoryPicker = new DirectoryPickerView();
                DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext;

                if (SelectedIncludeLocation == null)
                {
                    vm.SelectedPath = mediaFileWatcher.Path;
                }
                else
                {
                    vm.SelectedPath = SelectedIncludeLocation.Location;
                }

                if (directoryPicker.ShowDialog() == true)
                {
                    ScanLocation newLocation = new ScanLocation(vm.SelectedPath);
                    if (!IncludeLocations.Contains(newLocation))
                    {
                        IncludeLocations.Add(newLocation);
                    }
                }

                if (IncludeLocations.Count > 0)
                {
                    OkCommand.IsExecutable = true;
                }
               
            }));

            RemoveIncludeLocationCommand = new Command(new Action(() =>
                {
                    for (int i = IncludeLocations.Count() - 1; i >= 0; i--)
                    {
                        if (IncludeLocations[i].IsSelected == true)
                        {
                            IncludeLocations.RemoveAt(i);
                        }
                    }

                    if (IncludeLocations.Count == 0)
                    {
                        OkCommand.IsExecutable = false;
                    }
                }));

            ClearIncludeLocationsCommand = new Command(new Action(() =>
            {
                IncludeLocations.Clear();
                OkCommand.IsExecutable = false;
            }));

            ExcludeLocations = new ObservableCollection<ScanLocation>();
       
            AddExcludeLocationCommand = new Command(new Action(() =>
            {
                DirectoryPickerView directoryPicker = new DirectoryPickerView();
                DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext;

                if (SelectedExcludeLocation == null)
                {
                    vm.SelectedPath = mediaFileWatcher.Path;
                }
                else
                {
                    vm.SelectedPath = SelectedExcludeLocation.Location;
                }

                if (directoryPicker.ShowDialog() == true)
                {
                    ScanLocation newLocation = new ScanLocation(vm.SelectedPath);
                    if (!ExcludeLocations.Contains(newLocation))
                    {
                        ExcludeLocations.Add(newLocation);
                    }
                }
          
            }));

            RemoveExcludeLocationCommand = new Command(new Action(() =>
            {
                for (int i = ExcludeLocations.Count() - 1; i >= 0; i--)
                {
                    if (ExcludeLocations[i].IsSelected == true)
                    {
                        ExcludeLocations.RemoveAt(i);
                    }
                }
             
            }));

            ClearExcludeLocationsCommand = new Command(new Action(() =>
            {
                ExcludeLocations.Clear();             
            }));
        }
        /// <summary>
        /// Analysiert die aktuelle Konfiguration des Suchlaufs auf Basis
        /// der DVB <i>Network Information Table (NIT)</i> Informationen.
        /// </summary>
        private void AnalyserThread()
        {
            // Be safe
            try
            {
                // Configure language
                UserProfile.ApplyLanguage();

                // Uses hardware manager
                using (HardwareManager.Open())
                {
                    // Attach to the hardware itself
                    Hardware device = HardwareManager.OpenHardware(Profile);

                    // Reset counters
                    TotalLocations  = m_Locations.Count;
                    CurrentLocation = 0;

                    // Last inversion used
                    SpectrumInversions lastInversion = SpectrumInversions.On;

                    // Process all transponders
                    foreach (GroupLocation location in m_Locations)
                    {
                        // Update counter
                        ++CurrentLocation;

                        // Reset
                        CurrentLocationGroupsPending = 0;
                        CurrentLocationGroup         = 0;

                        // Check caller
                        if (!LocationStart(location))
                        {
                            return;
                        }

                        // Groups found on this location
                        Dictionary <SourceGroup, bool> found = new Dictionary <SourceGroup, bool>();

                        // Groups with valid network information - only those are considered
                        List <SourceGroup> nitAvailable = new List <SourceGroup>();

                        // Load counter
                        CurrentLocationGroupsPending = location.Groups.Count;

                        // Process all groups
                        foreach (SourceGroup group in location.Groups)
                        {
                            // Get the expected type
                            Type groupType = group.GetType();

                            // Clone the group
                            SourceGroup newGroup = SourceGroup.FromString <SourceGroup>(group.ToString());

                            // Count up
                            --CurrentLocationGroupsPending;
                            ++CurrentLocationGroup;

                            // See if this is already processed
                            if (null != found.Keys.FirstOrDefault(p => p.CompareTo(newGroup, true)))
                            {
                                continue;
                            }

                            // Check for external termination
                            if (null == m_Worker)
                            {
                                return;
                            }

                            // Not supported
                            if (!Profile.SupportsGroup(newGroup) || !device.CanHandle(newGroup))
                            {
                                // Remember
                                m_UnhandledGroups.Add(newGroup);

                                // Next
                                continue;
                            }

                            // Check caller
                            if (!GroupStart(location, newGroup))
                            {
                                return;
                            }

                            // Attach to the group
                            if (null != SelectGroup(device, location, newGroup, ref lastInversion))
                            {
                                // See if we are a cable group
                                CableGroup cableGroup = newGroup as CableGroup;

                                // Attach to the NIT
                                var nit = device.GetLocationInformation(15000);
                                if (null != nit)
                                {
                                    // Remember
                                    nitAvailable.Add(newGroup);

                                    // Process
                                    foreach (SourceGroup other in nit.Groups)
                                    {
                                        if (other.GetType() == groupType)
                                        {
                                            // See if this is a cable group
                                            CableGroup otherCable = other as CableGroup;

                                            // Update inversion
                                            if (null != otherCable)
                                            {
                                                // Other must be cable, too
                                                if (null == cableGroup)
                                                {
                                                    continue;
                                                }

                                                // Use same parameters
                                                otherCable.SpectrumInversion = cableGroup.SpectrumInversion;
                                                otherCable.Bandwidth         = cableGroup.Bandwidth;
                                            }

                                            // Report
                                            if (ScannerTraceSwitch.Level >= TraceLevel.Info)
                                            {
                                                Trace.WriteLine(string.Format(Properties.Resources.Trace_Scanner_NIT, other), ScannerTraceSwitch.DisplayName);
                                            }

                                            // Mark it
                                            found[other] = true;
                                        }
                                    }
                                }
                            }

                            // Check caller
                            if (!GroupDone(location, newGroup))
                            {
                                return;
                            }
                        }

                        // Create a brand new scan location
                        ScanLocation scan = location.ToScanLocation();

                        // Try to update
                        foreach (SourceGroup group in nitAvailable)
                        {
                            // Try to find the full qualified name
                            SourceGroup nitGroup = found.Keys.FirstOrDefault(p => p.CompareTo(group, true));

                            // Update
                            if (null == nitGroup)
                            {
                                scan.Groups.Add(group);
                            }
                            else
                            {
                                scan.Groups.Add(nitGroup);
                            }
                        }

                        // Just remember
                        m_AnalyseResult[location] = scan;

                        // Check caller
                        if (!LocationDone(location))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Remember
                m_ThreadException = e;
            }
        }