private void Initialize() { foreach (var typeId in typesService.GetRegisteredTypes()) { if (!typesService.IsScalarType(typeId)) { var type = typesService.GetTypeFromId(typeId); var rule = new TypeMergeRule(); Type collectionType = null; Type dictionaryType = null; if (!Utils.IsCollectionType(type, ref collectionType) && !Utils.IsDictionaryType(type, ref dictionaryType)) { var attributes = type.GetCustomAttributes(typeof(ConcurrentAttribute), true); if (attributes.Length == 1) { rule.IsConcurrent = true; rule.IsStaticConcurrency = ((ConcurrentAttribute)attributes[0]).Behavior == ConcurrentBehavior.Static; if (!rule.IsStaticConcurrency) { rule.DynamicResolverType = ((ConcurrentAttribute)attributes[0]).Resolver; } else { foreach (var edge in typesService.GetTypeEdges(typeId)) { if (edge.Data.Semantic == Graph.EdgeType.Property) { var memberId = edge.ToNodeId; //var memberTypeId = typesService.GetMemberTypeId(memberId); var memberName = typesService.GetMemberName(typeId, memberId); PropertyInfo propertyInfo = FindPropertyInfo(type, memberName); bool isOverride = propertyInfo.GetCustomAttributes(typeof(OverrideAttribute), false).Length == 1; rule.IsMemberOverride.Add(memberId, isOverride); } } } } } else { rule.IsConcurrent = true; rule.IsStaticConcurrency = true; } // Add rule for the type in cache typeMergeRules.Add(typeId, rule); } } }
public bool IsScalarType(Guid typeId) { return(typesService.IsScalarType(typeId)); }
/// <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); } } }