///-------------------------------------------------------------------------------------------------
            /// <summary>
            ///  Constructor.
            /// </summary>
            /// <param name="context">
            ///  The context.
            /// </param>
            /// <param name="handler">
            ///  The handler.
            /// </param>
            ///-------------------------------------------------------------------------------------------------
            public CommandPipeline(ExecutionCommandContext <T> context, ICommandHandler <T> handler)
            {
                DebugContract.Requires(context);

                _context = context;
                _handler = handler;
            }
Example #2
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Constructor.
 /// </summary>
 /// <param name="ruleCommandType">
 ///  Type of the rule command.
 /// </param>
 /// <param name="interceptor">
 ///  The interceptor.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public InterceptorWrapper(Type ruleCommandType, ICommandInterceptor interceptor)
 {
     DebugContract.Requires(ruleCommandType);
     DebugContract.Requires(interceptor);
     _ruleCommandType = ruleCommandType;
     _interceptor     = interceptor;
 }
Example #3
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Gets in snapshot.
        /// </summary>
        /// <param name="ctx">
        ///  The context.
        /// </param>
        /// <returns>
        ///  The in snapshot.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public ISlot GetInSnapshot(CommandContext ctx)
        {
            DebugContract.Requires(ctx);

            //    this._lock.EnterReadLock();
            var enumerator = GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    var item = enumerator.Current;
                    if (ctx.IsValidInSnapshot(item))
                    {
                        return(item);
                    }
                }
            }
            finally
            {
                if (enumerator != null)
                {
                    enumerator.Dispose();
                }
                //      this._lock.ExitReadLock();
            }
            return(null);
        }
Example #4
0
        private void SendEvents(ISessionInformation session)
        {
            DebugContract.Requires(session);

            if (_disposed || Filters == null)
            {
                return;
            }

            var origin = session.OriginStoreId;
            //if (origin != Store.Id)
            //    return;

            bool          first  = true;
            List <IEvent> events = new List <IEvent>();

            foreach (var evt in session.Events)
            {
                if (ShouldBePropagated(evt))
                {
                    if (first)
                    {
                        Store.Trace.WriteTrace(TraceCategory.EventBus, "Send events on channel {0} Store {1}", this.GetType().Name, Store.Id);
                    }
                    first = false;
                    Store.Trace.WriteTrace(TraceCategory.EventBus, "Prepare event {0}", evt);
                    events.Add(evt);
                }
            }

            if (events.Count > 0)
            {
                SendMessage(origin, session, events);
            }
        }
