public void EatStubOptions(ISnapshot snapshot, ICSharpExpression options)
        {
            if (options is IConditionalAndExpression)
            {
                EatStubOptions(snapshot, (options as IConditionalAndExpression).LeftOperand);
                EatStubOptions(snapshot, (options as IConditionalAndExpression).RightOperand);
                return;
            }

            if (options is IEqualityExpression)
            {
                EatStubOptions(snapshot, (options as IEqualityExpression).LeftOperand);
                var kind = _eater.Eat(snapshot, (options as IEqualityExpression).RightOperand);
                EatOptionValue(snapshot, kind, (options as IEqualityExpression).RightOperand);
                return;
            }

            if (options is IInvocationExpression)
            {
                var optType = _moqStubOptionTargetEater.EatOption(snapshot, options as IInvocationExpression);
                snapshot.Add(optType, options);
                return;
            }

            if (options is IReferenceExpression)
            {
                var optType = _moqStubOptionTargetEater.EatOption(snapshot, options as IReferenceExpression);
                snapshot.Add(optType, options);
                return;
            }

            throw new MoqStubOptionWrongTypeException(this, options);
        }
Example #2
0
        public void Eat(ISnapshot snapshot, IVariableDeclaration variableDeclaration)
        {
            if (variableDeclaration == null)
                throw new ArgumentNullException("variableDeclaration");

            GetEater(variableDeclaration).Eat(snapshot, variableDeclaration);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSourcedAggregate{T}"/> class.
 /// </summary>
 /// <param name="snapshot">A snapshot of the aggregate's built-up state.</param>
 protected internal EventSourcedAggregate(ISnapshot snapshot)
     : this(snapshot.IfNotNull()
                    .Then(s => s.AggregateId)
                    .ElseThrow(() => new ArgumentNullException(nameof(snapshot))))
 {
     sourceSnapshot = snapshot;
 }
Example #4
0
        public ExpressionKind Eat(ISnapshot snapshot, IQueryClause queryClause)
        {
            if (queryClause == null)
                throw new ArgumentNullException("queryClause");

            return GetEater(queryClause).Eat(snapshot, queryClause);
        }
 public OptimisticEventStream(ISnapshot snapshot, ICommitEvents persistence, int maxRevision)
     : this(snapshot.BucketId, snapshot.StreamId, persistence)
 {
     IEnumerable<ICommit> commits = persistence.GetFrom(snapshot.BucketId, snapshot.StreamId, snapshot.StreamRevision, maxRevision);
     PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits);
     StreamRevision = snapshot.StreamRevision + _committed.Count;
 }
Example #6
0
        public void Eat(ISnapshot snapshot, ICSharpStatement statement)
        {
            if (statement == null)
                throw new ArgumentNullException("statement");

            GetEater(statement).Eat(snapshot, statement);
        }
