Beispiel #1
1
        /// <summary>
        /// Serializes to a bcfzip and saves it to disk
        /// </summary>
        /// <param name="bcffile"></param>
        /// <returns></returns>
        private 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 = ""

            };
            var bcfVersion = new Bcf2.Version { VersionId = "2.0", DetailedVersion = "2.0" };

            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(Bcf2.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.Any() && (issue.Viewpoints.Count == 1 || issue.Viewpoints.All(o => o.Viewpoint != "viewpoint.bcfv")))
              {
            if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint)))
              File.Delete(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint));
            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
              foreach (var bcfViewpoint in issue.Viewpoints)
              {
            Stream writerV = new FileStream(Path.Combine(issuePath, bcfViewpoint.Viewpoint), FileMode.Create);
            serializerV.Serialize(writerV, bcfViewpoint.VisInfo);
            writerV.Close();
              }

            }

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

            ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Optimal, false);

            //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;
        }
Beispiel #2
0
        /// <summary>
        /// Serializes to a bcfzip and saves it to disk
        /// </summary>
        /// <param name="bcffile"></param>
        /// <returns></returns>
        private 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 Project();
                var bcfVersion = new Bcf2.Version {
                    VersionId = "2.0", DetailedVersion = "2.0"
                };

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

                var    serializerVers = new XmlSerializer(typeof(Bcf2.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.Any() && (issue.Viewpoints.Count == 1 || issue.Viewpoints.All(o => o.Viewpoint != "viewpoint.bcfv")))
                    {
                        if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint)))
                        {
                            File.Delete(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint));
                        }
                        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
                    foreach (var bcfViewpoint in issue.Viewpoints)
                    {
                        Stream writerV = new FileStream(Path.Combine(issuePath, bcfViewpoint.Viewpoint), FileMode.Create);
                        serializerV.Serialize(writerV, bcfViewpoint.VisInfo);
                        writerV.Close();
                    }
                }

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

                ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Fastest, false);

                //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);
        }
Beispiel #3
0
        /// <summary>
        /// Serializes to a bcfzip and saves it to disk
        /// </summary>
        /// <param name="bcffile"></param>
        /// <returns></returns>
        private 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 = ""
                };
                var bcfVersion = new Bcf2.Version {
                    VersionId = "2.1", DetailedVersion = "2.1"
                };

                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(Bcf2.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));

                var i = 0;
                foreach (var issue in bcffile.Issues)
                {
                    //set topic index
                    issue.Topic.Index          = i;
                    issue.Topic.IndexSpecified = true;
                    i++;

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

                    //set viewpoint index
                    for (var l = 0; l < issue.Viewpoints.Count; l++)
                    {
                        issue.Viewpoints[l].Index          = l;
                        issue.Viewpoints[l].IndexSpecified = true;
                    }

                    //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.Any() && (issue.Viewpoints.Count == 1 || issue.Viewpoints.All(o => o.Viewpoint != "viewpoint.bcfv")))
                    {
                        if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint)))
                        {
                            File.Delete(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint));
                        }
                        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
                    foreach (var bcfViewpoint in issue.Viewpoints)
                    {
                        Stream writerV = new FileStream(Path.Combine(issuePath, bcfViewpoint.Viewpoint), FileMode.Create);
                        serializerV.Serialize(writerV, bcfViewpoint.VisInfo);
                        writerV.Close();
                    }
                }

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

                //added encoder to address backslashes issue #11
                //issue: https://github.com/teocomi/BCFier/issues/11
                //ref: http://stackoverflow.com/questions/27289115/system-io-compression-zipfile-net-4-5-output-zip-in-not-suitable-for-linux-mac
                ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Optimal, false, new ZipEncoder());

                //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);
        }