/// <summary>
 /// Assigns the level.
 /// </summary>
 /// <param name="list">The list.</param>
 /// <param name="dictionary">The dictionary.</param>
 public static void AssignLevel(this IList<DeveloperListItem> list, Dictionary<int, DeveloperListItem> dictionary)
 {
     if (list != null)
     {
         list.AsParallel().Select(item => AssignDeveloperValues(item, dictionary)).ToList();
     }
 }
 public static bool RetriveRedirectCondition(this ICollection<RedirectConditionDetail> redirectConditionDetails, RedirectDimension redirectDemension, string requestConditionDefinitionCode)
 {
     var requestCondition = FindRedirectConditionDefinition(redirectDemension.RedirectConditionDefinitions, requestConditionDefinitionCode);
     if (requestCondition == null)
     {
         return false;
     }
     return redirectConditionDetails.AsParallel().Any(o => o.RedirectConditionDefinitionId == requestCondition.RedirectConditionDefinitionId || FindRedirectConditionDefinition(FindRedirectConditionDefinition(redirectDemension.RedirectConditionDefinitions, o.RedirectConditionDefinitionId.Value).ChildRedirectConditionDefinitions, requestCondition.RedirectConditionDefinitionId) != null);
 }
        public static HashSet<Type> GetTuples(this IEnumerable<Type> types)
        {
            if (types == null)
            {
                return new HashSet<Type>();
            }

            var enumTypes =
                from type in types.AsParallel()
                where type.IsTuple()
                select type;

            return new HashSet<Type>(enumTypes);
        }
        public static HashSet<Type> GetPublicEnums(this ICollection<Type> types)
        {
            if (types.IsEmpty())
            {
                return new HashSet<Type>();
            }

            var enumTypes = 
                (from type in types.AsParallel()
                 where
                     type != null
                     && type.IsEnum
                     && type.IsPublic
                 select type
                ).ToList();

            return new HashSet<Type>(enumTypes);
        }
        /// <summary>
        /// Deletes the files.
        /// </summary>
        /// <param name="files">The files.</param>
        /// <returns>IEnumerable&lt;KeyValuePair&lt;System.String, System.String&gt;&gt;.</returns>
        public static IEnumerable<KeyValuePair<string, string>> DeleteFiles(this IEnumerable<string> files)
        {
            var errors = new SortedDictionary<string, string>();

            foreach (var information in files.AsParallel())
            {
                try
                {
                    File.Delete(information);
                }
                catch (IOException fileIOException)
                {
                    errors.AddIfNotExists(new KeyValuePair<string, string>(information, fileIOException.Message));
                }
                catch (UnauthorizedAccessException notAuthorizedException)
                {
                    errors.AddIfNotExists(new KeyValuePair<string, string>(information, notAuthorizedException.Message));
                }
            }
            return errors.AsEnumerable();
        }
Beispiel #6
0
        /// <summary>
        /// Filters the source by the specified search text.
        /// </summary>
        /// <param name="source">The songs to search.</param>
        /// <param name="searchText">The search text.</param>
        /// <returns>The filtered sequence of songs.</returns>
        public static IEnumerable<Song> FilterSongs(this IEnumerable<Song> source, string searchText)
        {
            if (searchText == null)
                throw new ArgumentNullException(Reflector.GetMemberName(() => searchText));

            if (String.IsNullOrWhiteSpace(searchText))
                return source;

            IEnumerable<string> keyWords = searchText.ToUpperInvariant().Split(' ');

            return source
                .AsParallel()
                .Where
                (
                    song => keyWords.All
                    (
                        keyword =>
                            song.Artist.ToUpperInvariant().Contains(keyword) ||
                            song.Album.ToUpperInvariant().Contains(keyword) ||
                            song.Genre.ToUpperInvariant().Contains(keyword) ||
                            song.Title.ToUpperInvariant().Contains(keyword)
                    )
                );
        }
Beispiel #7
0
        /// <summary>
        /// Filters the source by the specified search text.
        /// </summary>
        /// <param name="source">The songs to search.</param>
        /// <param name="searchText">The search text.</param>
        /// <returns>The filtered sequence of songs.</returns>
        public static IEnumerable<Song> FilterSongs(this IEnumerable<Song> source, string searchText)
        {
            if (searchText == null)
                Throw.ArgumentNullException(() => searchText);

            if (String.IsNullOrWhiteSpace(searchText))
                return source;

            IEnumerable<string> keyWords = searchText.Split(' ');

            return source
                .AsParallel()
                .Where
                (
                    song => keyWords.All
                    (
                        keyword =>
                            song.Artist.ContainsIgnoreCase(keyword) ||
                            song.Album.ContainsIgnoreCase(keyword) ||
                            song.Genre.ContainsIgnoreCase(keyword) ||
                            song.Title.ContainsIgnoreCase(keyword)
                    )
                );
        }
 public static IList<Domain.Entity.DemoValue> ToEntitySet(this IList<DataTransfer.DemoValue> values)
 {
     IList<Domain.Entity.DemoValue> set = values.AsParallel().Select(value => value.ToEntity()).ToList();
     return set;
 }
 public static IList<DataTransfer.DemoValue> ToDataTransferSet(this IList<Domain.Entity.DemoValue> entities, params PropertyDirective[] directives)
 {
     IList<DataTransfer.DemoValue> set = entities.AsParallel().Select(entity => entity.ToDataTransferValue(directives)).ToList();
     return set;
 }
Beispiel #10
0
 /// <summary>
 /// The only thing that could be better is to generally improve the 
 /// algorithm. Here we are just wasting threads. And the main thread (which is
 /// also part of the parallel execution) will block the event loop. Bad!
 /// </summary>
 public static int CountWordsInFilesParallel(this IEnumerable<string> input)
 {
     return input.AsParallel().Select(CountWords).Sum();
 }
Beispiel #11
0
 /// <summary>
 /// This works fine in parallel -- good speedup and great use-case.
 /// </summary>
 public static int CountPrimesParallel(this IEnumerable<int> input)
 {
     return input.AsParallel().Where(IsPrime).Count();
 }
 public static IList<Domain.Entity.OAuth2UserIdentity> ToEntitySet(this IList<DataTransfer.OAuth2UserIdentity> values)
 {
     IList<Domain.Entity.OAuth2UserIdentity> set = values.AsParallel().Select(value => value.ToEntity()).ToList();
     return set;
 }
Beispiel #13
0
 /// <summary>
 /// Computes stepwise (usually daily) returns relative to 0, where 0 implies no change in value.
 /// @return the array is revised in place
 /// </summary>
 public static IList<float> Returnize(this IList<float> prices)
 {
     Func<float, float, float> _returnize = (a,b) => (float) ((b/a)-1.0);
     IList<float> dailyReturns = prices.AsParallel().Select((x, index) => (index==0) ? 0 : _returnize(prices[index - 1], prices[index])).ToList();
     return dailyReturns;
 }
 public static bool RetriveRedirectCondition(this ICollection<RedirectConditionDetail> redirectConditionDetails, RedirectDimension redirectDemension, Guid requestConditionId)
 {
     return redirectConditionDetails.AsParallel().Any(o => o.RedirectConditionDefinitionId == requestConditionId || FindRedirectConditionDefinition(FindRedirectConditionDefinition(redirectDemension.RedirectConditionDefinitions, o.RedirectConditionDefinitionId.Value).ChildRedirectConditionDefinitions, requestConditionId) != null);
 }