public void TestSize1()
        {
            CyclicBuffer cb = new CyclicBuffer(1);

            Assert.AreEqual(0, cb.Length, "Empty Buffer should have length 0");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should have max size 1");

            LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);

            LoggingEvent discardedEvent = cb.Append(event1);

            Assert.IsNull(discardedEvent, "No event should be discarded untill the buffer is full");
            Assert.AreEqual(1, cb.Length, "Buffer should have length 1");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should still have max size 1");


            discardedEvent = cb.Append(event2);

            Assert.AreSame(event1, discardedEvent, "Expect event1 to now be discarded");
            Assert.AreEqual(1, cb.Length, "Buffer should still have length 1");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should really still have max size 1");

            LoggingEvent[] discardedEvents = cb.PopAll();

            Assert.AreEqual(1, discardedEvents.Length, "Poped events length should be 1");
            Assert.AreSame(event2, discardedEvents[0], "Expect event2 to now be popped");
            Assert.AreEqual(0, cb.Length, "Buffer should be back to length 0");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should really really still have max size 1");
        }
Пример #2
0
        public void TestSize1()
        {
            CyclicBuffer cb = new CyclicBuffer(1);

            Assert.AreEqual(0, cb.Length, "空缓冲区的长度应该为0");   //Empty Buffer should have length 0
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的最大大小应该是1"); //Buffer should have max size 1

            LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);

            LoggingEvent discardedEvent = cb.Append(event1);

            Assert.IsNull(discardedEvent, "在缓冲区满之前,不应该丢弃任何事件"); //No event should be discarded untill the buffer is full
            Assert.AreEqual(1, cb.Length, "缓冲区的长度应该为1");        //Buffer should have length 1
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的大小应该仍然是1");     //Buffer should still have max size 1


            discardedEvent = cb.Append(event2);

            Assert.AreSame(event1, discardedEvent, "现在可以预期event1将被丢弃"); //Expect event1 to now be discarded
            Assert.AreEqual(1, cb.Length, "缓冲区的长度应该仍然为1");              //Buffer should still have length 1
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的大小应该仍然是1");             //Buffer should really still have max size 1

            LoggingEvent[] discardedEvents = cb.PopAll();

            Assert.AreEqual(1, discardedEvents.Length, "取出事件的长度应该是1");    //Poped events length should be 1
            Assert.AreSame(event2, discardedEvents[0], "预计event2现在会被取出"); //Expect event2 to now be popped
            Assert.AreEqual(0, cb.Length, "缓冲区的长度应该回到0");                 //Buffer should be back to length 0
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的大小应该仍然是1");               //Buffer should really really still have max size 1
        }
Пример #3
0
	// Use this for initialization
	void Start () {
        CyclicBuffer<int> test = new CyclicBuffer<int>(9);

        int val = 5;
        for (int i = 0; i < 8; i++)
        {
            val++;
            Debug.Log("CyclicBuffer in " + val);
            test.Add(val);
        }

        for (int i = 0; i < 6; i++)
        {
            Debug.Log("CyclicBuffer out " + test.GetFirst());
        }

        for (int i = 0; i < 4; i++)
        {
            val++;
            Debug.Log("CyclicBuffer in " + val);
            test.Add(val);
        }

        for (int i = 0; i < 6; i++)
        {
            Debug.Log("CyclicBuffer out " + test.GetFirst());
        }
    }
Пример #4
0
        [Test] public void TestSize2()
        {
            CyclicBuffer cb = new CyclicBuffer(2);

            Assert.AreEqual(0, cb.Length, "Empty Buffer should have length 0");
            Assert.AreEqual(2, cb.MaxSize, "Buffer should have max size 2");

            LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event3 = new LoggingEvent(null, null, null, null, null, null);

            LoggingEvent discardedEvent = null;

            discardedEvent = cb.Append(event1);
            Assert.IsNull(discardedEvent, "No event should be discarded after append 1");
            discardedEvent = cb.Append(event2);
            Assert.IsNull(discardedEvent, "No event should be discarded after append 2");

            discardedEvent = cb.Append(event3);
            Assert.AreSame(event1, discardedEvent, "Expect event1 to now be discarded");

            discardedEvent = cb.PopOldest();
            Assert.AreSame(event2, discardedEvent, "Expect event2 to now be discarded");

            LoggingEvent[] discardedEvents = cb.PopAll();

            Assert.AreEqual(1, discardedEvents.Length, "Poped events length should be 1");
            Assert.AreSame(event3, discardedEvents[0], "Expect event3 to now be popped");
            Assert.AreEqual(0, cb.Length, "Buffer should be back to length 0");
            Assert.AreEqual(2, cb.MaxSize, "Buffer should really really still have max size 2");
        }
