예제 #1
0
        private void AddCommentNodes(XmlDocument xmlDoc, BCF bcf)
        {
            try
            {
                bool        found = false;
                XmlNodeList nodes = xmlDoc.SelectNodes("Markup/Comment");
                foreach (Comment comment in bcf.MarkUp.Comments)
                {
                    found = false;
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes[0].Value == comment.CommentGuid) //update existing Comment
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        XmlElement   root           = xmlDoc.DocumentElement;
                        XmlElement   commentElement = xmlDoc.CreateElement("Comment");
                        XmlAttribute attribute      = xmlDoc.CreateAttribute("Guid");
                        attribute.Value = comment.CommentGuid;
                        commentElement.SetAttributeNode(attribute);
                        root.AppendChild(commentElement);

                        XmlNode newNode = xmlDoc.CreateNode("element", "VerbalStatus", "");
                        newNode.InnerText = comment.VerbalStatus;
                        commentElement.AppendChild(newNode);

                        newNode           = xmlDoc.CreateNode("element", "Status", "");
                        newNode.InnerText = comment.Status.ToString();
                        commentElement.AppendChild(newNode);

                        newNode = xmlDoc.CreateNode("element", "Date", "");
                        DateTimeOffset offset = new DateTimeOffset(comment.Date);
                        newNode.InnerText = offset.ToString("yyyy-MM-dd'T'HH:mm:sszzz");
                        commentElement.AppendChild(newNode);

                        newNode           = xmlDoc.CreateNode("element", "Author", "");
                        newNode.InnerText = comment.Author;
                        commentElement.AppendChild(newNode);

                        newNode           = xmlDoc.CreateNode("element", "Comment", "");
                        newNode.InnerText = comment.CommentString;
                        commentElement.AppendChild(newNode);

                        XmlElement   newElement   = xmlDoc.CreateElement("Topic");
                        XmlAttribute newAttribute = xmlDoc.CreateAttribute("Guid");
                        newAttribute.Value = bcf.MarkUp.MarkUpTopic.TopicGuid;
                        newElement.SetAttributeNode(newAttribute);
                        commentElement.AppendChild(newElement);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add comment nodes.\n" + ex.Message, "BCFReaderClass:AddCommentNodes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #2
0
 private void DeleteCommentNodes(XmlDocument xmlDoc, BCF bcf)
 {
     try
     {
         bool        found = false;
         XmlNodeList nodes = xmlDoc.SelectNodes("Markup/Comment");
         for (int i = 0; i < nodes.Count; i++)
         {
             XmlNode node = nodes[i];
             found = false;
             foreach (Comment comment in bcf.MarkUp.Comments)
             {
                 if (node.Attributes[0].Value == comment.CommentGuid) //update existing Comment
                 {
                     found = true;
                 }
             }
             if (found)
             {
                 continue;
             }
             else
             {
                 xmlDoc.DocumentElement.RemoveChild(node);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to delete comment nodes. \n" + ex.Message, "BCFReaderClass:DeleteCommentNodes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
예제 #3
0
        private BCF CombineReferenceData(BCF rawBcf)
        {
            try
            {
                if (refBCF.ContainsKey(rawBcf.MarkUp.MarkUpTopic.TopicGuid))
                {
                    BCF bcfReference = refBCF[rawBcf.MarkUp.MarkUpTopic.TopicGuid];
                    rawBcf.IssueNumber = bcfReference.IssueNumber;

                    List <Comment> comments = rawBcf.MarkUp.Comments;
                    for (int i = comments.Count - 1; i > -1; i--)
                    {
                        Comment comment = comments[i];
                        foreach (Comment refComment in bcfReference.MarkUp.Comments)
                        {
                            if (refComment.CommentGuid == comment.CommentGuid)
                            {
                                comment.Action = refComment.Action;
                                comments.RemoveAt(i);
                                comments.Add(comment);
                                break;
                            }
                        }
                    }
                    rawBcf.MarkUp.Comments = comments;
                }
                return(rawBcf);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read markup.bcf \n" + ex.Message, "BCFReaderClass:CombineReferenceData", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                readSucceeded = false;
                return(rawBcf);
            }
        }
예제 #4
0
        public void WriteMarkUp()
        {
            try
            {
                BCF      bcfToWrite = new BCF();
                FileInfo fileInfo   = new FileInfo(bcfPath);
                string   baseFolder = bcfPath.Remove(bcfPath.Length - fileInfo.Extension.Length);

                string[] directories = Directory.GetDirectories(baseFolder);
                if (directories.Length > 0)
                {
                    for (int i = 0; i < directories.Length; i++)
                    {
                        string guidFolder = directories[i];
                        markupPath = Path.Combine(guidFolder, "markup.bcf");

                        using (FileStream fileStream = File.Open(markupPath, FileMode.OpenOrCreate))
                        {
                            XmlDocument xmlDoc = new XmlDocument();

                            string currentAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()).Location;
                            string schemaPath      = Path.GetDirectoryName(currentAssembly) + "\\Resources\\markup.xsd";

                            XmlTextReader reader = new XmlTextReader(schemaPath);
                            XmlSchema     schema = XmlSchema.Read(reader, null);

                            xmlDoc.Schemas.Add(schema);
                            xmlDoc.Load(fileStream);

                            XmlNode singlenode = xmlDoc.SelectSingleNode("Markup/Topic");
                            string  guid       = singlenode.Attributes[0].Value;
                            if (bcfFiles.ContainsKey(guid))
                            {
                                bcfToWrite = bcfFiles[guid];
                                DeleteCommentNodes(xmlDoc, bcfToWrite);
                                UpdateCommentNodes(xmlDoc, bcfToWrite);
                                AddCommentNodes(xmlDoc, bcfToWrite);
                                fileStream.Close();
                                xmlDoc.Schemas.Compile();
                                xmlDoc.Save(markupPath);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write markup.bcf \n" + ex.Message, "BCFReaderClass:WriteMarkUp", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #5
0
        private void UpdateCommentNodes(XmlDocument xmlDoc, BCF bcf)
        {
            try
            {
                XmlNodeList nodes = xmlDoc.SelectNodes("Markup/Comment");
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node = nodes[i];
                    foreach (Comment comment in bcf.MarkUp.Comments)
                    {
                        if (node.Attributes[0].Value == comment.CommentGuid) //update existing Comment
                        {
                            foreach (XmlNode childNode in node.ChildNodes)
                            {
                                switch (childNode.Name)
                                {
                                case "VerbalStatus":
                                    childNode.InnerText = comment.VerbalStatus;
                                    break;

                                case "Status":
                                    childNode.InnerText = comment.Status.ToString();
                                    break;

                                case "Date":
                                    DateTimeOffset offset = new DateTimeOffset(comment.Date);
                                    childNode.InnerText = offset.ToString("yyyy-MM-dd'T'HH:mm:sszzz");
                                    break;

                                case "Author":
                                    childNode.InnerText = comment.Author;
                                    break;

                                case "Comment":
                                    childNode.InnerText = comment.CommentString;
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update comment nodes.\n" + ex.Message, "BCFReaderClass:UpdateCommentNodes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #6
0
 public BCF GetSanpShot(BCF bcfImage)
 {
     try
     {
         if (File.Exists(imagePath))
         {
             FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
             bcfImage.SnapShot = Image.FromStream(fs);
             fs.Close();
         }
         return(bcfImage);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to get snapshot.png \n" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         readSucceeded = false;
         return(bcfImage);
     }
 }
예제 #7
0
        //change the file extension from bcfzip to zip and read xml files
        public void ChangeToZip()
        {
            try
            {
                FileInfo fileInfo = new FileInfo(bcfPath);
                fileInfo.MoveTo(Path.ChangeExtension(bcfPath, ".zip"));
                tempBcfPath = fileInfo.FullName;
                string baseFolder = tempBcfPath.Remove(tempBcfPath.Length - fileInfo.Extension.Length);
                DecompressFiles(tempBcfPath, baseFolder);

                string[] directories = Directory.GetDirectories(baseFolder);
                if (directories.Length > 0)
                {
                    for (int i = 0; i < directories.Length; i++)
                    {
                        string guidFolder = directories[i];
                        markupPath = Path.Combine(guidFolder, "markup.bcf");
                        imagePath  = Path.Combine(guidFolder, "snapshot.png");
                        viewPath   = Path.Combine(guidFolder, "viewpoint.bcfv");
                        BCF bcf = new BCF();
                        bcf = ReadMarkUp(bcf);
                        bcf = GetSanpShot(bcf);
                        bcf = ReadViewPoint(bcf);
                        if (readSucceeded)
                        {
                            bcf.IssueNumber = (i + 1).ToString();
                            if (foundRef)
                            {
                                bcf = CombineReferenceData(bcf);
                            }
                            bcfFiles.Add(bcf.MarkUp.MarkUpTopic.TopicGuid, bcf);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to change the file extension as zip.\n" + ex.Message, "BCFReader:ChangeToZip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #8
0
        public void ReadINI()
        {
            try
            {
                if (File.Exists(iniPath))
                {
                    using (StreamReader sr = new StreamReader(iniPath))
                    {
                        string line;
                        Dictionary <string /*topicId*/, BCF> tempDictionary = new Dictionary <string, BCF>();
                        BCF bcf = new BCF();
                        bcf.MarkUp             = new BCFMarkUp();
                        bcf.MarkUp.MarkUpTopic = new Topic();
                        List <Comment> commentList = new List <Comment>();
                        string         bcfPath     = "";
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Contains("****"))
                            {
                                if (bcfPath != null)
                                {
                                    if (bcf.IssueNumber != null && commentList.Count > 0)
                                    {
                                        bcf.MarkUp.Comments = commentList;
                                        tempDictionary.Add(bcf.MarkUp.MarkUpTopic.TopicGuid, bcf);
                                    }

                                    refDictionary.Add(bcfPath, tempDictionary);
                                    tempDictionary         = new Dictionary <string, BCF>();
                                    bcf                    = new BCF();
                                    bcf.MarkUp             = new BCFMarkUp();
                                    bcf.MarkUp.MarkUpTopic = new Topic();
                                    commentList            = new List <Comment>();
                                }
                            }
                            else if (line.Contains("BCFFile##"))//BCFFile##Directory
                            {
                                string[] bcfInfo = line.Split(splitter, StringSplitOptions.None);
                                if (bcfInfo.Length == 2)
                                {
                                    bcfPath = bcfInfo[1];
                                }
                            }
                            else if (line.Contains("Issue##"))//Issue##TopicID##Title##IssueNumber
                            {
                                if (bcf.IssueNumber != null && commentList.Count > 0)
                                {
                                    bcf.MarkUp.Comments = commentList;
                                    tempDictionary.Add(bcf.MarkUp.MarkUpTopic.TopicGuid, bcf);
                                    bcf                    = new BCF();
                                    bcf.MarkUp             = new BCFMarkUp();
                                    bcf.MarkUp.MarkUpTopic = new Topic();
                                    commentList            = new List <Comment>();
                                }
                                string[] issueInfo = line.Split(splitter, StringSplitOptions.None);
                                if (issueInfo.Length == 4)
                                {
                                    bcf.MarkUp.MarkUpTopic.TopicGuid = issueInfo[1];
                                    bcf.MarkUp.MarkUpTopic.Title     = issueInfo[2];
                                    bcf.IssueNumber = issueInfo[3];
                                }
                            }
                            else if (line.Contains("Comment##")) //Comment##CommentID##CommentString##Action
                            {
                                string[] commentInfo = line.Split(splitter, StringSplitOptions.None);
                                if (commentInfo.Length == 4)
                                {
                                    Comment comment = new Comment();
                                    comment.CommentGuid   = commentInfo[1];
                                    comment.CommentString = commentInfo[2];
                                    comment.Action        = commentInfo[3];
                                    commentList.Add(comment);
                                }
                            }
                        }
                        sr.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read ini file.\n" + iniPath + "\n" + ex.Message, "INIDataManager:ReadINI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #9
0
        public void WriteINI()
        {
            try
            {
                if (!File.Exists(iniPath))
                {
                    using (FileStream fileStream = File.Create(iniPath))
                    {
                        fileStream.Close();
                    }
                }

                //delete all
                string tempFile = Path.GetTempFileName();
                using (StreamReader sr = new StreamReader(iniPath))
                {
                    using (StreamWriter sw = new StreamWriter(tempFile))
                    {
                        string line;

                        while ((line = sr.ReadLine()) != null)
                        {
                            sw.WriteLine("");
                        }
                    }
                }

                File.Delete(iniPath);
                File.Move(tempFile, iniPath);
                FileStream fs = File.Open(iniPath, FileMode.Create);

                if (refDictionary.ContainsKey(selectedFilePath))
                {
                    refDictionary.Remove(selectedFilePath);
                }
                refDictionary.Add(selectedFilePath, bcfFiles);

                using (StreamWriter sw = new StreamWriter(fs))
                {
                    string sp = "##";
                    foreach (string filePath in refDictionary.Keys)
                    {
                        Dictionary <string, BCF> tempBcfFiles = new Dictionary <string, BCF>();
                        tempBcfFiles = refDictionary[filePath];
                        sw.WriteLine("BCFFile" + sp + filePath);
                        foreach (string topicId in tempBcfFiles.Keys)
                        {
                            BCF bcf = tempBcfFiles[topicId];
                            sw.WriteLine("Issue" + sp + topicId + sp + bcf.MarkUp.MarkUpTopic.Title + sp + bcf.IssueNumber);
                            foreach (Comment comment in bcf.MarkUp.Comments)
                            {
                                sw.WriteLine("Comment" + sp + comment.CommentGuid + sp + comment.CommentString + sp + comment.Action);
                            }
                        }
                        sw.WriteLine("********************************************************");
                    }
                    sw.Close();
                }
                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write ini file.\n" + ex.Message, "INIDataManager:WriteINI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #10
0
        public BCF ReadViewPoint(BCF bcfViewPoint)
        {
            try
            {
                if (File.Exists(viewPath))
                {
                    XmlTextReader               reader      = new XmlTextReader(viewPath);
                    BCFViewPoint                viewpoint   = new BCFViewPoint();
                    List <Component>            components  = new List <Component>();
                    PerspectiveCameraProperties perspective = new PerspectiveCameraProperties();
                    Point point = new Point();

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "Components")
                        {
                            Component component = new Component();
                            reader.Read();
                            while (true)
                            {
                                if (reader.IsStartElement())
                                {
                                    switch (reader.Name)
                                    {
                                    case "Component":
                                        if (null != component.IfcGuid)
                                        {
                                            components.Add(component);
                                        }
                                        component         = new Component();
                                        component.IfcGuid = reader.GetAttribute("IfcGuid");
                                        break;

                                    case "OriginatingSystem":
                                        component.OriginatingSystem = reader.ReadElementContentAsString();
                                        break;

                                    case "AuthoringToolId":
                                        component.AuthoringToolId = reader.ReadElementContentAsString();
                                        break;
                                    }
                                }
                                else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Components")
                                {
                                    if (null != component.IfcGuid)
                                    {
                                        components.Add(component);
                                    }
                                    break;
                                }
                                reader.Read();
                            }
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "PerspectiveCamera")
                        {
                            while (true)
                            {
                                if (reader.IsStartElement())
                                {
                                    switch (reader.Name)
                                    {
                                    case "CameraViewPoint":
                                        point = new Point();
                                        reader.ReadToFollowing("X");  point.X = reader.ReadElementContentAsDouble();
                                        reader.ReadToFollowing("Y");  point.Y = reader.ReadElementContentAsDouble();
                                        reader.ReadToFollowing("Z");  point.Z = reader.ReadElementContentAsDouble();
                                        perspective.CameraViewPoint           = point;
                                        break;

                                    case "CameraDirection":
                                        point = new Point();
                                        reader.ReadToFollowing("X");  point.X = reader.ReadElementContentAsDouble();
                                        reader.ReadToFollowing("Y");  point.Y = reader.ReadElementContentAsDouble();
                                        reader.ReadToFollowing("Z");  point.Z = reader.ReadElementContentAsDouble();
                                        perspective.CameraDirection           = point;
                                        break;

                                    case "CameraUpVector":
                                        point = new Point();
                                        reader.ReadToFollowing("X");  point.X = reader.ReadElementContentAsDouble();
                                        reader.ReadToFollowing("Y");  point.Y = reader.ReadElementContentAsDouble();
                                        reader.ReadToFollowing("Z");  point.Z = reader.ReadElementContentAsDouble();
                                        perspective.CameraUpVector            = point;
                                        break;

                                    case "FieldOfView":
                                        perspective.FieldOfView = reader.ReadElementContentAsDouble();
                                        break;
                                    }
                                }
                                else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "PerspectiveCamera")
                                {
                                    break;
                                }
                                reader.Read();
                            }
                        }
                    }
                    reader.Close();

                    viewpoint.Components        = components;
                    viewpoint.PerspectiveCamera = perspective;
                    bcfViewPoint.ViewPoint      = viewpoint;
                }
                return(bcfViewPoint);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read viewpoint.bcfv \n" + ex.Message, "BCFReaderClass:ReadViewPoint", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                readSucceeded = false;
                return(bcfViewPoint);
            }
        }
예제 #11
0
        public BCF ReadMarkUp(BCF bcfMarkup)
        {
            try
            {
                if (File.Exists(markupPath))
                {
                    BCFMarkUp      markup   = new BCFMarkUp();
                    List <IfcFile> ifcFiles = new List <IfcFile>();
                    Topic          topic    = new Topic();
                    List <Comment> comments = new List <Comment>();

                    using (FileStream filestream = new FileStream(markupPath, FileMode.Open))
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.Load(filestream);

                        XmlNode headerNode = xmlDoc.SelectSingleNode("Markup/Header");
                        foreach (XmlNode fileNode in headerNode.ChildNodes)
                        {
                            IfcFile ifcFile = new IfcFile();
                            ifcFile.IfcGuid = fileNode.Attributes[0].Value;

                            foreach (XmlNode childnode in fileNode.ChildNodes)
                            {
                                if (childnode.Name == "Filename")
                                {
                                    ifcFile.FileName = childnode.InnerText;
                                }
                                if (childnode.Name == "Date")
                                {
                                    ifcFile.Date = DateTime.Parse(childnode.InnerText);
                                }
                            }
                            ifcFiles.Add(ifcFile);
                        }

                        XmlNode TopicNode = xmlDoc.SelectSingleNode("Markup/Topic");
                        topic.TopicGuid = TopicNode.Attributes[0].Value;
                        foreach (XmlNode node in TopicNode.ChildNodes)
                        {
                            if (node.Name == "ReferenceLink")
                            {
                                topic.ReferenceLink = node.InnerText;
                            }
                            if (node.Name == "Title")
                            {
                                topic.Title = node.InnerText;
                            }
                        }

                        XmlNodeList commentNodes = xmlDoc.SelectNodes("Markup/Comment");
                        foreach (XmlNode commentNode in commentNodes)
                        {
                            Comment comment = new Comment();
                            comment.CommentGuid = commentNode.Attributes[0].Value;

                            foreach (XmlNode node in commentNode.ChildNodes)
                            {
                                if (node.Name == "VerbalStatus")
                                {
                                    comment.VerbalStatus = node.InnerText;
                                }
                                if (node.Name == "Status")
                                {
                                    switch (node.InnerText)
                                    {
                                    case "Error":
                                        comment.Status = CommentStatus.Error;
                                        break;

                                    case "Info":
                                        comment.Status = CommentStatus.Info;
                                        break;

                                    case "Unknown":
                                        comment.Status = CommentStatus.Unknown;
                                        break;

                                    case "Warning":
                                        comment.Status = CommentStatus.Warning;
                                        break;
                                    }
                                }
                                if (node.Name == "Date")
                                {
                                    comment.Date = DateTime.Parse(node.InnerText);
                                }
                                if (node.Name == "Author")
                                {
                                    comment.Author = node.InnerText;
                                }
                                if (node.Name == "Comment")
                                {
                                    comment.CommentString = node.InnerText;
                                }
                                if (node.Name == "Topic")
                                {
                                    Topic linkedtopic = new Topic();
                                    linkedtopic.TopicGuid = node.Attributes[0].Value;
                                    comment.Topic         = linkedtopic;
                                }
                            }
                            comments.Add(comment);
                        }
                        filestream.Close();
                    }
                    markup.Header      = ifcFiles;
                    markup.MarkUpTopic = topic;
                    markup.Comments    = comments;
                    bcfMarkup.MarkUp   = markup;
                }
                return(bcfMarkup);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read markup.bcf \n" + ex.Message, "BCFReaderClass:ReadMarkUp", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                readSucceeded = false;
                return(bcfMarkup);
            }
        }