Пример #1
0
    //вернёт ооффсеты не нулевые в квадрате startPos endPos
    public BufferItem GetCollidersInRect(Vector2 startPos, Vector2 endPos, bool includingAll = false)
    {
        //List<Vector2Int> rezPos = new List<Vector2Int>();
        Buffer.NextBuffer();

        Vector2Int p0 = GetMapPos(startPos);
        Vector2Int p1 = GetMapPos(endPos);

        int minX = p0.x <= p1.x ? p0.x : p1.x;
        int minY = p0.y <= p1.y ? p0.y : p1.y;

        int maxX = p0.x >= p1.x ? p0.x : p1.x;
        int maxY = p0.y >= p1.y ? p0.y : p1.y;

        for (int x = minX; x <= maxX; x++)
        {
            for (int y = minY; y <= maxY; y++)
            {
                if (includingAll)
                {
                    Buffer.Add(new Vector2Int(x, y));
                }
                else
                {
                    if (!Map[x, y].IsEmpty())
                    {
                        Buffer.Add(new Vector2Int(x, y));
                    }
                }
            }
        }

        return(Buffer.GetCurrent);
    }
Пример #2
0
        public async Task GivenBufferListWhenFaultListFullShouldDrop()
        {
            var list = new BufferList <int>(new BufferListOptions(
                                                1,
                                                1,
                                                1,
                                                Timeout.InfiniteTimeSpan,
                                                TimeSpan.FromMilliseconds(10),
                                                TimeSpan.FromMilliseconds(100)));

            var dropped        = new List <int>(1);
            var autoResetEvent = new AutoResetEvent(false);
            var i = 0;

            list.Cleared += _ =>
            {
                if (++i == 2)
                {
                    autoResetEvent.Set();
                }
                throw new Exception();
            };
            list.Dropped += items => dropped.AddRange(items);

            list.Add(1);
            list.Add(2);
            await Task.Delay(250);

            dropped.Should().HaveCount(1);
            dropped.First().Should().Be(1);
            list.GetFailed().Should().HaveCount(1);
            list.GetFailed().First().Should().Be(2);
        }
Пример #3
0
 private static void OutputNoSearchResultsToSearchBuffer(Search search, BufferList searchBuffer)
 {
     if (search != null && !String.IsNullOrEmpty(search.DidYouMean))
     {
         searchBuffer.Add(new BufferItem("No search results. Did you mean: " + search.DidYouMean));
     }
     else
     {
         searchBuffer.Add(new BufferItem(StringStore.NoSearchResults));
     }
 }
Пример #4
0
        public void TestArraySegmentList()
        {
            var list = new BufferList();

            list.Add(new ArraySegment <byte>(new byte[1024], 0, 100));
            list.Add(new ArraySegment <byte>(new byte[1024], 2, 200));
            list.Add(new ArraySegment <byte>(new byte[1024], 3, 300));

            var lastOne = list.Last;

            Assert.Equal(3, lastOne.Offset);
            Assert.Equal(300, lastOne.Count);
        }
Пример #5
0
 /// <summary>
 /// 从本地缓存文件加载缓存数据
 /// </summary>
 public static void LoadLocalBufferList()
 {
     if (0 != BufferList.Count)
     {
         // 如果不为空, 说明已经load过了, 就不用再重新load了
         return;
     }
     else
     {
         // 否则如果为空, 检查是否存在本地缓存文件, 存在的话load进缓存数据列表里
         if (File.Exists(LocalBufFileName))
         {
             try
             {
                 // 读入缓存文件中被缓存的数据
                 StreamReader sr     = new StreamReader(LocalBufFileName);
                 string       rdLine = "";
                 while (null != (rdLine = sr.ReadLine()))
                 {
                     if (string.Empty != rdLine.Trim())
                     {
                         BufferList.Add(rdLine);
                     }
                 }
                 sr.Close();
                 File.Delete(LocalBufFileName);
             }
             catch (Exception ex)
             {
                 System.Diagnostics.Trace.WriteLine(ex.ToString());
             }
         }
     }
 }
