Example #1
0
            public void WriteToVersionXml()
            {
                var xmlInput = @"<?xml version=""1.0"" encoding=""utf-8""?>
<Markup xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <Topic Guid=""5019D939-62A4-45D9-B205-FAB602C98FE8"">
    <Title>Referenced topic</Title>
    <CreationDate>2016-11-22T13:20:03.0814453Z</CreationDate>
    <Description>This is just an empty topic that acts as a referenced topic.</Description>
  </Topic>
</Markup>";

                var inputSplitInLines = Regex.Split(xmlInput, "\r\n?|\n");
                var expected          = inputSplitInLines[0] + Environment.NewLine
                                        + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                                        + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);

                var actual = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(xmlInput);

                if (actual != expected)
                {
                    // Generating it again due to a possible difference in the timestamp (minute / hour might have changed)
                    expected = inputSplitInLines[0] + Environment.NewLine
                               + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                               + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);
                }
                Assert.Equal(expected, actual);
            }
Example #2
0
            public void HasCorrectText()
            {
                var commentText = BrandingCommentFactory.GetBrandingComment();

                Assert.StartsWith("Created with the iabi.BCF library, V", commentText);
                Assert.EndsWith($". Visit {BrandingCommentFactory.IABI_BRANDING_URL} to find out more.", commentText);
            }
Example #3
0
            public void WriteToProjectXml()
            {
                var xmlInput = @"<?xml version=""1.0"" encoding=""utf-8""?>
<ProjectExtension xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <Project ProjectId=""F338B6F0-A93E-40FF-A4D6-6117CD21EC2A"">
    <Name>BCF API Implementation</Name>
  </Project>
  <ExtensionSchema>extensions.xsd</ExtensionSchema>
</ProjectExtension>";

                var inputSplitInLines = Regex.Split(xmlInput, "\r\n?|\n");
                var expected          = inputSplitInLines[0] + Environment.NewLine
                                        + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                                        + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);

                var actual = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(xmlInput);

                if (actual != expected)
                {
                    // Generating it again due to a possible difference in the timestamp (minute / hour might have changed)
                    expected = inputSplitInLines[0] + Environment.NewLine
                               + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                               + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);
                }
                Assert.Equal(expected, actual);
            }
Example #4
0
            public void HasCorrectVersion()
            {
                var commentText           = BrandingCommentFactory.GetBrandingComment();
                var expectedVersionString = FileVersionProvider.NuGetVersion;

                Assert.Contains(expectedVersionString, commentText);
            }
Example #5
0
            public void WriteToViewpointXml()
            {
                var xmlInput = @"<?xml version=""1.0"" encoding=""utf-8""?>
<VisualizationInfo xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" Guid=""81daa431-bf01-4a49-80a2-1ab07c177717"">
  <Components DefaultVisibilitySpaces=""false"" DefaultVisibilitySpaceBoundaries=""false"">
    <Component IfcGuid=""0fdpeZZEX3FwJ7x0ox5kzF"" Visible=""false"" />
    <Component IfcGuid=""23Zwlpd71EyvHlH6OZ77nK"" Visible=""false"" />
    <Component IfcGuid=""1OpjQ1Nlv4sQuTxfUC_8zS"" Visible=""false"" />
    <Component IfcGuid=""0cSRUx$EX1NRjqiKcYQ$a0"" Visible=""false"" />
  </Components>
  <PerspectiveCamera>
    <CameraViewPoint>
      <X>-30.0807178226062</X>
      <Y>17.1180195726065</Y>
      <Z>11.4769701040657</Z>
    </CameraViewPoint>
    <CameraDirection>
      <X>0.520915589917324</X>
      <Y>-0.661777065303802</Y>
      <Z>-0.539164240672219</Z>
    </CameraDirection>
    <CameraUpVector>
      <X>-1.13083372396512E-08</X>
      <Y>-8.90132135110878E-09</Y>
      <Z>1</Z>
    </CameraUpVector>
    <FieldOfView>60</FieldOfView>
  </PerspectiveCamera>
</VisualizationInfo>";

                var inputSplitInLines = Regex.Split(xmlInput, "\r\n?|\n");
                var expected          = inputSplitInLines[0] + Environment.NewLine
                                        + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                                        + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);

                var actual = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(xmlInput);

                if (actual != expected)
                {
                    // Generating it again due to a possible difference in the timestamp (minute / hour might have changed)
                    expected = inputSplitInLines[0] + Environment.NewLine
                               + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                               + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);
                }
                Assert.Equal(expected, actual);
            }
