SolveIt

I am using Designer Rehosting code posted by Vihang Dalal.
I am also using DynamicPropertiesActivity from Ghenadie's blog.

I create a workflow with DynamicPropertyActivity as one of the activities.
Added 'strTest' to DynamicProperties collection.
In order to be able to use this attribute in the rest of the workflow to bing to other activities, I believe I have to bind 'strTest' to a new member. So created a new Property member say dynProp_strTest. I can now use dynProp_strTest to bind to other activities. So far so good.
The issue comes up when I try to save this workflow and then reopen it again in Designer.

I can no longer see the new member 'dynProp_strTest' that I created. I understand it is getting lost during Save, but do not exactly know how and where.
Here is the Save code (As far as I remember I am using the same code posted by Vihang and have not made any modifications to this method).

Highly appreciate any pointers to help resolve the issue.

public String Save(string filePath)
{
if (this.loader != null)
{
if (filePath != null && filePath != string.Empty)
this.loader.Xoml = filePath;
this.loader.Flush();
}

// Referesh the code compile unit every time the file is saved
TypeProvider typeProvider = (TypeProvider)GetService(typeof(ITypeProvider));
typeProvider.RemoveCodeCompileUnit(this.loader.XamlCodeCompileUnit);
this.loader.XamlCodeCompileUnit = new CodeCompileUnit();
this.loader.XamlCodeCompileUnit.Namespaces.Add(Helpers.GenerateCodeFromXomlDocument(Helpers.GetRootActivity(filePath != null filePath : this.loader.Xoml), this, ref this.nameSpace, ref this.typeName));
typeProvider.AddCodeCompileUnit(this.loader.XamlCodeCompileUnit);
// Returning the file name
if (filePath != null && filePath != string.Empty)
return filePath;
else
return this.loader.Xoml;

}





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

SolveIt

I have been looking more into this and I now think the issue is with the way GenerateCodeFromCompileUnit in PerformFlush method of Loader.cs is implemented.
But I am still unable to figure out the exact issue.

When the workflow is open and I re-bind the dynamic properties to new members, the .cs file corresponding to the workflow gets correctly updated with the created new dependency property members. But when I close the file and open it again, the PerformFlush method basically wipes out the newly added dependency properties corresponding to the dynamic property.

Has anyone got the dynamic properties and the designer to work together successfully.
Really appreciate any pointers in the direction of resolving this issue.

Please let me know if there is any other information that you might require if I was not clear in description of the problem.

Thanks a lot in advance.





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

SolveIt

Any clues please!!





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

SolveIt

I have not recieved any replies on this so far.
Has no-one faced this problem yet OR Is the problem description unclear

Highly appreciate if I can recieve any responses or further queries.
Thanks a lot in advance.





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Tom Lake - MSFT

The underlying problem has nothing to do with Ghenadie's DynamicPropertiesActivity. It is because the Designer Rehosting sample does not use the previously saved .cs file when the workflow is reloaded. This is because there are no .NET library functions to parse the .cs file and turning it into a CodeCompileUnit, and it would be way to much work for a sample. The last four lines for LoadWorkflow create the default empty class when any workflow is loaded:

// Add the code compile unit for the xaml file

TypeProvider typeProvider = (TypeProvider)GetService(typeof(ITypeProvider));

this.loader.XamlCodeCompileUnit = new CodeCompileUnit();

this.loader.XamlCodeCompileUnit.Namespaces.Add(Helpers.GenerateCodeFromXomlDocument(Helpers.GetRootActivity(xoml), this, ref this.nameSpace, ref this.typeName));

typeProvider.AddCodeCompileUnit(this.loader.XamlCodeCompileUnit);






Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Dudley

This is slightly alarming - don't you think

It sounds like the only way to load your .cs file back in to a program hosting the workflow design component would be to build your own c sharp parser!

I'm just wondering how useful the workflow designer component is going to be if it has a fundamental flaw like this





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

SolveIt

Is there anyway to circumvent this problem in Designer Hosting app
Will be grateful for any suggestions to overcome this problem.

Thanks in advance.





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Tom Lake - MSFT

Two options you could try are writing a CSharp parser that will read the .cs file in and give back the CodeCompileUnit or have logic that would parse the xoml file to figure out which variable / properties had been added and re-add them. There is no easy solution for this. You should be able to do the following:

// Add the code compile unit for the xaml file

string codeFilePath = Path.ChangeExtension(xoml, "cs");

CodeCompileUnit codeCompileUnit = null;

TypeProvider typeProvider = (TypeProvider)GetService(typeof(ITypeProvider));

if (File.Exists(codeFilePath))

{

CSharpCodeProvider csharpProvider = new CSharpCodeProvider();

codeCompileUnit = csharpProvider.Parse(File.OpenText(codeFilePath));

}

else

{

codeCompileUnit = new CodeCompileUnit();

codeCompileUnit.Namespaces.Add(Helpers.GenerateCodeFromXomlDocument(Helpers.GetRootActivity(xoml), this, ref this.nameSpace, ref this.typeName));

}

this.loader.XamlCodeCompileUnit = codeCompileUnit;

typeProvider.AddCodeCompileUnit(this.loader.XamlCodeCompileUnit);

But the Parse method is not implemented in the CSharpCodeProvider.






Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

SolveIt

Based on your suggestion above, I have implemented the Parse method which will return the codeCompileUnit and replaced the last four lines of code in LoadWorkflow with the lines suggested by you.
But I wonder if this is sufficient.
In WorkflowLoader constructor the codeBesideccu variable is being built with hardcoded values and this is what is used in PerformFlush method in the line
generator.GenerateCodeFromCompileUnit(this.CodeBesideCCU, writer, options);
Now this will flush out whatever was there in .cs file and fill it in with only the codeBesideccu content which is hardcoded and populated in the workflowLoader constructor.
This I suspect removes all contents of the .cs file and retains just the skeleton. So I am back to square one.

So the code snippet that you suggested with Parse implemented alone may not be a solution to the problem I am facing. Could you please help me proceed further on this.

Thanks a ton in advance.





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Tom Lake - MSFT

Please post or send me the code your are using. this.CodeBesideCCU should be the code compile unit that you put into the loader when you opened the workflow.




Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

SolveIt

Thanks for the quick response.
I have just mailed you the relevant files.
Please let me know if you would need any other information or have any more questions regarding my approach.

Thanks a ton.





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Tom Lake - MSFT

After looking at the code it looks like the parser you are using is not doing its job correctly. It seems to be parsing variables correctly, but not properties.




Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

NMM

I faced the same problem.. pls when you reach to a solution can you post it step-by-step to solve this problem... thanks



Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Edmundas

Regarding CodeCompileUnit issue:

I guess there is one more option besides the two suggested above on how to create CodeCompileUnit from *.cs (CSharp parser) or *.xoml file. What if you modify Designer Rehosting sample to save not only *.cs file, but also save binary serialized CodeCompileUnit as well In that case when loading *.cs file, you would also be able to use appropriate deserialized CodeCompileUnit.

Edmundas





Re: Windows Workflow Foundation Bound Dynamic properties not retained after save - Using Vihang Dalal's Designer Rehosting

Birth of presence

SolveIt!! I am facing the same problem. I hope you would have good intuition into the problem now.Please tell me how did you change the sample to keep the existing code intact. Please help.