Beispiel #1
0
        /// <summary>
        /// Returns a decoder instance based on the transcoding name (e.g json, bson).
        /// </summary>
        /// <param name="name">The transcoding name.</param>
        /// <returns></returns>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">Could not locate a decoder for '{name}'.</exception>
        public IResonanceDecoder GetDecoder(string name)
        {
            lock (_initLock)
            {
                IResonanceDecoder decoder = null;

                if (_decoders.TryGetValue(name, out decoder))
                {
                    return(decoder);
                }

                Dictionary <String, IResonanceDecoder> decoders = new Dictionary <string, IResonanceDecoder>();

                foreach (var type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).Where(x => x.GetCustomAttribute <ResonanceTranscodingAttribute>() != null && typeof(ResonanceDecoder).IsAssignableFrom(x)))
                {
                    decoders.Add(type.GetCustomAttribute <ResonanceTranscodingAttribute>().Name, Activator.CreateInstance(type) as IResonanceDecoder);
                }

                foreach (var d in decoders)
                {
                    _decoders[d.Key] = d.Value;
                }

                if (decoders.TryGetValue(name, out decoder))
                {
                    return(decoder);
                }

                throw new KeyNotFoundException($"Could not locate a decoder for '{name}'.");
            }
        }
Beispiel #2
0
        public static void Read_Write_Test(ResonanceTest test, IResonanceAdapter adapter1, IResonanceAdapter adapter2, IResonanceEncoder encoder, IResonanceDecoder decoder, bool enableCryptography, int count, int maxOutliersPercentage)
        {
            IResonanceTransporter t1 = ResonanceTransporter.Builder
                                       .Create()
                                       .WithAdapter(adapter1)
                                       .WithTranscoding(encoder, decoder)
                                       .NoKeepAlive()
                                       .Build();

            IResonanceTransporter t2 = ResonanceTransporter.Builder
                                       .Create()
                                       .WithAdapter(adapter2)
                                       .WithTranscoding(encoder, decoder)
                                       .NoKeepAlive()
                                       .Build();

            Read_Write_Test(test, t1, t2, enableCryptography, count, maxOutliersPercentage);
        }
Beispiel #3
0
 public static void Read_Write_Test(ResonanceTest test, IResonanceEncoder encoder, IResonanceDecoder decoder, bool enableCryptography, int count, int maxOutliersPercentage)
 {
     Read_Write_Test(test, new InMemoryAdapter("TST"), new InMemoryAdapter("TST"), encoder, decoder, enableCryptography, count, maxOutliersPercentage);
 }
Beispiel #4
0
 /// <summary>
 /// Called when the transcoding information is first available.
 /// </summary>
 /// <param name="info">The transcoding information.</param>
 protected override void OnTranscodingInformationDecoded(ResonanceDecodingInformation info)
 {
     base.OnTranscodingInformationDecoded(info);
     _decoder = ResonanceTranscodingFactory.Default.GetDecoder(info.Transcoding);
 }