Пример #1
0
        static void GenerateComponentCode(object component, SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeExpression cobj, CodeStatementCollection statements, CodeTypeDeclaration globalType, GenerationOptions options, List <SteticCompilationUnit> units, CodeIdentifiers ids, ArrayList warnings)
        {
            Gtk.Widget          widget  = component as Gtk.Widget;
            Wrapper.Widget      wwidget = Stetic.Wrapper.Widget.Lookup(widget);
            Wrapper.ActionGroup agroup  = component as Wrapper.ActionGroup;

            string name = widget != null ? widget.Name : agroup.Name;
            string internalClassName = ids.MakeUnique(CodeIdentifier.MakeValid(name));

            string typeName = widget != null ? wwidget.WrappedTypeName : "Gtk.ActionGroup";
            // Create the build method for the top level

            CodeMemberMethod met;

            met = GetBuildMethod(name, internalClassName, typeName, globalUnit, options, units);

            // Generate the build code

            CodeVariableDeclarationStatement varDecHash = new CodeVariableDeclarationStatement(typeof(System.Collections.Hashtable), "bindings");

            met.Statements.Add(varDecHash);
            varDecHash.InitExpression = new CodeObjectCreateExpression(
                typeof(System.Collections.Hashtable),
                new CodeExpression [0]
                );

            CodeVariableReferenceExpression targetObjectVar = new CodeVariableReferenceExpression("cobj");

            Stetic.WidgetMap map;

            if (widget != null)
            {
                map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, globalType, widget, targetObjectVar, met.Statements, options, warnings);
                CodeGenerator.BindSignalHandlers(targetObjectVar, wwidget, map, met.Statements, options);
            }
            else
            {
                map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, globalType, agroup, targetObjectVar, met.Statements, options, warnings);
                foreach (Wrapper.Action ac in agroup.Actions)
                {
                    CodeGenerator.BindSignalHandlers(targetObjectVar, ac, map, met.Statements, options);
                }
            }

            GenerateBindFieldCode(met.Statements, cobj);

            // Add a method call to the build method

            statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(options.GlobalNamespace + ".SteticGenerated." + internalClassName),
                    "Build",
                    new CodeCastExpression(typeName, cobj)
                    )
                );
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xsdFilename"></param>
        /// <param name="targetNamespace"></param>
        /// <returns></returns>
        public static CodeNamespace Process(string xsdFilename, string targetNamespace)
        {
            XmlReaderSettings settings = new XmlReaderSettings
            {
            };
            XmlSchema xsd;

            using (var reader = XmlReader.Create(xsdFilename))
            {
                xsd = XmlSchema.Read(reader, MyValidationEventHandler);
            }

            XmlSchemas schemas = new XmlSchemas(); // Internal class

            int elementCount = xsd.Elements.Count; // 0 Elements is a post-schema-compilation property
            int indexOf      = schemas.Add(xsd);   // Method will only add (to end) if it does not exists, and return the one stored internally

            elementCount = xsd.Elements.Count;     // 1 OOOPS! Looks like Add do some magic to added XmlSchema


            schemas.Compile(MyValidationEventHandler, true); // What is fullCompile?
            //var appinfos = xsd.Items.OfType<XmlSchemaAnnotation>().SelectMany(a => a.Items.OfType<XmlSchemaAppInfo>().SelectMany(m => m.Markup)).ToList();

            //foreach (var attr in xsd.UnhandledAttributes)
            //{
            //    Console.WriteLine("UnhandledAttribute: " + attr.LocalName);
            //}

            // Create the importer for these schemas.
            CodeDomProvider       codeProvider    = CodeDomProvider.CreateProvider("CSharp"); // shared import & export
            CodeGenerationOptions options         = CodeGenerationOptions.GenerateProperties; // shared import & export
            CodeIdentifiers       typeIdentifiers = new CodeIdentifiers();
            ImportContext         context         = new ImportContext(typeIdentifiers, true); // true=share custom types amongst schemas

            XmlSchemaImporter importer = new XmlSchemaImporter(schemas, options, context);


            // System.CodeDom namespace for the XmlCodeExporter to put classes in.
            CodeNamespace   ns = new CodeNamespace(targetNamespace);
            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
            Hashtable       mappings        = new Hashtable();

            XmlCodeExporter exporter = new XmlCodeExporter(ns, codeCompileUnit, options, mappings);

            // Test identifier uniqueness
            string s    = "FirstName";
            var    ustr = typeIdentifiers.MakeUnique(s); // FirstName

            ustr = typeIdentifiers.MakeUnique(s);        // FirstName
            typeIdentifiers.Add(s, s);
            ustr = typeIdentifiers.MakeUnique(s);        // FirstName1
            typeIdentifiers.Remove(s);
            ustr = typeIdentifiers.MakeUnique(s);        // FirstName
            typeIdentifiers.Add(s, s);


            // Iterate schema top-level elements and export code for each.
            foreach (XmlSchemaElement element in xsd.Elements.Values)
            {
                //var appinfos = element.Annotation.Items.OfType<XmlSchemaAppInfo>().ToArray();

                // Import the mapping first.
                var            ss      = typeIdentifiers.ToArray(typeof(string)); // 1
                XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);
                ss = typeIdentifiers.ToArray(typeof(string));                     // 2


                // Export the code finally.
                int count = mappings.Count; // 0
                exporter.ExportTypeMapping(mapping);
                count = mappings.Count;     // 5
            }

            foreach (var schemaType in xsd.SchemaTypes.Values.Cast <XmlSchemaType>())
            {
                var    map2 = importer.ImportSchemaType(schemaType.QualifiedName);
                string s2   = map2.TypeFullName;
            }
            return(ns);
        }
        internal SoapParameters(XmlMembersMapping request, XmlMembersMapping response, string[] parameterOrder, CodeIdentifiers identifiers)
        {
            ArrayList mappingsList = new ArrayList();
            ArrayList list2        = new ArrayList();

            AddMappings(mappingsList, request);
            if (response != null)
            {
                AddMappings(list2, response);
            }
            if (parameterOrder != null)
            {
                for (int i = 0; i < parameterOrder.Length; i++)
                {
                    string           elementName    = parameterOrder[i];
                    XmlMemberMapping requestMapping = FindMapping(mappingsList, elementName);
                    SoapParameter    parameter      = new SoapParameter();
                    if (requestMapping != null)
                    {
                        if (RemoveByRefMapping(list2, requestMapping))
                        {
                            parameter.codeFlags = CodeFlags.IsByRef;
                        }
                        parameter.mapping = requestMapping;
                        mappingsList.Remove(requestMapping);
                        this.AddParameter(parameter);
                    }
                    else
                    {
                        XmlMemberMapping mapping2 = FindMapping(list2, elementName);
                        if (mapping2 != null)
                        {
                            parameter.codeFlags = CodeFlags.IsOut;
                            parameter.mapping   = mapping2;
                            list2.Remove(mapping2);
                            this.AddParameter(parameter);
                        }
                    }
                }
            }
            foreach (XmlMemberMapping mapping3 in mappingsList)
            {
                SoapParameter parameter2 = new SoapParameter();
                if (RemoveByRefMapping(list2, mapping3))
                {
                    parameter2.codeFlags = CodeFlags.IsByRef;
                }
                parameter2.mapping = mapping3;
                this.AddParameter(parameter2);
            }
            if (list2.Count > 0)
            {
                if (!((XmlMemberMapping)list2[0]).CheckSpecified)
                {
                    this.ret = (XmlMemberMapping)list2[0];
                    list2.RemoveAt(0);
                }
                foreach (XmlMemberMapping mapping4 in list2)
                {
                    SoapParameter parameter3 = new SoapParameter {
                        mapping   = mapping4,
                        codeFlags = CodeFlags.IsOut
                    };
                    this.AddParameter(parameter3);
                }
            }
            foreach (SoapParameter parameter4 in this.parameters)
            {
                parameter4.name = identifiers.MakeUnique(CodeIdentifier.MakeValid(parameter4.mapping.MemberName));
            }
        }