internal bool AddEntity(Type type, IEntityObject entity) { if (!entityObjectType.IsAssignableFrom(type)) { throw new TypeAccessException("EntityManager : type is not sub class of EntityObject ! Type : " + type.ToString()); } bool result = false; if (!entityTypeObjectDict.ContainsKey(type)) { entityTypeObjectDict.Add(type, new List <IEntityObject>() { entity }); result = true; } else { var set = entityTypeObjectDict[type]; if (!set.Contains(entity)) { set.Add(entity); result = true; } } return(result); }
public IEntityObject GetModel(IEntityObject model, EntitySelectQuery selectQuery) { switch (model.Type) { case ObjectType.User: return(EntityWrapper.GetModel(model as User, selectQuery)); case ObjectType.Client: return(EntityWrapper.GetModel(model as Client, selectQuery)); case ObjectType.Machine: return(EntityWrapper.GetModel(model as Machine, selectQuery)); case ObjectType.MachineType: return(EntityWrapper.GetModel(model as MachineType, selectQuery)); case ObjectType.Order: return(EntityWrapper.GetModel(model as Order, selectQuery)); case ObjectType.RepairType: return(EntityWrapper.GetModel(model as RepairType, selectQuery)); default: return(null); } }
public static string GetValue(this IEntityObject Entity, string FieldName) { string sValue = ""; try { if ((Entity.Details.Properties[FieldName].Value != null)) { if (Entity.Details.Properties[FieldName].PropertyType.ToString() == "System.Byte[]") { sValue = "(Image)"; } else if (Entity.Details.Properties[FieldName].PropertyType.ToString().StartsWith("Microsoft.LightSwitch.Framework.EntityCollection")) { sValue = "(Collection)"; } else { sValue = Entity.Details.Properties[FieldName].Value.ToString(); } } } catch { } return(sValue); }
public IEntityObject GetModels(IEntityObject model) { switch (model.Type) { case ObjectType.User: return(EntityWrapper.GetModels(model as User)); case ObjectType.Client: return(EntityWrapper.GetModels(model as Client)); case ObjectType.Machine: return(EntityWrapper.GetModels(model as Machine)); case ObjectType.MachineType: return(EntityWrapper.GetModels(model as MachineType)); case ObjectType.Order: return(EntityWrapper.GetModels(model as Order)); case ObjectType.RepairType: return(EntityWrapper.GetModels(model as RepairType)); default: return(null); } }
public void SaveModel(IEntityObject model) { switch (model.Type) { case ObjectType.User: EntityWrapper.SaveObject(model as User); break; case ObjectType.Client: EntityWrapper.SaveObject(model as Client); break; case ObjectType.Machine: EntityWrapper.SaveObject(model as Machine); break; case ObjectType.MachineType: EntityWrapper.SaveObject(model as MachineType); break; case ObjectType.Order: EntityWrapper.SaveObject(model as Order); break; case ObjectType.RepairType: EntityWrapper.SaveObject(model as RepairType); break; default: break; } }
/// <summary> /// 将实体对象更新到数据库,调用该方法时实体对象必须具备主键属性 /// </summary> /// <param name="object">实体对象</param> public virtual int Update(object @object) { IEntityObject entity = (IEntityObject)@object; Type elementType = @object.GetType().BaseType; IUpdateable updateable = this.factory.CreateUpdateProvider(this).CreateUpdate(elementType); var properties = @object.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); properties.Each(property => { if (property.IsPrimaryKey() == false) { if (entity.ChangedProperties.Contains(property.Name)) { ParameterExpression pe = Expression.Parameter(@object.GetType(), "s"); MemberExpression me = Expression.MakeMemberAccess(pe, property); updateable.Set(me, property.EmitGetValue(@object)); } } else { ParameterExpression pe = Expression.Parameter(@object.GetType(), "s"); MemberExpression me = Expression.MakeMemberAccess(pe, property); ConstantExpression ce = Expression.Constant(property.EmitGetValue(@object), property.PropertyType); BinaryExpression be = Expression.Equal(me, ce); updateable = updateable.Where(be); } }); return(updateable.Execute(elementType)); }
/// <summary> /// Adds an object to the response collection. /// </summary> /// <param name="thing">The thing thats needs to be added.</param> /// <param name="cullValues"> /// The boolean indicating whether to cull Values. /// </param> public void AddToResponse(IEntityObject thing, bool cullValues = true) { if (cullValues) { ApiHelper.CullApiNullValues(thing); } var type = thing.GetType(); List <object> collection; // try to get the collection if it exists already if (this.TryGetValue(type.Name, out collection)) { // skip object if it is already in if (!collection.Contains(thing)) { collection.Add(thing); } } else { this.Add(type.Name, new List <object> { thing }); } }
/// <summary> /// Removes an entityObject from the lookup cache. /// It will be re-added the next time it is looked up with <seealso cref="GetSpatialOsEntity" />. /// </summary> public static void RemoveFromLookupCache(IEntityObject entityObject) { if (entityObject == null) { return; } List <GameObject> objectsToRemove; if (!EntityObjectToGameObjectCache.TryGetValue(entityObject, out objectsToRemove)) { return; } for (int index = 0; index < objectsToRemove.Count; index++) { var invalidObject = objectsToRemove[index]; if (invalidObject != null) { GameObjectToEntityObjectCache.Remove(invalidObject); } } EntityObjectToGameObjectCache.Remove(entityObject); }
public static void ServerEventOccured(string action, IEntityObject entity, IDataService dataService) { GuardMultiTenantEvents(action, entity, dataService); foreach (var handler in serverEventHandlers) { handler.ServerEventOccured(action, entity, dataService); } }
public int Insert(object @object) { IEntityObject entity = (IEntityObject)@object; string tableName = @object.GetType().BaseType.Name; IList <string> columns = new List <string>(); IList <object> parameters = new List <object>(); PropertyInfo[] properties = @object.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { // 忽略自增字段 if (Attribute.GetCustomAttributes(property, typeof(AutoIncreaseAttribute), true).Length > 0) { continue; } if (entity.ChangedProperties.Contains(property.Name)) { columns.Add(string.Format("{0}{1}{2}", Constants.LeftQuote, property.Name, Constants.RightQuote)); object value = property.EmitGetValue(@object); value = value == null ? DBNull.Value : value; parameters.Add(value); } } StringBuilder builder = new StringBuilder(); builder.Append("INSERT INTO "); builder.AppendFormat("{0}{1}{2} ", Constants.LeftQuote, tableName, Constants.RightQuote); builder.Append("( "); builder.Append(string.Join(", ", columns)); builder.Append(" ) VALUES ( "); for (int i = 0; i < parameters.Count; i++) { if (i == 0) { builder.Append("?"); } else { builder.Append(", ?"); } } builder.Append(" );"); SqlCmd command = new SqlCmd(builder.ToString(), parameters); SqlCmd.Current = command; return(this.ExecuteNonQuery(command.Sql, command.Parameters)); }
/// <summary> /// 复制值 /// </summary> /// <param name="source">复制的源字段</param> public void CopyValue(IEntityObject source) { var entity = source as EntityObjectBase; if (entity != null) { CopyValueInner(entity); } }
public void DeleteForeignKeyConstraint( PropertyInfo fromProperty, IEntityObject fromThing, PropertyInfo toProperty, IEntityObject toThing, object transaction = null) { return; }
public void AddEntity() { IEntityObject result = null; _window.DisplayName = string.Format("Add {0}", _entityName); _collection.AddNew(); OpenModalWindow(); }
/// <summary> /// Culls the API <see langword="null"/> values. /// </summary> /// <param name="resp">The response object.</param> public static void CullApiNullValues(IEntityObject resp) { var properties = resp.GetType().GetProperties().Where(p => p.IsDefined(typeof(ApiSerializeNullAttribute))); foreach (var property in properties) { property.SetValue(resp, null); } }
public void Initialize(IEntityObject entityObject, ISpatialCommunicator spatialCommunicator) { if (spatialCommunicator == null) { throw new ArgumentNullException("spatialCommunicator"); } Entity = entityObject; InitializeComponents(entityObject, spatialCommunicator); }
public void DeleteTable(IEntityObject thing, object transaction = null) { // should delete instances of type of that table. var instances = this.Cache.Where(kv => kv.Value.GetType() == thing.GetType()); foreach (var instance in instances) { this.Cache.Remove(instance.Key); } }
public void EnableEntity(IEntityObject entity) { if (m_allEntityObjects.TryGetValue(entity.EntityID, out IEntityObject entityObject)) { } //if (!m_allEntityObjects.ContainsKey(entity)) { // m_allEntityObjects.Add(entity, entity.EntityID); //} }
public int Update(object @object) { IEntityObject entity = (IEntityObject)@object; string tableName = @object.GetType().BaseType.Name; IList <string> keys = new List <string>(); IList <string> columns = new List <string>(); IList <object> parameters = new List <object>(); var properties = @object.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // 需更新的字段 properties.Where(property => Attribute.GetCustomAttributes(property, typeof(PrimaryKeyAttribute), true).Length == 0).Each(property => { if (@entity.ChangedProperties.Contains(property.Name)) { columns.Add(string.Format("{0}{1}{2} = ?", Constants.LeftQuote, property.Name, Constants.RightQuote)); object value = property.EmitGetValue(@object); value = value == null ? DBNull.Value : value; parameters.Add(value); } }); // 主键字段 properties.Where(property => Attribute.GetCustomAttributes(property, typeof(PrimaryKeyAttribute), true).Length > 0).Each(property => { keys.Add(string.Format("{0}{1}{2} = ?", Constants.LeftQuote, property.Name, Constants.RightQuote, Constants.ParameterPrefix)); object value = property.EmitGetValue(@object); value = value == null ? DBNull.Value : value; parameters.Add(value); }); StringBuilder builder = new StringBuilder(); builder.Append("UPDATE "); builder.AppendFormat("{0}{1}{2} ", Constants.LeftQuote, tableName, Constants.RightQuote); builder.Append("SET "); builder.Append(string.Join(", ", columns)); builder.Append(" WHERE "); builder.Append(string.Join(" AND ", keys)); builder.Append(";"); SqlCmd command = new SqlCmd(builder.ToString(), parameters); SqlCmd.Current = command; return(this.ExecuteNonQuery(command.Sql, command.Parameters)); }
public void CreateForeignKeyConstraint( PropertyInfo fromProperty, IEntityObject fromThing, PropertyInfo toProperty, IEntityObject toThing, FkDeleteBehaviorKind onDelete = FkDeleteBehaviorKind.NO_ACTION, bool deferred = true, object transaction = null) { return; }
/// <summary> /// Adds an entity object to the collection /// </summary> /// <param name="toAdd"></param> internal void InternalAdd(IEntityObject toAdd) { if (!(toAdd is BrightstarEntityObject)) { throw new ArgumentException(String.Format(Strings.InvalidEntityType, typeof(BrightstarEntityObject).FullName), "toAdd"); } if (IsLoaded) { RemoveFromLoadedObjects((toAdd as BrightstarEntityObject).DataObject.Identity); } }
private static void AddToReverseLookup(GameObject gameObject, IEntityObject entityObject) { List <GameObject> gameObjects; if (!EntityObjectToGameObjectCache.TryGetValue(entityObject, out gameObjects)) { gameObjects = new List <GameObject>(); EntityObjectToGameObjectCache[entityObject] = gameObjects; } gameObjects.Add(gameObject); }
public static dynamic GenerateDocument(string Template, IEntityObject Item, List <ColumnMapping> ColumnMappings) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); wordProxy.CreateWord(); wordProxy.OpenDocument(Template); PopulateContentControls(ColumnMappings, Item, wordProxy); doc = wordProxy.Document; wordProxy.ShowDocument(); return(doc); }
/// <summary> /// This is an implementation detail; it should not be called by user code. /// </summary> public virtual bool Init(ISpatialCommunicator communicator, IEntityObject entityObject) { if (this.communicator != null) { return(false); } this.communicator = communicator; this.entityObject = entityObject; this.entityId = entityObject.EntityId; entityObject.Components.RegisterInterestedComponent(ComponentId, this); return(true); }
private void DestroyEntity(IEntityObject entity) { var disposable = entity as IDisposable; if (disposable != null) { disposable.Dispose(); } entityComponentInterestOverridesUpdater.RemoveEntity(entity); universe.Remove(entity.EntityId); prefabFactory.DespawnComponent(entity.UnderlyingGameObject, entity.PrefabName); }
/// <summary> /// Removes an entity object from the collection /// </summary> /// <param name="toRemove"></param> internal void InternalRemove(IEntityObject toRemove) { if (!typeof(T).IsAssignableFrom(toRemove.GetType())) { throw new ArgumentException(String.Format(Strings.InvalidEntityType, typeof(T).FullName), "toRemove"); } if (IsLoaded) { var entityToRemove = toRemove as BrightstarEntityObject; if (entityToRemove != null) { RemoveFromLoadedObjects(entityToRemove.DataObject.Identity); } } }
public void AddEntity(IEntityObject entity) { if (entity == null) { Debug.LogError("Storing a null EntityObject"); return; } if (entities.Contains(entity)) { Debug.LogErrorFormat("Trying to store a duplicate with EntityId {0} for object {1}", entity.EntityId, entity.UnderlyingGameObject.name); return; } entities.Add(entity); }
private void InitializeComponents(IEntityObject entityObject, ISpatialCommunicator spatialCommunicator) { // N.B. this one works with interfaces, GetComponents<> doesn't. var spatialOsComponents = GetComponents(typeof(ISpatialOsComponentInternal)); for (var i = 0; i < spatialOsComponents.Length; i++) { var spatialOsComponent = spatialOsComponents[i] as ISpatialOsComponentInternal; if (spatialOsComponent == null) { continue; } spatialOsComponent.Init(spatialCommunicator, entityObject); } }
public void DeleteRecord(IEntityObject thing, object transaction = null) { var uuid = thing.GetType().GetProperty(thing.PrimaryKey).GetValue(thing) as Guid?; this.Cache.Remove((Guid)uuid); this.ThingCache.Remove((Guid)uuid); var deletedThing = new DeletedThing() { Uuid = (Guid)uuid, ModifiedOn = DateTime.UtcNow }; this.DeletedThingCache.Add((Guid)uuid, deletedThing); return; }
private void BaseOpenDialog() { _entity = (IEntityObject)_collection.SelectedItem; if (_entity != null) { Dispatchers.Main.Invoke(() => { ((IEditableObject)_entity.Details).EndEdit(); ((IEditableObject)_entity.Details).BeginEdit(); }); _screen.OpenModalWindow(_dialogName); } }
netDxf.Entities.Polyline CastPolyline(IEntityObject item) //IPolyline item) { netDxf.Entities.Polyline polyline = null; //if (item is LightWeightPolyline) //{ // polyline = ((LightWeightPolyline)item).ToPolyline(); //} //else if (item is Polyline) { polyline = (netDxf.Entities.Polyline)item; } else { polyline = null; } return(polyline); }
//IPolyline item) netDxf.Entities.Polyline CastPolyline(IEntityObject item) { netDxf.Entities.Polyline polyline = null; //if (item is LightWeightPolyline) //{ // polyline = ((LightWeightPolyline)item).ToPolyline(); //} //else if (item is Polyline) { polyline = (netDxf.Entities.Polyline)item; } else { polyline = null; } return polyline; }
private void OpenModalWindow() { _entity = _collection.SelectedItem as IEntityObject; _screen.OpenModalWindow(_dialogName); }
private static void PopulateContentControls(List<ColumnMapping> columnMappings, IEntityObject item, WordHelper wordProxy) { foreach (ColumnMapping mapping in columnMappings) { if (mapping.TableField != null && mapping.TableField.Name != "<Ignore>") { string value = item.Details.Properties[mapping.TableField.Name].Value.ToString(); wordProxy.SetContentControl(mapping.OfficeColumn, value); } } }
public static dynamic GenerateDocument(string Template, IEntityObject Item, List<ColumnMapping> ColumnMappings) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); wordProxy.CreateWord(); wordProxy.OpenDocument(Template); PopulateContentControls(ColumnMappings, Item, wordProxy); doc = wordProxy.Document; wordProxy.ShowDocument(); return doc; }
public static void SetCurrentParentEntity(IEntityObject entity) { currentParentEntity = entity; }
/// <summary> /// Adds a new <see cref="IEntityObject">entity</see> to the document. /// </summary> /// <param name="entity">An <see cref="IEntityObject">entity</see></param> public void AddEntity(IEntityObject entity) { // check if the entity has not been added to the document if (this.addedObjects.ContainsKey(entity)) throw new ArgumentException("The entity " + entity.Type + " object has already been added to the document.", "entity"); this.addedObjects.Add(entity, entity); if (entity.XData != null) { foreach (ApplicationRegistry appReg in entity.XData.Keys) { if (!this.appRegisterNames.ContainsKey(appReg.Name)) { this.appRegisterNames.Add(appReg.Name, appReg); } } } if (!this.layers.ContainsKey(entity.Layer.Name)) { if (!this.lineTypes.ContainsKey(entity.Layer.LineType.Name)) { this.lineTypes.Add(entity.Layer.LineType.Name, entity.Layer.LineType); } this.layers.Add(entity.Layer.Name, entity.Layer); } if (!this.lineTypes.ContainsKey(entity.LineType.Name)) { this.lineTypes.Add(entity.LineType.Name, entity.LineType); } switch (entity.Type) { case EntityType.Arc: this.arcs.Add((Arc) entity); break; case EntityType.Circle: this.circles.Add((Circle) entity); break; case EntityType.Ellipse: this.ellipses.Add((Ellipse) entity); break; case EntityType.NurbsCurve: throw new NotImplementedException("Nurbs curves not avaliable at the moment."); this.nurbsCurves.Add((NurbsCurve) entity); break; case EntityType.Point: this.points.Add((Point) entity); break; case EntityType.Face3D: this.faces3d.Add((Face3d) entity); break; case EntityType.Solid: this.solids.Add((Solid) entity); break; case EntityType.Insert: // if the block definition has already been added, we do not need to do anything else if (!this.blocks.ContainsKey(((Insert) entity).Block.Name)) { this.blocks.Add(((Insert) entity).Block.Name, ((Insert) entity).Block); if (!this.layers.ContainsKey(((Insert)entity).Block.Layer.Name)) { this.layers.Add(((Insert)entity).Block.Layer.Name, ((Insert)entity).Block.Layer); } //for new block definitions configure its entities foreach (IEntityObject blockEntity in ((Insert) entity).Block.Entities) { // check if the entity has not been added to the document if (this.addedObjects.ContainsKey(blockEntity)) throw new ArgumentException("The entity " + blockEntity.Type + " object of the block " + ((Insert) entity).Block.Name + " has already been added to the document.", "entity"); this.addedObjects.Add(blockEntity, blockEntity); if (!this.layers.ContainsKey(blockEntity.Layer.Name)) { this.layers.Add(blockEntity.Layer.Name, blockEntity.Layer); } if (!this.lineTypes.ContainsKey(blockEntity.LineType.Name)) { this.lineTypes.Add(blockEntity.LineType.Name, blockEntity.LineType); } } //for new block definitions configure its attributes foreach (Attribute attribute in ((Insert) entity).Attributes) { if (!this.layers.ContainsKey(attribute.Layer.Name)) { this.layers.Add(attribute.Layer.Name, attribute.Layer); } if (!this.lineTypes.ContainsKey(attribute.LineType.Name)) { this.lineTypes.Add(attribute.LineType.Name, attribute.LineType); } AttributeDefinition attDef = attribute.Definition; if (!this.layers.ContainsKey(attDef.Layer.Name)) { this.layers.Add(attDef.Layer.Name, attDef.Layer); } if (!this.lineTypes.ContainsKey(attDef.LineType.Name)) { this.lineTypes.Add(attDef.LineType.Name, attDef.LineType); } if (!this.textStyles.ContainsKey(attDef.Style.Name)) { this.textStyles.Add(attDef.Style.Name, attDef.Style); } } } this.inserts.Add((Insert) entity); break; case EntityType.Line: this.lines.Add((Line) entity); break; case EntityType.LightWeightPolyline: this.polylines.Add((IPolyline) entity); break; case EntityType.Polyline: this.polylines.Add((IPolyline) entity); break; case EntityType.Polyline3d: this.polylines.Add((IPolyline) entity); break; case EntityType.PolyfaceMesh: this.polylines.Add((IPolyline) entity); break; case EntityType.Text: if (!this.textStyles.ContainsKey(((Text) entity).Style.Name)) { this.textStyles.Add(((Text) entity).Style.Name, ((Text) entity).Style); } this.texts.Add((Text) entity); break; case EntityType.Vertex: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); case EntityType.PolylineVertex: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); case EntityType.Polyline3dVertex: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); case EntityType.PolyfaceMeshVertex: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); case EntityType.PolyfaceMeshFace: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); case EntityType.AttributeDefinition: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); case EntityType.Attribute: throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of another entity", "entity"); default: throw new NotImplementedException("The entity " + entity.Type + " is not implemented or unknown"); } }
public void WriteEntity(IEntityObject entity) { switch (entity.Type) { case EntityType.Arc: this.WriteArc((Arc) entity); break; case EntityType.Circle: this.WriteCircle((Circle) entity); break; case EntityType.Ellipse: this.WriteEllipse((Ellipse) entity); break; case EntityType.NurbsCurve: this.WriteNurbsCurve((NurbsCurve) entity); break; case EntityType.Point: this.WritePoint((Point) entity); break; case EntityType.Face3D: this.WriteFace3D((Face3d) entity); break; case EntityType.Solid: this.WriteSolid((Solid) entity); break; case EntityType.Insert: this.WriteInsert((Insert) entity); break; case EntityType.Line: this.WriteLine((Line) entity); break; case EntityType.LightWeightPolyline: this.WriteLightWeightPolyline((LightWeightPolyline) entity); break; case EntityType.Polyline: this.WritePolyline2d((Polyline) entity); break; case EntityType.Polyline3d: this.WritePolyline3d((Polyline3d) entity); break; case EntityType.PolyfaceMesh: this.WritePolyfaceMesh((PolyfaceMesh) entity); break; case EntityType.Text: this.WriteText((Text) entity); break; default: throw new NotImplementedException(entity.Type.ToString()); } }
private static void ExportSingle(System.IO.StreamWriter writer, IEntityObject entity, string[] properties) { List<string> stringArray = new List<string>(); Microsoft.LightSwitch.Details.IEntityProperty currentProperty; // Write each property to the string array foreach (string prop in properties) { try { // Get the property from the entity by name currentProperty = entity.Details.Properties[prop]; } catch (Exception) { throw new InvalidOperationException(String.Format("A property named {0} does not exist on the entity named {1}.", prop, entity.Details.Name)); } stringArray.Add(currentProperty.Value.ToString()); } // Write the string array writer.WriteLine(String.Join(",", stringArray.ToArray())); }
private void WriteEntityCommonCodes(IEntityObject entity) { this.WriteCodePair(8, entity.Layer); this.WriteCodePair(62, entity.Color.Index); this.WriteCodePair(6, entity.LineType); }