Example #1
0
        protected void SetSubItems(ListItem item, bool forceUpdate)
        {
            if (item == null)
            {
                return;
            }

            HomeMenuGroup group      = item.AdditionalProperties[KEY_ITEM_GROUP] as HomeMenuGroup;
            bool          fireChange = false;
            var           actions    = _homeProxy.GetGroupActions(group);

            if (forceUpdate || SubItemsNeedUpdate(_subItems, actions))
            {
                _subItemNavigationList.Clear();
                _subItems.Clear();

                List <SubItem> subItems = CreateSubItems(actions);
                CollectionUtils.AddAll(_subItemNavigationList, subItems);
                CollectionUtils.AddAll(_subItems, subItems);
                fireChange = true;
            }
            FocusCurrentSubItem(item);
            if (fireChange)
            {
                _subItems.FireChange();
            }
        }
        public override void AddPotentialFocusableElements(RectangleF?startingRect, ICollection <FrameworkElement> elements)
        {
            ICollection <FrameworkElement> potentialElements = new List <FrameworkElement>();

            base.AddPotentialFocusableElements(startingRect, potentialElements);

            object restoreFocusItem = RestoreFocusItem;

            // Try and find the element that has the restoreFocusItem as Context
            if (restoreFocusItem != null && _itemsHostPanel != null)
            {
                foreach (FrameworkElement potentialElement in potentialElements)
                {
                    Visual element = potentialElement;
                    while (element != null && element.VisualParent != _itemsHostPanel)
                    {
                        element = element.VisualParent;
                    }
                    if (element?.Context == restoreFocusItem)
                    {
                        // Just add this element to ensure that
                        // it gets the focus
                        elements.Add(potentialElement);
                        return;
                    }
                }
            }

            // No matching element found, use the default focus selection
            CollectionUtils.AddAll(elements, potentialElements);
        }
        private void LoadPlugins(string playerPluginsDirectory)
        {
            Log.Info("Loading player add-ins from '{0}'", playerPluginsDirectory);

            if (!Directory.Exists(playerPluginsDirectory))
            {
                Log.Error("Unable to find player add-ins folder '{0}'", playerPluginsDirectory);
                return;
            }

            IDictionary <int, string> plugins = Bass.BASS_PluginLoadDirectory(playerPluginsDirectory);

            foreach (string pluginFile in plugins.Values)
            {
                Log.Debug("Loaded plugin '{0}'", pluginFile);
            }
            CollectionUtils.AddAll(_decoderPluginHandles, plugins.Keys);

            if (plugins.Count == 0)
            {
                Log.Info("No audio decoders loaded; probably already loaded.");
            }
            else
            {
                Log.Info("Loaded {0} audio decoders.", plugins.Count);
            }
        }
Example #4
0
        /// <summary>
        /// Allows a secondary filter of the already loaded <see cref="Items"/> by the given <paramref name="search"/> term.
        /// </summary>
        /// <param name="search">Search term (or key)</param>
        public virtual void ApplySecondaryFilter(string search)
        {
            IItemsFilter filter = _filter;

            if (filter == null)
            {
                return;
            }

            // Init backup list
            if (_originalList == null)
            {
                _originalList = new ItemsList();
                CollectionUtils.AddAll(_originalList, _items);
            }
            filter.Filter(_items, _originalList, search);

            IsFiltered = filter.IsFiltered;
            if (IsFiltered)
            {
                // Filter defined by class
                NumItemsStr = filter.Text;
            }
            else
            {
                // Restore default text
                NumItemsStr = Utils.BuildNumItemsStr(NumItems, TotalNumItems);
            }
        }
