예제 #1
0
        public IConfiguration FromFileStream(string fileName)
        {
            byte[]            bytes    = File.ReadAllBytes(fileName);
            AvroConfiguration avroConf = AvroDeseriaize(bytes);

            return(FromAvro(avroConf));
        }
예제 #2
0
        public string ToString(IConfiguration c)
        {
            byte[]            bytes    = ToByteArray(c);
            AvroConfiguration avroConf = AvroDeseriaize(bytes);
            string            s        = JsonConvert.SerializeObject(avroConf, Formatting.Indented);

            return(s);
        }
예제 #3
0
        private byte[] AvroSerialize(AvroConfiguration obj)
        {
            var serializer = AvroSerializer.Create <AvroConfiguration>();

            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, obj);
                return(stream.GetBuffer());
            }
        }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }
예제 #6
0
        public byte[] ToByteArray(IConfiguration c)
        {
            AvroConfiguration obj = ToAvroConfiguration(c);

            return(AvroSerialize(obj));
        }
예제 #7
0
        public IConfiguration FromAvro(AvroConfiguration avroConfiguration, IClassHierarchy classHierarchy)
        {
            IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(classHierarchy);

            return(AddFromAvro(cb, avroConfiguration));
        }
예제 #8
0
        public IConfiguration FromAvro(AvroConfiguration avroConfiguration)
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            return(AddFromAvro(cb, avroConfiguration));
        }
예제 #9
0
        public IConfiguration FromString(string josonString)
        {
            AvroConfiguration avroConf = JsonConvert.DeserializeObject <AvroConfiguration>(josonString);

            return(FromAvro(avroConf));
        }
예제 #10
0
        public IConfiguration FromFile(string fileName)
        {
            AvroConfiguration avroConf = AvroDeseriaizeFromFile(fileName);

            return(FromAvro(avroConf));
        }
예제 #11
0
        public IConfiguration AddFromByteArray(ICsConfigurationBuilder cb, byte[] bytes)
        {
            AvroConfiguration avroConf = AvroDeseriaize(bytes);

            return(AddFromAvro(cb, avroConf));
        }
예제 #12
0
        public IConfiguration FromByteArray(byte[] bytes)
        {
            AvroConfiguration avroConf = AvroDeseriaize(bytes);

            return(FromAvro(avroConf));
        }