Пример #6
0
        public void GivenBufferShouldTryToCleanListUntilBagIsEmpty()
        {
            var read           = 0;
            var maxSize        = 0;
            var count          = 0;
            var list           = new BufferList <int>(10, Timeout.InfiniteTimeSpan);
            var autoResetEvent = new AutoResetEvent(false);

            list.Cleared += removed =>
            {
                maxSize = Math.Max(maxSize, removed.Count);
                count  += removed.Count;
                ++read;
                if (read >= 10)
                {
                    autoResetEvent.Set();
                }
                ;
            };

            for (var i = 0; i < 100; i++)
            {
                list.Add(i);
            }

            autoResetEvent.WaitOne();
            maxSize.Should().Be(10);
            count.Should().BeCloseTo(100, 10);
            list.Dispose();
        }
Пример #7
0
        public async Task GivenBufferListWhenClearShouldDispatchAListCopy()
        {
            IReadOnlyList <int> removedList = null;

            var list           = new BufferList <int>(1000, Timeout.InfiniteTimeSpan);
            var autoResetEvent = new AutoResetEvent(false);

            list.Cleared += removed =>
            {
                removedList = removed;
                autoResetEvent.Set();
            };
            for (var i = 0; i <= 1000; i++)
            {
                list.Add(i);
            }

            autoResetEvent.WaitOne();

            GC.Collect(0);
            GC.Collect(1);
            GC.Collect(2);
            await Task.Delay(TimeSpan.FromSeconds(5));

            removedList.Should().NotBeNull();
        }
Пример #8
0
    public void Add(T val)
    {
        int idx = vals.Count;

        val2idx.Add(val, idx);
        idx2val.Add(idx, val);

        vals.Add(val);
    }
Пример #9
0
    public void Add(TKey key, TVal val)
    {
        int idx = keys.Count;

        key2idx.Add(key, idx);
        idx2key.Add(idx, key);

        keys.Add(key);
        vals.Add(val);
    }
Пример #10
0
        private static void ShuffleAndQueueTracks(BufferItem item, BufferList playQueue, BufferList tracklist)
        {
            var algorithm = new FisherYatesShuffle(new RandomWrapper());
            var shuffled  = tracklist.Shuffle(algorithm).ToList();

            foreach (var shuffledItem in shuffled.Where(i => i != item))
            {
                playQueue.Add(shuffledItem);
            }
        }
Пример #11
0
        public void GivenBufferListWhenAddAndDisposedShouldThrow()
        {
            var list = new BufferList <int>(1, Timeout.InfiniteTimeSpan);

            list.Dispose();

            Action action = () => list.Add(1);

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("The buffer has been disposed.");
        }
Пример #12
0
 protected override void Printing()
 {
     foreach (var product in Products)
     {
         var name = product.Name;
         if (!string.IsNullOrEmpty(product.Description))
         {
             name += $"({product.Description})";
         }
         BufferList.Add(PrinterCmdUtils.PrintLineLeftRight2("*" + product.Quantity, name, Printer.FormatLen, 2));
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
 }
Пример #13
0
        private void QueueRemainingTracksWithoutShuffling(BufferList playQueue, BufferList tracklist)
        {
            int indexOfTrack = tracklist.CurrentItemIndex;

            if (indexOfTrack > 0)
            {
                var preceedingTracks = tracklist.Take(indexOfTrack).Cast <TrackBufferItem>().Select(i => i.Model);
                playbackManager.PutTracksIntoPreviousTracks(preceedingTracks);
            }
            for (int index = indexOfTrack + 1; index < tracklist.Count; index++)
            {
                playQueue.Add(tracklist[index]);
            }
        }
Пример #14
0
 private void Format(string name, string description)
 {
     BeforePrint();
     if (!string.IsNullOrEmpty(description))
     {
         name += $"({description})";
     }
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3));
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     BufferList.Add(PrinterCmdUtils.PrintLineLeftRight(name, "*1", Printer.FormatLen, 3));
     BufferList.Add(PrinterCmdUtils.NextLine());
     AfterPrint();
     Send();
 }
Пример #15
0
        protected override async Task ReadNextResponseAsync()
        {
            if (BufferList.Count > 10)
            {
                CheckInBuffers();
            }

            var buffer = await BufferManager.CheckOutAsync().ConfigureAwait(false);

            BufferList.Add(buffer);
            var bytesRead = await _stream.ReadAsync(buffer.Array, buffer.Offset, buffer.Count).ConfigureAwait(false);

            CurrentResponse = new ArraySegment <byte>(buffer.Array, buffer.Offset, bytesRead);
            CurrentPosition = 0;
        }
