Exemple #1
0
        public bool Execute(IPropertiesContainer container)
        {
            bool result = false;

            if (container != null)
            {
                var dialog = new RemoveSchemaDialog();
                dialog.Initialize(container);
                if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                {
                    var schema = dialog.SelectedSchema;
                    if (schema != null && MessageBox.Show($"You are about to remove Schema '{schema.ToString()}' from the selected object. Do you confirm?",
                                                          "Remove Schema", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        var properties = container.Properties?
                                         .Where(x => (x.PropertyType?.SchemaId ?? Guid.Empty) == schema.Id)
                                         .ToArray();

                        if (properties?.Any() ?? false)
                        {
                            foreach (var property in properties)
                            {
                                container.RemoveProperty(property.PropertyTypeId);
                            }

                            result = true;
                        }
                    }
                }
            }

            return(result);
        }
Exemple #2
0
 private void RemoveRelated([NotNull] IPropertySchema schema, IPropertiesContainer container)
 {
     if (container != null)
     {
         var properties = container.Properties?.Where(x => (x.PropertyType?.SchemaId ?? Guid.Empty) == schema.Id).ToArray();
         if (properties?.Any() ?? false)
         {
             foreach (var property in properties)
             {
                 container.RemoveProperty(property.PropertyType);
             }
         }
     }
 }
Exemple #3
0
        private static void CleanProperties(this IPropertiesContainer container, [NotNull] IThreatModel model)
        {
            var properties = container?.Properties?.ToArray();

            if (properties?.Any() ?? false)
            {
                foreach (var property in properties)
                {
                    var propertyType = model.GetPropertyType(property.PropertyTypeId);
                    if (propertyType == null)
                    {
                        container.RemoveProperty(property.PropertyTypeId);
                    }
                }
            }
        }
        public bool DisableAnnotations([NotNull] IPropertiesContainer container)
        {
            bool result = false;

            var propertyType = GetAnnotationsPropertyType();

            if (propertyType != null)
            {
                var property = container.GetProperty(propertyType);
                if (property != null)
                {
                    result = container.RemoveProperty(propertyType);
                }
            }

            return(result);
        }
Exemple #5
0
        public static SelectionRule GetRule(this IPropertiesContainer container, IThreatModel model = null)
        {
            SelectionRule result = null;

            if (model == null && container is IThreatModelChild child)
            {
                model = child.Model;
            }

            if (model != null)
            {
                var schemaManager = new AutoGenRulesPropertySchemaManager(model);
                var propertyType  = schemaManager.GetPropertyType();
                if (container.HasProperty(propertyType))
                {
                    if (container.GetProperty(propertyType) is IPropertyJsonSerializableObject jsonSerializableObject)
                    {
                        result = jsonSerializableObject.Value as SelectionRule;
                    }
                }
                else
                {
                    var oldSchema       = model.GetSchema(OldSchemaName, Properties.Resources.DefaultNamespace);
                    var oldPropertyType = oldSchema?.GetPropertyType(OldPropertyName);
                    if (oldPropertyType != null)
                    {
                        if (container.GetProperty(oldPropertyType) is IPropertyJsonSerializableObject
                            jsonSerializableObject)
                        {
                            result = jsonSerializableObject.Value as SelectionRule;
                            container.AddProperty(propertyType, jsonSerializableObject.StringValue);
                            container.RemoveProperty(oldPropertyType);
                        }
                    }
                }
            }

            return(result);
        }
Exemple #6
0
        private void Apply([NotNull] IPropertySchema schema, [NotNull] IPropertiesContainer container)
        {
            var existingProp = container.Properties?.ToArray();
            var schemaProp   = schema.PropertyTypes?.ToArray();
            var missing      = existingProp == null ? schemaProp : schemaProp?.Except(existingProp.Select(x => x.PropertyType)).ToArray();
            var inExcess     = existingProp?.Where(x => x.PropertyType != null &&
                                                   x.PropertyType.SchemaId == schema.Id && !(schemaProp?.Any(y => y.Id == x.PropertyTypeId) ?? false)).Select(x => x.PropertyType).ToArray();

            if (missing?.Any() ?? false)
            {
                foreach (var item in missing)
                {
                    container.AddProperty(item, null);
                }
            }

            if (inExcess?.Any() ?? false)
            {
                foreach (var item in inExcess)
                {
                    container.RemoveProperty(item);
                }
            }
        }