public static void DecodeTextureDataToWriter(byte[] data, int width, int height, TextureFormat format, PipelineWriter writer) { if (!format.IsSupported()) throw new FormatException("Unsupported format: " + format.ToString()); PipelineReader reader = null; switch (format) { case TextureFormat.DXT1: reader = new DXT1Reader(data, format, width, height); break; case TextureFormat.DXT2: case TextureFormat.DXT3: reader = new DXT3Reader(data, format, width, height); break; case TextureFormat.DXT4: case TextureFormat.DXT5: reader = new DXT5Reader(data, format, width, height); break; case TextureFormat.BC4: reader = new BC4Reader(data, format, width, height); break; case TextureFormat.BC5: reader = new BC5Reader(data, format, width, height); break; default: reader = new DefaultReader(data, format, width, height); break; } reader.Read(writer); }
static void Main(string[] args) { Console.WriteLine("Init"); InitRecvThread(); SpiderSeeds seeds = new SpiderSeeds(); for (int i = 0; i <= 10; ++i) { seeds.AddSeed("http://www.cozy.com/cn/actresses/currentPage/" + i); } IUrlMatch match = new FindStringMatch() { StringFind = "www.cozy.com/cn/star/", NoCase = true }; IUrlFilter filter = new BloomFilter(); IUrlReader reader = new DefaultReader(); SpiderSetting setting = new SpiderSetting(); setting.Depth = 1; setting.WorkerCount = 8; setting.Seeds = seeds; setting.Match = match; setting.Filter = filter; setting.Reader = reader; SpiderMaster master = new SpiderMaster(); master.Init(setting); master.AddUrlEventHandler += OnEvent; master.DataReceivedEventHandler += OnEvent; master.ErrorEventHandler += OnEvent; Console.WriteLine("Begin"); master.Crawl(); master.Stop(); StopRecvThread(); Console.WriteLine("search Finish"); var parsetask = new Task(Parse, 5); parsetask.Start(); parsetask.Wait(); Console.WriteLine("Parse Finish"); foreach (var obj in InfoList) { Console.WriteLine(obj.ToString()); } Console.ReadKey(); }
static AvroEventFormatter() { // we're going to confidently assume that the embedded schema works. If not, type initialization // will fail and that's okay since the type is useless without the proper schema using (var sr = new StreamReader(typeof(AvroEventFormatter).Assembly.GetManifestResourceStream("CloudNative.CloudEvents.Avro.AvroSchema.json"))) { avroSchema = (RecordSchema)RecordSchema.Parse(sr.ReadToEnd()); } avroReader = new DefaultReader(avroSchema, avroSchema); avroWriter = new DefaultWriter(avroSchema); }
static void Main(string[] args) { GenericRecord originalEvent; GenericRecord deserializedEvent; var timestamp = DateTime.UtcNow; // Create a UserLoginEvent using GenericRecord originalEvent = new GenericRecord(UserLoginEventSchema); originalEvent.Add("timestamp", DateTimeToAvroTimestampMillis(timestamp)); originalEvent.Add("userID", "blachniet"); originalEvent.Add("wasSuccessful", true); using (var memoryStream = new MemoryStream()) { // Write the record to a memory stream { var binaryEncoder = new BinaryEncoder(memoryStream); var defaultWriter = new DefaultWriter(UserLoginEventSchema); defaultWriter.Write(originalEvent, binaryEncoder); binaryEncoder.Flush(); } // Reset the stream position before we read it memoryStream.Position = 0; // Read the record from the memory stream { var binaryDecoder = new BinaryDecoder(memoryStream); var defaultReader = new DefaultReader(UserLoginEventSchema, UserLoginEventSchema); deserializedEvent = defaultReader.Read <GenericRecord>(null, binaryDecoder); } } Console.WriteLine($@" Original Event: timestamp : {originalEvent["timestamp"]} userID : {originalEvent["userID"]} wasSuccessful : {originalEvent["wasSuccessful"]} Deserialized Event: timestamp : {deserializedEvent["timestamp"]} userID : {deserializedEvent["userID"]} wasSuccessful : {deserializedEvent["wasSuccessful"]} Press 'Enter' to exit. ".TrimStart()); Console.ReadLine(); }
public ILifetimeScope CreateScope(string cfg) { var builder = new ContainerBuilder(); builder.Properties["ShortHand"] = _shortHand; builder.Properties["Methods"] = _methods; builder.RegisterModule(new CsScriptModule()); RegisterShortHand(new[] { new OperationSignature("hashcode") }); builder.Register((c, p) => _shortHand).As <ShorthandRoot>().InstancePerLifetimeScope(); builder.Register(ctx => { var reader = new DefaultReader(new FileReader(), new WebReader()); var environment = new EnvironmentModifier(new PlaceHolderReplacer('@', '[', ']'), "environments", "environment", "name", "parameters", "name", "value"); var customizer = new ShorthandCustomizer(ctx.Resolve <ShorthandRoot>(), new[] { "fields", "calculated-fields" }, "t", "transforms", "method"); return(new Process(cfg, reader, environment, customizer)); }).As <Process>().InstancePerDependency(); // because it has state, if you run it again, it's not so good return(builder.Build().BeginLifetimeScope()); }
static void Main(string[] args) { Console.WriteLine("Init"); InitRecvThread(); SpiderSeeds seeds = new SpiderSeeds(); seeds.AddSeed("http://www.javfee.com/cn"); IUrlMatch match = new FindStringMatch() { StringFind = "www.javfee.com", NoCase = true }; IUrlFilter filter = new BloomFilter(); IUrlReader reader = new DefaultReader(); SpiderSetting setting = new SpiderSetting(); setting.Depth = 2; setting.WorkerCount = 8; setting.Seeds = seeds; setting.Match = match; setting.Filter = filter; setting.Reader = reader; SpiderMaster master = new SpiderMaster(); master.Init(setting); master.AddUrlEventHandler += OnEvent; master.DataReceivedEventHandler += OnEvent; master.ErrorEventHandler += OnEvent; Console.WriteLine("Begin"); master.Crawl(); master.Stop(); StopRecvThread(); Console.WriteLine("Finish"); Console.ReadKey(); }
private static IMessageReader GetReader(Message message) { IMessageReader reader = null; switch (message.Type) { case MessageType.Attachment: reader = new AttachmentReader(); break; case MessageType.MissionVNext: reader = new MissionVNextReader(); break; default: reader = new DefaultReader(); break; } return(reader); }
/// <summary> /// Write a record using the v1 schema which doesn't have the 'fieldB' field. Read that /// data using the v2 schema, which has 'fieldB' with 'bravo' as the default value. /// </summary> static void WriteV1ReadV2() { GenericRecord originalEntry; GenericRecord deserializedEntry; // Create an entry using the v1 schema originalEntry = new GenericRecord(EntryV1Schema); originalEntry.Add("fieldA", "Hello"); using (var memoryStream = new MemoryStream()) { // Write the record using the v1 schema { var binaryEncoder = new BinaryEncoder(memoryStream); var writer = new DefaultWriter(EntryV1Schema); writer.Write(originalEntry, binaryEncoder); } memoryStream.Position = 0; // Read the record using the v2 schema { var binaryDecoder = new BinaryDecoder(memoryStream); var defaultReader = new DefaultReader(EntryV1Schema, EntryV2Schema); deserializedEntry = defaultReader.Read <GenericRecord>(null, binaryDecoder); } } Console.WriteLine($@" V1 --> V2 --------------------------------------- Original Entry (v1): fieldA: {originalEntry["fieldA"]} fieldB: <does not exist in v1> Deserialized Entry (v2): fieldA: {deserializedEntry["fieldA"]} fieldB: {deserializedEntry["fieldB"]} ".TrimStart()); }
/// <summary> /// Write a record using the v2 schema. Read that data using the v1 schema, which doesn't /// have the 'fieldB' field. /// </summary> static void WriteV2ReadV1() { GenericRecord originalEntry; GenericRecord deserializedEntry; originalEntry = new GenericRecord(EntryV2Schema); originalEntry.Add("fieldA", "Hello"); originalEntry.Add("fieldB", "World"); using (var memoryStream = new MemoryStream()) { { var binaryEncoder = new BinaryEncoder(memoryStream); var writer = new DefaultWriter(EntryV2Schema); writer.Write(originalEntry, binaryEncoder); } memoryStream.Position = 0; { var binaryDecoder = new BinaryDecoder(memoryStream); var defaultReader = new DefaultReader(EntryV2Schema, EntryV1Schema); deserializedEntry = defaultReader.Read <GenericRecord>(null, binaryDecoder); } } Console.WriteLine($@" V2 --> V1 --------------------------------------- Original Entry (v2): fieldA: {originalEntry["fieldA"]} fieldB: {originalEntry["fieldB"]} Deserialized Entry (v1): fieldA: {deserializedEntry["fieldA"]} fieldB: <does not exist in v1> ".TrimStart()); }
public void GenericReaderDefault() { ListSerializable <User> users = new UserList(); users.Add(new User("Toto", "Titi")); users.Add(new User("Tata", "Roro")); IWriter <User> write = new DefaultWriter <User>(); write.Write <UserList>(users, CsvFile); IGenericReader <User> reader = new DefaultReader <User>(); ListSerializable <User> usersToCompare = reader.read <UserList>(CsvFile); Assert.IsNotNull(usersToCompare); Assert.AreEqual(users[0].Firstname, usersToCompare[0].Firstname); Assert.AreEqual(users[0].Name, usersToCompare[0].Name); Assert.AreEqual(users[1].Firstname, usersToCompare[1].Firstname); Assert.AreEqual(users[1].Name, usersToCompare[1].Name); }
public int Read() { return(DefaultReader.Read()); }
public int PeekChar() { return(DefaultReader.PeekChar()); }
public string ReadString() { return(DefaultReader.ReadString()); }
public ulong ReadUInt64() { return(DefaultReader.ReadUInt64()); }
public uint ReadUInt32() { return(DefaultReader.ReadUInt32()); }
public byte ReadByte() { return(DefaultReader.ReadByte()); }
public int ReadInt32() { return(DefaultReader.ReadInt32()); }
public sbyte ReadSByte() { return(DefaultReader.ReadSByte()); }
public int Read(char[] buffer, int index, int count) { return(DefaultReader.Read(buffer, index, count)); }
public double ReadDouble() { return(DefaultReader.ReadDouble()); }
public char[] ReadChars(int count) { return(DefaultReader.ReadChars(count)); }
public char ReadChar() { return(DefaultReader.ReadChar()); }
public byte[] ReadBytes(int count) { return(DefaultReader.ReadBytes(count)); }
public static async Task Run( [EventHubTrigger("table-update", Connection = "eventHubConnection")] EventData[] events, [CosmosDB( databaseName: "Temenos", collectionName: "Events", ConnectionStringSetting = "CosmosDBConnection")] IAsyncCollector <JObject> eventsOut, ILogger log) { log.LogInformation($"ProcessAvroEvent triggered with {events.Count()} events"); var exceptions = new List <Exception>(); foreach (EventData eventData in events) { try { // convert messageBody of this event to a stream MemoryStream stream = new MemoryStream(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count); // skip the first 2 bytes stream.Position = 3; // decode the stream and get the schema number BinaryDecoder decoder = new BinaryDecoder(stream); var magicCode = (decoder.ReadBoolean() == false); var schemaNumber = decoder.ReadLong(); // get the appropriate schema Schema schema = null; switch (schemaNumber) { case 23: schema = Schema.Parse(File.ReadAllText(@"SerializationID-46-CUSTOMER.avsc")); break; case -21: schema = Schema.Parse(File.ReadAllText(@"SerializationID-41-DE_ADDRESS.avsc")); break; default: throw new Exception("Unknown schema nuumber: " + schemaNumber); } // read the avro message using the identified schema var reader = new DefaultReader(schema, schema); GenericRecord record = reader.Read(null, schema, schema, decoder) as GenericRecord; // convert to JSON and return JObject outputData = ConvertToJson(record); eventsOut.AddAsync(outputData).Wait(); // Replace these two lines with your processing logic. await Task.Yield(); } catch (Exception e) { // We need to keep processing the rest of the batch - capture this exception and continue. // TODO: consider capturing details of the message that failed processing so it can be processed again later. exceptions.Add(e); } } // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure. if (exceptions.Count > 1) { throw new AggregateException(exceptions); } if (exceptions.Count == 1) { throw exceptions.Single(); } }
public float ReadSingle() { return(DefaultReader.ReadSingle()); }
private object DecodeIBytesMessage(IBytesMessage msg, JSONPROXY map) { int len = (int) msg.BodyLength; byte[] bytes = new byte[len]; msg.ReadBytes(bytes, len); MemoryStream ins = new MemoryStream(bytes); Schema rs = SchemeFor(msg.ContentType, map); Schema ws = rs; if (rs != null) { var sdr = new DefaultReader(rs, ws); Avro.IO.Decoder dc = new Avro.IO.BinaryDecoder(ins); try { object actual = sdr.Read<object>(null, dc); Type t = actual.GetType(); return actual; } catch (Exception e) { Console.Error.WriteLine(e); throw; } finally { ins.Close(); } } else { Console.WriteLine("*** NO DECODER FOR msg.ContentType='{0}' FOUND ***", msg.ContentType); return null; } }
public ushort ReadUInt16() { return(DefaultReader.ReadUInt16()); }
public decimal ReadDecimal() { return(DefaultReader.ReadDecimal()); }
public bool ReadBoolean() { return(DefaultReader.ReadBoolean()); }