[RESOLVED]Shared Auction Round Object in MVC

Hi,

I’m creating a new auction type MVC application which has the concept of auction round for each participant.

This means each user session will be bidding and updating an instance of a ’round’ class along with any number of other users – i’m trying to find the best way of creating each round instance – I can’t creat each round based on user session because this
will spawn multiple instances in the user session context.

I tried an application level variable but this caused problems as again, its creation was triggered for every user currently in session.

I’m now thinking of creating stubs in the database in anticipation of each round based on a DB trigger perhaps..

Can anyone suggest the best of way of going about this ?

Thanks,

MJ

pnoble

This means each user session will be bidding and updating an instance of a ’round’ class along with any number of other users – i’m trying to find the best way of creating each round instance – I can’t creat each round based on user session because this
will spawn multiple instances in the user session context.

I tried an application level variable but this caused problems as again, its creation was triggered for every user currently in session.

I do not understand. Could you give example for 3 users what needs to be created?

pnoble

I tried an application level variable

You need to use application level variable (or some kind of application scope object). But you may need to store multiple "round" at a given time. So generate a unique id for each round object and store it in the application level.

Application["R1"] = new Round();

Application["R2"] = new Round();

pnoble

its creation was triggered for every user currently in session

As your round object has the user list, write code so that you can only trigger only for those users in the round object

First refer to Prasanna;s reply and think about caching the data in System.Runtime.Cache. and clear the cache on auction complete

The issue here is concurrency – imagine that an auction starts at an absolute point in time so at that point possibly hundreds of user requests get handled at the same time.

In which case I need to ensure that some actions are only executed once at the start of the auction but still triggered by a request from the user.

It’s here I need to be able to say ‘first request will create a round object in database and subsequent requests will be ignored’ - I’ve achieved it partly by implementing something along the lines you suggested but still found that creating the state variable
did not always get picked up by subsequent calls to the same..

It’s not pretty but it works, not quite sure how it will scale yet though.

Thanks,

P Noble  

You are talking about a state machine.  State machines require persistence, either in memory or in a database.   This means most likely you either have to hook into a web-service, or even back-end your database to keep track of your states.  1 or 1000 users
shouldn’t matter because that what a state machine does, it tracks workflow.  

Just remember MVC is stateless, but can be rendered to keep state, but why?  Keep states where they belong!

Hi pnoble,

pnoble

The issue here is concurrency

To deal with the concurrency, you could lock the resource or use Semaphore.

# lock Statement (C# Reference)

http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx

# Semaphore Class

http://msdn.microsoft.com/en-us/library/system.threading.semaphore(v=vs.110).aspx

Best Regards

Starain

If you keep in application, it will be gone when the server gets restarted. IIS kills the idle w3wp process if no requests are processed for 30 minutes. This setting is done in App pool advanced setting.

If you have a database its better to keep the data in dabatabase.

You need to create an Auction Table, when each auction starts you need to create a record in this table, it should have a primary key.

You need to create an another table called AuctionBid, it will have a foreign key relation ship with auction table, In this table you will need to add each user bid against the corresponding auction. when user adds a bid you need to add a record in this
table.

A user might bid more than once for the same auction, you can update the previous User bid for the auction, or you can add new bid.

To find the winning bid for a particular auction you can take the max of bid from AuctionBid

i’m quite surprised why nobody mentioned signalr 

signalr actually has all the functionality you need for this without too much coding.

http://www.asp.net/signalr/overview/getting-started/introduction-to-signalr

Thanks for link on SignalR.  I did a bit of work with ReactiveExtensions (Rx) and the first paragraph of the SinalR reminds me of what RX is all about which is this:  "Push based, rather than Pull based"  The observer pattern incarnate!  I’ll be personally
reading more on SignalR soon…. Thanks again.

I like this suggestion – in fact, I gravitated towards to SignalR right off the bat but, perhaps like others, a sense of nervousness around it’s maturity has kept me away in favour of highly established patterns.

I will look to creating a hub to broadcast the auction throughout it’s lifecycle in parallel with the other suggestions made herein. Thanks, and yes, I like to embellish sentences with elaborate language.

Much appreciate everyone’s input.

PN

Leave a Reply