I am currently working on designing a web application that will be built with MVC4.
The gist of the system is that there is a main view that will show a list of records. Records will be added to the grid as they are generated. The user can open a record in an "edit" type view.
One of the requirements is that if one user has a record open in the "edit" view and another user tries to open the same record the second user will be notified that the first user is currently working on that record.
I have been asked to avoid any kind of locking mechanism. They just want to be notified that someone else has it open.
Is something like this possible? I have been racking my brain but I am at a loss.
You should implement it using optimistic locking (actually, no locking... see the link to learn more about this approach) or last to save the record wins.
In the other hand, I believe you should implement that notification the same way as you would do if it was an actual lock, but without locking.
When user A, B, C, D, N starts some record edition, your system should be aware about this and store some temp global state with identifiers of users editing the so-called record. Once you store this data, everyone should be notified in real-time that someone has started to edit that record (f.e. your view might show user names of users being editing the record).
How you would notify everyone about this and in real-time? The answer is SignalR, which is an abstraction over WebSockets and other protocols/approaches to real-time Web development. Check this getting started with SignalR 2 article if you want to learn more about how you would implement SignalR in a real-world project.
Related
I'm a beginner with ASP.NET and webapplications in general.
For a project I have to interact with an enginnering software to read some data, for this I have to to use a ASP.NET project based on the .Net Framework 4.8.
For now I called these functions with buttons and displayed the data in gridviews. The problem is I want to show the data on all clients and the data should still be there when I refresh the page on one client.
To load some data in the gridview I tested it by using a function like this.
Load data to datagrid
The problem is I can't see these changes on other clients.
Is there a way to implement this?
Well, running some in-memmory code for one user of course will not work for other users. You probably would be best to write a seperate console application, place it on the server, and then say schedule it to run ever 5 minuites or whatever. That console or desktop program would thus then write out the data to a database table. Now, any and all web pages (and users) can now have a grid display that quieres against that database.
The other possbile (if for some strange reason you wanted to avoid a database to persist and store this information?
You could consider using signalR. It is complex, but allows you to push (send) out information to all web clients connected to your system. This involves some rather fancy foot work, and does require your web page to include some JavaScript. As a result, the simple database idea is less work, simple, and does not require many hand-stands.
but, signalR is what is used for say pushing out information to each client browser, you can get started here, since this is a vast topic well beyond that of a simple Q & A on SO.
https://learn.microsoft.com/en-us/aspnet/signalr/overview/getting-started/
I am working on an application where users in a local network are notified when a "record" from the database changes. So if person "A" changes Record 1 and person "B" has Record 1 in their view, person "B" will be notified that Record 1 has changed.
We are currently using what is called a "duplex" service to send these notifications through a WCF service. The service is rather slow and ideally we would like to remove it. Are there any ways to keep data in real-time (or close to it) for users, when another user has updated the database?
If you are just looking to replace your notification service my suggestion would be to use SignalR to keep your clients synchronized with your DB.
I had a similar problem once and ended up crossing over to a NoSql cloud solution called Firebase with the Firesharp library. Firebase - Features, Firesharp.
It is blindingly fast and actually really easy to use. So if your application is still quite small and the business risk of migrating to a NoSql setup is small it might be a worthwhile solution.
How long they keep the record in view?
What is the mechanism that is checking if the value changed?
what kind of client application are you using?
You could create an async method that is validating the status of the item the user is using against a nodejs server that will be querying the db, for that particular record, reply with the value and the async method can validate if the current value is different from the one from the DB and then it can inform the user or update the record.
Those have small footprint and should run more efficiently.
how to update the gridview automatically without using timer control when there is a change in database table.
please let me comment if anyone can't get my question .
thanks in advance
In order for the application to detect a change in the database it must either monitor the relevant tables or somehow be notified of changes in the database by an outside source. Using a timer to poll the database for changes is one option. Having another program perform that task and then notify your application is another way to do it. Some databases, like Firebird, has the ability to post events that your application can listen to.
In my experience having the database post events is by far the easiest solution but it of course requires you to use a database with that capability. You should probably also consider your design. Why do you need the database to notify the GUI? Is it really necessary or just an easy way to have the GUI updated? Take some time to think about what roles the different layers in an application should fill before deciding on this strategy.
That being said sometimes having the database instigate GUI changes or other actions is perfectly acceptable. If the database is shared amongst multiple users and each user needs to be notified of actions taken by the other users it could be a good solution. Personally I'd try to find other ways of communicating before settling on the data driven approach but in some cases ther's really not that many other viable options.
actually when the application needs it queries the database but in this situation the database needs to cause events.though the database can cause events using triggers but that has some limitations and the scope of the change taking place is limited within the database.to show a change in the application(here updation of gridview) can only take place if a call is made from the application only.this can be done using timer controls from the application .but without sending a call to the database from the application its impossible
You can use windows service that will run offline from the application...
The service will query the db and will update file in the system when there is a change...
In the application you can use cahce dependency on the file.
I'm not 100% sure, but I think you could look into Windows Communication Foundation and some of the examples they they have.
I'm starting a new project which will need to allow edits on forms but to keep track of the original and who did what edits and where (p.s. I wouldn't be able to use any extra software other than visual studio 2010 and Microsoft SQL Server Management Studio so no point suggesting any addition software, this is purely a code or table design minded question) .
I'm a perfectionist and I know some possible routes to achieve this will prob change my overall project design but I'm not sure if the ideas I have on how to implement this are best so I like to hear others opinions on below ideas and your own ideas on the quickest most effective way to implement above problem.
Ideas:-
I'd set it up so that when they edit it would display all existing ranges of data from textboxs to radiobuttons and even some drop downs and the value which they had and then on submit it would copy the original record via the Id into a achieve table, create the new record and then delete the original from the main table.
I figure some way to add X amount of comments to any section of the form and each would have a timestamp and username from win auth recorded at the bottom.
Edit - My intention was to get a variety of solutions but I suppose once I'm able to start on the editing section of this project if the single solution given works then I'll mark that correct.
I'm not sure whether this is what you are looking for but I have the need to log all changes to data (for audit reasons) and the way I have implemented this is to create a new 'History' table in SQL Server that will store the record ID, username of person who changed it, whether they added/modified/deleted something and when this happened etc.
In the code to add/edit/delete things in my database I always call ObjectContext.SaveChanges (I use Entity Framework 4) so what I have implemented is an extension to this method that uses various parts of the ObjectStateManager to get the information required about the entity that has changed and inserts the details into the History table. You then just need to query this table in the database to display details of what has changed.
I have some C# form application.I'm using some central data base which is developed on SQLServer2005.According to my application there are several user levels such as admin,reception,...
problem
There is a requirement that if someone has changed the database(eg: add new record/delete record) that will be noticed admin and higher level of user.
What will be the way that should I follow to achieve this task!
Thank in advance!
Audit trial could be the solution for your question. It basically means, for your data-table of concern, include the columns - 'modified_by', modified_date' in addition to 'created_by', 'created_date' columns. So whenever someone edits a record for the first time - 'modified_by' and 'modified_date' columns will be different from 'created_by' and 'created_date' columns.
And in your application, you can develop a screen (or email alert) which is accessible only for admin or higher level users, to display the modified records in reverse chronological order.
Note: The above audit trial method, only maintains the latest changes in database. If you want to maintain the history of edits, then you can establish the same by maintaining the audit trial information in a separate dedicated set of data-tables.