Example #5
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Constructor.
        /// </summary>
        /// <param name="id">
        ///  The identifier.
        /// </param>
        /// <param name="schemaId">
        ///  Identifier for the meta class.
        /// </param>
        /// <param name="nodetype">
        ///  The type of the node.
        /// </param>
        /// <param name="start">
        ///  (Optional) the start.
        /// </param>
        /// <param name="end">
        ///  (Optional) the end.
        /// </param>
        /// <param name="value">
        ///  (Optional) The value.
        /// </param>
        /// <param name="version">
        ///  (Optional) The version.
        /// </param>
        /// <param name="outgoings">
        ///  (Optional) The outgoings.
        /// </param>
        /// <param name="incomings">
        ///  (Optional) The incomings.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        internal GraphNode(Identity id, Identity schemaId, NodeType nodetype,
                           Identity start = null,
                           Identity end   = null,
                           object value   = null, long?version = null,
                           IEnumerable <EdgeInfo> outgoings = null, IEnumerable <EdgeInfo> incomings = null
                           )
            : base(id, schemaId, end)
        {
            DebugContract.Requires(id, "id");
            DebugContract.Requires(schemaId, "schemaId");
            DebugContract.Requires(start == null || end != null, "start/end");

            StartId = start;

            Value    = value;
            Version  = version ?? DateTime.UtcNow.Ticks;
            NodeType = nodetype;

            if (outgoings != null)
            {
                _outgoings = _outgoings.AddRange(outgoings.ToDictionary(e => e.Id));
            }
            if (incomings != null)
            {
                _incomings = _incomings.AddRange(incomings.ToDictionary(e => e.Id));
            }
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Handles the given context.
        /// </summary>
        /// <param name="context">
        ///  The context.
        /// </param>
        /// <returns>
        ///  An IEvent.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IEvent Handle(ExecutionCommandContext <ChangePropertyValueCommand> context)
        {
            DebugContract.Requires(context);
            var dm = DomainModel as IUpdatableDomainModel;

            if (dm == null)
            {
                return(null);
            }

            using (CodeMarker.MarkBlock("ChangeAttributeCommand.Handler"))
            {
                var pv = dm.SetPropertyValue(Element, SchemaProperty, Value, this.Version);
                if (pv == null)
                {
                    return(null);
                }
                OldValue   = pv.OldValue;
                OldVersion = pv.CurrentVersion;
            }

            var evt = new ChangePropertyValueEvent(Element.DomainModel.Name,
                                                   DomainModel.ExtensionName,
                                                   Element.Id,
                                                   Element.SchemaInfo.Id,
                                                   SchemaProperty.Name,
                                                   Value,
                                                   OldValue,
                                                   context.CurrentSession.SessionId,
                                                   Version.Value);

            evt.SetInternalValue(Value, OldValue);
            return(evt);
        }
Example #7
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Registers for attribute changed event.
        /// </summary>
        /// <param name="element">
        ///  The element.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public IDisposable RegisterForAttributeChangedEvent(IModelElement element)
        {
            if (element is IPropertyChangedNotifier)
            {
                DebugContract.Requires(element.Id);
                _attributedChangedObserversSync.EnterWriteLock();
                try
                {
                    if (_attributedChangedObservers.ContainsKey(element.Id))
                    {
                        _attributedChangedObservers[element.Id]++;
                    }
                    else
                    {
                        _attributedChangedObservers.Add(element.Id, 1);
                    }

                    return(Disposables.ExecuteOnDispose(() =>
                    {
                        _attributedChangedObservers[element.Id]--;
                        if (_attributedChangedObservers[element.Id] == 0)
                        {
                            _attributedChangedObservers.Remove(element.Id);
                        }
                    }));
                }
                finally
                {
                    _attributedChangedObserversSync.ExitWriteLock();
                }
            }
            return(Disposables.Empty);
        }
Example #8
0
        internal static string GetNameWithSimpleAssemblyName(this Type type)
        {
            DebugContract.Requires(type);

            var typeinfo = type.GetTypeInfo();

            if (!typeinfo.IsGenericType)
            {
                return(String.Format("{0}, {1}", type.FullName, GetAssemblyName(type)));
            }

            var sb = new StringBuilder();

            sb.Append(type.Namespace);
            sb.Append('.');
            sb.Append(type.Name);
            sb.Append('[');
            foreach (var t in typeinfo.GenericTypeArguments)
            {
                sb.Append('[');
                sb.Append(GetNameWithSimpleAssemblyName(t));
                sb.Append(']');
            }
            sb.Append(']');
            sb.Append(',');
            sb.Append(GetAssemblyName(type));
            return(sb.ToString());
        }
Example #9
0
        internal GraphPath(IDomainModel domain, Identity node)
        {
            DebugContract.Requires(node, "node");

            DomainModel = domain;
            EndElement  = node;
        }
Example #10
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Gets the attribute.
        /// </summary>
        /// <exception cref="InvalidElementException">
        ///  Thrown when an Invalid Element error condition occurs.
        /// </exception>
        /// <param name="ownerId">
        ///  The identifier that owns this item.
        /// </param>
        /// <param name="property">
        ///  The property.
        /// </param>
        /// <returns>
        ///  The property value or null if not exists.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public PropertyValue GetPropertyValue(Identity ownerId, ISchemaProperty property)
        {
            DebugContract.Requires(ownerId);
            DebugContract.Requires(property);

            GraphNode v;

            if (!GraphNodeExists(ownerId))
            {
                throw new InvalidElementException(ownerId);
            }

            var pid = ownerId.CreateAttributeIdentity(property.Name);

            if (!GetGraphNode(pid, NodeType.Property, out v) || v == null)
            {
                return(null);
            }

            var p = v as GraphNode;

            Debug.Assert(p != null);

            return(new PropertyValue
            {
                Value = p.Value,
                CurrentVersion = p.Version
            });
        }
Example #11
0
        protected PropertyValue SetPropertyValueCore(IModelElement owner, ISchemaProperty property, object value, long?version, GraphNode oldNode)
        {
            DebugContract.Requires(owner);
            DebugContract.Requires(property);
            DebugContract.Requires(Session.Current);

            _trace.WriteTrace(TraceCategory.Hypergraph, "{0}.{1} = {2}", owner, property.Name, value);
            using (var tx = BeginTransaction())
            {
                // Vérification si le owner existe
                if (!GraphNodeExists(owner.Id))
                {
                    throw new InvalidElementException(owner.Id);
                }

                var pid = owner.Id.CreateAttributeIdentity(property.Name);

                // Recherche si l'attribut existe
                var pnode = _storage.GetNode(pid) as GraphNode;
                if (pnode == null)
                {
                    // N'existe pas encore. On crée l'attribut et une relation avec son owner
                    pnode = new GraphNode(pid, property.Id, NodeType.Property, value: value, version: version);
                    _storage.AddNode(pnode, owner.Id);
                    DeferAddIndex(owner.SchemaInfo, owner.Id, property.Name, value);
                    tx.Commit();

                    var oldPropertyNode = oldNode as GraphNode;
                    return(new PropertyValue {
                        Value = value, OldValue = oldPropertyNode != null ? oldPropertyNode.Value : property.DefaultValue, CurrentVersion = pnode.Version
                    });
                }

                var oldValue = pnode.Value;
                // TODO
                //if (version != null && pnode.Version != version)
                //{
                //    throw new ConflictException(ownerId, ownerMetadata, property, value, oldValue, version.Value, pnode.Version);
                //}

                if (Equals(oldValue, value))
                {
                    tx.Commit();
                    return(new PropertyValue {
                        Value = value, OldValue = oldValue, CurrentVersion = pnode.Version
                    });
                }

                DeferRemoveIndex(owner.SchemaInfo, owner.Id, property.Name, oldValue);

                pnode = pnode.SetValue(value);
                _storage.UpdateNode(pnode);
                DeferAddIndex(owner.SchemaInfo, owner.Id, property.Name, value);

                tx.Commit();
                return(new PropertyValue {
                    Value = value, OldValue = oldValue, CurrentVersion = pnode.Version
                });
            }
        }
Example #12
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Adds the element.
        /// </summary>
        /// <param name="id">
        ///  .
        /// </param>
        /// <param name="schemaEntity">
        ///  The meta class.
        /// </param>
        /// <returns>
        ///  The new entity.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public virtual GraphNode CreateEntity(Identity id, ISchemaEntity schemaEntity)
        {
            DebugContract.Requires(id, "id");
            DebugContract.Requires(schemaEntity);

            if (Session.Current == null)
            {
                throw new SessionRequiredException();
            }

            Session.Current.AcquireLock(LockType.Exclusive, id);

            _trace.WriteTrace(TraceCategory.Hypergraph, "Add element {0}", id);

            using (var tx = BeginTransaction())
            {
                if (CurrentTransaction != null)
                {
                    CurrentTransaction.UpdateProfiler(p => p.NodesCreated.Incr());
                    CurrentTransaction.UpdateProfiler(p => p.NumberOfNodes.Incr());
                }

                var node = new GraphNode(id, schemaEntity.Id, NodeType.Node);
                _storage.AddNode(node);

                tx.Commit();
                return(node);
            }
        }
Example #13
0
        protected void Configure(IDomainModel domainModel)
        {
            DebugContract.Requires(domainModel);
            if (_domainModel != null)
            {
                return;
            }

            _trace       = domainModel.Resolve <IHyperstoreTrace>(false) ?? new EmptyHyperstoreTrace();
            _domainModel = domainModel;

            var kv = _services.Resolve <IKeyValueStore>() ?? new Hyperstore.Modeling.MemoryStore.TransactionalMemoryStore(domainModel);

            _storage = kv;
            if (kv is IDomainService)
            {
                ((IDomainService)kv).SetDomain(domainModel);
            }
            _indexManager = new Hyperstore.Modeling.HyperGraph.Index.MemoryIndexManager(this); // TODO lier avec TransactionalMemoryStore
            _loader       = _services.Resolve <IGraphAdapter>();
            if (_loader is IDomainService)
            {
                ((IDomainService)_loader).SetDomain(domainModel);
            }
            _lazyLoader = _loader as ISupportsLazyLoading;
        }
Example #14
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Creates the index.
        /// </summary>
        /// <exception cref="NotImplementedException">
        ///  Thrown when the requested operation is unimplemented.
        /// </exception>
        /// <param name="metaclass">
        ///  .
        /// </param>
        /// <param name="name">
        ///  The name.
        /// </param>
        /// <param name="unique">
        ///  true to unique.
        /// </param>
        /// <param name="propertyNames">
        ///  List of names of the properties.
        /// </param>
        /// <returns>
        ///  The new index.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IIndex CreateIndex(ISchemaElement metaclass, string name, bool unique, params string[] propertyNames)
        {
            DebugContract.Requires(metaclass);
            DebugContract.RequiresNotEmpty(name);

            return(_indexManager.CreateIndex(metaclass, name, unique, propertyNames));
        }
Example #15
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Constructor.
 /// </summary>
 /// <param name="store">
 ///  The store.
 /// </param>
 /// <param name="index">
 ///  Zero-based index of the.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public IndexWrapper(IHyperstore store, IIndex index)
 {
     DebugContract.Requires(store);
     DebugContract.Requires(index);
     _store = store;
     _index = index;
 }
Example #16
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Specialised constructor for use only by derived classes.
 /// </summary>
 /// <param name="id">
 ///  The identifier.
 /// </param>
 /// <param name="schemaId">
 ///  The identifier of the schema.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public NodeInfo(Identity id, Identity schemaId)
 {
     DebugContract.Requires(id);
     DebugContract.Requires(schemaId);
     Id       = id;
     SchemaId = schemaId;
 }
Example #17
0
        internal void Add(Identity id, object key)
        {
            DebugContract.Requires(id);

            _sync.EnterWriteLock();
            try
            {
                HashSet <Identity> list;
                if (!_index.TryGetValue(key, out list))
                {
                    _index[key] = list = new HashSet <Identity>();
                }
                else if (_unique)
                {
                    throw new UniqueConstraintException(String.Format("Unique constraint failed for index {0}, id={1}, key={2}", Name, id, key));
                }

                if (!list.Add(id))
                {
                    throw new Exception(ExceptionMessages.IndexInsertionFailed);
                }

                HashSet <object> keys;
                if (!_keysById.TryGetValue(id, out keys))
                {
                    _keysById[id] = keys = new HashSet <object>();
                }
                keys.Add(key);
            }
            finally
            {
                _sync.ExitWriteLock();
            }
        }
Example #18
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Unloads.
        /// </summary>
        /// <param name="activeSessions">
        ///  The active sessions.
        /// </param>
        /// <param name="extension">
        ///  The extension.
        /// </param>
        /// <returns>
        ///  true if it succeeds, false if it fails.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public virtual bool Unload(List <int> activeSessions, T extension)
        {
            if (extension == null || extension.InstanceId == DomainModel.InstanceId)
            {
                DebugContract.Requires(activeSessions);
                DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, "*** Unload extension for {1} with active sessions {0}", String.Join(",", activeSessions), DomainModel.Name);

                if (PendingUnloadSessions != null)
                {
                    DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, "- Abort extension with pending unload sessions {0}", String.Join(",", PendingUnloadSessions));
                    // On est dèja en train de décharger ????
                    return(false);
                }

                DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, " - OK");
                // Sessions actives au moment du déchargement de l'extension
                if (activeSessions.Count > 0)
                {
                    PendingUnloadSessions = new List <int>(activeSessions);
                    return(false);
                }

                OnUnload();
                return(true);
            }
            return(false);
        }
