How to use CSLA FieldDataManager to track individual property IsDirty status? - csla

In a WinForms application I want to track the IsDirty status of a specific property (besides the IsDirty status of the business object. I found some references to Csla.Core.FieldManager.FieldDataManager being able to do this via its IsFieldDirty method, but I can not find an example.
In Visual Studio Intellisense does not show which parameters are needed in the FieldDataManager's constructor. I just get errors that there is no constructor with x arguments (tested with 0 up to 4 arguments).
FieldDataManager isn't mentioned in the CSLA books.
How can I use FieldDataManager to track the IsDirty status of a property?
Is there another way to do it?
Regards,
George

Related

Does UI5 Remember's previous entity

I am building simple crud for an entity. Initial state is read on particular entity(key) using view>form.bindElement('/entity(key)').
when I click on new button I clear the form and when the cancel button is clicked during the new/create process(without performing the save), how to go back to the previous entity. Is there some place ui5 stores, the previous entity or should I have some variable and assign it to the controller.previousEntity = oldsPath?
what are the different members in the oModel,it start with
a(aBindings)
b(bUseBatch)
m(mContexts)
o(oHeaders)
p(pCallAsync)
s(sPathUrl).
Is there a naming convention in these?
From what I can see, there are following things you need to notice and work upon.
Its generally not a good idea if you use the same form to display and to create/update also. A simpler approach would be to
use a new popover to show the form for create and in that case, the view binding would not be changed when you cancel the operation.
However, if you still want to use the same form, yes you would have to bind the view/form again on cancel operation. You can have a variable declared in the Component.js to store the path for you. In UI5, the model captures the current state to ensure the back the binding concept by default.
You can check all properties and their definitions here: oData Model
Yes, there is a naming convention followed here.
a - Array, s-String, b- Boolean etc.
Read more about Hungarian notations for naming conventions
The previous entity is still there in the cache (ODataModel.oData), but you'll need to re-bind it. For that purpose, as you have written, you'll need to store the path to the entity yourself. Once you bind the control, I don't think the previous binding context is stored somewhere (why should it).

Colliding aspects in postsharp

I am using the PostSharp solution for INotifyPropertyChanged by decorating my business classes with the [NotifyPropertyChanged] attribute.
All works fine.
Now I wrote a custom aspect that handles property changes so that I get some custom flags set when some special properties change. This aspects is named [HandlePropertyChanged] and works when used alone.
Now I try to use both aspects in combination. As I read on the PostSharp page I can manually order them to ensure a fixed order by using
[NotifyPropertyChanged(AspectPriority = 0)]
[HandlePropertyChanged(AspectPriority = 1)]
In this case, I can build my solution, but because "NotifyPropertyChanged" runs before "HandlePropertyChanged", the changes on my properties are already done and the custom logic does not run correctly.
If I try this
[HandlePropertyChanged(AspectPriority = 0)]
[NotifyPropertyChanged(AspectPriority = 1)]
my build fails with the error at the bottm of the text (see below).
Best would be to simply do what NotifyPropertyChanged does in my custom aspect and forget about the PostSharp aspect
Is this possible?
0: Error C:\Source\WAVE\WAVE.Data.Contracts\Entities\Base\EntityBase.cs (17,16) PS0115: Conflicting aspects on "TopMotive.WAVE.Data.Contracts.Entities.Base.EntityBase`1": according to aspect dependencies, transformation "Instantiation of aspect PostSharp.Patterns.Model.NotifyPropertyChangedAttribute" should be located both before and after transformation "Instantiates binding collection for field "PostSharp.Patterns.Model.NotifyPropertyChangedAttribute/LocationBindings".".
This bug is fixed in PostSharp 5.0.52 and PostSharp 6.0.16 RC.
Try superior and free alternative: Stepen Cleary's Calculated Properties.
https://github.com/StephenCleary/CalculatedProperties/blob/master/README.md
I used both in production and found it to be far better than PostSharp's aspect.
Also from PostSharp docs:
"If a property getter calls a virtual method from its class or a delegate, or references a property of another object (without using canonical form this.field.Property), PostSharp will generate an error because it cannot resolve such a dependency at build time. The same limitations apply when your property getter contains complex data flows, such as loops, or calls to methods (except property getters) of other classes.
When this happens, you can either refactor your code so that it can be automatically analyzed by PostSharp, or you can take over the responsibility for analyzing the code"
None of those limitations apply to Calculated Properties. It can do loops, virtual methods, LINQ to objects, basically any runtime dependencies that you can imagine doesn't matter how indirect. Dependency graph rewires itself at runtime and just works without any ceremony. They are also fast.

Validating the Workflow in Design Time

At the beginning, let me confess that I am totally new to Workflow Foundation. I am trying to write one custom activity, let's say we call it GoTo. This activity has a property called TargetActivityName (of type string). The TargetActivityName specifies the name (or DisplayName) of another activity present in the workflow. Now, I need to validate that the activity name is valid, that is, whenever the someone designs a workflow with the GoTo activity and specifies the TargetActivityName, the workflow should validate that an activity of that name is present.
Any ways to achieve this? I am not rehosting it, just using Visual Studio.
Thanks,
Jeevan
If you need all the activities present in a assembly you can check
C#: List All Classes in Assembly
and then use that list to get compare your string with fullName.

What is the difference between Entity.GetAttributeValue<T>(name) and Entity[name] in Dynamics CRM?

When coding against the CRM SDK using late binding what is the difference between accessing attributes using the GetAttributeValue method and accessing the attributes directly on the Entity object?
I am still very new to .NET and c# so if it is a simple language/platform understanding issue then apologies but maybe that's why I can't find much on the difference.
entity["myattributename"] will throw an exception if you attempt to access an attribute that is not in the attribute collection of the entity. It will also return it as an object.
entity.GetAttributeValue<T> will return the default value of the type if not found, and will not throw an exception if it isn't in the attributes collection of the entity.
The entity.GetAttributeValue<T> will return an IEnumerable object which can be used in LINQ expressions. This may greatly speed-up development time and reduce lines of code logic. Based on Daryl's response (good explaination here: ).

Does Core Data automatically validate new values when they are set?

In this question, someone asked how to write a validation method for Core Data. I did that, and it looks cool. But one thing doesn't happen: The validation. I can easily set any "bad" value and this method doesn't get called automatically. What's the concept behind this? Must I always first call the validation method before setting any value? So would I write setter methods which call the appropriate validation method first?
And if yes, what's the point of following a strict convention in how to write the validation method signature? I guess there's also some automatic way of validation, then. How to activate this?
Validation is not "automatic" especially on iOS. On the desktop you will have the UI elements handling the call to validation. On iOS you should be calling validateValue:forKey:error: with the appropriate key and dealing with the error should there be one. The reason for this is the lack of a standard error display on iOS and the overhead of validating all values.
Note this comment in the documentation:
If you do implement custom validation methods, you should typically not invoke them directly. Instead you should call validateValue:forKey:error: with the appropriate key. This ensures that any constraints defined in the managed object model are also applied.