Files
spark/src/DataStreamSuite/DataStreamCore/BlueData/GridBindableBlueTable.cs
T
2023-09-04 16:25:40 -04:00

385 lines
11 KiB
C#

// using System;
// using System.Reflection;
// using System.Reflection.Emit;
// using System.Collections;
// using System.ComponentModel;
// namespace BCG
// {
// public class GridBindableBlueTable : IBindingList, IBlueRowCollection, ITypedList
// {
// private class MyComparer : IComparer
// {
// private string myColName;
// public MyComparer (string colName)
// {
// myColName = colName;
// }
// #region IComparer Members
// public int Compare (object x, object y)
// {
// IBlueRow r1 = x as IBlueRow;
// IBlueRow r2 = y as IBlueRow;
// try
// {
// return
// r1[myColName] == DBNull.Value ?
// r2[myColName] == DBNull.Value ?
// 0
// :
// -1
// :
// r2[myColName] == DBNull.Value ?
// 1
// :
// (r1[myColName] as IComparable).CompareTo (r2[myColName]);
// }
// catch (Exception e)
// {
// Console.WriteLine (e);
// return 0;
// }
// }
// #endregion
// }
// private PropertyDescriptor mySortPropertyDescriptor;
// private IBlueTableSchema mySchema;
// private PropertyDescriptorCollection myPDColl;
// protected ArrayList myList = new ArrayList ();
// protected ListSortDirection mySortDirection;
// protected IComparer myComparer;
// public event System.ComponentModel.ListChangedEventHandler ListChanged;
// public GridBindableBlueTable (IBlueTableSchema schema)
// : this (schema, new ArrayList())
// {}
// public GridBindableBlueTable (IBlueTableSchema schema, ICollection data)
// {
// myComparer = new MyComparer ("id");
// mySchema = schema;
// myInitPropertyDescriptors ();
// foreach (object o in data)
// Add (o);
// }
// private void myInitPropertyDescriptors ()
// {
// ArrayList temp = new ArrayList ();
// foreach (ColumnInfo ci in mySchema.columnInfo)
// temp.Add (new BlueDataPropertyDescriptor (ci));
// myPDColl = new PropertyDescriptorCollection (
// temp.ToArray (typeof(PropertyDescriptor)) as PropertyDescriptor[]);
// }
// #region IList Members
// public bool IsReadOnly {get {return false;}}
// public virtual object this [int index]
// {
// get {return myList[index];}
// set {throw new NotSupportedException ("Illegal operation for a Sorted list");}
// }
// public virtual void RemoveAt(int index)
// {
// myList.RemoveAt (index);
// if (ListChanged != null)
// ListChanged (this, new ListChangedEventArgs (ListChangedType.ItemDeleted, index));
// }
// public virtual void Insert (int index, object value)
// {
// throw new NotSupportedException ("Illegal operation for a Sorted list");
// }
// public virtual void Remove (object value)
// {
// RemoveAt (myList.IndexOf (value));
// }
// public virtual bool Contains (object value)
// {
// return myList.Contains (value);
// }
// public virtual void Clear()
// {
// myList.Clear ();
// if (ListChanged != null)
// ListChanged (this, new ListChangedEventArgs (ListChangedType.Reset, 0));
// }
// public virtual int IndexOf (object value)
// {
// return myList.IndexOf (value);
// }
// /// <summary>
// /// Adds the value to the right index in the sorted list
// /// </summary>
// /// <param name="value"></param>
// /// <returns></returns>
// public virtual int Add (object value)
// {
// int insertionIndex = -1;
// if (Count > 0)
// {
// for (int i = 0; i < myList.Count; i++)
// {
// if ((insertionIndex = myGetInsertionIndex (value, i)) > -1)
// {
// myList.Insert (insertionIndex, value);
// break;
// }
// insertionIndex = -1;
// }
// }
// else
// {
// insertionIndex = 0;
// myList.Add (value);
// }
// if (ListChanged != null)
// ListChanged (this, new ListChangedEventArgs (ListChangedType.ItemAdded, insertionIndex));
// return insertionIndex;
// }
// private int myGetInsertionIndex (object obj, int listIndex)
// {
// if (mySortPropertyDescriptor == null)
// return myList.Count;
// if (mySortDirection.Equals (ListSortDirection.Ascending))
// {
// if (myComparer.Compare (obj, myList[listIndex]) <= 0)
// return listIndex;
// else if (listIndex == myList.Count-1)
// return myList.Count;
// }
// else
// {
// if (myComparer.Compare (obj, myList[listIndex]) >= 0)
// return listIndex;
// else if (listIndex == myList.Count-1)
// return myList.Count;
// }
// return -1;
// }
// public bool IsFixedSize {get {return false;}}
// #endregion
// #region ICollection Members
// public bool IsSynchronized {get {return false;}}
// public int Count {get {return myList.Count;}}
// public void CopyTo(Array array, int index) {myList.CopyTo (array, index);}
// public object SyncRoot {get {return null;}}
// #endregion
// #region IEnumerable Members
// public IEnumerator GetEnumerator() {return myList.GetEnumerator ();}
// #endregion
// #region IBindingList Members
// public void AddIndex(PropertyDescriptor property)
// {
// throw new NotSupportedException ("Adding index is not supported");
// }
// public bool AllowNew
// {
// get {return false;}
// }
// public void ApplySort (PropertyDescriptor property, System.ComponentModel.ListSortDirection direction)
// {
// if (mySortPropertyDescriptor != null
// && mySortPropertyDescriptor.Name == property.Name)
// {
// if (mySortDirection == direction)
// return;
// else
// {
// mySortDirection = direction;
// myList.Reverse ();
// return;
// }
// }
// foreach (PropertyDescriptor pd in myPDColl)
// if (pd.Name == property.Name)
// mySortPropertyDescriptor = pd;
// myComparer = new MyComparer (property.Name);
// mySortDirection = direction;
// myList.Sort (myComparer);
// }
// public PropertyDescriptor SortProperty
// {
// get {return mySortPropertyDescriptor;}
// }
// public int Find (PropertyDescriptor property, object key)
// {
// throw new NotSupportedException ("Find not supported");
// }
// public bool SupportsSorting
// {
// get {return true;}
// }
// public bool IsSorted {get {return mySortPropertyDescriptor != null;}}
// public bool AllowRemove {get {return false;}}
// public bool SupportsSearching {get {return false;}}
// public System.ComponentModel.ListSortDirection SortDirection {get {return mySortDirection;}}
// public bool SupportsChangeNotification {get {return true;}}
// public void RemoveSort()
// {
// mySortPropertyDescriptor = null;
// }
// public object AddNew()
// {
// throw new NotSupportedException ("Find not supported");
// }
// public bool AllowEdit
// {
// get {return false;}
// }
// public void RemoveIndex(PropertyDescriptor property)
// {
// throw new NotSupportedException ("Find not supported");
// }
// #endregion
// #region IBlueRowCollection Members
// IBlueRow BCG.IBlueRowCollection.this[int id]
// {
// get
// {
// foreach (IBlueRow r in (this as IList))
// {
// if (r["id"].Equals(id))
// return r;
// }
// return null;
// }
// }
// public bool containsID (int id)
// {
// return (this as IBlueRowCollection) [id] != null;
// }
// public IBlueTableSchema schema {get {return mySchema;}}
// #endregion
// #region Dynamic Type Creation
// private IBlueRow myCreateDynamicRow (IBlueRow r)
// {
// //return Activator.CreateInstance (myRowType, new object[] {r}) as IBlueRow;
// return r;
// }
// private Type myGenerateType ()
// {
// ILGenerator ilg;
// AssemblyName an = new AssemblyName ();
// an.Name = "DynamicRowAssembly";
// AssemblyBuilder aBuilder =
// AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
// ModuleBuilder mBuilder =
// aBuilder.DefineDynamicModule ("DefaultModule");
// TypeBuilder tBuilder =
// mBuilder.DefineType ("DynamicBlueRow", TypeAttributes.Public, typeof(BlueRow));
// ConstructorBuilder cb =
// tBuilder.DefineConstructor (
// MethodAttributes.Public,
// CallingConventions.Standard,
// new Type[] {typeof(IBlueRow)}
// );
// ilg = cb.GetILGenerator ();
// ilg.Emit (OpCodes.Ldarg_0);
// ilg.Emit (OpCodes.Ldarg_1);
// ilg.Emit (OpCodes.Call,
// typeof(BlueRow).GetConstructor (new Type[] {typeof(IBlueRow)}));
// ilg.Emit (OpCodes.Ret);
// foreach (string col in mySchema.columnNames)
// {
// myAddProperty (col, tBuilder);
// }
// Type dynType = tBuilder.CreateType ();
// return dynType;
// }
// private void myAddProperty (string colName, TypeBuilder tBuilder)
// {
// MethodBuilder methodBuilder =
// tBuilder.DefineMethod ("get_" + colName,
// MethodAttributes.Public,
// CallingConventions.Standard,
// typeof(object),
// new Type[]{}
// );
// ILGenerator ilg =
// methodBuilder.GetILGenerator ();
// ilg.Emit (OpCodes.Ldarg_0);
// ilg.Emit (OpCodes.Ldstr, colName);
// ilg.Emit (OpCodes.Call, typeof(BlueRow).GetMethod ("get_Item", new Type[]{typeof(string)}));
// ilg.Emit (OpCodes.Ret);
// PropertyBuilder propBuilder =
// tBuilder.DefineProperty (colName, System.Reflection.PropertyAttributes.None , typeof(object), new Type[]{});
// propBuilder.SetGetMethod (methodBuilder);
// }
// #endregion
// #region ITypedList Members
// public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
// {
// return myPDColl;
// }
// public string GetListName(PropertyDescriptor[] listAccessors)
// {
// return "GridBindableBlueTable";
// }
// #endregion
// }
// }