Beispiel #1
0
        /// <summary>Called by the control's OnDoubleClick()</summary>
        /// <param name="e">A DiagramPointEventArgs that contains event data.</param>
        public override void OnDoubleClick(DiagramPointEventArgs e)
        {
            base.OnDoubleClick(e);

            if (OpenCodeFile != null)
            {
                ModelEnum modelEnum = (ModelEnum)ModelElement;

                if (OpenCodeFile(modelEnum))
                {
                    return;
                }

                if (!modelEnum.GenerateCode)
                {
                    ErrorDisplay.Show(Store, $"{modelEnum.Name} has its GenerateCode property set to false. No file available to open.");

                    return;
                }

                if (ExecCodeGeneration != null && BooleanQuestionDisplay.Show(Store, $"Can't open generated file for {modelEnum.Name}. It may not have been generated yet. Do you want to generate the code now?") == true)
                {
                    ExecCodeGeneration();

                    if (OpenCodeFile(modelEnum))
                    {
                        return;
                    }
                }

                ErrorDisplay.Show(Store, $"Can't open generated file for {modelEnum.Name}");
            }
        }
Beispiel #2
0
 /// <summary>
 ///    Called after the IsOutputDirectoryTracking property changes.
 /// </summary>
 /// <param name="element">The model element that has the property that changed. </param>
 /// <param name="oldValue">The previous value of the property. </param>
 /// <param name="newValue">The new value of the property. </param>
 protected override void OnValueChanged(ModelEnum element, bool oldValue, bool newValue)
 {
     base.OnValueChanged(element, oldValue, newValue);
     if (!element.Store.InUndoRedoOrRollback && newValue)
     {
         DomainPropertyInfo propInfo = element.Store.DomainDataDirectory.GetDomainProperty(OutputDirectoryDomainPropertyId);
         propInfo.NotifyValueChange(element);
     }
 }
Beispiel #3
0
 public AddCodeForm(ModelEnum element) : this()
 {
     lblClassName.Text = element.Name;
     txtCode.Lines     = element.Values.Select(x => x.ToString()).ToArray();
     // ReSharper disable once VirtualMemberCallInConstructor
     Text        = "Add values as code";
     label1.Text = "Enum name";
     label2.Text = "Values";
     txtCode.AutoCompleteCustomSource.AddRange(element.ModelRoot.ValidTypes);
 }
Beispiel #4
0
        /// <summary>Virtual method to process the menu Delete operation</summary>
        protected override void ProcessOnMenuDeleteCommand()
        {
            foreach (EnumShape enumShape in CurrentSelection.OfType <EnumShape>())
            {
                if (enumShape.ModelElement is ModelEnum modelEnum &&
                    ModelEnum.IsUsed(modelEnum) &&
                    BooleanQuestionDisplay.Show($"{modelEnum.FullName} is used as an entity property. Deleting the enumeration will remove those properties. Are you sure?") != true)
                {
                    return;
                }
            }

            base.ProcessOnMenuDeleteCommand();
        }
Beispiel #5
0
        public static IEnumerable <string> GetErrors(ModelEnum element)
        {
            return(new string[0]);

            // for later

            //ModelRoot modelRoot = element.ModelRoot;
            //Store store = modelRoot.Store;
            //List<string> errorMessages = new List<string>();

            //if (modelRoot.EntityFrameworkVersion == EFVersion.EFCore)
            //{

            //}

            //return errorMessages;
        }
Beispiel #6
0
        /// <summary>Virtual method to process the menu Delete operation</summary>
        protected override void ProcessOnMenuDeleteCommand()
        {
            switch (SelectedElement)
            {
            case ModelDiagramData diagramData when BooleanQuestionDisplay.Show($"About to permanently delete diagram named {diagramData.Name} - are you sure?") == true:
            {
                base.ProcessOnMenuDeleteCommand();

                break;
            }

            case ModelEnum modelEnum when !ModelEnum.IsUsed(modelEnum) ||
                BooleanQuestionDisplay.Show($"{modelEnum.FullName} is used as an entity property. Deleting the enumeration will remove those properties. Are you sure?") == true:
            {
                base.ProcessOnMenuDeleteCommand();

                break;
            }
            }
        }