Example #6
0
            public void HasCorrectTimestamp()
            {
                var commentText     = BrandingCommentFactory.GetBrandingComment();
                var currentDateTime = DateTime.UtcNow;
                var regexDateTime   = @"\d\d\.\d\d\.\d\d\d\d \d\d:\d\d";
                var regexMatch      = Regex.Match(commentText, regexDateTime);

                Assert.True(regexMatch.Success, $"Failed to find a timestamp in: \"{commentText}\"");
                var extractedDateTime = regexMatch.Value;
                var day            = int.Parse(extractedDateTime.Substring(0, 2));
                var month          = int.Parse(extractedDateTime.Substring(3, 2));
                var year           = int.Parse(extractedDateTime.Substring(6, 4));
                var hour           = int.Parse(extractedDateTime.Substring(11, 2));
                var minute         = int.Parse(extractedDateTime.Substring(14, 2));
                var parsedDateTime = new DateTime(year, month, day, hour, minute, 0, DateTimeKind.Utc);
                var timeDifference = Math.Abs((currentDateTime - parsedDateTime).TotalSeconds);

                Assert.True(timeDifference < 600, $"Time difference is {timeDifference} seconds, current time: {currentDateTime:dd.MM.yyyy HH:mm}, actual: {parsedDateTime:dd.MM.yyyy HH:mm}");  // should be within ten minutes of eachother, accounts for slow CI server environments
                // and the fact that the actual date is only given with minutes and has no seconds part
            }
Example #7
0
            public void WriteToSimpleXml()
            {
                var xmlInput = @"<?xml version=""1.0"" encoding=""utf-8""?>
<SomeElement>
  Hello
</SomeElement>";

                var inputSplitInLines = Regex.Split(xmlInput, "\r\n?|\n");
                var expected          = inputSplitInLines[0] + Environment.NewLine
                                        + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                                        + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);

                var actual = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(xmlInput);

                if (actual != expected)
                {
                    // Generating it again due to a possible difference in the timestamp (minute / hour might have changed)
                    expected = inputSplitInLines[0] + Environment.NewLine
                               + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                               + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);
                }
                Assert.Equal(expected, actual);
            }
Example #8
0
            public void HasCorrectUrl()
            {
                var commentText = BrandingCommentFactory.GetBrandingComment();

                Assert.Contains(BrandingCommentFactory.IABI_BRANDING_URL, commentText);
            }
