Ejemplo n.º 1
0
        private int CalculateQueueLength()
        {
            var queueLength = 0;
            var serializer  = new QueueRecordSerializer();

            foreach (var file in _files)
            {
                var startPosition = 0;
                var positionFile  = file.Replace(".dat", ".position");
                if (FileExists(positionFile))
                {
                    using (
                        var stream = new FileStream(positionFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite,
                                                    16384, FileOptions.SequentialScan))
                    {
                        if (stream.Length > 4)
                        {
                            stream.Position = stream.Length - 4;
                            var intBuffer = new byte[4];
                            var pos       = stream.Read(intBuffer, 0, 4);
                            startPosition = BitConverter.ToInt32(intBuffer, 0);
                        }
                    }
                }

                using (
                    var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 16384,
                                                FileOptions.SequentialScan))
                {
                    stream.Position = startPosition;
                    while (true)
                    {
                        var record = serializer.Read(stream);
                        if (record != null)
                        {
                            ++queueLength;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            return(queueLength);
        }
Ejemplo n.º 2
0
        private int CalculateQueueLength()
        {
            var queueLength = 0;
            var serializer = new QueueRecordSerializer();
            foreach (var file in _files)
            {
                var startPosition = 0;
                var positionFile = file.Replace(".dat", ".position");
                if (FileExists(positionFile))
                {
                    using (
                        var stream = new FileStream(positionFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite,
                            16384, FileOptions.SequentialScan))
                    {
                        if (stream.Length > 4)
                        {
                            stream.Position = stream.Length - 4;
                            var intBuffer = new byte[4];
                            var pos = stream.Read(intBuffer, 0, 4);
                            startPosition = BitConverter.ToInt32(intBuffer, 0);
                        }
                    }
                }

                using (
                    var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 16384,
                        FileOptions.SequentialScan))
                {
                    stream.Position = startPosition;
                    while (true)
                    {
                        var record = serializer.Read(stream);
                        if (record != null)
                            ++queueLength;
                        else
                            break;
                    }
                }
            }

            return queueLength;
        }