How to Prevent Concurrent Data Collisions


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
If two users modify data at the same time ( e.g. user 1 Reads data into a BO, Changes It, Users 2 reads same Data into a BO, User 1 then saves the BO, and then User 2 Attempts to Save the same data), a message comes up:

Data Collision... Another user made changes to the same record..choose the changes to accept  (MyValue or Server Value)

Now, this is fine most of the time (say for Master File Changes)

However, If say an Invocie is being modified in this way, I NEVER want the second user to have their changes accepted. In this case, I would prefer if an error was raised and a notification to this effect ended up in the BrokenRules Collection

In my BusinessObject, I would like to do something like:

if (DataCollision = true) {this.AddBrokenRule("XXX", "Another User has just amended the transaction ");}

and I do not want the user to have the option to choose what is to be done.

 

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Ger.

What I do is to handle collision myself, then I have control to do whatever I want. To accomplish this, on my Base BO, I handle the ConcurrencyException and then call my own method to take care of it:

    Private Sub _PFNBaseBO_ConcurrencyException(ByVal e As MicroFour.StrataFrame.Data.ConcurrencyExceptionEventArgs) Handles Me.ConcurrencyException
        '-- handle concurrency with our own Collision form
        Me.HandleConcurrency(e)
    End Sub


Then, I use my own dialog to show collisions, for the fields I want, formatted in the way I want. You will find all collisions in the e.Collision Concurrency Exception Event Argument.
Also, I guess you can just set the BO CollisionNotificationType at form level to ThrowException, which will have all information about what happened in the collision and you can deal with that.
There are some good posts on collisions in the Forum, here are some links to get you started:

http://forum.strataframe.net/FindPost27465.aspx
http://forum.strataframe.net/FindPost15123.aspx
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Ivan. Thanks for replying. I  tam taking your  advice and Put some code in to my Base Class for BO as follows:

protected override void ConcurrencyException(MicroFour.StrataFrame.Data.ConcurrencyExceptionEventArgs e)        

//-- Hhandle concurrency with our own Collision i.e. Want to add an error to Errors Collection

{

   this.AddBrokenRule(this.PrimaryKeyField, "Another user has amended this item at the same time");

}

However, above gives a Compile error (...BusinessLyer.ConcurrencyException is not a function)

I must have syntax wrong ??

Also, other than just setting the AutoHandleCollisions on the form to false, it there amything else I neeed to do. If there is a Concurrency problem, all I want to do is add this to the BrokenRules collection and not show any other form, but definitiely NOT to save the data. Presumably if I have added a line to the BrokenRules, the form will NOT be saved


Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Ger.

C# is not my "mother tongue", but I guess it should be something like:

private void YourBaseBO_ConcurrencyException(MicroFour.StrataFrame.Data.ConcurrencyExceptionEventArgs e)
     {
         this.AddBrokenRule(this.PrimaryKeyField, "Another user has amended this item at the same time");
         e.ResaveRecord = False;
     }

The e.ResaveRecord will take care of cancelling the Save.
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Ivan. Thanks for that. I can now get it to compile .

I am still having two issues.

1. Even though I have code to AddbrokenRules, it does not seem to be doing this. If there is a collision, it is not now showing the SF Collision Form and it is not saving (which is what I want) but I want to update the BrokenRule collection so that all errors are seen from the same place

2. In the above, for testing, I was setting the propeties on the Form Instances , rather than on a subclassed form, as I am having difficulty setting a Property on a SubClassed form. I have previosuly  added functionality to other controls successfully , but this is the first time I am trying to add functionality to a subclassed Form. The AutoHandleCollisions = false does not seem to be doing anything.  My Code to subclass the form is:

    public class StandardForm : MicroFour.StrataFrame.UI.Windows.Forms.StandardForm

    {

         private voidInitializeComponent()

        {

           this.SuspendLayout();

           //

           // StandardForm

           //

           this.ClientSize = new System.Drawing.Size(294,274);

           this.Name = "StandardForm";

           this.Load += newSystem.EventHandler(this.StandardForm_Load);

           this.AutoHandleCollisions = false;

           this.ResumeLayout(false);

 

        }

 

        private voidStandardForm_Load(object sender, EventArgs e)

        {

        }

    }


Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
1. Even though I have code to AddbrokenRules, it does not seem to be doing this. If there is a collision, it is not now showing the SF Collision Form and it is not saving (which is what I want) but I want to update the BrokenRule collection so that all errors are seen from the same place


If you let it try resaving, after adding the broken rule, won't it work the way you want?


2. In the above, for testing, I was setting the propeties on the Form Instances , rather than on a subclassed form, as I am having difficulty setting a Property on a SubClassed form. I have previosuly  added functionality to other controls successfully , but this is the first time I am trying to add functionality to a subclassed Form. The AutoHandleCollisions = false does not seem to be doing anything.  My Code to subclass the form is:


Sorry, I am a bit confused on this one. Would you like to produce a small simple sample application of what you want to accomplish? Then it could be easier to follow it.
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Ivan.

I will do up a small project to iluustrate both issues.
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Ivan.

I have attached a Sample Project to illustrate the second problem I am having. Just trying to Subclass a StratatFrame Form and have the AutoHandleCollisions set to False in my SubClass

In the Sample, My Subclass is called MyForm, and I have a line in it with this.AutoHandleCollisions = false

When I run up my Form (Form2, called from Form1) , I have a button whcih displays a messagebox, indicating what the AutoHandleCollisions property is. It is saying True, even though my BaseClass has set it to false. (This may very well be the result of my Inexperience of Subclassing a Form and I may have left out something or not done it the correct way.

(Sample project based on the Customers Tbale in the StartaFrame sample database)
Attachments
TestConcurr1.ZIP (99 views, 97.00 KB)
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Ivan.

Any update on this. (Trying to subclass a and have the AutoHandleCollisions set to False in my SubClass...see attached Sample on laste thread)
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)Strategic Support Team Member (3.6K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Ger.

I tried to have a look at your sample but couldn't find out how to solve your problem. As I told you, I do vb.net and tried to Google how the C# inheritance should behave, but didn't get to a conclusion why yours is not working. In my solutions, my base form is set with AutoHandleCollisions to False and all inherited forms from it also has it like that.

So, I hope someone will jump in and clarify this for you.
Edited 12 Years Ago by Ivan George Borges
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search