/// <summary>
 /// Constructor with default serializer
 /// </summary>
 /// <param name="configuration"></param>
 public RemoteCacheManager(ClientConfig configuration)
 {
     this.config = configuration;
     this.serializer = new DefaultSerializer();
     this.codec = new Codec();
     this.transportFactory = new TCPTransportFactory(this.config);
 }
 public override void SetUp()
 {
     base.SetUp();
     // set the default codec, so adding test cases to this isn't fragile
     SavedCodec = Codec.Default;
     Codec.Default = Codec;
 }
Esempio n. 3
0
 public bool Equals(Codec codec)
 {
     if (string.IsNullOrEmpty(this.Type))
         return false;
     if (string.IsNullOrEmpty(codec.Type))
         return false;
     return this.Type.Equals(codec.Type);
 }
Esempio n. 4
0
 protected HotRodOperation(Codec codec, Flag[] flags, byte[] cacheName, int topologyId)
 {
     this.flags = flags;
     this.cacheName = cacheName;
     this.topologyId = topologyId;
     this.codec = codec;
     logger = LogManager.GetLogger("Hot Rod Operation");
 }
Esempio n. 5
0
		public void MessageTest()
		{
			Action<Codec> setMessage = m => 
			{
				m.Id = Codec.MessageId.Message;

				m.Message.MessageId = 123;
				m.Message.RelatedMessageId = 123;
    			m.Message.Service = "Life is short but Now lasts for ever";
    			m.Message.Subject = "Life is short but Now lasts for ever";
				m.Message.Body = Encoding.ASCII.GetBytes("Captcha Diem");
				m.Message.OneWay = 123;
				m.Message.ConnectionId = 123;
			};

			Action<Codec> checkMessage = m=> 
			{
				Assert.That(m.Id, Is.EqualTo(Codec.MessageId.Message));
				Assert.That(m.Message.MessageId, Is.EqualTo(123));              
				Assert.That(m.Message.RelatedMessageId, Is.EqualTo(123));       
				Assert.That(m.Message.Service, Is.EqualTo("Life is short but Now lasts for ever"));                        
				Assert.That(m.Message.Subject, Is.EqualTo("Life is short but Now lasts for ever"));                        
				Assert.That(m.Message.Body, Is.EqualTo(Encoding.ASCII.GetBytes("Captcha Diem")));				
				Assert.That(m.Message.OneWay, Is.EqualTo(123));                 
				Assert.That(m.Message.ConnectionId, Is.EqualTo(123));           
			};
			
			using (var client = new DealerSocket("inproc://zprototest"))
			using (var server = new RouterSocket("inproc://zprototest"))
			{
				Codec clientMessage = new Codec();
				Codec serverMessage = new Codec();

				for (int i=0; i < 2; i++)
				{
					// client send message to server
					setMessage(clientMessage);				
					clientMessage.Send(client);				
												
					// server receive the message
					serverMessage.Receive(server);
				
					// check that message received ok
					Assert.That(serverMessage.RoutingId, Is.Not.Null);					
					checkMessage(serverMessage);

					// reply to client, no need to set the message, using client data
					serverMessage.Send(server);

					// client receive the message
					clientMessage.Receive(client);
				
					// check that message received ok
					Assert.That(clientMessage.RoutingId, Is.Null);					
					checkMessage(clientMessage);
				}				
			}			
		}	
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();

            ClearOperation target = new ClearOperation(codec, null, 0, null);
            Transport transport = null;
            target.executeOperation(transport);
        }
Esempio n. 7
0
 static Stream()
 {
     // Add MP3 codec to list of codecs
     Codec mp3 = new Codec("MP3", "libmp3lame", 128, new int[] { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 });
     codecs.Add(mp3);
     // Add IceCast to the list of server types
     ServerType iceCast = new ServerType("IceCast", "icecast", 8000, true, true);
     serverTypes.Add(iceCast);
 }
Esempio n. 8
0
 public void executeTest()
 {
     Transport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
     Codec codec = new Codec();
     PingOperation target = new PingOperation(codec, 0, trans);
     PingOperation.PingResult expected = PingOperation.PingResult.SUCCESS;
     PingOperation.PingResult actual;
     actual = target.execute();
     Assert.AreEqual(expected, actual);
 }
Esempio n. 9
0
 public Bitstream (Page page)
 {
    if (page == null)
       throw new ArgumentNullException ("page");
    
    // Assume that the first packet is completely enclosed. This should be
    // sufficient for codec recognition.
    _codec = Codec.GetCodec (page.Packets [0]);
    
    _first_absolute_granular_position = page.Header.AbsoluteGranularPosition;
 }
Esempio n. 10
0
        public EncryptionSettings(byte[] encryptionKey, Type symmetricAlgorithmType, bool encryptIndexes,int preferedEncryptionKeyBitsSize)
        {
            EncryptionKey = encryptionKey;
            this.encryptIndexes = encryptIndexes;

            Codec = new Codec(this);

            algorithmType = symmetricAlgorithmType;
            this.preferedEncryptionKeyBitsSize = preferedEncryptionKeyBitsSize;
            algorithmGenerator = Expression.Lambda<Func<SymmetricAlgorithm>>
                (Expression.New(symmetricAlgorithmType)).Compile();
        }
 public static void beforeClass()
 {
     savedCodec = Codec.Default;
     // currently only these codecs that support random access ordinals
     int victim = Random().nextInt(3);
     switch (victim)
     {
         case 0: Codec.Default = (TestUtil.AlwaysDocValuesFormat(new DirectDocValuesFormat())); break;
         case 1: Codec.Default = (TestUtil.AlwaysDocValuesFormat(new DiskDocValuesFormat())); break;
         default: Codec.Default = (TestUtil.AlwaysDocValuesFormat(new Lucene45DocValuesFormat())); break;
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Gets all Windows media Codecs.
        /// </summary>
        /// <param name="guid">MediaTypes WMMEDIATYPE_Audio or WMMEDIATYPE_Video expected</param>
        public static Codec[] GetCodecs(Guid mediaType)
        {
            IWMCodecInfo2 codecInfo = (IWMCodecInfo2)WM.CreateProfileManager();

            int count;
            codecInfo.GetCodecInfoCount(mediaType, out count);
            var list = new Codec[count];
            for (int i = 0; i < count; i++)
                list[i] = new Codec(codecInfo,i,mediaType);

            return list;
        }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");

            ContainsKeyOperation target = new ContainsKeyOperation(codec, key, null, 0, null);
            Transport transport = trans;
            bool expected = false;
            bool actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 14
0
 public OperationsFactory(string cacheName, bool forceReturnValue, Codec codec)
 {
     if (cacheName==null)
     {
         this.cacheNameBytes = DEFAULT_CACHE_NAME_BYTES; //For base client using the default cache
     }
     else
     {
         this.cacheNameBytes = this.e.GetBytes(cacheName);
     }
     this.forceReturnValue = forceReturnValue;
     this.codec = codec;
 }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");

            GetWithVersionOperation target = new GetWithVersionOperation(codec, key, null, 0, null);
            Transport transport = trans;
            BinaryVersionedValue expected = null;
            BinaryVersionedValue actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual.Ver1);
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            Type t = Type.GetType ("Mono.Runtime");
            var r = t != null ? "Mono" : ".NET";
            Console.WriteLine ("WindupConsoleTest v1.0.0");
            Console.WriteLine ("OS: " + Environment.OSVersion.Platform);
            Console.WriteLine ("Runtime: " + r + Environment.Version.Major);
            /*
            var list = SerialList.ReturnSerialList ();
            foreach (var port in list) {
                Console.WriteLine (port + "\t");
            }
            */

            if (SerialAgent.TouchAgentPort ("COM3", 9600)) {
                SerialAgent s;
                AnalyzerNT a;
                MyCodecFactory f;
                Codec codec;

                s = new SerialAgent ("COM3", 9600);
                s.AgentOpen ();
                a = new AnalyzerNT (s);
                f = new MyCodecFactory ();
                codec = new Codec (f, a);

                while (true) {
                    Console.Write ("> ");
                    var cmd = Console.ReadLine ();
                    if ("EXIT" == cmd.ToUpper ()) {
                        Console.WriteLine ("< See you later.");
                        Thread.Sleep (700);
                        break;
                    } else {
                        codec.WriteData (cmd);
                        Thread.Sleep (200);
                    }
                    if (0 < codec.queue.Count) {
                        var d = codec.queue.Dequeue ();
                        foreach (var kv in d) {
                            Console.WriteLine ("< " + kv.Value);
                        }
                    }
                }
                s.AgentClose ();
            } else {
                Console.WriteLine ("Serial ports may be occupied.");
                Console.WriteLine ("Press Enter exit.");
                Console.Read ();
            }
        }
