/// <summary> /// Adds a new meta collection. /// </summary> public MetaCollection <ushort> AddUInt16(string name) { var metaCollection = new MetaCollection <ushort>(BLOCK_SIZE); _collections[name] = metaCollection; return(metaCollection); }
/// <summary> /// Adds a new meta collection. /// </summary> public MetaCollection <int> AddInt32(string name) { var metaCollection = new MetaCollection <int>(BLOCK_SIZE); _collections[name] = metaCollection; return(metaCollection); }
/// <summary> /// Adds a new meta collection. /// </summary> public MetaCollection <ulong> AddUInt64(string name) { var metaCollection = new MetaCollection <ulong>(BLOCK_SIZE); _collections[name] = metaCollection; return(metaCollection); }
public void SerializeDeserialize() { var collection = new MetaCollection <int>(0); var size = 1024; for (uint i = 0; i < size; i++) { collection[i] = (int)(i * 2); } using (var stream = new MemoryStream()) { collection.Serialize(stream); stream.Seek(0, SeekOrigin.Begin); collection = MetaCollection.Deserialize(stream, null) as MetaCollection <int>; } for (uint i = 0; i < size; i++) { Assert.AreEqual(i * 2, collection[i]); } }
protected void CheckSkip <T>(IEnumerable <T> allList, IEnumerable <T> actualList, MetaCollection meta, int skip, int defaultLimit) { Assert.IsNotNull(actualList); CheckMeta(meta, skip, defaultLimit); var all = allList as IList <T> ?? allList.ToList(); var actual = actualList as IList <T> ?? actualList.ToList(); if (IsPerhapsNotAnExactMatch) { CheckCollectionNotAnExactMatch(all, actual, "Skip (NotAnExactMatch mode) failed, items are not equal"); } else { if (all.Count > skip) { Assert.IsTrue(actual.Any(), "Collection must not be empty"); } for (var i = 0; i < all.Count - skip; i++) { Assert.AreEqual(all[i + skip], actual[i], $"Skip failed, items (skip index={i}) are not equal"); } } }
/// <summary> /// Adds a new meta collection. /// </summary> public MetaCollection <float> AddSingle(string name) { var metaCollection = new MetaCollection <float>(BLOCK_SIZE); _collections[name] = metaCollection; return(metaCollection); }
/// <summary> /// Adds a new meta collection. /// </summary> public MetaCollection <double> AddDouble(string name) { var metaCollection = new MetaCollection <double>(BLOCK_SIZE); _collections[name] = metaCollection; return(metaCollection); }
public CommandHandlerContext(ICommand command, MetaCollection metadata) { Contract.Requires(command != null); Contract.Requires(metadata != null); Command = command; Metadata = metadata; }
public CommandHandlerContext(TCommand command, MetaCollection metadata) : base(command, metadata) { Contract.Requires(command != null); Contract.Requires(metadata != null); Command = command; }
public DomainEventHandlerContext(IDomainEvent domainEvent, MetaCollection metadata) { Contract.Requires(domainEvent != null); Contract.Requires(metadata != null); Metadata = metadata; DomainEvent = domainEvent; }
/// <summary> /// Intializes this target. /// </summary> public override void Initialize() { _firstPass = true; if (this.KeepNodeIds) { _nodeData = _db.VertexData.AddInt64("node_ids"); } }
private MetaCollection GetMetadata() { Contract.Ensures(Contract.Result <MetaCollection>() != null); var metadata = new MetaCollection(); _metaFactories.ForEach(x => metadata.Add(x.GetMeta())); return(metadata); }
public MetaCollection GetDefaultMetaData() { if (action == null) { return null; } var meta = new MetaCollection(); action.Invoke(meta); return meta; }
/// <summary> /// Get MetaBuilder for fluent adding meta tags /// </summary> /// <param name="html">HtmlHelper</param> /// <returns>MetaBuilder</returns> public static MetaBuilder Meta(this HtmlHelper html) { var collection = html.ViewData.Get <MetaCollection>(true); if (collection == null) { collection = new MetaCollection(); html.ViewData.Set(collection, true); } return(new MetaBuilder(collection)); }
public static void AddMeta(this IMeta target, MetaCollection meta) { if (meta == null) { return; } foreach (var item in meta) { target.AddMeta(item.Key, item.Value); } }
/// <summary> /// Tries to get an edge meta collection for the given key. /// </summary> public bool TryGet <T>(string name, out MetaCollection <T> metaCollection) where T : struct { MetaCollection collection; if (_collections.TryGetValue(name, out collection)) { metaCollection = (collection as MetaCollection <T>); return(metaCollection != null); } metaCollection = null; return(false); }
protected override void TransactionCommitted(EventProviderTransaction transaction) { // get domain events var domainEvents = transaction.GetDomainEvents(); // get metadata var metadata = new MetaCollection(transaction.Metadata); // create contexts var contexts = domainEvents.Select(x => new DomainEventHandlerContext(x, metadata)) .ToArray(); // public contexts _dispatcher.Publish(contexts); }
/// <summary> /// Initializes this target. /// </summary> public override void Initialize() { _firstPass = true; if (this.KeepNodeIds) { _nodeData = _db.VertexData.AddInt64(Itinero.IO.Osm.Constants.NODE_ID_META_NAME); } if (this.KeepWayIds) { _wayIds = _db.EdgeData.AddInt64(Itinero.IO.Osm.Constants.WAY_ID_META_NAME); _wayNodeIndices = _db.EdgeData.AddUInt16(Itinero.IO.Osm.Constants.WAY_NODE_IDX_META_NAME); } }
public void TestGetSet() { var collection = new MetaCollection <int>(0); var size = 1024; for (uint i = 0; i < size; i++) { collection[i] = (int)(i * 2); } for (uint i = 0; i < size; i++) { Assert.AreEqual(i * 2, collection[i]); } }
public void Save(MetaCollection list) { const string commandName = "dbo.SPSaveMeta"; ExecuteWithTransaction((transaction) => { foreach (MetaEntity meta in list) { DynamicParameters dynamicParameters = new DynamicParameters(); dynamicParameters.Add("categoryId", meta.CategoryId); dynamicParameters.Add("entityId", meta.EntityId); dynamicParameters.Add("entityType", (int)meta.EntityType); dynamicParameters.Add("metaValue", meta.MetaValueAsString); dynamicParameters.Add("valueType", (int)meta.ValueType); meta.DiscoverType(); meta.MetaId = transaction.Connection.Query <int?>(commandName, dynamicParameters, transaction: transaction, commandType: CommandType.StoredProcedure).FirstOrDefault(); } }); }
public static HtmlString RenderMeta(this HtmlHelper helper) { if (!(helper.ViewData.Model is IBaseVD)) { return(new HtmlString("")); } IBaseVD model = helper.ViewData.Model as IBaseVD; MetaCollection metaCollection = model.MetaCollection as MetaCollection; string result = null; foreach (var item in metaCollection) { if (!string.IsNullOrEmpty(item.Value)) { result += string.Format("<meta name=\"{0}\" content=\"{1}\" />\r\n", item.Key.ToString(), //helper.AttributeEncode(item.Value) //COCONET 此方法已失效 item.Value ); } } return(new HtmlString(result)); }
protected void CheckSkipAndLimit <T>(IEnumerable <T> allList, IEnumerable <T> actualList, MetaCollection meta, int skip, int limit) { Assert.IsNotNull(actualList); CheckMeta(meta, skip, limit); var all = allList as IList <T> ?? allList.ToList(); var actual = actualList as IList <T> ?? actualList.ToList(); if (IsPerhapsNotAnExactMatch) { CheckCollectionNotAnExactMatch(all, actual, "Skip and Limit (NotAnExactMatch mode) items aren not equal"); } else { Assert.AreEqual(Math.Min(all.Count - skip, limit), actual.Count, "Skip and Limit count failed"); for (var i = 0; i < actual.Count; i++) { Assert.AreEqual(all[i + skip], actual[i], $"Skip and Limit items aren not equal"); } } }
protected void CheckLimit <T>(IEnumerable <T> allList, IEnumerable <T> actualList, MetaCollection meta, int limit) { Assert.IsNotNull(actualList, $"'{nameof(actualList)}' must not be null"); CheckMeta(meta, limit); var all = allList as IList <T> ?? allList.ToList(); var actual = actualList as IList <T> ?? actualList.ToList(); Assert.AreEqual(Math.Min(all.Count, limit), actual.Count, $"Limit count is wrong"); if (IsPerhapsNotAnExactMatch) //if (!string.IsNullOrEmpty(SortingField)) { CheckCollectionNotAnExactMatch(all, actual, "Limit (NotAnExactMatch mode) failed, items are not equal"); } else { for (var i = 0; i < actual.Count; i++) { Assert.AreEqual(all[i], actual[i], $"Limit failed, items are not equal"); } } }
/// <summary> /// Deserializes a db. /// </summary> public static MetaCollectionDb Deserialize(Stream stream, ArrayProfile profile = null) { var version = stream.ReadByte(); if (version != 1) { if (version != 1) { throw new Exception(string.Format("Cannot deserialize meta-data db: Invalid version #: {0}, upgrade Itinero.", version)); } } var collections = new Dictionary <string, MetaCollection>(); var count = stream.ReadByte(); for (var i = 0; i < count; i++) { var name = stream.ReadWithSizeString(); var collection = MetaCollection.Deserialize(stream, profile); collections[name] = collection; } return(new MetaCollectionDb(collections)); }
public void TestCreate() { var collection = new MetaCollection <int>(1024); Assert.AreEqual(0, collection.Count); }
public IDomainEventHandlerContext <TDomainEvent> GetContext <TDomainEvent>(TDomainEvent domainEvent) where TDomainEvent : IDomainEvent { MetaCollection metadata = GetMetadata(); return(new DomainEventHandlerContext <TDomainEvent>(domainEvent, metadata)); }
/// <summary> /// Tries to get an edge meta collection for the given key. /// </summary> public bool TryGet(string name, out MetaCollection metaCollection) { return(_collections.TryGetValue(name, out metaCollection)); }
public ICommandHandlerContext GetContext(ICommand command) { MetaCollection metadata = GetMetadata(); return(new CommandHandlerContext(command, metadata)); }
public ICommandHandlerContext <TCommand> GetContext <TCommand>(TCommand command) where TCommand : ICommand { MetaCollection metadata = GetMetadata(); return(new CommandHandlerContext <TCommand>(command, metadata)); }
public void Populate(string baseUri, MetaCollection collection, IServiceProvider serviceProvider) { var foldersByType = new Dictionary <TypeInfo, MetaFolder>(); var foldersByGroupName = new Dictionary <string, List <MetaFolder> >(); // var rootVersion = _explorer.ApiDescriptionGroups.Version; var groupNames = _explorer.ApiDescriptionGroups.Items.Where(x => !string.IsNullOrWhiteSpace(x.GroupName)) .SelectMany(x => x.GroupName.Contains(",") ? x.GroupName.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) : new[] { x.GroupName }).Distinct().ToList(); var groupFolders = groupNames.Select(x => new MetaFolder { name = x, description = new MetaDescription { content = "", type = "", version = null }, variable = new List <dynamic>(), item = new List <MetaItem>(), @event = new List <dynamic>(), auth = null, protocolProfileBehavior = new { } }).ToDictionary(k => k.name, v => v); // // Map all folders: foreach (var descriptionGroup in _explorer.ApiDescriptionGroups.Items) { var groupName = descriptionGroup.GroupName; var orderedActions = descriptionGroup.Items.OrderBy(x => x.RelativePath).ThenBy(x => x.HttpMethod); foreach (var description in orderedActions) { var controllerDescriptor = (ControllerActionDescriptor)description.ActionDescriptor; var controllerTypeInfo = controllerDescriptor.ControllerTypeInfo; if (!ResolveControllerFeatureEnabled(controllerTypeInfo.AsType(), serviceProvider)) { continue; } var controllerName = ResolveControllerName(controllerTypeInfo); var item = CreateOperationMetaItem(baseUri, description, serviceProvider); if (!foldersByType.TryGetValue(controllerTypeInfo, out var folder)) { foldersByType.Add(controllerTypeInfo, folder = new MetaFolder { name = controllerName, description = new MetaDescription { content = ResolveControllerDescription(controllerTypeInfo)?.Content, type = ResolveControllerDescription(controllerTypeInfo)?.MediaType, version = null }, variable = new List <dynamic>(), item = new List <MetaItem>(), @event = new List <dynamic>(), auth = ResolveAuth(controllerDescriptor), protocolProfileBehavior = new { } }); } folder.item.Add(item); if (groupName == null) { continue; } var groups = groupName.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var group in groups) { if (!foldersByGroupName.TryGetValue(group, out var list)) { foldersByGroupName.Add(group, list = new List <MetaFolder>()); } if (list.Contains(folder)) { continue; } list.Add(folder); } } } // // Create folder hierarchy: var roots = new List <MetaFolder>(); var categories = new Dictionary <MetaCategoryAttribute, List <MetaFolder> >(); foreach (var folder in foldersByType) { var controllerType = folder.Key; var category = ResolveControllerCategory(controllerType); if (category != null) { if (!categories.TryGetValue(category, out var list)) { categories.Add(category, list = new List <MetaFolder>()); } // Does this folder belong to a group? var inGroup = false; foreach (var groupName in groupNames) { if (!foldersByGroupName[groupName].Contains(folder.Value)) { continue; } var groupFolder = groupFolders[groupName]; groupFolder.item.Add(folder.Value); if (!list.Contains(groupFolder)) { list.Add(groupFolder); } inGroup = true; break; } if (!inGroup) { list.Add(folder.Value); } } else { roots.Add(folder.Value); } } // // Add category folders: foreach (var entry in categories) { var category = entry.Key; var folderExists = collection.TryGetFolder(category.Name, out var categoryFolder); if (!folderExists) { categoryFolder = new MetaFolder { name = category.Name, description = new MetaDescription { content = category.Description, type = category.DescriptionMediaType, version = null }, variable = new List <dynamic>(), item = new List <MetaItem>(), @event = new List <dynamic>(), protocolProfileBehavior = new { } }; collection.item.Add(categoryFolder); } foreach (var subFolder in entry.Value.OrderBy(x => x.name)) { categoryFolder.item.Add(subFolder); } categoryFolder.auth = ResolveCategoryAuth(categoryFolder); } // // Add root level folders: foreach (var folder in roots.OrderBy(x => x.name)) { collection.item.Add(folder); } // // Change group name folder meta: foreach (var groupFolder in groupFolders) { var revisionName = groupFolder.Value.name; groupFolder.Value.name = $"Revision {revisionName}"; if (_versionProvider.Enabled) { foreach (var objectGroup in groupFolder.Value.item.OfType <MetaFolder>()) { foreach (var item in objectGroup.item) { item.request.url.query ??= (item.request.url.query = new List <MetaParameter>()); item.request.url.query.Add(new MetaParameter { key = _versionProvider.VersionParameter, value = revisionName, description = "Sets the version revision number for this API request." // MetaDescription.PlainText("Sets the version revision number for this API request.") }); } } } } }