Example #1
0
        /// <summary>
        /// This event is fired AFTER the storedProcedure is parsed.
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="storedProcedure"></param>
        /// <returns>True if cancelled else false if not.</returns>
        public bool Parsed(XmlNode xmlNode, ref StoredProcedure storedProcedure)
        {
            // initial value
            bool cancel = false;

            // If the storedProcedure object exists
            if (NullHelper.Exists(storedProcedure))
            {
                // Decode the text
                storedProcedure.Text = XmlPatternHelper.Decode(storedProcedure.Text);

                // Create a new instance of a 'StoredProcedureParametersParser' object.
                StoredProcedureParametersParser parametersParser = new StoredProcedureParametersParser();

                // load the parameters if available
                storedProcedure.Parameters = parametersParser.ParseStoredProcedureParameters(xmlNode);

                // Create a new instance of a 'DataFieldsParser' object.
                ReturnSetSchemaParser returnSetSchemaParser = new ReturnSetSchemaParser();

                // load the ReturnSetSchema if available
                storedProcedure.ReturnSetSchema = returnSetSchemaParser.ParseDataFields(xmlNode);
            }

            // return value
            return(cancel);
        }
        // <Summary>
        // This method is used to export a StoredProcedure object to xml.
        // </Summary>
        public string ExportStoredProcedure(StoredProcedure storedProcedure, int indent = 0)
        {
            // initial value
            string storedProcedureXml = "";

            // locals
            string indentString  = TextHelper.Indent(indent);
            string indentString2 = TextHelper.Indent(indent + 2);

            // If the storedProcedure object exists
            if (NullHelper.Exists(storedProcedure))
            {
                // Create a StringBuilder
                StringBuilder sb = new StringBuilder();

                // Append the indentString
                sb.Append(indentString);

                // Write the open storedProcedure node
                sb.Append("<StoredProcedure>" + Environment.NewLine);

                // Write out each property

                // Write out the value for DoesNotHaveParameters

                sb.Append(indentString2);
                sb.Append("<DoesNotHaveParameters>" + storedProcedure.DoesNotHaveParameters + "</DoesNotHaveParameters>" + Environment.NewLine);

                // Write out the value for Parameters

                // Create the ParametersWriter
                ParametersWriter parametersWriter = new ParametersWriter();

                // Export the Parameters collection to xml
                string storedProcedureParameterXml = parametersWriter.ExportList(storedProcedure.Parameters, indent + 2);
                sb.Append(storedProcedureParameterXml);
                sb.Append(Environment.NewLine);

                // Write out the value for ProcedureName

                sb.Append(indentString2);
                sb.Append("<ProcedureName>" + storedProcedure.ProcedureName + "</ProcedureName>" + Environment.NewLine);

                // Write out the value for ReturnSetSchema

                // Create the ReturnSetSchemaWriter
                ReturnSetSchemaWriter returnSetSchemaWriter = new ReturnSetSchemaWriter();

                // Export the ReturnSetSchemas collection to xml
                string dataFieldXml = returnSetSchemaWriter.ExportList(storedProcedure.ReturnSetSchema, indent + 2);
                sb.Append(dataFieldXml);
                sb.Append(Environment.NewLine);

                // Write out the value for StoredProcedureType

                sb.Append(indentString2);
                sb.Append("<StoredProcedureType>" + storedProcedure.StoredProcedureType + "</StoredProcedureType>" + Environment.NewLine);

                // Write out the value for Text

                // I accidently overwrote this line making the video:
                // The xml has to be formatted if the procedure text contains any greater than or less than symbos or ampersands:
                string encodedText = XmlPatternHelper.Encode(storedProcedure.Text);

                sb.Append(indentString2);
                sb.Append("<Text>" + encodedText + "</Text>" + Environment.NewLine);

                // Append the indentString
                sb.Append(indentString);

                // Write out the close storedProcedure node
                sb.Append("</StoredProcedure>" + Environment.NewLine);

                // set the return value
                storedProcedureXml = sb.ToString();
            }
            // return value
            return(storedProcedureXml);
        }