public IEnumerator _1_Attack_Return_True_If_Exit_After_Attacking() { player = entityBuilder.Build(TypeOfEntity.Player, TypeOfWeapon.Empty).GetComponent <Player>(); yield return(new WaitForSeconds(0.5f)); bool target = player.Attack(); Assert.IsTrue(target); }
public IETCTollTransaction Submit(IETCTollTransaction transaction) { var builtTransaction = EntityBuilder.Build(transaction); if (builtTransaction != null) { try { var builtETCTransaction = ETCEntityBuilder.Build(transaction); var syncTransaction = Mapper.Map <ITollTransaction, Transaction>(builtTransaction); var syncETCTransaction = Mapper.Map <IETCTollTransaction, ETCTransaction>(builtETCTransaction); Sync.Client.SyncClient.SubmitETCTransaction(syncTransaction, syncETCTransaction , GetIAuthenticator(syncETCTransaction.IssuerAuthenticatorGuid) , GetOAuthenticator(syncETCTransaction.OperatorAuthenticatorGuid)); transaction.IsSent = true; return(builtTransaction); } catch (Exception ex) { Log.LogException(ex); Log.LogTrace(ex.Message + ". Check error log for more details."); } } return(transaction); }
public Entity Build(Post post) { var entityBuilder = new EntityBuilder() .WithClass("post") .WithProperty("linkFlairText", post.LinkFlairText) .WithTitle(post.Title) .WithProperty("score", post.Score) .WithProperty("domain", post.Domain) .WithProperty("subreddit", post.SubredditName) .WithProperty("submitted", post.CreatedUTC) .WithProperty("authorName", post.AuthorName) .WithProperty("comments", post.CommentCount) .WithProperty("selfText", post.SelfText); if (post.Thumbnail.OriginalString != string.Empty) { entityBuilder .WithProperty("url", post.Url); if (post.Thumbnail.OriginalString == "self" || post.Thumbnail.OriginalString == "nsfw" || post.Thumbnail.OriginalString == "default") { entityBuilder .WithProperty("thumbnail", "/" + post.Thumbnail); } else { entityBuilder .WithProperty("thumbnail", post.Thumbnail); } } BuildCommentTree(post, entityBuilder); return(entityBuilder.Build()); }
public ActionResult <IEnumerable <StarshipClass> > Get() { var baseUrl = GetBaseUrl(); using (var db = new LiteDatabase(@"ships.db")) { var col = db.GetCollection <StarshipClass>("ShipClass"); var classes = col.FindAll(); var sirenEntity = new EntityBuilder() .WithClass("starshipClass") .WithClass("collection") .WithProperty("classCount", classes.Count()) .WithLink(new LinkBuilder() .WithRel("self") .WithHref($"{baseUrl}/api/starshipclass")); foreach (var @class in classes) { sirenEntity.WithSubEntity(new EmbeddedLinkBuilder() .WithClass("starshipClass") .WithRel($"{baseUrl}/rels/starship-class") .WithHref($"{baseUrl}/api/starshipclass/{@class.Id}" )); } return(Ok(sirenEntity.Build())); } }
public virtual TEntity Get(long id) { var sql = string.Concat(QueryHelper.GetSelectAllQuery <TEntity>().Sql, " WHERE ", QueryHelper.GetKeyColumnName <TEntity>(), " = @id"); if (Logger.IsTraceEnabled) { Logger.Trace(sql); } using (var reader = Connection.ExecuteReader(sql, new { id }, Transaction)) { if (reader.Read()) { return(EntityBuilder.Build <TEntity>(reader)); } else { var exc = new EntityNotFoundException(); exc.Data["Kaia.Entity"] = typeof(TEntity).FullName; exc.Data["Kaia.Id"] = id; throw exc; } } }
public ActionResult <StarshipClass> Get(Guid id) { var baseUrl = GetBaseUrl(); using (var db = new LiteDatabase(@"ships.db")) { var col = db.GetCollection <StarshipClass>("ShipClass"); var @class = col.FindById(id); var sirenEntity = new EntityBuilder() .WithClass("starshipClass") .WithProperty("name", @class.Name) .WithLink(new LinkBuilder() .WithRel("self") .WithHref($"{baseUrl}/api/starshipclass/{id}")); foreach (var ship in @class.Ships) { sirenEntity.WithSubEntity(new EmbeddedLinkBuilder() .WithClass("starship") .WithRel($"{baseUrl}/rels/starship") .WithHref($"{baseUrl}/api/starshipclass/{@class.Id}/ships/{ship.Id}" )); } return(Ok(sirenEntity.Build())); } }
public ActionResult <Starship> GetStarship(Guid id, Guid shipId) { var baseUrl = GetBaseUrl(); using (var db = new LiteDatabase(@"ships.db")) { var col = db.GetCollection <StarshipClass>("ShipClass"); var @class = col.FindById(id); var ship = @class.Ships.Single(x => x.Id == shipId); var sirenEnity = new EntityBuilder() .WithClass("starship") .WithProperty("name", ship.Name) .WithProperty("registry", ship.Registry) .WithProperty("details", ship.Details) .WithLink(new LinkBuilder() .WithRel("self") .WithHref($"{baseUrl}/api/starshipclass/{@class.Id}/ships/{ship.Id}")) .WithAction(new ActionBuilder() .WithName("report-missing") .WithTitle("Report Missing") .WithHref($"{baseUrl}/api/starshipclass/{@class.Id}/ships/{ship.Id}/reportmissing") .WithType("application/json") .WithMethod("POST") .WithField(new FieldBuilder() .WithName("report") .WithType("text"))); return(Ok(sirenEnity.Build())); } }
//buffer private void DataReceived(IList <DataRecord> dataRecords) { ConcurrentDictionary <EntityKey, Entity> buffer = new ConcurrentDictionary <EntityKey, Entity>(); for (int i = 0; i < dataRecords.Count; i++) { var key = String.Intern(dataRecords[i].DataRecordKey); var name = String.Intern(dataRecords[i].PropertyName); var value = dataRecords[i].PropertyValue; Entity entity; bool isNew = !_entityIndex.TryGetValue(EntityBuilder.Fnv1Hash(key), out entity); // add if (isNew) { entity = EntityBuilder.Build <Entity>(key, KeyType.Isin); _entityIndex.TryAdd(entity.Key.HashedValue, entity); } // update entity.Values.AddOrUpdate(name, new EntityItem(value), (n, oldValue) => new EntityItem(value, oldValue.Value)); buffer.AddOrUpdate(entity.Key, entity, (n, oldValue) => entity); } _eventExploder(buffer.Values); }
public EntityInternal Clone(string name, EntityInternal entity, EntityBuilder entityBuilder) { entityBuilder.SetName(name); if (entity.TemplateAccessor.IsPresent()) { TemplateAccessor accessor = entity.TemplateAccessor.Get(); if (accessor != null) { TemplateDescription templateDescription = accessor.TemplateDescription; entityBuilder.SetTemplate(templateDescription.TemplateClass); if (accessor.HasConfigPath()) { entityBuilder.SetConfig(accessor.ConfigPath); } else { YamlNode yamlNode = accessor.YamlNode; if (yamlNode != null) { entityBuilder.SetTemplateYamlNode(yamlNode); } } } } EntityInternal internal2 = entityBuilder.Build(true); foreach (Type type in entity.ComponentClasses) { if (!ReferenceEquals(type, this.newEntityComponentType)) { internal2.AddComponent(entity.GetComponent(type)); } } return(internal2); }
static void Test11() { var xmlFile = Path.Combine(Directory.GetCurrentDirectory(), "../X/XCode/Model.xml"); var output = Path.Combine(Directory.GetCurrentDirectory(), "../"); EntityBuilder.Build(xmlFile, output); }
private Entity <Model> NewModelEntity(Action <EntityBuilder <Model> > setUp = null) { EntityBuilder <Model> entityBuilder = new EntityBuilder <Model>(); setUp?.Invoke(entityBuilder); return(entityBuilder.Build()); }
internal void BuildConfiguration() { var entityBuilder = new EntityBuilder <TEntity>(); Configure(entityBuilder); entityBuilder.Build(); }
public void ThrowWhenKeyDuplicateProperty() { var sut = new EntityBuilder() .Name("Test") .Source(NullDataSource.Instance) .Id("Id", TypeSystem.Integer) .AddProperty("Id", TypeSystem.Integer); Assert.Throws <DuplicatePropertiesException>(() => sut.Build()); }
public void ShouldReturnEmptyListWhenNotSeeded() { // Arrange var builder = new EntityBuilder <IHasCustomerId>(null, null); // Act var result = builder.Build(); // Assert Assert.AreEqual(0, result.Count()); }
public Entity Build(Subreddit subreddit) { var entityBuilder = new EntityBuilder() .WithClass("root") .WithClass("subreddit"); BuildListings(entityBuilder, subreddit); BuildPagination(entityBuilder); BuildPosts(subreddit, entityBuilder); return(entityBuilder.Build()); }
protected override void VisitInsert(InsertBuilder item) { GuardInsertBuilder(item); item.Table.Source.Accept(this); Columns = item.Columns.ToArray(); item.Values.Accept(this); Columns = null; CurrentRequest.Target = EntityBuilder.Build(); EntityBuilder = null; OutputColumns = item.Output.ToArray(); UpgradeToExecuteMultipleIfNecessary(); }
/// <summary> /// Find user login by login information and user id. /// </summary> /// <param name="userId">Target user.</param> /// <param name="loginInfo">User login information.</param> /// <returns>Returns the user login if found; otherwise, returns null.</returns> public TUserLogin Find(TKey userId, UserLoginInfo loginInfo) { PropertyConfiguration loginProviderPropCfg = Configuration.Property(p => p.LoginProvider); PropertyConfiguration providerKeyPropCfg = Configuration.Property(p => p.ProviderKey); PropertyConfiguration userIdPropCfg = Configuration.Property(p => p.UserId); DbCommand command = StorageContext.CreateCommand(); command.CommandText = String.Format( @"SELECT * FROM {0} WHERE {1} = @{4} AND {2} = @{5} AND {3} = @{6};", QueryBuilder.GetQuotedIdentifier(Configuration.TableName), // Configured field names QueryBuilder.GetQuotedIdentifier(loginProviderPropCfg.ColumnName), QueryBuilder.GetQuotedIdentifier(providerKeyPropCfg.ColumnName), QueryBuilder.GetQuotedIdentifier(userIdPropCfg.ColumnName), // Parameter names loginProviderPropCfg.PropertyName, providerKeyPropCfg.PropertyName, userIdPropCfg.PropertyName); DbCommandContext cmdContext = new DbCommandContext(command); cmdContext.Parameters[loginProviderPropCfg.PropertyName].Value = loginInfo.LoginProvider; cmdContext.Parameters[providerKeyPropCfg.PropertyName].Value = loginInfo.ProviderKey; cmdContext.Parameters[userIdPropCfg.PropertyName].Value = userId; DbDataReader reader = null; TUserLogin userLogin = default(TUserLogin); StorageContext.Open(); try { reader = cmdContext.ExecuteReader(); userLogin = EntityBuilder.Build(reader); } catch (Exception) { throw; } finally { if (reader != null) { reader.Close(); } cmdContext.Dispose(); StorageContext.Close(); } return(userLogin); }
public void CanCloneBuilder() { var expected = new EntityBuilder() .Name("Test") .Source(NullDataSource.Instance) .Id("Id", TypeSystem.Integer) .AddProperty("Name", TypeSystem.String) .Alias("Alias") .Version("Version") .PropertyNameComparer(StringComparer.CurrentCulture); var actual = EntityBuilder.FromEntity(expected); Assert.Equal(expected.Build(), actual.Build(), EntityContextComparer.Instance); }
protected override void VisitUpdate(UpdateBuilder item) { GuardUpdateBuilder(item); item.Table.Source.Accept(this); int whereCount = 0; CurrentUpdateStatementPart = UpdateStatementPart.WhereClause; foreach (IVisitableBuilder where in item.Where) { where.Accept(this); whereCount++; } // IsVisitingWhereFilter = false; if (whereCount != 1) { throw new ArgumentException("The update statement should have a single filter in the where clause, which should specify the entity id of the record to be updated."); } if (EqualToFilter == null) { throw new NotSupportedException("The update statement has an unsupported filter in it's where clause. The where clause should contain a single 'equal to' filter that specifies the entity id of the particular record to update."); } if (IdFilterColumn == null) { throw new NotSupportedException("The update statement has an unsupported filter in it's where clause. The'equal to' filter should specify the entity id column on one side."); } var idAttName = GetColumnLogicalAttributeName(IdFilterColumn); var expectedIdAttributeName = string.Format("{0}id", EntityName.ToLower()); if (idAttName != expectedIdAttributeName) { throw new NotSupportedException("The update statement has an unsupported filter in it's where clause. The'equal to' filter should specify the id column of the entity on one side."); } EntityBuilder.WithAttribute(idAttName).SetValueWithTypeCoersion(IdFilterValue); CurrentUpdateStatementPart = UpdateStatementPart.Setter; foreach (IVisitableBuilder setter in item.Setters) { setter.Accept(this); } CurrentRequest.Target = EntityBuilder.Build(); EntityBuilder = null; CurrentUpdateStatementPart = UpdateStatementPart.OutputClause; OutputColumns = item.Output.ToArray(); UpgradeToExecuteMultipleIfNecessary(); }
public void ComponentValue() { var entityManager = new EntityManager(); var entityTemplate = new EntityBuilder( new ComponentValue <StructComponent>(new StructComponent(10)), new ComponentValue <Struct2Component>(new Struct2Component(20))); var entity = entityTemplate.Build(entityManager); Assert.IsTrue(entityManager.IsExists(entity.Entity)); Assert.IsTrue(entity.HasComponent <StructComponent>()); Assert.IsTrue(entity.HasComponent <Struct2Component>()); Assert.AreEqual(10, entity.GetComponent <StructComponent>().Value); Assert.AreEqual(20, entity.GetComponent <Struct2Component>().Value); }
public void it_does_not_share_references() { _builder .WithClass("class") .WithProperty("key", "value") .WithSubEntity(new EmbeddedRepresentationBuilder().WithRel("rel")) .WithLink(new LinkBuilder().WithRel("rel").WithHref("href")) .WithAction(new ActionBuilder().WithName("name").WithHref("href")); var entity1 = _builder.Build(); var entity2 = _builder.Build(); Assert.That(entity1, Is.Not.SameAs(entity2)); Assert.That(entity1.Class, Is.Not.SameAs(entity2.Class)); Assert.That(entity1.Properties, Is.Not.SameAs(entity2.Properties)); Assert.That(entity1.Links, Is.Not.SameAs(entity2.Links)); Assert.That(entity1.Actions, Is.Not.SameAs(entity2.Actions)); }
public virtual IEnumerable <TEntity> GetAll() { var query = QueryHelper.GetSelectAllQuery <TEntity>(); if (Logger.IsTraceEnabled) { Logger.Trace(query); } using (var reader = Connection.ExecuteReader(query.Sql, null, Transaction)) { while (reader.Read()) { yield return(EntityBuilder.Build <TEntity>(reader)); } } }
public virtual IEnumerable <TEntity> Get(IEnumerable <long> ids) { var query = QueryHelper.GetSelectManyQuery <TEntity>(ids); if (Logger.IsTraceEnabled) { Logger.Trace(query.Sql); } using (var reader = Connection.ExecuteReader(query.Sql, query.Parameters, Transaction)) { while (reader.Read()) { yield return(EntityBuilder.Build <TEntity>(reader)); } } }
/// <summary> /// Find user by id. /// </summary> /// <param name="email">Target user email.</param> /// <returns>Returns the user if found; otherwise, returns null.</returns> public TUser FindByEmail(string email) { PropertyConfiguration emailPropCfg = Configuration.Property(p => p.Email); DbCommand command = StorageContext.CreateCommand(); command.CommandText = String.Format( @"SELECT * FROM {0} WHERE LOWER({1}) = LOWER(@{2});", QueryBuilder.GetQuotedIdentifier(Configuration.TableName), // Configured field names QueryBuilder.GetQuotedIdentifier(emailPropCfg.ColumnName), // Parameter names emailPropCfg.PropertyName); DbCommandContext cmdContext = new DbCommandContext(command); cmdContext.Parameters[emailPropCfg.PropertyName].Value = email; DbDataReader reader = null; TUser user = default(TUser); StorageContext.Open(); try { reader = cmdContext.ExecuteReader(); user = EntityBuilder.Build(reader); } catch (Exception) { throw; } finally { if (reader != null) { reader.Close(); } cmdContext.Dispose(); StorageContext.Close(); } return(user); }
/// <summary> /// Find role by id. /// </summary> /// <param name="id">Target role id.</param> /// <returns>Returns the role if found; otherwise, returns null.</returns> public TRole FindById(TKey id) { PropertyConfiguration idPropCfg = Configuration.Property(p => p.Id); DbCommand command = StorageContext.CreateCommand(); command.CommandText = String.Format( @"SELECT * FROM {0} WHERE {1} = @{2};", QueryBuilder.GetQuotedIdentifier(Configuration.TableName), // Configured field names QueryBuilder.GetQuotedIdentifier(idPropCfg.ColumnName), // Parameter names idPropCfg.PropertyName); DbCommandContext cmdContext = new DbCommandContext(command); cmdContext.Parameters[idPropCfg.PropertyName].Value = id; DbDataReader reader = null; TRole role = default(TRole); StorageContext.Open(); try { reader = cmdContext.ExecuteReader(); role = EntityBuilder.Build(reader); } catch (Exception) { throw; } finally { if (reader != null) { reader.Close(); } cmdContext.Dispose(); StorageContext.Close(); } return(role); }
private static async Task BuildModelsAsync(string input, string DestinationPath) { if (string.IsNullOrEmpty(input)) { return; } XDocument xDoc = XDocument.Parse(input); var nSpace = from c in xDoc.Descendants() where c.Name.LocalName == "Schema" select c.Attribute("Namespace").Value; //Create Directory string dir = DestinationPath; DirectoryInfo dirInfo = Directory.CreateDirectory(dir); var associations = (from ent in xDoc.Descendants() where ent.Name.LocalName == "Association" select ent).ToList(); var entities = from ent in xDoc.Descendants() where ent.Name.LocalName == "EntityType" select ent; foreach (XElement entity in entities) { IEnumerable <XElement> keys = from key in entities.Descendants() where key.Name.LocalName == "PropertyRef" select key; EntityBuilder eb = Factory.Create <EntityBuilder>(); BaseModel bm = eb.Build(nSpace.FirstOrDefault(), entity, keys, associations);; string fullPath = $"{dir}\\{bm.Class.Name}.cs"; await CreateSourceFile(fullPath, bm.ToString()).ConfigureAwait(false); } }
/// <summary>测试序列化</summary> private static void Test12() { EntityBuilder.Build("../../Src/XCode/model.xml"); }
public void ThrowsOnEntityWithoutName() { var sut = new EntityBuilder(); Assert.Throws <EntityConfigurationException>(() => sut.Build()); }
public Entity Build(IEnumerable <Thing> things) { var previousPage = _count == null || _count <= 0 ? null : _count < 25 ? 0 : _count - 25; var nextPage = _count + 25; var entityBuilder = new EntityBuilder() .WithClass("search") .WithAction(new ActionBuilder() .WithName("search") .WithTitle("Search") .WithMethod("GET") .WithHref("/search") .WithField(new FieldBuilder() .WithName("q") .WithType("text") .WithValue(_query))); if (_onlySubreddit) { entityBuilder .WithLink(new LinkBuilder() .WithClass("pagination") .WithRel("next") .WithRel("subreddit") .WithHref($"?q={_query}&type=subreddit&count={nextPage}") .WithTitle("next")); if (previousPage != null) { entityBuilder .WithLink(new LinkBuilder() .WithClass("pagination") .WithRel("previous") .WithRel("subreddit") .WithHref($"?q={_query}&type=subreddit&count={previousPage}") .WithTitle("previous")); } } else if (_onlyPost) { entityBuilder .WithLink(new LinkBuilder() .WithClass("pagination") .WithRel("next") .WithRel("post") .WithHref($"?q={_query}&type=post&count={nextPage}") .WithTitle("next")); if (previousPage != null) { entityBuilder .WithLink(new LinkBuilder() .WithClass("pagination") .WithRel("previous") .WithRel("post") .WithHref($"?q={_query}&type=post&count={previousPage}") .WithTitle("previous")); } } else { entityBuilder .WithLink(new LinkBuilder() .WithClass("pagination") .WithRel("next") .WithRel("subreddit") .WithHref($"?q={_query}&type=subreddit&count=3") .WithTitle("next")) .WithLink(new LinkBuilder() .WithClass("pagination") .WithRel("next") .WithRel("post") .WithHref($"?q={_query}&type=post&count=22") .WithTitle("next")); } foreach (var thing in things) { var subreddit = thing as Subreddit; if (subreddit != null) { entityBuilder .WithSubEntity(Build(subreddit)); } var post = thing as Post; if (post != null) { entityBuilder .WithSubEntity(Build(post)); } } return(entityBuilder .Build()); }
public void ThrowsOnEntityWithoutSource() { var sut = new EntityBuilder().Name("Test"); Assert.Throws <DataSourceNotDefinedException>(() => sut.Build()); }