Esempio n. 17
0
 public void executeOperationTest()
 {
     TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
     Codec codec = new Codec();
     byte[] cacheName = null;
     int topologyId = 0;
     Flag[] flags = null;
     StatsOperation target = new StatsOperation(codec, cacheName, topologyId, flags);
     Transport transport = trans;
     string expected = "";
     Dictionary<string, string> actual;
     actual = target.executeOperation(transport);
     Assert.AreEqual(expected, actual[ServerStatistics.CURRENT_NR_OF_ENTRIES]);
 }
Esempio n. 18
0
        public OperationsFactory(string cacheName, int topologyId, bool forceReturnValue, Codec codec)
        {
            if (cacheName.Equals("default"))
            {
                this.cacheNameBytes = DEFAULT_CACHE_NAME_BYTES; //For base client using the default cache
            }
            else
            {
                this.cacheNameBytes = this.e.GetBytes(cacheName);
            }

            this.topologyId = topologyId;
            this.forceReturnValue = forceReturnValue;
            this.codec = codec;
        }
Esempio n. 19
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();

            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");

            RemoveOperation target = new RemoveOperation(codec, key, null, 0, null);
            Transport transport = trans;
            byte[] expected = null;
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 20
0
        public void executeOperationTest()
        {
            Transport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();
            Serializer s2 = new DefaultSerializer();

            //byte[] key = s.serialize("11");
            byte[] key = s.serialize("key15");
            //byte[] key=UTF8Encoding.UTF8.GetBytes("key10");
            byte[] val = s.serialize("hexachlorocyclohexane777");//UTF8Encoding.UTF8.GetBytes("hexachlorocyclohexane777");
            PutOperation target = new PutOperation(codec, key, null, 0, null, val, 0, 0); // TODO: Initialize to an appropriate value
            Transport transport = trans;

            byte[] expected = null; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 21
0
        /// <summary>
        /// Gets all media formats for a codec.
        /// </summary>
        /// <param name="codec">Codec</param>
        /// <returns>All media formats for the specified codec</returns>
        public static CodecFormat[] GetMediaFormats(Codec codec)
        {
            var codecInfo = codec.CodecInformation;

            Guid mediaType = codec.MediaType;
            int formatCount;
            codecInfo.GetCodecFormatCount(mediaType, codec.Index, out formatCount);

            var formats = new CodecFormat[formatCount];
            for (int i = 0; i < formatCount; i++)
            {
                IWMStreamConfig config;
                codecInfo.GetCodecFormat(mediaType , codec.Index,  i, out config);
                WMStreamConfig stream = new WMStreamConfig(config);
                formats[i] = new CodecFormat(codec, stream, (int)i);
            }

            return formats;
        }
Esempio n. 22
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();

            // byte[] key = s.serialize("11");

            byte[] key = s.serialize("key10");
            //byte[] key= UTF8Encoding.UTF8.GetBytes("key10");

            GetOperation target = new GetOperation(codec, key, null, 0, null);
            Transport transport = trans;
            string expected = "hexachlorocyclohexane 777";
            byte[] actual;
            actual = target.executeOperation(transport);
            string res = (string)(s.deserialize(actual));

            Assert.AreEqual(expected, res);
        }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();
            byte[] key = s.serialize("key10");
            byte[] value = s.serialize("trinitrotoluene");

            byte[] cacheName = null;
            int topologyId = 0;
            Flag[] flags = null;

            int lifespan = 0;
            int maxIdle = 0;
            ReplaceOperation target = new ReplaceOperation(codec, key, cacheName, topologyId, flags, value, lifespan, maxIdle);
            Transport transport = trans;
            byte[] expected = null;
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 24
0
 public MediaBox(IsochronousTrackInfo trackInfo)
     : this()
 {
     ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfo.TimeScale, trackInfo.DurationIn100NanoSecs);
       MediaHeaderBox = new MediaHeaderBox(this, scaledDuration, trackInfo.TimeScale);
       this.Size += MediaHeaderBox.Size;
       Codec codec = null;
       if (trackInfo.GetType() == typeof(RawAudioTrackInfo))
       {
     RawAudioTrackInfo audioInfo = (RawAudioTrackInfo)trackInfo;
     codec = new Codec(CodecTypes.Audio);
     codec.PrivateCodecData = audioInfo.CodecPrivateData;
       }
       else if (trackInfo.GetType() == typeof(RawVideoTrackInfo))
       {
     RawVideoTrackInfo videoInfo = (RawVideoTrackInfo)trackInfo;
     codec = new Codec(CodecTypes.Video);
     codec.PrivateCodecData = videoInfo.CodecPrivateData;
       }
       HandlerReferenceBox = new HandlerReferenceBox(this, codec);
       this.Size += HandlerReferenceBox.Size;
       MediaInformationBox = new MediaInformationBox(this, trackInfo);
       // MediaInformationBox.Size is indeterminate at this time; it is determined only during SampleTableBox.FinalizeBox
 }
Esempio n. 25
0
 public DefaultProtocolEncode(Endpoint endpoint)
 {
     this.endpoint = endpoint;
     codec         = new DefaultCodec(endpoint);
 }
 public ContainsKeyOperation(Codec codec, byte[] key, byte[] cacheName, int topologyId, Flag[] flags) :
     base(codec, key, cacheName, topologyId, flags)
 {
 }
