Exemple #1
0
            /// <summary>
            /// parses an <see cref="InsertBatchQuery"/> from <paramref name="tableDataXmlDocument"/>.
            /// </summary>
            /// <seealso cref="InsertBatchQuery.Parse(XmlNode)"/>
            /// <param name="tableDataXmlDocument"></param>
            /// <returns>
            /// <see cref="InsertBatchQuery"/> parsed from <paramref name="tableDataXmlDocument"/>
            /// </returns>
            /// <exception cref="InvalidFileXmlDocumentException">
            /// thrown if parsing <see cref="InsertBatchQuery"/> failed
            /// </exception>
            public static InsertBatchQuery ParseInsertBatchQuery(FileXmlDocument tableDataXmlDocument)
            {
                try
                {
                    InsertBatchQuery insertBatchQuery;

                    // get table data xml node
                    XmlNode tableDataXmlNode = tableDataXmlDocument.GetNodes("table")[0];

                    insertBatchQuery = InsertBatchQuery.Parse(tableDataXmlNode);

                    return(insertBatchQuery);
                }
                catch (Exception exception)
                {
                    // parsing InsertBatchQuery failed
                    if (
                        exception is XmlNodeMissingNodeException ||
                        exception is InsertBatchQueryParseException)
                    {
                        throw new InvalidFileXmlDocumentException(
                                  tableDataXmlDocument,
                                  exception);
                    }
                    else // unhandled exception
                    {
                        throw exception;
                    }
                }
            }
Exemple #2
0
            /// <summary>
            /// parses an <see cref="InsertQuery"/> array from <paramref name="tableDataXmlDocument"/>.
            /// </summary>
            /// <seealso cref="ParseInsertBatchQuery(FileXmlDocument)"/>
            /// <param name="tableDataXmlDocument"></param>
            /// <returns>
            /// <see cref="InsertQuery"/> array parsed from <paramref name="tableDataXmlDocument"/>
            /// </returns>
            /// <exception cref="InvalidFileXmlDocumentException">
            /// <seealso cref="ParseInsertQueries(FileXmlDocument)"/>
            /// </exception>
            public static InsertQuery[] ParseInsertQueries(FileXmlDocument tableDataXmlDocument)
            {
                InsertQuery[] insertQueries;

                InsertBatchQuery insertBatchQuery = ParseInsertBatchQuery(tableDataXmlDocument);

                insertQueries = insertBatchQuery.InsertQueries;

                return(insertQueries);
            }
            /// <summary>
            /// parses <see cref="InsertBatchQuery"/> from <paramref name="tableDataXmlNode"/>.
            /// </summary>
            /// <param name="tableDataXmlNode"></param>
            /// <returns>
            /// <see cref="InsertBatchQuery"/> parsed from <paramref name="tableDataXmlNode"/>
            /// </returns>
            /// <exception cref="InsertBatchQueryParseException">
            /// thrown if <see cref="InsertBatchQuery"/> parse failed
            /// </exception>
            public static InsertBatchQuery Parse(XmlNode tableDataXmlNode)
            {
                try
                {
                    InsertBatchQuery insertBatchQuery;

                    // get table name
                    string tableName = tableDataXmlNode.GetAttributeValue("name");

                    // parse InsertQueries from row data XmlNodeList
                    XmlNodeList rowDataXmlNodeList = tableDataXmlNode.GetNodes("row");

                    InsertQuery[] insertQueries = new InsertQuery[rowDataXmlNodeList.Count];

                    for (int i = 0; i < rowDataXmlNodeList.Count; i++)
                    {
                        XmlNode rowDataXmlNode = rowDataXmlNodeList[i];
                        insertQueries[i] = InsertQuery.Parse(rowDataXmlNode, tableName);
                    }

                    insertBatchQuery = new InsertBatchQuery(tableName, insertQueries);

                    return(insertBatchQuery);
                }
                catch (Exception exception)
                {
                    // exception while trying to parse InsertBatch
                    if (
                        exception is XmlNodeMissingNodeException ||
                        exception is XmlNodeMissingAttributeException ||
                        exception is InsertQueryParseException)
                    {
                        throw new InsertBatchQueryParseException(null, exception);
                    }
                    else // unhandled exception
                    {
                        throw exception;
                    }
                }
            }