Exemplo n.º 1
0
        public Task <bool> WriteDrawing(string fileName, Stream fileStream, Drawing drawing, ViewPort viewPort, object fileSettings)
        {
            var file    = new IgesFile();
            var oldFile = drawing.Tag as IgesFile;

            if (oldFile != null)
            {
                // preserve settings from original file
                file.TimeStamp = oldFile.TimeStamp;
            }

            file.Author           = drawing.Author;
            file.FullFileName     = fileName;
            file.Identification   = Path.GetFileName(fileName);
            file.Identifier       = Path.GetFileName(fileName);
            file.ModelUnits       = drawing.Settings.UnitFormat.ToIgesUnits();
            file.ModifiedTime     = DateTime.Now;
            file.SystemIdentifier = "BCad";
            file.SystemVersion    = "1.0";
            foreach (var entity in drawing.GetEntities())
            {
                var igesEntity = entity.ToIgesEntity();
                if (igesEntity != null)
                {
                    file.Entities.Add(igesEntity);
                }
            }

            file.Save(fileStream);
            return(Task.FromResult(true));
        }
Exemplo n.º 2
0
        private static void VerifyFileText(IgesFile file, string expected, Action <string, string> verifier)
        {
            var stream = new MemoryStream();

            file.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var bytes  = stream.ToArray();
            var actual = Encoding.ASCII.GetString(bytes);

            verifier(expected.Trim('\r', '\n').Replace("\r", ""), actual.Trim('\r', '\n'));
        }
Exemplo n.º 3
0
        public void ReadWithDifferningNewlinesTest()
        {
            var file = new IgesFile();

            file.Entities.Add(new IgesLine(new IgesPoint(0.0, 0.0, 0.0), new IgesPoint(1.0, 1.0, 1.0)));

            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(ms))
                {
                    var text = reader.ReadToEnd();

                    // verify file reading with LF
                    text = text.Replace("\r", "");
                    var lengthLF = 0L;
                    using (var ms2 = new MemoryStream())
                    {
                        using (var writer = new StreamWriter(ms2, Encoding.ASCII, bufferSize: 1024, leaveOpen: true))
                        {
                            writer.Write(text);
                        }

                        ms2.Seek(0, SeekOrigin.Begin);
                        lengthLF = ms2.Length;
                        var fileLF = IgesFile.Load(ms2);
                        Assert.Single(fileLF.Entities);
                    }

                    // verify file reading with CRLF
                    text = text.Replace("\n", "\r\n");
                    var lengthCRLF = 0L;
                    using (var ms2 = new MemoryStream())
                    {
                        using (var writer = new StreamWriter(ms2, Encoding.ASCII, bufferSize: 1024, leaveOpen: true))
                        {
                            writer.Write(text);
                        }

                        ms2.Seek(0, SeekOrigin.Begin);
                        lengthCRLF = ms2.Length;
                        var fileLF = IgesFile.Load(ms2);
                        Assert.Single(fileLF.Entities);
                    }

                    // verify that the file lengths were non-zero and not equal
                    Assert.NotEqual(0L, lengthLF);
                    Assert.NotEqual(0L, lengthCRLF);
                    Assert.NotEqual(lengthLF, lengthCRLF);
                }
            }
        }
Exemplo n.º 4
0
        public void WriteOnlyNewlinesTest()
        {
            var file = new IgesFile();

            file.Entities.Add(new IgesLine(new IgesPoint(0.0, 0.0, 0.0), new IgesPoint(1.0, 1.0, 1.0)));
            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(ms))
                {
                    var text = reader.ReadToEnd();
                    Assert.DoesNotContain("\r", text);
                }
            }
        }
Exemplo n.º 5
0
        public void RoundTripFileWithNonStandardDelimitersTest()
        {
            var file = new IgesFile()
            {
                FieldDelimiter  = ';', // inverted field and record delimiters
                RecordDelimiter = ',',
            };

            file.Entities.Add(new IgesLine(new IgesPoint(1.0, 2.0, 3.0), new IgesPoint(4.0, 5.0, 6.0)));

            // write then re-read the file
            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                var file2 = IgesFile.Load(ms);
                Assert.Equal(';', file.FieldDelimiter);
                Assert.Equal(',', file.RecordDelimiter);
                var line = (IgesLine)file.Entities.Single();
                Assert.Equal(new IgesPoint(1.0, 2.0, 3.0), line.P1);
                Assert.Equal(new IgesPoint(4.0, 5.0, 6.0), line.P2);
            }
        }