Пример #5
0
        public void FinishedTest()
        {
            var buffer = new CyclicBuffer <char>(10);

            Assert.IsFalse(buffer.Finished);
            buffer.Write('o');
            buffer.Write('l');
            buffer.Write('a');
            buffer.Write('k');
            buffer.Write('e');
            buffer.Write('a');
            buffer.Write('s');
            buffer.Dispose();
            Assert.IsTrue(buffer.Finished);
            buffer.Write('e');
            var  builder = new StringBuilder();
            char read;

            do
            {
                read = buffer.Read();
                builder.Append(read);
            } while (read != default(char));
            Assert.AreEqual(builder.ToString(), "olakeas");
        }
Пример #6
0
 public override void ActivateOptions()
 {
     base.ActivateOptions();
     if (this.m_lossy && (this.m_evaluator == null))
     {
         this.ErrorHandler.Error("Appender [" + base.Name + "] is Lossy but has no Evaluator. The buffer will never be sent!");
     }
     this.m_cb = (this.m_bufferSize <= 1) ? null : new CyclicBuffer(this.m_bufferSize);
 }
Пример #7
0
            public Connection(Socket socket, bool isSocketAccepted, int receivedQueueSize)
            {
                Id = NewConnectionId();

                ReceiveQueue = new CyclicBuffer(receivedQueueSize);
                SpinLock     = new SpinLock();

                Socket           = socket;
                IsSocketAccepted = isSocketAccepted;
                RemoteEndPoint   = socket.RemoteEndPoint as IPEndPoint;
            }
Пример #8
0
        public AudioEncoder(EncoderSettings settings, string path, Stream IO = null)
        {
            m_settings  = settings;
            _path       = path;
            useTempFile = m_settings.Parameters.Contains("%I");
            tempFile    = path + ".tmp.wav";

            _encoderProcess = new Process();
            _encoderProcess.StartInfo.FileName       = m_settings.Path;
            _encoderProcess.StartInfo.Arguments      = m_settings.Parameters.Replace("%O", "\"" + path + "\"").Replace("%M", m_settings.EncoderMode).Replace("%P", m_settings.Padding.ToString()).Replace("%I", "\"" + tempFile + "\"");
            _encoderProcess.StartInfo.CreateNoWindow = true;
            if (!useTempFile)
            {
                _encoderProcess.StartInfo.RedirectStandardInput = true;
            }
            _encoderProcess.StartInfo.UseShellExecute = false;
            if (!m_settings.Parameters.Contains("%O"))
            {
                _encoderProcess.StartInfo.RedirectStandardOutput = true;
            }
            if (useTempFile)
            {
                wrt = new WAV.AudioEncoder(new WAV.EncoderSettings(settings.PCM), tempFile);
                return;
            }
            bool      started = false;
            Exception ex      = null;

            try
            {
                started = _encoderProcess.Start();
                if (started)
                {
                    _encoderProcess.PriorityClass = Process.GetCurrentProcess().PriorityClass;
                }
            }
            catch (Exception _ex)
            {
                ex = _ex;
            }
            if (!started)
            {
                throw new Exception(m_settings.Path + ": " + (ex == null ? "please check the path" : ex.Message));
            }
            if (_encoderProcess.StartInfo.RedirectStandardOutput)
            {
                Stream outputStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
                outputBuffer = new CyclicBuffer(2 * 1024 * 1024, _encoderProcess.StandardOutput.BaseStream, outputStream);
            }
            Stream inputStream = new CyclicBufferOutputStream(_encoderProcess.StandardInput.BaseStream, 128 * 1024);

            wrt = new WAV.AudioEncoder(new WAV.EncoderSettings(settings.PCM), path, inputStream);
        }
Пример #9
0
        public void TestConstructorSize0()
        {
            CyclicBuffer cb = null;

            try
            {
                cb = new CyclicBuffer(0);
            }
            catch
            {
            }

            Assert.IsNull(cb);
        }
Пример #10
0
        /// <summary>
        /// Initialise the appender based on the options set
        /// </summary>
        override public void ActivateOptions()
        {
            base.ActivateOptions();

            // If the appender is in Lossy mode then we will
            // only send the buffer when the Evaluator triggers
            // therefore check we have an evaluator.
            if (m_lossy && m_evaluator == null)
            {
                ErrorHandler.Error("Appender [" + Name + "] is Lossy but has no Evaluator. The buffer will never be sent!");
            }

            m_cb = new CyclicBuffer(m_bufferSize);
        }