Example #7
0
        public ExpressionKind Eat(ISnapshot snapshot, ICSharpExpression expression)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");

            return GetEater(expression).Eat(snapshot, expression);
        }
        public FakeOptionType EatOption(ISnapshot snapshot, IReferenceExpression referenceExpression)
        {
            if (referenceExpression.QualifierExpression == null)
            {
                throw new MoqStubWrongSyntaxException("Moq-stub property-option has not parent reference", this,
                    referenceExpression);
            }

            if (referenceExpression.QualifierExpression is IInvocationExpression)
            {
                return EatOption(snapshot, referenceExpression.QualifierExpression as IInvocationExpression);
            }

            if (referenceExpression.QualifierExpression is IReferenceExpression)
            {
                var declaredElement = _eatExpressionHelper.GetReferenceElement(referenceExpression.QualifierExpression as IReferenceExpression);
                if (declaredElement is ILambdaParameterDeclaration)
                {
                    return FakeOptionType.Property;
                }
                return EatOption(snapshot, referenceExpression.QualifierExpression as IReferenceExpression);
            }

            throw new MoqStubOptionTargetWrongTypeException(this, referenceExpression.QualifierExpression);
        }
 public void Invalidate(ISnapshot tentativeSnapshot)
 {
     lock (synchRoot)
     {
         snapshots = null;
     }
 }
        public virtual ITextNode LoadIncludeFile(SnapshotParseContext snapshotParseContext, ISnapshot snapshot, string includeFileName)
        {
            var extension = PathHelper.GetExtension(snapshot.SourceFile.AbsoluteFileName);
            var projectDirectory = snapshot.SourceFile.AbsoluteFileName.Left(snapshot.SourceFile.AbsoluteFileName.Length - snapshot.SourceFile.ProjectFileName.Length - extension.Length + 1);

            string sourceFileName;
            if (includeFileName.StartsWith("~/"))
            {
                sourceFileName = PathHelper.Combine(projectDirectory, includeFileName.Mid(2));
            }
            else
            {
                sourceFileName = PathHelper.Combine(Path.GetDirectoryName(snapshot.SourceFile.AbsoluteFileName) ?? string.Empty, includeFileName);
            }

            if (!FileSystem.FileExists(sourceFileName))
            {
                throw new FileNotFoundException("Include file not found", sourceFileName);
            }

            var projectFileName = "~/" + PathHelper.NormalizeItemPath(PathHelper.UnmapPath(projectDirectory, PathHelper.GetDirectoryAndFileNameWithoutExtensions(sourceFileName))).TrimStart('/');
            var sourceFile = Factory.SourceFile(FileSystem, sourceFileName, projectFileName);

            var includeSnapshot = LoadSnapshot(snapshotParseContext, sourceFile) as TextSnapshot;

            return includeSnapshot?.Root ?? TextNode.Empty;
        }
 private void EatOptionValue(ISnapshot snapshot, ExpressionKind kind, ICSharpExpression optionValue)
 {
     var addableKinds = new[] { ExpressionKind.Target, ExpressionKind.Stub, ExpressionKind.Mock };
     if (addableKinds.Contains(kind))
     {
         snapshot.Add(kind, optionValue);
     }
 }
Example #12
0
 public void SaveShapshot(ISnapshot source)
 {
     FileInfo file = source.EventSourceId.GetSnapshotFileInfo(_path);
     if (!file.Exists && !file.Directory.Exists)
         file.Directory.Create();
     var jo = JObject.FromObject(source);
     WriteSnapshotTest(source, file.FullName, jo.ToString());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSourcedAggregate{T}"/> class.
 /// </summary>
 /// <param name="snapshot">A snapshot of the aggregate's built-up state.</param>
 /// <param name="eventHistory">The event history.</param>
 protected internal EventSourcedAggregate(ISnapshot snapshot, IEnumerable<IEvent> eventHistory = null) :
     this(snapshot.IfNotNull()
                  .Then(s => s.AggregateId)
                  .ElseThrow(() => new ArgumentNullException("snapshot")))
 {
     sourceEvents = eventHistory.OrEmpty().ToArray();
     SourceSnapshot = snapshot;
 }
Example #14
0
		public Commit(long id, Guid targetId, long targetVersion, IList<IDomainEvent> events, long? snapshotId = null, ISnapshot snapshot = null)
		{
			Id = id;
			TargetId = targetId;
			TargetVersion = targetVersion;
			Events = events;
			SnapshotId = snapshotId;
			Snapshot = snapshot;
		}
        public async Task SaveSnapshot(ISnapshot snapshot)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException(nameof(snapshot));
            }

            snapshots[snapshot.AggregateId] = snapshot;
        }
 public IncrementalCachingSnapshot(ISnapshot parentSnapshot, ICommandExecutor commandExecutor, IChangeSet changeSet)
 {
     this.parentSnapshot = parentSnapshot;
     this.commandExecutor = commandExecutor;
     foreach (var command in changeSet.Commands)
     {
         Load(command);
     }
 }
        public async Task<bool> AddSnapshot(ISnapshot snapshot)
        {
            bool result = await _persistence.AddSnapshot(snapshot);
            if (result)
            {
                _counters.CountSnapshot();
            }

            return result;
        }