Example #9
0
            public void WriteToExtensionsSchemaXsd()
            {
                var xmlInput = @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
  <xs:redefine schemaLocation=""markup.xsd"">
    <xs:simpleType name=""TopicType"">
      <xs:restriction>
        <xs:enumeration value=""Architecture"" />
        <xs:enumeration value=""Hidden Type"" />
        <xs:enumeration value=""Structural"" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=""TopicStatus"">
      <xs:restriction>
        <xs:enumeration value=""Finished status"" />
        <xs:enumeration value=""Open"" />
        <xs:enumeration value=""Closed"" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=""TopicLabel"">
      <xs:restriction>
        <xs:enumeration value=""Architecture"" />
        <xs:enumeration value=""IT Development"" />
        <xs:enumeration value=""Management"" />
        <xs:enumeration value=""Mechanical"" />
        <xs:enumeration value=""Structural"" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=""SnippetType"">
      <xs:restriction>
        <xs:enumeration value=""IFC2X3"" />
        <xs:enumeration value=""PDF"" />
        <xs:enumeration value=""XLSX"" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=""Priority"">
      <xs:restriction>
        <xs:enumeration value=""Low"" />
        <xs:enumeration value=""High"" />
        <xs:enumeration value=""Medium"" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=""UserIdType"">
      <xs:restriction>
        <xs:enumeration value=""*****@*****.**"" />
        <xs:enumeration value=""*****@*****.**"" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name=""Stage"">
      <xs:restriction>
        <xs:enumeration value=""*****@*****.**"" />
        <xs:enumeration value=""*****@*****.**"" />
      </xs:restriction>
    </xs:simpleType>
  </xs:redefine>
</xs:schema>";

                var inputSplitInLines = Regex.Split(xmlInput, "\r\n?|\n");
                var expected          = inputSplitInLines[0] + Environment.NewLine
                                        + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                                        + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);

                var actual = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(xmlInput);

                if (actual != expected)
                {
                    // Generating it again due to a possible difference in the timestamp (minute / hour might have changed)
                    expected = inputSplitInLines[0] + Environment.NewLine
                               + $"<!--{BrandingCommentFactory.GetBrandingComment()}-->" + Environment.NewLine
                               + inputSplitInLines.Skip(1).Aggregate((current, next) => current + Environment.NewLine + next);
                }
                Assert.Equal(expected, actual);
            }
