/// <summary> /// Gets interface /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="obj">Object</param> /// <returns>Interface</returns> public static T GetInterface <T>(this IAssociatedObject obj) where T : class { if (obj is T) { return(obj as T); } if (obj is IChildrenObject) { IChildrenObject co = obj as IChildrenObject; IAssociatedObject[] ch = co.Children; if (ch != null) { foreach (IAssociatedObject ob in ch) { if (ob != null) { T o = GetInterface <T>(ob); if (o != null) { return(o); } } } } } return(null); }
/// <summary> /// Creates transformer of associated object /// </summary> /// <param name="tr">Initial transformer</param> /// <param name="obj">The object</param> /// <returns>The transformer</returns> static public Action <double[]> CreateTransformer(Action <double[]> tr, IAssociatedObject obj) { if (!(obj is IChildrenObject)) { return(tr); } IChildrenObject ch = obj as IChildrenObject; IAssociatedObject[] ao = ch.Children; List <Action <double[]> > l = new List <Action <double[]> >(); foreach (IAssociatedObject ob in ao) { if (!(ob is IVectorTransformer)) { continue; } IVectorTransformer t = ob as IVectorTransformer; Action <double[]> tv = t.Transformer; if (tv != null) { l.Add(tv); } } if (l.Count == 0) { return(tr); } Action <double[]> trv = Sum(l.ToArray()); Action <double[]> tvr = tr + trv; return(tvr); }
static void SetTimeProvider(object o, ITimeMeasureProvider provider, IDictionary <ITimeMeasureConsumer, IMeasurement> dictionary) { ITimeMeasureConsumer tc = o.GetLabelObject <ITimeMeasureConsumer>(); if (tc != null) { if (dictionary.ContainsKey(tc)) { if (tc.Time != provider.TimeMeasurement) { dictionary[tc] = tc.Time; tc.Time = provider.TimeMeasurement; } } else { dictionary[tc] = tc.Time; tc.Time = provider.TimeMeasurement; } } IChildrenObject co = o.GetLabelObject <IChildrenObject>(); if (co != null) { IAssociatedObject[] ch = co.Children; if (ch != null) { foreach (object ob in ch) { SetTimeProvider(ob, provider, dictionary); } } } }
private void GetObjectsPrivate(IAssociatedObject ao, IList <ICategoryObject> objects, IList <ICategoryArrow> arrows) { { if (ao is ICategoryObject) { objects.Add(ao as ICategoryObject); } if (ao is ICategoryArrow) { arrows.Add(ao as ICategoryArrow); } if (ao is IChildrenObject) { IChildrenObject co = ao as IChildrenObject; IAssociatedObject[] ass = co.Children; if (ass != null) { foreach (IAssociatedObject asso in ass) { if (asso != null) { GetObjects(asso, objects, arrows); } } } } } }
void Add(object o) { if (o == null) { return; } if (o is IDataConsumer) { IDataConsumer c = o as IDataConsumer; if (!consumers.Contains(c)) { consumers.Add(c); } } if (o is IUpdatableObject) { IUpdatableObject u = o as IUpdatableObject; if (!upd.Contains(u)) { upd.Add(u); } } if (o is IDynamical) { IDynamical d = o as IDynamical; if (!dyn.Contains(d)) { dyn.Add(d); } } if (o is IStep) { IStep s = o as IStep; s.Step = 0; if (!steps.Contains(s)) { steps.Add(s); } } if (o is IChildrenObject) { IChildrenObject ch = o as IChildrenObject; IAssociatedObject[] objs = ch.Children; foreach (object obj in objs) { Add(obj); } } if (o is MeasurementsWrapper) { MeasurementsWrapper mw = o as MeasurementsWrapper; int n = mw.Count; for (int i = 0; i < n; i++) { Add(mw[i]); } } }
static void SetTimeProvider(object o, ITimeMeasureProvider provider, IDictionary <ITimeMeasureConsumer, IMeasurement> dictionary) { ITimeMeasureConsumer tc = o.GetLabelObject <ITimeMeasureConsumer>(); IMeasurement timeMeasurement = provider.TimeMeasurement; if (!(timeMeasurement is TimeMeasurement)) { throw new Exception(); } Func <object> f = timeMeasurement.Parameter; if (tc != null) { TimeMeasurement tmr = tc.Time as TimeMeasurement; if (tmr == null) { tc.Time = new TimeMeasurement(() => { return((double)0); }); } tmr = tc.Time as TimeMeasurement; if (dictionary.ContainsKey(tc)) { if (tc.Time != provider.TimeMeasurement) { dictionary[tc] = tc.Time; if (tmr != null) { tmr.TimeParameter = f; } } } else { dictionary[tc] = tc.Time; if (tmr != null) { tmr.TimeParameter = f; } } } IChildrenObject co = o.GetLabelObject <IChildrenObject>(); if (co != null) { IAssociatedObject[] ch = co.Children; if (ch != null) { foreach (object ob in ch) { SetTimeProvider(ob, provider, dictionary); } } } }
private bool Check(ICategoryObject value) { Type t = value.GetType(); System.Reflection.TypeInfo ti = System.Reflection.IntrospectionExtensions.GetTypeInfo(t); Type to = source.Type; if (t.Equals(to) | ti.IsSubclassOf(to)) { Accept(value); return(true); } IEnumerable <Type> types = ti.ImplementedInterfaces; foreach (Type tp in types) { if (tp.Equals(to)) { Accept(value); return(true); } } if (value is IChildrenObject) { IChildrenObject ch = value as IChildrenObject; IAssociatedObject[] ass = ch.Children; if (ass != null) { foreach (object o in ass) { if (o is ICategoryObject) { ICategoryObject co = o as ICategoryObject; if (Check(co)) { return(true); } } } } } return(false); }
/// <summary> /// Sets associated object to object and all its children; /// </summary> /// <param name="ao">The associated object</param> /// <param name="obj">The object to set</param> static public void SetAssociatedObject(this IAssociatedObject ao, object obj) { ao.Object = obj; if (ao is IChildrenObject) { IChildrenObject co = ao as IChildrenObject; IAssociatedObject[] ch = co.Children; if (ch != null) { foreach (IAssociatedObject o in ch) { if (o != null) { SetAssociatedObject(o, obj); } } } } }
private void Reset(object o) { if (o is ITimeMeasureConsumer) { ITimeMeasureConsumer tc = o as ITimeMeasureConsumer; if (dictionary.ContainsKey(tc)) { tc.Time = dictionary[tc]; } } if (o is IChildrenObject) { IChildrenObject co = o as IChildrenObject; IAssociatedObject[] ch = co.Children; foreach (object ob in ch) { Reset(ob); } } }
/// <summary> /// Loading /// </summary> /// <param name="info">Serialization info</param> /// <param name="o">Loaded object</param> /// <returns>Result of loading</returns> public static RelativeField Load(SerializationInfo info, object o) { RelativeField f = info.Deserialize <RelativeField>("RelativeField"); if (o != null) { if (o is IChildrenObject) { IChildrenObject ch = o as IChildrenObject; if (ch.Children.Length != 0) { if (ch.Children.Length > 0) { ch.Children[0] = f; } } } } return(f); }
private static IDataConsumer Get(IDataConsumer master, IAssociatedObject root, IAssociatedObject obj) { IDataConsumer res = null; if (obj is IDataConsumer) { res = obj as IDataConsumer; } res = Create(root, master, res); if (obj is IChildrenObject) { IChildrenObject co = obj as IChildrenObject; IAssociatedObject[] ch = co.Children; foreach (IAssociatedObject ao in ch) { res = Get(res, root, ao); } } return(res); }
private static IAlias GetAlias(IAlias alias, IAssociatedObject obj) { IAlias res = null; if (obj is IAlias) { res = obj as IAlias; } res = Create(alias, res); if (!(obj is IChildrenObject)) { return(res); } IChildrenObject co = obj as IChildrenObject; IAssociatedObject[] children = co.Children; foreach (IAssociatedObject ao in children) { res = GetAlias(res, ao); } return(res); }
static void SetTimeProvider(IChildrenObject co, ITimeMeasureProvider provider, IDictionary <ITimeMeasureConsumer, IMeasurement> dictionary) { IAssociatedObject[] ao = co.Children; foreach (object o in ao) { if (o is IDataConsumer) { IDataConsumer dc = o as IDataConsumer; SetTimeProvider(dc, provider, dictionary); } else if (o is IMeasurements) { IMeasurements mea = o as IMeasurements; SetTimeProvider(mea, provider, dictionary); } if (o is IChildrenObject) { IChildrenObject cho = o as IChildrenObject; SetTimeProvider(cho, provider, dictionary); } } }
Control Recursion(object child) { if (child is IPropertiesEditor) { IPropertiesEditor ed = child as IPropertiesEditor; object o = ed.Editor; if (o is object[]) { object[] oo = o as object[]; foreach (object ob in oo) { if ((ob is Control) & !(ob is Form)) { Control c = ob as Control; //c.Dock = DockStyle.Fill; //anelCenter.Controls.Add(c); return(c); } } } } if (child is IChildrenObject) { IChildrenObject chl = child as IChildrenObject; IAssociatedObject[] ao = chl.Children; foreach (object aa in ao) { Control cc = Recursion(aa); if (cc != null) { return(cc); } } } return(null); }
/// <summary> /// Gets object of predefined type /// </summary> /// <typeparam name="T">The type</typeparam> /// <param name="obj">The prototype</param> /// <returns>The object of predefined type</returns> public static T GetObject <T>(this IAssociatedObject obj) where T : class { // If obj is subtype of T if (obj is T) { // Returns obj as T return(obj as T); } // Search in children // If obj is IChildrenObject if (obj is IChildrenObject) { IChildrenObject co = obj as IChildrenObject; // Gets children IAssociatedObject[] ch = co.Children; if (ch != null) { // Recursive search among children foreach (IAssociatedObject ob in ch) { T a = GetObject <T>(ob); // If child object is found if (a != null) { // Returns the object return(a); } } } } if (obj is IAssociatedObject) { return(Find <T>(obj as IAssociatedObject)); } return(null); }
private void Reset(object o) { if (o is ITimeMeasureConsumer) { ITimeMeasureConsumer tc = o as ITimeMeasureConsumer; IMeasurement m = tc.Time; if (m != null) { if (dictionary.ContainsKey(tc)) { (tc.Time as TimeMeasurement).TimeParameter = dictionary[tc].Parameter; } } } if (o is IChildrenObject) { IChildrenObject co = o as IChildrenObject; IAssociatedObject[] ch = co.Children; foreach (object ob in ch) { Reset(ob); } } }
/// <summary> /// Recursive post set arrow /// </summary> /// <param name="obj">Object for post set arrow</param> public static void PostSetObject(IAssociatedObject obj) { if (obj == null) { return; } if (obj is IPostSetObject) { IPostSetObject p = obj as IPostSetObject; p.PostSetObject(); } if (obj is IChildrenObject) { IChildrenObject cho = obj as IChildrenObject; IAssociatedObject[] ch = cho.Children; if (ch != null) { foreach (IAssociatedObject ao in ch) { PostSetObject(ao); } } } }
private static IMeasurements Get(IMeasurements master, IAssociatedObject root, IAssociatedObject obj) { IMeasurements res = null; if (obj is IMeasurements) { res = obj as IMeasurements; } res = Create(root, master, res); if (obj is IChildrenObject) { IChildrenObject co = obj as IChildrenObject; IAssociatedObject[] ch = co.Children; if (ch != null) { foreach (IAssociatedObject ao in ch) { res = Get(res, root, ao); } } } return(res); }
object ISeparatedPropertyEditor.GetEditor(object o) { if (f != null) { if (!f.IsDisposed) { return(ob); } } IChildrenObject c = o as IChildrenObject; if (c.Children != null) { if (c.Children[0] != null) { f = new Forms.FormNORADChild(o as SatelliteData); ob[0] = f; return(ob); } } f = new Forms.FormNORAD(o as SatelliteData); ob[0] = f; return(ob); }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="info">Serialization info</param> /// <param name="context">Streaming context</param> protected ChildrenObjectWrapper(SerializationInfo info, StreamingContext context) { wrappedObject = info.Deserialize <IChildrenObject>("Object"); }
/// <summary> /// Constructor /// </summary> /// <param name="wrappedObject">Wrapped object</param> public ChildrenObjectWrapper(IChildrenObject wrappedObject) { this.wrappedObject = wrappedObject; }
static private void GetAllAliases(INamedComponent nc, IObjectLabel lab, object labObject, List <string> list, object type) { if (labObject == null) { return; } IDesktop d = nc.Desktop; if (labObject is IAliasBase) { IAliasBase ab = labObject as IAliasBase; if (ab is IAlias) { IAlias al = ab as IAlias; foreach (string s in al.AliasNames) { string str = lab.GetName(d) + "." + s; if (type != null) { if (!al.GetType(s).Equals(type)) { continue; } } if (list.Contains(str)) { continue; } list.Add(lab.GetName(d) + "." + s); } } if (ab is IAliasVector) { IAliasVector av = ab as IAliasVector; foreach (string s in av.AliasNames) { string str = lab.GetName(d) + "." + s; if (type != null) { if (!av.GetType(s).Equals(type)) { continue; } } if (list.Contains(str)) { continue; } list.Add(lab.GetName(d) + "." + s); } } } if (labObject is IChildrenObject) { IChildrenObject co = labObject as IChildrenObject; IAssociatedObject[] children = co.Children; foreach (object child in children) { GetAllAliases(nc, lab, child, list, type); } } }