Пример #1
0
 public void SetModifiedFlag()
 {
     if (!ReadOnly)
     {
         var val = day.IsModified(TrainingDayPageContext.Day);
         IsModified = val;
         NotifyOfPropertyChange(() => IsModified);
     }
 }
Пример #2
0
        public void MergeNew(TrainingDayDTO fromServer, ApplicationState appState, bool updateLocalCache, Func <ModificationType, bool> useServerQuestion)
        {
            Guid?customerId = appState.TrainingDay.TrainingDay.CustomerId;
            var  holder     = state[new CacheKey()
                                    {
                                        CustomerId = customerId, ProfileId = myProfileId
                                    }];

            if (fromServer != null)
            {
                if (fromServer.IsModified(appState.TrainingDay.TrainingDay))
                {
                    foreach (var serverEntry in fromServer.Objects)
                    {
                        var localEntry = appState.TrainingDay.TrainingDay.Objects.Where(x => x.GlobalId == serverEntry.GlobalId).SingleOrDefault();
                        if (localEntry == null)
                        {
                            //if (useServerQuestion(ModificationType.EntryOnServerButNotOnClient))
                            //{
                            //    appState.TrainingDay.TrainingDay.Objects.Add(serverEntry.Copy());
                            //}
                            appState.TrainingDay.TrainingDay.Objects.Add(serverEntry.Copy());
                            appState.TrainingDay.TrainingDay.GlobalId = fromServer.GlobalId;
                            //todo:here we "create" two entries so mabye we should inform the user about this
                        }
                        else if (serverEntry.IsModified(localEntry))
                        {
                            //the same entry has been modified
                            if (useServerQuestion(ModificationType.EntryModified))
                            {
                                //user wants to server version so replace it
                                appState.TrainingDay.TrainingDay.Objects.Remove(localEntry);
                                appState.TrainingDay.TrainingDay.Objects.Add(serverEntry);
                            }
                            else
                            {
                                localEntry.Version = serverEntry.Version;
                            }
                        }
                        else
                        {
                            localEntry.Version = serverEntry.Version;
                        }
                    }

                    //now we check what entries we remove on the client
                    for (int index = appState.TrainingDay.TrainingDay.Objects.Count - 1; index >= 0; index--)
                    {
                        var localEntry = appState.TrainingDay.TrainingDay.Objects[index];
                        if (localEntry.GlobalId != Guid.Empty)
                        {
//this is saved entry (not newly added) so we must check if it exists still on the server
                            var serverEntry =
                                fromServer.Objects.Where(x => x.GlobalId == localEntry.GlobalId).SingleOrDefault();
                            if (serverEntry == null)
                            {
//this entry doesn't exist on the server. we must remove it from the client
                                appState.TrainingDay.TrainingDay.Objects.Remove(localEntry);
                            }
                        }
                    }
                    //if (useServerQuestion())
                    //{
                    //    var localTemp = appState.TrainingDay;
                    //    appState.TrainingDay = fromServer;
                    //    if (updateLocalCache)
                    //    {
                    //        state.TrainingDays[fromServer.TrainingDate].IsModified = true;
                    //    }
                    //    intelligentCopy(fromServer, localTemp);

                    //    if (updateLocalCache)
                    //    {
                    //        state.TrainingDays[fromServer.TrainingDate].TrainingDay = appState.TrainingDay.Copy();
                    //    }
                    //}
                    //else
                    //{

                    //    setVersion(appState.TrainingDay, fromServer);
                    //    intelligentCopy(appState.TrainingDay, fromServer);

                    //    if (updateLocalCache)
                    //    {
                    //        state.TrainingDays[fromServer.TrainingDate].IsModified = true;
                    //    }
                    //}
                }
                else
                {
                    //appState.TrainingDay.Version = fromServer.Version;
                    setVersion(appState.TrainingDay.TrainingDay, fromServer);
                    if (updateLocalCache)
                    {
                        holder.TrainingDays[fromServer.TrainingDate].IsModified = false;
                        //state.TrainingDays[fromServer.TrainingDate].TrainingDay.Version = fromServer.Version;
                        setVersion(holder.TrainingDays[fromServer.TrainingDate].TrainingDay, fromServer);
                    }
                }
                if (updateLocalCache)
                {
                    holder.TrainingDays[fromServer.TrainingDate].IsConflict = false;
                }
            }
            else
            {
                //if on the server entry is deleted then we must set Id to 0 (newly created object)
                //TODO: teraz gdy na serwerze wpis został usunięty po prostu robimy tak ze dalej user go ma. mozna też wyswietlic
                //pytanie że wpis został usunięty i niech user zadecyduje co z tym fantem zrobić
                appState.TrainingDay.TrainingDay.GlobalId = Guid.Empty;
                if (updateLocalCache)
                {
                    holder.TrainingDays.Remove(appState.TrainingDay.TrainingDay.TrainingDate);
                }
                setVersion(appState.TrainingDay.TrainingDay, null);
                //appState.TrainingDay.Version = 0;
            }
        }