Example #10
0
        /// <summary>
        ///     Creates a BCFv2 zip archive
        /// </summary>
        /// <param name="streamToWrite"></param>
        public void WriteStream(Stream streamToWrite)
        {
            using (var bcfZip = new ZipArchive(streamToWrite, ZipArchiveMode.Create, true))
            {
                // Write the version information
                var versionInformation = bcfZip.CreateEntry("bcf.version");
                using (var versionWriter = new StreamWriter(versionInformation.Open()))
                {
                    var serializedVersionInfo = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(BcfVersionInfo.Serialize());
                    versionWriter.Write(serializedVersionInfo);
                }

                if (ProjectExtensions != null && !ProjectExtensions.IsEmpty())
                {
                    var projectInformation = bcfZip.CreateEntry("extensions.xsd");
                    using (var projectInfoWriter = new StreamWriter(projectInformation.Open()))
                    {
                        var serializedExtensions = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(ProjectExtensions.WriteExtension());
                        projectInfoWriter.Write(serializedExtensions);
                    }
                    if (BcfProject == null)
                    {
                        BcfProject = new ProjectExtension();
                    }
                    BcfProject.ExtensionSchema = "extensions.xsd";
                }
                // Write the project info if it is present
                if (BcfProject != null)
                {
                    var projectEntry = bcfZip.CreateEntry("project.bcfp");
                    using (var projectInfoWriter = new StreamWriter(projectEntry.Open()))
                    {
                        var serializedProjectInfo = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(BcfProject.Serialize());
                        projectInfoWriter.Write(serializedProjectInfo);
                    }
                }
                // Write file attachments
                if (FileAttachments.Any())
                {
                    foreach (var attachment in FileAttachments)
                    {
                        var attachmentEntry = bcfZip.CreateEntry(attachment.Key);
                        using (var attachmentWriter = new BinaryWriter(attachmentEntry.Open()))
                        {
                            attachmentWriter.Write(attachment.Value);
                        }
                    }
                }
                // Write an entry for each topic
                foreach (var topic in Topics)
                {
                    if (!topic.Markup.Topic.CreationDateSpecified)
                    {
                        topic.Markup.Topic.CreationDate = DateTime.UtcNow;
                    }
                    if (string.IsNullOrWhiteSpace(topic.Markup.Topic.Guid))
                    {
                        topic.Markup.Topic.Guid = Guid.NewGuid().ToString();
                    }
                    if (topic.Markup.Topic.ShouldSerializeBimSnippet())
                    {
                        // Write BIM Snippet if present in the file and internal
                        if (!topic.Markup.Topic.BimSnippet.isExternal)
                        {
                            topic.Markup.Topic.BimSnippet.isExternal = false;
                            var bimSnippetBinaryEntry = bcfZip.CreateEntry(topic.Markup.Topic.Guid + "/" + topic.Markup.Topic.BimSnippet.Reference);
                            using (var snippetWriter = new BinaryWriter(bimSnippetBinaryEntry.Open()))
                            {
                                if (topic.SnippetData != null)
                                {
                                    snippetWriter.Write(topic.SnippetData);
                                }
                            }
                        }
                    }
                    var topicEntry = bcfZip.CreateEntry(topic.Markup.Topic.Guid + "/" + "markup.bcf");
                    for (var i = 0; i < topic.Viewpoints.Count; i++)
                    {
                        if (topic.ViewpointSnapshots.ContainsKey(topic.Viewpoints[i].GUID))
                        {
                            topic.Markup.Viewpoints[i].Snapshot = "Snapshot_" + topic.Viewpoints[i].GUID + ".png";
                        }
                    }
                    using (var topicWriter = new StreamWriter(topicEntry.Open()))
                    {
                        var serializedTopic = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(topic.Markup.Serialize());
                        topicWriter.Write(serializedTopic);
                    }
                    // Write viewpoints if present
                    for (var i = 0; i < topic.Viewpoints.Count; i++)
                    {
                        var entryName = topic.Markup.Topic.Guid + "/" + topic.Markup.Viewpoints[i].Viewpoint;
                        var viewpoint = bcfZip.CreateEntry(entryName);

                        using (var viewpointWriter = new StreamWriter(viewpoint.Open()))
                        {
                            if (topic.Viewpoints[i].Bitmaps.Count > 0)
                            {
                                foreach (var bitmap in topic.Viewpoints[i].Bitmaps)
                                {
                                    bitmap.Reference = "Bitmap_" + Guid.NewGuid() + "." + (bitmap.Bitmap == BitmapFormat.JPG ? "jpg" : "png");
                                }
                            }
                            var serializedViewpoint = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(topic.Viewpoints[i].Serialize());
                            viewpointWriter.Write(serializedViewpoint);
                        }
                        // Write snapshot if present
                        if (topic.ViewpointSnapshots.ContainsKey(topic.Viewpoints[i].GUID))
                        {
                            var snapshotEntryName = topic.Markup.Topic.Guid + "/" + topic.Markup.Viewpoints[i].Snapshot;
                            var viewpointSnapshot = bcfZip.CreateEntry(snapshotEntryName);
                            using (var CurrentViewpointSnapshotWriter = new BinaryWriter(viewpointSnapshot.Open()))
                            {
                                CurrentViewpointSnapshotWriter.Write(topic.ViewpointSnapshots[topic.Markup.Viewpoints[i].Guid]);
                            }
                        }
                        // Write bitmaps if present
                        if (topic.ViewpointBitmaps.ContainsKey(topic.Viewpoints[i]))
                        {
                            for (var j = 0; j < topic.ViewpointBitmaps[topic.Viewpoints[i]].Count; j++)
                            {
                                // It's a little bit hacky still....
                                var bitmapEntryName      = topic.Markup.Topic.Guid + "/" + topic.Viewpoints[i].Bitmaps[j].Reference;
                                var viewpointBitmapEntry = bcfZip.CreateEntry(bitmapEntryName);
                                using (var viewpointBitmapWriter = new BinaryWriter(viewpointBitmapEntry.Open()))
                                {
                                    viewpointBitmapWriter.Write(topic.ViewpointBitmaps[topic.Viewpoints[i]][j]);
                                }
                            }
                        }
                    }
                }
            }
        }