Exemplo n.º 1
0
        /// <summary>
        ///     Inserts a song from a specified index to a other index in the playlist and moves all songs in between these indexes
        ///     one index back.
        /// </summary>
        /// <param name="fromIndex">The index of the song to move.</param>
        /// <param name="toIndex">To index to insert the song.</param>
        internal void InsertMove(int fromIndex, int toIndex)
        {
            if (fromIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => fromIndex, 0);
            }

            if (toIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => toIndex, 0);
            }

            if (toIndex >= fromIndex)
            {
                Throw.ArgumentException(
                    String.Format("{0} has to be smaller than {1}",
                                  Reflector.GetMemberName(() => toIndex), Reflector.GetMemberName(() => fromIndex)),
                    () => toIndex);
            }

            PlaylistEntry from = this[fromIndex];

            for (int i = fromIndex; i > toIndex; i--)
            {
                _playlist[i].Index = i - 1;
                _playlist[i]       = this[i - 1];
            }

            from.Index         = toIndex;
            _playlist[toIndex] = from;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inserts a song from a specified index to a other index in the playlist and moves all songs in between these indexes one index back.
        /// </summary>
        /// <param name="fromIndex">The index of the song to move.</param>
        /// <param name="toIndex">To index to insert the song.</param>
        public void InsertMove(int fromIndex, int toIndex)
        {
            if (fromIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => fromIndex, 0);
            }

            if (toIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => 0);
            }

            if (toIndex >= fromIndex)
            {
                Throw.ArgumentException(
                    String.Format("{0} has to be small than {1}",
                                  Reflector.GetMemberName(() => toIndex), Reflector.GetMemberName(() => fromIndex)),
                    () => toIndex);
            }

            Song from = this[fromIndex];

            for (int i = fromIndex; i > toIndex; i--)
            {
                this.playlist[i] = this[i - 1];
            }

            this.playlist[toIndex] = from;
        }
