Ejemplo n.º 1
0
        private IEnumerable <Polygon> readIndices(GltfAccessor accessor, GltfMeshPrimitive.ModeEnum mode)
        {
            if (!accessor.BufferView.HasValue)
            {
                return(new List <Polygon>());
            }

            StreamIO stream = getBufferStream(accessor);

            switch (mode)
            {
            case GltfMeshPrimitive.ModeEnum.TRIANGLES:
                return(readAccessor <Triangle>(stream, accessor.ComponentType, accessor.Count / 3, 3));

            case GltfMeshPrimitive.ModeEnum.POINTS:
            case GltfMeshPrimitive.ModeEnum.LINES:                      //Works with the 3d lines, like polylines and lines
            case GltfMeshPrimitive.ModeEnum.LINE_LOOP:
            case GltfMeshPrimitive.ModeEnum.LINE_STRIP:
            case GltfMeshPrimitive.ModeEnum.TRIANGLE_STRIP:
            case GltfMeshPrimitive.ModeEnum.TRIANGLE_FAN:
                return(new List <Polygon>());

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
 public void CopyStream_WithWriteOnlyStreamAsSource_Throws()
 {
     using (var sourceStream = File.OpenWrite("DummyFileOne.txt"))
         using (var targetStream = File.OpenWrite("DummyFileTwo.txt"))
         {
             StreamIO.CopyStream(sourceStream, targetStream);
         }
 }
Ejemplo n.º 3
0
 public void CopyStream_WithReadOnlyStreamAsTarget_Throws()
 {
     using (var sourceStream = File.OpenRead("DummyFileOne.txt"))
         using (var targetStream = File.OpenRead("DummyFileTwo.txt"))
         {
             StreamIO.CopyStream(sourceStream, targetStream);
         }
 }
Ejemplo n.º 4
0
        public void MD5Stream_WithAWriteOnlyStream_Throws()
        {
            string result = "";

            using (var fileInput = File.OpenWrite("DummyFileOne.txt"))
            {
                result = StreamIO.MD5Stream(fileInput);
            }
        }
Ejemplo n.º 5
0
        public GltfReader(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            _stream = new StreamIO(new FileStream(path, FileMode.Open));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StlWriter"/> class for the specified file.
        /// </summary>
        /// <param name="path">The complete file path to write to.</param>
        public StlWriter(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            this._stream = new StreamIO(File.Create(path));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Read method through StreamReader
        /// </summary>
        /// <param name="filePath"></param>
        public void StreamRead(string filePath)
        {
            List <IFigure> figures = StreamIO.StreamRead(filePath);

            if (figures.Count > 20)
            {
                throw new NoPlaceException();
            }
            this.figures = figures;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Check if the file format is in binary.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static bool IsBinary(Stream stream)
        {
            string sentinel = "AutoCAD Binary DXF";

            StreamIO sio = new StreamIO(stream);

            sio.Position = 0;
            string sn = sio.ReadString(sentinel.Length);

            return(sn == sentinel);
        }
Ejemplo n.º 9
0
        public void MD5Stream_WithAValidStream_CreatesAnMD5Checksum()
        {
            string result = "";

            using (var fileInput = File.OpenRead("DummyFileOne.txt"))
            {
                result = StreamIO.MD5Stream(fileInput);
            }

            Assert.AreEqual("BFAF8AE957937AF5B8652A2137F1D95A", result, "Failed to create an MD5 checksum for a file stream");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StlReader"/> class for the specified file.
        /// </summary>
        /// <param name="path">The complete file path to read to.</param>
        /// <param name="onNotification"></param>
        public StlReader(string path, NotificationHandler onNotification = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            this._stream = new StreamIO(path, FileMode.Open, FileAccess.Read);

            this.OnNotification = onNotification;
        }
Ejemplo n.º 11
0
        private StreamIO getBufferStream(GltfAccessor accessor)
        {
            GltfBufferView bufferView = _root.BufferViews[accessor.BufferView.Value];
            GltfBuffer     buffer     = _root.Buffers[bufferView.Buffer];

            StreamIO stream = new StreamIO(_chunk.GetBytes(0, buffer.ByteLength));

            stream.Position = bufferView.ByteOffset + accessor.ByteOffset;

            return(stream);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Write method through StreamWriter
        /// </summary>
        /// <param name="filePath"></param>
        public void StreamWritePaper(string filePath)
        {
            List <IFigure> paperFigures = new List <IFigure>();

            foreach (IFigure figure in figures)
            {
                if (figure is Paper)
                {
                    paperFigures.Add(figure);
                }
            }
            StreamIO.StreamWriteAll(filePath, paperFigures);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StlWriter"/> class for the specified stream.
        /// </summary>
        /// <param name="stream">The stream to write to.</param>
        public StlWriter(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must support seeking. Try reading the data into a buffer first");
            }

            this._stream = new StreamIO(stream);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Write the data in the loaded rows to disk.
        /// </summary>
        public void Write()
        {
            if (sHelper == null) // If data was loaded from SQL
            {
                sHelper = new StreamIO(encoding);
            }
            else
            {
                sHelper.Clear();
            }

            writeHeader();
            writeContents();
        }
Ejemplo n.º 15
0
        public void CopyStream_WithTwoValidStreams_CopiesOneStreamsDataToAnother()
        {
            string result = "";

            using (var targetStream = new MemoryStream())
                using (var fileInput = File.OpenRead("DummyFileOne.txt"))
                {
                    StreamIO.CopyStream(fileInput, targetStream);

                    targetStream.Seek(0, SeekOrigin.Begin);
                    result = new StreamReader(targetStream).ReadLine();
                }

            Assert.AreEqual("0123456789", result, "Failed to copy from stream to stream");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FbxReader"/> class for the specified stream.
        /// </summary>
        /// <param name="stream">The stream to write to.</param>
        /// <param name="errorLevel"></param>
        public StlReader(Stream stream, NotificationHandler onNotification = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must support seeking. Try reading the data into a buffer first");
            }

            this._stream = new StreamIO(stream);

            this.OnNotification = onNotification;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Send recover password email
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public void SendRecoverLink(string email, string name, string title, Guid activeCode)
        {
            string emailTemplateUrl = _hostEnvironment.GetRootContentUrl()
                                      + "/resources/templates/password_recover.html";

            string emailContent = StreamIO.ReadFile(emailTemplateUrl);

            emailContent = emailContent.Replace("{UserName}", name);
            emailContent = emailContent.Replace("{Url}", "http://localhost:52767/change-password.html?code=" + activeCode).ToString();

            _mesageCenter.Push(new EmailMessage
            {
                Content = emailContent,
                Title   = title,
                To      = email
            });
        }
Ejemplo n.º 18
0
        protected List <T> readAccessor <T>(StreamIO stream, GltfAccessor.ComponentTypeEnum componentType, int count, int nargs)
        {
            List <T> vecs = new List <T>();

            for (int i = 0; i < count; i++)
            {
                List <object> args = new List <object>();

                for (int j = 0; j < nargs; j++)
                {
                    switch (componentType)
                    {
                    case GltfAccessor.ComponentTypeEnum.BYTE:
                    case GltfAccessor.ComponentTypeEnum.UNSIGNED_BYTE:
                        args.Add(stream.ReadByte());
                        break;

                    case GltfAccessor.ComponentTypeEnum.SHORT:
                        args.Add(stream.ReadShort());
                        break;

                    case GltfAccessor.ComponentTypeEnum.UNSIGNED_SHORT:
                        args.Add(stream.ReadUShort());
                        break;

                    case GltfAccessor.ComponentTypeEnum.UNSIGNED_INT:
                        args.Add(stream.ReadUInt());
                        break;

                    case GltfAccessor.ComponentTypeEnum.FLOAT:
                        args.Add(stream.ReadSingle());
                        break;

                    default:
                        throw new Exception();
                    }
                }

                vecs.Add((T)Activator.CreateInstance(typeof(T), args.ToArray()));
            }

            return(vecs);
        }
Ejemplo n.º 19
0
        public Scene Read()
        {
            //The 12-byte header consists of three 4-byte entries:
            _header = new GlbHeader();
            //magic equals 0x46546C67. It is ASCII string glTF, and can be used to identify data as Binary glTF.
            _header.Magic = _stream.ReadUInt <LittleEndianConverter>();
            //version indicates the version of the Binary glTF container format. This specification defines version 2.
            _header.Version = _stream.ReadUInt <LittleEndianConverter>();
            //length is the total length of the Binary glTF, including Header and all Chunks, in bytes.
            _header.Length = _stream.ReadUInt <LittleEndianConverter>();

            if (_header.Version != 2)
            {
                throw new NotImplementedException($"Version {_header.Version} not implemented");
            }

            //Chunk 0 Json
            uint   jsonChunkLength = _stream.ReadUInt <LittleEndianConverter>();
            string jsonChunkType   = _stream.ReadString(4);

            if (jsonChunkType != "JSON")
            {
                throw new GltfReaderException("Chunk type does not match", _stream.Position);
            }

            _root = JsonConvert.DeserializeObject <GltfRoot>(_stream.ReadString((int)jsonChunkLength));

            //Chunk 1 bin
            uint   binChunkLength = _stream.ReadUInt <LittleEndianConverter>();
            string binChunkType   = _stream.ReadString(4);

            //Check the chunk type
            if (binChunkType != "BIN\0")
            {
                throw new GltfReaderException("Chunk type does not match", _stream.Position);
            }

            byte[] binChunk = _stream.ReadBytes((int)binChunkLength);
            _binaryStream = new StreamIO(binChunk);

            return(GltfBinaryReaderBase.GetBynaryReader((int)_header.Version, _root, binChunk).Read());
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Send an email to invite an user joins project
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="memberId"></param>
        /// <returns></returns>
        public async Task SendInvitation(int projectId, int memberId, bool isNewMember,
                                         string title, string activeCode)
        {
            string emailTemplateUrl = _hostEnvironment.GetRootContentUrl()
                                      + "/resources/templates/invite_email.html";

            AccountInfoModel member = await _accountBusiness.GetAccountInfo(memberId);

            ProjectModel project = await GetProject(projectId);

            string password = string.Empty;

            if (isNewMember)
            {
                emailTemplateUrl = _hostEnvironment.GetRootContentUrl()
                                   + "/resources/templates/invite_new_email.html";

                string hash = Cryptography.GetHashString(member.AccountName);
                password = Decrypt.Do(member.Password, hash);
            }

            string emailContent = StreamIO.ReadFile(emailTemplateUrl);

            emailContent = emailContent.Replace("{UserName}", member.DisplayName);
            emailContent = emailContent.Replace("{Project}", project.ProjectName.ToUpper());
            emailContent = emailContent.Replace("{Url}", "http://eztask.dotnetvn.com/project/accept-invite.html?ref=" + activeCode);
            emailContent = emailContent.Replace("{Account}", member.AccountName);
            emailContent = emailContent.Replace("{Password}", password);

            _mesageCenter.Push(new EmailMessage
            {
                Content = emailContent,
                Title   = title + " " + project.ProjectName.ToUpper(),
                To      = member.AccountName
            });
        }
Ejemplo n.º 21
0
        protected Dictionary <int, StreamIO> _buffers;          //TODO: implement gltf reader for multiple buffers

        public GltfBinaryReaderBase(GltfRoot root, byte[] chunk)
        {
            this._root  = root;
            this._chunk = new StreamIO(chunk);
        }
Ejemplo n.º 22
0
 public void ReadFileToMemory_WithAnEmptyFilePath_Throws()
 {
     StreamIO.ReadFileToMemory("");
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Process the data stored in a RDB buffer.
 /// </summary>
 /// <param name="buffer">Buffer to be processed</param>
 public void ParseBuffer(byte[] buffer)
 {
     sHelper = new StreamIO(buffer);
     parseHeader();
     parseContents();
 }
Ejemplo n.º 24
0
        public void ReadFileToMemory_WithAMissingFile_ReturnsNull()
        {
            var result = StreamIO.ReadFileToMemory("MissingFile.txt");

            Assert.IsNull(result, "Did not return null when attempting to read a non-existant file");
        }
Ejemplo n.º 25
0
 public void MD5Stream_WithANullStream_Throws()
 {
     StreamIO.MD5Stream(null);
 }
Ejemplo n.º 26
0
 public void ReadFileToMemory_WithANullFilePath_Throws()
 {
     StreamIO.ReadFileToMemory(null);
 }
Ejemplo n.º 27
0
        public void ReadFileToMemory_WithAnExistingFileAndAnIncorrectChecksum_ReturnsNull()
        {
            var result = StreamIO.ReadFileToMemory("DummyFileOne.txt", "INCORRECTCHECKSUM");

            Assert.IsNull(result, "Read a file into memory when the checksum did not match");
        }
Ejemplo n.º 28
0
 public void CopyStream_WithNullStreams_Throws()
 {
     StreamIO.CopyStream(null, null);
 }
Ejemplo n.º 29
0
        public void ReadFileToMemory_WithAnExistingFileAndValidChecksum_ReturnsADataStream()
        {
            var result = StreamIO.ReadFileToMemory("DummyFileOne.txt", "BFAF8AE957937AF5B8652A2137F1D95A");

            Assert.IsNotNull(result, "Failed to read a valid file to memory");
        }
Ejemplo n.º 30
0
 public void ReadFileToMemory_WithAnExistingFileAndAnEmptyChecksum_Throws()
 {
     StreamIO.ReadFileToMemory("DummyFileOne.txt", "");
 }