Esempio n. 27
0
        public virtual void TestFixedPostings()
        {
            const int NUM_TERMS = 100;

            TermData[] terms = new TermData[NUM_TERMS];
            for (int i = 0; i < NUM_TERMS; i++)
            {
                int[]  docs = new int[] { i };
                string text = Convert.ToString(i);
                terms[i] = new TermData(this, text, docs, null);
            }

            FieldInfos.Builder builder = new FieldInfos.Builder();

            FieldData field = new FieldData(this, "field", builder, terms, true, false);

            FieldData[] fields     = new FieldData[] { field };
            FieldInfos  fieldInfos = builder.Finish();

            // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
            using (Directory dir = NewDirectory())
            {
                this.Write(fieldInfos, dir, fields, true);
                Codec       codec = Codec.Default;
                SegmentInfo si    = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);

                // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
                using (FieldsProducer reader = codec.PostingsFormat.FieldsProducer(new SegmentReadState(dir, si, fieldInfos, NewIOContext(Random), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR)))
                {
                    IEnumerator <string> fieldsEnum = reader.GetEnumerator();
                    fieldsEnum.MoveNext();
                    string fieldName = fieldsEnum.Current;
                    Assert.IsNotNull(fieldName);
                    Terms terms2 = reader.GetTerms(fieldName);
                    Assert.IsNotNull(terms2);

                    TermsEnum termsEnum = terms2.GetIterator(null);

                    DocsEnum docsEnum = null;
                    for (int i = 0; i < NUM_TERMS; i++)
                    {
                        BytesRef term = termsEnum.Next();
                        Assert.IsNotNull(term);
                        Assert.AreEqual(terms[i].Text2, term.Utf8ToString());

                        // do this twice to stress test the codec's reuse, ie,
                        // make sure it properly fully resets (rewinds) its
                        // internal state:
                        for (int iter = 0; iter < 2; iter++)
                        {
                            docsEnum = TestUtil.Docs(Random, termsEnum, null, docsEnum, DocsFlags.NONE);
                            Assert.AreEqual(terms[i].Docs[0], docsEnum.NextDoc());
                            Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, docsEnum.NextDoc());
                        }
                    }
                    Assert.IsNull(termsEnum.Next());

                    for (int i = 0; i < NUM_TERMS; i++)
                    {
                        Assert.AreEqual(termsEnum.SeekCeil(new BytesRef(terms[i].Text2)), TermsEnum.SeekStatus.FOUND);
                    }

                    Assert.IsFalse(fieldsEnum.MoveNext());
                }
            }
        }
 // send different media type to different channels for efficiency
 internal byte photonChannelForCodec(Codec c)
 {
     return((byte)(1 + Array.IndexOf(Enum.GetValues(typeof(Codec)), c)));
 }
Esempio n. 29
0
 /// <summary>
 /// Construct a new complete SegmentInfo instance from input.
 /// <p>Note: this is public only to allow access from
 /// the codecs package.</p>
 /// </summary>
 public SegmentInfo(Directory dir, string version, string name, int docCount, bool isCompoundFile, Codec codec, IDictionary <string, string> diagnostics, IDictionary <string, string> attributes)
 {
     Debug.Assert(!(dir is TrackingDirectoryWrapper));
     this.Dir                 = dir;
     this.Version_Renamed     = version;
     this.Name                = name;
     this.DocCount_Renamed    = docCount;
     this.IsCompoundFile      = isCompoundFile;
     this.Codec_Renamed       = codec;
     this.Diagnostics_Renamed = diagnostics;
     this.Attributes_Renamed  = attributes;
 }
Esempio n. 30
0
        public void Sign(
            [Argument(Name = "KEY-ID", Description = "A private key to use for signing.")]
            Guid keyId,
            [Argument(Name = "VERSION", Description = "A version number to sign.")]
            int version,
            [Option(
                 'p',
                 ValueName = "PASSPHRASE",
                 Description = "Take passphrase through this option instead of prompt."
                 )]
            string?passphrase = null,
            [Option(
                 'E',
                 ValueName = "FILE",
                 Description = "Bencodex file to use for extra data.  " +
                               "For standard input, use a hyphen (`-').  " +
                               "For an actual file named a hyphen, prepend `./', i.e., `./-'."
                 )]
            string?extraFile = null,
            [Option(
                 'e',
                 ValueName = "KEY=VALUE",
                 Description = "Set a value to a key on extra Bencodex dictionary.  " +
                               "Can be applied multiple times (e.g., `-e foo=1 -e bar=baz').  " +
                               "This option implies the extra data to be a Bencodex dictionary, " +
                               "hence cannot be used together with -E/--extra-file option."
                 )]
            string[]?extra = null
            )
        {
            PrivateKey key        = new KeyCommand().UnprotectKey(keyId, passphrase);
            IValue?    extraValue = null;

            if (extraFile is string path)
            {
                if (extra is string[] e && e.Length > 0)
                {
                    throw Utils.Error(
                              "-E/--extra-file and -e/--extra cannot be used together at a time."
                              );
                }

                var codec = new Codec();
                if (path == "-")
                {
                    // Stream for stdin does not support .Seek()
                    using MemoryStream buffer = new MemoryStream();
                    using (Stream stream = Console.OpenStandardInput())
                    {
                        stream.CopyTo(buffer);
                    }

                    buffer.Seek(0, SeekOrigin.Begin);
                    extraValue = codec.Decode(buffer);
                }
                else
                {
                    using Stream stream = File.Open(path, FileMode.Open, FileAccess.Read);
                    extraValue          = codec.Decode(stream);
                }
            }
            else if (extra is string[] e && e.Length > 0)
            {
                var dict = Bencodex.Types.Dictionary.Empty;
                foreach (string pair in e)
                {
                    int sepPos = pair.IndexOf('=');
                    if (sepPos < 0)
                    {
                        throw Utils.Error(
                                  "-e/--extra must be a pair of KEY=VALUE, but no equal (=) separator: " +
                                  $"`{pair}'."
                                  );
                    }

                    string key_  = pair.Substring(0, sepPos);
                    string value = pair.Substring(sepPos + 1);
                    dict = dict.SetItem(key_, value);
                }

                extraValue = dict;
            }

            AppProtocolVersion v = AppProtocolVersion.Sign(key, version, extraValue);

            Console.WriteLine(v.Token);
        }
