public void CanDoQueryableNumeric()
        {
            var config = new SiteConfig()
            {
                RootUrl = String.Empty,
                Url = "http://www.example.com"
            };

            var meta1 = new MetadataCollection();
            meta1.Add("number", 1);

            var meta2 = new MetadataCollection();
            meta2.Add("number", 20);

            var meta3 = new MetadataCollection();
            meta3.Add("number", 3);

            var documents = new[]
            {
                new DocumentFile("1.html.md", Path.GetFullPath("documents"), "documents", "1", "1", String.Empty, null, meta1, null),
                new DocumentFile("20.html.md", Path.GetFullPath("documents"), "documents", "20", "20", String.Empty, null, meta2, null),
                new DocumentFile("3.html.md", Path.GetFullPath("documents"), "documents", "3", "3", String.Empty, null, meta3, null),
            };

            var site = new Site(config, Enumerable.Empty<DataFile>(), documents, Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            var query = @"query documents where number gt 1 ascending number";

            var p = QueryProcessor.Parse(site, query);

            var q = p.Results.ToList();
            Assert.Equal(3, q[0].Number);
            Assert.Equal(20, q[1].Number);
        }
        public void AddRange_throws_ArgumentNullException_for_null_collection_item()
        {
            var metadataCollection = new MetadataCollection<MetadataItem>();

            Assert.Equal(
                Strings.ADP_CollectionParameterElementIsNull("items"),
                Assert.Throws<ArgumentException>(
                    () => metadataCollection.AtomicAddRange(
                        new List<MetadataItem>
                            {
                                null
                            })).Message);
        }
Exemplo n.º 3
0
        public DataFile(string path, string rootPath, string sourceContent, MetadataCollection metadata, IDictionary<string, string> queries)
            : base(path, rootPath)
        {
            var relativePath = this.SourcePath.Substring(rootPath.Length);

            this.Id = Path.Combine(Path.GetDirectoryName(relativePath), Path.GetFileNameWithoutExtension(relativePath));

            this.SourceContent = sourceContent;

            this.Metadata = metadata;

            this.Queries = queries;
        }
        public void Can_remove_item_from_collection()
        {
            var metadataCollection = new MetadataCollection<EntityType>();

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            metadataCollection.Add(entityType);

            Assert.Equal(1, metadataCollection.Count);

            metadataCollection.Remove(entityType);

            Assert.Empty(metadataCollection);
        }
        public ScriptPlaylistItem()
        {
            FileSize = 0;
            FrameRate = 30;
            JumpToLive = false;
            MediaSource = null;
            ThumbSource = null;
            Description = string.Empty;
            Title = String.Empty;
            VideoStretchMode = "Uniform";
            VideoWidth = double.NaN;
            VideoHeight = double.NaN;
			ScriptS3DProperties = new ScriptS3DProperties();
			CustomMetadata = new MetadataCollection();
        }
Exemplo n.º 6
0
        public DocumentFile(string path, string rootPath, string outputPath, string outputRootPath, string url, string rootUrl, Author author, MetadataCollection metadata, IDictionary<string, string> queries)
            : base(path, rootPath, outputPath, outputRootPath, rootUrl, url)
        {
            this.Now = DateTime.Now;

            this.Author = author;

            if (metadata != null)
            {
                this.Layout = metadata.Get<string>("layout");
                metadata.Remove("layout");

                this.Metadata = metadata;
            }

            this.Queries = queries;
        }
        public void Can_replace_item_via_ordinal_indexer()
        {
            var metadataCollection = new MetadataCollection<EntityType>();

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            metadataCollection.Add(entityType);

            Assert.Equal(1, metadataCollection.Count);

            var entityType2 = new EntityType("E", "N", DataSpace.CSpace);

            metadataCollection[0] = entityType2;

            Assert.Equal(1, metadataCollection.Count);
            Assert.Same(entityType2, metadataCollection[0]);
        }
        public void Add_throws_ArgumentException_for_duplicate_identity()
        {
            var metadataCollection = new MetadataCollection<EntityType>();
            var item = new EntityType("E", "N", DataSpace.CSpace);
            metadataCollection.Add(item);
            Assert.Equal(1, metadataCollection.Count);

            Assert.Contains(
                Strings.ItemDuplicateIdentity(item.Identity),
                Assert.Throws<ArgumentException>(
                    () => metadataCollection.Add(item)).Message);

            Assert.Contains(
                Strings.ItemDuplicateIdentity(item.Identity),
                Assert.Throws<ArgumentException>(
                    () => metadataCollection.Add(
                        new EntityType("E", "N", DataSpace.CSpace))).Message);
        }
Exemplo n.º 9
0
        public void CanDoQueryableMultipleWhere()
        {
            var config = new SiteConfig()
            {
                RootUrl = String.Empty,
                Url = "http://www.example.com"
            };

            var meta1 = new MetadataCollection
            {
                { "number", 1 },
                { "canonical", null }
            };

            var meta2 = new MetadataCollection
            {
                { "number", 20 },
                { "canonical", "true" }
            };

            var meta3 = new MetadataCollection
            {
                { "number", 3 },
                { "canonical", null }
            };

            var documents = new[]
            {
                new DocumentFile("1.html.md", Path.GetFullPath("documents"), "documents", "1", "1", String.Empty, null, meta1, null),
                new DocumentFile("20.html.md", Path.GetFullPath("documents"), "documents", "20", "20", String.Empty, null, meta2, null),
                new DocumentFile("3.html.md", Path.GetFullPath("documents"), "documents", "3", "3", String.Empty, null, meta3, null),
            };

            var site = new Site(config, Enumerable.Empty<DataFile>(), documents, Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            var query = @"query documents where number gt 1 where canonical equals null ascending number";

            var p = QueryProcessor.Parse(site, query);

            var q = p.Results.ToList();
            Assert.Single(q);
            Assert.Equal(3, q[0].Number);
        }
Exemplo n.º 10
0
        /// <summary>
        /// parameterless constructor required for Edit in Blend.
        /// </summary>
        public PlaylistItem()
        {
            TimelineMarkers = new List<TimelineMediaMarker>();
            Chapters = new List<Chapter>();
            Captions = new List<CaptionRegion>();
            MarkerResources = new List<MarkerResource>();
            InterstitialAdvertisements = new List<Advertisement>();
            MediaPluginRequiredMetadata = new MetadataCollection();
			CustomMetadata = new MetadataCollection();
            ChunkDownloadStrategy = Plugins.Primitives.ChunkDownloadStrategy.Unspecified;
            Title = string.Empty;
            Description = string.Empty;
            ThumbSource = null;
            FileSize = 0;
            JumpToLive = true;
            VideoHeight = DefaultVideoHeight;
            VideoWidth = DefaultVideoWidth;
            VideoStretchMode = DefaultVideoStretchMode;
        }
Exemplo n.º 11
0
    /// <summary>
    /// Converts musicbrainz metadata collection to 
    /// <see cref="mp3tag.MetadataCollection"/>.
    /// </summary>
    /// <param name="album">Musicbrainz album object</param>
    /// <returns>Corresponding tag collection</returns>
    /// <remarks>
    /// Musicbrainz supports release types. This information
    /// in the case of non-album releases the data is appended
    /// to the album name. Date defaults to today if nothing 
    /// is set.
    /// 
    /// In the case of various artist, the artist is set to
    /// album artist first to locate album art & genre. 
    /// Then artist is based on a per-track basis.
    /// </remarks>
    static public Metadata ToTag(this MusicBrainz.Release album)
    {
      Metadata Collection = new MetadataCollection();
      Metadata Metadata = new Id3();

      // If date is not set, use current date
      string ReleaseDate = String.Empty;
      try {
        ReleaseDate = album.GetEvents().First().Date.ToString();
      } 
      catch(Exception)
      {
        ReleaseDate = DateTime.Now.Year.ToString();
      }
      
      // Build tag with search data
      Art Art = new Art();
      Metadata.MusicBrainzReleaseArtistId = album.GetArtist().Id;
      Metadata.MusicBrainzReleaseId = album.Id;
      Metadata.MusicBrainzReleaseType = album.GetReleaseType().ToString();
      Metadata.AlbumArtist = album.GetArtist();
      Metadata.Release = album.GetTitle();
      Metadata.AmazonId = album.GetAsin();
      Metadata.ReleaseYear = ReleaseDate.Substring(0, 4);
      Metadata.Art = Art.Search(Metadata);

      // Search for genre; populate with default for now
      Metadata.Genre = "Hardcore";
      //Metadata.Genre = ITunesService.SearchArtistGenre(Metadata);

      // Set track titles
      foreach (Track Trk in album.GetTracks())
      {
        Metadata.Title = Trk.GetTitle();
        Metadata.Artist = Trk.GetArtist();
        Metadata.MusicBrainzArtistId = Trk.GetArtist().Id;
        Metadata.Track = (Collection.ToList<Metadata>().Count() + 1).ToString();
        Collection.Add(new Id3(Metadata));
      }

      return Collection;
    }
        public void AddRange_can_add_items_to_readonly_collection()
        {
            var metadataCollection = new MetadataCollection<EntityType>();
            var item = new EntityType("E", "N", DataSpace.CSpace);
            metadataCollection.Add(item);
            Assert.Equal(1, metadataCollection.Count);

            metadataCollection.SetReadOnly();
            Assert.True(metadataCollection.IsReadOnly);

            metadataCollection.AddRange(
                new List<EntityType>
                {
                    new EntityType("F", "N", DataSpace.CSpace),
                    new EntityType("G", "N", DataSpace.CSpace)
                });

            Assert.Equal(3, metadataCollection.Count);
            Assert.True(metadataCollection.IsReadOnly);
        }
        public void Can_remove_item_from_collection_and_identity_dictionary_updated()
        {
            var metadataCollection = new MetadataCollection<EntityType>();

            for (var i = 0; i < 30; i++)
            {
                metadataCollection.Add(new EntityType("E" + i, "N", DataSpace.CSpace));
            }

            for (var i = 0; i < metadataCollection.Count; i++)
            {
                // This will throw if the identity cache gets out of sync.

                var entityType = metadataCollection[i];

                metadataCollection.Remove(entityType);
                metadataCollection.Add(entityType);
            }

            Assert.Equal(30, metadataCollection.Count);
        }
Exemplo n.º 14
0
        public LayoutFile(string path, string rootPath, string sourceContent, MetadataCollection metadata, IDictionary<string, string> queries)
            : base(path, rootPath)
        {
            var relativePath = this.SourcePath.Substring(rootPath.Length);

            this.Id = Path.Combine(Path.GetDirectoryName(relativePath), Path.GetFileNameWithoutExtension(relativePath));

            this.SourceContent = sourceContent;

            this.Metadata = metadata;

            string layout;
            if (this.Metadata != null && this.Metadata.TryGet("layout", out layout))
            {
                this.Layout = layout;

                this.Metadata.Remove("layout");
            }

            this.Queries = queries;
        }
Exemplo n.º 15
0
        Player( [NotNull] TcpClient tcpClient ) {
            if( tcpClient == null ) throw new ArgumentNullException( "tcpClient" );
            State = SessionState.Connecting;
            LoginTime = DateTime.UtcNow;
            LastActiveTime = DateTime.UtcNow;
            LastPatrolTime = DateTime.UtcNow;
            LeaveReason = LeaveReason.Unknown;
            LastUsedBlockType = Block.Undefined;

            client = tcpClient;
            client.SendTimeout = SocketTimeout;
            client.ReceiveTimeout = SocketTimeout;

            Brush = NormalBrushFactory.Instance;
            Metadata = new MetadataCollection<object>();

            try {
                IP = ((IPEndPoint)(client.Client.RemoteEndPoint)).Address;
                if( Server.RaiseSessionConnectingEvent( IP ) ) return;

                stream = client.GetStream();
                reader = new BinaryReader( stream );
                writer = new PacketWriter( stream );

                ioThread = new Thread( IoLoop ) {
                    Name = "fCraft.Session",
                    IsBackground = true,
                    CurrentCulture = new CultureInfo( "en-US" )
                };
                ioThread.Start();

            } catch( SocketException ) {
                // Mono throws SocketException when accessing Client.RemoteEndPoint on disconnected sockets
                Disconnect();

            } catch( Exception ex ) {
                Logger.LogAndReportCrash( "Session failed to start", "fCraft", ex, false );
                Disconnect();
            }
        }
Exemplo n.º 16
0
        public DocumentFile(string path, string rootPath, string outputPath, string outputRootPath, string url, string rootUrl, Author author, MetadataCollection metadata, IDictionary<string, string> queries)
            : base(path, rootPath, outputPath, outputRootPath, rootUrl, url)
        {
            this.Author = author;

            var now = DateTime.Now;

            this.Now = now;
            this.NowUtc = now.ToUniversalTime();
            this.NowFriendlyDate = now.ToString("D");
            this.NowStandardUtcDate = now.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ");

            if (metadata != null)
            {
                this.Layout = metadata.Get<string>("layout");
                metadata.Remove("layout");

                this.Metadata = metadata;
            }

            this.Queries = queries;
        }
Exemplo n.º 17
0
    /// <summary>
    /// Explicitly casts <see cref="Lastfm.Services.Album"/>
    /// to <see cref="mp3tag.Metadata"/>
    /// </summary>
    /// <param name="album">Album tag to be casted</param>
    /// <returns>mp3tag.Tag object</returns>
    static public Metadata ToTag(this Lastfm.Services.Album album)
    {
      // Set album specific data
      Metadata Collection = new MetadataCollection();
      Metadata Metadata = new Id3();
      Metadata.Artist = album.Artist.Name;
      Metadata.Release = album.Name;
      Metadata.ReleaseYear = album.GetReleaseDate().Year.ToString();
      Metadata.Art = album.GetImageURL(AlbumImageSize.ExtraLarge);
      
      // Invoke copy constructor on tag object
      // otherwirse all tags in the collection will have changes
      // applied.
      foreach (Track t in album.GetTracks())
      {
        Metadata.Title = t.Title;
        Metadata.Track = (Collection.ToList<Metadata>().Count() + 1).ToString();
        Collection.Add(new Id3(Metadata));
      }

      // Return tag collection for album
      return Collection;
    }
        public void Can_check_if_collection_contains_item_with_specified_identity()
        {
            var items = new[]
            {
                new EntityType("E0", "N", DataSpace.CSpace),
                new EntityType("E1", "N", DataSpace.CSpace),
                new EntityType("E2", "N", DataSpace.CSpace),
                new EntityType("E3", "N", DataSpace.CSpace),
                new EntityType("E4", "N", DataSpace.CSpace)
            };

            var collection = new MetadataCollection<EntityType>(items);

            for (var i = 0; i < collection.Count; i++)
            {
                Assert.True(collection.ContainsIdentity("N.E" + i));
            }

            Assert.False(collection.ContainsIdentity("missing"));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Asynchronously gets the specified metadata.
 /// </summary>
 /// <remarks>
 /// Sets the specified metadata.
 /// </remarks>
 /// <returns>An asynchronous task context.</returns>
 /// <param name="metadata">The metadata.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="metadata"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 /// The <see cref="ImapClient"/> has been disposed.
 /// </exception>
 /// <exception cref="ServiceNotConnectedException">
 /// The <see cref="ImapClient"/> is not connected.
 /// </exception>
 /// <exception cref="ServiceNotAuthenticatedException">
 /// The <see cref="ImapClient"/> is not authenticated.
 /// </exception>
 /// <exception cref="System.NotSupportedException">
 /// The IMAP server does not support the METADATA or METADATA-SERVER extension.
 /// </exception>
 /// <exception cref="System.OperationCanceledException">
 /// The operation was canceled via the cancellation token.
 /// </exception>
 /// <exception cref="System.IO.IOException">
 /// An I/O error occurred.
 /// </exception>
 /// <exception cref="ImapProtocolException">
 /// The server's response contained unexpected tokens.
 /// </exception>
 /// <exception cref="ImapCommandException">
 /// The server replied with a NO or BAD response.
 /// </exception>
 public override Task SetMetadataAsync(MetadataCollection metadata, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(SetMetadataAsync(metadata, true, cancellationToken));
 }
Exemplo n.º 20
0
 public static IDictionary <string, string> ToDictionary(this MetadataCollection collection)
 {
     return(collection.Keys.ToDictionary(key => key, key => collection[key]));
 }
Exemplo n.º 21
0
        private PlaylistItem(PlaylistItem playlistItem)
        {
            CustomMetadata = new MetadataCollection();
            MediaPluginRequiredMetadata = new MetadataCollection();
            playlistItem.MediaPluginRequiredMetadata
                        .Select(i => i.Clone())
                        .ForEach(MediaPluginRequiredMetadata.Add);
			playlistItem.CustomMetadata
						.Select(i => i.Clone())
						.ForEach(CustomMetadata.Add);
            InterstitialAdvertisements = playlistItem.InterstitialAdvertisements
                                                     .Select(i => i.Clone())
                                                     .ToList();

            TimelineMarkers = playlistItem.TimelineMarkers
                                          .Select(i => i.Clone())
                                          .ToList();

            Chapters = playlistItem.Chapters
                                   .Select(i => i.Clone())
                                   .ToList();

            Captions = playlistItem.Captions.ToList();

            playlistItem.MarkerResources.IfNotNull(i => MarkerResources = i.Select(j => j.Clone()).ToList());
            playlistItem.PreRollAdvertisement.IfNotNull(i => PreRollAdvertisement = i.Clone());
            playlistItem.PostRollAdvertisement.IfNotNull(i => PostRollAdvertisement = i.Clone());

            DeliveryMethod = playlistItem.DeliveryMethod;
			S3DProperties = playlistItem.S3DProperties;
            FrameRate = playlistItem.FrameRate;
            LiveDvrRequired = playlistItem.LiveDvrRequired;
            MediaSource = playlistItem.MediaSource;
            SelectedAudioStreamLanguage = playlistItem.SelectedAudioStreamLanguage;
            SelectedAudioStreamName = playlistItem.SelectedAudioStreamName;
            SelectedCaptionStreamLanguage = playlistItem.SelectedCaptionStreamLanguage;
            SelectedCaptionStreamName = playlistItem.SelectedCaptionStreamName;
            StartPosition = playlistItem.StartPosition;
            StreamSource = playlistItem.StreamSource;
            Title = playlistItem.Title;
            Description = playlistItem.Description;
            ThumbSource = playlistItem.ThumbSource;
            FileSize = playlistItem.FileSize;
            JumpToLive = playlistItem.JumpToLive;
            VideoHeight = playlistItem.VideoHeight;
            VideoWidth = playlistItem.VideoWidth;
            VideoStretchMode = playlistItem.VideoStretchMode;
        }
Exemplo n.º 22
0
		/// <summary>
		/// Asynchronously sets the specified metadata.
		/// </summary>
		/// <remarks>
		/// Asynchronously sets the specified metadata.
		/// </remarks>
		/// <returns>An asynchronous task context.</returns>
		/// <param name="metadata">The metadata.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="metadata"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The folder does not support metadata.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public virtual Task SetMetadataAsync (MetadataCollection metadata, CancellationToken cancellationToken = default (CancellationToken))
		{
			return Task.Factory.StartNew (() => {
				lock (SyncRoot) {
					SetMetadata (metadata, cancellationToken);
				}
			}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
		}
Exemplo n.º 23
0
		/// <summary>
		/// Sets the specified metadata.
		/// </summary>
		/// <remarks>
		/// Sets the specified metadata.
		/// </remarks>
		/// <param name="metadata">The metadata.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="metadata"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The folder does not support metadata.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public abstract void SetMetadata (MetadataCollection metadata, CancellationToken cancellationToken = default (CancellationToken));
Exemplo n.º 24
0
        public static IDictionary <string, string> GetCombinedMetadata(HeadersCollection headers, MetadataCollection metadata)
        {
            var result = new Dictionary <string, string>();

            foreach (var key in headers.Keys.Where(SupportedSpecialHeaders.ContainsKey))
            {
                result.Add(key, SupportedSpecialHeaders[key](headers));
            }

            foreach (var key in metadata.Keys)
            {
                result.Add(key, metadata[key]);
            }

            return(result);
        }
        public void Modifiers_throw_when_collection_is_readonly()
        {
            var metadataCollection = new MetadataCollection<EntityType>();
            var item = new EntityType("E", "N", DataSpace.CSpace);
            metadataCollection.Add(item);
            Assert.Equal(1, metadataCollection.Count);

            metadataCollection.SetReadOnly();
            Assert.True(metadataCollection.IsReadOnly);

            Assert.Equal(
                Strings.OperationOnReadOnlyCollection,
                Assert.Throws<InvalidOperationException>(
                    () => metadataCollection.Add(
                        new EntityType("E", "N", DataSpace.CSpace))).Message);

            Assert.Equal(
                Strings.OperationOnReadOnlyCollection,
                Assert.Throws<InvalidOperationException>(
                    () => metadataCollection.Remove(item)).Message);

            Assert.Equal(
                Strings.OperationOnReadOnlyCollection,
                Assert.Throws<InvalidOperationException>(
                    () => metadataCollection[0] = item).Message);
        }
Exemplo n.º 26
0
        /// <summary>
        /// checks if encryption credentials are in object metadata
        /// </summary>
        /// <param name="response">Response of the object</param>
        /// <returns></returns>
        internal static bool IsEncryptionInfoInMetadata(GetObjectResponse response)
        {
            MetadataCollection metadata = response.Metadata;

            return((metadata[XAmzKey] != null || metadata[XAmzKeyV2] != null) && metadata[XAmzIV] != null);
        }
Exemplo n.º 27
0
        /// <summary> Creates an empty new map of given dimensions.
        /// Dimensions cannot be changed after creation. </summary>
        /// <param name="world"> World that owns this map. May be null, and may be changed later. </param>
        /// <param name="width"> Width (horizontal, Notch's X). </param>
        /// <param name="length"> Length (horizontal, Notch's Z). </param>
        /// <param name="height"> Height (vertical, Notch's Y). </param>
        /// <param name="initBlockArray"> If true, the Blocks array will be created. </param>
        /// <exception cref="ArgumentOutOfRangeException"> Width, length, or height is not between 16 and 2048. </exception>
        /// <exception cref="ArgumentException"> Map volume exceeds Int32.MaxValue. </exception>
        public Map([CanBeNull] World world, int width, int length, int height, bool initBlockArray) {
            if (!IsValidDimension(width)) throw new ArgumentOutOfRangeException("width", "Invalid map width.");
            if (!IsValidDimension(length)) throw new ArgumentOutOfRangeException("length", "Invalid map length.");
            if (!IsValidDimension(height)) throw new ArgumentOutOfRangeException("height", "Invalid map height.");
            if ((long)width*length*height > Int32.MaxValue) {
                throw new ArgumentException("Map volume exceeds Int32.MaxValue.");
            }
            DateCreated = DateTime.UtcNow;
            DateModified = DateCreated;
            Guid = Guid.NewGuid();

            Metadata = new MetadataCollection<string>();
            Metadata.Changed += OnMetaOrZoneChange;

            Zones = new ZoneCollection();
            Zones.Changed += OnMetaOrZoneChange;

            World = world;

            Width = width;
            Length = length;
            Height = height;
            Bounds = new BoundingBox(Vector3I.Zero, Width, Length, Height);
            Volume = Bounds.Volume;

            if (initBlockArray) {
                Blocks = new byte[Volume];
            }

            ResetSpawn();
        }
Exemplo n.º 28
0
		/// <summary>
		/// Sets the specified metadata.
		/// </summary>
		/// <remarks>
		/// Sets the specified metadata.
		/// </remarks>
		/// <returns>The metadata.</returns>
		/// <param name="metadata">The metadata.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="metadata"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="ImapClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="ImapClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="ImapClient"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The IMAP server does not support the METADATA extension.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ImapProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="ImapCommandException">
		/// The server replied with a NO or BAD response.
		/// </exception>
		public override void SetMetadata (MetadataCollection metadata, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (metadata == null)
				throw new ArgumentNullException ("metadata");

			CheckState (false, false);

			if ((Engine.Capabilities & ImapCapabilities.Metadata) == 0)
				throw new NotSupportedException ("The IMAP server does not support the METADATA extension.");

			var command = new StringBuilder ("SETMETADATA %F (");
			var args = new object[metadata.Count * 2 + 1];
			int argc = 0;

			args[argc++] = this;

			for (int i = 0; i < metadata.Count; i++) {
				if (i > 0)
					command.Append (' ');

				command.Append ("%S %S");
				args[argc++] = metadata[i].Tag.Id;
				args[argc++] = metadata[i].Value;
			}
			command.Append (")\r\n");

			var ic = new ImapCommand (Engine, cancellationToken, null, command.ToString (), args);

			Engine.QueueCommand (ic);
			Engine.Wait (ic);

			ProcessResponseCodes (ic, null);

			if (ic.Response != ImapCommandResponse.Ok)
				throw ImapCommandException.Create ("SETMETADATA", ic);
		}
        public void Can_get_IndexOf_item()
        {
            var items = new []
            {
                new EntityType("E0", "N", DataSpace.CSpace),
                new EntityType("E1", "N", DataSpace.CSpace),
                new EntityType("E2", "N", DataSpace.CSpace),
                new EntityType("E3", "N", DataSpace.CSpace),
                new EntityType("E4", "N", DataSpace.CSpace)
            };

            var collection = new MetadataCollection<EntityType>(items);

            for (var i = 0; i < items.Length; i++)
            {
                Assert.Equal(i, collection.IndexOf(items[i]));
            }
        }
Exemplo n.º 30
0
		/// <summary>
		/// Gets the specified metadata.
		/// </summary>
		/// <remarks>
		/// Gets the specified metadata.
		/// </remarks>
		/// <returns>The requested metadata value.</returns>
		/// <param name="tag">The metadata tag.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="ImapClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="ImapClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="ImapClient"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The IMAP server does not support the METADATA extension.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ImapProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="ImapCommandException">
		/// The server replied with a NO or BAD response.
		/// </exception>
		public override string GetMetadata (MetadataTag tag, CancellationToken cancellationToken = default (CancellationToken))
		{
			CheckState (false, false);

			if ((Engine.Capabilities & ImapCapabilities.Metadata) == 0)
				throw new NotSupportedException ("The IMAP server does not support the METADATA extension.");

			var ic = new ImapCommand (Engine, cancellationToken, null, "GETMETADATA %F (%S)\r\n", this, tag.Id);
			ic.RegisterUntaggedHandler ("METADATA", UntaggedMetadata);
			var metadata = new MetadataCollection ();
			ic.UserData = metadata;

			Engine.QueueCommand (ic);
			Engine.Wait (ic);

			ProcessResponseCodes (ic, null);

			if (ic.Response != ImapCommandResponse.Ok)
				throw ImapCommandException.Create ("GETMETADATA", ic);

			for (int i = 0; i < metadata.Count; i++) {
				if (metadata[i].Tag.Id == tag.Id)
					return metadata[i].Value;
			}

			return null;
		}
        public void Dictionaries_are_updated_when_HandleIdentityChange_is_called()
        {
            var members = new List<EdmProperty>();

            for (var i = 0; i < MetadataCollection<EntityType>.UseDictionaryCrossover + 1; i++)
            {
                members.Add(EdmProperty.CreatePrimitive("P" + i, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));
            }

            var collection = new MetadataCollection<EdmProperty>(members);
            Assert.Equal(members.Count, collection.Count);

            collection.GetValue(collection[0].Identity, false);
            collection.GetValue(collection[0].Identity, true);

            Assert.True(collection.HasCaseSensitiveDictionary);
            Assert.True(collection.HasCaseInsensitiveDictionary);

            var item = collection[3];
            item.Name = "R3";
            collection.HandleIdentityChange(item, "P3");

            Assert.True(collection.HasCaseSensitiveDictionary);
            Assert.False(collection.HasCaseInsensitiveDictionary);

            Assert.Same(item, collection["R3"]);
        }
Exemplo n.º 32
0
        /// <summary> Creates an empty new map of given dimensions.
        /// Dimensions cannot be changed after creation. </summary>
        /// <param name="world"> World that owns this map. May be null, and may be changed later. </param>
        /// <param name="width"> Width (horizontal, Notch's X). </param>
        /// <param name="length"> Length (horizontal, Notch's Z). </param>
        /// <param name="height"> Height (vertical, Notch's Y). </param>
        /// <param name="initBlockArray"> If true, the Blocks array will be created. </param>
        public Map( World world, int width, int length, int height, bool initBlockArray )
        {
            if( !IsValidDimension( width ) ) throw new ArgumentException( "Invalid map dimension.", "width" );
            if( !IsValidDimension( length ) ) throw new ArgumentException( "Invalid map dimension.", "length" );
            if( !IsValidDimension( height ) ) throw new ArgumentException( "Invalid map dimension.", "height" );
            DateCreated = DateTime.UtcNow;
            DateModified = DateCreated;
            Guid = Guid.NewGuid();

            Metadata = new MetadataCollection<string>();
            Metadata.Changed += OnMetaOrZoneChange;

            Zones = new ZoneCollection();
            Zones.Changed += OnMetaOrZoneChange;

            World = world;

            Width = width;
            Length = length;
            Height = height;
            Bounds = new BoundingBox( Vector3I.Zero, Width, Length, Height );
            Volume = Bounds.Volume;

            if( initBlockArray ) {
                Blocks = new byte[Volume];
            }

            LifeZones = new Dictionary<string, Life2DZone>();

            ResetSpawn();
        }
        public void HandleIdentityChange_does_not_update_collection_if_does_not_contain_specified_item()
        {
            var members = new List<EdmProperty>();
            var memberCount = MetadataCollection<EntityType>.UseDictionaryCrossover + 1;

            for (var i = 0; i < memberCount; i++)
            {
                members.Add(EdmProperty.CreatePrimitive("P" + i, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));
            }

            var collection = new MetadataCollection<EdmProperty>(members);
            Assert.Equal(memberCount, collection.Count);

            var property = EdmProperty.CreatePrimitive("MyProperty", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            property.Name = "MyNewProperty";
            collection.HandleIdentityChange(property, "MyProperty");

            Assert.Equal(memberCount, collection.Count);            
            Assert.False(collection.ContainsIdentity("MyProperty"));
            Assert.False(collection.ContainsIdentity("MyNewProperty"));

            property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            property.Name = "MyProperty";
            collection.HandleIdentityChange(property, "P2");

            Assert.Equal(memberCount, collection.Count);            
            Assert.False(collection.ContainsIdentity("MyProperty"));
            Assert.True(collection.ContainsIdentity("P2"));
            Assert.NotSame(property, collection.GetValue("P2", ignoreCase: false));
        }
Exemplo n.º 34
0
 protected DynamicSourceFile(SourceFile file, MetadataCollection persistedMetadata = null)
     : base(file.SourceRelativePath, persistedMetadata)
 {
     _sourceFile = file;
 }
Exemplo n.º 35
0
 public static IDictionary <string, string> ToMetadata(this MetadataCollection amzMeta)
 {
     return(amzMeta.Keys.ToDictionary(k => k.Replace("x-amz-meta-", string.Empty), k => amzMeta[k]));
 }