Exemplo n.º 1
0
 public void GetRotation()
 {
     if (CheckForCube())
     {
         _writer.NextLine();
         _writer.Write("Current rotation is: ");
         _writer.WriteBold(cube.transform.rotation.eulerAngles.ToString());
     }
 }
Exemplo n.º 2
0
        public virtual void WriteString(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value.Length > 255)
            {
                throw new ArgumentException($"The string length is out of AMQP bounds.", nameof(value));
            }

            var buffer = Buffer.GetBuffer();

            int length;

            try
            {
                length = AmqpDefinitions.UTF8.GetBytes(value, 0, value.Length, buffer, 0);
            }
            catch (ArgumentException)
            {
                length = int.MaxValue;
            }

            if (length > 255)
            {
                throw new ArgumentException($"The data length of the string is out of AMQP bounds.", nameof(value));
            }

            BaseWriter.Write((byte)length);
            BaseWriter.Write(buffer, 0, length);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public void Write(ReadOnlySpan <char> content)
        {
            var sourceCount = BytesWritten;

            if (Options.MaxSize == 0)
            {
                BaseWriter.Write(content);
                return;
            }

            if (sourceCount >= Options.MaxSize - 1)
            {
                ReachedLimit = true;
                return;
            }

            //TODO this is a performance critical operation. As we might deal with variable-length encodings this cannot be compute initial
            var cl = Options.Encoding.GetByteCount(content);

            var overflow = sourceCount + cl - Options.MaxSize;

            if (overflow <= 0)
            {
                BytesWritten += cl;
                BaseWriter.Write(content);
                return;
            }

            if (overflow < content.Length)
            {
                BytesWritten += cl - overflow;
                //BaseWriter.Write(content.ToCharArray(0, (int)(cl - overflow)));
                BaseWriter.Write(content[0..((int)(cl - overflow))]);
Exemplo n.º 4
0
 public void WriteIndent()
 {
     for (int i = 0; i < IndentLevel; i++)
     {
         BaseWriter.Write(Tab);
     }
 }
Exemplo n.º 5
0
 public override void Write(string value)
 {
     if (real_time_reporting)
     {
         BaseWriter.Write(value);
     }
 }
Exemplo n.º 6
0
        public override void Close()
        {
            if (XmlOutputWriter != null)
            {
                // now we want the XML report to write
                real_time_reporting = true;
                // write to a temporary string, because NUnit2XmlOutputWriter.WriteResultFile closes the stream,
                // and we need to write more things to it.
                var wrapped = mode == XmlMode.Wrapped;

                if (!wrapped)
                {
                    XmlOutputWriter.WriteResultFile(Runner.Result, BaseWriter);
                    if (extra_data.Length > 0)
                    {
                        BaseWriter.Write("<!--");
                        extra_data.Replace("--", "- - ");
                        BaseWriter.Write(extra_data);
                        BaseWriter.Write(" -->");
                    }
                }
                else
                {
                    BaseWriter.WriteLine("<TouchUnitTestRun>");
                    BaseWriter.WriteLine("<NUnitOutput>");

                    using (var textWriter = new StringWriter()) {
                        XmlOutputWriter.WriteResultFile(Runner.Result, textWriter);
                        var str = textWriter.ToString();
                        // Remove any xml declarations, since we're embedding this inside a different xml document.
                        if (str.StartsWith("<?xml", StringComparison.Ordinal))
                        {
                            var closing = str.IndexOf('>');
                            if (closing > 0)
                            {
                                str = str.Substring(closing + 1);
                            }
                        }
                        BaseWriter.WriteLine(str);
                    }
                    BaseWriter.WriteLine("</NUnitOutput>");
                    if (extra_data.Length > 0)
                    {
                        BaseWriter.Write("<TouchUnitExtraData><![CDATA[");
                        BaseWriter.Write(extra_data);
                        BaseWriter.WriteLine("]]>");
                        BaseWriter.WriteLine("</TouchUnitExtraData>");
                    }
                    BaseWriter.WriteLine("</TouchUnitTestRun>");
                }
                BaseWriter.WriteLine("<!-- the end -->");
                BaseWriter.Close();
                real_time_reporting = false;
            }
            base.Close();
        }
Exemplo n.º 7
0
        public virtual void WriteFieldValue(IEnumerable <KeyValuePair <string, object> > value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            BaseWriter.Write((byte)'F');
            WriteTable(value);
        }
Exemplo n.º 8
0
        public virtual void WriteFieldValue(DateTime value)
        {
            if (value.ToUniversalTime() < AmqpDefinitions.UnixEpoch)
            {
                throw new ArgumentException($"The time value '{value}' is out of AMQP bounds.", nameof(value));
            }

            BaseWriter.Write((byte)'T');
            WriteTime(value);
        }
Exemplo n.º 9
0
        public virtual void WriteFieldValue(byte[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            BaseWriter.Write((byte)'S');
            WriteBytes(value);
        }
Exemplo n.º 10
0
        public virtual void WriteFieldValue(IEnumerable value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            BaseWriter.Write((byte)'A');
            WriteArray(value);
        }
Exemplo n.º 11
0
 public override void Write(string value)
 {
     if (real_time_reporting)
     {
         BaseWriter.Write(value);
     }
     else
     {
         extra_data.Append(value);
     }
 }
Exemplo n.º 12
0
        public virtual void WriteBytes(byte[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var length = checked ((uint)value.LongLength);

            SealedWriteUInt32(length);
            BaseWriter.Write(value);
        }
Exemplo n.º 13
0
        public void Write(string content)
        {
            if (ReadOnly)
            {
                return;
            }
            content = content ?? _options.Null?.ToString();

            var sourceCount = BytesWritten;

            if (_options.MaxSize == 0)
            {
                BaseWriter.Write(content);
                return;
            }

            if (sourceCount >= _options.MaxSize - 1)
            {
                ReachedLimit = true;
                return;
            }

            //TODO this is a performance critical operation. As we might deal with variable-length encodings this cannot be compute initial
            var cl = _options.Encoding.GetByteCount(content);

            var overflow = sourceCount + cl - _options.MaxSize;

            if (overflow <= 0)
            {
                BytesWritten += cl;
                BaseWriter.Write(content);
                return;
            }

            if (overflow < content.Length)
            {
                BytesWritten += cl - overflow;
                BaseWriter.Write(content.ToCharArray(0, (int)(cl - overflow)));
            }
            else
            {
                BytesWritten += cl;
                BaseWriter.Write(content);
            }
        }
Exemplo n.º 14
0
        public override void Write(SharedDataBuffer val)
        {
            if (val.File != null)
            {
                using var ms         = new MemoryStream();
                using var cr2wWriter = new CR2WWriter(ms);

                cr2wWriter.WriteFile((CR2WFile)val.File);

                ms.Seek(0, SeekOrigin.Begin);

                var buffer = ms.ToArray();
                BaseWriter.Write(buffer.Length);
                BaseWriter.Write(buffer);
            }
            else
            {
                base.Write(val);
            }
        }
Exemplo n.º 15
0
        private void FlushLine()
        {
            if (_lineBuffer.Length == 0)
            {
                return;
            }

            if (_indentationAllowed.Count == 0 || _indentationAllowed.Peek())
            {
                var indent = (_blockDepth + (_lineOverflow ? 1 : 0)) * IndentationWidth;
                for (var i = 0; i < indent; ++i)
                {
                    BaseWriter.Write(" ");
                }
            }

            BaseWriter.Write(_lineBuffer);
            BaseWriter.Write("\r\n");
            _lineBuffer.Remove(0, _lineBuffer.Length);
        }
Exemplo n.º 16
0
        public virtual void WriteDecimal(decimal value)
        {
            var parts = Decimal.GetBits(value);

            if (parts[0] < 0 || parts[1] != 0 || parts[2] != 0)
            {
                throw new ArgumentException($"The decimal value '{value}' is out of AMQP bounds.", nameof(value));
            }

            var  signal = parts[3] < 0;
            byte scale  = (byte)((parts[3] >> 16) & 0x7F);
            var  part   = parts[0];

            if (signal)
            {
                part = unchecked (part | -0x80000000);
            }

            BaseWriter.Write(scale);
            SealedWriteInt32(part);
        }
Exemplo n.º 17
0
        /// <inheritdoc />
        public void Write(string content)
        {
            if (_state == ByteCounterStreamPartType.Closed)
            {
                throw new InvalidOperationException("The current state of this partial is closed and cannot be written to anymore");
            }

            content = content ?? Options.Null?.ToString();
            _state  = ByteCounterStreamPartType.Writing;

            if (Options.MaxSize == 0)
            {
                BaseWriter.Write(content);
                return;
            }

            if (Info.ReachedLimit)
            {
                return;
            }

            //TODO this is a performance critical operation. As we might deal with variable-length encodings this cannot be compute initial
            var cl = Options.Encoding.GetByteCount(content);

            var overflow = Info.Increment(cl);

            if (overflow == cl)
            {
                BaseWriter.Write(content);
                return;
            }

            if (overflow == 0)
            {
                return;
            }

            BaseWriter.Write(content.ToCharArray(0, overflow));
        }
Exemplo n.º 18
0
 public void Write(byte[] val) => BaseWriter.Write(val);
Exemplo n.º 19
0
 public void Write(char val) => BaseWriter.Write(val);
Exemplo n.º 20
0
 public void Write(bool val) => BaseWriter.Write(val);
Exemplo n.º 21
0
 public void Write(double val) => BaseWriter.Write(val);
Exemplo n.º 22
0
 void SealedWriteSingle(float value)
 => BaseWriter.Write(AmqpDefinitions.FloatConverter.GetBytes(value));
Exemplo n.º 23
0
        public void WriteFile(CR2WFile file)
        {
            _file = file;

            BaseStream.WriteStruct(CR2WFile.MAGIC);

            var fileHeader = new CR2WFileHeader {
                version = _file.MetaData.Version, buildVersion = _file.MetaData.BuildVersion, numChunks = 6
            };
            var tableHeaders = new CR2WTable[10];

            var headerPos = BaseStream.Position;

            // Write empty header, fill it later
            BaseStream.WriteStruct(fileHeader);
            BaseStream.WriteStructs(tableHeaders);

            Debug.Assert(BaseStream.Position == 160);

            var dataCollection = GenerateData();

            foreach (var embedded in _file.EmbeddedFiles)
            {
                var tuple = ("", (CName)embedded.FileName, (ushort)8);
                if (!dataCollection.ImportList.Contains(tuple))
                {
                    dataCollection.ImportList.Add(tuple);
                }
            }

            fileHeader.objectsEnd = (uint)BaseStream.Position;

            var combinedList = new List <CName>(dataCollection.StringList);

            combinedList.AddRange(dataCollection.ImportList.Select(x => x.Item2).ToList());

            var(stringBuffer, stringOffsets) = GenerateStringBuffer(combinedList);

            tableHeaders[0] = new CR2WTable()
            {
                offset    = (uint)BaseStream.Position,
                itemCount = (uint)stringBuffer.Length,
                crc32     = Crc32Algorithm.Compute(stringBuffer)
            };

            BaseWriter.Write(stringBuffer);

            if (_file.Properties.Count < 1)
            {
                _file.Properties.Add(new CR2WProperty());
            }

            var afterHeaderPosition = CalculateHeaderLength(dataCollection);

            fileHeader.objectsEnd += (uint)afterHeaderPosition;

            #region Names

            tableHeaders[1].offset    = (uint)BaseStream.Position;
            tableHeaders[1].itemCount = (uint)dataCollection.StringList.Count;

            var crc = new Crc32Algorithm(false);
            foreach (var str in dataCollection.StringList)
            {
                if (_file.MetaData.HashVersion == EHashVersion.Pre120)
                {
#pragma warning disable CS0618 // Typ oder Element ist veraltet
                    BaseStream.WriteStruct(new CR2WNameInfo {
                        hash = str.GetOldRedHash(), offset = stringOffsets[str]
                    }, crc);
#pragma warning restore CS0618 // Typ oder Element ist veraltet
                }
                else
                {
                    BaseStream.WriteStruct(new CR2WNameInfo {
                        hash = str.GetShortRedHash(), offset = stringOffsets[str]
                    }, crc);
                }
            }
            tableHeaders[1].crc32 = crc.HashUInt32;

            #endregion Names

            #region Imports

            if (dataCollection.ImportList.Count > 0)
            {
                tableHeaders[2].offset    = (uint)BaseStream.Position;
                tableHeaders[2].itemCount = (uint)dataCollection.ImportList.Count;

                crc = new Crc32Algorithm(false);
                foreach (var import in dataCollection.ImportList)
                {
                    var entry = new CR2WImportInfo()
                    {
                        className = (ushort)dataCollection.StringList.IndexOf(import.Item1),
                        offset    = stringOffsets[import.Item2],
                        flags     = import.Item3
                    };

                    BaseStream.WriteStruct(entry, crc);
                }

                tableHeaders[2].crc32 = crc.HashUInt32;
            }

            #endregion Imports

            #region Properties

            tableHeaders[3].offset    = (uint)BaseStream.Position;
            tableHeaders[3].itemCount = (uint)_file.Properties.Count;

            crc = new Crc32Algorithm(false);
            foreach (var property in _file.Properties)
            {
                BaseStream.WriteStruct(new CR2WPropertyInfo(), crc);
            }

            tableHeaders[3].crc32 = crc.HashUInt32;

            #endregion

            #region Chunks

            if (dataCollection.ChunkInfoList.Count > 0)
            {
                tableHeaders[4].offset    = (uint)BaseStream.Position;
                tableHeaders[4].itemCount = (uint)dataCollection.ChunkInfoList.Count;

                crc = new Crc32Algorithm(false);
                foreach (var chunkInfo in dataCollection.ChunkInfoList)
                {
                    var entry = chunkInfo;
                    entry.dataOffset += (uint)afterHeaderPosition;

                    BaseStream.WriteStruct(entry, crc);
                }
                tableHeaders[4].crc32 = crc.HashUInt32;
            }

            #endregion Chunks

            #region Buffers

            var beforeBufferTablePos = BaseStream.Position;
            if (dataCollection.BufferInfoList.Count > 0)
            {
                tableHeaders[5].offset    = (uint)BaseStream.Position;
                tableHeaders[5].itemCount = (uint)dataCollection.BufferInfoList.Count;

                foreach (var buffer in dataCollection.BufferInfoList)
                {
                    BaseStream.WriteStruct(buffer, crc);
                }
            }

            #endregion Buffers

            #region Embedded

            var(embeddedInfoList, embeddedData) = GenerateEmbeddedData(dataCollection.ImportList);
            if (embeddedInfoList.Count > 0)
            {
                tableHeaders[6].offset    = (uint)BaseStream.Position;
                tableHeaders[6].itemCount = (uint)embeddedInfoList.Count;

                crc = new Crc32Algorithm(false);
                foreach (var embedded in embeddedInfoList)
                {
                    BaseStream.WriteStruct(embedded, crc);
                }

                tableHeaders[6].crc32 = crc.HashUInt32;
            }

            #endregion Embedded

            Debug.Assert(BaseStream.Position == afterHeaderPosition);

            BaseStream.Write(dataCollection.ChunkData);
            fileHeader.objectsEnd = (uint)BaseStream.Position;

            if (dataCollection.BufferInfoList.Count > 0)
            {
                BaseStream.Position = beforeBufferTablePos;
                crc = new Crc32Algorithm(false);
                for (var i = 0; i < dataCollection.BufferInfoList.Count; i++)
                {
                    var entry = dataCollection.BufferInfoList[i];
                    entry.offset += fileHeader.objectsEnd;
                    dataCollection.BufferInfoList[i] = entry;

                    BaseStream.WriteStruct(entry, crc);
                }
                tableHeaders[5].crc32 = crc.HashUInt32;
            }

            BaseStream.Position = fileHeader.objectsEnd;
            BaseStream.Write(dataCollection.BufferData);
            fileHeader.buffersEnd = (uint)BaseStream.Position;

            fileHeader.crc32    = CalculateHeaderCRC32(fileHeader, tableHeaders);
            BaseStream.Position = headerPos;
            BaseStream.WriteStruct(fileHeader);
            BaseStream.WriteStructs(tableHeaders);

            //for (int i = 0; i < dataCollection.ChunkInfoList.Count; i++)
            //{
            //    var newInfo = dataCollection.ChunkInfoList[i];
            //    var oldInfo = _file.Info.ExportInfo[i];
            //
            //    if ((newInfo.dataOffset + afterHeaderPosition) != oldInfo.dataOffset)
            //    {
            //
            //    }
            //
            //    if (newInfo.dataSize != oldInfo.dataSize)
            //    {
            //
            //    }
            //
            //    if (newInfo.parentID != oldInfo.parentID)
            //    {
            //        throw new TodoException("Invalid parent id");
            //    }
            //
            //    if (newInfo.className != oldInfo.className)
            //    {
            //
            //    }
            //
            //    if (newInfo.objectFlags != oldInfo.objectFlags)
            //    {
            //
            //    }
            //
            //    if (newInfo.template != oldInfo.template)
            //    {
            //
            //    }
            //}
            //
            //for (int i = 0; i < dataCollection.BufferInfoList.Count; i++)
            //{
            //    var newInfo = dataCollection.BufferInfoList[i];
            //    var oldInfo = _file.Info.BufferInfo[i];
            //
            //    if (newInfo.index != oldInfo.index)
            //    {
            //
            //    }
            //
            //    if (newInfo.crc32 != oldInfo.crc32)
            //    {
            //
            //    }
            //
            //    if (newInfo.diskSize != oldInfo.diskSize)
            //    {
            //
            //    }
            //
            //    if (newInfo.flags != oldInfo.flags)
            //    {
            //
            //    }
            //
            //    if (newInfo.memSize != oldInfo.memSize)
            //    {
            //
            //    }
            //
            //    if (newInfo.offset != oldInfo.offset)
            //    {
            //
            //    }
            //}
        }
Exemplo n.º 24
0
 public void Write(int val) => BaseWriter.Write(val);
Exemplo n.º 25
0
 protected void SealedWriteUInt32(uint value)
 => BaseWriter.Write(AmqpDefinitions.IntegerConverter.GetBytes(value));
Exemplo n.º 26
0
 public void Write(string value)
 {
     BaseWriter.Write(value);
 }
Exemplo n.º 27
0
 public void Write(char[] value, long sizeOfContent)
 {
     BytesWritten += sizeOfContent;
     BaseWriter.Write(value);
 }
Exemplo n.º 28
0
 public void Write(short val) => BaseWriter.Write(val);
Exemplo n.º 29
0
 public void Write(float val) => BaseWriter.Write(val);
Exemplo n.º 30
0
 protected void SealedWriteInt64(long value)
 => BaseWriter.Write(AmqpDefinitions.IntegerConverter.GetBytes(value));