/// <summary>
        /// Save a list of DG fields (all defined on the same grid) into the database.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="database"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public static ITimestepInfo SaveTimestep <T>(this IDatabaseInfo database, IEnumerable <T> fields) where T : DGField
        {
            if (fields.Count() < 1)
            {
                throw new ArgumentException("empty list");
            }
            DGField[] _fields = fields.Select(f => (DGField)f).ToArray <DGField>();

            IGridData gDat = _fields[0].GridDat;

            for (int i = 0; i < _fields.Length; i++)
            {
                if (!object.ReferenceEquals(gDat, _fields[i].GridDat))
                {
                    throw new ArgumentException("Mismatch of grids: DG field #" + i + " is defined on a different grid than the previous ones.");
                }
            }

            var grid = gDat.Grid;

            if (grid.ID.Equals(Guid.Empty) || database.Grids.Where(g => g.ID.Equals(grid.ID)).Count() < 1)
            {
                // its necessary to save the grid to the database first

                /*
                 * var gridNew = SaveGrid(database, grid);
                 * if(!object.ReferenceEquals(gridNew, grid)) {
                 *  for (int i = 0; i < _fields.Length; i++) {
                 *      DGField fOld = _fields[i];
                 *      if(fOld.GetType() != typeof(SinglePhaseField)) {
                 *          throw
                 *      }
                 *  }
                 * }
                 */

                // note: calling save grid would be easy,
                // but that would require re-creation of the DG fields on the new grid,
                // if 'SaveGrid' returns some *other* grid object that is already present in the database.

                throw new ArgumentException("Grid is not stored in database; Save the grid to database in order to use this method.");
            }

            SessionInfo dummySession = new SessionInfo(Guid.NewGuid(), database);

            dummySession.Name        = "InitialValueSession";
            dummySession.ProjectName = InteractiveShell.WorkflowMgm.CurrentProject;
            dummySession.Save();

            var tsi = new TimestepInfo(0.0, dummySession, 0, _fields);

            database.Controller.DBDriver.SaveTimestep(tsi);
            return(tsi);
        }
Beispiel #2
0
            public object this[string key] {
                get {
                    if (key == null)
                    {
                        throw new ArgumentNullException();
                    }
                    int idx = m_Keys.IndexOf(key, (a, b) => a.Equals(b));
                    if (idx < 0)
                    {
                        throw new KeyNotFoundException();
                    }

                    return(m_Values[idx]);
                }
                set {
                    if (key == null)
                    {
                        throw new ArgumentNullException();
                    }
                    TestSerializibility(value);

                    int idx = m_Keys.IndexOf(key, (a, b) => a.Equals(b));
                    if (idx < 0)
                    {
                        Array.Resize(ref this.m_Keys, this.m_Keys.Length + 1);
                        Array.Resize(ref this.m_Values, this.m_Values.Length + 1);

                        this.m_Keys[this.m_Keys.Length - 1]     = key;
                        this.m_Values[this.m_Values.Length - 1] = value;
                    }
                    else
                    {
                        m_Values[idx] = value;
                    }
                    if (m_Owner != null)
                    {
                        m_Owner.Save();
                    }
                }
            }
Beispiel #3
0
        /// <summary>
        /// Copies this IDatabaseObjectInfo object for storage in a different database.
        /// </summary>
        /// <param name="targetDatabase">The target database</param>
        /// <returns>
        /// A copy of this IDatabaseObjectInfo object with all the same
        /// information, except for the database field, which will be the one of the
        /// target database
        /// </returns>
        public ISessionInfo CopyFor(IDatabaseInfo targetDatabase)
        {
            SessionInfo copy = new SessionInfo(this.ID, targetDatabase);

            // Copy all the field values
            foreach (var field in this.GetType().GetFields(BindingFlags.Public
                                                           | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                field.SetValue(copy, field.GetValue(this));
            }

            copy.m_Database = targetDatabase; // only field with different value
            copy.Save();                      // to commit changes

            return(copy);
        }