Example #18
0
 protected override void DoBuildFromSnapshot(ISnapshot snapshot)
 {
     SourcedCustomerSnapshot s = (SourcedCustomerSnapshot)snapshot;
     this.Birth = s.Birth;
     this.Email = s.Email;
     this.FirstName = s.FirstName;
     this.LastName = s.LastName;
     this.Password = s.Password;
     this.Username = s.Username;
 }
        public bool AddSnapshot(ISnapshot snapshot)
        {
            bool result = _persistence.AddSnapshot(snapshot);
            if (result)
            {
                _counters.CountSnapshot();
            }

            return result;
        }
        public virtual IEventStream OpenStream(ISnapshot snapshot, int maxRevision)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            Logger.Debug(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision);
            maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;
            return new OptimisticEventStream(snapshot, this, maxRevision);
        }
Example #21
0
 private static void WriteSnapshotTest(ISnapshot source, string path, string jsonData)
 {
     try
     {
         source.EventSourceId.GetWriteLock("snapshot");
         File.WriteAllText(path, source.GetType().AssemblyQualifiedName + "\n\r" + jsonData);
     } finally
     {
         source.EventSourceId.ReleaseWriteLock("snapshot");
     }
 }
 public void Add(ChangeSetId changeSetId, ISnapshot snapshot)
 {
     lock (synchRoot)
     {
         if (snapshots.ContainsKey(changeSetId))
         {
             throw new InvalidOperationException(
                 string.Format("Another change set with the id {0} has already been loaded.", changeSetId));
         }
         snapshots[changeSetId] = snapshot;
     }
 }
Example #23
0
 public void SaveShapshot(ISnapshot source)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Store(new StoredSnaphot
                           {
                               Id = source.EventSourceId.ToString(),
                               Data = source,
                               EventSourceId = source.EventSourceId
                           });
         session.SaveChanges();
     }
 }
Example #24
0
        /// <summary>
        /// Creates a new FuzzController. Once the snapshotBreakpoint is reached a snapshot is created.
        /// The snapshot gets restored once restore Breakpoint is reached
        /// </summary>
        /// <param name="connector">connector to use</param>
        /// <param name="snapshotBreakpoint">Location to create a snapshot</param>
        /// <param name="restoreBreakpoint">Location to restore the snapshot</param>
        public FuzzController(ITargetConnector connector, string logDestination,
			IDataLogger logger, FuzzDescription fuzzDescription, IFuzzLocation[] preConditions)
        {
            _connector = connector;
            _snapshot = null;
            _dataLogger = logger;
            _logDestination = logDestination;

            _errorLog = new ErrorLog (_logDestination);

            _fuzzDescription = fuzzDescription;
            _fuzzDescription.Init ();

            _preConditions = preConditions;
        }
 protected override void TraceLine(ITraceService trace, int msg, string text, ITextNode textNode, ISnapshot snapshot, string details)
 {
     if (textNode != null)
     {
         trace.TraceInformation(msg, text, textNode, details);
     }
     else if (snapshot != null)
     {
         trace.TraceInformation(msg, text, snapshot.SourceFile, details);
     }
     else
     {
         trace.TraceInformation(msg, text, details);
     }
 }
 protected override void TraceLine(int msg, string text, ITextNode textNode, ISnapshot snapshot, string details)
 {
     if (textNode != null)
     {
         Trace.TraceError(msg, text, textNode, details);
     }
     else if (snapshot != null)
     {
         Trace.TraceError(msg, text, snapshot.SourceFile, details);
     }
     else
     {
         Trace.TraceError(msg, text, details);
     }
 }
        public IParseContext With(IProject project, ISnapshot snapshot, PathMappingContext pathMappingContext)
        {
            Project = project;
            Snapshot = snapshot;

            FilePath = pathMappingContext.FilePath;
            ItemName = pathMappingContext.ItemName;
            ItemPath = pathMappingContext.ItemPath;
            DatabaseName = pathMappingContext.DatabaseName;
            UploadMedia = pathMappingContext.UploadMedia;

            Trace = new ProjectDiagnosticTraceService(Configuration, Console, Factory).With(Project);

            return this;
        }
        private ExpressionKind EatResults(ISnapshot snapshot, ICSharpExpression initialExpression)
        {
            ExpressionKind expressionKind = _eater.Eat(snapshot, initialExpression);

            if (expressionKind == ExpressionKind.StubCandidate)
            {
                return ExpressionKind.Stub;
            }

            if (expressionKind == ExpressionKind.TargetCall)
            {
                return ExpressionKind.Result;
            }

            return expressionKind;
        }
        public IParseContext With(IProject project, ISnapshot snapshot)
        {
            Project = project;
            Snapshot = snapshot;
            Trace = new ProjectDiagnosticTraceService(Configuration, Console, Factory).With(Project);

            var fileContext = FileContext.GetFileContext(Project, Configuration, snapshot.SourceFile);
            FilePath = fileContext.FilePath;
            ItemName = fileContext.ItemName;
            ItemPath = fileContext.ItemPath;
            DatabaseName = fileContext.DatabaseName;
            IsExtern = fileContext.IsExtern;
            UploadMedia = fileContext.UploadMedia;

            return this;
        }