Example #19
0
        private void OnSesssionCompleted(ISessionInformation session)
        {
            DebugContract.Requires(session);

            var originId = session.OriginStoreId;

            if (session.IsAborted || !session.Events.Any() || _disposed || (originId != null && originId != Store.Id) || (session.Mode & SessionMode.Loading) == SessionMode.Loading || (session.Mode & SessionMode.LoadingSchema) == SessionMode.LoadingSchema)
            {
                return;
            }

            var elements = session.TrackingData.InvolvedTrackedElements.Where(e => String.Compare(e.DomainName, DomainModel.Name, StringComparison.OrdinalIgnoreCase) == 0 && String.Compare(e.Extension, DomainModel.ExtensionName, StringComparison.OrdinalIgnoreCase) == 0);

            if (!elements.Any())
            {
                return;
            }

            var observer = this as IPersistenceGraphAdapter;

            Debug.Assert(observer != null);

            try
            {
                observer.PersistElements(session, elements);
            }
            catch (Exception ex)
            {
                session.Log(new DiagnosticMessage(MessageType.Error, ExceptionMessages.Diagnostic_ErrorInPersistenceAdapter, observer.GetType().FullName, null, ex));
            }
        }
Example #20
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Méthode appelée à la fin de chaque session.
        /// </summary>
        /// <param name="sessionId">
        ///  .
        /// </param>
        /// <returns>
        ///  true if it succeeds, false if it fails.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public bool OnSessionCompleted(int sessionId)
        {
            DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, "Session completed for {0}", sessionId);

            if (PendingLoadSessions != null)
            {
                DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, " Update load sessions {0}", String.Join(",", PendingLoadSessions));
                PendingLoadSessions.Remove(sessionId);
                if (PendingLoadSessions.Count == 0)
                {
                    PendingLoadSessions = null;
                }
            }

            if (PendingUnloadSessions != null)
            {
                PendingUnloadSessions.Remove(sessionId);
                DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, " Update unload sessions {0}", String.Join(",", PendingUnloadSessions));
                if (PendingUnloadSessions.Count == 0)
                {
                    if (PendingLoadSessions == null)
                    {
                        DebugContract.Requires(Status == ScopeStatus.ScopeEnabled);
                        DomainModel.Store.Trace.WriteTrace(TraceCategory.DomainControler, " - Set extensionDomain to null");
                        PendingUnloadSessions = null; // Raz que si _pendingLoadSessions est null

                        OnUnload();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #21
0
        private void OnChangedAttributeEvent(ISessionInformation session, ISessionContext log, ChangePropertyValueEvent cmd, Dictionary <Identity, IModelElement> notifications)
        {
            DebugContract.Requires(session);
            DebugContract.Requires(log);
            DebugContract.Requires(cmd);

            if (!Equals(cmd.OldValue, cmd.Value))
            {
                var ctx = new EventContext <ChangePropertyValueEvent>(session, cmd);
                try
                {
                    _attributeChanged.OnNext(ctx);
                }
                catch (Exception ex)
                {
                    NotifyEventError(log, ex);
                }

                IModelElement mel;
                if (notifications.TryGetValue(cmd.Id, out mel))
                {
                    var propertyName = cmd.PropertyName;
                    NotifyPropertyChanged(mel, propertyName);
                }
            }
        }
        internal void RemoveFromIndex(ISchemaElement metaclass, Identity owner, string propertyName, object value)
        {
            DebugContract.Requires(metaclass);
            DebugContract.Requires(owner);

            if (_indexActions == null)
            {
                _indexActions = new List <IndexAction>();
            }

            var indexes = _indexManager.GetIndexDefinitionsFor(metaclass);

            if (indexes == null)
            {
                return;
            }

            foreach (var def in indexes)
            {
                if (def.IsImpactedBy(metaclass, propertyName))
                {
                    var action = new RemoveFromIndexAction(metaclass, def.Index.Name, owner, value);
                    _indexActions.Add(action);
                }
            }
        }
Example #23
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Adds an edge.
        /// </summary>
        /// <exception cref="DuplicateElementException">
        ///  Thrown when a Duplicate Element error condition occurs.
        /// </exception>
        /// <param name="id">
        ///  The identifier.
        /// </param>
        /// <param name="schemaRelationship">
        ///  Identifier for the metadata.
        /// </param>
        /// <param name="direction">
        ///  The direction.
        /// </param>
        /// <param name="endId">
        ///  The identifier of the end.
        /// </param>
        /// <returns>
        ///  A GraphNode.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public virtual GraphNode AddEdge(Identity id, ISchemaRelationship schemaRelationship, Direction direction, Identity endId)
        {
            DebugContract.Requires(id, "id");
            DebugContract.Requires(schemaRelationship, "schemaRelationship");
            DebugContract.Requires(endId, "endId");

            if ((direction & Direction.Outgoing) == Direction.Outgoing && _outgoings.ContainsKey(id) ||
                (direction & Direction.Incoming) == Direction.Incoming && _incomings.ContainsKey(id))
            {
                throw new DuplicateElementException("Duplicate relationship");
            }

            // Check multi containers
            // TODO no it's valid if they are not all set (make a test in the command ???)
            //if ((direction & Direction.Incoming) == Direction.Incoming && schemaRelationship.IsEmbedded)
            //{
            //    if (_incomings.Any(r => r.Value.SchemaId == schemaRelationship.Id))
            //        return null;
            //}
            var edge = new EdgeInfo(id, schemaRelationship.Id, endId);

            return(new GraphNode(this,
                                 (direction & Direction.Outgoing) == Direction.Outgoing ? _outgoings.Add(id, edge) : _outgoings,
                                 (direction & Direction.Incoming) == Direction.Incoming ? _incomings.Add(id, edge) : _incomings
                                 ));
        }
Example #24
0
        private void Initialize(string domainModelName, int memoryStoreVacuumIntervalInSeconds, ITransactionManager transactionManager, IHyperstoreTrace trace, IStatistics stat)
        {
            DebugContract.RequiresNotEmpty(domainModelName);
            DebugContract.Requires(transactionManager);

            _trace = trace ?? new EmptyHyperstoreTrace();
            _transactionManager = transactionManager;
            if (memoryStoreVacuumIntervalInSeconds < 0)
            {
                memoryStoreVacuumIntervalInSeconds = defaultInterval;
            }

            _jobScheduler  = new JobScheduler(Vacuum, TimeSpan.FromSeconds(memoryStoreVacuumIntervalInSeconds));
            _involvedSlots = PlatformServices.Current.CreateConcurrentQueue <SlotList>();

            if (stat == null)
            {
                stat = EmptyStatistics.DefaultInstance;
            }

            _vaccumCounter = VACUUM_EVICTIONS_THROTTLE;

            _statAddValue      = stat.RegisterCounter("MemoryStore", String.Format("#AddValue {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statGeIGraphNode  = stat.RegisterCounter("MemoryStore", String.Format("#GeIGraphNode {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statUpdateValue   = stat.RegisterCounter("MemoryStore", String.Format("#UpdateValue {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statRemoveValue   = stat.RegisterCounter("MemoryStore", String.Format("#RemoveValue {0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statVaccumCount   = stat.RegisterCounter("MemoryStore", String.Format("#Vaccum{0}", domainModelName), domainModelName, StatisticCounterType.Value);
            _statVaccumAverage = stat.RegisterCounter("MemoryStore", String.Format("VaccumAvgTimes{0}", domainModelName), domainModelName, StatisticCounterType.Average);
            _statVaccumSkipped = stat.RegisterCounter("MemoryStore", String.Format("#VaccumSkipped{0}", domainModelName), domainModelName, StatisticCounterType.Value);
        }
Example #25
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Handles the given context.
        /// </summary>
        /// <param name="context">
        ///  The context.
        /// </param>
        /// <returns>
        ///  An IEvent.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IEvent Handle(ExecutionCommandContext <RemoveRelationshipCommand> context)
        {
            DebugContract.Requires(context);
            var dm = DomainModel as IUpdatableDomainModel;

            if (dm == null || Relationship == null)
            {
                return(null);
            }

            // Le noeud terminal n'existe peut-être pas réellement (si il fait partie d'un autre domaine qui n'est pas chargé)
            // Il faut utiliser directement son id
            var endId = Relationship.EndId;

            // Avant la suppression effective
            var @event = new RemoveRelationshipEvent(Relationship.DomainModel.Name,
                                                     Relationship.DomainModel.ExtensionName,
                                                     Relationship.Id,
                                                     Relationship.SchemaInfo.Id,
                                                     _startId,
                                                     endId,
                                                     context.CurrentSession.SessionId,
                                                     Version.Value);

            using (CodeMarker.MarkBlock("RemoveRelationshipCommand.Handle"))
            {
                if (dm.RemoveRelationship(Relationship.Id, _throwExceptionIfNotExists) == null)
                {
                    return(null);
                }
            }
            return(@event);
        }
Example #26
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Gets a value.
        /// </summary>
        /// <param name="key">
        ///  The key.
        /// </param>
        /// <returns>
        ///  The value.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public GraphNode GetNode(Identity key)
        {
            DebugContract.Requires(key);

            using (var ctx = CreateCommandContext())
            {
                _valuesLock.EnterReadLock();
                try
                {
                    var result = SelectSlot(key, ctx);
                    if (result != null)
                    {
                        return(result.Value);
                    }

                    return(default(GraphNode));
                }
                finally
                {
                    ctx.Complete();
                    //                NotifyVacuum();
                    _valuesLock.ExitReadLock();
                    _statGeIGraphNode.Incr();
                }
            }
        }
Example #27
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Adds slot.
        /// </summary>
        /// <param name="slot">
        ///  The slot to remove.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public void Add(ISlot slot)
        {
            DebugContract.Requires(slot);

            this._slots.Add(slot);
            Length++;
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Handles the given context.
        /// </summary>
        /// <exception cref="InvalidElementException">
        ///  Thrown when an Invalid Element error condition occurs.
        /// </exception>
        /// <param name="context">
        ///  The context.
        /// </param>
        /// <returns>
        ///  An IEvent.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IEvent Handle(ExecutionCommandContext <AddRelationshipCommand> context)
        {
            DebugContract.Requires(context);
            var dm = DomainModel as IUpdatableDomainModel;

            if (dm == null)
            {
                return(null);
            }

            if (Start == null)
            {
                new InvalidElementException(Start.Id, "Source element must exists to create a relationship");
            }

            if (String.Compare(Start.Id.DomainModelName, EndId.DomainModelName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (DomainModel.Store.GetElement(EndId) == null)
                {
                    throw new InvalidElementException(EndId, "Target element must exists to create a relationship.");
                }
            }

            using (CodeMarker.MarkBlock("AddRelationshipCommand.Handle"))
            {
                dm.CreateRelationship(Id, SchemaRelationship, Start, EndId, _element);
            }

            return(new AddRelationshipEvent(_domainModel.Name, DomainModel.ExtensionName, Id, SchemaRelationship.Id, Start.Id, EndId, context.CurrentSession.SessionId, Version.Value));
        }
Example #29
0
            ///-------------------------------------------------------------------------------------------------
            /// <summary>
            ///  Constructor.
            /// </summary>
            /// <param name="list">
            ///  The list.
            /// </param>
            ///-------------------------------------------------------------------------------------------------
            public ReverseEnumerator(IList <ISlot> list)
            {
                DebugContract.Requires(list);

                _list = list;
                _pos  = list.Count;
            }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Unload domain extension.
        /// </summary>
        /// <param name="domainModel">
        ///  The domain model.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public void UnloadScope(T domainModel)
        {
            DebugContract.Requires(domainModel != null);
            ScopeStack <T> item;
            List <int>     activeSessions;

            _sync.EnterWriteLock();
            try
            {
                item = FindDomainStack(domainModel.Name);
                if (item == null)
                {
                    return;
                }

                // TODO immutable
                activeSessions = new List <int>(_activeSessions);
            }
            finally
            {
                _sync.ExitWriteLock();
            }

            item.Unload(activeSessions, domainModel);
        }