Esempio n. 1
0
            public void Returns_the_bits_of_the_bytes()
            {
                byte b = 0b11001010;

                var bits = EnumerableHelpers.ToArray(
                    this.translator.GetBits(
                        new[]
                {
                    b
                }));

                Assert.True(
                    bits[0]);
                Assert.True(
                    bits[1]);
                Assert.False(
                    bits[2]);
                Assert.False(
                    bits[3]);
                Assert.True(
                    bits[4]);
                Assert.False(
                    bits[5]);
                Assert.True(
                    bits[6]);
                Assert.False(
                    bits[7]);
            }
            public TResult[] ToArray()
            {
                var builder = new SparseArrayBuilder <TResult>(initialize: true);
                ArrayBuilder <IEnumerable <TResult> > deferredCopies = default;

                foreach (TSource element in _source)
                {
                    IEnumerable <TResult> enumerable = _selector(element);

                    if (builder.ReserveOrAdd(enumerable))
                    {
                        deferredCopies.Add(enumerable);
                    }
                }

                TResult[] array = builder.ToArray();

                ArrayBuilder <Marker> markers = builder.Markers;

                for (int i = 0; i < markers.Count; i++)
                {
                    Marker marker = markers[i];
                    IEnumerable <TResult> enumerable = deferredCopies[i];
                    EnumerableHelpers.Copy(enumerable, array, marker.Index, marker.Count);
                }

                return(array);
            }
Esempio n. 3
0
        public virtual XTuple <string, string, string> Convert(
            LogEntry entry,
            string name)
        {
            if (entry == null)
            {
                return(XTuple.Create <string, string, string>(
                           null, null, null));
            }

            var    r      = this.runner;
            string format = null;

            r?.Run <SettingsHolder>(settings =>
            {
                format = settings.TimestampFormat;
            },
                                    name);

            return(XTuple.Create(
                       entry.Timestamp.ToString(
                           format,
                           CultureInfo.CurrentCulture),
                       entry.Type,
                       string.Join(
                           Environment.NewLine,
                           EnumerableHelpers.ToArray(
                               entry.Content))));
        }
Esempio n. 4
0
            public override TSource[] ToArray()
            {
                int count = GetCount(onlyIfCheap: true);

                if (count == -1)
                {
                    return(LazyToArray());
                }

                TSource[] array = new TSource[count];
                int       index;

                if (_appending)
                {
                    index = 0;
                }
                else
                {
                    array[0] = _item;
                    index    = 1;
                }

                EnumerableHelpers.Copy(_source, array, index, count - 1);

                if (_appending)
                {
                    array[array.Length - 1] = _item;
                }

                return(array);
            }
Esempio n. 5
0
 public virtual Lot <string> WebNames()
 {
     return(new LinkedListLot <string>(
                EH.Select(
                    this.webs,
                    webHolder => webHolder?.Name)));
 }
Esempio n. 6
0
 public IEnumerator <T> GetEnumerator()
 {
     return(this.collection?.GetEnumerator()
            ?? EnumerableHelpers
            .Empty <T>()
            .GetEnumerator());
 }
Esempio n. 7
0
        public virtual void ComputeRange(
            DateTime startDate,
            DateTime endDate)
        {
            var r = this.runner;

            r.Run <Log, Lotter>((l, lotter) =>
            {
                var matches = lotter.Materialize(
                    EnumerableHelpers.Where(
                        EnumerableHelpers.Where(
                            l.ReadEntries(),
                            e =>
                {
                    var ts = e.Timestamp;
                    return(ts >= startDate &&
                           ts < endDate.AddDays(1));
                }),
                        this.passesFilters));

                this.computeTotal(matches);
                this.computeAvgPerDay(
                    matches.Count,
                    startDate,
                    endDate);
                this.computeOldestTimestamp(matches);
                this.computeNewestTimestamp(matches);
                this.computeEarliestTimestamp(matches);
                this.computeLatestTimestamp(matches);
            },
                                this.LogDependencyName,
                                Framework.Log.DependencyNames.Lotter);
        }
Esempio n. 8
0
        public virtual T[] Sort <T>(
            IEnumerable <T> finiteSource)
            where T : IComparable
        {
            if (finiteSource == null)
            {
                return(new T[zero]);
            }

            if (finiteSource is T[] array)
            {
                this.Sort(
                    array,
                    zero,
                    array.Length - one);
                return(array);
            }

            var sourceArray = EnumerableHelpers.ToArray(
                finiteSource);

            this.Sort(
                sourceArray,
                zero,
                sourceArray.Length - one);

            return(sourceArray);
        }
        public EnumerableHelpersTests()
        {
            _array = new[]
            {
                new A
                {
                    X = 100,
                    B = new B
                    {
                        Num   = 1,
                        Field = "f"
                    }
                },
                new A
                {
                    X = 200,
                    B = null
                },
                null
            };

            _contextMock = new Mock <IHandlebars>();

            _sut = new EnumerableHelpers(_contextMock.Object);
        }
