Example #1
0
        private void InternalCreateDataTable(DataTableBase dataTable, Stream stream)
        {
            IEnumerable <GameFrameworkSegment <Stream> > dataRowSegments = null;

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

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

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

            foreach (GameFrameworkSegment <Stream> dataRowSegment in dataRowSegments)
            {
                if (!dataTable.AddDataRow(dataRowSegment))
                {
                    throw new GameFrameworkException("Add data row failure.");
                }
            }
        }
        private void InternalCreateDataTable(DataTableBase dataTable, object dataTableData)
        {
            GameFrameworkDataSegment[] dataRowSegments = null;
            object dataTableUserData = null;

            try
            {
                dataRowSegments   = m_DataTableHelper.GetDataRowSegments(dataTableData);
                dataTableUserData = m_DataTableHelper.GetDataTableUserData(dataTableData);
            }
            catch (Exception exception)
            {
                if (exception is GameFrameworkException)
                {
                    throw;
                }

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

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

            foreach (GameFrameworkDataSegment dataRowSegment in dataRowSegments)
            {
                if (!dataTable.AddDataRow(dataRowSegment, dataTableUserData))
                {
                    throw new GameFrameworkException("Add data row failure.");
                }
            }
        }
Example #3
0
        /// <summary>
        /// 创建数据表。
        /// </summary>
        /// <param name="dataRowType">数据表行的类型。</param>
        /// <param name="name">数据表名称。</param>
        /// <param name="text">要解析的数据表文本。</param>
        /// <returns>要创建的数据表。</returns>
        public DataTableBase CreateDataTable(Type dataRowType, string name, string text)
        {
            if (dataRowType == null)
            {
                throw new GameFrameworkException("Data row type is invalid.");
            }

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

            if (HasDataTable(dataRowType, name))
            {
                throw new GameFrameworkException(string.Format("Already exist data table '{0}'.", Utility.Text.GetFullName(dataRowType, name)));
            }

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

            string[] dataRowTexts = m_DataTableHelper.SplitToDataRows(text);
            foreach (string dataRowText in dataRowTexts)
            {
                dataTable.AddDataRow(dataRowText);
            }

            m_DataTables.Add(Utility.Text.GetFullName(dataRowType, name), dataTable);
            return(dataTable);
        }