コード例 #1
0
        public static ChangeSet EvaluateDiffWith3dmData(IFileDataTable table, IEnumerable table3dm, ref DataStore store)
        {
            Type      tableObjectType = null;
            ChangeSet changes         = new ChangeSet();
            Dictionary <Guid, ModelComponent> table3dmCached = new Dictionary <Guid, ModelComponent>();
            HashSet <Guid> objGuidsWithMatches = new HashSet <Guid>();
            var            i = table3dm.GetEnumerator();

            while (i.MoveNext())
            {
                ModelComponent comp = (ModelComponent)i.Current;
                if (tableObjectType == null)
                {
                    tableObjectType = comp.GetType();
                }
                //caching this for future use
                table3dmCached.Add(comp.Id, comp);
                //now doing the comparison
                if (table.Contains(comp.Id))
                {
                    objGuidsWithMatches.Add(comp.Id);
                    ModelComponent obj = table.GetModelComponent(comp.Id);
                    if (!obj.Equals(comp))
                    {
                        //object has been modified
                        Guid initialVersion;
                        if (!table.ObjectHasAlias(comp.Id, out initialVersion))
                        {
                            initialVersion = comp.Id;
                        }
                        //adding the new version of the object to the store
                        Guid finalVersion = store.AddObject(comp, true);
                        //create modification type change from initial version to final version
                        changes.AddChange(ChangeType.Modification, tableObjectType, comp.Id, initialVersion, finalVersion);
                    }
                }
                else
                {
                    //create addition change
                    changes.AddChange(ChangeType.Addition, tableObjectType, comp.Id);
                }
            }

            //finding the objects in the original tables whose matches were not found
            var deletedGuids = table.Objects.Except(objGuidsWithMatches);

            foreach (var deleted in deletedGuids)
            {
                changes.AddChange(ChangeType.Deletion, tableObjectType, deleted);
            }

            return(changes);
        }
コード例 #2
0
        public bool Move(ChessBoxState actualPlayer, Move move)
        {
            ValidateMove(actualPlayer, move);
            ChangeSet     step      = new ChangeSet(move);
            ChessBoxState stateFrom = desk.GetState(move.From);
            ChessBoxState stateTo   = desk.GetState(move.To);

            step.AddChange(move.From, stateFrom, ChessBoxState.Empty);
            step.AddChange(move.To, stateTo, stateFrom);
            step.AddChangesRange(MoveEffects(actualPlayer, move));
            desk.DoStep(step);
            Moved?.Invoke(this, step);
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Сохраняем журнал изменений через новый UnitOfWork.
        /// </summary>
        public void SaveChangeSet(IUnitOfWork userUoW)
        {
            if (changes.Count == 0)
            {
                return;
            }

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot())
            {
                var user = UserRepository.GetCurrentUser(uow);

                var    conStr  = userUoW.Session.Connection.ConnectionString;
                var    reg     = new Regex("user id=(.+?)(;|$)");
                var    match   = reg.Match(conStr);
                string dbLogin = match.Success ? match.Groups[1].Value : null;

                var changeset = new ChangeSet(userUoW.ActionTitle?.UserActionTitle
                                              ?? userUoW.ActionTitle?.CallerMemberName + " - "
                                              + userUoW.ActionTitle.CallerFilePath.Substring(userUoW.ActionTitle.CallerFilePath.LastIndexOfAny(DIRECTORY_SEPARATORS.ToArray()) + 1)
                                              + " (" + userUoW.ActionTitle.CallerLineNumber + ")",
                                              user,
                                              dbLogin);
                changeset.AddChange(changes.ToArray());
                uow.Save(changeset);
                uow.Commit();
                logger.Debug(NumberToTextRus.FormatCase(changes.Count, "Зарегистрировано изменение {0} объекта.", "Зарегистрировано изменение {0} объектов.", "Зарегистрировано изменение {0} объектов."));

                Reset();
            }
        }