Exemple #1
0
        public IThreatModel Load(LocationType locationType, [Required] string location,
                                 IEnumerable <IExtensionMetadata> extensions, bool strict = true)
        {
            IThreatModel result = null;

            if (File.Exists(location))
            {
                var threatModelContent = File.ReadAllBytes(location);
                if (threatModelContent != null)
                {
                    try
                    {
                        result = ThreatModelManager.Deserialize(threatModelContent, !strict);
                    }
                    catch (JsonSerializationException e)
                    {
                        throw new ThreatModelOpeningFailureException("A serialization issue has occurred.", e);
                    }
                }
            }
            else
            {
                throw new FileNotFoundException("Unable to find the specified file.", location);
            }

            return(result);
        }
Exemple #2
0
        public IThreatModel Load(LocationType locationType, [Required] string location,
                                 IEnumerable <IExtensionMetadata> extensions, bool strict = true)
        {
            IThreatModel result = null;

            if (File.Exists(location))
            {
                var package = new Package(location);

                var threatModelContent = package.Read(ThreatModelFile);
                if (threatModelContent != null)
                {
                    try
                    {
                        result = ThreatModelManager.Deserialize(threatModelContent, !strict);
                    }
                    catch (JsonSerializationException e)
                    {
                        HandleJsonSerializationException(package, extensions, e);
                        throw;
                    }
                }
            }
            else
            {
                throw new FileNotFoundException("Unable to find the specified file.", location);
            }

            return(result);
        }
        public IThreatModel OpenModel(string fileName)
        {
            IThreatModel result = null;

            var package = new Package(fileName);

            var threatModelContent = package.Read("threatmodel.json");

            if (threatModelContent != null)
            {
                try
                {
                    result = ThreatModelManager.Deserialize(threatModelContent, true);
                }
                catch (JsonSerializationException e)
                {
                    Console.WriteLine($"Some required extension was missing.\nMore details: {e.Message}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Exception {e.ToString()}");
                }
            }

            return(result);
        }
Exemple #4
0
        public IThreatModel Load(LocationType locationType, string location, SecureString password)
        {
            IThreatModel result = null;

            if (File.Exists(location))
            {
                var package = new Package(location);

                var threatModelContent = package.Read(ThreatModelFile, password);
                if (threatModelContent != null)
                {
                    result = ThreatModelManager.Deserialize(threatModelContent);
                }
            }
            else
            {
                throw new FileNotFoundException();
            }

            return(result);
        }