Пример #16
0
 protected override void Printing()
 {
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3));
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     foreach (var product in Products)
     {
         var name = product.Name;
         if (!string.IsNullOrEmpty(product.Description))
         {
             name += $"({product.Description})";
         }
         BufferList.Add(PrinterCmdUtils.PrintLineLeftRight(name, "*" + double.Parse(product.Quantity + "").ToString(), Printer.FormatLen, 3));
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
 }
Пример #17
0
        public void GivenBufferListWhenDisposeShouldClear()
        {
            var removedCount = 0;

            var list = new BufferList <int>(1000, TimeSpan.FromSeconds(10));

            list.Cleared += removed => { removedCount = removed.Count(); };
            for (var i = 0; i < 1000; i++)
            {
                list.Add(i);
            }

            list.Dispose();
            removedCount.Should().Be(1000);
        }
Пример #18
0
        //---------------------------------------------------------------------
        public override BufferedPackageInfo <ushort> ResolvePackage(IList <ArraySegment <byte> > package_data)
        {
            using (var reader = this.GetBufferReader <BufferedPackageInfo <ushort> >(package_data))
            {
                ushort body_len = reader.ReadUInt16(true);

                //var bl = reader.Take(body_len);

                byte[] data = new byte[body_len];
                reader.ReadBytes(data, 0, body_len);
                BufferList buf = new BufferList();
                buf.Add(new ArraySegment <byte>(data), new BufferState());
                return(new BufferedPackageInfo <ushort>(body_len, buf));

                //return mPackage;
                //return new BufferedPackageInfo<ushort>(body_len, package_data);
            }
        }
Пример #19
0
        public void GivenBufferWhenThrowOnClearingShouldRequeue()
        {
            const int BATCHING_SIZE = 100;
            var       list          = new BufferList <int>(BATCHING_SIZE, TimeSpan.FromSeconds(1));
            var       faultCount    = 0;

            list.Cleared  += removed => throw new Exception();
            list.Disposed += failed => Interlocked.Add(ref faultCount, failed.Count);
            list.Dropped  += dropped => Interlocked.Add(ref faultCount, dropped.Count);

            for (var i = 0; i < 1000; i++)
            {
                list.Add(i);
            }

            list.Dispose();
            faultCount.Should().Be(1000);
        }
Пример #20
0
 private void Format(string name, string description, double quantity, string remark)
 {
     BeforePrint();
     if (!string.IsNullOrEmpty(description))
     {
         name += $"({description})";
     }
     BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
     BufferList.Add(PrinterCmdUtils.AlignLeft());
     BufferList.Add(PrinterCmdUtils.PrintLineLeftRight2("*" + quantity, name, Printer.FormatLen, 2));
     BufferList.Add(PrinterCmdUtils.NextLine());
     if (remark != null)
     {
         BufferList.Add(TextToByte($"备注:{remark}"));
         BufferList.Add(PrinterCmdUtils.NextLine());
     }
     AfterPrint();
     Send();
 }
Пример #21
0
        protected override async Task ReadNextResponseAsync()
        {
            if (BufferList.Count > 10)
            {
                CheckInBuffers();
            }

            if (_asyncSocket.Connected == false)
            {
                throw new RedisException("Socket is not connected.");
            }

            var buffer = await BufferManager.CheckOutAsync().ConfigureAwait(false);

            BufferList.Add(buffer);
            CurrentResponse = await _asyncSocket.ReceiveAsync(buffer);

            CurrentPosition = 0;
        }
Пример #22
0
 /// <summary>
 /// 将字串追加到缓存列表的末尾
 /// </summary>
 /// <param name="cmdStr"></param>
 protected void AppendToBufferList(string cmdStr)
 {
     lock (BufferList)
     {
         if (null == BufferList)
         {
             BufferList = new List <string>();
         }
         BufferList.Add(cmdStr);
         try
         {
             StreamWriter sw = new StreamWriter(LocalBufFileName, true);
             sw.WriteLine(cmdStr);
             sw.Close();
         }
         catch (Exception ex)
         {
             System.Diagnostics.Trace.WriteLine(ex.ToString());
         }
     }
 }
Пример #23
0
        public void GivenBufferListWhenCapacityAchievedShouldClear()
        {
            var removedCount = 0;

            var list           = new BufferList <int>(100, Timeout.InfiniteTimeSpan);
            var autoResetEvent = new AutoResetEvent(false);

            list.Cleared += removed =>
            {
                removedCount = removed.Count;
                autoResetEvent.Set();
            };
            for (var i = 0; i <= 100; i++)
            {
                list.Add(i);
            }

            autoResetEvent.WaitOne();
            removedCount.Should().Be(100);
            list.Should().HaveCount(1);
        }