Esempio n. 31
0
        public virtual void WriteFieldUpdates(Directory dir, DocValuesFieldUpdates.Container dvUpdates)
        {
            lock (this)
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(Monitor.IsEntered(writer));
                }
                //System.out.println("rld.writeFieldUpdates: seg=" + info + " numericFieldUpdates=" + numericFieldUpdates);

                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(dvUpdates.Any());
                }

                // Do this so we can delete any created files on
                // exception; this saves all codecs from having to do
                // it:
                TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(dir);

                FieldInfos fieldInfos = null;
                bool       success    = false;
                try
                {
                    Codec codec = Info.Info.Codec;

                    // reader could be null e.g. for a just merged segment (from
                    // IndexWriter.commitMergedDeletes).
                    SegmentReader reader = this.reader ?? new SegmentReader(Info, writer.Config.ReaderTermsIndexDivisor, IOContext.READ_ONCE);
                    try
                    {
                        // clone FieldInfos so that we can update their dvGen separately from
                        // the reader's infos and write them to a new fieldInfos_gen file
                        FieldInfos.Builder builder = new FieldInfos.Builder(writer.globalFieldNumberMap);
                        // cannot use builder.add(reader.getFieldInfos()) because it does not
                        // clone FI.attributes as well FI.dvGen
                        foreach (FieldInfo fi in reader.FieldInfos)
                        {
                            FieldInfo clone = builder.Add(fi);
                            // copy the stuff FieldInfos.Builder doesn't copy
                            if (fi.Attributes != null)
                            {
                                foreach (KeyValuePair <string, string> e in fi.Attributes)
                                {
                                    clone.PutAttribute(e.Key, e.Value);
                                }
                            }
                            clone.DocValuesGen = fi.DocValuesGen;
                        }
                        // create new fields or update existing ones to have NumericDV type
                        foreach (string f in dvUpdates.numericDVUpdates.Keys)
                        {
                            builder.AddOrUpdate(f, NumericDocValuesField.TYPE);
                        }
                        // create new fields or update existing ones to have BinaryDV type
                        foreach (string f in dvUpdates.binaryDVUpdates.Keys)
                        {
                            builder.AddOrUpdate(f, BinaryDocValuesField.TYPE);
                        }

                        fieldInfos = builder.Finish();
                        long              nextFieldInfosGen     = Info.NextFieldInfosGen;
                        string            segmentSuffix         = nextFieldInfosGen.ToString(CultureInfo.InvariantCulture);//Convert.ToString(nextFieldInfosGen, Character.MAX_RADIX));
                        SegmentWriteState state                 = new SegmentWriteState(null, trackingDir, Info.Info, fieldInfos, writer.Config.TermIndexInterval, null, IOContext.DEFAULT, segmentSuffix);
                        DocValuesFormat   docValuesFormat       = codec.DocValuesFormat;
                        DocValuesConsumer fieldsConsumer        = docValuesFormat.FieldsConsumer(state);
                        bool              fieldsConsumerSuccess = false;
                        try
                        {
                            //          System.out.println("[" + Thread.currentThread().getName() + "] RLD.writeFieldUpdates: applying numeric updates; seg=" + info + " updates=" + numericFieldUpdates);
                            foreach (KeyValuePair <string, NumericDocValuesFieldUpdates> e in dvUpdates.numericDVUpdates)
                            {
                                string field = e.Key;
                                NumericDocValuesFieldUpdates fieldUpdates = e.Value;
                                FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
                                if (Debugging.AssertsEnabled)
                                {
                                    Debugging.Assert(fieldInfo != null);
                                }

                                fieldInfo.DocValuesGen = nextFieldInfosGen;
                                // write the numeric updates to a new gen'd docvalues file
                                fieldsConsumer.AddNumericField(fieldInfo, GetInt64Enumerable(reader, field, fieldUpdates));
                            }

                            //        System.out.println("[" + Thread.currentThread().getName() + "] RAU.writeFieldUpdates: applying binary updates; seg=" + info + " updates=" + dvUpdates.binaryDVUpdates);
                            foreach (KeyValuePair <string, BinaryDocValuesFieldUpdates> e in dvUpdates.binaryDVUpdates)
                            {
                                string field = e.Key;
                                BinaryDocValuesFieldUpdates dvFieldUpdates = e.Value;
                                FieldInfo fieldInfo = fieldInfos.FieldInfo(field);
                                if (Debugging.AssertsEnabled)
                                {
                                    Debugging.Assert(fieldInfo != null);
                                }

                                //          System.out.println("[" + Thread.currentThread().getName() + "] RAU.writeFieldUpdates: applying binary updates; seg=" + info + " f=" + dvFieldUpdates + ", updates=" + dvFieldUpdates);

                                fieldInfo.DocValuesGen = nextFieldInfosGen;
                                // write the numeric updates to a new gen'd docvalues file
                                fieldsConsumer.AddBinaryField(fieldInfo, GetBytesRefEnumerable(reader, field, dvFieldUpdates));
                            }

                            codec.FieldInfosFormat.FieldInfosWriter.Write(trackingDir, Info.Info.Name, segmentSuffix, fieldInfos, IOContext.DEFAULT);
                            fieldsConsumerSuccess = true;
                        }
                        finally
                        {
                            if (fieldsConsumerSuccess)
                            {
                                fieldsConsumer.Dispose();
                            }
                            else
                            {
                                IOUtils.DisposeWhileHandlingException(fieldsConsumer);
                            }
                        }
                    }
                    finally
                    {
                        if (reader != this.reader)
                        {
                            //          System.out.println("[" + Thread.currentThread().getName() + "] RLD.writeLiveDocs: closeReader " + reader);
                            reader.Dispose();
                        }
                    }

                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        // Advance only the nextWriteDocValuesGen so that a 2nd
                        // attempt to write will write to a new file
                        Info.AdvanceNextWriteFieldInfosGen();

                        // Delete any partially created file(s):
                        foreach (string fileName in trackingDir.CreatedFiles)
                        {
                            try
                            {
                                dir.DeleteFile(fileName);
                            }
                            catch (Exception t) when(t.IsThrowable())
                            {
                                // Ignore so we throw only the first exc
                            }
                        }
                    }
                }

                Info.AdvanceFieldInfosGen();
                // copy all the updates to mergingUpdates, so they can later be applied to the merged segment
                if (isMerging)
                {
                    foreach (KeyValuePair <string, NumericDocValuesFieldUpdates> e in dvUpdates.numericDVUpdates)
                    {
                        if (!mergingDVUpdates.TryGetValue(e.Key, out DocValuesFieldUpdates updates))
                        {
                            mergingDVUpdates[e.Key] = e.Value;
                        }
                        else
                        {
                            updates.Merge(e.Value);
                        }
                    }
                    foreach (KeyValuePair <string, BinaryDocValuesFieldUpdates> e in dvUpdates.binaryDVUpdates)
                    {
                        if (!mergingDVUpdates.TryGetValue(e.Key, out DocValuesFieldUpdates updates))
                        {
                            mergingDVUpdates[e.Key] = e.Value;
                        }
                        else
                        {
                            updates.Merge(e.Value);
                        }
                    }
                }

                // create a new map, keeping only the gens that are in use
                IDictionary <long, ISet <string> > genUpdatesFiles    = Info.UpdatesFiles;
                IDictionary <long, ISet <string> > newGenUpdatesFiles = new Dictionary <long, ISet <string> >();
                long fieldInfosGen = Info.FieldInfosGen;
                foreach (FieldInfo fi in fieldInfos)
                {
                    long dvGen = fi.DocValuesGen;
                    if (dvGen != -1 && !newGenUpdatesFiles.ContainsKey(dvGen))
                    {
                        if (dvGen == fieldInfosGen)
                        {
                            newGenUpdatesFiles[fieldInfosGen] = trackingDir.CreatedFiles;
                        }
                        else
                        {
                            newGenUpdatesFiles[dvGen] = genUpdatesFiles[dvGen];
                        }
                    }
                }

                Info.SetGenUpdatesFiles(newGenUpdatesFiles);

                // wrote new files, should checkpoint()
                writer.Checkpoint();

                // if there is a reader open, reopen it to reflect the updates
                if (reader != null)
                {
                    SegmentReader newReader = new SegmentReader(Info, reader, liveDocs, Info.Info.DocCount - Info.DelCount - pendingDeleteCount);
                    bool          reopened  = false;
                    try
                    {
                        reader.DecRef();
                        reader   = newReader;
                        reopened = true;
                    }
                    finally
                    {
                        if (!reopened)
                        {
                            newReader.DecRef();
                        }
                    }
                }
            }
        }
 public PutIFAbsentOperation(Codec codec, byte[] key, byte[] cacheName, int topologyId, Flag[] flags, byte[] value, int lifespan, int maxIdle) :
     base(codec, key, cacheName, topologyId, flags, value, lifespan, maxIdle)
 {
     logger = LogManager.GetLogger("PutIfAbsentOperation");
 }
Esempio n. 33
0
 public override void Init(Protocol protocol)
 {
     this.movementCodec = protocol.GetCodec(typeof(Movement));
 }
Esempio n. 34
0
 static string GetOptions(Codec codec)
 {
     return(_options[(int)codec]);
 }
Esempio n. 35
0
 static string GetSuffix(Codec codec)
 {
     return(_suffixes[(int)codec]);
 }
