public void TakeSnapshotPasses() { var data = new SnapshotData { value1 = 100, value2 = "Test", }; var stackFrame = new StackFrame(); System.Func <SnapshotData, SnapshotData, bool> validateSnapshot = (correct, got) => correct.AreSame(got); //Snapshotの作成のテスト DoTakeSnapshot = true; var snapshot = TakeOrValid(data, stackFrame, 0, validateSnapshot, "Failed to Take snapshot..."); Assert.AreSame(snapshot, LastSnapshot); var snapshotFilepath = CreateSnapshotFilepath(stackFrame); Assert.AreEqual(snapshot.GetAssetPath(), snapshotFilepath); Assert.IsTrue(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotFilepath), $"don't exist snapshot file... filepath='{snapshotFilepath}'"); var savedSnapshot = AssetDatabase.LoadAssetAtPath <Snapshot>(snapshotFilepath); AssertionUtils.AssertEnumerable(new[] { "snapshot" }, AssetDatabase.GetLabels(savedSnapshot), "想定したラベルが付けられていません。"); //Snapshotによる検証のテスト DoTakeSnapshot = false; Assert.DoesNotThrow(() => { var snap = TakeOrValid(data, stackFrame, 0, validateSnapshot, "Failed to Take snapshot..."); Assert.AreSame(snap, LastSnapshot); }); ReserveDeleteAssets(snapshotFilepath); }
Snapshot IOperationSource <Snapshot> .CreateResult(Response response, CancellationToken cancellationToken) { using var document = JsonDocument.Parse(response.ContentStream); var data = SnapshotData.DeserializeSnapshotData(document.RootElement); return(new Snapshot(_armClient, data)); }
public void SetSnapshot(SnapshotData snapshotData) { Dictionary <int, GameObject> copy = new Dictionary <int, GameObject>(playerInstances); foreach (var playerData in snapshotData.playerDatas) { if (playerInstances.ContainsKey(playerData.EntityID)) { playerInstances[playerData.EntityID].GetComponent <PlayerScript>().UpdateData(playerData); copy.Remove(playerData.EntityID); } else { GameObject newPlayerInstance = Instantiate(playerPrefab); newPlayerInstance.GetComponent <PlayerScript>().Init(playerData); playerInstances.Add(playerData.EntityID, newPlayerInstance); } } foreach (var remove in copy) { GameObject removeGameObject = playerInstances[remove.Key]; playerInstances.Remove(remove.Key); Destroy(removeGameObject); } }
private void AddMigration(string contextName, string version, MigrationData migration, string snapshot, bool createNew) { using (var context = this.contextService.Get <MigrationContext>()) { SnapshotData newSnapshot; if (createNew) { newSnapshot = new SnapshotData { Context = contextName }; context.Snapshots.Add(newSnapshot); } else { newSnapshot = context.Snapshots.Single(x => x.Context == contextName); } newSnapshot.Version = version; if (migration != null) { newSnapshot.Snapshot = snapshot; context.Migrations.Add(migration); } context.SaveChanges(); } }
/// <summary> /// 保存快照 /// </summary> public override Task Save(SnapshotData snapshot) { if (!_persistent) { return(base.Save(snapshot)); } var triggered = base.GetTriggeredVersion(snapshot.AggregateRootTypeCode); if (snapshot.Version % triggered != 0) { return(base.Save(snapshot)); } return(Task.Factory.StartNew(() => { using (var context = _dbContextFactory.CreateDataContext()) { bool exist = context.CreateQuery <SnapshotData>() .Any(entity => entity.AggregateRootId == snapshot.AggregateRootId && entity.AggregateRootTypeCode == snapshot.AggregateRootTypeCode); if (exist) { context.Update(snapshot); } else { context.Save(snapshot); } context.Commit(); } })); }
internal static SnapshotList DeserializeSnapshotList(JsonElement element) { IReadOnlyList <SnapshotData> value = default; Optional <string> nextLink = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("value")) { List <SnapshotData> array = new List <SnapshotData>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(SnapshotData.DeserializeSnapshotData(item)); } value = array; continue; } if (property.NameEquals("nextLink")) { nextLink = property.Value.GetString(); continue; } } return(new SnapshotList(value, nextLink.Value)); }
internal void CreateSnapshotData() { var binIds = new Dictionary <int, Tuple <int, int> >(); foreach (var propType in PropertyTypes) { if (propType.DataType == DataType.Binary) { var binValue = GetDynamicRawData(propType) as BinaryDataValue; if (binValue != null) { binIds.Add(propType.Id, new Tuple <int, int>(binValue.Id, binValue.FileId)); } } } _snapshotData = new SnapshotData { Id = this.Id, Path = this.Path, NodeTimestamp = this.NodeTimestamp, VersionId = this.VersionId, Version = this.Version, VersionTimestamp = this.VersionTimestamp, BinaryIds = binIds }; }
/// <inheritdoc/> protected override void ApplySnapshot(Message message) { if (message.Timestamp <= newestSnapshot.Timestamp) { return; } previousSnapshot = newestSnapshot; //Parse incoming snapshot newestSnapshot.LocalPosition = message.Content.PopDecompressedPosition(); var position = newestSnapshot.LocalPosition + transform.parent.position; newestSnapshot.Rotation = message.Content.PopDecompressedRotation(); newestSnapshot.Timestamp = message.Timestamp; switch (SimulationType) { case MockingSimulationType.ApplySnapshotsOnly: CachedRigidbody.position = position; CachedRigidbody.rotation = newestSnapshot.Rotation; break; case MockingSimulationType.ExtrapolateVelocities: if (message.Content.Count > 0) { newestSnapshot.Velocity = message.Content.PopDecompressedVector3(-200.0f, 200.0f, 2); newestSnapshot.AngularVelocity = message.Content.PopDecompressedVector3(-10.0f, 10.0f, 2); } break; default: throw new ArgumentOutOfRangeException(); } }
public SnapshotData ToNetworkModel() { SnapshotData data = new SnapshotData(); data.TickNum = this.Tick; data.Skeletons.AddRange(this.SkeletonStates.Select(x => x.Value.ToNetworkModel())); data.Objects.AddRange(this.ObjectStates.Select(x => x.Value.ToNetworkModel())); return(data); }
public void OnSuccess(SnapshotData snapshotData) { var msg = "AddSnapshot succeed. \n"; msg += string.Format( "snapshot id{0}, unique name{1}, player name:{2}, played time:{3}, progress value:{4}, desc:{5}, gameName:{6}", snapshotData.SnapshotId, snapshotData.UniqueName, snapshotData.Player != null ? snapshotData.Player.DisplayName : "", snapshotData.PlayedTime, snapshotData.ProgressValue, snapshotData.Description, snapshotData.Game != null ? snapshotData.Game.DisplayName : ""); Show(msg); snapshotId = snapshotData.SnapshotId; tempSnapshotData = snapshotData; }
public static SnapshotData AddDiff(this SnapshotData obj, SnapshotData diff) { Dictionary <ulong, Skeleton> tmpDict = obj.Skeletons.ToDictionary(x => x.UserId, x => x); SnapshotData retVal = new SnapshotData(); retVal.TickNum = diff.TickNum; retVal.Skeletons.AddRange( diff.Skeletons .Select(x => tmpDict.TryGetValue(x.UserId, out Skeleton val) ? x.Add(val) : x) ); retVal.Objects.AddRange(diff.Objects); return(retVal); }
public void RecordIsVisibleToItsCreator() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new int[] { }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); Assert.IsTrue(record.HasVisibleVersionTo(0)); }
public void VersionCreatedByCommitedTransactionIsVisible() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new[] { 0 }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); Assert.IsTrue(record.HasVisibleVersionTo(1)); }
public void ExpireOfUpdatedRecordProduceWriteConflict() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new int[] { }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); record.Update(new byte[] { 2, 3 }, 0); // zero transaction updates the record Assert.That(() => record.Expire(1), Throws.Exception.TypeOf <WriteConflictException>()); // first transaction trying to expire it }
public void ExpiredVersionIsInvisible() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new int[] { }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); record.Expire(0); Assert.IsFalse(record.HasVisibleVersionTo(0)); }
public void UpdateRecordCreatedByCommitedTransaction() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var newContent = new byte[] { 2, 3 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new[] { 0 }); // zero transaction is commited var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); record.Update(newContent, 1); Assert.IsTrue(newContent.SequenceEqual(record.GetMatchingVersion(1).RawData)); }
public IEnumerator CaptureScreenshotPasses() { var data = new SnapshotData { value1 = 100, value2 = "Test", }; var stackFrame = new StackFrame(); System.Func <SnapshotData, SnapshotData, bool> validateSnapshot = (correct, got) => correct.AreSame(got); //Snapshotの作成のテスト DoTakeSnapshot = true; var enumerator = TakeOrValidWithCaptureScreen(data, stackFrame, 0, validateSnapshot, "Failed to Take snapshot..."); while (enumerator.MoveNext()) { yield return(enumerator.Current); } Assert.IsNotNull(LastSnapshot); var snapshotFilepath = CreateSnapshotFilepath(stackFrame); Assert.IsTrue(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotFilepath)); var savedSnapshot = AssetDatabase.LoadAssetAtPath <Snapshot>(snapshotFilepath); Assert.AreEqual(savedSnapshot, LastSnapshot); AssertionUtils.AssertEnumerable(new[] { "snapshot" }, AssetDatabase.GetLabels(savedSnapshot), "想定したラベルが付けられていません。"); //Snapshotによる検証のテスト DoTakeSnapshot = false; enumerator = TakeOrValidWithCaptureScreen(data, stackFrame, 0, validateSnapshot, "Failed to Take snapshot..."); while (enumerator.MoveNext()) { yield return(enumerator.Current); } Assert.IsNotNull(LastSnapshot); var snapshotForTest = LastSnapshot; Assert.IsTrue(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotForTest.ScreenshotFilepath), $"検証用のスクリーンショットはAssetとして保存するようにしてください。assetPath={snapshotForTest.ScreenshotFilepath}"); Assert.AreEqual(Path.GetDirectoryName(savedSnapshot.GetAssetPath()), Path.GetDirectoryName(snapshotForTest.ScreenshotFilepath), $"検証用のスクリーンショットはSnapshotと同じディレクトリに保存するようにしてください"); Assert.IsFalse(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotForTest.ScreenshotFilepathAtTest), $"テスト用のスクリーンショットはAssetとしては保存しないでください. filepath={snapshotForTest.ScreenshotFilepathAtTest}"); FileAssert.Exists(snapshotForTest.ScreenshotFilepathAtTest, $"テスト用のスクリーンショットはAssetとしては保存しないでください. filepath={snapshotForTest.ScreenshotFilepathAtTest}"); ReserveDeleteAssets(snapshotForTest.ScreenshotFilepath, snapshotForTest.ScreenshotFilepathAtTest, Path.GetDirectoryName(snapshotFilepath)); }
public void UpdateProduceNewVersion() { var memoryManager = new MemoryManager(); var oldContent = new byte[] { 0, 1 }; var newContent = new byte[] { 2, 3 }; var recordReference = VersionedRecord.CreateNew(oldContent, 0, memoryManager); var snapshotData = new SnapshotData(new int[] { }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); record.Update(newContent, 0); Assert.IsTrue(record.HasVisibleVersionTo(0)); Assert.IsTrue(newContent.SequenceEqual(record.GetMatchingVersion(0).RawData)); }
public void ConcurrentlyRunningTransactionsViewTheirOwnVersions() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var newContent = new byte[] { 2, 3 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new[] { 0 }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); var newReference = record.InsertOrUpdate(newContent, 1); record = new VersionedRecord(memoryManager.Get(newReference).RawData, memoryManager, snapshotData); Assert.IsTrue(newContent.SequenceEqual(record.GetMatchingVersion(1).RawData)); Assert.IsTrue(content.SequenceEqual(record.GetMatchingVersion(2).RawData)); }
public void ResurrectRecordExpiredByCommitedTransaction() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var newContent = new byte[] { 2, 3 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new int[] { }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); var newReference = record.Expire(0); snapshotData = new SnapshotData(new[] { 0 }); record = new VersionedRecord(memoryManager.Get(newReference).RawData, memoryManager, snapshotData); record.Insert(newContent, 1); Assert.IsTrue(newContent.SequenceEqual(record.GetMatchingVersion(1).RawData)); }
public void UpdateRecordExpiredByRolledBackTransaction() { var memoryManager = new MemoryManager(); var content = new byte[] { 0, 1 }; var newContent = new byte[] { 2, 3 }; var recordReference = VersionedRecord.CreateNew(content, 0, memoryManager); var snapshotData = new SnapshotData(new[] { 0 }); var record = new VersionedRecord(memoryManager.Get(recordReference).RawData, memoryManager, snapshotData); var newReference = record.Expire(1); snapshotData = new SnapshotData(new[] { 0 }, new[] { 1 }); record = new VersionedRecord(memoryManager.Get(newReference).RawData, memoryManager, snapshotData); record.Update(newContent, 2); Assert.IsTrue(newContent.SequenceEqual(record.GetMatchingVersion(2).RawData)); }
public void InitData() { //Get all managed type names m_ManagedTypeNames = MakeSnapshotData(m_Snapshot.typeDescriptions.typeDescriptionName); m_ManagedFieldNames = MakeSnapshotData(m_Snapshot.fieldDescriptions.fieldDescriptionName); m_ManagedFieldOffsets = MakeSnapshotData(m_Snapshot.fieldDescriptions.offset); m_ManagedbaseOrElementTypeIndex = MakeSnapshotData(m_Snapshot.typeDescriptions.baseOrElementTypeIndex); m_ManagedTypeIndex = MakeSnapshotData(m_Snapshot.typeDescriptions.typeIndex); m_NativeObject_InstanceID = MakeSnapshotData(m_Snapshot.nativeObjects.instanceId); m_NativeObject_Address = MakeSnapshotData(m_Snapshot.nativeObjects.nativeObjectAddress); m_NativeObject_Name = MakeSnapshotData(m_Snapshot.nativeObjects.objectName); m_ManagedHeapSectionsByte = MakeSnapshotData(m_Snapshot.managedHeapSections.bytes); m_ManagedHeapSectionsStartAddress = MakeSnapshotData(m_Snapshot.managedHeapSections.startAddress); m_gcHandlesTarget = MakeSnapshotData(m_Snapshot.gcHandles.target); m_managedTypeInfo = MakeSnapshotData(m_Snapshot.typeDescriptions.typeInfoAddress); m_managedTypeFieldIndex = MakeSnapshotData(m_Snapshot.typeDescriptions.fieldIndices); m_ConnectionFrom = MakeSnapshotData(m_Snapshot.connections.from); m_ConnectionTo = MakeSnapshotData(m_Snapshot.connections.to); m_NativeType_Name = MakeSnapshotData(m_Snapshot.nativeTypes.typeName); m_NativeObject_TypeIndex = MakeSnapshotData(m_Snapshot.nativeObjects.nativeTypeArrayIndex); // Find Unity object m_UnityEngineObject_TypeIndex = m_ManagedTypeNames.FindIndex(x => x == "UnityEngine.Object"); if (m_UnityEngineObject_TypeIndex < 0) { throw new Exception("No Unity Object!"); } //Get Unity Object field index int[] UnityObjectFields = m_managedTypeFieldIndex[m_UnityEngineObject_TypeIndex]; //Find UnityEngine.Object.m_InstanceID field int iField_UnityEngineObject_m_InstanceID = System.Array.FindIndex(UnityObjectFields, iField => m_ManagedFieldNames[iField] == "m_InstanceID"); m_UnityEngineObject_instanceIDOffset = -1; m_UnityEngineObject_cachedPtrOffset = -1; if (iField_UnityEngineObject_m_InstanceID >= 0) { //Get m_InstanceID offset if valid var fieldIndex = UnityObjectFields[iField_UnityEngineObject_m_InstanceID]; m_UnityEngineObject_instanceIDOffset = m_ManagedFieldOffsets[fieldIndex]; } if (m_UnityEngineObject_instanceIDOffset < 0) { // on UNITY_5_4_OR_NEWER, there is the member m_CachedPtr we can use to identify the connection //Since Unity 5.4, UnityEngine.Object no longer stores instance id inside when running in the player. Use cached ptr instead to find the instanceID of native object int iField_UnityEngineObject_m_CachedPtr = System.Array.FindIndex(UnityObjectFields, iField => m_ManagedFieldNames[iField] == "m_CachedPtr"); if (iField_UnityEngineObject_m_CachedPtr >= 0) { m_UnityEngineObject_cachedPtrOffset = m_ManagedFieldOffsets[iField_UnityEngineObject_m_CachedPtr]; } } if (m_UnityEngineObject_instanceIDOffset < 0 && m_UnityEngineObject_cachedPtrOffset < 0) { throw new Exception("Could not find unity object instance id field or m_CachedPtr"); } // init m_NativeInstanceID to native object index m_NativeObjectInstanceID_ToIndex = new SortedDictionary <int, int>(); for (int i = 0; i != m_NativeObject_InstanceID.Length; ++i) { var id = m_NativeObject_InstanceID[i]; m_NativeObjectInstanceID_ToIndex[id] = i; } m_ManagedTypeIndex_ToTypeDescription = new SortedDictionary <int, int>(); for (int i = 0; i != m_ManagedTypeIndex.Length; ++i) { var index = m_ManagedTypeIndex[i]; if (index != i) { Debug.Log("TypeIndex is not index in array"); } m_ManagedTypeIndex_ToTypeDescription[index] = i; } m_ManagedTypeInfo_ToTypeDescription = new SortedDictionary <ulong, int>(); for (int i = 0; i != m_managedTypeInfo.Length; ++i) { ulong tinfo = m_managedTypeInfo[i]; m_ManagedTypeInfo_ToTypeDescription[tinfo] = i; } }
public bool AreSame(SnapshotData other) { return(value1 == other.value1 && value2 == other.value2); }
private void SetElements(SnapshotData data) { titleText.text = data.title; leftImage.sprite = data.left; rightImage.sprite = data.right; }
// for the unity editor public void Reset() { options.Reset(); data = new SnapshotData(); capturedTimestamp = 0; }
private void DrawSnapshotCurve(SnapshotData snapshotData, ref int colorIndex) { foreach (CurveData data in snapshotData.CurveDataList) { this.DrawCurve(snapshotData.Name, data, ref colorIndex); } }
void SnapshotHandler(byte[] data) { SnapshotData snapshotData = MessagePackSerializer.Deserialize <SnapshotData>(data); unitManager.SetSnapshot(snapshotData); }
/// <summary> /// 保存聚合事件。 /// </summary> public void Save(IEventSourced aggregateRoot, string correlationId = null) { var events = aggregateRoot.GetEvents(); if (events.IsEmpty()) { return; } var aggregateRootType = aggregateRoot.GetType(); int aggregateRootTypeCode = _typeCodeProvider.GetTypeCode(aggregateRootType); string aggregateRootId = aggregateRoot.Id.ToString(); if (!_eventStore.IsExist(correlationId)) { var sourcedEvents = events.Select(@event => new EventData() { AggregateRootId = aggregateRootId, AggregateRootTypeCode = aggregateRootTypeCode, Version = @event.Version, CorrelationId = correlationId, Payload = _serializer.Serialize(@event) }).ToArray(); _eventStore.Append(sourcedEvents); _logger.Info("sourcing events persistent completed. aggregateRootId:{0},aggregateRootType:{1}.", aggregateRootId, aggregateRootType.FullName); _cache.Set(aggregateRoot, aggregateRoot.Id); } else { events = _eventStore.FindAll(correlationId).Select(Deserialize); _logger.Info("the command generates events have been saved, load from storage. command id:{0}", correlationId); } _eventBus.Publish(new EventStream { AggregateRootId = aggregateRootId, AggregateRootTypeCode = aggregateRootTypeCode, CommandId = correlationId, StartVersion = events.Min(item => item.Version), EndVersion = events.Max(item => item.Version), Events = events.OfType <IEvent>().ToArray() }); _logger.Info("publish all events. event ids: [{0}]", string.Join(",", events.Select(@event => @event.Id).ToArray())); if (_snapshotStore.StorageEnabled) { var snapshot = new SnapshotData(aggregateRootTypeCode, aggregateRootId) { Data = _serializer.Serialize(aggregateRoot), Version = aggregateRoot.Version }; _snapshotStore.Save(snapshot).ContinueWith(task => { if (task.Status == TaskStatus.Faulted) { _logger.Error(task.Exception, "snapshot persistent failed. aggregateRootId:{0},aggregateRootType:{1},version:{2}.", aggregateRootId, aggregateRootType.FullName, aggregateRoot.Version); } }); //Task.Factory.StartNew(() => { // try { // _snapshotStore.Save(snapshot); // } // catch (Exception ex) { // _logger.Error(ex, "snapshot persistent failed. aggregateRootId:{0},aggregateRootType:{1},version:{2}.", aggregateRootId, aggregateRootType.FullName, aggregateRoot.Version); // } //}); } }