I am working on a large Silverlight application that uses duplex Net.TCP to work with WCF content. I am in the process of moving this application from the MVC approach to MVVM. However, I'm struggling to implement my ViewModels. We use WCF proxies for our model, which is quite complicated, including dozens of classes, many collections, and many many-to-many relationships. For example, a User can belong to many rooms, a room can have many users, a User can have many SharedFiles, and each SharedFile can be shared with any room of which the User is a part. That kind of thing.
In addition, since we use WCF in full duplex mode, changes to the model can be triggered either by the end user or by the WCF service on the internal server. In other words, the model we use is several orders of magnitude more complicated than the typical “Model” that you see presented in any of the various MVVM articles / articles / blog posts. And what is where the problem arises because keeping the ViewModel layer in sync with the base level of the model becomes a bit complicated.
This is a typical problem. The new "User" joins the "Room", so WCF services trigger a "SessionAdded" notification to all other users in the room. The SessionAdded notification carries a Session object that has an associated room and an associated user object. This Room object, which is deserialized from the WCF service, is basically the same as the Room object on the local client and probably has most of the same data, but of course it doesn’t have the same data and at least some of the data (for example, his collection of whiteboards) is certainly erroneous. Therefore, we need to somehow take this input data and combine them into our existing model.And then we need to create ViewModels on top of each of the new objects and / or update the existing ViewModels with new objects and / or their data.
, ViewModels WCF , . , SynchronizedObservableCollection ( ), () Room.Sessions ObservableCollection SessionViewModels RoomViewModel.SessionViewModels. ViewModelFactory, , , , SessionViewModel, , , Session . ( , viewmodel-first, , , ViewModel, WCF.)
. . . . , . , , , , 20- CollectionChanged, , , , .
, , , , . , :
(1) - , , . , , . Entity Framework, myRoom.Users.Add(myUser) myUser.Room = myRoom, , . ( , , - - , .)
(2) - Truss Obtics, . , , , .
... ? , .