Esempio n. 36
0
        public virtual void TestChangeCodecAndMerge()
        {
            Directory dir = NewDirectory();

            if (Verbose)
            {
                Console.WriteLine("TEST: make new index");
            }
            IndexWriterConfig iwconf = NewIndexWriterConfig(TEST_VERSION_CURRENT,
                                                            new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE).SetCodec(new MockCodec());

            iwconf.SetMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH);
            // ((LogMergePolicy)iwconf.getMergePolicy()).setMergeFactor(10);
            IndexWriter writer = NewWriter(dir, iwconf);

            AddDocs(writer, 10);
            writer.Commit();
            AssertQuery(new Term("content", "aaa"), dir, 10);
            if (Verbose)
            {
                Console.WriteLine("TEST: addDocs3");
            }
            AddDocs3(writer, 10);
            writer.Commit();
            writer.Dispose();

            AssertQuery(new Term("content", "ccc"), dir, 10);
            AssertQuery(new Term("content", "aaa"), dir, 10);
            Codec codec = iwconf.Codec;

            iwconf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
                     .SetOpenMode(OpenMode.APPEND).SetCodec(codec);
            // ((LogMergePolicy)iwconf.getMergePolicy()).setNoCFSRatio(0.0);
            // ((LogMergePolicy)iwconf.getMergePolicy()).setMergeFactor(10);
            iwconf.SetMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH);

            iwconf.SetCodec(new MockCodec2()); // uses standard for field content
            writer = NewWriter(dir, iwconf);
            // swap in new codec for currently written segments
            if (Verbose)
            {
                Console.WriteLine("TEST: add docs w/ Standard codec for content field");
            }
            AddDocs2(writer, 10);
            writer.Commit();
            codec = iwconf.Codec;
            Assert.AreEqual(30, writer.MaxDoc);
            AssertQuery(new Term("content", "bbb"), dir, 10);
            AssertQuery(new Term("content", "ccc"), dir, 10); ////
            AssertQuery(new Term("content", "aaa"), dir, 10);

            if (Verbose)
            {
                Console.WriteLine("TEST: add more docs w/ new codec");
            }
            AddDocs2(writer, 10);
            writer.Commit();
            AssertQuery(new Term("content", "ccc"), dir, 10);
            AssertQuery(new Term("content", "bbb"), dir, 20);
            AssertQuery(new Term("content", "aaa"), dir, 10);
            Assert.AreEqual(40, writer.MaxDoc);

            if (Verbose)
            {
                Console.WriteLine("TEST: now optimize");
            }
            writer.ForceMerge(1);
            Assert.AreEqual(40, writer.MaxDoc);
            writer.Dispose();
            AssertQuery(new Term("content", "ccc"), dir, 10);
            AssertQuery(new Term("content", "bbb"), dir, 20);
            AssertQuery(new Term("content", "aaa"), dir, 10);

            dir.Dispose();
        }
Esempio n. 37
0
        internal SegmentCoreReaders(SegmentReader owner, Directory dir, SegmentCommitInfo si, IOContext context, int termsIndexDivisor)
        {
            fieldsReaderLocal = new AnonymousFieldsReaderLocal(this);
            termVectorsLocal  = new AnonymousTermVectorsLocal(this);

            if (termsIndexDivisor == 0)
            {
                throw new System.ArgumentException("indexDivisor must be < 0 (don't load terms index) or greater than 0 (got 0)");
            }

            Codec     codec = si.Info.Codec;
            Directory cfsDir; // confusing name: if (cfs) its the cfsdir, otherwise its the segment's directory.

            bool success = false;

            try
            {
                if (si.Info.UseCompoundFile)
                {
                    cfsDir = cfsReader = new CompoundFileDirectory(dir, IndexFileNames.SegmentFileName(si.Info.Name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), context, false);
                }
                else
                {
                    cfsReader = null;
                    cfsDir    = dir;
                }

                FieldInfos fieldInfos = owner.FieldInfos;

                this.termsIndexDivisor = termsIndexDivisor;
                PostingsFormat   format           = codec.PostingsFormat;
                SegmentReadState segmentReadState = new SegmentReadState(cfsDir, si.Info, fieldInfos, context, termsIndexDivisor);
                // Ask codec for its Fields
                fields = format.FieldsProducer(segmentReadState);
                Debug.Assert(fields != null);
                // ask codec for its Norms:
                // TODO: since we don't write any norms file if there are no norms,
                // kinda jaky to assume the codec handles the case of no norms file at all gracefully?!

                if (fieldInfos.HasNorms)
                {
                    normsProducer = codec.NormsFormat.NormsProducer(segmentReadState);
                    Debug.Assert(normsProducer != null);
                }
                else
                {
                    normsProducer = null;
                }

                fieldsReaderOrig = si.Info.Codec.StoredFieldsFormat.FieldsReader(cfsDir, si.Info, fieldInfos, context);

                if (fieldInfos.HasVectors) // open term vector files only as needed
                {
                    termVectorsReaderOrig = si.Info.Codec.TermVectorsFormat.VectorsReader(cfsDir, si.Info, fieldInfos, context);
                }
                else
                {
                    termVectorsReaderOrig = null;
                }

                success = true;
            }
            finally
            {
                if (!success)
                {
                    DecRef();
                }
            }
        }
Esempio n. 38
0
        public virtual void TestBasic()
        {
            HashSet <string> fileExtensions = new HashSet <string>();

            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_EXTENSION);
            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION);

            MockDirectoryWrapper primaryDir = new MockDirectoryWrapper(Random, new RAMDirectory());

            primaryDir.CheckIndexOnDispose = false; // only part of an index
            MockDirectoryWrapper secondaryDir = new MockDirectoryWrapper(Random, new RAMDirectory());

            secondaryDir.CheckIndexOnDispose = false; // only part of an index

            FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
            // for now we wire Lucene40Codec because we rely upon its specific impl
            bool oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;

            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
            IndexWriter writer = new IndexWriter(fsd, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).SetMergePolicy(NewLogMergePolicy(false)).SetCodec(Codec.ForName("Lucene40")).SetUseCompoundFile(false));

            TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
            IndexReader reader = DirectoryReader.Open(writer, true);

            Assert.AreEqual(100, reader.MaxDoc);
            writer.Commit();
            // we should see only fdx,fdt files here
            string[] files = primaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsTrue(fileExtensions.Contains(ext));
            }
            files = secondaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            // we should not see fdx,fdt files here
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsFalse(fileExtensions.Contains(ext));
            }
            reader.Dispose();
            writer.Dispose();

            files = fsd.ListAll();
            for (int i = 0; i < files.Length; i++)
            {
                Assert.IsNotNull(files[i]);
            }
            fsd.Dispose();
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
        }
