예제 #1
0
파일: Compression.cs 프로젝트: bin09/Helper
 /// <summary>
 /// 取得序列化后的字节
 /// </summary>
 /// <param name="ds"></param>
 /// <returns></returns>
 public static byte[] GetDataSetSurrogateZipBytes(DataTable dt)
 {
     DataTableSurrogate dss = new DataTableSurrogate(dt);
     BinaryFormatter ser = new BinaryFormatter();
     MemoryStream ms = new MemoryStream();
     ser.Serialize(ms, dss);
     byte[] buffer = ms.ToArray();
     byte[] zipBuffer = Compress(buffer);
     return zipBuffer;
 }
예제 #2
0
        private ArrayList _relations; //An ArrayList of foreign key constraints : [relationName]->[parentTableIndex, parentcolumnIndexes]->[childTableIndex, childColumnIndexes]->[Nested]->[extendedProperties]

        #endregion Fields

        #region Constructors

        /*
            Constructs a DataSetSurrogate object from a DataSet.
        */
        public DataSetSurrogate(DataSet ds)
        {
            if (ds == null)
            {
                throw new ArgumentNullException("The parameter dataset is null");
            }

            //DataSet properties
            _datasetName = ds.DataSetName;
            _namespace = ds.Namespace;
            _prefix = ds.Prefix;
            _caseSensitive = ds.CaseSensitive;
            _locale = ds.Locale;
            _enforceConstraints = ds.EnforceConstraints;

            //Tables, Columns, Rows
            _dataTableSurrogates = new DataTableSurrogate[ds.Tables.Count];
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                _dataTableSurrogates[i] = new DataTableSurrogate(ds.Tables[i]);
            }

            //ForeignKeyConstraints
            _fkConstraints = GetForeignKeyConstraints(ds);

            //Relations
            _relations = GetRelations(ds);

            //ExtendedProperties
            _extendedProperties = new Hashtable();
            if (ds.ExtendedProperties.Keys.Count > 0)
            {
                foreach (object propertyKey in ds.ExtendedProperties.Keys)
                {
                    _extendedProperties.Add(propertyKey, ds.ExtendedProperties[propertyKey]);
                }
            }
        }