Example #30
0
        public void Init()
        {
            
            m_SnapshotDic = new Dictionary<NetWorkType, List<ISnapshot>>();
            gsmSnapshot = new MockGSMSnapshot();
            r99Snapshot = new UMTSR99Snapshot();
            List<ISnapshot> gsmList = new List<ISnapshot>();
            gsmList.Add(gsmSnapshot);
            List<ISnapshot> umtsList = new List<ISnapshot>();
            umtsList.Add(r99Snapshot);
            m_SnapshotDic.Add(NetWorkType.GSM, gsmList);
            m_SnapshotDic.Add(NetWorkType.UMTS, umtsList);

            m_VersionDic = new Dictionary<NetVersion, NetWorkType>();
            m_VersionDic.Add(NetVersion.GSM, NetWorkType.GSM);
            m_VersionDic.Add(NetVersion.UMTSR99, NetWorkType.UMTS);
            m_VersionDic.Add(NetVersion.UMTSHSUPA, NetWorkType.UMTS);

            m_SimulationGroup = new MockSimulationGroup();

            NetworkParam networkParam = new NetworkParam();
            Dictionary<NetWorkType,object> netWorkTypeDic = new Dictionary<NetWorkType,object>();
            netWorkTypeDic.Add(NetWorkType.UMTS, null);
            netWorkTypeDic.Add(NetWorkType.GSM, null);
            networkParam.Param = netWorkTypeDic;

            UnionUIParam unionParam = new UnionUIParam();
            unionParam.AllocateType = AllocateUserType.Load;
            List<NetWorkType> netTypes = new List<NetWorkType>();
            netTypes.Add(NetWorkType.GSM);
            netTypes.Add(NetWorkType.UMTS);
            unionParam.NETS = netTypes;

            unionParam.UnionIterationNumber = 2;

            networkParam.UnionParam = unionParam;

            m_SimulationGroup.AdvanceParam = networkParam;

            IApplicationContext context = new MockAppContext();
            m_SimulationGroup.Region = CreatRegion();
            IProject project = new MockProject();
            ProjectSingleton.CurrentProject = project;
            m_Target = new CoSnapshot(m_SimulationGroup, m_SnapshotDic, m_VersionDic,context);
           
 
        }
Example #31
0
 public ItemServer(Guid id, ISnapshot snapshot) : base(id, snapshot)
 {
 }
Example #32
0
 public SidecarValues(ISnapshot valuesFactory)
 {
     _values = valuesFactory;
 }