Пример #11
0
 /// <summary>
 /// Initialize the appender based on the options set
 /// </summary>
 /// <remarks>
 /// <para>
 /// This is part of the <see cref="T:log4net.Core.IOptionHandler" /> delayed object
 /// activation scheme. The <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions" /> method must
 /// be called on this object after the configuration properties have
 /// been set. Until <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions" /> is called this
 /// object is in an undefined state and must not be used.
 /// </para>
 /// <para>
 /// If any of the configuration properties are modified then
 /// <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions" /> must be called again.
 /// </para>
 /// </remarks>
 public override void ActivateOptions()
 {
     base.ActivateOptions();
     if (m_lossy && m_evaluator == null)
     {
         ErrorHandler.Error("Appender [" + base.Name + "] is Lossy but has no Evaluator. The buffer will never be sent!");
     }
     if (m_bufferSize > 1)
     {
         m_cb = new CyclicBuffer(m_bufferSize);
     }
     else
     {
         m_cb = null;
     }
 }
Пример #12
0
 protected virtual void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
 {
     LoggingEvent[] events = buffer.PopAll();
     if (firstLoggingEvent == null)
     {
         this.SendBuffer(events);
     }
     else if (events.Length == 0)
     {
         LoggingEvent[] eventArray1 = new LoggingEvent[] { firstLoggingEvent };
         this.SendBuffer(eventArray1);
     }
     else
     {
         LoggingEvent[] destinationArray = new LoggingEvent[] { firstLoggingEvent };
         Array.Copy(events, 0, destinationArray, 1, events.Length);
         this.SendBuffer(destinationArray);
     }
 }
Пример #13
0
 /// <summary>
 /// Sends the contents of the buffer.
 /// </summary>
 /// <param name="firstLoggingEvent">The first logging event.</param>
 /// <param name="buffer">The buffer containing the events that need to be send.</param>
 /// <remarks>
 /// <para>
 /// The subclass must override <see cref="M:SendBuffer(LoggingEvent[])" />.
 /// </para>
 /// </remarks>
 protected virtual void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
 {
     LoggingEvent[] array = buffer.PopAll();
     if (firstLoggingEvent == null)
     {
         SendBuffer(array);
         return;
     }
     if (array.Length == 0)
     {
         SendBuffer(new LoggingEvent[1]
         {
             firstLoggingEvent
         });
         return;
     }
     LoggingEvent[] array2 = new LoggingEvent[array.Length + 1];
     Array.Copy(array, 0, array2, 1, array.Length);
     array2[0] = firstLoggingEvent;
     SendBuffer(array2);
 }
        /// <summary>
        /// Sends the contents of the buffer.
        /// </summary>
        /// <param name="firstLoggingEvent">The first logging event.</param>
        /// <param name="buffer">The buffer containing the events that need to be send.</param>
        /// <remarks>
        /// <para>
        /// The subclass must override <see cref="SendBuffer(LoggingEvent[])"/>.
        /// </para>
        /// </remarks>
        virtual protected void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
        {
            LoggingEvent[] bufferEvents = buffer.PopAll();

            if (firstLoggingEvent == null)
            {
                SendBuffer(bufferEvents);
            }
            else if (bufferEvents.Length == 0)
            {
                SendBuffer(new LoggingEvent[] { firstLoggingEvent });
            }
            else
            {
                // Create new array with the firstLoggingEvent at the head
                LoggingEvent[] events = new LoggingEvent[bufferEvents.Length + 1];
                Array.Copy(bufferEvents, 0, events, 1, bufferEvents.Length);
                events[0] = firstLoggingEvent;

                SendBuffer(events);
            }
        }
        public void TestConstructorSize0()
        {
            CyclicBuffer cb = new CyclicBuffer(0);

            Assert.IsNotNull(cb);
        }
Пример #16
0
 public void TestConstructorSize0()
 {
     CyclicBuffer cb = new CyclicBuffer(0);
 }
Пример #17
0
 Initializer(Analyzer main, CyclicBuffer <Mat> frameBuffer)
 {
     Main        = main;
     FrameBuffer = frameBuffer;
 }