Пример #24
0
        public void GivenBufferListWhenTtlElapsedShouldClear()
        {
            var autoResetEvent = new AutoResetEvent(false);
            var removedCount   = 0;

            var list = new BufferList <int>(1000, TimeSpan.FromSeconds(1));

            list.Cleared += removed =>
            {
                removedCount = removed.Count;
                autoResetEvent.Set();
            };
            for (var i = 0; i < 999; i++)
            {
                list.Add(i);
            }
            autoResetEvent.WaitOne();

            removedCount.Should().Be(999);
            list.Should().BeEmpty();
        }
Пример #25
0
        public void Split()
        {
            _bytes = GetBytes(_msg);
            var bytes = new byte[4096];

            bytes[0] = _bytes[0];
            var x = new BufferList {
                new ArraySegment <byte>(bytes, 0, 1)
            };
            var count = _bytes.Length;
            var r     = _receiveFilter.Filter(x, out _rest);

            Assert.Equal(r, null);
            Assert.Equal(_rest, 0);
            var a = new byte[count - 1];

            Array.Copy(_bytes, 1, a, 0, count - 1);
            x.Add(new ArraySegment <byte>(a));
            r = _receiveFilter.Filter(x, out _rest);
            Assert.Equal(r.Body, _msg, _compare);
            Assert.Equal(_rest, 0);
        }
Пример #26
0
        public async Task GivenBufferListWhenDisposeShouldFullClearList()
        {
            var count  = 0;
            var source = new CancellationTokenSource(TimeSpan.FromSeconds(5));

            var list = new BufferList <int>(10, Timeout.InfiniteTimeSpan);

            list.Cleared += removed => Interlocked.Add(ref count, removed.Count);
            var tasks    = new Task[10];
            var expected = 0;

            for (var i = 0; i < 10; i++)
            {
                tasks[i] = Task.Factory.StartNew(async() =>
                {
                    while (!source.Token.IsCancellationRequested)
                    {
                        list.Add(i);
                        Interlocked.Increment(ref expected);
                        await Task.Delay(10);
                    }
                });
            }

            var autoResetEvent = new AutoResetEvent(false);

            source.Token.Register(() =>
            {
                list.Dispose();
                autoResetEvent.Set();
            });

            autoResetEvent.WaitOne();
            await Task.WhenAll(tasks);

            count.Should().Be(expected);
        }
