Пример #1
0
        public DataSet GetDataSet()
        {
            ConstDataSetPoolEntry poolEntry = null;

            if (!globalPool.TryGetValue(DataSetXml, out poolEntry))
            {
                poolEntry = new ConstDataSetPoolEntry()
                {
                    OriginalDataSet = LoadDataSetFromXml(),
                    Pool            = new ConcurrentBag <ConstDataSet>()
                };
                globalPool[DataSetXml] = poolEntry;
            }
            if (ReadOnly)
            {
                ConstDataSet constDs = null;
                if (!poolEntry.Pool.TryTake(out constDs))
                {
                    constDs = (ConstDataSet)poolEntry.OriginalDataSet.Copy();
                    newInstanceCount++;
                    constDs.MakeReadOnlyColumns();
                    constDs.SubscribeOnChangeEvents();
                }
                localInstances.Add(constDs);
                return(constDs);
            }
            else
            {
                // global pool is not used in this case
                var ds = poolEntry.OriginalDataSet.Copy();
                newInstanceCount++;
                return(ds);
            }
        }
Пример #2
0
        internal ConstDataSet LoadDataSetFromXml()
        {
            var ds = new ConstDataSet();

            ds.ReadXml(new StringReader(DataSetXml), XmlReadMode.Auto);
            if (DataSetFactory != null)
            {
                var dsWithSchema = new ConstDataSet();
                foreach (DataTable t in ds.Tables)
                {
                    var schemaTblName = t.TableName;
                    if (SchemaMapping.ContainsKey(schemaTblName))
                    {
                        schemaTblName = SchemaMapping[schemaTblName];
                    }
                    var tblDs = DataSetFactory.GetDataSet(schemaTblName);
                    if (tblDs != null)
                    {
                        var schemaTbl = tblDs.Tables[schemaTblName].Clone();
                        schemaTbl.TableName = t.TableName;
                        dsWithSchema.Tables.Add(schemaTbl);
                    }
                }
                dsWithSchema.ReadXml(new StringReader(DataSetXml), XmlReadMode.Auto);
            }
            return(ds);
        }