Пример #1
0
        /// <summary>
        /// Get the column metatada from the DataReader and store it in a Dictionary
        /// This Dictionary could be cached for better performances
        /// </summary>
        /// <param name="dr">IDataReader from which obtaining metadata</param>
        /// <returns>The dictionary</returns>
        public static FieldDictionary GetFields(IDataReader dr)
        {
            int             FieldCount = dr.FieldCount;
            FieldDictionary dic        = new FieldDictionary(FieldCount);

            for (int i = 0; i < FieldCount; i++)
            {
                dic.Add(dr.GetName(i), i);
            }
            return(dic);
        }
Пример #2
0
        public FieldDictionary fillFieldDictionary(XmlSchema schema, SnapView sv)
        {
            // Create a new FieldDictionary to fill:
            FieldDictionary return_dict = new FieldDictionary(10); // this is growable.

            // Iterate over the schema and process appinfo
            // NOTE: this code is totally unproteced from unhandled exceptions (To fix: 30/7/13)
            // The structure of this code totally depends on the form of the xsd file.
            // WARNING: If you change the xsd file - this code will become invalid (code weakness)
            foreach (XmlSchemaObject xso in schema.Items)
            {
                XmlSchemaComplexType xsa = xso as XmlSchemaComplexType;

                if (xsa != null)
                {
                    string comment =
                        //    ((XmlSchemaDocumentation)xsa.Items[0]).Markup[0].InnerText;
                        xsa.Name; // THIS is where we got to. Look at MSDN article "Traversing XML Schemas"
                    Console.WriteLine(comment);

                    // Only consider gameRowType block
                    if (xsa.Name == config.xsdFieldBlockName)
                    {
                        Console.WriteLine("Inside gameRowType if");


                        // Get the sequence particle of the complex type.
                        XmlSchemaSequence sequence = xsa.ContentTypeParticle as XmlSchemaSequence;


                        // Initial value of address for the fields (0)
                        int current_field_address = 0;

                        // Iterate over each XmlSchemaElement in the Items collection.
                        foreach (XmlSchemaElement childElement in sequence.Items)
                        {
                            Console.WriteLine("Element: {0}", childElement.Name);

                            string field_name = childElement.Name;

                            // Iterate over appinfo
                            XmlSchemaAnnotation annotation = childElement.Annotation;

                            // Iterate over Items to find appinfo
                            foreach (XmlSchemaObject xso2 in annotation.Items)
                            {
                                XmlSchemaAppInfo ai = xso2 as XmlSchemaAppInfo;
                                Console.WriteLine("     Markup[0] displayStr : " + (ai.Markup[0]).Attributes[config.xsdFieldName_displayStr].InnerText);
                                Console.WriteLine("     Markup[0] descStr : " + (ai.Markup[0]).Attributes[config.xsdFieldName_descStr].InnerText);

                                string field_displayStr = (ai.Markup[0]).Attributes[config.xsdFieldName_displayStr].InnerText;
                                string field_descStr    = (ai.Markup[0]).Attributes[config.xsdFieldName_descStr].InnerText;


                                // NOTE: we may want to construct the field outside this foreach
                                // Now we can construct the Field object and add it to the FieldDictionary
                                Field f = new Field(field_name, field_displayStr, field_descStr, current_field_address, sv);

                                // Increment field address
                                current_field_address++;

                                // Add field to the dictionary
                                // NOTE: one of the few accesses to a SnapView data member.
                                return_dict.Add(f);
                            }//foreach
                        }


                        // NEED some kind of protection for not finding anything (i.e., fails to find any entries at all)
                    } //if
                }     //if
            }         //foreach (loop over xsd top level elements)



            return(return_dict);
        }