Exemplo n.º 3
0
        public static unsafe string Repeat(this string s, int count)
        {
            if (s == null)
            {
                Throw.ArgumentNullException(Argument.s);
            }
            if (count < 0)
            {
                Throw.ArgumentOutOfRangeException(Argument.count);
            }

            if (s.Length == 0 || count == 1)
            {
                return(s);
            }
            if (count == 0)
            {
                return(String.Empty);
            }

            string result = new String('\0', count * s.Length);

            fixed(char *pResult = result)
            {
                var sb = new MutableStringBuilder(pResult, result.Length);

                for (int i = 0; i < count; i++)
                {
                    sb.Append(s);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                Throw.ArgumentNullException(nameof(array));
            }
            if (arrayIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(nameof(arrayIndex), Message.Common.NonNegativeArrayIndex);
            }
            if (arrayIndex > array.Length)
            {
                Throw.ArgumentOutOfRangeException(nameof(arrayIndex), Message.Common.ArrayIndexCannotGreaterThanArraySize);
            }
            if (Count > array.Length - arrayIndex)
            {
                Throw.ArgumentException(Message.Common.ArraySizeLess);
            }
            if (IsEmpty)
            {
                return;
            }

            var current = Head;

            while (current != null)
            {
                array[arrayIndex++] = current.Item;
                current             = current.Next;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Copies the elements of the <see cref="T:System.Collections.ICollection" /> to an <see cref="T:System.Array" />, starting at a particular <see cref="T:System.Array" /> index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection" />. The <see cref="T:System.Array" /> must have zero-based indexing.</param>
        /// <param name="index">The zero-based index in <paramref name="array" /> at which copying begins.</param>
        public void CopyTo(Array array, int index)
        {
            if (array == null)
            {
                Throw.ArgumentNullException(nameof(array));
            }
            if (index < 0)
            {
                Throw.ArgumentOutOfRangeException(nameof(index), index, Message.Common.NonNegativeArrayIndex);
            }
            if (index > array.Length)
            {
                Throw.ArgumentOutOfRangeException(nameof(index), index, Message.Common.ArrayIndexCannotGreaterThanArraySize);
            }
            if (Count > array.Length - index)
            {
                Throw.ArgumentException(Message.Common.ArraySizeLess);
            }
            if (_head < _tail)
            {
                Array.Copy(_array, 0, array, index, Count);
                return;
            }

            Array.Copy(_array, _head, array, 0, _array.Length - _head);
            Array.Copy(_array, 0, array, _array.Length - _head, _tail);
        }
        /// <summary>
        /// Copies the <paramref name="source"/>&#160;<see cref="Stream"/> into the <paramref name="destination"/> one.
        /// Copy begins on the current position of source stream. None of the streams are closed or sought after
        /// the end of the copy progress.
        /// </summary>
        /// <param name="source">Source stream.</param>
        /// <param name="destination">Destination stream.</param>
        /// <param name="bufferSize">Size of the buffer used for copying.</param>
        public static void CopyTo(this Stream source, Stream destination, int bufferSize)
        {
            if (source == null)
            {
                Throw.ArgumentNullException(Argument.source);
            }
            if (destination == null)
            {
                Throw.ArgumentNullException(Argument.destination);
            }
            if (bufferSize <= 0)
            {
                Throw.ArgumentOutOfRangeException(Argument.bufferSize);
            }
            if (!source.CanRead)
            {
                Throw.ArgumentException(Argument.source, Res.StreamExtensionsStreamCannotRead);
            }
            if (!destination.CanWrite)
            {
                Throw.ArgumentException(Argument.destination, Res.StreamExtensionsStreamCannotWrite);
            }

            byte[] buffer = new byte[bufferSize];
            int    read;

            while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
            {
                destination.Write(buffer, 0, read);
            }
        }
        public ArraySection(int length, bool assureClean = true)
        {
            if (length < 0)
            {
                Throw.ArgumentOutOfRangeException(Argument.length);
            }
            offset      = 0;
            this.length = length;

#if !(NETFRAMEWORK || NETSTANDARD2_0)
            poolArray = length >= poolingThreshold;
            if (poolArray)
            {
                array = ArrayPool <T> .Shared.Rent(length);

                if (assureClean)
                {
                    Clear();
                }
                return;
            }
#endif

            array = length == 0 ? Reflector.EmptyArray <T>() : new T[length];
        }
Exemplo n.º 8
0
        internal void MoveSong(int fromIndex, int toIndex)
        {
            if (fromIndex >= this.playlist.Count)
            {
                Throw.ArgumentOutOfRangeException(() => fromIndex);
            }

            if (fromIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => fromIndex);
            }

            if (toIndex >= this.playlist.Count)
            {
                Throw.ArgumentOutOfRangeException(() => fromIndex);
            }

            if (toIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => fromIndex);
            }

            using (this.WithIndexRebuild())
            {
                this.playlist.Move(fromIndex, toIndex);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Repeats a <see cref="string"/>&#160;<paramref name="count"/> times.
        /// </summary>
        /// <param name="s">The string to repeat <paramref name="count"/> times.</param>
        /// <param name="count">The count of repeating <paramref name="s"/>. If 0, an empty string is returned. If 1 the original <paramref name="s"/> is returned.</param>
        /// <returns><paramref name="s"/> repeated <paramref name="count"/> times.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="s"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than 0.</exception>
        public static string Repeat(this string s, int count)
        {
            if (s == null)
            {
                Throw.ArgumentNullException(Argument.s);
            }
            if (count < 0)
            {
                Throw.ArgumentOutOfRangeException(Argument.count);
            }

            if (s.Length == 0 || count == 1)
            {
                return(s);
            }
            if (count == 0)
            {
                return(String.Empty);
            }

            StringBuilder result = new StringBuilder(s);

            for (int i = 0; i < count; i++)
            {
                result.Append(s);
            }

            return(result.ToString());
        }
Exemplo n.º 10
0
 public RequireAuthorChannelPermissionsAttribute(Permission permissions)
 {
     Permissions = ChannelPermissions.Mask(permissions, out var remainingPermissions);
     if (remainingPermissions != Permission.None)
     {
         Throw.ArgumentOutOfRangeException(nameof(permissions), $"The permissions specified for {GetType()} contain non-channel permissions: {remainingPermissions}.");
     }
 }
 internal int ThrowByHelper(int value)
 {
     if (value < 0)
     {
         Throw.ArgumentOutOfRangeException(Argument.value);
     }
     return(value + 1);
 }
 public static IEnumerable GetEnumerator(JsonElement document)
 {
     return(document.ValueKind switch
     {
         JsonValueKind.Object => EnumerateObject(),
         JsonValueKind.Array => ArrayProperties,
         _ => Throw.ArgumentOutOfRangeException <IEnumerable>()
     });
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CircularBuffer&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="capacity">The initial capacity of the <see cref="CircularBuffer{T}"/>.</param>
        public CircularBuffer(int capacity)
        {
            if (capacity < 1)
            {
                Throw.ArgumentOutOfRangeException(() => capacity, 1);
            }

            this.buffer = new List <T>(capacity);
        }
Exemplo n.º 14
0
        public Stack(int capacity)
        {
            if (capacity < 0)
            {
                Throw.ArgumentOutOfRangeException(nameof(capacity), capacity, Message.Stack.NonNegativeCapacity);
            }

            _array = new T[capacity];
        }
Exemplo n.º 15
0
        /// <summary>
        ///     Plays the song with the specified index in the playlist.
        /// </summary>
        /// <param name="playlistIndex">The index of the song in the playlist.</param>
        public void PlaySong(int playlistIndex)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            InternPlaySong(playlistIndex);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Rotates an array passed.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="array">Array to be rotated.</param>
 /// <param name="index">Index of the element from where the rotation must start.</param>
 /// <param name="numberOfElements">Number of elements to be rotated.</param>
 public void ToRotateIt <T>(T[] array, int index, int numberOfElements)
 {
     if (index < 0)
     {
         Throw.ArgumentOutOfRangeException(nameof(index));
     }
     //var currentIndexOfNewFirstElement = index > 0 ? index - 1 : ;
     var newIndexOfCurrentFirstElement = array.Length - numberOfElements + index;
     //var tempElement =
 }
 public ref T GetElementReference(int index)
 {
     // For better performance we throw an ArgumentOutOfRangeException only when a NullReferenceException
     // would come otherwise, and let the ArgumentOutOfRangeException come from array, even if a not localized one.
     if (array == null)
     {
         Throw.ArgumentOutOfRangeException(Argument.index);
     }
     return(ref GetElementReferenceInternal(index));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QueueUsingArray{T}"/> class.
        /// </summary>
        /// <param name="capacity">The capacity.</param>
        public QueueUsingArray(int capacity)
        {
            if (capacity < 0)
            {
                Throw.ArgumentOutOfRangeException(nameof(capacity), capacity, Message.Common.NonNegativeCapacity);
            }

            _array = new T[capacity];
            Count  = _head = _tail = 0;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamCopyOperation"/> class.
        /// </summary>
        /// <param name="sourceStream">The source stream.</param>
        /// <param name="targetStream">The target stream.</param>
        /// <param name="bufferSize">Size of the buffer.</param>
        /// <param name="updateInterval">The interval, after how much copied bytes the <see cref="CopyProgressChanged"/> should be raised.</param>
        public StreamCopyOperation(Stream sourceStream, Stream targetStream, int bufferSize, int updateInterval)
            : this(sourceStream, targetStream, bufferSize)
        {
            if (updateInterval < 1)
            {
                Throw.ArgumentOutOfRangeException(() => updateInterval, 1);
            }

            this.UpdateInterval = updateInterval;
        }
Exemplo n.º 20
0
        private void InternPlaySong(int playlistIndex)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            if (_currentPlayingPlaylist != null)
            {
                _currentPlayingPlaylist.CurrentSongIndex = null;
            }

            _currentPlayingPlaylist = CurrentPlaylist;

            CurrentPlaylist.CurrentSongIndex = playlistIndex;

            Song song = CurrentPlaylist[playlistIndex].Song;

            RenewCurrentPlayer(song);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    _currentPlayer.Load();
                }

                catch (SongLoadException)
                {
                    //song.IsCorrupted = true;
                    SongCorrupted.RaiseSafe(this, EventArgs.Empty);

                    HandleSongCorruption();

                    return;
                }

                try
                {
                    _currentPlayer.Play();
                }

                catch (PlaybackException)
                {
                    //song.IsCorrupted = true;
                    SongCorrupted.RaiseSafe(this, EventArgs.Empty);

                    HandleSongCorruption();

                    return;
                }

                SongStarted.RaiseSafe(this, EventArgs.Empty);
            });
        }
Exemplo n.º 21
0
        /// <summary>
        /// Plays the song with the specified index in the playlist.
        /// </summary>
        /// <param name="playlistIndex">The index of the song in the playlist.</param>
        public async Task PlaySongAsync(int playlistIndex, Guid accessToken)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            this.accessControl.VerifyAccess(accessToken, this.settings.LockPlayPause);

            await this.InternPlaySongAsync(playlistIndex);
        }
Exemplo n.º 22
0
 /// <summary>
 /// Computes the CRC-32 hash value for the specified byte array.
 /// </summary>
 /// <param name="buffer">The input to compute the hash code for.</param>
 /// <param name="offset">The offset into the byte array from which to begin using data.</param>
 /// <param name="count">The number of bytes in the array to use as data.</param>
 /// <param name="initialCrc">The initial CRC value to use. If the final CRC is calculated in more sessions the result of the last calculation can be specified here. This parameter is optional.
 /// <br/>Default value: <c>0</c>.</param>
 /// <param name="polynomial">The polynomial to use to calculate the CRC value. This parameter is optional.
 /// <br/>Default value: <see cref="StandardPolynomial"/>.</param>
 /// <returns>The CRC-32 hash value of the specified <paramref name="buffer"/>; or, if <paramref name="initialCrc"/> was specified, an
 /// accumulated hash value appended by the current <paramref name="buffer"/>.</returns>
 public static uint CalculateHash(byte[] buffer, int offset, int count, uint initialCrc = 0U, uint polynomial = StandardPolynomial)
 {
     if (buffer == null)
     {
         Throw.ArgumentNullException(Argument.buffer);
     }
     if (offset < 0 || count < 0 || offset + count > buffer.Length)
     {
         Throw.ArgumentOutOfRangeException(Argument.count);
     }
     return(CalculateHash(tablesCache[polynomial], initialCrc, buffer, offset, count));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Gets a <see cref="StringSegment"/> instance, which represents a segment of the specified <see cref="string">string</see>.
 /// No new string allocation occurs when using this method.
 /// </summary>
 /// <param name="s">The string to create the <see cref="StringSegment"/> from.</param>
 /// <param name="offset">The offset that points to the first character of the returned segment.</param>
 /// <returns>A <see cref="StringSegment"/> instance, which represents a segment of the specified <see cref="string">string</see>.</returns>
 public static StringSegment AsSegment(this string s, int offset)
 {
     if (s == null)
     {
         Throw.ArgumentNullException(Argument.s);
     }
     if ((uint)offset > (uint)s.Length)
     {
         Throw.ArgumentOutOfRangeException(Argument.offset);
     }
     return(new StringSegment(s, offset, s.Length - offset));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Plays the song with the specified index in the playlist.
        /// </summary>
        /// <param name="playlistIndex">The index of the song in the playlist.</param>
        public void PlaySong(int playlistIndex)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            if (this.LockPlayPause && this.AccessMode == AccessMode.Party)
            {
                throw new InvalidOperationException("Not allowed to play when in party mode.");
            }

            this.InternPlaySong(playlistIndex);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Gets the character at the specified position in this <see cref="StringSegment"/>.
 /// </summary>
 /// <param name="index">The index of the character to obtain.</param>
 /// <returns>The character at the specified position in this <see cref="StringSegment"/>.</returns>
 public char this[int index]
 {
     [MethodImpl(MethodImpl.AggressiveInlining)]
     get
     {
         // For better performance we throw an ArgumentOutOfRangeException only when a NullReferenceException
         // would come otherwise, and let the ArgumentOutOfRangeException come from string, even if a not localized one.
         if (str == null)
         {
             Throw.ArgumentOutOfRangeException(Argument.index);
         }
         return(GetCharInternal(index));
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// Returns the logarithm of a specified <paramref name="value"/> in a specified <paramref name="base"/>.
        /// </summary>
        /// <param name="value">The value whose logarithm is to be found. Must be greater than zero.</param>
        /// <param name="base">The base of the logarithm.</param>
        /// <returns>The logarithm of the specified <paramref name="value"/> in the specified <paramref name="base"/>.</returns>
        /// <remarks>
        /// <para>This member is similar to <see cref="Math.Log(double,double)">Math.Log(double, double)</see> but uses <see cref="decimal"/> type instead of <see cref="double"/>.</para>
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to 0.
        /// <br/>-or-
        /// <br/><paramref name="base"/> equals to 1 or is less or equal to 0.</exception>
        public static decimal Log(this decimal value, decimal @base)
        {
            if (@base == 1m)
            {
                Throw.ArgumentOutOfRangeException(Argument.value);
            }
            if (value == 1m && @base == 0m)
            {
                return(0m);
            }
            var result = Log(value) / Log(@base);

            return(RoundInternal(result));
        }
Exemplo n.º 27
0
        private void InternPlaySong(int playlistIndex)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            if (this.isWaitingOnCache)
            {
                this.overrideCurrentCaching = true;

                // Let the song that is selected to be played wait here, if there is currently another song caching
                cacheResetHandle.WaitOne();
            }

            this.playlist.CurrentSongIndex = playlistIndex;

            Song song = this.playlist[playlistIndex];

            if (this.currentPlayer != null)
            {
                this.currentPlayer.Dispose();
            }

            this.currentPlayer = song.CreateAudioPlayer();

            this.currentPlayer.SongFinished += (sender, e) => this.HandleSongFinish();
            this.currentPlayer.Volume        = this.volume;

            Task.Factory.StartNew(() =>
            {
                if (song.HasToCache && !song.IsCached)
                {
                    bool cached = this.AwaitCaching(song);

                    if (!cached)
                    {
                        return;
                    }
                }

                this.overrideCurrentCaching = false;

                this.currentPlayer.Load(song);
                this.currentPlayer.Play();

                this.SongStarted.RaiseSafe(this, EventArgs.Empty);
            });
        }
Exemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataTransferEventArgs"/> class.
        /// </summary>
        /// <param name="totalBytes">The total number of bytes.</param>
        /// <param name="transferredBytes">The transferred bytes.</param>
        public DataTransferEventArgs(long totalBytes, long transferredBytes)
        {
            if (totalBytes < 1)
            {
                Throw.ArgumentOutOfRangeException(() => totalBytes, 1);
            }

            if (transferredBytes < 1)
            {
                Throw.ArgumentOutOfRangeException(() => transferredBytes, 1);
            }

            this.TotalBytes       = totalBytes;
            this.TransferredBytes = transferredBytes;
        }
Exemplo n.º 29
0
        internal PlaylistEntry(int index, Song song)
        {
            if (index < 0)
            {
                Throw.ArgumentOutOfRangeException(() => index, 0);
            }

            if (song == null)
            {
                Throw.ArgumentNullException(() => song);
            }

            Index = index;
            Song  = song;
        }
Exemplo n.º 30
0
 private static void InternalValidationForListAndIndex <T>(Singly <T> list, int nTh)
 {
     if (list == null)
     {
         Throw.ArgumentNullException(nameof(list));
     }
     if (nTh < 1)
     {
         Throw.ArgumentOutOfRangeException(nameof(nTh), Message.OnSinglyLinkedList.NthMustBePositiveNonZero);
     }
     if (nTh > list.Count)
     {
         Throw.ArgumentOutOfRangeException(nameof(nTh), Message.OnSinglyLinkedList.NthCannotBeGreaterThanListCount);
     }
 }