private void AssignOutputValuesToObject(SqlCommand cmd, IRelatable relatee, ORMTypeMapping typeMap, string relationKey) { // Logger.Write( MethodBase.GetCurrentMethod() ); ORMCommandMap ocm = typeMap.GetMapByName(relationKey); foreach (object ob in ocm.PropertyMaps) { ORMPropertyMap propMap = (ORMPropertyMap)ob; if ((propMap.DataDirection == ParameterDirection.Output) || (propMap.DataDirection == ParameterDirection.InputOutput)) { PropertyInfo prop; Type t = relatee.GetType(); prop = t.GetProperty(propMap.MemberName); if (prop != null) { if (cmd.Parameters[propMap.Parameter].Value != DBNull.Value) { prop.SetValue(relatee, cmd.Parameters[propMap.Parameter].Value, null); } } else { // ExceptionPolicy.HandleException( new NullReferenceException(("Missing member " + t.FullName + "." + propMap.MemberName)), "Exception" ); } } } }
/// <summary> /// All the objects which are direct children to the parent relatable. /// </summary> /// <param name="relatable"></param> /// <returns></returns> public static List <ITECObject> GetDirectChildren(this IRelatable relatable) { return(relatable.PropertyObjects.ChildList() .Where(x => !relatable.LinkedObjects.Contains(x.PropertyName)) .Select(y => y.Child) .ToList()); }
protected ORMTypeMapping FetchTypeMap(IRelatable relatee) { //Logger.Write("Testing"); //LogWriter.gger.Writer.SystemTrace.MethodStart( MethodBase.GetCurrentMethod() ); Type t = relatee.GetType(); Assembly sourceAssembly = t.Assembly; string resourceName = t.Namespace + ".ORM.xml"; XmlDocument xDoc = new XmlDocument(); StreamReader xmlRaw = new StreamReader(sourceAssembly.GetManifestResourceStream(resourceName)); // StreamReader xmlRaw = new StreamReader((esourceName); xDoc.Load(xmlRaw); string query = "//type[@fullname='" + t.FullName + "']"; XmlNode typeMapNode = xDoc.DocumentElement.SelectSingleNode(query); if (typeMapNode != null) { ORMTypeMapping typeMap = new ORMTypeMapping(typeMapNode); return(typeMap); } else { // SystemTrace.TraceError("Failed to load type map for {0}", t.FullName); // ExceptionPolicy.HandleException( new NullReferenceException("Unable to fetch type map for " + t.FullName), "Exception" ); string debug = "Unable to fetch type map for " + t.FullName; } return(null); }
private void Move_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var hits = HT.Viewport3DHelper.FindHits(viewport.Viewport, e.GetPosition(viewport.Viewport)); if (hits.Count > 0) { IRelatable ent = null; foreach (var hit in hits) { if (hit.Visual is IRelatable) { ent = hit.Visual as IRelatable; break; } } if (ent != null) { this.moving = ent; lastPos = e.GetPosition(viewport.Viewport); viewport.Viewport.MouseMove += Move_MouseMove; viewport.Viewport.MouseLeftButtonUp += Move_MouseLeftButtonUp; } else { viewport.Viewport.MouseLeftButtonDown -= Move_MouseLeftButtonDown; viewport.Viewport.MouseMove -= Move_MouseMove; viewport.Viewport.MouseLeftButtonUp -= Move_MouseLeftButtonUp; } } }
private void Select_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { var hits = HT.Viewport3DHelper.FindHits(viewport.Viewport, e.GetPosition(viewport.Viewport)); if (hits.Count > 0) { //var ent = hits.OfType<o3DLib.Sketching.Entity2D>().First<o3DLib.Sketching.Entity2D>(); IRelatable ent = null; foreach (var hit in hits) { if (this.filter.Text == "Line" && hit.Visual is Line2D || this.filter.Text == "Point" && hit.Visual is Point2D) { ent = hit.Visual as IRelatable; break; } } if (ent != null) { if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { this.Selected.NotIdioticClear <IRelatable>(); } this.Selected.Add(ent); } else { Selected.NotIdioticClear <IRelatable>(); } } else { Selected.NotIdioticClear <IRelatable>(); } }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="watcher"></param> /// <param name="includeFilter">Predicate for "where" clause of direct children of root.</param> public ConnectionsVM(IRelatable root, ChangeWatcher watcher, TECCatalogs catalogs, IEnumerable <TECLocation> locations = null, Func <ITECObject, bool> filterPredicate = null) { if (filterPredicate == null) { filterPredicate = item => true; } this.filterPredicate = filterPredicate; ConnectableFilter.basePredicate = connectable => { if (!connectable.IsConnected() && connectable.AvailableProtocols.Count == 0) { return(false); } if (connectable == SelectedController) { return(false); } return(true); }; this.InterlocksVM = new InterlocksVM(root, watcher, catalogs, filterPredicate); this.root = root; this.Catalogs = catalogs; this.Locations = locations != null ? new ObservableCollection <TECLocation>(locations) : new ObservableCollection <TECLocation>(); if (this.Catalogs.ConduitTypes.Count > 0) { this.DefaultConduitType = this.Catalogs.ConduitTypes[0]; } watcher.Changed += parentChanged; new DirectRelationshipChangedFilter(watcher).DirectRelationshipChanged += parentScopeChanged; this.rootConnectableGroup = new FilteredConnectablesGroup("root", this.ConnectableFilter); this.rootControllerGroup = new FilteredConnectablesGroup("root", this.ControllerFilter); repopulateGroups(null, root, addConnectable); SelectProtocolCommand = new RelayCommand(selectProtocolExecute, selectProtocolCanExecute); CancelProtocolSelectionCommand = new RelayCommand(cancelProtocolSelectionExecute); ConnectionDropHandler = new NetworkConnectionDropTarget(this); this.ControllerFilter.FilterChanged += () => { if (SelectedControllerGroup?.PassesFilter == false) { SelectedControllerGroup = null; } }; this.ConnectableFilter.FilterChanged += () => { if (SelectedConnectableGroup?.PassesFilter == false) { SelectedConnectableGroup = null; } }; DeleteCommand = new RelayCommand <IControllerConnection>(deleteConnectionExecute, canDeleteConnection); }
private SqlCommand BuildCommandFromTypeMap(IRelatable relatee, ORMTypeMapping typeMap, string relationKey) { // Logger.Write( MethodBase.GetCurrentMethod() ); ORMCommandMap ocm = typeMap.GetMapByName(relationKey); if (ocm != null) { SqlCommand cmd = new SqlCommand(ocm.StoredProcedure, conn); cmd.CommandType = CommandType.StoredProcedure; foreach (object ob in ocm.PropertyMaps) { ORMPropertyMap propMap = (ORMPropertyMap)ob; SqlParameter newParam = CreateParameterFromPropertyMap(propMap); if ((newParam.Direction == ParameterDirection.Input) || (newParam.Direction == ParameterDirection.InputOutput)) { SetParameterValue(newParam, relatee, propMap.MemberName); } cmd.Parameters.Add(newParam); } return(cmd); } else { //ExceptionPolicy.HandleException( new NullReferenceException("No such command mapping: " + typeMap.FullName + ":" + relationKey), "Exception" ); } return(null); }
private void addConnectable(FilteredConnectablesGroup rootGroup, IConnectable connectable, IEnumerable <ITECObject> parentPath) { if (!filterPredicate(connectable)) { return; } IRelatable rootScope = rootGroup.Scope as IRelatable ?? this.root; List <ITECObject> path = new List <ITECObject>(parentPath); if (rootScope != parentPath.First()) { path = rootScope.GetObjectPath(parentPath.First()); path.Remove(parentPath.First()); path.AddRange(parentPath); } if (path.Count == 0) { logger.Error("New connectable doesn't exist in root object."); return; } FilteredConnectablesGroup lastGroup = rootGroup; int lastIndex = 0; for (int i = path.Count - 1; i > 0; i--) { if (path[i] is ITECScope scope) { FilteredConnectablesGroup group = rootGroup.GetGroup(scope); if (group != null) { lastGroup = group; lastIndex = i; break; } } else { logger.Error("Object in path to connectable isn't ITECScope, cannot build group hierarchy."); return; } } FilteredConnectablesGroup currentGroup = lastGroup; for (int i = lastIndex + 1; i < path.Count; i++) { if (path[i] is ITECScope scope) { currentGroup = currentGroup.Add(scope); } else { logger.Error("Object in path to connectable isn't ITECScope, cannot build group hierarchy."); return; } } }
public static List <ITECObject> GetObjectPath(this IRelatable parent, ITECObject descendant) { List <ITECObject> path = new List <ITECObject>(); getObjectPath(parent, descendant, path); path.Reverse(); return(path); }
private void SetParameterValue(SqlParameter param, IRelatable relatee, string member) { //Logger.Write( MethodBase.GetCurrentMethod() ); PropertyInfo propInfo; Type t = relatee.GetType(); propInfo = t.GetProperty(member); if (propInfo != null) { param.Value = propInfo.GetValue(relatee, null); } else { //Logger.Write("Read failed on member {0} on type {1}", "pos exception"); } }
public static List <UpdateItem> ChildStack(Change change, IRelatable item, DBType type) { List <UpdateItem> outStack = new List <UpdateItem>(); foreach (var saveItem in item.PropertyObjects.ChildList()) { outStack.AddRange(addRemoveStack(change, saveItem.PropertyName, item as ITECObject, saveItem.Child, type, true)); } if (item is TECTypical system) { outStack.AddRange(typicalInstanceStack(change, system, type)); } else if (item is TECTemplates templates) { outStack.AddRange(templatesReferencesStack(change, templates)); } return(outStack); }
public static ITECObject FindChild(this IRelatable parent, Guid guid) { foreach (ITECObject child in parent.GetDirectChildren()) { if (child.Guid == guid) { return(child); } else if (child is IRelatable childRel) { var found = childRel.FindChild(guid); if (found != null) { return(found); } } } return(null); }
/// <summary> /// Returns all objects of type T which exist as a direct descendant /// </summary> /// <typeparam name="T"></typeparam> /// <param name="relatable"></param> /// <returns></returns> public static List <T> GetAll <T>(this IRelatable relatable) { List <T> list = new List <T>(); if (relatable is T typedObj) { list.Add(typedObj); } foreach (var item in relatable.GetDirectChildren()) { if (item is IRelatable rel) { list.AddRange(GetAll <T>(rel)); } else if (item is T x) { list.Add(x); } } return(list); }
public Relation(Relationship relationship, TreeListNode category, IRelatable firstEntity, IRelatable secondEntity, object info, string reference, string remark, TimeInterval effectivePeriod) { if (relationship.IsPermanent) { this.EffectivePeriod = TimeInterval.Eternal; } else if (effectivePeriod == null) { throw new iSabayaException("Relation.Relation(): Effective period must not be null for transient relationship."); } else { this.EffectivePeriod = effectivePeriod; } this.category = category; this.firstEntity = firstEntity; this.secondEntity = secondEntity; this.info = info; this.Reference = reference; this.Remark = remark; this.Relationship = relationship; }
private static void getObjectPath(IRelatable parent, ITECObject descendant, List <ITECObject> path) { var children = parent.GetDirectChildren(); if (children.Contains(descendant)) { path.Add(descendant); path.Add(parent); } else { foreach (var child in children.OfType <IRelatable>()) { int before = path.Count; getObjectPath(child, descendant, path); if (path.Count > before) { path.Add(parent); break; } } } }
public override void Relate(IRelatable relatee, string relationKey) { //Logger.Write( MethodBase.GetCurrentMethod() ); ORMTypeMapping typeMap = FetchTypeMap(relatee); ORMCommandMap cmdMap = typeMap.GetMapByName(relationKey); SqlCommand cmd = BuildCommandFromTypeMap(relatee, typeMap, relationKey); //Logger.Write(cmd.ToString()); try { conn.Open(); if (cmdMap.ReturnsMultiple) { SqlDataAdapter da = new SqlDataAdapter(cmd); IRelatableSet relateSet = (IRelatableSet)relatee; da.Fill(relateSet.ResultSet); } else { // Logger.Write(cmd.CommandText); // Logger.Write(cmd.Parameters.ToString()); cmd.ExecuteNonQuery(); } AssignOutputValuesToObject(cmd, relatee, typeMap, relationKey); //conn.Close(); } catch (Exception e) { string b = e.ToString(); MessageBox.Show(relationKey + "\\n" + e.ToString()); } finally { conn.Close(); } }
public InterlocksVM(IRelatable root, ChangeWatcher watcher, TECCatalogs catalogs, Func <ITECObject, bool> filterPredicate = null) { if (filterPredicate == null) { filterPredicate = item => true; } this.filterPredicate = filterPredicate; this.root = root; new DirectRelationshipChangedFilter(watcher).DirectRelationshipChanged += parentScopeChanged; noneConduit = new TECElectricalMaterial(); noneConduit.Name = "None"; this.rootInterlockablesGroup = new ScopeGroup("root"); this.AddInterlockCommand = new RelayCommand(addInterlockExecute, canAddInterlock); this.DeleteInterlockCommand = new RelayCommand <TECInterlockConnection>(deleteInterlockExecute, canDeleteInterlock); this.ConduitTypes = new List <TECElectricalMaterial>(catalogs.ConduitTypes); this.ConduitTypes.Add(noneConduit); this.ConduitType = noneConduit; repopulateGroups(null, root, addInterlockable); }
public bool IsDriven(IRelatable relatable) { return(this.Relatables.Last() == relatable && this.Relatables.Count() > 1); }
public void DoSomething <T>(IRelatable <T> rel) where T : Entity { T relatedTo = rel.RelatedEntity; // ... }
public bool IsDriven(IRelatable relatable) { return this.Relatables.Last() == relatable && this.Relatables.Count() > 1; }
public Point2D GetDriven() { IRelatable last = this.Relatables.Last(); return((last is Point2D) ? last as Point2D : null); }
public void DoSomething(IRelatable <T> rel) { T relatedTo = rel.RelatedEntity; // ... }
public bool IsLargerThan(IRelatable relatable) { Rectangle obj = (Rectangle)relatable; return(this.GetArea() > obj.GetArea()); }
public virtual void Relate(IRelatable relatee, string relationKey) { }
public virtual void Relate(IRelatable relatee, RelationType relationType) { }
public bool IsDriven(IRelatable relatable) { return this.Relatables.Last() == relatable; }
public static bool IsDirectDescendant(this IRelatable relatable, ITECObject item) { return(relatable.GetObjectPath(item).Count > 0); }
public override void Relate(IRelatable relatee, RelationType relationType) { //SystemTrace.MethodStart( MethodBase.GetCurrentMethod() ); //Logger.Write(MethodBase.GetCurrentMethod()); Relate(relatee, relationType.ToString()); }
public bool IsDriven(IRelatable relatable) { return(this.Relatables.Last() == relatable); }
public static bool IsDirectChildProperty(this IRelatable relatable, string propertyName) { return(!relatable.LinkedObjects.Contains(propertyName) && relatable.PropertyObjects.Contains(propertyName)); }
private void Move_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var hits = HT.Viewport3DHelper.FindHits(viewport.Viewport, e.GetPosition(viewport.Viewport)); if (hits.Count > 0) { IRelatable ent = null; foreach (var hit in hits) if (hit.Visual is IRelatable) { ent = hit.Visual as IRelatable; break; } if (ent != null) { this.moving = ent; lastPos = e.GetPosition(viewport.Viewport); viewport.Viewport.MouseMove += Move_MouseMove; viewport.Viewport.MouseLeftButtonUp += Move_MouseLeftButtonUp; } else { viewport.Viewport.MouseLeftButtonDown -= Move_MouseLeftButtonDown; viewport.Viewport.MouseMove -= Move_MouseMove; viewport.Viewport.MouseLeftButtonUp -= Move_MouseLeftButtonUp; } } }