Exemple #1
0
        public void AppendChangeSet(CompositeObjectChangeSet changeSet)
        {
            var compositeObjectId         = changeSet.CompositeObjectId;
            var compositeObjectChangeSets = changeSetsByCompositeObjects.GetOrAdd(compositeObjectId, guid => new ConcurrentDictionary <Guid, CompositeObjectChangeSet>());

            compositeObjectChangeSets.TryAdd(changeSet.ChangeSetId, changeSet);
        }
        public void AppendChangeSet(CompositeObjectChangeSet changeSet)
        {
            var stream = new MemoryStream();

            Serializer.Serialize(stream, changeSet);
            var content = stream.ToArray();

            using (var connection = dbConnectionFactory.Get())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText =
                        "INSERT INTO CompositeObjectChangeSets (CompositeObjectId, ChangeSetId, UserId, Timestamp, ContentLength, Content) VALUES (@CompositeObjectId, @ChangeSetId, @UserId, @Timestamp, @ContentLength, @Content)";

                    var p1 = command.CreateParameter();
                    p1.ParameterName = "@CompositeObjectId";
                    p1.DbType        = DbType.Guid;
                    p1.Value         = changeSet.CompositeObjectId;
                    command.Parameters.Add(p1);

                    var p2 = command.CreateParameter();
                    p2.ParameterName = "@ChangeSetId";
                    p2.DbType        = DbType.Guid;
                    p2.Value         = changeSet.ChangeSetId;
                    command.Parameters.Add(p2);

                    var p3 = command.CreateParameter();
                    p3.ParameterName = "@UserId";
                    p3.DbType        = DbType.Guid;
                    p3.Value         = changeSet.UserId;
                    command.Parameters.Add(p3);

                    var p4 = command.CreateParameter();
                    p4.ParameterName = "@Timestamp";
                    p4.DbType        = DbType.Int64;
                    p4.Value         = changeSet.Timestamp;
                    command.Parameters.Add(p4);

                    var p5 = command.CreateParameter();
                    p5.ParameterName = "@ContentLength";
                    p5.DbType        = DbType.Int32;
                    p5.Value         = content.Length;
                    command.Parameters.Add(p5);

                    var p6 = command.CreateParameter();
                    p6.ParameterName = "@Content";
                    p6.DbType        = DbType.Binary;
                    p6.Size          = content.Length;
                    p6.Value         = content;
                    command.Parameters.Add(p6);

                    command.ExecuteNonQuery();
                }
            }
        }
        public void UpdateChangeSet(CompositeObjectChangeSet changeSet, bool yesIKnowWhatIAmDoing = false)
        {
            if (!yesIKnowWhatIAmDoing)
            {
                throw new Exception("You must know what are you doing!");
            }

            var stream = new MemoryStream();

            Serializer.Serialize(stream, changeSet);
            var content = stream.ToArray();

            using (var connection = dbConnectionFactory.Get())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText =
                        "UPDATE CompositeObjectChangeSets SET Timestamp = @Timestamp, ContentLength = @ContentLength, Content = @Content) WHERE CompositeObjectId = @CompositeObjectId AND ChangeSetId = @ChangeSetId";

                    var p1 = command.CreateParameter();
                    p1.ParameterName = "@CompositeObjectId";
                    p1.DbType        = DbType.Guid;
                    p1.Value         = changeSet.CompositeObjectId;
                    command.Parameters.Add(p1);

                    var p2 = command.CreateParameter();
                    p2.ParameterName = "@ChangeSetId";
                    p2.DbType        = DbType.Guid;
                    p2.Value         = changeSet.ChangeSetId;
                    command.Parameters.Add(p2);

                    var p3 = command.CreateParameter();
                    p3.ParameterName = "@Timestamp";
                    p3.DbType        = DbType.Int64;
                    p3.Value         = changeSet.Timestamp;
                    command.Parameters.Add(p3);

                    var p4 = command.CreateParameter();
                    p4.ParameterName = "@ContentLength";
                    p4.DbType        = DbType.Int32;
                    p4.Value         = content.Length;
                    command.Parameters.Add(p4);

                    var p5 = command.CreateParameter();
                    p5.ParameterName = "@Content";
                    p5.DbType        = DbType.Binary;
                    p5.Size          = content.Length;
                    p5.Value         = content;
                    command.Parameters.Add(p5);

                    command.ExecuteNonQuery();
                }
            }
        }
Exemple #4
0
        public void AppendChangeSet(CompositeObjectChangeSet changeSet)
        {
            var entity = ToEntity(changeSet);

            using (var context = GetDataContext())
            {
                context.GetTable <CompositeObjectChangeSetEntity>().InsertOnSubmit(entity);
                context.SubmitChanges();
            }
        }
Exemple #5
0
        public void UpdateChangeSet(CompositeObjectChangeSet changeSet, bool yesIKnowWhatIAmDoing = false)
        {
            if (!yesIKnowWhatIAmDoing)
            {
                throw new Exception("You must know what are you doing!");
            }

            var compositeObjectId         = changeSet.CompositeObjectId;
            var compositeObjectChangeSets = changeSetsByCompositeObjects[compositeObjectId];

            compositeObjectChangeSets.TryUpdate(compositeObjectId, changeSet, changeSet);
        }
Exemple #6
0
        public void UpdateChangeSet(CompositeObjectChangeSet changeSet, bool yesIKnowWhatIAmDoing = false)
        {
            if (!yesIKnowWhatIAmDoing)
            {
                throw new Exception("You must know what are you doing!");
            }

            var entity = ToEntity(changeSet);

            using (var context = GetDataContext())
            {
                context.GetTable <CompositeObjectChangeSetEntity>().Attach(entity);
                context.Refresh(RefreshMode.KeepCurrentValues, entity);
                context.SubmitChanges();
            }
        }