Example #5
0
        public ICollection <DvStateVariable> GetDueEvents()
        {
            DateTime now = DateTime.Now;
            ICollection <DvStateVariable> result = null;
            // Continue stepping through the (sorted) list of pending event notifications and collect all
            // variables to event until we find an entry which is scheduled in the future
            KeyValuePair <DateTime, HashSet <DvStateVariable> >?kvp;

            while ((kvp = GetFirstScheduledEventNotification()).HasValue)
            {
                if (kvp.Value.Key <= now)
                {
                    if (result == null)
                    {
                        result = new HashSet <DvStateVariable>();
                    }
                    CollectionUtils.AddAll(result, kvp.Value.Value);
                    _scheduledEventNotifications.RemoveAt(0);
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
Example #6
0
        protected ICollection <ListItem> CollectSkinResourcesColors(SkinResources resourceBundle)
        {
            ICollection <ListItem> result = new List <ListItem>();

            foreach (KeyValuePair <object, object> localStyleResource in resourceBundle.LocalStyleResources)
            {
                object key   = localStyleResource.Key;
                object value = localStyleResource.Value;
                object c;
                object testString;
                int    testInt;
                if (TypeConverter.Convert(value, typeof(Color), out c))
                {
                    // Avoid conversion of strings containing int values
                    if (!TypeConverter.Convert(value, typeof(string), out testString) || !int.TryParse((string)testString, out testInt))
                    {
                        Color color = (Color)c;
                        result.Add(BuildColorListItem(key.ToString(), color));
                    }
                }
            }
            SkinResources inherited = resourceBundle.InheritedSkinResources;

            if (inherited != null)
            {
                CollectionUtils.AddAll(result, CollectSkinResourcesColors(inherited));
            }
            return(result);
        }
        public void SaveSharesToSettings()
        {
            SharesSettings settings = new SharesSettings();

            CollectionUtils.AddAll(settings.LocalShares, _shares.Values);
            ServiceRegistration.Get <ISettingsManager>().Save(settings);
        }
        protected ICollection <IFileSystemResourceAccessor> WrapLocalFsResourceAccessors(ICollection <IFileSystemResourceAccessor> localFsResourceAccessors)
        {
            ICollection <IFileSystemResourceAccessor> result = new List <IFileSystemResourceAccessor>();

            CollectionUtils.AddAll(result, localFsResourceAccessors.Select(resourceAccessor => new NetworkNeighborhoodResourceAccessor(_parent, resourceAccessor.Path.Substring(1))));
            return(result);
        }
Example #9
0
        private static void SetMultiEpisodeDetailsl(SeriesInfo seriesInfo, List <TvdbEpisode> episodes)
        {
            seriesInfo.TotalRating = episodes.Sum(e => e.Rating) / episodes.Count; // Average rating
            seriesInfo.Episode     = string.Join("; ", episodes.OrderBy(e => e.EpisodeNumber).Select(e => e.EpisodeName).ToArray());
            seriesInfo.Summary     = string.Join("\r\n\r\n", episodes.OrderBy(e => e.EpisodeNumber).
                                                 Select(e => string.Format("{0,02}) {1}", e.EpisodeNumber, e.Overview)).ToArray());

            // Don't clear seriesInfo.Actors again. It's already been filled with actors from series details.
            var guestStars = episodes.SelectMany(e => e.GuestStars).Distinct().ToList();

            if (guestStars.Count > 0)
            {
                CollectionUtils.AddAll(seriesInfo.Actors, guestStars);
            }
            seriesInfo.Directors.Clear();
            var directors = episodes.SelectMany(e => e.Directors).Distinct().ToList();

            if (directors.Count > 0)
            {
                CollectionUtils.AddAll(seriesInfo.Directors, directors);
            }
            var writers = episodes.SelectMany(e => e.Writer).Distinct().ToList();

            seriesInfo.Writers.Clear();
            if (writers.Count > 0)
            {
                CollectionUtils.AddAll(seriesInfo.Writers, writers);
            }
        }
Example #10
0
        /// <summary>
        /// Tries to lookup the series from TheTvDB and updates the given <paramref name="seriesInfo"/> with the online information (Series and Episode names).
        /// </summary>
        /// <param name="seriesInfo">Series to check</param>
        /// <returns><c>true</c> if successful</returns>
        public bool FindAndUpdateSeries(SeriesInfo seriesInfo)
        {
            TvdbSeries seriesDetail;

            if (TryMatch(seriesInfo, false, out seriesDetail))
            {
                int tvDbId = 0;
                if (seriesDetail != null)
                {
                    tvDbId            = seriesDetail.Id;
                    seriesInfo.Series = seriesDetail.SeriesName;
                    seriesInfo.Actors.Clear();
                    if (seriesDetail.Actors.Count > 0)
                    {
                        CollectionUtils.AddAll(seriesInfo.Actors, seriesDetail.Actors);
                    }
                    seriesInfo.Genres.Clear();
                    if (seriesDetail.Genre.Count > 0)
                    {
                        CollectionUtils.AddAll(seriesInfo.Genres, seriesDetail.Genre);
                    }

                    // Also try to fill episode title from series details (most file names don't contain episode name).
                    TryMatchEpisode(seriesInfo, seriesDetail);
                }

                if (tvDbId > 0)
                {
                    ScheduleDownload(tvDbId);
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Filter remaining keys using an IDictionary of available indexes.
        /// </summary>
        /// <remarks>
        /// The filter is responsible for removing all keys from the passed
        /// set of keys that the applicable indexes can prove should be
        /// filtered. If the filter does not fully evaluate the remaining
        /// keys using just the index information, it must return a filter
        /// (which may be an <see cref="IEntryFilter"/>) that can complete the
        /// task using an iterating implementation. If, on the other hand, the
        /// filter does fully evaluate the remaining keys using just the index
        /// information, then it should return <c>null</c> to indicate that no
        /// further filtering is necessary.
        /// </remarks>
        /// <param name="indexes">
        /// The available <see cref="ICacheIndex"/> objects keyed by the
        /// related IValueExtractor; read-only.
        /// </param>
        /// <param name="keys">
        /// The mutable set of keys that remain to be filtered.
        /// </param>
        /// <returns>
        /// An <see cref="IFilter"/> object that can be used to process the
        /// remaining keys, or <c>null</c> if no additional filter processing
        /// is necessary.
        /// </returns>
        public IFilter ApplyIndex(IDictionary indexes, ICollection keys)
        {
            var index = (ICacheIndex)indexes[ValueExtractor];

            if (index == null)
            {
                // there is no relevant index
                return(this);
            }

            var values = (ICollection)Value;
            var setIn  = new HashSet();

            foreach (object oValue in values)
            {
                var colEQ = (ICollection)index.IndexContents[oValue];
                if (colEQ != null)
                {
                    CollectionUtils.AddAll(setIn, colEQ);
                }
            }

            if (setIn.Count == 0)
            {
                CollectionUtils.Clear(keys);
            }
            else
            {
                CollectionUtils.RetainAll(keys, setIn);
            }
            return(null);
        }
Example #12
0
        public override async Task <bool> UpdateItemsAsync(int maxItems, UpdateReason updateReason)
        {
            if (!TryInitTvHandler())
            {
                return(false);
            }
            var tvHandlerScheduleControl = _tvHandler.ScheduleControl;

            if (tvHandlerScheduleControl == null)
            {
                return(false);
            }

            if (!updateReason.HasFlag(UpdateReason.Forced) && !updateReason.HasFlag(UpdateReason.PeriodicMinute))
            {
                return(true);
            }

            var scheduleResult = await tvHandlerScheduleControl.GetSchedulesAsync();

            if (!scheduleResult.Success)
            {
                return(false);
            }

            var schedules        = scheduleResult.Result;
            var scheduleSortList = new List <Tuple <ISchedule, ProgramProperties> >();

            foreach (ISchedule schedule in schedules)
            {
                var programResult = await tvHandlerScheduleControl.GetProgramsForScheduleAsync(schedule);

                if (!programResult.Success || programResult.Result.Count == 0)
                {
                    continue;
                }
                ProgramProperties programProperties = new ProgramProperties();
                programProperties.SetProgram(programResult.Result.OrderBy(p => p.StartTime).First());
                scheduleSortList.Add(new Tuple <ISchedule, ProgramProperties>(schedule, programProperties));
            }
            scheduleSortList.Sort(ChannelAndProgramStartTimeComparison);

            var scheduleList = new List <Tuple <ISchedule, ProgramProperties> >(scheduleSortList.Take(maxItems));

            if (_currentSchedules.Select(s => s.Item1.ScheduleId).SequenceEqual(scheduleList.Select(s => s.Item1.ScheduleId)))
            {
                return(true);
            }

            ListItem[] items = scheduleList.Select(s => CreateScheduleItem(s.Item1, s.Item2)).ToArray();
            lock (_allItems.SyncRoot)
            {
                _currentSchedules = scheduleList;
                _allItems.Clear();
                CollectionUtils.AddAll(_allItems, items);
            }
            _allItems.FireChange();
            return(true);
        }
            /// <summary>
            /// Add the specified collection of keys to the Bundle.
            /// </summary>
            /// <note>
            /// A call to this method must be externally synchronized for
            /// this Bundle object.
            /// </note>
            /// <param name="colKeys">
            /// The collection of keys to add to this Bundle.
            /// </param>
            /// <returns>
            /// True if this Bundle was empty prior to this call.
            /// </returns>
            public bool AddAll(ICollection colKeys)
            {
                ICollection setKeys = m_setKeys;
                bool        isFirst = setKeys.Count == 0;

                CollectionUtils.AddAll(setKeys, colKeys);
                return(isFirst);
            }
Example #14
0
            /// <summary>
            /// Add the specified collection of entries to the Bundle.
            /// </summary>
            /// <note>
            /// A call to this method must be externally synchronized
            /// for this Bundle object.
            /// </note>
            /// <param name="dictionary">
            /// The collection of entries.
            /// </param>
            /// <returns>
            /// True if this Bundle was empty prior to this call.
            /// </returns>
            public bool AddAll(IDictionary dictionary)
            {
                IDictionary mapEntries = m_mapEntries;
                bool        isFirst    = mapEntries.Count == 0;

                CollectionUtils.AddAll(mapEntries, dictionary);
                return(isFirst);
            }
        public void TestAddAllByNullElements()
        {
            var collection = new List <string> {
                "Satish", "Kumar"
            };

            Assert.Throws <NullReferenceException>(() => CollectionUtils.AddAll(collection, null));
        }
Example #16
0
        public void ExportPlaylistContents(PlaylistContents data)
        {
            IList <MediaItem> items = data.ItemList;

            items.Clear();
            lock (_syncObj)
                CollectionUtils.AddAll(items, _itemList);
        }
Example #17
0
        public void ExportPlaylistRawData(PlaylistRawData data)
        {
            IList <Guid> idList = data.MediaItemIds;

            idList.Clear();
            lock (_syncObj)
                CollectionUtils.AddAll(idList, _itemList.Select(item => item.MediaItemId));
        }
 protected void LoadPendingImportJobs()
 {
     lock (_syncObj)
     {
         _importJobs.Clear();
         CollectionUtils.AddAll(_importJobs, _settings.Settings.PendingImportJobs);
         _importJobsReadyAvailableEvent.Set();
     }
 }
        private void InitPluginAssemblyList()
        {
            IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();

            foreach (PluginRuntime plugin in pluginManager.AvailablePlugins.Values)
            {
                CollectionUtils.AddAll(_knownAssemblies, plugin.Metadata.AssemblyFilePaths);
            }
        }
        protected void CyclePositionedItems()
        {
            var tmpItems = _nextPageItems.ToList();

            _positionedItems.Clear();
            CollectionUtils.AddAll(_positionedItems, tmpItems);
            SetFocusOnNewPage();
            _positionedItems.FireChange();
        }
Example #21
0
 protected void UpdateMediaCategories(ICollection <string> selectedCategories)
 {
     _mediaCategories.Clear();
     if (selectedCategories != null)
     {
         CollectionUtils.AddAll(_mediaCategories, selectedCategories);
     }
     IsMediaCategoriesSelected = _mediaCategories.Count > 0;
 }
Example #22
0
        /// <summary>
        /// Builds a subquery that returns the ids of the media items returned by the <paramref name="filter"/>.
        /// </summary>
        /// <param name="filter">Relationship filter instance to create the sub query for.</param>
        /// <param name="subqueryFilter">Additional filter to apply to all subqueries.</param>
        /// <param name="miaManagement">MIA_Management instance to generate attribute column names.</param>
        /// <param name="bvNamespace">Namespace used to build bind var names.</param>
        /// <param name="resultParts">Statement parts for the filter.</param>
        /// <param name="resultBindVars">Bind variables for the filter.</param>
        public static void BuildRelationshipSubquery(AbstractRelationshipFilter filter, IFilter subqueryFilter, MIA_Management miaManagement,
                                                     BindVarNamespace bvNamespace, IList <object> resultParts, IList <BindVar> resultBindVars)
        {
            //Simple relationship filter with linked id
            BindVar            linkedIdVar        = null;
            RelationshipFilter relationshipFilter = filter as RelationshipFilter;

            if (relationshipFilter != null && relationshipFilter.LinkedMediaItemId != Guid.Empty)
            {
                linkedIdVar = new BindVar(bvNamespace.CreateNewBindVarName("V"), relationshipFilter.LinkedMediaItemId, typeof(Guid));
                resultBindVars.Add(linkedIdVar);
            }

            //Role
            BindVar roleVar = null;

            if (filter.Role != Guid.Empty)
            {
                roleVar = new BindVar(bvNamespace.CreateNewBindVarName("V"), filter.Role, typeof(Guid));
                resultBindVars.Add(roleVar);
            }

            //Linked role
            BindVar linkedRoleVar = null;

            if (filter.LinkedRole != Guid.Empty)
            {
                linkedRoleVar = new BindVar(bvNamespace.CreateNewBindVarName("V"), filter.LinkedRole, typeof(Guid));
                resultBindVars.Add(linkedRoleVar);
            }

            //Complex relationship filter with linked filter
            string                     sqlStatement = null;
            IList <BindVar>            bindVars     = null;
            FilteredRelationshipFilter filteredRelationshipFilter = filter as FilteredRelationshipFilter;

            if (filteredRelationshipFilter != null && filteredRelationshipFilter.Filter != null)
            {
                //Build a sub query for the linked filter
                string idAlias = null;
                ICollection <QueryAttribute> requiredAttributes = new List <QueryAttribute>();
                SubQueryBuilder filterBuilder = new SubQueryBuilder(miaManagement, requiredAttributes,
                                                                    new List <MediaItemAspectMetadata>(), filteredRelationshipFilter.Filter, subqueryFilter, bvNamespace.BindVarCounter);
                filterBuilder.GenerateSqlStatement(out idAlias, out sqlStatement, out bindVars);
                sqlStatement = " SELECT TS." + idAlias + " FROM (" + sqlStatement + ") TS";

                bvNamespace.BindVarCounter += bindVars.Count;
                CollectionUtils.AddAll(resultBindVars, bindVars);
            }

            //Relationships are only stored for one party in the relationship so we need to union the query with a query
            //that reverses the relationship to ensure that all relationships are selected
            BuildRelationshipSubqueryPart(roleVar, linkedRoleVar, linkedIdVar, sqlStatement, false, miaManagement, resultParts);
            resultParts.Add(" UNION ");
            BuildRelationshipSubqueryPart(roleVar, linkedRoleVar, linkedIdVar, sqlStatement, true, miaManagement, resultParts);
        }
        public void TestAddAllByInt()
        {
            var collection = new List <int> {
                1, 2
            };
            var elements = new[] { 3, 4 };

            Assert.True(CollectionUtils.AddAll(collection, elements));
            Assert.True(collection.Contains(3));
        }
        public void TestAddAll()
        {
            var collection = new List <string> {
                "Satish", "Kumar"
            };
            var elements = new[] { "Roronoa", "Zoro" };

            Assert.True(CollectionUtils.AddAll(collection, elements));
            Assert.True(collection.Contains("Roronoa"));
        }
        protected ICollection <Guid> GetMetadataExtractorIdsForMediaCategories(IEnumerable <string> mediaCategories)
        {
            IMediaAccessor     mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
            ICollection <Guid> result        = new HashSet <Guid>();

            foreach (string mediaCategory in mediaCategories)
            {
                CollectionUtils.AddAll(result, mediaAccessor.GetMetadataExtractorsForCategory(mediaCategory));
            }
            return(result);
        }
Example #26
0
        protected ICollection <IFileSystemResourceAccessor> WrapLocalFsResourceAccessors(ICollection <IFileSystemResourceAccessor> localFsResourceAccessors)
        {
            ICollection <IFileSystemResourceAccessor> result = new List <IFileSystemResourceAccessor>();

            if (localFsResourceAccessors != null && localFsResourceAccessors.Count > 0)
            {
                CollectionUtils.AddAll(result, localFsResourceAccessors.Where(resourceAccessor => resourceAccessor != null && resourceAccessor.Path != null).
                                       Select(resourceAccessor => new NetworkNeighborhoodResourceAccessor(_parent, resourceAccessor.Path.Substring(1))));
            }
            return(result);
        }
Example #27
0
        protected void InitFilter()
        {
            _actionIds.Clear();
            var filter = Filter;

            if (string.IsNullOrEmpty(filter))
            {
                return;
            }
            CollectionUtils.AddAll(_actionIds, filter.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => new Guid(s)));
        }
Example #28
0
 protected void LoadPendingImportJobs()
 {
     lock (_syncObj)
     {
         ISettingsManager       settingsManager = ServiceRegistration.Get <ISettingsManager>();
         ImporterWorkerSettings settings        = settingsManager.Load <ImporterWorkerSettings>();
         _importJobs.Clear();
         CollectionUtils.AddAll(_importJobs, settings.PendingImportJobs);
         _importJobsReadyAvailableEvent.Set();
     }
 }
Example #29
0
        protected static ICollection <string> UnrollPathSegments(ResourcePath rp)
        {
            ICollection <string> result = new List <string>();

            foreach (ProviderPathSegment segment in rp._pathSegments)
            {
                result.Add(segment.ProviderId.ToString());
                CollectionUtils.AddAll(result, segment.Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
            }
            return(result);
        }
Example #30
0
 protected bool InitializePropertiesWithShare(Share share, string nativeSystem)
 {
     _origShare           = share;
     BaseResourceProvider = GetBaseResourceProviderMetadata(share.BaseResourcePath);
     NativeSystem         = nativeSystem;
     ChoosenResourcePath  = share.BaseResourcePath;
     ShareName            = share.Name;
     MediaCategories.Clear();
     CollectionUtils.AddAll(MediaCategories, share.MediaCategories);
     return(true);
 }