Пример #27
0
        public async Task GivenBufferWhenFailedHasAnyShouldDispatchClearForFailedMessages()
        {
            var list           = new BufferList <int>(1, Timeout.InfiniteTimeSpan);
            var autoResetEvent = new AutoResetEvent(false);
            var i = 0;

            list.Cleared += removed =>
            {
                autoResetEvent.Set();
                if (++i == 1)
                {
                    throw new Exception();
                }
            };


            list.Add(1);
            autoResetEvent.WaitOne();
            await Task.Delay(300);

            list.GetFailed().Should().NotBeEmpty();
            list.Clear();
            list.GetFailed().Should().BeEmpty();
        }
        void AcquisitionStart()
        {
            Helpers.Log.LogThisInfo("DEVICE PARAMETER SETUP\n");
            Helpers.Log.LogThisInfo("######################\n\n");

            IsProcessing = true;
            try
            {
                //SET TRIGGER MODE OFF (FreeRun)
                Helpers.Log.LogThisInfo("         TriggerMode:             {0}\n", (string)mDevice.RemoteNodeList["TriggerMode"].Value);

                if (Parameters.TriggerMode)
                {
                    mDevice.RemoteNodeList["TriggerMode"].Value     = "On";
                    mDevice.RemoteNodeList["LineSelector"].Value    = "Line1";
                    mDevice.RemoteNodeList["TriggerSource"].Value   = "All";                  //Or Line0
                    mDevice.RemoteNodeList["LineSelector"].Value    = "Line1";
                    mDevice.RemoteNodeList["LineSource"].Value      = "Line0";
                    mDevice.RemoteNodeList["LineInverter"].Value    = false;
                    mDevice.RemoteNodeList["UserOutputValue"].Value = true;
                    mDevice.RemoteNodeList["TriggerDelay"].Value    = (double)Parameters.TriggerDelay;
                }
                else
                {
                    mDevice.RemoteNodeList["TriggerMode"].Value  = "Off";
                    mDevice.RemoteNodeList["LineInverter"].Value = false;
                }
                if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTime"))
                {
                    sExposureNodeName = "ExposureTime";
                }
                else if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTimeAbs"))
                {
                    sExposureNodeName = "ExposureTimeAbs";
                }

                //get current value and limits
                //Parameters.ExposureValue = (double)mDevice.RemoteNodeList[sExposureNodeName].Value;
                Parameters.ExposureMin = (double)mDevice.RemoteNodeList[sExposureNodeName].Min;
                Parameters.ExposureMax = (double)mDevice.RemoteNodeList[sExposureNodeName].Max;

                if (Parameters.ExposureValue < Parameters.ExposureMin)
                {
                    Parameters.ExposureValue = Parameters.ExposureMin;
                }

                if (Parameters.ExposureValue > Parameters.ExposureMax)
                {
                    Parameters.ExposureValue = Parameters.ExposureMax;
                }

                mDevice.RemoteNodeList[sExposureNodeName].Value = Parameters.ExposureValue;

                Helpers.Log.LogThisInfo("         ==>Line Selector:             {0}\n         ==>Trigger Source:             {1}\n         ==>Line Source:             {2}\n         ==>Line Inverter:             {3}\n", mDevice.RemoteNodeList["LineSelector"].Value, mDevice.RemoteNodeList["TriggerSource"].Value, mDevice.RemoteNodeList["LineSource"].Value, mDevice.RemoteNodeList["Line Inverter"].Value);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }


            Helpers.Log.LogThisInfo("DATA STREAM LIST\n");
            Helpers.Log.LogThisInfo("################\n\n");

            try
            {
                //COUNTING AVAILABLE DATASTREAMS
                datastreamList = mDevice.DataStreams;
                datastreamList.Refresh();

                //Helpers.Log.LogThisInfo("5.1.8   Detected datastreams:     {0}\n", datastreamList.Count);
                ////DATASTREAM INFORMATION BEFORE OPENING
                //foreach (KeyValuePair<string, BGAPI2.DataStream> dst_pair in datastreamList)
                //{
                //    Helpers.Log.LogThisInfo("  5.2.4   DataStream ID:          {0}\n\n", dst_pair.Key);
                //}
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }


            Helpers.Log.LogThisInfo("DATA STREAM\n");
            Helpers.Log.LogThisInfo("###########\n\n");

            //OPEN THE FIRST DATASTREAM IN THE LIST
            try
            {
                foreach (KeyValuePair <string, BGAPI2.DataStream> dst_pair in datastreamList)
                {
                    Helpers.Log.LogThisInfo("5.1.9   Open first datastream \n");
                    Helpers.Log.LogThisInfo("          DataStream ID:          {0}\n\n", dst_pair.Key);
                    //if (dst_pair.Value.IsOpen || dst_pair.Value.IsGrabbing )
                    //{
                    if (mDevice.RemoteNodeList.GetNodePresent("AcquisitionAbort") == true)
                    {
                        mDevice.RemoteNodeList["AcquisitionAbort"].Execute();
                        Helpers.Log.LogThisInfo("5.1.12   {0} aborted\n", mDevice.Model);
                    }

                    mDevice.RemoteNodeList["AcquisitionStop"].Execute();
                    //dst_pair.Value.Close();
                    System.Threading.Thread.Sleep(50);
                    //}
                    dst_pair.Value.Open();
                    sDataStreamID = dst_pair.Key;
                    Helpers.Log.LogThisInfo("        Opened datastream - NodeList Information \n");
                    Helpers.Log.LogThisInfo("          StreamAnnounceBufferMinimum:  {0}\n", dst_pair.Value.NodeList["StreamAnnounceBufferMinimum"].Value);
                    if (dst_pair.Value.TLType == "GEV")
                    {
                        Helpers.Log.LogThisInfo("          StreamDriverModel:            {0}\n", dst_pair.Value.NodeList["StreamDriverModel"].Value);
                    }
                    Helpers.Log.LogThisInfo("  \n");
                    break;
                }
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }

            if (sDataStreamID == "")
            {
                Helpers.Log.LogThisInfo(" No DataStream found \n");
                Helpers.Log.LogThisInfo("\nEnd\nInput any number to close the program:\n");
                //Console.Read();
                mDevice.Close();
                mInterface.Close();
                mSystem.Close();
                IsProcessing = false;
                return;
            }
            else
            {
                mDataStream = datastreamList[sDataStreamID];
            }


            Helpers.Log.LogThisInfo("BUFFER LIST\n");
            Helpers.Log.LogThisInfo("###########\n\n");

            try
            {
                //BufferList
                bufferList = mDataStream.BufferList;

                // 4 buffers using internal buffer mode
                for (int i = 0; i < InternalBufferCount; i++)
                {
                    mBuffer = new BGAPI2.Buffer();
                    bufferList.Add(mBuffer);
                    mBuffer.QueueBuffer();
                }
                Helpers.Log.LogThisInfo("5.1.10   Announced buffers:       {0} using {1} [bytes]\n", bufferList.AnnouncedCount, mBuffer.MemSize * bufferList.AnnouncedCount);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }
            Helpers.Log.LogThisInfo("\n");

            Helpers.Log.LogThisInfo("CAMERA START\n");
            Helpers.Log.LogThisInfo("############\n\n");

            mDataStream.RegisterNewBufferEvent(BGAPI2.Events.EventMode.EVENT_HANDLER);
            System.Console.Write("        Register Event Mode to:   {0}\n\n", mDataStream.EventMode.ToString());
            mDataStream.NewBufferEvent += new BGAPI2.Events.DataStreamEventControl.NewBufferEventHandler(mDataStream_NewBufferEvent);

            //START DATASTREAM ACQUISITION
            try
            {
                mDataStream.StartAcquisition();
                Helpers.Log.LogThisInfo("5.1.12   DataStream started \n");
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }

            //START CAMERA
            try
            {
                mDevice.RemoteNodeList["AcquisitionStart"].Execute();
                Helpers.Log.LogThisInfo("5.1.12   {0} started \n", mDevice.Model);
            }
            catch (BGAPI2.Exceptions.IException ex)
            {
                Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
                Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
                Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
            }

            Status = BaumerStatus.Ready;
        }
