public void Example() { var others = new OtherData[] { new OtherData(), new OtherData() }; var data = new ExampleData(); data.otherData = others; data.otherExample = new ExampleData(); data.otherExample.otherData = others; data.otherExample.otherExample = data; string blob = BlobSerializer.Serialize(data); Debug.Log("Blob:\n" + blob); ExampleData deserializedData; if (BlobSerializer.Deserialize <ExampleData>(blob).TryGet(out deserializedData)) { Debug.LogFormat("integer = {0}", deserializedData.integer); Debug.LogFormat("number = {0}", deserializedData.number); Debug.LogFormat("boolean = {0}", deserializedData.boolean); Debug.LogFormat("text = {0}", deserializedData.text); Debug.LogFormat("abc = {0}", deserializedData.abc.ToStringFull()); Debug.LogFormat("other = {0}", deserializedData.otherData.ToStringFull()); Debug.LogFormat("OHTER integer = {0}", deserializedData.otherExample.integer); Debug.LogFormat("OHTER number = {0}", deserializedData.otherExample.number); Debug.LogFormat("OHTER boolean = {0}", deserializedData.otherExample.boolean); Debug.LogFormat("OHTER text = {0}", deserializedData.otherExample.text); Debug.LogFormat("OHTER abc = {0}", deserializedData.otherExample.abc.ToStringFull()); Debug.LogFormat("OHTER other = {0}", deserializedData.otherExample.otherData.ToStringFull()); } }
/// <summary> /// Retrieves the value of the given key, if present. Value is deserialized using given /// custom serializer. /// </summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="session">The session.</param> /// <param name="serializer">The custom serializer.</param> /// <param name="key">The key.</param> /// <returns>An optional cache result which contains result value, if any.</returns> public static CacheResult <T> GetObject <T>(this ISession session, ISerializer serializer, string key) { if (session.TryGetValue(key, out var serializedBytes)) { using (var serializedStream = new PooledMemoryStream(serializedBytes)) { return(BlobSerializer.Deserialize <T>(serializer, serializedStream)); } } return(default(CacheResult <T>)); }
public void DeserializeAfterAddingDataMember() { var s = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Integration.Common.UserDTO, Tp.Integration.Messages</Type> <Version>2</Version> <string>{""__type"":""UserDTO:#Tp.Integration.Common"",""<ID>k__BackingField"":null,""<ActiveDirectoryName>k__BackingField"":null,""<AvailableFrom>k__BackingField"":null,""<AvailableFutureAllocation>k__BackingField"":0,""<AvailableFutureHours>k__BackingField"":0.0000,""<CreateDate>k__BackingField"":""\/Date(1361685600000+0300)\/"",""<CurrentAllocation>k__BackingField"":100,""<CurrentAvailableHours>k__BackingField"":0.0000,""<DefaultRoleName>k__BackingField"":""Support Person"",""<DeleteDate>k__BackingField"":null,""<Email>k__BackingField"":""*****@*****.**"",""<FirstName>k__BackingField"":""Tod"",""<IsActive>k__BackingField"":false,""<IsAdministrator>k__BackingField"":false,""<IsObserver>k__BackingField"":false,""<LastName>k__BackingField"":""Black"",""<Login>k__BackingField"":""*****@*****.**"",""<ModifyDate>k__BackingField"":""\/Date(1361685600000+0300)\/"",""<Password>k__BackingField"":""1846175709"",""<RoleID>k__BackingField"":6,""<Skills>k__BackingField"":null,""<UserID>k__BackingField"":4,""<WeeklyAvailableHours>k__BackingField"":40.0000}</string> </Value>"; var user = BlobSerializer.Deserialize(XDocument.Parse(s), "Tp.Integration.Common.UserDTO, Tp.Integration.Messages") as UserDTO; user.UserID.Should(Be.EqualTo(4)); }
public void DeserializeAfterCustomFieldsModifications() { var s = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Integration.Common.ProjectDTO, Tp.Integration.Messages</Type> <Version>2</Version> <string>{""__type"":""ProjectDTO:#Tp.Integration.Common"",""ID"":13,""Abbreviation"":""TPW"",""CompanyID"":null,""CreateDate"":""\/Date(1372312800000+0300)\/"",""CustomField1"":null,""CustomField10"":null,""CustomField11"":null,""CustomField12"":null,""CustomField13"":null,""CustomField14"":null,""CustomField15"":null,""CustomField16"":null,""CustomField17"":null,""CustomField18"":null,""CustomField19"":null,""CustomField2"":null,""CustomField20"":null,""CustomField21"":null,""CustomField22"":null,""CustomField23"":null,""CustomField24"":null,""CustomField25"":null,""CustomField26"":null,""CustomField27"":null,""CustomField28"":null,""CustomField29"":null,""CustomField3"":null,""CustomField30"":null,""CustomField31"":null,""CustomField32"":null,""CustomField33"":null,""CustomField34"":null,""CustomField35"":null,""CustomField36"":null,""CustomField37"":null,""CustomField38"":null,""CustomField39"":null,""CustomField4"":null,""CustomField40"":null,""CustomField41"":null,""CustomField42"":null,""CustomField43"":null,""CustomField44"":null,""CustomField45"":null,""CustomField46"":null,""CustomField47"":null,""CustomField48"":null,""CustomField49"":null,""CustomField5"":null,""CustomField50"":null,""CustomField51"":null,""CustomField52"":null,""CustomField53"":null,""CustomField54"":null,""CustomField55"":null,""CustomField56"":null,""CustomField57"":null,""CustomField58"":null,""CustomField59"":null,""CustomField6"":null,""CustomField60"":null,""CustomField7"":null,""CustomField8"":null,""CustomField9"":null,""CustomFieldsMetaInfo"":[{""<EntityFieldName>k__BackingField"":""CustomField1"",""<FieldType>k__BackingField"":6,""<Items>k__BackingField"":[],""<Name>k__BackingField"":""cfnumber"",""<Required>k__BackingField"":false,""<Value>k__BackingField"":null}],""DeleteDate"":null,""Description"":null,""EndDate"":null,""EntityTypeName"":""Tp.BusinessObjects.Project"",""InboundMailAutoCheck"":false,""InboundMailAutomaticalEmailCheckTime"":0,""InboundMailCreateRequests"":false,""InboundMailLogin"":null,""InboundMailPassword"":null,""InboundMailPort"":110,""InboundMailProtocol"":null,""InboundMailReplyAddress"":null,""InboundMailServer"":null,""InboundMailUseSSL"":false,""IsActive"":true,""IsInboundMailEnabled"":false,""IsProduct"":false,""LastCommentDate"":null,""LastCommentUserID"":null,""LastEditorID"":2,""ModifyDate"":""\/Date(1372312800000+0300)\/"",""Name"":""Tau Product Web Site - Scrum #1"",""NumericPriority"":2,""OwnerID"":2,""ParentProjectID"":null,""ParentProjectName"":null,""ProcessID"":3,""ProcessName"":""Scrum"",""ProgramOfProjectID"":1,""ProgramOfProjectName"":""tauLine #1"",""ProjectID"":13,""SCConnectionString"":null,""SCPassword"":null,""SCStartingRevision"":null,""SCUser"":null,""SourceControlType"":0,""StartDate"":""\/Date(1372312800000+0300)\/""}</string> </Value>"; var project = BlobSerializer.Deserialize(XDocument.Parse(s), "Tp.Integration.Common.ProjectDTO, Tp.Integration.Messages") as ProjectDTO; project.ProjectID.Should(Be.EqualTo(13)); }
public void DeserializeGeneralProjectChangedSagaDataAfterAddingFields() { const string oldSaga = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Search.Bus.Workflow.GeneralProjectChangeSagaData, Tp.Search</Type> <Version>2</Version> <string>{""__type"":""GeneralProjectChangeSagaData:#Tp.Search.Bus.Workflow"",""CommentsCurrentDataWindowSize"":0,""CommentsRetrievedCount"":0,""GeneralId"":147,""Id"":""534a26de-645c-4e66-9f83-a43b0152e933"",""OriginalMessageId"":""9753de6d-3e2d-4d1b-9b60-8d449f5592cc\\3914349"",""Originator"":""Tp.Search@D-KANASHEVICH"",""ProjectId"":13}</string> </Value>"; var deserialized = (GeneralProjectChangeSagaData)BlobSerializer.Deserialize(XDocument.Parse(oldSaga), string.Empty); deserialized.ProjectId.Should(Be.EqualTo(13)); deserialized.TestStepsRetrievedCount.Should(Be.EqualTo(0)); }
public void DeserializeAfterAdding60CustomFields() { const string s = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Integration.Common.ProjectDTO, Tp.Integration.Messages</Type> <Version>2</Version> <string>{""__type"":""ProjectDTO:#Tp.Integration.Common"",""<ID>k__BackingField"":null,""<Abbreviation>k__BackingField"":""TPW"",""<CompanyID>k__BackingField"":null,""<CreateDate>k__BackingField"":""\/Date(1360821600000+0300)\/"",""<CustomField10>k__BackingField"":null,""<CustomField11>k__BackingField"":null,""<CustomField12>k__BackingField"":null,""<CustomField13>k__BackingField"":null,""<CustomField14>k__BackingField"":null,""<CustomField15>k__BackingField"":null,""<CustomField1>k__BackingField"":null,""<CustomField2>k__BackingField"":null,""<CustomField3>k__BackingField"":null,""<CustomField4>k__BackingField"":null,""<CustomField5>k__BackingField"":null,""<CustomField6>k__BackingField"":null,""<CustomField7>k__BackingField"":null,""<CustomField8>k__BackingField"":null,""<CustomField9>k__BackingField"":null,""<DeleteDate>k__BackingField"":null,""<Description>k__BackingField"":null,""<EndDate>k__BackingField"":null,""<EntityTypeName>k__BackingField"":""Tp.BusinessObjects.Project"",""<InboundMailAutoCheck>k__BackingField"":false,""<InboundMailAutomaticalEmailCheckTime>k__BackingField"":0,""<InboundMailCreateRequests>k__BackingField"":false,""<InboundMailLogin>k__BackingField"":null,""<InboundMailPassword>k__BackingField"":null,""<InboundMailPort>k__BackingField"":110,""<InboundMailProtocol>k__BackingField"":null,""<InboundMailReplyAddress>k__BackingField"":null,""<InboundMailServer>k__BackingField"":null,""<InboundMailUseSSL>k__BackingField"":false,""<IsActive>k__BackingField"":true,""<IsInboundMailEnabled>k__BackingField"":false,""<IsProduct>k__BackingField"":false,""<LastCommentDate>k__BackingField"":null,""<LastCommentUserID>k__BackingField"":null,""<LastEditorID>k__BackingField"":1,""<ModifyDate>k__BackingField"":""\/Date(1365165112000+0300)\/"",""<Name>k__BackingField"":""Tau Product Web Site - Scrum #1"",""<NumericPriority>k__BackingField"":2,""<OwnerID>k__BackingField"":2,""<ParentProjectID>k__BackingField"":null,""<ParentProjectName>k__BackingField"":null,""<ProcessID>k__BackingField"":3,""<ProcessName>k__BackingField"":""Scrum"",""<ProgramOfProjectID>k__BackingField"":1,""<ProgramOfProjectName>k__BackingField"":""tauLine #1"",""<ProjectID>k__BackingField"":13,""<SCConnectionString>k__BackingField"":null,""<SCPassword>k__BackingField"":null,""<SCStartingRevision>k__BackingField"":null,""<SCUser>k__BackingField"":null,""<SourceControlType>k__BackingField"":0,""<StartDate>k__BackingField"":""\/Date(1360821600000+0300)\/""}</string> </Value>"; var project = BlobSerializer.Deserialize(XDocument.Parse(s), "Tp.Integration.Common.ProjectDTO, Tp.Integration.Messages") as ProjectDTO; project.ID.Should(Be.EqualTo(13)); project.CustomFieldsMetaInfo.Should(Be.Null); }
public void DeserializeProjectProcessChangedSagaDataAfterAddingFields() { const string oldSaga = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Search.Bus.Workflow.ProjectProcessChangedSagaData, Tp.Search</Type> <Version>2</Version> <string>{""__type"":""ProjectProcessChangedSagaData:#Tp.Search.Bus.Workflow"",""Id"":""00000000-0000-0000-0000-000000000000"",""OriginalMessageId"":null,""Originator"":null,""ProjectId"":1,""SkipGenerals"":10}</string> </Value>"; var deserialized = (ProjectProcessChangedSagaData)BlobSerializer.Deserialize(XDocument.Parse(oldSaga), string.Empty); deserialized.ProjectId.Should(Be.EqualTo(1)); deserialized.AssignablesRetrievedCount.Should(Be.EqualTo(0)); }
public void Test() { const string oldSaga = "<Value xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Type>Tp.Search.Bus.Workflow.IndexExistingEntitiesSagaData, Tp.Search</Type><Version>2</Version><string>{\"__type\":\"IndexExistingEntitiesSagaData:#Tp.Search.Bus.Workflow\",\"<CommentsRetrievedCount>k__BackingField\":0,\"<GeneralsRetrievedCount>k__BackingField\":0,\"<Id>k__BackingField\":\"4981ab85-8f0d-4a37-aa0b-a1c0010f88f0\",\"<OriginalMessageId>k__BackingField\":\"15a0e019-ace7-42b5-bc7d-f969c7270432\\1842090\",\"<Originator>k__BackingField\":\"Tp.Search@SHOTKIN\",\"<OuterSagaId>k__BackingField\":\"95a6b77a-1b9a-49cb-8e7c-a1c0010f8429\",\"<SkipComments>k__BackingField\":0,\"<SkipGenerals>k__BackingField\":30}</string></Value>\""; var path = new IndexExistingEntitiesSagaPreviousVersionCorrecter(); path.NeedToApply(oldSaga).Should(Be.True); var text = path.Apply(oldSaga); var deserialized = BlobSerializer.Deserialize(XDocument.Parse(text), string.Empty); var typed = deserialized as IndexExistingEntitiesSagaData; typed.Should(Be.Not.Null); typed.Id.Should(Be.EqualTo(Guid.Parse("4981ab85-8f0d-4a37-aa0b-a1c0010f88f0"))); }
public void BlobSerializerTest() { var res = BlobSerializer.Serialize(new TestSagaData { TestValue = "testValue" }); res.Should(Be.Not.Null); var des = BlobSerializer.Deserialize(res, typeof(ISagaEntity).Name); des.Should(Be.Not.Null); des.Should(Be.TypeOf <TestSagaData>()); ((TestSagaData)des).TestValue.Should(Be.EqualTo("testValue")); }
public void AttachToEntitySaga() { const string oldXml = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Subversion.Workflow.AttachToEntitySagaData, Tp.Subversion</Type> <Version>2</Version> <string>{""__type"":""AttachToEntitySagaData:#Tp.Subversion.Workflow"",""EntityId"":0,""Id"":""c2afc097-6ea3-4a0e-8170-9fb400bb8bbe"",""OriginalMessageId"":""b4a0874e-6a92-4920-8e29-bea29a8ff361\\5498359"",""Originator"":""Tp.SubversionIntegration@TRUHTANOV"",""RevisionDto"":{""<ID>k__BackingField"":null,""<AuthorID>k__BackingField"":null,""<CommitDate>k__BackingField"":null,""<Description>k__BackingField"":null,""<PluginProfileID>k__BackingField"":null,""<ProjectID>k__BackingField"":null,""<ProjectName>k__BackingField"":null,""<RevisionID>k__BackingField"":1,""<SourceControlID>k__BackingField"":null}}</string> </Value> "; var result = BlobSerializer.Deserialize(XDocument.Parse(oldXml), new TypeNameWithoutVersion(typeof(AttachToEntitySagaData)).Value) as AttachToEntitySagaData; result.Id.ToString().Should(Be.EqualTo("c2afc097-6ea3-4a0e-8170-9fb400bb8bbe")); result.RevisionDto.ID.Should(Be.EqualTo(1)); }
public void RevisionRangeInProfileStorage() { const string oldXml = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Subversion.VersionControlSystem.RevisionRange, Tp.Subversion</Type> <Version>2</Version> <string>{""__type"":""RevisionRange:#Tp.Subversion.VersionControlSystem"",""FromChangeset"":{""__type"":""SvnRevisionId:#Tp.Subversion.Subversion"",""_value"":1},""ToChangeset"":{""__type"":""SvnRevisionId:#Tp.Subversion.Subversion"",""_value"":2}}</string> </Value> "; var result = BlobSerializer.Deserialize(XDocument.Parse(oldXml), new TypeNameWithoutVersion(typeof(RevisionRange)).Value) as RevisionRange; result.FromChangeset.Value.Should(Be.EqualTo("1")); result.ToChangeset.Value.Should(Be.EqualTo("2")); }
public void DeserializeAllDtos() { var assembly = Assembly.GetAssembly(typeof(ProjectDTO)); Directory.GetFiles("SerializedDtos") .ForEach(fileName => { var file = new FileInfo(fileName); var type = assembly.GetType("Tp.Integration.Common." + file.Name + "DTO") ?? assembly.GetType("Tp.Integration.Messages.Entities." + file.Name + "DTO"); using (var reader = file.OpenRead()) { var xml = XDocument.Load(reader); var dto = BlobSerializer.Deserialize(xml, type.Name); dto.Should(Be.Not.Null); } }); }
public void CreateRevisionSaga() { const string oldXml = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Subversion.Workflow.CreateRevisionSagaData, Tp.Subversion</Type> <Version>2</Version> <string>{""__type"":""CreateRevisionSagaData:#Tp.Subversion.Workflow"",""<Id>k__BackingField"":""baf1a9ae-b874-44ea-827d-9fb400b48a78"",""<OriginalMessageId>k__BackingField"":""b4a0874e-6a92-4920-8e29-bea29a8ff361\\5498259"",""<Originator>k__BackingField"":""Tp.SubversionIntegration@TRUHTANOV"",""<RevisionEntries>k__BackingField"":[{""Action"":3,""Path"":""\/New\/test.txt""}],""<RevisionFilesCreated>k__BackingField"":0,""<RevisionId>k__BackingField"":0}</string> </Value> "; var result = BlobSerializer.Deserialize(XDocument.Parse(oldXml), new TypeNameWithoutVersion(typeof(CreateRevisionSagaData)).Value) as CreateRevisionSagaData; result.Id.ToString().Should(Be.EqualTo("baf1a9ae-b874-44ea-827d-9fb400b48a78")); result.RevisionId.Should(Be.EqualTo(0)); result.RevisionFilesCreated.Should(Be.EqualTo(0)); result.RevisionEntries[0].Action.Should(Be.EqualTo(FileActionEnum.Modify)); result.RevisionEntries[0].Path.Should(Be.EqualTo(@"/New/test.txt")); }
public void EnsureXmlSerializerAppliedToOldSerializedData() { const string toDeserialize = @"<Value xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <Type>Tp.Integration.Plugin.Common.Tests.Common.SagaPersister.TestSagaData, Tp.Integration.Plugin.Common.Tests</Type> <TestSagaData> <TestValue>testValue</TestValue> <Id>00000000-0000-0000-0000-000000000000</Id> </TestSagaData> </Value>" ; var toDeserializeXml = XDocument.Parse(toDeserialize); var profile = BlobSerializer.Deserialize(toDeserializeXml, typeof(ISagaEntity).Name); var typedProfile = profile as TestSagaData; typedProfile.Id.Should(Be.EqualTo(Guid.Empty)); typedProfile.TestValue.Should(Be.EqualTo("testValue")); }
public IMessage Retrieve() { return((IMessage)BlobSerializer.Deserialize(_serializedMsg, _type)); }
private object GetValueDeserialized() { _value = BlobSerializer.Deserialize(ValueBlob, ValueKey); GetValueInt = GetValueCached; return(_value); }
public T DeserializeAs <T>() { return((T)BlobSerializer.Deserialize(SagaEntity, typeof(T).Name)); }
public void ShouldThrowExceptionIfNoSerializersApplied() { var toDeserialize = XDocument.Parse("<SomeTag>Value</SomeTag>"); BlobSerializer.Deserialize(toDeserialize, typeof(ISagaEntity).Name); }