Problem editing custom styles

Oct 24, 2012 at 10:56 AM
Edited Oct 24, 2012 at 11:00 AM

Hi,

I created several fill styles programmatically using your recommendations. That's the code I used:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        ...
        this.LinkComponents();
        this.CreateProject();
        this.CreateDiagram();
        ...
    }

    private void CreateProject()
    {
        this.project1.Name = "Test NShape project";
        this.project1.Create();
        this.CreateStyles(); // << must be done after .Create() but before .AddLibrary(<library_using_these_styles>)!
        this.project1.AddLibrary(typeof(MyShapes.ProcessorShape).Assembly, false);
    }

    private void CreateStyles()
    {
        this.CreateSolidFillStyle(Color.LightGreen);
        this.CreateSolidFillStyle(Color.LightGray);
        ... etc ...

        this.project1.Repository.Update(this.project1.Design);
    }

    private void CreateSolidFillStyle(Color color)
    {
        string colorStyleName = "My" + color.Name;
        string fillStyleName = color.Name + " Solid";
		
        if (!this.project1.Design.ColorStyles.Contains(colorStyleName))
            this.project1.Design.AddStyle(new ColorStyle(colorStyleName, color, 0));
        FillStyle fillStyle = new FillStyle(fillStyleName);
        fillStyle.BaseColorStyle = this.project1.Design.ColorStyles[colorStyleName];
        fillStyle.FillMode = FillMode.Solid;
        this.project1.Design.FillStyles.Add(fillStyle, this.project1.Design.CreatePreviewStyle(fillStyle));
    }
}

Everything is OK until I try to modify any of my custom styles in the "Design Editor": it throws the following CachedRepositoryException: "FillStyle 'LightGreen Solid' does not exist in the repository or is already deleted". For example, this exception was thrown when I tried to modify BaseColorStyle property from "MyLightGreen" to "Green".

What am I doing wrong?

Full exception info:

Dataweb.NShape.Advanced.CachedRepositoryException was unhandled by user code
  Message=FillStyle 'LightGreen Solid' does not exist in the repository or is already deleted.
  Source=Dataweb.NShape
  StackTrace:
       in Dataweb.NShape.Advanced.CachedRepository.AssertCanUpdate(IStyle style) in C:\NShape\Source\Core\CachedRepository.cs:line 2811
       in Dataweb.NShape.Advanced.CachedRepository.Update(IStyle style) in C:\NShape\Source\Core\CachedRepository.cs:line 531
       in Dataweb.NShape.Commands.StylePropertySetCommand.UpdateDesignAndRepository(Boolean styleRenamed) in C:\NShape\Source\Core\Command.cs:line 4332
       in Dataweb.NShape.Commands.StylePropertySetCommand.Execute() in C:\NShape\Source\Core\Command.cs:line 4304
       in Dataweb.NShape.Advanced.History.ExecuteAndAddCommand(ICommand command) in C:\NShape\Source\Core\History.cs:line 334
       in Dataweb.NShape.Project.ExecuteCommand(ICommand command) in C:\NShape\Source\Core\Project.cs:line 408
       in Dataweb.NShape.Controllers.PropertyController.CommitSetProperty() in C:\NShape\Source\Core\PropertyController.cs:line 253
       in Dataweb.NShape.Controllers.PropertyController.SetPropertyValue(Object obj, String propertyName, Object oldValue, Object newValue) in C:\NShape\Source\Core\PropertyController.cs:line 164
       in Dataweb.NShape.Advanced.PropertyDescriptorDg.SetValue(Object component, Object value) in C:\NShape\Source\Core\TypeDescriptionProviders.cs:line 652
       in System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.SetPropertyValueCore(Object obj, Object value, Boolean doUndo)
       in System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.SetPropertyValue(Object obj, Object objVal, Boolean reset, String undoText)
 
InnerException:

Coordinator
Oct 24, 2012 at 2:47 PM

The exception says it all: "FillStyle 'LightGreen Solid' does not exist in the repository (...)"

All Repository methods are rather atomic in order to reduce overhead. IRepository.Update(Design) does not insert/deleteany of the styles. You have to add them by calling Repository.Insert(style):

fillStyle.FillMode = FillMode.Solid;
this.project1.Design.AddStyle(fillStyle); project1.Repository.Insert(design, fillStyle);
Oct 24, 2012 at 2:58 PM

Thank You, it works now!