Esempio n. 10
0
 IEnumerator <T> IEnumerable <T> .GetEnumerator()
 {
     return(this.linkedList?.GetEnumerator()
            ?? EnumerableHelpers
            .Empty <T>()
            .GetEnumerator());
 }
        /// <summary>
        /// Uninstalls target-specific objects from current system.
        /// </summary>
        /// <param name="installationContext">The installation context.</param>
        /// <remarks>
        /// Uninstallation typically runs with administrative permissions.
        /// </remarks>
        public void Uninstall(InstallationContext installationContext)
        {
            if (installationContext == null)
            {
                throw new ArgumentNullException("installationContext");
            }

            this.InitializeAll();

            foreach (IInstallable installable in EnumerableHelpers.OfType <IInstallable>(this.configItems))
            {
                installationContext.Info("Uninstalling '{0}'", installable);

                try
                {
                    installable.Uninstall(installationContext);
                    installationContext.Info("Finished uninstalling '{0}'.", installable);
                }
                catch (Exception exception)
                {
                    if (exception.MustBeRethrown())
                    {
                        throw;
                    }

                    installationContext.Error("Uninstallation of '{0}' failed: {1}.", installable, exception);
                }
            }
        }
Esempio n. 12
0
        public void OutputIndex(IndexOutputRequest indexOutputRequest)
        {
            IndexParameter      indexParameter      = IndexParameterParser.ParseIndexParameter();
            DictionaryParameter dictionaryParameter = DictionaryParameterParser.ParseDictionaryParameter();

            if (indexParameter.IsPresent)
            {
                List <string> dictionaryWords = DictionaryFileLoader.ReadWords();

                int unknwonWordsCount = EnumerableHelpers.CountUnknownWords(
                    distinctWords: indexOutputRequest.DistinctWords,
                    dictionaryWords: dictionaryWords);

                if (dictionaryParameter.IsPresent)
                {
                    DisplayOutput.WriteResourceLine(
                        resourceIdent: "INDEX_WITH_UNKNOWN",
                        placeholderValues: unknwonWordsCount);
                }
                else
                {
                    DisplayOutput.WriteResourceLine(
                        resourceIdent: "INDEX");
                }

                DisplayWords(
                    distinctWords: indexOutputRequest.DistinctWords,
                    dictionaryWords: dictionaryWords);
            }
        }
Esempio n. 13
0
 Lot <T> Lotter.Materialize <T>(
     IEnumerable <T> source)
 {
     return(new ArrayLot <T>(
                EnumerableHelpers.ToArray(
                    source)));
 }
Esempio n. 14
0
        public virtual bool Unregister <T>(
            string name = null)
        {
            var ds           = this.dependencies;
            var unregistered = falsity;

            lock (this.locker)
            {
                foreach (var d in ds
                         ?? EH.Empty <Dependency>())
                {
                    if (this.tryGet(
                            d.Content,
                            d.Name,
                            name,
                            out T _))
                    {
                        unregistered = ds?.Remove(d)
                                       ?? falsity;
                        break;
                    }
                }
            }

            return(unregistered);
        }
Esempio n. 15
0
            public override int GetCount(bool onlyIfCheap)
            {
                int firstCount, secondCount;

                if (!EnumerableHelpers.TryGetCount(_first, out firstCount))
                {
                    if (onlyIfCheap)
                    {
                        return(-1);
                    }

                    firstCount = _first.Count();
                }

                if (!EnumerableHelpers.TryGetCount(_second, out secondCount))
                {
                    if (onlyIfCheap)
                    {
                        return(-1);
                    }

                    secondCount = _second.Count();
                }

                return(checked (firstCount + secondCount));
            }
Esempio n. 16
0
 IEnumerator <T> IEnumerable <T> .GetEnumerator()
 {
     return(this.stack?.GetEnumerator()
            ?? EnumerableHelpers
            .Empty <T>()
            .GetEnumerator());
 }
Esempio n. 17
0
        public static ReadOnlyCollection <T> ToReadOnly <T>(this IEnumerable <T> enumerable)
        {
            if (enumerable == null)
            {
                return(EmptyReadOnlyCollection <T> .Instance);
            }

            var troc = enumerable as TrueReadOnlyCollection <T>;

            if (troc != null)
            {
                return(troc);
            }

            var builder = enumerable as ReadOnlyCollectionBuilder <T>;

            if (builder != null)
            {
                return(builder.ToReadOnlyCollection());
            }

            T[] array = EnumerableHelpers.ToArray(enumerable);
            return(array.Length == 0 ?
                   EmptyReadOnlyCollection <T> .Instance :
                   new TrueReadOnlyCollection <T>(array));
        }
