/// <summary>
            /// Fetches the array.
            /// </summary>
            /// <param name="reader">The reader.</param>
            /// <returns></returns>
            internal static T[] FetchArray <T>(IDataReader reader)
            {
                DataAccessView <T> list = FetchCollection <T>(reader);

                T[] array = new T[list.Count];
                list.CopyTo(array, 0);
                return(array);
            }
Beispiel #2
0
 /// <summary>
 /// Initialize the project controller
 /// </summary>
 /// <param name="xtmfRuntime">A connection back to the XTMF we are apart of</param>
 internal ProjectController(XTMFRuntime xtmfRuntime)
 {
     this.XTMFRuntime = xtmfRuntime;
     this.Configuration = xtmfRuntime.Configuration;
     this.DataView = new DataAccessView<IProject>( this.Configuration.ProjectRepository.Projects );
     // initialize the hooks into added / removed
     ( (ProjectRepository)this.Configuration.ProjectRepository ).ProjectAdded += new Action<IProject>( ProjectController_ProjectAdded );
     ( (ProjectRepository)this.Configuration.ProjectRepository ).ProjectRemoved += new Action<IProject, int>( ProjectController_ProjectRemoved );
 }
Beispiel #3
0
 internal ModelSystemController(XTMFRuntime xtmfRuntime)
 {
     this.XTMFRuntime = xtmfRuntime;
     this.Configuration = this.XTMFRuntime.Configuration;
     this.DataView = new DataAccessView<IModelSystem>( this.Configuration.ModelSystemRepository.ModelSystems );
     // initialize the add / remove modelsystems
     ( (ModelSystemRepository)this.Configuration.ModelSystemRepository ).ModelSystemAdded += new Action<IModelSystem>( ModelSystemController_ModelSystemAdded );
     ( (ModelSystemRepository)this.Configuration.ModelSystemRepository ).ModelSystemRemoved += new Action<IModelSystem, int>( ModelSystemController_ModelSystemRemoved );
 }
            /// <summary>
            /// Fetches the collection.
            /// </summary>
            /// <param name="reader">The reader.</param>
            /// <returns></returns>
            internal static DataAccessView <T> FetchCollection <T>(IDataReader reader)
            {
                DataAccessView <T> list = new DataAccessView <T>();
                Type type    = typeof(T);
                T    current = default(T);

                System.Reflection.ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                if (constructor != null)
                {
                    // get all db fields
                    List <string> allFields = new List <string>(reader.FieldCount);
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        allFields.Add(reader.GetName(i).ToLower());
                    }
                    // get all object db fields and intersect
                    string        __fieldName;
                    List <string> fields = new List <string>(reader.FieldCount);
                    foreach (string fieldName in ObjectHelper.GetAllFields(type))
                    {
                        __fieldName = fieldName.ToLower();
                        if (allFields.Contains(__fieldName))
                        {
                            fields.Add(__fieldName);
                        }
                    }
                    // now fetch reader
                    while (reader.Read())
                    {
                        current = (T)constructor.Invoke(null);
                        foreach (string fieldName in fields)
                        {
                            ObjectHelper.SetFieldValue(current, fieldName, reader[fieldName]);
                        }
                        list.Add(current);
                    }
                    return(list);//.ToArray(type);
                }
                else
                {
                    throw new Exception(string.Format(
                                            @"Type '{0}' does not have a default(parameterless) public constructor! ", type));
                }
            }