Пример #29
0
        void ProcessPackageWithSessionID(Socket listenSocket, IPEndPoint remoteEndPoint, ArraySegment <byte> receivedData)
        {
            TPackageInfo requestInfo;

            string sessionID;

            int rest;

            try
            {
                var receiveData = new BufferList();
                receiveData.Add(receivedData);

                requestInfo = this.m_UdpRequestFilter.Filter(receiveData, out rest);
            }
            catch (Exception exc)
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("Failed to parse UDP package!", exc);
                }
                return;
            }

            var udpRequestInfo = requestInfo as IUdpPackageInfo;

            if (rest > 0)
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("The output parameter rest must be zero in this case!");
                }
                return;
            }

            if (udpRequestInfo == null)
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("Invalid UDP package format!");
                }
                return;
            }

            if (string.IsNullOrEmpty(udpRequestInfo.SessionID))
            {
                if (AppServer.Logger.IsErrorEnabled)
                {
                    AppServer.Logger.Error("Failed to get session key from UDP package!");
                }
                return;
            }

            sessionID = udpRequestInfo.SessionID;

            var appSession = AppServer.GetSessionByID(sessionID);

            if (appSession == null)
            {
                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                var socketSession = new UdpSocketSession(listenSocket, remoteEndPoint, sessionID);
                appSession = AppServer.CreateAppSession(socketSession);

                if (appSession == null)
                {
                    return;
                }

                if (!DetectConnectionNumber(remoteEndPoint))
                {
                    return;
                }

                if (!AppServer.RegisterSession(appSession))
                {
                    return;
                }

                Interlocked.Increment(ref m_ConnectionCount);

                socketSession.Closed += OnSocketSessionClosed;
                socketSession.Start();
            }
            else
            {
                var socketSession = appSession.SocketSession as UdpSocketSession;
                //Client remote endpoint may change, so update session to ensure the server can find client correctly
                socketSession.UpdateRemoteEndPoint(remoteEndPoint);
            }

            m_RequestHandler.ExecuteCommand(appSession, requestInfo);
        }
Пример #30
0
 public void Publish(Exchange exchange, Queue queue, RoutingKey routingKey, Message message)
 {
     _publisherBuffer.Add(new BatchItem(exchange, queue, routingKey, message));
 }