Exemple #1
0
        public void Initialize([NotNull] IThreatModel model)
        {
            var schemaManager = new DefinitionsPropertySchemaManager(model);

            var propertyType = schemaManager.DefinitionsPropertyType;

            if (propertyType != null)
            {
                var property = model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null);

                if (property is IPropertyJsonSerializableObject jsonProperty)
                {
                    var definitions = new DefinitionContainer();
                    definitions.SetDefinition("Threat Model",
                                              "Threat Modeling is a process to understand potential threat events to a system, determine risks from those threats, and establish appropriate mitigations.");
                    definitions.SetDefinition("Threat Events",
                                              "Potential attack scenarios to the system. Who performs those attack scenarios is called Threat Actor.");
                    definitions.SetDefinition("Risks",
                                              "Potential loss caused by the occurring of a Threat Event. It is typically expressed in monetary terms.");
                    definitions.SetDefinition("Mitigations",
                                              "Actions that may decrease the Risk associated to a Threat Event.");

                    jsonProperty.Value = definitions;
                }
            }
        }
        public static List <ProvinceDefinition> GenerateDefinitions(DefinitionContainer container)
        {
            var retVal = new List <ProvinceDefinition> ();


            LandSeaLake humidity = new LandSeaLake();

            if (container.LSLinput != 99)
            {
                humidity = (LandSeaLake)container.LSLinput;
            }

            List <string> RGBValues = new List <string>();

            var i = 0;

            while (i < container.provNumber)
            {
                var RGBValue = GenerateRandomRGBValues();
                if (!RGBValues.Any().Equals(RGBValue))
                {
                    RGBValues.Add(RGBValue);
                    i++;
                }
            }

            Dictionary <int, int> ContinentIdValues = new Dictionary <int, int>();

            ContinentIdValues = PopulateContinentIds(container.provId, container.provNumber, container.continents, container.continentsLowerBound);

            int provId = container.provId;

            foreach (var value in RGBValues)
            {
                if (container.LSLinput == 99)
                {
                    humidity = (LandSeaLake)MainClass.GetRandomNumber(0, 3);
                }
                var province = new ProvinceDefinition();
                province.ProvId      = provId;
                province.Humidity    = humidity;
                province.IsCoastal   = EvaluateIfCoastal(humidity);
                province.TerrainType = PopulateTerrainType(humidity);
                province.RGBvalue    = value;
                province.ContinentId = ContinentIdValues[provId];
                if (humidity == LandSeaLake.Sea)
                {
                    province.ContinentId = 0;
                }
                retVal.Add(province);
                provId++;
            }
            return(retVal);
        }
        public void SetThreatModel(IThreatModel model)
        {
            try
            {
                if (model != null)
                {
                    var schema       = new DefinitionsPropertySchemaManager(model);
                    var propertyType = schema.DefinitionsPropertyType;
                    if (propertyType != null)
                    {
                        var property = model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null);
                        if (property is IPropertyJsonSerializableObject jsonProperty)
                        {
                            if (jsonProperty.Value is DefinitionContainer container)
                            {
                                _container = container;

                                var definitions = container.Definitions?.ToArray();
                                if (definitions?.Any() ?? false)
                                {
                                    foreach (var definition in definitions)
                                    {
                                        _data.Rows.Add(definition.Key, definition.Value);
                                    }
                                }
                            }
                            else
                            {
                                _container         = new DefinitionContainer();
                                jsonProperty.Value = _container;
                            }
                        }
                    }
                }
            }
            finally
            {
                _loading = false;
            }
        }
Exemple #4
0
        public static void DefinitionsMain()
        {
            DefinitionContainer container = new DefinitionContainer();

            Console.WriteLine("Input number of provinces requiring definition:");
            var input      = Console.ReadLine();
            int provNumber = 1;

            Int32.TryParse(input, out provNumber);
            container.provNumber = provNumber;

            Console.WriteLine("Start from 1? (y/n):");
            input = Console.ReadLine();
            bool startat1 = MainClass.ValidateYesNoInput(input);

            container.provId = 1;

            if (!startat1)
            {
                int provId = 1;
                Console.WriteLine("Enter start value:");
                input = Console.ReadLine();
                Int32.TryParse(input, out provId);
                container.provId = provId;
            }

            Console.WriteLine("Input upper number of continents:");
            input = Console.ReadLine();
            int continents = 1;

            Int32.TryParse(input, out continents);
            container.continents = continents;

            Console.WriteLine("Input lower number of continents:");
            input = Console.ReadLine();
            int continentsLowerBound = 1;

            Int32.TryParse(input, out continentsLowerBound);
            container.continentsLowerBound = continentsLowerBound;

            int LSLinput = 99;

            Console.WriteLine("Override random generation of Land, Sea and Lakes? (y/n):");
            input = Console.ReadLine();
            bool LSLoverride = MainClass.ValidateYesNoInput(input);

            if (LSLoverride)
            {
                Console.WriteLine("Land (0) Sea (1) Lakes (2):");
                input = Console.ReadLine();
                Int32.TryParse(input, out LSLinput);
                container.LSLinput = LSLinput;
            }

            string filename = string.Empty;

            Console.WriteLine("Save to custom filename? (y/n):");
            input = Console.ReadLine();
            bool nonDefaultFilename = MainClass.ValidateYesNoInput(input);

            if (nonDefaultFilename)
            {
                Console.WriteLine("Enter filename (excluding extension):");
                filename = Console.ReadLine();
            }

            Console.WriteLine("Generating definitions...");
            var definitions = DefinitionGeneration.GenerateDefinitions(container);

            Console.WriteLine("Saving output to local folder.");
            FileManagement.SaveDefinitionstoCsv(definitions, filename);

            Console.WriteLine("Generation of {0} province definitions, complete", container.provNumber);
            Console.WriteLine("Press Any Key to Kill.");
            Console.ReadKey();
        }