Example #33
0
        ProjectionStream LoadProjectionStream(Type projectionType, ProjectionVersion projectionVersion, IBlobId projectionId, ISnapshot snapshot)
        {
            if (ReferenceEquals(null, projectionVersion))
            {
                throw new ArgumentNullException(nameof(projectionVersion));
            }
            if (ReferenceEquals(null, projectionId))
            {
                throw new ArgumentNullException(nameof(projectionId));
            }
            if (ReferenceEquals(null, snapshot))
            {
                throw new ArgumentNullException(nameof(snapshot));
            }

            ISnapshot currentSnapshot = snapshot;
            string    contractId      = projectionVersion.ProjectionContractId;

            List <ProjectionCommit> projectionCommits = new List <ProjectionCommit>();
            int snapshotMarker = snapshot.Revision;

            while (true)
            {
                snapshotMarker++;
                var loadedCommits = projectionStore.Load(projectionVersion, projectionId, snapshotMarker).ToList();
                projectionCommits.AddRange(loadedCommits);
                bool isSnapshotable = typeof(IAmNotSnapshotable).IsAssignableFrom(projectionType) == false;

                if (isSnapshotable && snapshotStrategy.ShouldCreateSnapshot(projectionCommits, snapshot.Revision))
                {
                    ProjectionStream checkpointStream = new ProjectionStream(projectionId, projectionCommits, currentSnapshot);
                    var       projectionState         = checkpointStream.RestoreFromHistory(projectionType).Projection.State;
                    ISnapshot newSnapshot             = new Snapshot(projectionId, contractId, projectionState, snapshot.Revision + 1);
                    snapshotStore.Save(newSnapshot, projectionVersion);
                    currentSnapshot = newSnapshot;

                    projectionCommits.Clear();

                    log.Debug(() => $"Snapshot created for projection `{contractId}` with id={projectionId} where ({loadedCommits.Count}) were zipped. Snapshot: `{snapshot.GetType().Name}`");
                }
                else if (loadedCommits.Count() < snapshotStrategy.EventsInSnapshot)
                {
                    break;
                }
                else
                {
                    log.Warn($"Potential memory leak. The system will be down fairly soon. The projection `{contractId}` with id={projectionId} loads a lot of projection commits ({loadedCommits.Count}) and snapshot `{snapshot.GetType().Name}` which puts a lot of CPU and RAM pressure. You can resolve this by configuring the snapshot settings`.");
                }
            }

            ProjectionStream stream = new ProjectionStream(projectionId, projectionCommits, currentSnapshot);

            return(stream);
        }
Example #34
0
        public Promotions(Guid id, ISnapshot snapshot) : base(id, snapshot)
        {
            var state = (PromotionsSnapshot)snapshot;

            this.points = state.Points;
        }
Example #35
0
        private async Task <ProjectionStream> LoadProjectionStreamAsync(ProjectionVersion version, IBlobId projectionId, ISnapshot snapshot)
        {
            bool             shouldLoadMore = true;
            Func <ISnapshot> loadSnapshot   = () => snapshot;

            List <ProjectionCommit> projectionCommits = new List <ProjectionCommit>();
            int snapshotMarker = snapshot.Revision;

            while (shouldLoadMore)
            {
                snapshotMarker++;

                var  loadProjectionCommits   = projectionStore.LoadAsync(version, projectionId, snapshotMarker).ConfigureAwait(false);
                bool checkNextSnapshotMarker = await projectionStore.HasSnapshotMarkerAsync(version, projectionId, snapshotMarker + 1).ConfigureAwait(false);

                shouldLoadMore = checkNextSnapshotMarker;

                await foreach (var commit in loadProjectionCommits)
                {
                    projectionCommits.Add(commit);
                }
            }

            ProjectionStream stream = new ProjectionStream(projectionId, projectionCommits, loadSnapshot);

            return(stream);
        }
        private IAggregateEx GetAggregate <TAggregate>(ISnapshot snapshot, IEventStream stream)
        {
            IMementoEx memento = snapshot == null ? null : snapshot.Payload as IMementoEx;

            return(this._factory.Build(typeof(TAggregate), _identityConverter.ToIdentity(stream.StreamId), memento));
        }
Example #37
0
 public abstract void Eat(ISnapshot snapshot, T statement);
