Esempio n. 1
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            ModelRoot   element = (ModelRoot)e.ModelElement;
            Store       store   = element.Store;
            Transaction current = store.TransactionManager.CurrentTransaction;

            if (current.IsSerializing)
            {
                return;
            }

            if (Equals(e.NewValue, e.OldValue))
            {
                return;
            }

            List <string> errorMessages = EFCoreValidator.GetErrors(element).ToList();
            bool          redraw        = false;

            switch (e.DomainProperty.Name)
            {
            case "ConnectionString":
                if (e.NewValue != null)
                {
                    element.ConnectionStringName = null;
                }
                break;

            case "ConnectionStringName":
                if (e.NewValue != null)
                {
                    element.ConnectionString = null;
                }
                break;

            case "DatabaseSchema":
                if (string.IsNullOrEmpty((string)e.NewValue))
                {
                    element.DatabaseSchema = "dbo";
                }
                break;

            case "EntityFrameworkVersion":
                element.EntityFrameworkPackageVersion = "Latest";

                if (element.EntityFrameworkVersion == EFVersion.EFCore)
                {
                    element.InheritanceStrategy = CodeStrategy.TablePerHierarchy;
                }

                break;

            case "EnumOutputDirectory":
                if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory))
                {
                    element.EnumOutputDirectory = element.EntityOutputDirectory;
                }
                break;

            case "StructOutputDirectory":
                if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory))
                {
                    element.StructOutputDirectory = element.EntityOutputDirectory;
                }
                break;

            case "EntityOutputDirectory":
                if (string.IsNullOrEmpty(element.EnumOutputDirectory) || element.EnumOutputDirectory == (string)e.OldValue)
                {
                    element.EnumOutputDirectory = (string)e.NewValue;
                }
                if (string.IsNullOrEmpty(element.StructOutputDirectory) || element.StructOutputDirectory == (string)e.OldValue)
                {
                    element.StructOutputDirectory = (string)e.NewValue;
                }
                break;

            case "FileNameMarker":
                string newFileNameMarker = (string)e.NewValue;
                if (!Regex.Match($"a.{newFileNameMarker}.cs",
                                 @"^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\"";|/]+$")
                    .Success)
                {
                    errorMessages.Add("Invalid value to make part of file name");
                }
                break;

            case "InheritanceStrategy":

                if ((element.EntityFrameworkVersion == EFVersion.EFCore) && (element.NuGetPackageVersion.MajorMinorVersionNum < 2.1))
                {
                    element.InheritanceStrategy = CodeStrategy.TablePerHierarchy;
                }

                break;

            case "Namespace":
                errorMessages.Add(CommonRules.ValidateNamespace((string)e.NewValue, CodeGenerator.IsValidLanguageIndependentIdentifier));
                break;

            case "ShowCascadeDeletes":

                // need these change rules to fire even though nothing in Association has changed
                // so we need to set this early -- requires guarding against recursion.
                bool newShowCascadeDeletes = (bool)e.NewValue;
                if (element.ShowCascadeDeletes != newShowCascadeDeletes)
                {
                    element.ShowCascadeDeletes = newShowCascadeDeletes;
                    foreach (Association association in store.ElementDirectory.FindElements <Association>())
                    {
                        AssociationChangeRules.UpdateDisplayForCascadeDelete(association);
                    }
                }

                redraw = true;
                break;

            case "ShowWarningsInDesigner":
                redraw = true;
                break;

            case "WarnOnMissingDocumentation":
                if (element.ShowWarningsInDesigner)
                {
                    redraw = true;
                }

                ModelRoot.ExecuteValidator?.Invoke();
                break;
            }

            errorMessages = errorMessages.Where(m => m != null).ToList();
            if (errorMessages.Any())
            {
                current.Rollback();
                ErrorDisplay.Show(string.Join("\n", errorMessages));
            }

            if (redraw)
            {
                element.InvalidateDiagrams();
            }
        }
Esempio n. 2
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            ModelRoot   element = (ModelRoot)e.ModelElement;
            Store       store   = element.Store;
            Transaction current = store.TransactionManager.CurrentTransaction;

            if (current.IsSerializing)
            {
                return;
            }

            string errorMessage = null;

            switch (e.DomainProperty.Name)
            {
            case "ConnectionString":
                if (e.NewValue != null)
                {
                    element.ConnectionStringName = null;
                }
                break;

            case "ConnectionStringName":
                if (e.NewValue != null)
                {
                    element.ConnectionString = null;
                }
                break;

            case "Namespace":
                errorMessage = CommonRules.ValidateNamespace((string)e.NewValue, CodeGenerator.IsValidLanguageIndependentIdentifier);
                break;

            case "EntityOutputDirectory":
                if (string.IsNullOrEmpty(element.EnumOutputDirectory))
                {
                    element.EnumOutputDirectory = (string)e.NewValue;
                }
                break;

            case "EnumOutputDirectory":
                if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory))
                {
                    element.EnumOutputDirectory = element.EntityOutputDirectory;
                }
                break;

            case "EntityFrameworkVersion":
                if ((EFVersion)e.NewValue == EFVersion.EFCore)
                {
                    errorMessage = ImposeEFCoreRestrictions(element, store);
                }
                break;

            case "DatabaseSchema":
                if (string.IsNullOrEmpty((string)e.NewValue))
                {
                    element.DatabaseSchema = "dbo";
                }
                break;

            case "FileNameMarker":
                string newFileNameMarker = (string)e.NewValue;
                if (!Regex.Match($"a.{newFileNameMarker}.cs",
                                 @"^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\"";|/]+$").Success)
                {
                    errorMessage = "Invalid value to make part of file name";
                }
                break;

            case "InheritanceStrategy":
                //TODO: EFCore limitation as of 2.0. Review for each new release.
                if (element.EntityFrameworkVersion == EFVersion.EFCore && (CodeStrategy)e.NewValue != CodeStrategy.TablePerHierarchy)
                {
                    element.InheritanceStrategy = CodeStrategy.TablePerHierarchy;
                }
                break;

            case "ShowCascadeDeletes":
                // need these change rules to fire even though nothing in Association has changed
                // so we need to set this early -- requires guarding against recursion.
                bool newShowCascadeDeletes = (bool)e.NewValue;
                if (element.ShowCascadeDeletes != newShowCascadeDeletes)
                {
                    element.ShowCascadeDeletes = newShowCascadeDeletes;
                    foreach (Association association in store.ElementDirectory.FindElements <Association>())
                    {
                        AssociationChangeRules.UpdateDisplayForCascadeDelete(association);
                    }
                }
                break;
            }

            if (errorMessage != null)
            {
                current.Rollback();
                MessageBox.Show(errorMessage);
            }
        }