Esempio n. 39
0
        public virtual bool WriteLiveDocs(Directory dir)
        {
            lock (this)
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(Monitor.IsEntered(writer));
                }
                //System.out.println("rld.writeLiveDocs seg=" + info + " pendingDelCount=" + pendingDeleteCount + " numericUpdates=" + numericUpdates);
                if (pendingDeleteCount == 0)
                {
                    return(false);
                }

                // We have new deletes
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(liveDocs.Length == Info.Info.DocCount);
                }

                // Do this so we can delete any created files on
                // exception; this saves all codecs from having to do
                // it:
                TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(dir);

                // We can write directly to the actual name (vs to a
                // .tmp & renaming it) because the file is not live
                // until segments file is written:
                bool success = false;
                try
                {
                    Codec codec = Info.Info.Codec;
                    codec.LiveDocsFormat.WriteLiveDocs((IMutableBits)liveDocs, trackingDir, Info, pendingDeleteCount, IOContext.DEFAULT);
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        // Advance only the nextWriteDelGen so that a 2nd
                        // attempt to write will write to a new file
                        Info.AdvanceNextWriteDelGen();

                        // Delete any partially created file(s):
                        foreach (string fileName in trackingDir.CreatedFiles)
                        {
                            try
                            {
                                dir.DeleteFile(fileName);
                            }
                            catch (Exception t) when(t.IsThrowable())
                            {
                                // Ignore so we throw only the first exc
                            }
                        }
                    }
                }

                // If we hit an exc in the line above (eg disk full)
                // then info's delGen remains pointing to the previous
                // (successfully written) del docs:
                Info.AdvanceDelGen();
                Info.DelCount      = Info.DelCount + pendingDeleteCount;
                pendingDeleteCount = 0;

                return(true);
            }
        }
Esempio n. 40
0
        private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type)
        {
            lock (this)
            {
                if (!this.allNodes.ContainsKey(nodeHandle))
                {
                    if (type == null)
                    {
                        IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = NodeInfo.FromNative(pNodeInfo).Description.Type;
                    }

                    ProductionNode node;

                    switch (type)
                    {
                        case NodeType.Device:
                            node = new Device(this, nodeHandle, true);
                            break;
                        case NodeType.Depth:
                            node = new DepthGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Image:
                            node = new ImageGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Audio:
                            node = new AudioGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.IR:
                            node = new IRGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.User:
                            node = new UserGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Recorder:
                            node = new Recorder(this, nodeHandle, true);
                            break;
                        case NodeType.Player:
                            node = new Player(this, nodeHandle, true);
                            break;
                        case NodeType.Gesture:
                            node = new GestureGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Scene:
                            node = new SceneAnalyzer(this, nodeHandle, true);
                            break;
                        case NodeType.Hands:
                            node = new HandsGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Codec:
                            node = new Codec(this, nodeHandle, true);
                            break;
                        case NodeType.ProductionNode:
                            node = new ProductionNode(this, nodeHandle, true);
                            break;
                        case NodeType.Generator:
                            node = new Generator(this, nodeHandle, true);
                            break;
                        case NodeType.MapGenerator:
                            node = new MapGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.ScriptNode:
                            node = new ScriptNode(this, nodeHandle, true);
                            break;
                        default:
                            throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }
                    this.allNodes[nodeHandle] = node;
                }

                return this.allNodes[nodeHandle];
            } // lock
        }
Esempio n. 41
0
        public Message ToMimeMessage(int tenant, string user, bool load_attachments)
        {
            var mime_message = new Message
            {
                Date = DateTime.UtcNow,
                From = new Address(From, string.IsNullOrEmpty(DisplayName) ? "" : Codec.RFC2047Encode(DisplayName))
            };

            if (Important)
            {
                mime_message.Priority = MessagePriority.High;
            }

            mime_message.To.AddRange(To.ConvertAll(address =>
            {
                var addr  = Parser.ParseAddress(address);
                addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                return(new Address(addr.Email, addr.Name));
            }));

            mime_message.Cc.AddRange(Cc.ConvertAll(address =>
            {
                var addr  = Parser.ParseAddress(address);
                addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                return(new Address(addr.Email, addr.Name));
            }));

            mime_message.Bcc.AddRange(Bcc.ConvertAll(address =>
            {
                var addr  = Parser.ParseAddress(address);
                addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                return(new Address(addr.Email, addr.Name));
            }));

            mime_message.Subject = Codec.RFC2047Encode(Subject);

            // Set correct body
            if (Attachments.Any() || AttachmentsEmbedded.Any())
            {
                foreach (var attachment in Attachments)
                {
                    attachment.user   = user;
                    attachment.tenant = tenant;
                    var attach = CreateAttachment(attachment, load_attachments);
                    if (attach != null)
                    {
                        mime_message.Attachments.Add(attach);
                    }
                }

                foreach (var embedded_attachment in AttachmentsEmbedded)
                {
                    embedded_attachment.user   = user;
                    embedded_attachment.tenant = tenant;
                    var attach = CreateAttachment(embedded_attachment, true);
                    if (attach != null)
                    {
                        mime_message.EmbeddedObjects.Add(attach);
                    }
                }
            }

            mime_message.BodyText.Charset = Encoding.UTF8.HeaderName;
            mime_message.BodyText.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            mime_message.BodyText.Text = "";

            mime_message.BodyHtml.Charset = Encoding.UTF8.HeaderName;
            mime_message.BodyHtml.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            mime_message.BodyHtml.Text = HtmlBody;

            return(mime_message);
        }
Esempio n. 42
0
		public override Stream Encode( Stream input, Codec.CodecData data )
		{
			throw new NotImplementedException();
		}
Esempio n. 43
0
 /// <summary>
 /// Construct a new complete SegmentInfo instance from input.
 /// <p>Note: this is public only to allow access from
 /// the codecs package.</p>
 /// </summary>
 public SegmentInfo(Directory dir, string version, string name, int docCount, bool isCompoundFile, Codec codec, IDictionary <string, string> diagnostics)
     : this(dir, version, name, docCount, isCompoundFile, codec, diagnostics, null)
 {
 }
Esempio n. 44
0
		public override void EncodeToFile( Stream input, string outFileName, Codec.CodecData codecData )
		{
			int imageID;

			// create and bind a new image
			Il.ilGenImages( 1, out imageID );
			Il.ilBindImage( imageID );

			var buffer = new byte[input.Length];
			input.Read( buffer, 0, buffer.Length );

			var imgData = (ImageData)codecData;

			PixelBox src;
			using ( var bufHandle = BufferBase.Wrap( buffer ) )
			{
				src = new PixelBox( imgData.width, imgData.height, imgData.depth, imgData.format, bufHandle );
			}

			try
			{
				// Convert image from Axiom to current IL image
				ILUtil.ConvertToIL( src );
			}
			catch ( Exception ex )
			{
				LogManager.Instance.Write( "IL Failed image conversion :", ex.Message );
			}

			// flip the image
			Ilu.iluFlipImage();

			// save the image to file
			Il.ilSaveImage( outFileName );

			var error = Il.ilGetError();

			if ( error != Il.IL_NO_ERROR )
			{
				LogManager.Instance.Write( "IL Error, could not save file: {0} : {1}", outFileName, Ilu.iluErrorString( error ) );
			}

			Il.ilDeleteImages( 1, ref imageID );
		}
Esempio n. 45
0
 public CodecSettings(Codec codec, uint frameSize, int sampleRate)
 {
     _codec      = codec;
     _frameSize  = frameSize;
     _sampleRate = sampleRate;
 }
Esempio n. 46
0
 public override void Init(Protocol protocol)
 {
     this.longCodec = protocol.GetCodec(typeof(long));
 }
Esempio n. 47
0
 public override void Init(Protocol protocol)
 {
     this.elementCodec = protocol.GetCodec(this.elementCodecInfo);
 }
Esempio n. 48
0
 static BaseNode()
 {
     _codec = new Codec();
 }