Пример #18
0
 /// <summary>
 /// Sends the contents of the buffer.
 /// </summary>
 /// <param name="buffer">The buffer containing the events that need to be send.</param>
 /// <remarks>
 /// The subclass must override either <see cref="SendBuffer(CyclicBuffer)"/>
 /// or <see cref="SendBuffer(LoggingEvent[])"/>.
 /// </remarks>
 virtual protected void SendBuffer(CyclicBuffer buffer)
 {
     SendBuffer(buffer.PopAll());
 }
		/// <summary>
		/// Initialize the appender based on the options set
		/// </summary>
		/// <remarks>
		/// <para>
		/// This is part of the <see cref="IOptionHandler"/> delayed object
		/// activation scheme. The <see cref="ActivateOptions"/> method must 
		/// be called on this object after the configuration properties have
		/// been set. Until <see cref="ActivateOptions"/> is called this
		/// object is in an undefined state and must not be used. 
		/// </para>
		/// <para>
		/// If any of the configuration properties are modified then 
		/// <see cref="ActivateOptions"/> must be called again.
		/// </para>
		/// </remarks>
		override public void ActivateOptions() 
		{
			base.ActivateOptions();

			// If the appender is in Lossy mode then we will
			// only send the buffer when the Evaluator triggers
			// therefore check we have an evaluator.
			if (m_lossy && m_evaluator == null)
			{
				ErrorHandler.Error("Appender ["+Name+"] is Lossy but has no Evaluator. The buffer will never be sent!"); 
			}

			if (m_bufferSize > 1)
			{
				m_cb = new CyclicBuffer(m_bufferSize);
			}
			else
			{
				m_cb = null;
			}
		}
Пример #20
0
        public void TestConstructorSize0()
        {
            CyclicBuffer cb = null;

            Assert.Throws <ArgumentOutOfRangeException>(() => cb = new CyclicBuffer(0));
        }
Пример #21
0
        public void HasBack()
        {
            var buffer  = new CyclicBuffer <char>(8);
            var builder = new StringBuilder();

            buffer.Write('a');
            buffer.Write('b');
            buffer.Write('c');
            buffer.Write('d');
            buffer.Write('e');
            char read;

            buffer.Read();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);

            buffer.Read();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);

            buffer.Read();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);

            buffer.Read();
            Assert.IsFalse(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);

            buffer.ReadBack();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);

            read = buffer.ReadBack();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);
            builder.Append(read);
            Assert.AreEqual(builder.ToString(), "c");

            read = buffer.ReadBack();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsTrue(buffer.HasBack);
            builder.Append(read);
            Assert.AreEqual(builder.ToString(), "cb");


            read = buffer.ReadBack();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsFalse(buffer.HasBack, "No HasBack");
            builder.Append(read);
            Assert.AreEqual(builder.ToString(), "cba");


            buffer.Write('f');

            read = buffer.Read();
            //Assert.IsTrue(buffer.HasFront, "NO HasFront");
            //Assert.IsFalse(buffer.HasBack, "No HasBack");
            builder.Append(read);
            Assert.AreEqual(builder.ToString(), "cbaa");
            buffer.Read();
            buffer.Read();
            buffer.Read();
            buffer.Read();
            read = buffer.Read();
            Assert.IsTrue(buffer.HasFront, "NO HasFront");
            Assert.IsFalse(buffer.HasBack, "No HasBack");
            builder.Append(read);
            Assert.AreEqual(builder.ToString(), "cbaaf");

            buffer.Write('g');
            buffer.Write('h');
            buffer.Write('i');
            buffer.Write('j');
            buffer.Write('k');
            buffer.Read();
            buffer.Write('l');
        }
		/// <summary>
		/// Sends the contents of the buffer.
		/// </summary>
		/// <param name="firstLoggingEvent">The first logging event.</param>
		/// <param name="buffer">The buffer containing the events that need to be send.</param>
		/// <remarks>
		/// <para>
		/// The subclass must override <see cref="M:SendBuffer(LoggingEvent[])"/>.
		/// </para>
		/// </remarks>
		virtual protected void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
		{
			LoggingEvent[] bufferEvents = buffer.PopAll();

			if (firstLoggingEvent == null)
			{
				SendBuffer(bufferEvents);
			}
			else if (bufferEvents.Length == 0)
			{
				SendBuffer(new LoggingEvent[] { firstLoggingEvent } );
			}
			else
			{
				// Create new array with the firstLoggingEvent at the head
				LoggingEvent[] events = new LoggingEvent[bufferEvents.Length + 1];
				Array.Copy(bufferEvents, 0, events, 1, bufferEvents.Length);
				events[0] = firstLoggingEvent;

				SendBuffer(events);
			}
		}