Example #1
0
            /// <summary>
            /// Beginnt mit dem Laden von Quellinformationen.
            /// </summary>
            /// <param name="source">Die gewünschte Quelle.</param>
            /// <returns>Die Hintergrundaufgabe zum Laden der Quellinformationen.</returns>
            CancellableTask <SourceInformation> IDevice.GetSourceInformationAsync(SourceSelection source)
            {
                Assert.IsNotNull(m_currentSourceGroup, "not allocated");

                // Make it async
                return(CancellableTask <SourceInformation> .Run(cancel => m_currentSourceGroup.Contains( source )?new SourceInformation { Source = source.Source } : null));
            }
Example #2
0
            /// <summary>
            /// Aktiviert den Empfang einer Quellgruppe.
            /// </summary>
            /// <param name="source">Eine Quelle der Gruppe.</param>
            /// <returns>Die Hintergrundaufgabe zur Aktivierung.</returns>
            CancellableTask <SourceSelection[]> IDevice.Activate(SourceSelection source)
            {
                // Find the source map
                var group = m_provider.AllAvailableSources.SingleOrDefault(g => g.Contains(source));

                Assert.IsNotNull(group, "no such source");

                m_currentSourceGroup = new HashSet <SourceSelection>();

                // Report
                return(CancellableTask <SourceSelection[]> .Run(cancel => (m_currentSourceGroup = group).ToArray()));
            }
            /// <summary>
            /// Wählt eine Quellgruppe an.
            /// </summary>
            /// <param name="source">Eine der Quellen der Gruppe.</param>
            /// <returns>Die Liste aller Quellen der Gruppe.</returns>
            public CancellableTask <SourceSelection[]> Activate(SourceSelection source)
            {
                // Map to indicated device
                var localSource = m_profile.FindSource(source.Source).FirstOrDefault();

                if (localSource == null)
                {
                    throw new ArgumentException("bad source", "source");
                }

                // Create task
                return
                    (CancellableTask <SourceSelection[]> .Run(cancel =>
                {
                    // Check for cancel
                    if (cancel.IsCancellationRequested)
                    {
                        return _NoSources;
                    }

                    // Start the hardware on first call - this may take some time
                    var device = localSource.GetHardware();

                    // Check for cancel
                    if (cancel.IsCancellationRequested)
                    {
                        return _NoSources;
                    }

                    // Select the group - again this may last a bit
                    localSource.SelectGroup(device);

                    // Check for cancel
                    if (cancel.IsCancellationRequested)
                    {
                        return _NoSources;
                    }

                    // Validate
                    var groupReader = device.GroupReader;
                    if (groupReader == null)
                    {
                        return _NoSources;
                    }
                    if (!groupReader.CancellableWait(cancel))
                    {
                        return _NoSources;
                    }

                    // Load the map
                    var groupInformation = groupReader.Result;
                    if (groupInformation == null)
                    {
                        return _NoSources;
                    }

                    // Use profile to map to full source information
                    return
                    groupInformation
                    .Sources
                    .Select(s => m_profile.FindSource(s).FirstOrDefault())
                    .Where(s => s != null)
                    .ToArray();
                }));
            }