Esempio n. 49
0
        /// <summary>
        /// Deserializes the data from the buffer.
        /// </summary>
        /// <param name="buffer">Buffer to deserialize data from.</param>
        /// <param name="offset">Starting offset.</param>
        /// <param name="length">The number of bytes that can be read (starting at offset, not 0).</param>
        /// <returns>
        /// <c>true</c>, if all fields in this message were known,
        /// <c>false</c> if some of the fields were unknown.
        /// </returns>
        /// <exception cref="ProtoException">
        /// On error or if the message doesn't validate after being deserialized.
        /// </exception>
        internal virtual bool DeserializeMessageData(byte[] buffer, uint offset, uint length)
        {
            this.ClearMessage();

            uint maxSize = offset + length;

            if (buffer == null || maxSize > buffer.Length)
            {
                throw new ProtoException(
                          ProtoException.ErrorCodes.InvalidParameter,
                          "No buffer provided, or incorrect buffer size");
            }

            bool ret = true;

            uint desOffset = offset;

            while (offset < maxSize)
            {
                uint            fieldId;
                uint            payloadSize;
                Codec.WireTypes wireType;
                uint            fieldOffset = offset;

#if DEBUG2
                Debug.WriteLine("Field; Offset: " + offset + "; MaxSize: " + maxSize);
#endif

                if (!Codec.ReadHeader(buffer, ref offset, maxSize, out fieldId, out payloadSize, out wireType))
                {
                    // There is not enough data. In this function we should have enough data!
                    throw new ProtoException(
                              ProtoException.ErrorCodes.InvalidDataSize,
                              "Not enough data to decode next field's header");
                }

#if DEBUG2
                Debug.WriteLine("FieldId: " + fieldId + "; WireType: " + wireType + "; Offset: "
                                + offset + "; PayloadSize: " + payloadSize + "; MaxSize: " + maxSize);
#endif

                if (offset + payloadSize > maxSize)
                {
                    // There was enough data to decode the header,
                    // but the payload size in this header describes data that we don't have...
                    throw new ProtoException(
                              ProtoException.ErrorCodes.InvalidDataSize,
                              "Not enough data to decode next field's payload; Field Id: " + fieldId
                              + "; WireType: " + (( int )wireType)
                              + "; PayloadSize: " + payloadSize + "; DesOffset: " + desOffset
                              + "; FieldOffset: " + fieldOffset + "; CurOffset: " + offset
                              + "; MaxSize: " + maxSize + "; Length: " + length
                              + "; BufSize: " + buffer.Length);
                }

                if (!this.DeserializeMessageField(buffer, offset, fieldId, payloadSize, wireType))
                {
                    // Unknown field
                    ret = false;
                }

                // If we are still here (no exception),
                // it means that the field was handled properly (even if it was unknown)!
                offset += payloadSize;
            }

            this.ValidateMessage();

            return(ret);
        }
Esempio n. 50
0
 public static void Convert(VideoFile file, Codec codec)
 {
 }
Esempio n. 51
0
 public override void SetUp()
 {
     Codec_Renamed = new RandomCodec(new Random(Random().Next()), new HashSet <string>());
     base.SetUp();
 }
        public override void Before(LuceneTestCase testInstance)
        {
            // LUCENENET specific - SOLR setup code removed

            // if verbose: print some debugging stuff about which codecs are loaded.
            if (LuceneTestCase.Verbose)
            {
                // LUCENENET: Only list the services if the underlying ICodecFactory
                // implements IServiceListable
                if (Codec.GetCodecFactory() is IServiceListable)
                {
                    ICollection <string> codecs = Codec.AvailableCodecs;
                    foreach (string codec in codecs)
                    {
                        Console.WriteLine("Loaded codec: '" + codec + "': " + Codec.ForName(codec).GetType().Name);
                    }
                }

                // LUCENENET: Only list the services if the underlying IPostingsFormatFactory
                // implements IServiceListable
                if (PostingsFormat.GetPostingsFormatFactory() is IServiceListable)
                {
                    ICollection <string> postingsFormats = PostingsFormat.AvailablePostingsFormats;
                    foreach (string postingsFormat in postingsFormats)
                    {
                        Console.WriteLine("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.ForName(postingsFormat).GetType().Name);
                    }
                }
            }

            savedInfoStream = InfoStream.Default;
            Random random = LuceneTestCase.Random;
            bool   v      = random.NextBoolean();

            if (LuceneTestCase.UseInfoStream)
            {
                InfoStream.Default = new ThreadNameFixingPrintStreamInfoStream(Console.Out);
            }
            else if (v)
            {
                InfoStream.Default = new NullInfoStream();
            }

            Type targetClass = testInstance?.GetType() ?? LuceneTestCase.GetTestClass();

            avoidCodecs = new JCG.HashSet <string>();
            var suppressCodecsAttribute = targetClass.GetCustomAttribute <LuceneTestCase.SuppressCodecsAttribute>();

            if (suppressCodecsAttribute != null)
            {
                avoidCodecs.UnionWith(suppressCodecsAttribute.Value);
            }

            // set back to default
            LuceneTestCase.OldFormatImpersonationIsActive = false;

            savedCodec = Codec.Default;
            int randomVal = random.Next(10);

            if ("Lucene3x".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                          "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                          "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                          randomVal == 3 &&
                                                                                          !ShouldAvoidCodec("Lucene3x"))) // preflex-only setup
            {
                codec = Codec.ForName("Lucene3x");
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is PreFlexRWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
                LuceneTestCase.OldFormatImpersonationIsActive = true;
            }
            else if ("Lucene40".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 0 &&
                                                                                               !ShouldAvoidCodec("Lucene40"))) // 4.0 setup
            {
                codec = Codec.ForName("Lucene40");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene40RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((PostingsFormat.ForName("Lucene40") is Lucene40RWPostingsFormat), "fix your IPostingsFormatFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if ("Lucene41".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 1 &&
                                                                                               !ShouldAvoidCodec("Lucene41")))
            {
                codec = Codec.ForName("Lucene41");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene41RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if ("Lucene42".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 2 &&
                                                                                               !ShouldAvoidCodec("Lucene42")))
            {
                codec = Codec.ForName("Lucene42");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene42RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if ("Lucene45".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) || ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) &&
                                                                                               "random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) &&
                                                                                               randomVal == 5 &&
                                                                                               !ShouldAvoidCodec("Lucene45")))
            {
                codec = Codec.ForName("Lucene45");
                LuceneTestCase.OldFormatImpersonationIsActive = true;
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert((codec is Lucene45RWCodec), "fix your ICodecFactory to scan Lucene.Net.Tests before Lucene.Net.TestFramework");
                }
            }
            else if (("random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal) == false) ||
                     ("random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal) == false))
            {
                // the user wired postings or DV: this is messy
                // refactor into RandomCodec....

                PostingsFormat format;
                if ("random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal))
                {
                    format = PostingsFormat.ForName("Lucene41");
                }
                else if ("MockRandom".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal))
                {
                    format = new MockRandomPostingsFormat(new Random(random.Next()));
                }
                else
                {
                    format = PostingsFormat.ForName(LuceneTestCase.TestPostingsFormat);
                }

                DocValuesFormat dvFormat;
                if ("random".Equals(LuceneTestCase.TestDocValuesFormat, StringComparison.Ordinal))
                {
                    dvFormat = DocValuesFormat.ForName("Lucene45");
                }
                else
                {
                    dvFormat = DocValuesFormat.ForName(LuceneTestCase.TestDocValuesFormat);
                }

                codec = new Lucene46CodecAnonymousClass(format, dvFormat);
            }
            else if ("SimpleText".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 9 && LuceneTestCase.Rarely(random) && !ShouldAvoidCodec("SimpleText")))
            {
                codec = new SimpleTextCodec();
            }
            else if ("CheapBastard".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 8 && !ShouldAvoidCodec("CheapBastard") && !ShouldAvoidCodec("Lucene41")))
            {
                // we also avoid this codec if Lucene41 is avoided, since thats the postings format it uses.
                codec = new CheapBastardCodec();
            }
            else if ("Asserting".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 6 && !ShouldAvoidCodec("Asserting")))
            {
                codec = new AssertingCodec();
            }
            else if ("Compressing".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) ||
                     ("random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal) && randomVal == 5 && !ShouldAvoidCodec("Compressing")))
            {
                codec = CompressingCodec.RandomInstance(random);
            }
            else if (!"random".Equals(LuceneTestCase.TestCodec, StringComparison.Ordinal))
            {
                codec = Codec.ForName(LuceneTestCase.TestCodec);
            }
            else if ("random".Equals(LuceneTestCase.TestPostingsFormat, StringComparison.Ordinal))
            {
                codec = new RandomCodec(random, avoidCodecs);
            }
            else
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(false);
                }
            }
            Codec.Default = codec;

            // Initialize locale/ timezone.
            string testLocale   = SystemProperties.GetProperty("tests:locale", "random");   // LUCENENET specific - reformatted with :
            string testTimeZone = SystemProperties.GetProperty("tests:timezone", "random"); // LUCENENET specific - reformatted with :

            // Always pick a random one for consistency (whether tests.locale was specified or not).
            savedLocale = CultureInfo.CurrentCulture;
            CultureInfo randomLocale = LuceneTestCase.RandomCulture(random);

            locale = testLocale.Equals("random", StringComparison.Ordinal) ? randomLocale : LuceneTestCase.CultureForName(testLocale);
