public void RegisterSchema()
        {
            string groupName = TestEnvironment.SchemaRegistryGroup;

            #region Snippet:SchemaRegistryRegisterSchema
            string       name   = "employeeSample";
            SchemaFormat format = SchemaFormat.Avro;
            // Example schema's definition
            string definition = @"
            {
               ""type"" : ""record"",
                ""namespace"" : ""TestSchema"",
                ""name"" : ""Employee"",
                ""fields"" : [
                { ""name"" : ""Name"" , ""type"" : ""string"" },
                { ""name"" : ""Age"", ""type"" : ""int"" }
                ]
            }";

            Response <SchemaProperties> schemaProperties = client.RegisterSchema(groupName, name, definition, format);
            #endregion

            Assert.NotNull(schemaProperties);
            _schemaProperties = schemaProperties.Value;
            _definition       = definition;
        }
        public void RetrieveSchemaId()
        {
            string groupName = TestEnvironment.SchemaRegistryGroup;

            #region Snippet:SchemaRegistryRetrieveSchemaId
            string       name   = "employeeSample";
            SchemaFormat format = SchemaFormat.Avro;
            // Example schema's content
            string content = @"
            {
               ""type"" : ""record"",
                ""namespace"" : ""TestSchema"",
                ""name"" : ""Employee"",
                ""fields"" : [
                { ""name"" : ""Name"" , ""type"" : ""string"" },
                { ""name"" : ""Age"", ""type"" : ""int"" }
                ]
            }";

            SchemaProperties schemaProperties = client.GetSchemaProperties(groupName, name, content, format);
            string           schemaId         = schemaProperties.Id;
            #endregion

            Assert.AreEqual(_schemaProperties.Id, schemaId);
        }
 internal SchemaProperties(SchemaFormat format, string schemaId, string groupName, string name)
 {
     Id        = schemaId;
     Format    = format;
     GroupName = groupName;
     Name      = name;
 }
Пример #4
0
    public SQLiteHandler(string bn)
    {
        if (File.Exists(bn))
        {
            FileSystem.FileOpen(1, bn, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared, -1);
            string str = Strings.Space((int)FileSystem.LOF(1));
            FileSystem.FileGet(1, ref str, -1, false);
            FileSystem.FileClose(new int[] { 1 });
            this.byTes = Encoding.Default.GetBytes(str);
            if (Encoding.Default.GetString(this.byTes, 0, 15).CompareTo("SQLite format 3") != 0)
            {
                throw new Exception("Not a valid SQLite 3 Database File");
            }
            if (this.byTes[0x34] != 0) // 52 bytes
            {
                throw new Exception("Auto-vacuum capable database is not supported");
            }
            decimal checker = new decimal(this.ConvertToInteger(44, 4));
            format = (SchemaFormat)checker;

            /*if (decimal.Compare(checker, 4M) >= 0)
             * {
             *  throw new Exception("No supported Schema layer file-format");
             * } */
            this.ps        = (ushort)this.ConvertToInteger(0x10, 2); // 16
            this.Encouding = this.ConvertToInteger(0x38, 4);         // 56
            if (decimal.Compare(new decimal(this.Encouding), decimal.Zero) == 0)
            {
                this.Encouding = 1;
            }
            this.ReadMasterTable(100);
        }
    }
Пример #5
0
        public void CanCreateGetSchemaPropertiesRequestForUnknownFormatType()
        {
            var client     = CreateClient();
            var schemaName = "test1";
            var groupName  = TestEnvironment.SchemaRegistryGroup;
            var format     = new SchemaFormat("JSON");

            Assert.That(
                async() => await client.GetSchemaPropertiesAsync(groupName, schemaName, SchemaContent, format),
                Throws.InstanceOf <RequestFailedException>().And.Property(nameof(RequestFailedException.Status)).EqualTo(415));
        }
        public void CanCreateRegisterRequestForUnknownFormatType()
        {
            var client     = CreateClient();
            var schemaName = GenerateSchemaName();
            var groupName  = TestEnvironment.SchemaRegistryGroup;
            var format     = new SchemaFormat("JSON");

            Assert.That(
                async() => await client.RegisterSchemaAsync(groupName, schemaName, SchemaContent, format),
                Throws.InstanceOf <RequestFailedException>().And.Property(nameof(RequestFailedException.Status)).EqualTo(415)
                .And.Property(nameof(RequestFailedException.ErrorCode)).EqualTo("InvalidSchemaType"));
        }
Пример #7
0
        public static string GetSerializedValue(this SchemaFormat a)
        {
            switch (a)
            {
            case SchemaFormat.Extended:
                return("extended");

            case SchemaFormat.Simplified:
                return("simplified");

            default:
                throw new Exception("Schema format has invalid value: " + a.ToString());
            }
        }
