Ejemplo n.º 1
0
        /// <summary>
        /// Determines if member with given ID is of scalar type
        /// </summary>
        /// <param name="memberId">Member ID</param>
        /// <returns>True if member type is scalar</returns>
        public bool IsScalarMember(Guid memberId)
        {
            Guid typeId = typesService.GetMemberTypeId(memberId);

            return(typesService.IsScalarType(typeId));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invokes events for object change subscriptions
        /// </summary>
        /// <param name="workspaceId">Workspace Id which is making the changes</param>
        /// <param name="commitResult">Commit result to process</param>
        public void InvokeEvents(Guid workspaceId, CommitResult <Guid> commitResult)
        {
            lock (subscriptions)
            {
                Collection <Guid> removalList = new Collection <Guid>();

                foreach (var item in subscriptions.Values)
                {
                    // Was the object changed in the commit?
                    if (commitResult.Mapping.ContainsKey(item.InstanceId))
                    {
                        // Is the change originating from different workspace OR we wanted events from same workspace
                        bool doThrowEvent = !item.WorkspaceId.Equals(workspaceId) || item.NotifyChangesFromSameWorkspace;

                        // If property was specified
                        if (doThrowEvent && !item.MemberId.Equals(Guid.Empty))
                        {
                            var isScalarMember = typesService.IsScalarType(typesService.GetMemberTypeId(item.MemberId));

                            if (isScalarMember)
                            {
                                // Get scalar property values
                                var oldValue = objectInstancesService.GetScalarInstanceMember(item.InstanceId, item.MemberId);
                                var newValue = objectInstancesService.GetScalarInstanceMember(commitResult.Mapping[item.InstanceId], item.MemberId);

                                // Throw event if they are not the same
                                doThrowEvent = Comparer.Default.Compare(oldValue, newValue) != 0;
                            }
                            else
                            {
                                bool isPermanent;
                                // Get reference property values
                                var oldValue = objectInstancesService.GetReferenceInstanceMember(item.InstanceId, item.MemberId, out isPermanent);
                                var newValue = objectInstancesService.GetReferenceInstanceMember(commitResult.Mapping[item.InstanceId], item.MemberId, out isPermanent);

                                // Throw event if they are not pointing to the same Ids
                                doThrowEvent = Comparer.Default.Compare(oldValue, newValue) != 0;
                            }
                        }

                        if (doThrowEvent)
                        {
                            var args = new ObjectChangedEventArgs(commitResult.ResultSnapshotId, item.InstanceId, commitResult.Mapping[item.InstanceId], new Subscription(item.SubscriptionId, item.WorkspaceId));
                            // Throw event
                            item.Del(this, args);

                            if (args.RenewSubscription)
                            {
                                // Renew subscription to new version
                                item.InstanceId = commitResult.Mapping[item.InstanceId];
                            }
                            else
                            {
                                // Register for removal
                                removalList.Add(item.SubscriptionId);
                            }
                        }
                        else
                        {
                            // Automatically renew subscriptions when processing own changes
                            item.InstanceId = commitResult.Mapping[item.InstanceId];
                        }
                    }
                }

                // Remove items which are not renewed
                foreach (var item in removalList)
                {
                    subscriptions.Remove(item);
                }
            }
        }