Пример #1
0
        /// <summary>
        /// Save the Threat Model passed as argument as Template.
        /// </summary>
        /// <param name="model">Threat Model to be saved as Template.</param>
        /// <param name="definition">Definition of the information to export.</param>
        /// <param name="name">Name of the Template.</param>
        /// <param name="description">Description of the Template.</param>
        /// <param name="path">Path to the Template to be created.</param>
        public static void SaveTemplate(this IThreatModel model, [NotNull] DuplicationDefinition definition,
                                        [Required] string name, string description, [Required] string path)
        {
            var newModel = model.Duplicate(name, definition);

            newModel.Description = description;
            var serialization = ThreatModelManager.Serialize(newModel);

            var extension = Path.GetExtension(path)?.ToLower();

            switch (extension)
            {
            case ".tmt":
                var package = Package.Create(path);
                package.Add(Resources.ThreatModelTemplateFile, serialization);
                package.Save();
                break;

            case ".tmk":
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                using (var file = File.OpenWrite(path))
                {
                    using (var writer = new BinaryWriter(file))
                    {
                        writer.Write(serialization);
                    }
                }
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Save the Threat Model passed as argument as Template.
        /// </summary>
        /// <param name="model">Threat Model to be saved as Template.</param>
        /// <param name="definition">Definition of the information to export.</param>
        /// <param name="name">Name of the Template.</param>
        /// <param name="description">Description of the Template.</param>
        /// <param name="path">Path to the Template to be created.</param>
        public static void SaveTemplate(this IThreatModel model, [NotNull] DuplicationDefinition definition,
                                        [Required] string name, string description, [Required] string path)
        {
            var newModel = model.Duplicate(name, definition);

            newModel.Description = description;
            var serialization = ThreatModelManager.Serialize(newModel);

            var package = Package.Create(path);

            package.Add(Resources.ThreatModelTemplateFile, serialization);
            package.Save();
        }