Beispiel #7
0
            /// <summary>Performs the reset operation for the IsOutputDirectoryTracking property for a model element.</summary>
            /// <param name="element">The model element that has the property to reset.</param>
            internal void ResetValue(ModelEnum element)
            {
                object    calculatedValue = null;
                ModelRoot modelRoot       = element.Store.ModelRoot();

                try
                {
                    calculatedValue = modelRoot?.EnumOutputDirectory;
                }
                catch (NullReferenceException) { }
                catch (Exception e)
                {
                    if (CriticalException.IsCriticalException(e))
                    {
                        throw;
                    }
                }

                if (calculatedValue != null && element.OutputDirectory == (string)calculatedValue)
                {
                    element.isOutputDirectoryTrackingPropertyStorage = true;
                }
            }
Beispiel #8
0
        public static void AdjustEFCoreProperties(PropertyDescriptorCollection propertyDescriptors, ModelEnum element)
        {
            //ModelRoot modelRoot = element.ModelRoot;
            //for (int index = 0; index < propertyDescriptors.Count; index++)
            //{
            //   bool shouldRemove = false;
            //   switch (propertyDescriptors[index].Name)
            //   {
            //   }

            //   if (shouldRemove)
            //      propertyDescriptors.Remove(propertyDescriptors[index--]);
            //}
        }
Beispiel #9
0
 /// <summary>
 ///    Method to set IsOutputDirectoryTracking to false so that this instance of this tracking property is not
 ///    storage-based.
 /// </summary>
 /// <param name="element">
 ///    The element on which to reset the property
 ///    value.
 /// </param>
 internal void PreResetValue(ModelEnum element) =>
 // Force the IsOutputDirectoryTracking property to false so that the value
 // of the OutputDirectory property is retrieved from storage.
 element.isOutputDirectoryTrackingPropertyStorage = false;
Beispiel #10
0
 /// <summary>
 ///    Method to set IsNamespaceTracking to false so that this instance of this tracking property is not
 ///    storage-based.
 /// </summary>
 /// <param name="element">
 ///    The element on which to reset the property
 ///    value.
 /// </param>
 internal void PreResetValue(ModelEnum element) =>
 // Force the IsNamespaceTracking property to false so that the value
 // of the Namespace property is retrieved from storage.
 element.isNamespaceTrackingPropertyStorage = false;
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

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

            if (current.IsSerializing)
            {
                return;
            }

            string errorMessage = null;

            switch (e.DomainProperty.Name)
            {
            case "Name":
                string newName = (string)e.NewValue;
                if (current.Name.ToLowerInvariant() == "paste")
                {
                    return;
                }

                if (current.Name.ToLowerInvariant() != "paste" && (string.IsNullOrWhiteSpace(newName) || !CodeGenerator.IsValidLanguageIndependentIdentifier(newName)))
                {
                    errorMessage = "Name must be a valid .NET identifier";
                }
                else if (store.ElementDirectory
                         .AllElements
                         .OfType <ModelClass>()
                         .Any(x => x.Name == newName))
                {
                    errorMessage = "Enum name already in use by a class";
                }
                else if (store.ElementDirectory
                         .AllElements
                         .OfType <ModelEnum>()
                         .Except(new[] { element })
                         .Any(x => x.Name == newName))
                {
                    errorMessage = "Enum name already in use by another enum";
                }

                break;

            case "Namespace":
                string newNamespace = (string)e.NewValue;
                if (current.Name.ToLowerInvariant() != "paste")
                {
                    errorMessage = CommonRules.ValidateNamespace(newNamespace, CodeGenerator.IsValidLanguageIndependentIdentifier);
                }
                break;

            case "IsFlags":
                bool isFlags = (bool)e.NewValue;
                element.SetFlagValues();

                break;
            }

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