Exemple #1
0
        public SnapView loadData(SnapViewDirector svd)
        {
            // Create root level snapview here (passing in the SnapViewDirector)
            _initial_SnapView = new SnapView(svd);

            // Initialise it
            XmlInit svInit = new XmlInit();

            svInit.initSnapView(_initial_SnapView);

            return(_initial_SnapView);
        }
Exemple #2
0
        // Main parent method which calls the other methods
        public void initSnapView(SnapView sv)
        {
            // First load the xml from disk, and validate against the xsd
            loadAndValidateXml();

            // Then given the schema read in from the xsd, pull out the meta-data
            FieldDictionary dict = fillFieldDictionary(fsSchema, sv);

            // Set the meta-data for the SnapView
            sv.setDict(dict);

            // Finally, pull out the table from the xml file
            fillSnapViewTable(sv);
        } //method
Exemple #3
0
        public void fillSnapViewTable(SnapView sv)
        {
            // LINQ query to return a list of rows
            var rowList = from row in xdoc.Descendants(config.xmlRootName).Descendants(config.xmlRowName)
                          select new
            {
                fieldList = row.Descendants()
            };

            // Loop over the rows
            foreach (var row in rowList)
            {
                // Have to iterate over row twice: once to find its size, so
                // the array can be created; second to fill the array.
                // This is because IEnumerable<T> doesn't provide a way of knowing
                // the number of elements in the collection without iterating over them all.

                int arr_size = 0;

                foreach (var field in row.fieldList)
                {
                    arr_size++;
                }//foreach

                // Create the string array
                string[] row_array = new string[arr_size];

                int arr_idx = 0;

                Console.WriteLine("Another row");
                // Loop over the fields in the row
                foreach (var field in row.fieldList)
                {
                    Console.WriteLine("  Another field: ");
                    Console.WriteLine(field.Value.ToString());

                    // Add string to array

                    row_array[arr_idx] = field.Value.ToString();
                    arr_idx++;
                }//foreach loop over fields in a row

                // Add row to the SnapView datastructure
                SVRow svr = new SVRow();
                svr.row = row_array;
                sv.addRow(svr);
            }//foreach loop over rows
        }
Exemple #4
0
        // Initialise the svd
        public void init_svd()
        {
            // Only the initial init if there is not already an entry for the svd in the current session:
            if (GetFromSession <SnapViewDirector>("svd") == null)
            {
                // Order is important as snapview needs svd in its constructor -> So create it before snapview
                SnapViewDirector svd_local = new SnapViewDirector();

                SnapView snapview = null;

                // If the _initial_SnapView static member is null - read from disk (once per app instance)
                // Otherwise copy the _initial_SnapView (once per new session)
                if (_initial_SnapView == null)
                {
                    snapview = loadData(svd_local);
                }
                else
                {
                    // Copy the initial snapview (contains a deep copy of the table, but shallow copy of the dict)
                    snapview = new SnapView(svd_local, _initial_SnapView);
                }

                // And register the snapview with the director
                svd_local.Attach(snapview);


                // Set this for the current session
                SetInSession("svd", svd_local);
            }
            //else
            //{
            //    // If init has been called, but an svd already exists - reinitialise this svd.
            //    // (This occurs if the user closes the window in the session, and navigates to the root SelectPlayer page)

            //    // The setter automatically cleans out an exisiting svd in the session if its there.
            //    svd = new SnapViewDirector();

            //    // Property getter.
            //    SnapViewDirector svd_ref = svd;


            //    SnapView snapview = new SnapView(svd, _initial_SnapView);
            //    svd.Attach(snapview);
            //}
        }
Exemple #5
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);
        }