Example #38
0
 public virtual void AddSnapshot(ISnapshot snapshot)
 {
     _snapshots.Add(snapshot);
 }
 public OriginalValues(InternalEntityEntry entry)
 {
     _values = entry.EntityType.GetOriginalValuesFactory()(entry);
 }
Example #40
0
 public EventSourced(Guid id, ISnapshot snapshot)
     : this(id)
 {
     this.version = snapshot.Version;
 }
Example #41
0
 public ReadOptions Snapshot(ISnapshot snapshot)
 {
     _snapshot = snapshot;
     return(this);
 }
Example #42
0
 public CustomerAccount(
     ISnapshot snapshot,
     IEnumerable <IEvent> additionalEvents = null) : base(snapshot, additionalEvents)
 {
 }
 public RelationshipsSnapshot(InternalEntityEntry entry)
 {
     _values = ((EntityType)entry.EntityType).RelationshipSnapshotFactory(entry);
 }
Example #44
0
 public abstract IReadOnlyList <ISendable <ITransmittable> > Create(ISnapshot <TUser, TTransmission> input);
 public void AddSnapshot(ISnapshot snapshot)
 {
     snapshots.Add(snapshot);
 }
Example #46
0
 public HomeController(ISnapshot snapshot)
 {
     this.Snapshot = snapshot;
 }
Example #47
0
 protected abstract void DoLoadFromSnapshot(ISnapshot snapshot);
Example #48
0
 ///GENMHASH:5BA6C6B418238F9AAD214C5F09B6E1CB:1EB84A49445D7528CE46D6A009A82F9E
 public DiskImpl FromSnapshot(ISnapshot snapshot)
 {
     return(FromSnapshot(snapshot.Id));
 }
 private static SnapshotContainer CreateSnapshotContainer(ISnapshot snapshot)
 {
     return(new SnapshotContainer(
                snapshot,
                new SnapshotMetadata()));
 }
Example #50
0
        private async Task OnRestoreSnapshotExecuteAsync(ISnapshot snapshot)
        {
            Log.Info($"Restoring snapshot '{snapshot}'");

            await _snapshotManager.RestoreSnapshotAsync(snapshot);
        }
Example #51
0
 public OriginalValues(InternalEntityEntry entry)
 {
     _values = ((EntityType)entry.EntityType).OriginalValuesFactory(entry);
 }
Example #52
0
 ///GENMHASH:317134690AC492A13AB6664204ABFD95:2CD52FED9DD80D3ACA7A05FE17CBFC89
 public VirtualMachineCustomImageImpl WithLinuxFromSnapshot(ISnapshot sourceSnapshot, OperatingSystemStateTypes osState)
 {
     return(this.WithLinuxFromSnapshot(sourceSnapshot.Id, osState));
 }
 public virtual SourceProperty <T> AddSourceTextNode([NotNull] ISnapshot snapshot)
 {
     return(AddAdditionalSourceTextNode(new FileNameTextNode(PathHelper.GetFileNameWithoutExtensions(snapshot.SourceFile.AbsoluteFileName), snapshot)));
 }
Example #54
0
 public void Eat(ISnapshot snapshot, IVariableDeclaration variableDeclaration)
 {
 }
 public override ExpressionKind Eat(ISnapshot snapshot, IQueryWhereClause queryClause)
 {
     return(ExpressionKind.None);
 }
Example #56
0
 public Task SaveAsync(ISnapshot snapshot, ProjectionVersion version)
 {
     return(Task.CompletedTask);
 }
 public FileNameTextNode([NotNull] string fileName, [NotNull] ISnapshot snapshot)
 {
     Value    = fileName;
     Snapshot = snapshot;
 }
Example #58
0
 public void BuildFromSnapshot(ISnapshot snapshot)
 {
     throw new NotImplementedException();
 }
Example #59
0
 public bool AddSnapshot(ISnapshot snapshot)
 {
     return(_original.AddSnapshot(snapshot));
 }
Example #60
0
 protected abstract void ApplySnapshot(ISnapshot snapshot);