Example #1
0
        public static IEnumerable <IFxtTransformation> Deanonymize(
            this XmlSchemaSet schemas, // the schemas to transform
            FxtScope scope,            // affected abstractions
            bool strict,               // be strict about de-anonymization
            FxtLog log                 // log transformations and analyses
            )
        {
            // Determine potential ambiguity of local element names
            var recurrence = new Dictionary <string, int>();

            foreach (var el in schemas.LocalXsdElements())
            {
                if (el.SchemaType != null &&
                    el.SchemaType is XmlSchemaComplexType)
                {
                    if (!recurrence.ContainsKey(el.Name))
                    {
                        recurrence.Add(el.Name, 1);
                    }
                    else
                    {
                        recurrence[el.Name]++;
                    }
                }
            }

            foreach (var el in schemas.LocalXsdElements())
            {
                // Test whether element is affected
                if (el.SchemaType != null &&
                    el.SchemaType is XmlSchemaComplexType &&
                    scope.Test(el))
                {
                    // Determine name of new type
                    var qname = new XmlQualifiedName(
                        el.Name,
                        el.XmlSchema().TargetNamespace);

                    // Check for name clashes
                    if (schemas.DefinesXsdType(qname) ||
                        recurrence[el.Name] > 1)
                    {
                        if (!strict)
                        {
                            continue; // Skip this candidate
                        }
                        else
                        {
                            throw new FxtTypeClashException(qname);
                        }
                    }

                    // Build and yield transformation
                    var trafo = new ExtractType();
                    trafo.element = el;
                    log.AtType(qname).Add(new ExtractTypeAnnotation());
                    yield return(trafo);
                }
            }
        }
Example #2
0
        public static IEnumerable<IFxtTransformation> Deanonymize(
            this XmlSchemaSet schemas,  // the schemas to transform
            FxtScope scope,             // affected abstractions
            bool strict,                // be strict about de-anonymization
            FxtLog log                  // log transformations and analyses
            )
        {

            // Determine potential ambiguity of local element names
            var recurrence = new Dictionary<string,int>();
            foreach (var el in schemas.LocalXsdElements())
                if (el.SchemaType!=null
                    && el.SchemaType is XmlSchemaComplexType)
                    if (!recurrence.ContainsKey(el.Name))
                        recurrence.Add(el.Name,1);
                    else
                        recurrence[el.Name]++;

            foreach (var el in schemas.LocalXsdElements())

                // Test whether element is affected
                if (el.SchemaType!=null
                    && el.SchemaType is XmlSchemaComplexType
                    && scope.Test(el)) 
                {
                    // Determine name of new type
                    var qname = new XmlQualifiedName(
                        el.Name,
                        el.XmlSchema().TargetNamespace);

                    // Check for name clashes
                    if (schemas.DefinesXsdType(qname)
                        || recurrence[el.Name] > 1)
                        if (!strict)
                            continue; // Skip this candidate
                        else
                            throw new FxtTypeClashException(qname);

                    // Build and yield transformation
                    var trafo = new ExtractType();
                    trafo.element = el;
                    log.AtType(qname).Add(new ExtractTypeAnnotation());
                    yield return trafo;
                }
        }
        public static IEnumerable <IFxtTransformation> Deanonymize(this XmlSchemaSet schemas, FxtScope scope, bool strict, FxtLog log)
        {
            bool                     flag;
            bool                     flag1;
            bool                     flag2;
            XmlQualifiedName         xmlQualifiedName;
            Dictionary <string, int> strs = new Dictionary <string, int>();

            foreach (XmlSchemaElement xmlSchemaElement in schemas.LocalXsdElements())
            {
                flag = (xmlSchemaElement.SchemaType == null ? true : !(xmlSchemaElement.SchemaType is XmlSchemaComplexType));
                if (flag)
                {
                    continue;
                }
                if (strs.ContainsKey(xmlSchemaElement.Name))
                {
                    Dictionary <string, int> item  = strs;
                    Dictionary <string, int> strs1 = item;
                    string name = xmlSchemaElement.Name;
                    item[name] = strs1[name] + 1;
                }
                else
                {
                    strs.Add(xmlSchemaElement.Name, 1);
                }
            }
            IEnumerator <XmlSchemaElement> enumerator = schemas.LocalXsdElements().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    XmlSchemaElement current = enumerator.Current;
                    flag1 = (current.SchemaType == null || !(current.SchemaType is XmlSchemaComplexType) ? true : !scope.Test(current));
                    if (flag1)
                    {
                        continue;
                    }
                    xmlQualifiedName = new XmlQualifiedName(current.Name, current.XmlSchema().TargetNamespace);
                    flag2            = (schemas.DefinesXsdType(xmlQualifiedName) ? false : strs[current.Name] <= 1);
                    if (flag2)
                    {
                        ExtractType extractType = new ExtractType()
                        {
                            element = current
                        };
                        log.AtType(xmlQualifiedName).Add(new ExtractTypeAnnotation());
                        yield return(extractType);
                    }
                    else if (strict)
                    {
                        throw new FxtTypeClashException(xmlQualifiedName);
                    }
                }
                goto Label1;
                throw new FxtTypeClashException(xmlQualifiedName);
            }
            finally
            {
                if (enumerator != null)
                {
                    enumerator.Dispose();
                }
            }
Label1:
            yield break;
        }