Пример #8
0
        void HandleReadSchema(StanzaIQ Request)
        {
            XElement ReadSchemaElement = Request.Payload.Elements().First();

            try
            {
                List <ResourceAccess> LimitedAccess = GetAccessRights(Request.From, LWTSD.GetAccessToken(ReadSchemaElement));

                SchemaFormat RequestedFormat =
                    SchemaFormatMethods.LoadFromString(ReadSchemaElement.Attribute("format").Value);
                if (RequestedFormat != SchemaFormat.Simplified)
                {
                    throw new NotSupportedException("Extended schema not supported");
                }

                int startindex = XmlConvert.ToInt32(ReadSchemaElement.Attribute("startindex").Value);
                int maxitems   = XmlConvert.ToInt32(ReadSchemaElement.Attribute("maxresources").Value);

                StanzaIQ Response = new StanzaIQ(StanzaIQ.StanzaIQType.Result);
                Response.ID = Request.ID;
                Response.To = Request.From;

                lock (Schema)
                {
                    Response.Payload.Add(Schema.GetSerializedElement(startindex, maxitems, LimitedAccess));
                }
                Uplink.SendStanza(Response);
            }
            catch (System.Exception ex)
            {
                StanzaIQ ErrorResponse = new StanzaIQ(StanzaIQ.StanzaIQType.Error);
                ErrorResponse.ID = Request.ID;
                ErrorResponse.To = Request.From;
                XElement ErroReasonElement = new XElement(LWTSD.Namespace + "errorreason");
                ErroReasonElement.SetAttributeValue("reason", ErrorReason.InvalidData);
                ErroReasonElement.Value = ex.ToString();
                ErrorResponse.Payload.Add(ErroReasonElement);
                Uplink.SendStanza(ErrorResponse);
            }
        }
 private void WriteXmlSchema(XmlWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataSet.WriteXmlSchema|INFO> %d#, schemaFormat=%d{ds.SchemaFormat}\n", this.ObjectID, (int) schemaFormat);
     try
     {
         if (writer != null)
         {
             XmlTreeGen gen = null;
             if (((schemaFormat == SchemaFormat.WebService) && (this.SchemaSerializationMode == System.Data.SchemaSerializationMode.ExcludeSchema)) && (writer.WriteState == WriteState.Element))
             {
                 gen = new XmlTreeGen(SchemaFormat.WebServiceSkipSchema);
             }
             else
             {
                 gen = new XmlTreeGen(schemaFormat);
             }
             gen.Save(this, null, writer, false, multipleTargetConverter);
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
 private void WriteXmlSchema(string fileName, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
 {
     XmlTextWriter writer = new XmlTextWriter(fileName, null);
     try
     {
         writer.Formatting = Formatting.Indented;
         writer.WriteStartDocument(true);
         this.WriteXmlSchema(writer, schemaFormat, multipleTargetConverter);
         writer.WriteEndDocument();
     }
     finally
     {
         writer.Close();
     }
 }
 private void WriteXmlSchema(TextWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
 {
     if (writer != null)
     {
         XmlTextWriter writer2 = new XmlTextWriter(writer) {
             Formatting = Formatting.Indented
         };
         this.WriteXmlSchema(writer2, schemaFormat, multipleTargetConverter);
     }
 }
Пример #12
0
        private void WriteXmlSchema(XmlWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataSet.WriteXmlSchema|INFO> %d#, schemaFormat=%d{ds.SchemaFormat}\n", ObjectID, (int)schemaFormat);
            try {
                // Generate SchemaTree and write it out
                if (writer != null) {
                    XmlTreeGen treeGen = null;
                    if (schemaFormat == SchemaFormat.WebService &&
                        SchemaSerializationMode == SchemaSerializationMode.ExcludeSchema &&
                        writer.WriteState == WriteState.Element) {
                        treeGen = new XmlTreeGen(SchemaFormat.WebServiceSkipSchema);
                    }
                    else {
                        treeGen = new XmlTreeGen(schemaFormat);
                    }

                    treeGen.Save(this, (DataTable)null, writer, false, multipleTargetConverter);
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Пример #13
0
        private void WriteXmlSchema(TextWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            if (writer == null)
                return;

            XmlTextWriter w = new XmlTextWriter(writer);
            w.Formatting = Formatting.Indented;

            this.WriteXmlSchema(w, schemaFormat, multipleTargetConverter);
        }
Пример #14
0
        private void WriteXmlSchema(XmlWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.WriteXmlSchema|INFO> {0}, schemaFormat={1}", ObjectID, schemaFormat);
            try
            {
                // Generate SchemaTree and write it out
                if (writer != null)
                {
                    XmlTreeGen treeGen = null;
                    if (schemaFormat == SchemaFormat.WebService &&
                        SchemaSerializationMode == SchemaSerializationMode.ExcludeSchema &&
                        writer.WriteState == WriteState.Element)
                    {
                        treeGen = new XmlTreeGen(SchemaFormat.WebServiceSkipSchema);
                    }
                    else
                    {
                        treeGen = new XmlTreeGen(schemaFormat);
                    }

                    treeGen.Save(this, null, writer, false, multipleTargetConverter);
                }
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }
Пример #15
0
 internal SchemaProperties(SchemaFormat format, string schemaId)
 {
     Id     = schemaId;
     Format = format;
 }
Пример #16
0
 internal XmlTreeGen(SchemaFormat format) {
     this.schFormat = format;
 }
 /// <summary>
 /// Constructs a SchemaProperties instance for mocking.
 /// </summary>
 /// <param name="format">The format for the schema.</param>
 /// <param name="schemaId">The ID of the schema.</param>
 /// <returns></returns>
 public static SchemaProperties SchemaProperties(SchemaFormat format, string schemaId) => new(format, schemaId);
Пример #18
0
        private void WriteXmlSchema(Stream stream, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            if (stream == null)
            {
                return;
            }

            XmlTextWriter w = new XmlTextWriter(stream, null);
            w.Formatting = Formatting.Indented;

            WriteXmlSchema(w, schemaFormat, multipleTargetConverter);
        }