public async Task VeryLargeRuntimeStateConverterTest() { string veryLargeInput = TestUtils.GenerateRandomString(20 * 1024); OrchestrationRuntimeState newOrchestrationRuntimeStateLarge = generateOrchestrationRuntimeState(veryLargeInput); var runtimeState = new OrchestrationRuntimeState(); DataConverter dataConverter = new JsonDataConverter(); // test for very large size runtime state that cannot be saved externally: should throw exception try { Stream rawStreamVeryLarge = await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateLarge, runtimeState, dataConverter, true, this.serviceBusSessionSettings, this.azureStorageBlobStore, SessionId); Utils.UnusedParameter(rawStreamVeryLarge); Assert.Fail("ArgumentException must be thrown"); } catch (OrchestrationException e) { // expected Assert.IsTrue(e.Message.Contains("exceeded"), "Exception must contain exceeded."); } }
public void PackageUpgradeCompatibilityDeserializationTest() { var dataConverter = new JsonDataConverter(); string serialized = File.ReadAllText(@"TestData\v1.0\SerializedTaskMessage.json"); var message = dataConverter.Deserialize <TaskMessage>(serialized); Assert.IsNotNull(message); serialized = File.ReadAllText(@"TestData\v1.0\SerializedOrchestrationStateNoTags.json"); var state = dataConverter.Deserialize <OrchestrationState>(serialized); Assert.IsNotNull(state); serialized = File.ReadAllText(@"TestData\v1.0\SerializedRuntimeState.json"); var runtimeState = dataConverter.Deserialize <OrchestrationRuntimeState>(serialized); Assert.IsNotNull(runtimeState); serialized = File.ReadAllText(@"TestData\vnext\SerializedExecutionStartedEvent.json"); var executionStarted = dataConverter.Deserialize <ExecutionStartedEvent>(serialized); Assert.IsNotNull(executionStarted); serialized = File.ReadAllText(@"TestData\vnext\SerializedStateWithTags.json"); state = dataConverter.Deserialize <OrchestrationState>(serialized); Assert.IsNotNull(state); }
public void SerializeEnum() { // Verify that Enum values serialize correctly. var converter = new JsonDataConverter(); byte[] contents; string json; // Verify that an enum type with custom [EnumMemver] values // serializes as expected. var enumValue = new EnumEntity() { Gender = Gender.Male }; contents = converter.ToData(enumValue); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"male\"}", json); // Verify that an enum type without custom [EnumMemver] values // serializes as expected. var enumNotCustomValue = new EnumNotCustomEntity() { Gender = GenderNotCustom.Male }; contents = converter.ToData(enumNotCustomValue); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"Male\"}", json); }
public void JsonDataConverter_deserializedUnits() { string Testunits = "[{ \"units\":[\"0000A1,test01\",\"0000A2,test02\",\"0000A3,test03\",\"0000A4,null\"]}]"; string expectedoutput_01 = "0000A1,test01"; string expectedoutput_02 = "0000A2,test02"; string expectedoutput_03 = "0000A3,test03"; string expectedoutput_04 = "0000A4,null"; int expectedoutputcount = 3; List <Userunits> unitsWithNull = JsonDataConverter.deserializedUnits(Testunits, false); List <Userunits> unitsWithOutNull = JsonDataConverter.deserializedUnits(Testunits, true); string[] unitsarray = new string[unitsWithNull.Count]; for (int i = 0; i < unitsWithNull.Count; i++) { unitsarray[i] = unitsWithNull[i].id + "," + unitsWithNull[i].name; } Assert.AreEqual(expectedoutput_01, unitsarray[0]); Assert.AreEqual(expectedoutput_02, unitsarray[1]); Assert.AreEqual(expectedoutput_03, unitsarray[2]); Assert.AreEqual(expectedoutput_04, unitsarray[3]); Assert.AreEqual(expectedoutputcount, unitsWithOutNull.Count); }
public async Task ConverterCompatibilityTest() { var smallInput = "abc"; OrchestrationRuntimeState newOrchestrationRuntimeStateSmall = generateOrchestrationRuntimeState(smallInput); DataConverter dataConverter = new JsonDataConverter(); // deserialize a OrchestrationRuntimeState object, with both compression and not compression Stream stream = serializeToStream(dataConverter, newOrchestrationRuntimeStateSmall, true); OrchestrationRuntimeState convertedRuntimeStateSmall = await RuntimeStateStreamConverter.RawStreamToRuntimeState(stream, "sessionId", null, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall); stream = serializeToStream(dataConverter, newOrchestrationRuntimeStateSmall, false); convertedRuntimeStateSmall = await RuntimeStateStreamConverter.RawStreamToRuntimeState(stream, "sessionId", null, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall); // deserialize a IList<HistoryEvent> object, with both compression and not compression Stream stream2 = serializeToStream(dataConverter, newOrchestrationRuntimeStateSmall.Events, true); OrchestrationRuntimeState convertedRuntimeStateSmall2 = await RuntimeStateStreamConverter.RawStreamToRuntimeState(stream2, "sessionId", null, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall2); stream2 = serializeToStream(dataConverter, newOrchestrationRuntimeStateSmall.Events, false); convertedRuntimeStateSmall2 = await RuntimeStateStreamConverter.RawStreamToRuntimeState(stream2, "sessionId", null, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall2); }
/// <summary> /// Function for login fase used by Enterkey event and Login butten event /// </summary> private void login() { if (string.IsNullOrEmpty(tb_mail.Text) || string.IsNullOrEmpty(pb_password.Password) || string.IsNullOrEmpty(tb_mail.Text) && string.IsNullOrEmpty(pb_password.Password)) { MessageBox.Show("Please fill out username and password"); } else { if (tb_password.Visibility == Visibility.Visible) { pb_password.Password = tb_password.Text; } string JSONapikey = HttpApiRequest.ClimateLogin(tb_mail.Text, pb_password.Password); if (string.IsNullOrEmpty(JSONapikey)) { MessageBox.Show("Wrong username or password"); } else { UserInformation.ApiKey = JsonDataConverter.deserializedApikey(JSONapikey); UserInformation.Mail = tb_mail.Text; UserInformation.Password = pb_password.Password; Climate c = new Climate(); c.Show(); Close(); } } }
public async Task LargeRuntimeStateConverterTest() { string largeInput = TestUtils.GenerateRandomString(5 * 1024); OrchestrationRuntimeState newOrchestrationRuntimeStateLarge = generateOrchestrationRuntimeState(largeInput); var runtimeState = new OrchestrationRuntimeState(); DataConverter dataConverter = new JsonDataConverter(); // a large runtime state that needs external storage. Stream rawStreamLarge = await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateLarge, runtimeState, dataConverter, true, this.serviceBusSessionSettings, this.azureStorageBlobStore, SessionId); OrchestrationRuntimeState convertedRuntimeStateLarge = await RuntimeStateStreamConverter.RawStreamToRuntimeState(rawStreamLarge, "sessionId", this.azureStorageBlobStore, dataConverter); verifyEventInput(largeInput, convertedRuntimeStateLarge); // test for un-compress case string largeInput2 = TestUtils.GenerateRandomString(3 * 1024); OrchestrationRuntimeState newOrchestrationRuntimeStateLarge2 = generateOrchestrationRuntimeState(largeInput2); Stream rawStreamLarge2 = await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateLarge2, runtimeState, dataConverter, false, this.serviceBusSessionSettings, this.azureStorageBlobStore, SessionId); OrchestrationRuntimeState convertedRuntimeStateLarge2 = await RuntimeStateStreamConverter.RawStreamToRuntimeState(rawStreamLarge2, "sessionId", this.azureStorageBlobStore, dataConverter); verifyEventInput(largeInput2, convertedRuntimeStateLarge2); // test for an un-implemented (or null) IBlobStorage for large runtime states: should throw exception try { await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateLarge, runtimeState, dataConverter, true, this.serviceBusSessionSettings, null, SessionId); Assert.Fail("ArgumentException must be thrown"); } catch (OrchestrationException e) { // expected Assert.IsTrue(e.Message.Contains("IOrchestrationServiceBlobStore"), "Exception must contain IOrchestrationServiceBlobStore."); } }
public void JsonDataConverter_deserializedApikey() { string Testapikey = "[{\"userapi\":\"testapikey\"}]"; string expectedoutput = "testapikey"; string key = JsonDataConverter.deserializedApikey(Testapikey); Assert.AreEqual(expectedoutput, key); }
public void JsonDataConverterTest() { IDataConverter dataConverter = new JsonDataConverter(); ConfigTest1 configTest1 = (ConfigTest1)dataConverter.Parse(typeof(ConfigTest1), Constant.JsonDataConverterTestValue1); Assert.IsNotNull(configTest1); Assert.AreEqual("127.0.0.1", configTest1.Host); Assert.AreEqual(81, configTest1.Port); }
public TaskOrchestrationContext(OrchestrationInstance orchestrationInstance, TaskScheduler taskScheduler) { this.taskScheduler = taskScheduler; openTasks = new Dictionary <int, OpenTaskInfo>(); orchestratorActionsMap = new Dictionary <int, OrchestratorAction>(); idCounter = 0; dataConverter = new JsonDataConverter(); OrchestrationInstance = orchestrationInstance; IsReplaying = false; }
public OrchestrationTestHost() { dataConverter = new JsonDataConverter(); orchestrationObjectManager = new NameVersionObjectManager <TaskOrchestration>(); activityObjectManager = new NameVersionObjectManager <TaskActivity>(); orchestrationExecutor = new FakeOrchestrationExecutor(orchestrationObjectManager); taskActivityExecutor = new FakeTaskActivityExecutor(activityObjectManager); clock = new FakeOrchestrationClock(); ClockSpeedUpFactor = 1; }
public TaskOrchestrationContext(OrchestrationInstance orchestrationInstance, TaskScheduler taskScheduler) { Utils.UnusedParameter(taskScheduler); this.openTasks = new Dictionary <int, OpenTaskInfo>(); this.orchestratorActionsMap = new Dictionary <int, OrchestratorAction>(); this.idCounter = 0; this.dataConverter = new JsonDataConverter(); OrchestrationInstance = orchestrationInstance; IsReplaying = false; }
/// <summary> /// Creates a new AsyncTaskActivity with the supplied dataconverter /// </summary> /// <param name="dataConverter"></param> protected AsyncTaskActivity(DataConverter dataConverter) { if (dataConverter != null) { DataConverter = dataConverter; } else { DataConverter = new JsonDataConverter(); } }
public async Task SmallRuntimeStateConverterTest() { var smallInput = "abc"; OrchestrationRuntimeState newOrchestrationRuntimeStateSmall = generateOrchestrationRuntimeState(smallInput); var runtimeState = new OrchestrationRuntimeState(); DataConverter dataConverter = new JsonDataConverter(); // a small runtime state doesn't need external storage. Stream rawStreamSmall = await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateSmall, runtimeState, dataConverter, true, this.serviceBusSessionSettings, this.azureStorageBlobStore, SessionId); OrchestrationRuntimeState convertedRuntimeStateSmall = await RuntimeStateStreamConverter.RawStreamToRuntimeState(rawStreamSmall, "sessionId", this.azureStorageBlobStore, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall); // test for un-compress case Stream rawStreamSmall2 = await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateSmall, runtimeState, dataConverter, false, this.serviceBusSessionSettings, this.azureStorageBlobStore, SessionId); OrchestrationRuntimeState convertedRuntimeStateSmall2 = await RuntimeStateStreamConverter.RawStreamToRuntimeState(rawStreamSmall2, "sessionId", this.azureStorageBlobStore, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall2); // test for backward comp: ok for an un-implemented (or null) IBlobStorage for small runtime states Stream rawStreamSmall3 = await RuntimeStateStreamConverter.OrchestrationRuntimeStateToRawStream( newOrchestrationRuntimeStateSmall, runtimeState, dataConverter, true, this.serviceBusSessionSettings, null, SessionId); OrchestrationRuntimeState convertedRuntimeStateSmall3 = await RuntimeStateStreamConverter.RawStreamToRuntimeState(rawStreamSmall3, "sessionId", null, dataConverter); verifyEventInput(smallInput, convertedRuntimeStateSmall3); }
public void JsonDataConverter_deserializedClimateData() { string Testdataset = "[{\"datestamp\":\"1500000000\",\"climatedata\":{\"temperature\":\"20\",\"humidity\":\"50\",\"heatindex\":\"21\"}}]"; int expectedoutput_datestamp = 1500000000; int expectedoutput_temperature = 20; int expectedoutput_humidity = 50; int expectedoutput_heatindex = 21; List <unitData> dataset = JsonDataConverter.deserializedClimateData(Testdataset); Assert.AreEqual(expectedoutput_datestamp, dataset[0].datestamp); Assert.AreEqual(expectedoutput_temperature, dataset[0].climatedata.temperature); Assert.AreEqual(expectedoutput_humidity, dataset[0].climatedata.humidity); Assert.AreEqual(expectedoutput_heatindex, dataset[0].climatedata.heatindex); }
public void DataConverterDeserializationTest() { var dataConverter = new JsonDataConverter(); string serializedState = File.ReadAllText(@"TestData\SerializedExecutionStartedEvent.json"); var startedEvent = dataConverter.Deserialize <ExecutionStartedEvent>(serializedState); Assert.IsNotNull(startedEvent); serializedState = File.ReadAllText(@"TestData\SerializedOrchestrationState.json"); var runtimeState = dataConverter.Deserialize <OrchestrationRuntimeState>(serializedState); Assert.IsNotNull(runtimeState); serializedState = File.ReadAllText(@"TestData\SerializedOrchestrationStateWithTags.json"); runtimeState = dataConverter.Deserialize <OrchestrationRuntimeState>(serializedState); Assert.IsNotNull(runtimeState); }
public void SerializeDateTime() { // Verify that Enum values with the [Flags] attribute serialize correctly. var converter = new JsonDataConverter(); byte[] contents; string json; var enumValue = new EnumEntity() { Gender = Gender.Male }; contents = converter.ToData(enumValue); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"male\"}", json); }
public void DataWithGenericType() { // Verify that we can serialize and deserialize various (non-roundtrip) data items // using the generic FromData() method. var converter = new JsonDataConverter(); byte[] contents; // Serialize NULL. contents = converter.ToData(null); Assert.Null(converter.FromData <object>(contents)); // Serialize a string. contents = converter.ToData("foo"); Assert.Equal("foo", converter.FromData <string>(contents)); // Serialize a byte array. var items = new int[] { 0, 1, 2, 3, 4 }; contents = converter.ToData(items); Assert.Equal(items, converter.FromData <int[]>(contents)); // Serialize an array of non-roundtrip objects. var items2 = new TestData[] { new TestData() { Hello = "World!" }, new TestData() { Hello = "Goodbye!" }, null }; contents = converter.ToData(items2); items2 = converter.FromData <TestData[]>(contents); Assert.Equal(3, items2.Length); Assert.Equal("World!", items2[0].Hello); Assert.Equal("Goodbye!", items2[1].Hello); Assert.Null(items2[2]); }
public void RoundTripDataWithGeneric() { // Verify that we can serialize and deserialize various roundtrip data items // using the generic converter. var converter = new JsonDataConverter(); byte[] contents; // Serialize NULL. contents = converter.ToData(null); Assert.Null(converter.FromData <Person>(contents)); // Serialize a roundtrip item without extra data. var bob = new Person() { Name = "Bob", Age = 27, Data = new byte[] { 0, 1, 2, 3, 4 }, Gender = Gender.Male }; contents = converter.ToData(bob); Assert.Equal(bob, converter.FromData <Person>(contents)); // Serialize a roundtrip item WITH extra data. bob.__O.Add("foo", "bar"); contents = converter.ToData(bob); var deserializedBob = converter.FromData <Person>(contents); Assert.Equal(bob, deserializedBob); Assert.Equal("bar", (string)deserializedBob.__O["foo"]); }
/// <summary> /// Creates a new ReflectionBasedTaskActivity based on an activity object and method info /// </summary> /// <param name="activityObject">The activity object to invoke methods on</param> /// <param name="methodInfo">The Reflection.methodInfo for invoking the method on the activity object</param> public ReflectionBasedTaskActivity(object activityObject, MethodInfo methodInfo) { DataConverter = new JsonDataConverter(); this.activityObject = activityObject; MethodInfo = methodInfo; }
public FakeOrchestrationExecutor(NameVersionObjectManager <TaskOrchestration> orchestrationObjectManager) { scheduler = new SynchronousTaskScheduler(); dataConverter = new JsonDataConverter(); this.orchestrationObjectManager = orchestrationObjectManager; }
public void DataArray() { // Verify that we can deserialize arrays of data items. var converter = new JsonDataConverter(); JArray jArray; byte[] contents; object[] items; // Empty array. jArray = new JArray(); contents = Encoding.UTF8.GetBytes(jArray.ToString()); items = converter.FromDataArray(contents, new Type[0]); Assert.Empty(items); // Single item. jArray = new JArray(); jArray.Add("foo"); contents = Encoding.UTF8.GetBytes(jArray.ToString()); items = converter.FromDataArray(contents, new Type[] { typeof(string) }); Assert.Equal(new string[] { "foo" }, items); // Multiple object items jArray = new JArray(); jArray.Add("foo"); jArray.Add(1234); jArray.Add(JToken.FromObject(new TestData() { Hello = "World!" })); jArray.Add(null); contents = Encoding.UTF8.GetBytes(jArray.ToString()); items = converter.FromDataArray(contents, new Type[] { typeof(string), typeof(int), typeof(TestData), typeof(TestData) }); Assert.Equal(4, items.Length); Assert.Equal("foo", items[0]); Assert.Equal(1234, items[1]); Assert.Equal("World!", ((TestData)items[2]).Hello); Assert.Null(items[3]); // Roundtrip objects var bob = new Person() { Name = "Bob", Age = 27, Data = new byte[] { 0, 1, 2, 3, 4 }, Gender = Gender.Male }; bob.__O.Add("extra", "data"); jArray = new JArray(); jArray.Add("foo"); jArray.Add(1234); jArray.Add(bob.ToJObject()); jArray.Add(null); contents = Encoding.UTF8.GetBytes(jArray.ToString()); items = converter.FromDataArray(contents, new Type[] { typeof(string), typeof(int), typeof(Person), typeof(Person) }); Assert.Equal(4, items.Length); Assert.Equal("foo", items[0]); Assert.Equal(1234, items[1]); Assert.Equal(bob, (Person)items[2]); Assert.Equal("data", ((Person)items[2]).__O["extra"].ToString()); Assert.Null(items[3]); // Arrays of other types. var guid = Guid.NewGuid(); jArray = new JArray(); jArray.Add(10); jArray.Add(123.4); jArray.Add("Hello World!"); jArray.Add(null); jArray.Add(Gender.Female); jArray.Add(true); jArray.Add(new DateTime(2019, 7, 17, 12, 0, 0)); jArray.Add(TimeSpan.FromSeconds(1.5)); jArray.Add(guid); contents = Encoding.UTF8.GetBytes(jArray.ToString()); items = converter.FromDataArray(contents, new Type[] { typeof(int), typeof(double), typeof(string), typeof(string), typeof(Gender), typeof(bool), typeof(DateTime), typeof(TimeSpan), typeof(Guid) }); Assert.Equal(9, items.Length); Assert.Equal(10, (int)items[0]); Assert.Equal(123.4, (double)items[1]); Assert.Equal("Hello World!", (string)items[2]); Assert.Null((string)items[3]); Assert.Equal(Gender.Female, (Gender)items[4]); Assert.True((bool)items[5]); Assert.Equal(new DateTime(2019, 7, 17, 12, 0, 0), (DateTime)items[6]); Assert.Equal(TimeSpan.FromSeconds(1.5), (TimeSpan)items[7]); Assert.Equal(guid, (Guid)items[8]); }
public FakeTaskActivityExecutor(NameVersionObjectManager <TaskActivity> objectManager) { dataConverter = new JsonDataConverter(); pendingExecutions = 0; this.objectManager = objectManager; }
/// <summary> /// To poplulate LiveChart in the GUI is only used by btn_Showdata_Click event /// </summary> private void PopulateCharts() { DataContext = null; DateTime date = dp_datestampfrom.SelectedDate.Value; string clvl = null; switch (cb_CompressionLVL.SelectedIndex) { case 0: clvl = "1"; break; case 1: clvl = "2"; break; case 2: clvl = "3"; break; case 3: clvl = "4"; break; default: break; } string unitID = null; foreach (var unit in units) { if (unit.name == cb_UnitID.Text) { unitID = unit.id; } } string climatestringdata = HttpApiRequest.GetClimateData(UserInformation.ApiKey, UserInformation.Mail, unitID, date.ToString("yyyy.MM.dd"), clvl); List <unitData> ClimateDataList = JsonDataConverter.deserializedClimateData(climatestringdata); string format = "HH:mm"; int x = ClimateDataList.Count(); TimeLabel = new string[x]; List <double> TemperaturValues = new List <double>(); List <double> HeatIndexValues = new List <double>(); List <double> HumidityValues = new List <double>(); for (int i = 0; i < x; i++) { TimeLabel[i] = UnixStampConvert.UnixTimeToDateTime(ClimateDataList[i].datestamp).ToString(format); TemperaturValues.Add(Math.Round(ClimateDataList[i].climatedata.temperature, 2)); HeatIndexValues.Add(Math.Round(ClimateDataList[i].climatedata.heatindex, 2)); HumidityValues.Add(Math.Round(ClimateDataList[i].climatedata.humidity, 2)); } var TempLineColor = Colors.Red; var HeatLineColor = Colors.Yellow; var HumiLineColor = Colors.Blue; SolidColorBrush TempLineColorfil = new SolidColorBrush(); TempLineColorfil.Color = TempLineColor; TempLineColorfil.Opacity = 0.2; SolidColorBrush HeatLineColorfil = new SolidColorBrush(); HeatLineColorfil.Color = HeatLineColor; HeatLineColorfil.Opacity = 0.2; SolidColorBrush HumiLineColorfil = new SolidColorBrush(); HumiLineColorfil.Color = HumiLineColor; HumiLineColorfil.Opacity = 0.2; TempSeries = new SeriesCollection { new LineSeries { Title = "Temperatur", Values = TemperaturValues.AsChartValues(), LineSmoothness = 1, PointGeometrySize = 0, Stroke = Brushes.Red, Fill = TempLineColorfil }, new LineSeries { Title = "HeatIndex", Values = HeatIndexValues.AsChartValues(), LineSmoothness = 1, PointGeometrySize = 0, Stroke = Brushes.Yellow, Fill = HeatLineColorfil } }; HumiSeries = new SeriesCollection { new LineSeries { Title = "Humidity", Values = HumidityValues.AsChartValues(), LineSmoothness = 1, PointGeometrySize = 0, Stroke = Brushes.Blue, Fill = HumiLineColorfil } }; DataContext = this; }
/// <summary> /// Function used to getunits with and without null in unit names /// </summary> /// <param name="FilterNull">true is no units with null in unit names</param> /// <returns>return a list of the units</returns> private List <Userunits> GetUnits(bool FilterNull) { string JSONunits = HttpApiRequest.Userunits(UserInformation.ApiKey, UserInformation.Mail, UserInformation.Password); return(JsonDataConverter.deserializedUnits(JSONunits, FilterNull)); }
/// <summary> /// Create a new TaskHubClient with the given OrchestrationServiceClient and JsonDataConverter. /// </summary> /// <param name="serviceClient">Object implementing the <see cref="IOrchestrationServiceClient"/> interface </param> /// <param name="dataConverter">The <see cref="JsonDataConverter"/> to use for message serialization.</param> public TaskHubClient(IOrchestrationServiceClient serviceClient, JsonDataConverter dataConverter) { ServiceClient = serviceClient ?? throw new ArgumentNullException(nameof(serviceClient)); this.defaultConverter = dataConverter ?? throw new ArgumentNullException(nameof(dataConverter)); }
public void DataArray() { // Verify that we can deserialize arrays of data items. var converter = new JsonDataConverter(); var formatter = new ArrayFormatter(); byte[] contents; object[] items; // Empty array. contents = null; items = converter.FromDataArray(contents, Array.Empty <Type>()); Assert.Empty(items); // Single item. formatter.Clear(); formatter.Append("\"foo\""); contents = formatter.ToBytes(); items = converter.FromDataArray(contents, new Type[] { typeof(string) }); Assert.Equal(new string[] { "foo" }, items); // Multiple object items formatter.Clear(); formatter.Append("\"foo\""); formatter.Append("1234"); formatter.Append("{Hello: \"World!\"}"); formatter.Append("null"); contents = formatter.ToBytes(); items = converter.FromDataArray(contents, new Type[] { typeof(string), typeof(int), typeof(TestData), typeof(TestData) }); Assert.Equal(4, items.Length); Assert.Equal("foo", items[0]); Assert.Equal(1234, items[1]); Assert.Equal("World!", ((TestData)items[2]).Hello); Assert.Null(items[3]); // Roundtrip objects var bob = new Person() { Name = "Bob", Age = 27, Data = new byte[] { 0, 1, 2, 3, 4 }, Gender = Gender.Male }; bob.__O.Add("extra", "data"); formatter.Clear(); formatter.Clear(); formatter.Append("\"foo\""); formatter.Append("1234"); formatter.Append(bob.ToString(indented: false)); formatter.Append("null"); contents = formatter.ToBytes(); items = converter.FromDataArray(contents, new Type[] { typeof(string), typeof(int), typeof(Person), typeof(Person) }); Assert.Equal(4, items.Length); Assert.Equal("foo", items[0]); Assert.Equal(1234, items[1]); Assert.Equal(bob, (Person)items[2]); Assert.Equal("data", ((Person)items[2]).__O["extra"].ToString()); Assert.Null(items[3]); // Arrays of other types. formatter.Clear(); var guid = Guid.NewGuid(); formatter.Append("10"); formatter.Append("123.4"); formatter.Append("\"Hello World!\""); formatter.Append("null"); formatter.Append("\"female\""); formatter.Append("true"); formatter.Append(NeonHelper.JsonSerialize(new DateTime(2019, 7, 17, 12, 0, 0))); formatter.Append(NeonHelper.JsonSerialize(TimeSpan.FromSeconds(1.5))); formatter.Append($"\"{guid}\""); contents = formatter.ToBytes(); items = converter.FromDataArray(contents, new Type[] { typeof(int), typeof(double), typeof(string), typeof(string), typeof(Gender), typeof(bool), typeof(DateTime), typeof(TimeSpan), typeof(Guid) }); Assert.Equal(9, items.Length); Assert.Equal(10, (int)items[0]); Assert.Equal(123.4, (double)items[1]); Assert.Equal("Hello World!", (string)items[2]); Assert.Null((string)items[3]); Assert.Equal(Gender.Female, (Gender)items[4]); Assert.True((bool)items[5]); Assert.Equal(new DateTime(2019, 7, 17, 12, 0, 0), (DateTime)items[6]); Assert.Equal(TimeSpan.FromSeconds(1.5), (TimeSpan)items[7]); Assert.Equal(guid, (Guid)items[8]); }
public void SerializeFlagsEnum() { var converter = new JsonDataConverter(); byte[] contents; string json; EnumFlagsEntity value; // Verify uncombined flags. value = new EnumFlagsEntity() { Gender = GenderFlags.Unspecified }; contents = converter.ToData(value); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"unspecified\"}", json); //---------- value = new EnumFlagsEntity() { Gender = GenderFlags.Male }; contents = converter.ToData(value); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"male\"}", json); //---------- value = new EnumFlagsEntity() { Gender = GenderFlags.Female }; contents = converter.ToData(value); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"female\"}", json); //---------- value = new EnumFlagsEntity() { Gender = GenderFlags.Other }; contents = converter.ToData(value); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"other\"}", json); // Verifiy flag combinations value = new EnumFlagsEntity() { Gender = GenderFlags.Male | GenderFlags.Female }; contents = converter.ToData(value); json = Encoding.UTF8.GetString(contents); Assert.Equal("{\"Gender\":\"male, female\"}", json); }
/// <summary> /// Creates a new AsyncTaskActivity with the default dataconverter /// </summary> protected AsyncTaskActivity() { DataConverter = new JsonDataConverter(); }
/// <summary> /// Create a new TaskHubClient with the given OrchestrationServiceClient and JsonDataConverter. /// </summary> /// <param name="serviceClient">Object implementing the <see cref="IOrchestrationServiceClient"/> interface </param> /// <param name="dataConverter">The <see cref="JsonDataConverter"/> to use for message serialization.</param> public TaskHubClient(IOrchestrationServiceClient serviceClient, JsonDataConverter dataConverter) : this(serviceClient, dataConverter, null) { }