Exemplo n.º 1
0
        public long Write(byte[] data)
        {
            ThrowIfStreamClosed();

            var remainingCapacity = CIO.StreamGetRemainingWriteCapacityBytes(Stream);

            if (remainingCapacity < data.Length)
            {
                throw new NotSupportedException("Not enough stream capacity to write data.");
            }

            var bytesWritten = 0L;

            fixed(byte *dataToWrite = data)
            {
                bytesWritten = CIO.StreamWrite(Stream, dataToWrite, 1);
            }

            if (bytesWritten != -1)
            {
                return(bytesWritten);
            }

            var rawError = CIO.StreamGetLastError(Stream);

            throw new IOException(ApiInterop.FromUtf8Cstr(rawError));
        }
Exemplo n.º 2
0
        public static unsafe Item ConvertItem(CEventTrace.Item *itemContainer)
        {
            var newItem = new Item();

            if (itemContainer->ItemType == 0)
            {
                // The item is newly initialized so return an empty Item
                return(newItem);
            }

            newItem.ItemType = (ItemType)itemContainer->ItemType;
            switch (newItem.ItemType)
            {
            case ItemType.Span:
                newItem.Span = new Span();

                var newSpan = newItem.Span.Value;
                ApiInterop.Memcpy(newSpan.Id.Data, itemContainer->ItemUnion.Span.Id.Data, SpanId.SpanIdSize);

                newSpan.Causes = new SpanId[(int)itemContainer->ItemUnion.Span.CauseCount];
                for (var i = 0; i < newSpan.Causes.Length; i++)
                {
                    fixed(byte *spanIdDest = newSpan.Causes[i].Data)
                    {
                        ApiInterop.Memcpy(spanIdDest, itemContainer->ItemUnion.Span.Causes[i].Data, SpanId.SpanIdSize);
                    }
                }

                newItem.Span = newSpan;
                break;

            case ItemType.Event:
                newItem.Event = new Event();

                var newEvent = newItem.Event.GetValueOrDefault();
                newEvent.Id = new SpanId();
                ApiInterop.Memcpy(newEvent.Id.Data, itemContainer->ItemUnion.Event.Id.Data, SpanId.SpanIdSize);

                newEvent.UnixTimestampMillis = itemContainer->ItemUnion.Event.UnixTimestampMillis;
                newEvent.Type    = ApiInterop.FromUtf8Cstr(itemContainer->ItemUnion.Event.Type);
                newEvent.Message = ApiInterop.FromUtf8Cstr(itemContainer->ItemUnion.Event.Message);

                newEvent.Data = new TraceEventData(itemContainer->ItemUnion.Event.Data);
                var fields = newEvent.Data.GetAll();
                // Release memory allocated to the underlying event data in the itemContainer
                newEvent.Data.EventData.Dispose();

                // Add the data to the newly initialized event data struct
                newEvent.Data = new TraceEventData(fields);

                newItem.Event = newEvent;
                break;

            default:
                throw new NotSupportedException("Invalid Item Type provided.");
            }

            return(newItem);
        }
Exemplo n.º 3
0
        public long Ignore(uint bytesToIgnore)
        {
            ThrowIfStreamClosed();

            var bytesIgnored = CIO.StreamIgnore(Stream, bytesToIgnore);

            if (bytesIgnored != -1)
            {
                return(bytesIgnored);
            }

            var rawError = CIO.StreamGetLastError(Stream);

            throw new IOException(ApiInterop.FromUtf8Cstr(rawError));
        }
Exemplo n.º 4
0
        public static Item DeserializeNextItemFromStream(IOStream stream)
        {
            unsafe
            {
                var itemContainer = GetThreadLocalItem();
                var itemSize      = CEventTrace.GetNextSerializedItemSize(stream.Stream);

                var deserializeStatus = CEventTrace.DeserializeItemFromStream(stream.Stream, itemContainer, itemSize);
                if (deserializeStatus != 1)
                {
                    var errorMessage = CEventTrace.GetLastError();
                    throw new IOException(ApiInterop.FromUtf8Cstr(errorMessage));
                }

                return(ParameterConversion.ConvertItem(itemContainer));
            }
        }
Exemplo n.º 5
0
        public void SerializeToStream(IOStream stream)
        {
            unsafe
            {
                var serializedItemResult = 0;
                ParameterConversion.ConvertItem(this, nativeItem =>
                {
                    var itemSize         = CEventTrace.GetSerializedItemSize(nativeItem);
                    serializedItemResult = CEventTrace.SerializeItemToStream(stream.Stream, nativeItem, itemSize);
                });

                if (serializedItemResult == 1)
                {
                    return;
                }

                var errorMessage = CEventTrace.GetLastError();
                throw new IOException(ApiInterop.FromUtf8Cstr(errorMessage));
            }
        }
Exemplo n.º 6
0
        public long Read(byte[] streamData)
        {
            ThrowIfStreamClosed();

            var bytesToRead = (uint)streamData.Length;
            var bytesRead   = 0L;

            fixed(byte *streamDataPointer = streamData)
            {
                bytesRead = CIO.StreamRead(Stream, streamDataPointer, bytesToRead);
            }

            if (bytesRead != -1)
            {
                return(bytesRead);
            }

            var rawError = CIO.StreamGetLastError(Stream);

            throw new IOException(ApiInterop.FromUtf8Cstr(rawError));
        }
Exemplo n.º 7
0
        public long Peek(uint bytesToPeek, out byte[] streamData)
        {
            ThrowIfStreamClosed();

            streamData = new byte[bytesToPeek];

            var bytesPeeked = 0L;

            fixed(byte *streamDataPointer = streamData)
            {
                bytesPeeked = CIO.StreamPeek(Stream, streamDataPointer, bytesToPeek);
            }

            if (bytesPeeked != -1)
            {
                return(bytesPeeked);
            }

            var rawError = CIO.StreamGetLastError(Stream);

            throw new IOException(ApiInterop.FromUtf8Cstr(rawError));
        }