#if FEATURE_CULTUREINFO_CURRENTCULTURE_SETTER
            CultureInfo.CurrentCulture = locale;
#else
            Thread.CurrentThread.CurrentCulture = locale;
#endif

            // TimeZone.getDefault will set user.timezone to the default timezone of the user's locale.
            // So store the original property value and restore it at end.
            // LUCENENET specific - commented
            //restoreProperties["user:timezone"] = SystemProperties.GetProperty("user:timezone");
            savedTimeZone = TimeZoneInfo.Local;
            TimeZoneInfo randomTimeZone = LuceneTestCase.RandomTimeZone(random);
            timeZone = testTimeZone.Equals("random", StringComparison.Ordinal) ? randomTimeZone : TimeZoneInfo.FindSystemTimeZoneById(testTimeZone);
            //TimeZone.Default = TimeZone; // LUCENENET NOTE: There doesn't seem to be an equivalent to this, but I don't think we need it.
            similarity = random.NextBoolean() ? (Similarity) new DefaultSimilarity() : new RandomSimilarityProvider(random);

            // Check codec restrictions once at class level.
            try
            {
                CheckCodecRestrictions(codec);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("NOTE: " + e.Message + " Suppressed codecs: " + avoidCodecs);
                throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
            }
        }
Esempio n. 53
0
 /// <summary>
 /// Sole constructor. When subclassing this codec,
 /// create a no-arg ctor and pass the delegate codec
 /// and a unique name to this ctor.
 /// </summary>
 protected internal FilterCodec(string name, Codec @delegate)
     : base(name)
 {
     this.@delegate = @delegate;
 }
Esempio n. 54
0
        public OperationsFactory(string cacheName, int topologyId, bool forceReturnValue, Codec codec)
        {
            if (cacheName.Equals("default"))
            {
                this.cacheNameBytes = DEFAULT_CACHE_NAME_BYTES; //For base client using the default cache
            }
            else
            {
                this.cacheNameBytes = this.e.GetBytes(cacheName);
            }

            this.topologyId       = topologyId;
            this.forceReturnValue = forceReturnValue;
            this.codec            = codec;
        }
Esempio n. 55
0
		public override void EncodeToFile( Stream input, string outFileName, Codec.CodecData data )
		{
			throw new NotImplementedException();
		}
Esempio n. 56
0
        internal virtual void SealFlushedSegment(FlushedSegment flushedSegment)
        {
            Debug.Assert(flushedSegment != null);

            SegmentCommitInfo newSegment = flushedSegment.segmentInfo;

            IndexWriter.SetDiagnostics(newSegment.Info, IndexWriter.SOURCE_FLUSH);

            IOContext context = new IOContext(new FlushInfo(newSegment.Info.DocCount, newSegment.GetSizeInBytes()));

            bool success = false;

            try
            {
                if (indexWriterConfig.UseCompoundFile)
                {
                    Collections.AddAll(filesToDelete, IndexWriter.CreateCompoundFile(infoStream, directory, CheckAbort.NONE, newSegment.Info, context));
                    newSegment.Info.UseCompoundFile = true;
                }

                // Have codec write SegmentInfo.  Must do this after
                // creating CFS so that 1) .si isn't slurped into CFS,
                // and 2) .si reflects useCompoundFile=true change
                // above:
                codec.SegmentInfoFormat.SegmentInfoWriter.Write(directory, newSegment.Info, flushedSegment.fieldInfos, context);

                // TODO: ideally we would freeze newSegment here!!
                // because any changes after writing the .si will be
                // lost...

                // Must write deleted docs after the CFS so we don't
                // slurp the del file into CFS:
                if (flushedSegment.liveDocs != null)
                {
                    int delCount = flushedSegment.delCount;
                    Debug.Assert(delCount > 0);
                    if (infoStream.IsEnabled("DWPT"))
                    {
                        infoStream.Message("DWPT", "flush: write " + delCount + " deletes gen=" + flushedSegment.segmentInfo.DelGen);
                    }

                    // TODO: we should prune the segment if it's 100%
                    // deleted... but merge will also catch it.

                    // TODO: in the NRT case it'd be better to hand
                    // this del vector over to the
                    // shortly-to-be-opened SegmentReader and let it
                    // carry the changes; there's no reason to use
                    // filesystem as intermediary here.

                    SegmentCommitInfo info  = flushedSegment.segmentInfo;
                    Codec             codec = info.Info.Codec;
                    codec.LiveDocsFormat.WriteLiveDocs(flushedSegment.liveDocs, directory, info, delCount, context);
                    newSegment.DelCount = delCount;
                    newSegment.AdvanceDelGen();
                }

                success = true;
            }
            finally
            {
                if (!success)
                {
                    if (infoStream.IsEnabled("DWPT"))
                    {
                        infoStream.Message("DWPT", "hit exception creating compound file for newly flushed segment " + newSegment.Info.Name);
                    }
                }
            }
        }
Esempio n. 57
0
		public override Stream Encode( Stream input, Codec.CodecData data )
		{
			throw new NotImplementedException( "Encode to memory not implemented" );
		}
Esempio n. 58
0
 public ValueTests()
 {
     _codec = new Codec();
 }
Esempio n. 59
0
 public void SetDoNotDisturb(DoNotDisturbMode mode)
 {
     Codec.Send("xCommand Conference DoNotDisturb {0}",
                mode == DoNotDisturbMode.Active ? "Activate" : "Deactivate");
 }
Esempio n. 60
0
 public ValueTests(ITestOutputHelper output)
 {
     _output = output;
     _codec  = new Codec();
 }