internal void HandleDataSet(XmlSchemaElement node, bool isNewDataSet)
{
string dsName = node.Name;
string dsNamespace = node.QualifiedName.Namespace;
int initialTableCount = _ds.Tables.Count; // just use for inference backward compatablity
List<DataTable> tableSequenceList = new List<DataTable>();
string value = GetMsdataAttribute(node, Keywords.MSD_LOCALE);
if (null != value)
{ // set by user
if (0 != value.Length)
{
// <... msdata:Locale="en-US"/>
_ds.Locale = new CultureInfo(value);
}
else
{
_ds.Locale = CultureInfo.InvariantCulture;
}
}
else
{ // not set by user
// MSD_LOCALE overrides MSD_USECURRENTLOCALE
if (GetBooleanAttribute(node, Keywords.MSD_USECURRENTLOCALE, false))
{
_ds.SetLocaleValue(CultureInfo.CurrentCulture, false);
}
else
{
// everett behavior before <... msdata:UseCurrentLocale="true"/>
_ds.SetLocaleValue(new CultureInfo(0x409), false);
}
}
// reuse variable
value = GetMsdataAttribute(node, Keywords.MSD_DATASETNAME);
if (value != null && value.Length != 0)
{
dsName = value;
}
value = GetMsdataAttribute(node, Keywords.MSD_DATASETNAMESPACE);
if (value != null && value.Length != 0)
{
dsNamespace = value;
}
SetProperties(_ds, node.UnhandledAttributes);
SetExtProperties(_ds, node.UnhandledAttributes);
if (dsName != null && dsName.Length != 0)
_ds.DataSetName = XmlConvert.DecodeName(dsName);
// _ds.Namespace = node.QualifiedName.Namespace;
_ds.Namespace = dsNamespace;
if (FromInference)
_ds.Prefix = GetPrefix(_ds.Namespace);
XmlSchemaComplexType ct = (XmlSchemaComplexType)FindTypeNode(node);
if (ct.Particle != null)
{
XmlSchemaObjectCollection items = GetParticleItems(ct.Particle);
if (items == null)
{
return;
}
foreach (XmlSchemaAnnotated el in items)
{
if (el is XmlSchemaElement)
{
if (((XmlSchemaElement)el).RefName.Name.Length != 0)
{
if (!FromInference)
{
continue;
}
else
{
DataTable tempTable = _ds.Tables.GetTable(XmlConvert.DecodeName(GetInstanceName((XmlSchemaElement)el)), node.QualifiedName.Namespace);
if (tempTable != null)
{
tableSequenceList.Add(tempTable); // if ref table is created, add it
}
bool isComplexTypeOrValidElementType = false;
if (node.ElementSchemaType != null || !(((XmlSchemaElement)el).SchemaType is XmlSchemaComplexType))
{
isComplexTypeOrValidElementType = true;
}
// bool isComplexTypeOrValidElementType = (node.ElementType != null || !(((XmlSchemaElement)el).SchemaType is XmlSchemaComplexType));
if ((((XmlSchemaElement)el).MaxOccurs != decimal.One) && (!isComplexTypeOrValidElementType))
{
continue;
}
}
}
DataTable child = HandleTable((XmlSchemaElement)el);
if (child != null)
{
child._fNestedInDataset = true;
}
if (FromInference)
{
tableSequenceList.Add(child);
}
}
else if (el is XmlSchemaChoice)
{ // should we check for inference?
XmlSchemaObjectCollection choiceItems = ((XmlSchemaChoice)el).Items;
if (choiceItems == null)
continue;
foreach (XmlSchemaAnnotated choiceEl in choiceItems)
{
if (choiceEl is XmlSchemaElement)
{
if (((XmlSchemaParticle)el).MaxOccurs > decimal.One && (((XmlSchemaElement)choiceEl).SchemaType is XmlSchemaComplexType)) // amir
((XmlSchemaElement)choiceEl).MaxOccurs = ((XmlSchemaParticle)el).MaxOccurs;
if ((((XmlSchemaElement)choiceEl).RefName.Name.Length != 0) && (!FromInference && ((XmlSchemaElement)choiceEl).MaxOccurs != decimal.One && !(((XmlSchemaElement)choiceEl).SchemaType is XmlSchemaComplexType)))
continue;
DataTable child = HandleTable((XmlSchemaElement)choiceEl);
if (FromInference)
{
tableSequenceList.Add(child);
}
if (child != null)
{
child._fNestedInDataset = true;
}
}
}
}
}
}
// Handle the non-nested keyref constraints
if (node.Constraints != null)
{
foreach (XmlSchemaIdentityConstraint key in node.Constraints)
{
XmlSchemaKeyref keyref = key as XmlSchemaKeyref;
if (keyref == null)
continue;
bool isNested = GetBooleanAttribute(keyref, Keywords.MSD_ISNESTED, /*default:*/ false);
if (isNested)
continue;
HandleKeyref(keyref);
}
}
if (FromInference && isNewDataSet)
{
List<DataTable> _tableList = new List<DataTable>(_ds.Tables.Count);
foreach (DataTable dt in tableSequenceList)
{
AddTablesToList(_tableList, dt);
}
_ds.Tables.ReplaceFromInference(_tableList); // replace the list with the one in correct order: BackWard compatability for inference
}
}