Answered Different behaviors between first time opening and 2nd time opening of a Dsl

  • Wednesday, December 07, 2011 11:30 AM
     
     

    Hi,

    Here is my problem:

    I have a Shape (Generates Double derived set to true) for which I have Associated properties using AssociateValueWith in InitializeResources.

    The first time I open my Dsl, I see my breakpoint in InitializeResources Hit and everything works as expected. The shapes update when the properties change.

    If I close My DSL and reopen it (a second time) or if I open another (second) Dsl, I don't have the link between my properties and the Shape working any more in the second Dsl (but still OK in the first one). Only the first opened Dsl in a session is working correctly.

    What should I do to have the same behavior ?

    The second time I open my Dsl, it seems that the Dsl has lost the Associated Properties Information somehow...

    Thanks for your help,


    Alex.

    • Edited by Nietzsche61 Sunday, December 11, 2011 11:03 AM
    •  

All Replies

  • Friday, December 09, 2011 6:00 PM
    Owner
     
     

    InitializeResources is only called once per session even though it is an instance method which is why your breakpoint isn't being hit the second time.

    Have a look at the calls to AssociateValueWith in the generated code; that might give some ideas about what might be causing the different behaviour in your custom code.

    Regards,

    Duncan

  • Saturday, December 10, 2011 5:55 AM
     
      Has Code

    Thanks Duncan,

    I can't find what is causing this behaviour. My code in my Shape's InitializeResources is straightforward and looks like the calls to AssociateValueWith made in the generated code :

            protected override void InitializeResources(StyleSet classStyleSet)
            {
                base.InitializeResources(classStyleSet);
                // Add other properties here.
                AssociatedPropertyInfo isLinkInfo = new AssociatedPropertyInfo(ModelTable.IsLinkDomainPropertyId);
                AssociateValueWith(this.Store, isLinkInfo);
                AssociatedPropertyInfo isDirtyInfo = new AssociatedPropertyInfo(ModelTable.IsDirtyDomainPropertyId);
                AssociateValueWith(this.Store, isDirtyInfo);
            }
    
    

    IsLink and IsDirty are 2 normal properties inherited from base abstract classes.

    My feeling is that it is a problem with events handling, because stepping through my code I don't understand exactly when the call to OnAssociatedPropertyChanged is made. I have a bunch of Rules running (ChangeRule, AddRule, DeletingRule) with these properties at the same time. Can it be the reason of this problem ?

    Thanks again for your inputs.

    Regards,


    Alex.
  • Saturday, December 10, 2011 7:28 PM
     
     

    Hi Nietzsche61,

    could you try to open different DSLs at the same time, then close some of them again, and finally check whether everything is still working in one of the DSLs you left opened? I have the suspicion that there is the chance of a strange error to occur when a custom editor window / DSL is closed (maybe a race condition?).

    In my case it is the "DSL explorer" window that stops working correctly; as long as I do not close any DSL everything works fine, but after I have closed some of them I get an error if I try to copy a model element. This error is caught by the IDE and an error message is shown, but I was able to further trace this error by enabling Visual Studio to break on every exception, which showed that this error occurs in one of the Modeling SDK .dlls and none of my handcraftet code is touched. Unfortunately I'm not at my development machine at the moment, so I cant show exact messages or the stack trace, but I'll catch up on this monday.

    It might be that my issue is completely unrelated to yours. However, if you could reproduce your problem without "reopen" the DSL but just closing another one, this could corroborate my suspicion that a bug in the Modeling SDK is responsible for my issue. If so, it might be possible to avoid the problem by re-initializing the dsl package after a dsl is closed (I'll also try this on monday), which could be a solution for your problem as well.

    Cheers!





    • Edited by TheFish1 Saturday, December 10, 2011 7:31 PM
    •  
  • Sunday, December 11, 2011 10:58 AM
     
     

    Hi TheFish1,

    Thanks for your inputs. I made a test and in my case, it seems only the first opened Dsl is behaving as expected. If I open a second one, I don't see the shapes updating as the model changes. So it seems, after all, that it has nothing to do with opening and re-opening the Dsl, but rather with opening a second Dsl, though closing and re-opening the same Dsl brings the same result... So it seems my problem isn't related to yours.

    I'll update this thread accordingly.

    Hopefully we might be able to narrow the problem down...

    Cheers,


    Alex.
  • Monday, December 12, 2011 9:26 AM
     
     

    Hi Alex,

    thanks for trying out. I started another thread since our problems does not seem to be related. Everything seems to be somewhat complicated to solve :(

    Maybe you've got some exceptions that are "hidden" by Visual Studio as well. You could try to get some more information by navigating to "Debugging"->"Exceptions" in your development IDE and enabling to break on certain Common Language Runtime exception (e.g. System.NullReferenceException etc.).

    Cheers,

    Till

  • Friday, December 30, 2011 6:44 AM
     
      Has Code

    Hi,

    I had time to do some more tests on this issue.

    After associating the properties with the shape in InitializeResources, I did the following in OnAssociatedPropertyChanged :

     

            protected override void OnAssociatedPropertyChanged(PropertyChangedEventArgs e)
            {
                base.OnAssociatedPropertyChanged(e);
                // Can be called for any property change. Therefore,
                // Verify that this is the property we're interested in:
                if (!this.Store.InUndoRedoOrRollback)
                {
                    switch (e.PropertyName)
                    {
                        case "IsDirty":
                            if (!(this.ModelElement as ModelTable).IsVirtual)
                            {
                                if ((bool)e.NewValue == true)
                                {
                                    using (Transaction t = this.Store.TransactionManager.BeginTransaction("Set TableShape Dirty"))
                                    {
                                        this.FillColor = Color.OrangeRed;
                                        this.Invalidate();
                                        t.Commit();
                                    }
                                }
                                else
                                {
                                    using (Transaction t = this.Store.TransactionManager.BeginTransaction("Set TableShape Clean"))
                                    {
                                        this.FillColor = Color.LightSteelBlue;
                                        this.Invalidate();
                                        t.Commit();
                                    }
                                }
                            }
                            break;
                        case "IsLink":
                            if ((bool)e.NewValue == true)
                                this.Hide();
                            else
                                this.Show();
                            break;
                        default:
                            break;
                    }
                }
            }

     

    The code in OnAsssociatedPropertyChanged is hit only once at the first opening of the model (because I believe in this case, the model raises events). So my breakpoint in this code is hit only when the first diagram is opened. If I close the diagram and re-open it, it seems no events are fired and the breakpoint isn't hit.

    So is there a way to have a consistent behaviour, so that OnAsssociatedPropertyChanged runs each time a diagram is opened ? Maybe by adding some code in a place like LoadView() ?

     

    Thanks for your help,

     

    Cheers,


    Alex.
  • Thursday, April 19, 2012 10:22 AM
    Owner
     
     

    Alex, have you found a solution to this problem?

    Duncan

  • Thursday, April 19, 2012 2:45 PM
     
     Answered Has Code

    Hello Duncan,

    I didn't really solve this problem, but there is a simple workaround, it is just to do the changes not in OnAssociatedPropertyChanged, but in a custom ChangeRule.

    The code would look like this :

        [RuleOn(typeof(MyShape))]
        public sealed class MyShapeChangeRule : ChangeRule
        {
            public override void OnChanged(ElementPropertyChangedEventArgs e)
            {
                MyShape shape = e.ModelElement as MyShape;
    
                MyElement element = shape.ModelElement as MyElement;
    
                if (element != null && element.IsDirty)
                {
                    shape.Color = Color.Red;
                }
            }
        }
    

    Cheers,


    Alex.