Exemple #7
0
        private static CompositeObjectChangeSetEntity ToEntity(CompositeObjectChangeSet changeSet)
        {
            var stream = new MemoryStream();

            Serializer.Serialize(stream, changeSet);
            var content = stream.ToArray();

            return(new CompositeObjectChangeSetEntity
            {
                CompositeObjectId = changeSet.CompositeObjectId,
                ChangeSetId = changeSet.ChangeSetId,
                UserId = changeSet.UserId,
                Timestamp = changeSet.Timestamp,
                ContentLength = content.Length,
                Content = content
            });
        }
Exemple #8
0
        public void PushExistingComplexObjectChangeSet(Guid ownerId, CompositeObjectChangeSet changeSet)
        {
            var    compositeObjectId = changeSet.CompositeObjectId;
            object lockHandle;

            var cachedObject = compositeObjectCache.FindAndLock(compositeObjectId, lockTimespan, out lockHandle);

            if (cachedObject != null)
            {
                cachedObject.ApplyChangeSet(changeSet, businessObjectDefinitionProvider);
            }

            changeSetStorage.AppendChangeSet(changeSet);

            if (cachedObject != null)
            {
                compositeObjectCache.PutAndUnlock(cachedObject, lockHandle);
            }
            else
            {
                compositeObjectCache.Unlock(compositeObjectId, lockHandle);
            }
        }
Exemple #9
0
 public CompositeObjectChangeSetExceptionRecord(CompositeObjectChangeSet changeSet, Exception exception)
 {
     Exception = exception;
     ChangeSet = changeSet;
 }
Exemple #10
0
        /// <summary>
        /// Applying a changeset. This method is NOT thread safe.
        /// </summary>
        /// <param name="changeSet"></param>
        /// <param name="definitionProvider"></param>
        public void ApplyChangeSet(CompositeObjectChangeSet changeSet, IBusinessObjectDefinitionProvider definitionProvider)
        {
            if (appliedChangeSets.Contains(changeSet.ChangeSetId))
            {
                return;
            }

            foreach (var modification in changeSet.AttributeValues)
            {
                if (!compositeObjectDefinition.Attributes.ContainsKey(modification.Name))
                {
                    continue;
                }

                var attribute = compositeObjectDefinition.Attributes[modification.Name];
                attributes[attribute] = attribute.Serializer.Deserialize(attribute.Name, attribute.AttributeType, modification.Value);
            }

            var lastModified    = new DateTimeOffset(changeSet.Timestamp, new TimeSpan(0));
            var changeSetUserId = changeSet.UserId ?? Guid.Empty;             // TODO: a hack, changeSet.UserId should not be nullable

            foreach (var simpleObjectChangeSet in changeSet.ChildObjectChangeSets)
            {
                if (simpleObjectChangeSet.Action == SimpleObjectChangeSetType.Delete && simpleObjects.ContainsKey(simpleObjectChangeSet.SimpleObjectId))
                {
                    simpleObjects.Remove(simpleObjectChangeSet.SimpleObjectId);
                }
                else if (simpleObjectChangeSet.Action == SimpleObjectChangeSetType.UpdateParent &&
                         simpleObjects.ContainsKey(simpleObjectChangeSet.SimpleObjectId))
                {
                    var simpleObject = simpleObjects[simpleObjectChangeSet.SimpleObjectId];
                    var updateSimpleObjectParentChangeSet = (UpdateSimpleObjectParentChangeSet)simpleObjectChangeSet;
                    simpleObject.UpdateParentId(updateSimpleObjectParentChangeSet.ParentId);
                }
                else
                {
                    SimpleObject simpleObject;
                    var          createOrUpdateSimpleObjectCommand = simpleObjectChangeSet as CreateOrUpdateSimpleObjectChangeSet;

                    SimpleObjectDefinition simpleObjectDefinition;

                    if (simpleObjectChangeSet.Action == SimpleObjectChangeSetType.Create)
                    {
                        var commandCreate = (CreateSimpleObjectChangeSet)simpleObjectChangeSet;

                        simpleObjectDefinition = definitionProvider.FindSimpleObjectDefinition(CompositeObjectTypeId, commandCreate.SimpleObjectType);
                        if (simpleObjectDefinition == null)
                        {
                            continue;
                        }

                        simpleObject = new SimpleObject(commandCreate.SimpleObjectId, commandCreate.ParentId, simpleObjectDefinition, changeSetUserId, lastModified, changeSet.ChangeSetId);
                    }
                    else if (simpleObjects.ContainsKey(simpleObjectChangeSet.SimpleObjectId))
                    {
                        simpleObject           = simpleObjects[simpleObjectChangeSet.SimpleObjectId];
                        simpleObjectDefinition = simpleObject.SimpleObjectDefinition;
                    }
                    else
                    {
                        continue;
                    }

                    try
                    {
                        simpleObject.ApplyChangeSet(createOrUpdateSimpleObjectCommand, simpleObjectDefinition, changeSet.ChangeSetId, lastModified, changeSetUserId);
                    }
                    catch (Exception ex)
                    {
                        simpleObjectChangeSetExceptions.Add(new SimpleObjectChangeSetExceptionRecord(simpleObjectChangeSet, ex));
                    }

                    if (!simpleObjects.ContainsKey(simpleObjectChangeSet.SimpleObjectId))
                    {
                        simpleObjects.Add(simpleObjectChangeSet.SimpleObjectId, simpleObject);
                    }
                }
            }

            appliedChangeSets.Add(changeSet.ChangeSetId);
            LastModified        = lastModified;
            LastUpdatedByUserId = changeSetUserId;
            Revision            = changeSet.ChangeSetId;
        }