public IConfiguration FromFileStream(string fileName) { byte[] bytes = File.ReadAllBytes(fileName); AvroConfiguration avroConf = AvroDeseriaize(bytes); return(FromAvro(avroConf)); }
public string ToString(IConfiguration c) { byte[] bytes = ToByteArray(c); AvroConfiguration avroConf = AvroDeseriaize(bytes); string s = JsonConvert.SerializeObject(avroConf, Formatting.Indented); return(s); }
private byte[] AvroSerialize(AvroConfiguration obj) { var serializer = AvroSerializer.Create <AvroConfiguration>(); using (MemoryStream stream = new MemoryStream()) { serializer.Serialize(stream, obj); return(stream.GetBuffer()); } }
private IConfiguration AddFromAvro(IConfigurationBuilder cb, AvroConfiguration avroConfiguration) { IList <KeyValuePair <string, string> > settings = new List <KeyValuePair <string, string> >(); foreach (ConfigurationEntry e in avroConfiguration.Bindings) { settings.Add(new KeyValuePair <string, string>(e.key, e.value)); } ConfigurationFile.ProcessConfigData(cb, settings); //TODO return(cb.Build()); }
public AvroConfiguration AvroDeseriaizeFromFile(string fileName) { AvroConfiguration avroConf = null; try { using (var buffer = new MemoryStream()) { if (!ReadFile(buffer, fileName)) { var e = new ApplicationException("Error during file operation. Quitting method : " + fileName); Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } buffer.Seek(0, SeekOrigin.Begin); //AvroSerializerSettings settings = new AvroSerializerSettings(); //settings.Resolver = new AvroConfigurationResolver(); //using (var reader = new SequentialReader<AvroConfiguration>(AvroContainer.CreateReader<AvroConfiguration>(buffer, true, settings, new CodecFactory()))) using (var reader = new SequentialReader <AvroConfiguration>(AvroContainer.CreateReader <AvroConfiguration>(buffer, true))) { var results = reader.Objects; if (results != null) { avroConf = (AvroConfiguration)results.First(); } } } } catch (SerializationException ex) { Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER); var e = new ApplicationException("Cannot deserialize the file: " + fileName, ex); Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } return(avroConf); }
public byte[] ToByteArray(IConfiguration c) { AvroConfiguration obj = ToAvroConfiguration(c); return(AvroSerialize(obj)); }
public IConfiguration FromAvro(AvroConfiguration avroConfiguration, IClassHierarchy classHierarchy) { IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(classHierarchy); return(AddFromAvro(cb, avroConfiguration)); }
public IConfiguration FromAvro(AvroConfiguration avroConfiguration) { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); return(AddFromAvro(cb, avroConfiguration)); }
public IConfiguration FromString(string josonString) { AvroConfiguration avroConf = JsonConvert.DeserializeObject <AvroConfiguration>(josonString); return(FromAvro(avroConf)); }
public IConfiguration FromFile(string fileName) { AvroConfiguration avroConf = AvroDeseriaizeFromFile(fileName); return(FromAvro(avroConf)); }
public IConfiguration AddFromByteArray(ICsConfigurationBuilder cb, byte[] bytes) { AvroConfiguration avroConf = AvroDeseriaize(bytes); return(AddFromAvro(cb, avroConf)); }
public IConfiguration FromByteArray(byte[] bytes) { AvroConfiguration avroConf = AvroDeseriaize(bytes); return(FromAvro(avroConf)); }