Esempio n. 1
0
        public void MergeFiles(BcfFile bcf)
        {
            var bcffiles = OpenBcfDialog();

            if (bcffiles == null)
            {
                return;
            }
            bcf.MergeBcfFile(bcffiles);
        }
Esempio n. 2
0
 public void CloseFile(BcfFile bcf)
 {
     try
     {
         _bcfFiles.Remove(bcf);
         Utils.DeleteDirectory(bcf.TempPath);
     }
     catch (System.Exception ex1)
     {
         MessageBox.Show("exception: " + ex1);
     }
 }
Esempio n. 3
0
 private void BcfOpened(BcfFile newbcf)
 {
     if (newbcf != null)
     {
         BcfFiles.Add(newbcf);
         SelectedReportIndex = BcfFiles.Count - 1;
         if (newbcf.Issues.Any())
         {
             newbcf.SelectedIssue = newbcf.Issues.First();
         }
     }
 }
Esempio n. 4
0
 public void SaveFile(BcfFile bcf)
 {
     SaveBcfFile(bcf);
 }
Esempio n. 5
0
        /// <summary>
        /// Serializes to a bcfzip and saves it to disk
        /// </summary>
        /// <param name="bcffile"></param>
        /// <returns></returns>
        public static bool SaveBcfFile(BcfFile bcffile)
        {
            try
            {
                if (bcffile.Issues.Count == 0)
                {
                    MessageBox.Show("The current BCF Report is empty.", "No Issue", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
                if (!Directory.Exists(bcffile.TempPath))
                {
                    Directory.CreateDirectory(bcffile.TempPath);
                }
                // Show save file dialog box
                string name = !string.IsNullOrEmpty(bcffile.Filename)
            ? bcffile.Filename
            : "New BCF Report";
                string filename = SaveBcfDialog(name);

                // Process save file dialog box results
                if (string.IsNullOrWhiteSpace(filename))
                {
                    return(false);
                }

                var bcfProject = new ProjectExtension
                {
                    Project = new Project
                    {
                        Name      = string.IsNullOrEmpty(bcffile.ProjectName) ? bcffile.Filename : bcffile.ProjectName,
                        ProjectId = bcffile.ProjectId.Equals(Guid.Empty) ? Guid.NewGuid().ToString() : bcffile.ProjectId.ToString()
                    },
                    ExtensionSchema = "ExtensionSchema.xsd"
                };
                var bcfVersion = new Version {
                    VersionId = "2.0", DetailedVersion = "2.0 RC"
                };

                var    serializerP = new XmlSerializer(typeof(ProjectExtension));
                Stream writerP     = new FileStream(Path.Combine(bcffile.TempPath, "project.bcfp"), FileMode.Create);
                serializerP.Serialize(writerP, bcfProject);
                writerP.Close();

                var    serializerVers = new XmlSerializer(typeof(Version));
                Stream writerVers     = new FileStream(Path.Combine(bcffile.TempPath, "bcf.version"), FileMode.Create);
                serializerVers.Serialize(writerVers, bcfVersion);
                writerVers.Close();

                var serializerV = new XmlSerializer(typeof(VisualizationInfo));
                var serializerM = new XmlSerializer(typeof(Markup));

                foreach (var issue in bcffile.Issues)
                {
                    // Serialize the object, and close the TextWriter
                    string issuePath = Path.Combine(bcffile.TempPath, issue.Topic.Guid);
                    if (!Directory.Exists(issuePath))
                    {
                        Directory.CreateDirectory(issuePath);
                    }

                    //BCF 1 compatibility
                    //there needs to be a view whose viewpoint and snapshot are named as follows and not with a guid
                    //uniqueness is still guarenteed by the guid field

                    if (issue.Viewpoints != null)
                    {
                        if (issue.Viewpoints.Any() && (issue.Viewpoints.Count == 1 || issue.Viewpoints.All(o => o.Viewpoint != "viewpoint.bcfv")))
                        {
                            if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint)))
                            {
                                File.Move(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint), Path.Combine(issuePath, "viewpoint.bcfv"));
                            }
                            issue.Viewpoints[0].Viewpoint = "viewpoint.bcfv";
                            if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Snapshot)))
                            {
                                File.Move(Path.Combine(issuePath, issue.Viewpoints[0].Snapshot), Path.Combine(issuePath, "snapshot.png"));
                            }
                            issue.Viewpoints[0].Snapshot = "snapshot.png";
                        }
                    }

                    //serialize markup with updated content
                    Stream writerM = new FileStream(Path.Combine(issuePath, "markup.bcf"), FileMode.Create);
                    serializerM.Serialize(writerM, issue);
                    writerM.Close();

                    //serialize views
                    if (issue.Viewpoints != null)
                    {
                        foreach (var bcfViewpoint in issue.Viewpoints)
                        {
                            if (bcfViewpoint.Viewpoint != null)
                            {
                                string viewpointPath = Path.Combine(issuePath, bcfViewpoint.Viewpoint);
                                if (bcfViewpoint.VisInfo != null)
                                {
                                    Stream writerV = new FileStream(viewpointPath, FileMode.Create);
                                    serializerV.Serialize(writerV, bcfViewpoint.VisInfo);
                                    writerV.Close();
                                }
                                else if (File.Exists(viewpointPath)) // this code block is for Solibri
                                {
                                    XmlDocument doc = new XmlDocument();
                                    doc.PreserveWhitespace = true;
                                    try
                                    {
                                        doc.Load(viewpointPath);
                                        doc.DocumentElement.SetAttribute("noNamespaceSchemaLocation",
                                                                         "http://www.w3.org/2001/XMLSchema-instance",
                                                                         "visinfo.xsd"
                                                                         );
                                        doc.Save(viewpointPath);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("Failed to write schema info. Cannot be imported to Solibri.",
                                                        "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                                    }
                                }
                                else // fallback logic for Solibri and BCFier
                                {
                                    // add a blank viewpoint file
                                    Stream writerV = new FileStream(viewpointPath, FileMode.Create);
                                    serializerV.Serialize(writerV, new VisualizationInfo());
                                    writerV.Close();
                                }
                            }
                        }
                    }
                }

                //overwrite, without doubts
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }

                using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
                {
                    zip.AddDirectory(bcffile.TempPath);
                    zip.Save(filename);
                }

                //this library cause conflicts with Solibri
                //ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Fastest, false);

                //DeleteDirectory(bcffile.TempPath);

                //Open browser at location
                Uri    uri2       = new Uri(filename);
                string reportname = Path.GetFileName(uri2.LocalPath);

                if (File.Exists(filename))
                {
                    string argument = @"/select, " + filename;
                    System.Diagnostics.Process.Start("explorer.exe", argument);
                }
                bcffile.HasBeenSaved = true;
                bcffile.Filename     = reportname;
            }
            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Logic that extracts files from a bcfzip and deserializes them
        /// </summary>
        /// <param name="bcfzipfile">Path to the .bcfzip file</param>
        /// <returns></returns>
        private static BcfFile OpenBcfFile(string bcfzipfile)
        {
            var bcffile = new BcfFile();

            try
            {
                if (!File.Exists(bcfzipfile) || !String.Equals(Path.GetExtension(bcfzipfile), ".bcfzip", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(bcffile);
                }


                bcffile.Filename = Path.GetFileNameWithoutExtension(bcfzipfile);
                bcffile.Fullname = bcfzipfile;

                using (ZipArchive archive = ZipFile.OpenRead(bcfzipfile))
                {
                    archive.ExtractToDirectory(bcffile.TempPath);
                }

                var dir = new DirectoryInfo(bcffile.TempPath);

                var projectFile = Path.Combine(bcffile.TempPath, "project.bcfp");
                if (File.Exists(projectFile))
                {
                    var project = DeserializeProject(projectFile);
                    var g       = Guid.NewGuid();
                    Guid.TryParse(project.Project.ProjectId, out g);
                    bcffile.ProjectId = g;
                }


                //ADD ISSUES FOR EACH SUBFOLDER

                foreach (var folder in dir.GetDirectories())
                {
                    //An issue needs at least the markup file
                    var markupFile = Path.Combine(folder.FullName, "markup.bcf");
                    if (!File.Exists(markupFile))
                    {
                        continue;
                    }

                    var bcfissue = DeserializeMarkup(markupFile);


                    if (bcfissue == null)
                    {
                        continue;
                    }

                    //Is a BCF 2 file, has multiple viewpoints
                    if (bcfissue.Viewpoints != null && bcfissue.Viewpoints.Any())
                    {
                        foreach (var viewpoint in bcfissue.Viewpoints)
                        {
                            string viewpointpath = Path.Combine(folder.FullName, viewpoint.Viewpoint);
                            if (File.Exists(viewpointpath))
                            {
                                //deserializing the viewpoint into the issue
                                viewpoint.VisInfo      = DeserializeViewpoint(viewpointpath);
                                viewpoint.SnapshotPath = Path.Combine(folder.FullName, viewpoint.Snapshot);
                            }
                        }
                    }
                    //Is a BCF 1 file, only one viewpoint
                    //there is no Viewpoints tag in the markup
                    //update it to BCF 2
                    else
                    {
                        bcfissue.Viewpoints = new ObservableCollection <ViewPoint>();
                        string viewpointFile = Path.Combine(folder.FullName, "viewpoint.bcfv");
                        if (File.Exists(viewpointFile))
                        {
                            bcfissue.Viewpoints.Add(new ViewPoint(true)
                            {
                                VisInfo      = DeserializeViewpoint(viewpointFile),
                                SnapshotPath = Path.Combine(folder.FullName, "snapshot.png"),
                            });
                            //update the comments
                            foreach (var comment in bcfissue.Comment)
                            {
                                comment.Viewpoint      = new CommentViewpoint();
                                comment.Viewpoint.Guid = bcfissue.Viewpoints.First().Guid;
                            }
                        }
                    }
                    bcfissue.Comment = new ObservableCollection <Comment>(bcfissue.Comment.OrderBy(x => x.Date));
                    //register the collectionchanged events,
                    //it is needed since deserialization overwrites the ones set in the constructor
                    bcfissue.RegisterEvents();
                    //ViewComment stuff
                    bcffile.Issues.Add(bcfissue);
                }
            }
            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return(bcffile);
        }