private void ProcessInlineSchema()
 {
     if (!inlineSchemaParser.ParseReaderNode())   // Done
     {
         inlineSchemaParser.FinishParsing();
         XmlSchema schema   = inlineSchemaParser.XmlSchema;
         string    inlineNS = null;
         if (schema != null && schema.ErrorCount == 0)
         {
             try {
                 SchemaInfo inlineSchemaInfo = new SchemaInfo();
                 inlineSchemaInfo.SchemaType = SchemaType.XSD;
                 inlineNS = schema.TargetNamespace == null? string.Empty : schema.TargetNamespace;
                 if (!SchemaInfo.TargetNamespaces.ContainsKey(inlineNS))
                 {
                     if (SchemaCollection.Add(inlineNS, inlineSchemaInfo, schema, true) != null)   //If no errors on compile
                     //Add to validator's SchemaInfo
                     {
                         SchemaInfo.Add(inlineSchemaInfo, EventHandler);
                     }
                 }
             }
             catch (XmlSchemaException e) {
                 SendValidationEvent(Res.Sch_CannotLoadSchema, new string[] { BaseUri.AbsoluteUri, e.Message }, XmlSeverityType.Error);
             }
         }
         inlineSchemaParser = null;
     }
 }
예제 #2
0
        private DbTypeInfo GetDbTypeInfo <TEntity>()
            where TEntity : IDbEntity, new()
        {
            Type       entityType = typeof(TEntity);
            DbTypeInfo entityDbTypeInfo;

            if (!DbConnection.dbTypeInfo.TryGetValue(entityType, out entityDbTypeInfo))
            {
                IDbEntity        defaultEntity          = new TEntity();
                SchemaCollection entitySchemaCollection = new SchemaCollection();

                foreach (DbOperationInfo operation in defaultEntity.DbOperations.Values)
                {
                    if (operation.ParameterType != null && !entitySchemaCollection.Contains(operation.ParameterType))
                    {
                        DataTable schemaTable = this.GetSchema(operation.ParameterType);
                        entitySchemaCollection.Add(schemaTable);
                    }
                }

                entityDbTypeInfo = new DbTypeInfo()
                {
                    DefaultEntity = defaultEntity,
                    SchemaInfo    = entitySchemaCollection
                };

                DbConnection.dbTypeInfo[entityType] = entityDbTypeInfo;
            }

            return(entityDbTypeInfo);
        }
예제 #3
0
        public void Add_NullContentType_ShouldThrowException()
        {
            var schemaCollection = new SchemaCollection();
            var schema           = new JSchema(JsonSchemaType.Any, new JsonSchemaExtendedType());

            Assert.Throws <ArgumentNullException>(() => schemaCollection.Add(null, schema));
        }
예제 #4
0
        private void LoadSchemaFromLocation(string uri, string url)
        {
            XmlReader  reader     = null;
            SchemaInfo schemaInfo = null;

            try
            {
                Uri    ruri = this.XmlResolver.ResolveUri(BaseUri, url);
                Stream stm  = (Stream)this.XmlResolver.GetEntity(ruri, null, null);
                reader = new XmlTextReader(ruri.ToString(), stm, NameTable);
                //XmlSchema schema = SchemaCollection.Add(uri, reader, this.XmlResolver);

                Parser parser = new Parser(SchemaType.XSD, NameTable, SchemaNames, EventHandler);
                parser.XmlResolver = this.XmlResolver;
                SchemaType schemaType = parser.Parse(reader, uri);

                schemaInfo            = new SchemaInfo();
                schemaInfo.SchemaType = schemaType;
                if (schemaType == SchemaType.XSD)
                {
                    if (SchemaCollection.EventHandler == null)
                    {
                        SchemaCollection.EventHandler = this.EventHandler;
                    }
                    SchemaCollection.Add(uri, schemaInfo, parser.XmlSchema, true);
                }
                //Add to validator's SchemaInfo
                SchemaInfo.Add(schemaInfo, EventHandler);

                while (reader.Read())
                {
                    ;                  // wellformness check
                }
            }
            catch (XmlSchemaException e)
            {
                schemaInfo = null;
                SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Error);
            }
            catch (Exception e)
            {
                schemaInfo = null;
                SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Warning);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
예제 #5
0
        private void LoadSchemaFromLocation(string uri)
        {
            // is x-schema
            if (!XdrBuilder.IsXdrSchema(uri))
            {
                return;
            }
            string     url       = uri.Substring(x_schema.Length);
            XmlReader  reader    = null;
            SchemaInfo xdrSchema = null;

            try
            {
                Uri    ruri = this.XmlResolver.ResolveUri(BaseUri, url);
                Stream stm  = (Stream)this.XmlResolver.GetEntity(ruri, null, null);
                reader = new XmlTextReader(ruri.ToString(), stm, NameTable);
                ((XmlTextReader)reader).XmlResolver = this.XmlResolver;
                Parser parser = new Parser(SchemaType.XDR, NameTable, SchemaNames, EventHandler);
                parser.XmlResolver = this.XmlResolver;
                parser.Parse(reader, uri);
                while (reader.Read())
                {
                    ;                  // wellformness check
                }
                xdrSchema = parser.XdrSchema;
            }
            catch (XmlSchemaException e)
            {
                SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Error);
            }
            catch (Exception e)
            {
                SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Warning);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            if (xdrSchema != null && xdrSchema.ErrorCount == 0)
            {
                schemaInfo.Add(xdrSchema, EventHandler);
                SchemaCollection.Add(uri, xdrSchema, null, false);
            }
        }
예제 #6
0
 private void ProcessInlineSchema()
 {
     if (!_inlineSchemaParser.ParseReaderNode())
     { // Done
         _inlineSchemaParser.FinishParsing();
         SchemaInfo xdrSchema = _inlineSchemaParser.XdrSchema;
         if (xdrSchema != null && xdrSchema.ErrorCount == 0)
         {
             foreach (string inlineNS in xdrSchema.TargetNamespaces.Keys)
             {
                 if (!this.schemaInfo.HasSchema(inlineNS))
                 {
                     schemaInfo.Add(xdrSchema, EventHandler);
                     SchemaCollection.Add(inlineNS, xdrSchema, null, false);
                     break;
                 }
             }
         }
         _inlineSchemaParser = null;
     }
 }
예제 #7
0
        /// <summary>
        /// Gets the tables.
        /// </summary>
        /// <returns>The tables.</returns>
        public SchemaCollection GetTables()
        {
            SchemaCollection list = new SchemaCollection();

            using (SqlConnection connection = this.CreateConnection())
            {
                this.Logger.Write("Opening connection for table list");

                SqlCommand command = connection.CreateCommand();
                command.CommandText = @"
                SELECT h.name + '.' + s.name AS name, s.object_id, s.modify_date
                FROM sys.tables s
                INNER JOIN sys.schemas h
                    ON h.schema_id = s.schema_id
                WHERE s.type = 'U'
                ORDER BY s.name";

                command.CommandType = CommandType.Text;

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(new SchemaData()
                            {
                                Name = (string)reader["name"],
                                ObjectID = (int)reader["object_id"],
                                Type = SchemaDataType.Table,
                                Data = this.GetTableSchema((int)reader["object_id"]),
                                ModifyDate = (DateTime)reader["modify_date"]
                            });
                    }
                }
            }

            return list;
        }
예제 #8
0
        public void Add_NullSchema_ShouldThrowException()
        {
            var schemaCollection = new SchemaCollection();

            Assert.Throws <ArgumentNullException>(() => schemaCollection.Add("contentType", null));
        }