Esempio n. 18
0
        public void CountUnknownWordsTests_IEnumerables_null_Expect_0()
        {
            int actual = EnumerableHelpers.CountUnknownWords(
                distinctWords: null,
                dictionaryWords: null);

            Assert.Equal(expected: 0, actual: actual);
        }
Esempio n. 19
0
        public virtual MethodWebManager Shuffle()
        {
            var matchingManagers = this.shuffleManagers();

            return(EH.FirstOrDefault(
                       matchingManagers)?.
                   Manager);
        }
Esempio n. 20
0
 public virtual string ReadString(
     IEnumerable <bool> bits,
     Encoding encoding)
 {
     return(encoding?.GetString(
                EnumerableHelpers.ToArray(
                    this.GetBytes(bits))));
 }
Esempio n. 21
0
        public virtual MethodWeb Shuffle()
        {
            var matchingWebs = this.shuffleWebs();

            return(EnumerableHelpers.FirstOrDefault(
                       matchingWebs)?.
                   Web);
        }
Esempio n. 22
0
        public virtual long ReadNumber(
            IEnumerable <bool> bits)
        {
            var bytes = EnumerableHelpers.ToArray(
                this.GetBytes(bits));

            return(BitConverter.ToInt64(bytes, 0));
        }
        public IEnumerable <ISolutionExplorerProject> EnumerateProjects()
        {
            if (project == null)
            {
                throw new InvalidOperationException("No project has been loaded yet.");
            }

            return(EnumerableHelpers.EnumerableOf(project));
        }
Esempio n. 24
0
        // Returns an array of Directories in the current DirectoryInfo matching the
        // given search criteria (i.e. "System*" could match the System & System32
        // directories).
        private DirectoryInfo[] InternalGetDirectories(String searchPattern, SearchOption searchOption)
        {
            Debug.Assert(searchPattern != null);
            Debug.Assert(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly);

            IEnumerable <DirectoryInfo> enumerable = (IEnumerable <DirectoryInfo>)FileSystem.Current.EnumerateFileSystemInfos(FullPath, searchPattern, searchOption, SearchTarget.Directories);

            return(EnumerableHelpers.ToArray(enumerable));
        }
Esempio n. 25
0
        IEnumerator IEnumerable.GetEnumerator()
        {
            IEnumerable <T> source = this;

            return(source?.GetEnumerator()
                   ?? EnumerableHelpers
                   .Empty <T>()
                   .GetEnumerator());;
        }
Esempio n. 26
0
        // Returns an array of strongly typed FileSystemInfo entries in the path with the
        // given search criteria (ie, "*.txt").
        private FileSystemInfo[] InternalGetFileSystemInfos(String searchPattern, SearchOption searchOption)
        {
            Contract.Requires(searchPattern != null);
            Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly);

            IEnumerable <FileSystemInfo> enumerable = FileSystem.Current.EnumerateFileSystemInfos(FullPath, searchPattern, searchOption, SearchTarget.Both);

            return(EnumerableHelpers.ToArray(enumerable));
        }
Esempio n. 27
0
 public ActionLot(
     IEnumerable <Action <T> > source,
     Lot <T> items)
 {
     this.actionSource = source
                         ?? EnumerableHelpers.Empty <Action <T> >();
     this.items = items
                  ?? Lot.Empty <T>();
 }
Esempio n. 28
0
        protected virtual ICollection <DateTime> readAllTimestamps()
        {
            ICollection <DateTime> collection = new XLinkedList <DateTime>();
            var md = this.mainDirectory;

            try
            {
                if (!Directory.Exists(md))
                {
                    Directory.CreateDirectory(md);
                }
            }
            catch
            {
                return(collection);
            }

            string[] allDataFiles;
            try
            {
                allDataFiles = Directory.GetFiles(md);
            }
            catch
            {
                return(collection);
            }

            foreach (var filePath in allDataFiles)
            {
                IEnumerable <string> lines;
                try
                {
                    lines = File.ReadAllLines(filePath);
                }
                catch
                {
                    continue;
                }

                foreach (var line in lines)
                {
                    if (!long.TryParse(line, out var ticks))
                    {
                        continue;
                    }

                    collection.Add(new DateTime(ticks));
                }
            }

            collection = EnumerableHelpers.OrderBy(
                collection,
                timestamp => timestamp);

            return(collection);
        }
Esempio n. 29
0
        public static TSource[] ToArray <TSource>(this IEnumerable <TSource> source)
        {
            if (source == null)
            {
                throw Error.ArgumentNull("source");
            }
            IIListProvider <TSource> arrayProvider = source as IIListProvider <TSource>;

            return(arrayProvider != null?arrayProvider.ToArray() : EnumerableHelpers.ToArray(source));
        }
        protected virtual ICollection <DateTime> allTimes()
        {
            var r = this.runner;

            return(XLinkedList <DateTime> .Create(
                       EnumerableHelpers.OrderBy(
                           r?.Run <TimestampReader>()
                           ?.ReadAll(),
                           ts => ts)));
        }