コード例 #1
0
        private void InternalCreateDataTable(DataTableBase dataTable, Stream stream)
        {
            IEnumerable <GXSegment <Stream> > dataRowSegments = null;

            try
            {
                dataRowSegments = m_DataTableHelper.GetDataRowSegments(stream);
            }
            catch (Exception exception)
            {
                if (exception is GXException)
                {
                    throw;
                }

                throw new GXException(Utility.Text.Format("Can not get data row segments with exception '{0}'.", exception.ToString()), exception);
            }

            if (dataRowSegments == null)
            {
                throw new GXException("Data row segments is invalid.");
            }

            foreach (GXSegment <Stream> dataRowSegment in dataRowSegments)
            {
                if (!dataTable.AddDataRow(dataRowSegment))
                {
                    throw new GXException("Add data row failure.");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 创建数据表。
        /// </summary>
        /// <param name="dataRowType">数据表行的类型。</param>
        /// <param name="name">数据表名称。</param>
        /// <param name="stream">要解析的数据表二进制流。</param>
        /// <returns>要创建的数据表。</returns>
        public DataTableBase CreateDataTable(Type dataRowType, string name, Stream stream)
        {
            if (dataRowType == null)
            {
                throw new GXException("Data row type is invalid.");
            }

            if (!typeof(IDataRow).IsAssignableFrom(dataRowType))
            {
                throw new GXException(Utility.Text.Format("Data row type '{0}' is invalid.", dataRowType.FullName));
            }

            TypeNamePair typeNamePair = new TypeNamePair(dataRowType, name);

            if (HasDataTable(dataRowType, name))
            {
                throw new GXException(Utility.Text.Format("Already exist data table '{0}'.", typeNamePair.ToString()));
            }

            Type          dataTableType = typeof(DataTable <>).MakeGenericType(dataRowType);
            DataTableBase dataTable     = (DataTableBase)Activator.CreateInstance(dataTableType, name);

            InternalCreateDataTable(dataTable, stream);
            m_DataTables.Add(typeNamePair, dataTable);
            return(dataTable);
        }
コード例 #3
0
        /// <summary>
        /// 销毁数据表。
        /// </summary>
        /// <param name="dataTable">要销毁的数据表。</param>
        /// <returns>是否销毁数据表成功。</returns>
        public bool DestroyDataTable(DataTableBase dataTable)
        {
            if (dataTable == null)
            {
                throw new GXException("Data table is invalid.");
            }

            return(InternalDestroyDataTable(new TypeNamePair(dataTable.Type, dataTable.Name)));
        }
コード例 #4
0
        private DataTableBase InternalGetDataTable(TypeNamePair typeNamePair)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(typeNamePair, out dataTable))
            {
                return(dataTable);
            }

            return(null);
        }
コード例 #5
0
        private bool InternalDestroyDataTable(TypeNamePair typeNamePair)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(typeNamePair, out dataTable))
            {
                dataTable.Shutdown();
                return(m_DataTables.Remove(typeNamePair));
            }

            return(false);
        }
コード例 #6
0
        /// <summary>
        /// 获取所有数据表。
        /// </summary>
        /// <returns>所有数据表。</returns>
        public DataTableBase[] GetAllDataTables()
        {
            int index = 0;

            DataTableBase[] results = new DataTableBase[m_DataTables.Count];
            foreach (KeyValuePair <TypeNamePair, DataTableBase> dataTable in m_DataTables)
            {
                results[index++] = dataTable.Value;
            }

            return(results);
        }