public async Task <bool> Handle(EnviarAtualizacaoCadastralProdamCommand request, CancellationToken cancellationToken) { var httpClient = httpClientFactory.CreateClient("servicoAtualizacaoCadastralProdam"); var body = JsonConvert.SerializeObject(request.ResponsavelDto, UtilJson.ObterConfigConverterNulosEmVazio()); var resposta = await httpClient.PostAsync($"AtualizarResponsavelAluno", new StringContent(body, Encoding.UTF8, "application/json")); Console.WriteLine(body); if (resposta.IsSuccessStatusCode && resposta.StatusCode != HttpStatusCode.NoContent) { var json = await resposta.Content.ReadAsStringAsync(); Console.WriteLine(body); Console.WriteLine(json); SentrySdk.CaptureMessage(json); if (json.ToLower().Contains("false")) { throw new Exception($"Não foi possível atualizar os dados cadastrais do cpf {request.ResponsavelDto.CPF}. Retorno: {json}"); } return(true); } else { throw new Exception($"Não foi possível atualizar os dados cadastrais do cpf {request.ResponsavelDto.CPF}."); } }
private static bool ProcessHeader(string stringType, string key, IDictionary <string, string> dic, Template template) { if (stringType != "G") { return(false); } var json = dic[key]; var el = UtilJson.Deserialize <TemplateInfo>(json); // Template header config // DotLiquid specific config if (el.DotLiquidFilterTypes != null && el.DotLiquidFilterTypes.Count > 0) { var assemblyPaths = el.DotLiquidFilterAssemblies; var typeList = new List <Type>(); foreach (var typeDef in el.DotLiquidFilterTypes) { var type = GetType(assemblyPaths, typeDef); typeList.Add(type); } template.ExtendedInfo.Add("DotLiquidFilterTypes", typeList); } return(true); }
public async Task <bool> Handle(GerarRelatorioAssincronoCommand request, CancellationToken cancellationToken) { try { ParametrosRelatorioDto parametrosDoDto = ObterParametrosRelatorio(request.Dados); var post = new ExecucaoRelatorioRequisicaoDto() { UnidadeRelatorioUri = request.CaminhoRelatorio, Async = false, SalvarSnapshot = false, FormatoSaida = request.Formato.Name(), Interativo = false, IgnorarPaginacao = false, Paginas = null, Parametros = parametrosDoDto }; SentrySdk.CaptureMessage("6.1 - Obtendo jSessionId..."); var jsessionId = await loginService.ObterTokenAutenticacao(configuration.GetSection("ConfiguracaoJasper:Username").Value, configuration.GetSection("ConfiguracaoJasper:Password").Value); SentrySdk.CaptureMessage($"6.2 - jSessionId = {jsessionId}"); SentrySdk.CaptureMessage("6.3 - Solicitando relatório..."); var retorno = await execucaoRelatorioService.SolicitarRelatorio(post, jsessionId); var exportacaoId = retorno?.Exports?.FirstOrDefault()?.Id; SentrySdk.CaptureMessage($"6.4 - Exportação Id = {exportacaoId}"); if (exportacaoId != null) { var dadosRelatorio = new DadosRelatorioDto(retorno.RequestId, exportacaoId.Value, request.CodigoCorrelacao, jsessionId); var publicacaoFila = new PublicaFilaDto(dadosRelatorio, RotasRabbit.RotaRelatoriosProcessando, null, request.CodigoCorrelacao); servicoFila.PublicaFila(publicacaoFila); var jsonPublicaFila = UtilJson.ConverterApenasCamposNaoNulos(publicacaoFila); Console.WriteLine(jsonPublicaFila); SentrySdk.CaptureMessage("6.5 - Sucesso na publicação da fila: " + publicacaoFila.Rota); return(true); } SentrySdk.CaptureMessage("6.6 - Erro na geração"); return(false); } catch (Exception ex) { SentrySdk.CaptureException(ex); throw ex; } }
/// <summary> /// Serialize session state. /// </summary> public static void Serialize(AppJson appJson, out string jsonClient) { appJson.RequestJson = null; UtilStopwatch.TimeStart("Serialize"); UtilJson.Serialize(appJson, out string jsonSession, out jsonClient); UtilStopwatch.TimeStop("Serialize"); UtilServer.Session.SetString("AppInternal", jsonSession); UtilStopwatch.Log(string.Format("JsonSession.Length={0:n0}; JsonClient.Length={1:n0};", jsonSession.Length, jsonClient.Length)); }
/// <summary> /// Deserialize session state. /// </summary> public static AppJson Deserialize() { AppJson result = null; string json = UtilServer.Session.GetString("AppInternal"); if (!string.IsNullOrEmpty(json)) // Not session expired. { UtilStopwatch.TimeStart("Deserialize"); result = (AppJson)UtilJson.Deserialize(json); UtilStopwatch.TimeStop("Deserialize"); } return(result); }
public async Task Executar(FiltroRelatorioDto request) { var relatorioQuery = request.ObterObjetoFiltro <ObterRelatorioBoletimEscolarQuery>(); var relatorio = await mediator.Send(relatorioQuery); var jsonString = JsonConvert.SerializeObject(relatorio, UtilJson.ObterConfigConverterNulosEmVazio()); if (relatorioQuery.Modalidade == Modalidade.EJA) { await mediator.Send(new GerarRelatorioAssincronoCommand("/sgp/RelatorioBoletimEscolarEja/BoletimEscolarEja", jsonString, TipoFormatoRelatorio.Pdf, request.CodigoCorrelacao)); } else { await mediator.Send(new GerarRelatorioAssincronoCommand("/sgp/RelatorioBoletimEscolar/BoletimEscolar", jsonString, TipoFormatoRelatorio.Pdf, request.CodigoCorrelacao)); } }
private static SourceContext GetSourceContext(Definition definition) { var result = new SourceContext(); if (definition.ModelSourceType == SourceType.Object) { Type modelType; Type modelInitializerType = null; if (!string.IsNullOrEmpty(definition.ModelTypeAssemblyPath)) { var myAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(definition.ModelTypeAssemblyPath); modelType = myAssembly.GetType(definition.ModelType); if (!string.IsNullOrEmpty(definition.ModelInitializerType)) { modelInitializerType = myAssembly.GetType(definition.ModelInitializerType); } } else { modelType = Type.GetType(definition.ModelType); if (!string.IsNullOrEmpty(definition.ModelInitializerType)) { modelInitializerType = Type.GetType(definition.ModelInitializerType); } } if (modelType == null) { throw new ModelException(ModelException.FailValue.CouldNotLoadTypeForModel); } var json = File.ReadAllText(definition.Model); var jsonOptions = UtilJson.GetDefaultOptions(); var rawSource = JsonSerializer.Deserialize(json, modelType, jsonOptions); if (modelInitializerType != null) { var initializer = (IInitializer)Activator.CreateInstance(modelInitializerType); initializer.Initialize(rawSource); } var source = new ObjectSource(rawSource); result.Source = source; result.Type = modelType; } return(result); }
public override void Execute(IDictionary <string, object> input) { var macroName = input.Get <string>(NAME); var macroFolder = input.Get <string>(FOLDER); if (!string.IsNullOrEmpty(macroFolder) && !Directory.Exists(macroFolder)) { Directory.CreateDirectory(macroFolder); } var macroHolder = Context.MacroHolder; CleanMacroHolder(); var json = UtilJson.Serialize(macroHolder); var macroPath = Path.Combine(macroFolder, macroName + ".macro.json"); File.WriteAllText(macroPath, json); _collectionProvider.AddConfigValue(CollectionValues.Macro, macroName, macroPath); Context.MacroHolder = null; }
public static Definition LoadFrom(string sourceFile) { if (!File.Exists(sourceFile)) { throw new TemplateException(TemplateException.FailValue.DefinitionFileNotFound); } var json = File.ReadAllText(sourceFile); var definition = UtilJson.Deserialize <Definition>(json); var definitionDir = Path.GetDirectoryName(sourceFile); definition.Template = UtilFile.ToAbsoluteFrom(definitionDir, definition.Template); definition.Model = UtilFile.ToAbsoluteFrom(definitionDir, definition.Model); definition.OutputTarget = UtilFile.ToAbsoluteFrom(definitionDir, definition.OutputTarget); if (!string.IsNullOrEmpty(definition.ModelTypeAssemblyPath)) { definition.ModelTypeAssemblyPath = UtilFile.ToAbsoluteFrom(definitionDir, definition.ModelTypeAssemblyPath); } return(definition); }
private static void RunComponentJson() { // Reference to self { MyComponent source = new MyComponent(null); source.Component = source; UtilJson.Serialize(source, out string json, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(json); UtilFramework.Assert(dest.Component == dest); } // ComponentJson reference to ComponentJson do not send to client { MyComponent source = new MyComponent(null); source.HtmlAbc = new Html(source) { TextHtml = "JK" }; source.MyTextSession = "SessionValueX"; source.MyTextClient = "ClientValueX"; source.MyIgnore = "IgnoreX"; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("HtmlAbc")); // Do not send property name of ComponentJson reference to client UtilFramework.Assert(jsonSession.Contains("SessionValueX")); UtilFramework.Assert(!jsonClient.Contains("SessionValueX")); UtilFramework.Assert(!jsonSession.Contains("ClientValueX")); UtilFramework.Assert(jsonClient.Contains("ClientValueX")); UtilFramework.Assert(!jsonSession.Contains("IgnoreX")); UtilFramework.Assert(!jsonClient.Contains("IgnoreX")); UtilFramework.Assert(!jsonSession.Contains("Owner")); UtilFramework.Assert(!jsonClient.Contains("Owner")); } // ComponentJson.IsHide { MyComponent source = new MyComponent(null); new Html(source) { TextHtml = "X11" }; new Html(source) { TextHtml = "X12", IsHide = true }; new Html(source) { TextHtml = "X13" }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.List.Count == 3); UtilFramework.Assert(jsonClient.Contains("X11")); UtilFramework.Assert(!jsonClient.Contains("X12")); UtilFramework.Assert(jsonClient.Contains("X13")); } // ComponentJson.IsHide (Dto to ComponentJson { My source = new My(); source.MyComponent = new MyComponent(null) { Id = 789, IsHide = true }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); My dest = (My)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("789")); } // ComponentJson.IsHide { MyComponent source = new MyComponent(null); source.Html = new Html(source) { TextHtml = "My123", IsHide = true }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains("My123")); UtilFramework.Assert(!jsonClient.Contains("My123")); } // ComponentJson.IsHide (Root) { MyComponent source = new MyComponent(null); source.IsHide = true; source.Html = new Html(source) { TextHtml = "My123", IsHide = true }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains("My123")); UtilFramework.Assert(jsonClient == ""); } // Reference to Row { MyComponent source = new MyComponent(null); source.MyRow = new MyRow { Text = "My123", DateTime = DateTime.Now }; source.MyRowList = new List <Row>(); source.MyRowList.Add(new MyRow { Text = "My1234", DateTime = DateTime.Now }); source.MyRowList.Add(new MyRow { Text = "My12356", DateTime = DateTime.Now }); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("My123")); } // Reference to Row { MyComponent source = new MyComponent(null); source.MyRowList = new List <Row>(); source.MyRowList.Add(new MyRow { Text = "My1234", DateTime = DateTime.Now }); source.MyRowList.Add(new MyRow { Text = "My12356", DateTime = DateTime.Now }); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("My123")); } // Field of object type with Row value { MyComponent source = new MyComponent(null); source.V = new MyRow() { Text = "Hello" }; try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Can not send data row to client!"); // V is object declaration therefore no Row detection. } } // Reference to removed ComponentJson { MyComponent source = new MyComponent(null); var html = new Html(source) { TextHtml = "My" }; source.Html = html; html.ComponentRemove(); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Html == null); } // ComponentJson reference in list { MyComponent source = new MyComponent(null); var html = new Html(source) { TextHtml = "My" }; source.HtmlList = new List <Html>(); source.HtmlList.Add(html); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); try { var dest = (MyComponent)UtilJson.Deserialize(jsonSession); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Reference to ComponentJson in List not supported!"); } } { MyComponent source = new MyComponent(null); new MyComponent(source); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.List.Count == 1); } { MyComponent source = new MyComponent(null); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Index == null); } { MyComponent source = new MyComponent(null); source.Index = 0; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Index == 0); } { MyComponent source = new MyComponent(null); source.Index = -1; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Index == -1); } { My source = new My(); var myComponent1 = new MyComponent(null); Html html1 = new Html(myComponent1) { TextHtml = "A" }; myComponent1.Dto = new Dto { Css = "A", Html = html1 }; var myComponent2 = new MyComponent(null); Html html2 = new Html(myComponent2) { TextHtml = "B" }; myComponent2.Dto = new Dto { Css = "B", Html = html2 }; source.List.Add(myComponent1); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (My)UtilJson.Deserialize(jsonSession); dest.List[0].Dto.Html.TextHtml = "abc"; UtilFramework.Assert(((Html)dest.List[0].List[0]).TextHtml == "abc"); source.List.Add(myComponent2); try { UtilJson.Serialize(source, out jsonSession, out jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "JsonClient can only have one ComponentJson graph!"); } } { My source = new My(); var myComponent1 = new MyComponent(null); Html html1 = new Html(myComponent1) { TextHtml = "A" }; myComponent1.Dto = new Dto { Css = "A", Html = html1 }; var myComponent2 = new MyComponent(null); Html html2 = new Html(myComponent2) { TextHtml = "B" }; myComponent2.Dto = new Dto { Css = "B", Html = html2 }; var myComponent3 = new MyComponent(myComponent1); source.List.Add(myComponent3); // Reference not to root! try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Referenced ComponentJson not root!"); } source.List.Remove(myComponent3); source.List.Add(myComponent1); source.List.Add(myComponent2); try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "JsonClient can only have one ComponentJson graph!"); } } { My source = new My(); var myComponent1 = new MyComponent(null); Html html1 = new Html(myComponent1) { TextHtml = "A" }; myComponent1.Dto = new Dto { Css = "A", Html = html1 }; var myComponent2 = new MyComponent(null); Html html2 = new Html(myComponent2) { TextHtml = "B" }; myComponent2.Dto = new Dto { Css = "B", Html = html1 }; // Reference to object in different graph source.List.Add(myComponent2); source.List.Add(myComponent1); try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Referenced ComponentJson not in same object graph!"); } } { var source = new MyComponent(null); source.Html = new Html(source) { TextHtml = "Hello" }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); UtilFramework.Assert(!jsonSession.Contains("Owner")); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); var htmlOne = dest.Html; var htmlTwo = dest.List.OfType <Html>().First(); htmlOne.TextHtml = "K"; UtilFramework.Assert(htmlOne.TextHtml == htmlTwo.TextHtml); } // Referenced ComponentJson not in same graph { var source = new MyComponent(null); source.Html = new Html(null); try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Referenced ComponentJson not in same object graph!"); } } }
public static void Run() { { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("AbcDef"); UtilFramework.Assert(camelCase.TextList[0] == "Abc"); UtilFramework.Assert(camelCase.TextList[1] == "Def"); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("abcDef"); UtilFramework.Assert(camelCase.TextList[0] == "abc"); UtilFramework.Assert(camelCase.TextList[1] == "Def"); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("AbcDefCSharp"); UtilFramework.Assert(camelCase.TextList[0] == "Abc"); UtilFramework.Assert(camelCase.TextList[1] == "Def"); UtilFramework.Assert(camelCase.TextList[2] == "CSharp"); UtilFramework.Assert(camelCase.EndsWith("DefCSharp")); UtilFramework.Assert(camelCase.EndsWith("cDefCSharp") == false); UtilFramework.Assert(camelCase.EndsWith("AbcDefCSharp")); UtilFramework.Assert(camelCase.EndsWith("AbcDefCSharpCar") == false); UtilFramework.Assert(camelCase.EndsWith("CarAbcDefCSharp") == false); UtilFramework.Assert(camelCase.EndsWith("") == true); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("AbcDefCSharp"); UtilFramework.Assert(camelCase.StartsWith("Abc")); UtilFramework.Assert(camelCase.StartsWith("AbcDef")); UtilFramework.Assert(camelCase.StartsWith("AbcDefCSharp")); UtilFramework.Assert(camelCase.StartsWith("AbcDefCShar") == false); UtilFramework.Assert(camelCase.StartsWith("AbcDefCSharpLk") == false); UtilFramework.Assert(camelCase.StartsWith("LkAbcDefCSharp") == false); UtilFramework.Assert(camelCase.StartsWith("")); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("ImageFileId"); UtilFramework.Assert(camelCase.EndsWith("FileId")); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("ImagEFileId"); UtilFramework.Assert(camelCase.EndsWith("FileId") == false); } { var source = new AppMain(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (AppMain)UtilJson.Deserialize(jsonSession); } { var source = new MyApp(); source.Div = new Div(source); source.Div.ComponentRemove(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); } { var source = new MyApp(); source.Row = new BootstrapRow(source); source.Col = new BootstrapCol((BootstrapRow)source.Row); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains("PropertyReadOnly")); } { var source = new MyApp(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains("PropertyReadOnly")); } { var source = new MyApp(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains("PropertyReadOnly")); } { var source = new MyApp(); var myGrid = new MyGrid(source) { Text = "K7", IsHide = true }; source.MyCell = new MyCell { MyGridBoth = myGrid, MyText = "7755" }; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(UtilFramework.FindCount(jsonClient, "K7") == 1); UtilFramework.Assert(UtilFramework.FindCount(jsonSession, "K7") == 1); // Ensure session stores reference UtilFramework.Assert(dest.List[0] == dest.MyCell.MyGridBoth); } { var source = new MyApp(); var myGrid = new MyGrid(source) { Text = "K7", IsHide = true }; var myGrid2 = new MyGrid(source) { Text = "K8", IsHide = true }; source.MyCell = new MyCell { MyGrid = myGrid, MyGrid2 = myGrid2, MyText = "7755" }; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonClient.Contains("K7")); UtilFramework.Assert(!jsonClient.Contains("K8")); UtilFramework.Assert(dest.List[1] == dest.MyCell.MyGrid2); } RunComponentJson(); { A source = new A(); source.MyEnum = MyEnum.Left; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.MyEnum == MyEnum.Left); UtilFramework.Assert(dest.MyEnumNullable == null); } { A source = new A(); source.MyEnumNullable = MyEnum.None; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.MyEnumNullable == MyEnum.None); } { A source = new A(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains(nameof(A.MyEnumList))); UtilFramework.Assert(source.MyEnumList == null); UtilFramework.Assert(dest.MyEnumList != null); UtilFramework.Assert(dest.MyEnumList.Count == 0); } { A source = new A(); source.MyEnumList = new List <MyEnum>(); source.MyEnumList.Add(MyEnum.None); source.MyEnumList.Add(MyEnum.Left); source.MyEnumList.Add(MyEnum.Right); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.MyEnumList))); UtilFramework.Assert(dest.MyEnumList[0] == MyEnum.None); UtilFramework.Assert(dest.MyEnumList[1] == MyEnum.Left); UtilFramework.Assert(dest.MyEnumList[2] == MyEnum.Right); } { A source = new A(); source.MyEnumNullableList = new List <MyEnum?>(); source.MyEnumNullableList.Add(MyEnum.None); source.MyEnumNullableList.Add(MyEnum.Left); source.MyEnumNullableList.Add(null); source.MyEnumNullableList.Add(MyEnum.Right); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.MyEnumNullableList))); UtilFramework.Assert(dest.MyEnumNullableList[0] == MyEnum.None); UtilFramework.Assert(dest.MyEnumNullableList[1] == MyEnum.Left); UtilFramework.Assert(dest.MyEnumNullableList[2] == null); UtilFramework.Assert(dest.MyEnumNullableList[3] == MyEnum.Right); } { A source = new A(); source.IntNullableList = new List <int?>(); source.IntNullableList.Add(0); source.IntNullableList.Add(1); source.IntNullableList.Add(null); source.IntNullableList.Add(2); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.IntNullableList))); UtilFramework.Assert(dest.IntNullableList[0] == 0); UtilFramework.Assert(dest.IntNullableList[1] == 1); UtilFramework.Assert(dest.IntNullableList[2] == null); UtilFramework.Assert(dest.IntNullableList[3] == 2); } { A source = new A(); source.IntList = new List <int>(); source.IntList.Add(0); source.IntList.Add(1); source.IntList.Add(2); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.IntList))); UtilFramework.Assert(dest.IntList[0] == 0); UtilFramework.Assert(dest.IntList[1] == 1); UtilFramework.Assert(dest.IntList[2] == 2); } { A source = new A(); source.V = 33; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert((int)dest.V == 33); } { A source = new A(); source.V = "Hello"; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert((string)dest.V == "Hello"); } { var date = DateTime.Now; A source = new A(); source.Row = new FrameworkDeployDb { Id = 22, FileName = @"C:\Temp\Readme.txt", Date = date }; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Row.Id == 22); UtilFramework.Assert(dest.Row.FileName == @"C:\Temp\Readme.txt"); UtilFramework.Assert(dest.Row.Date == date); } { A source = new A(); source.V = MyEnum.None; // TODO Serialize enum on property of type object. // Serialize, deserialize // string json = UtilJson.Serialize(source); // A dest = (A)UtilJson.Deserialize(json); } }
public async Task <TrabalhoListaIdsDto> AtualizarTrabalhosEmLote(IEnumerable <int> ids, bool sobrescreverGatilhoIgnorandoTipo, TrabalhoDefinicaoDto trabalhoDefinicao) { var trabalhoDefinicaoJson = UtilJson.ConverterApenasCamposNaoNulos(trabalhoDefinicao); return(await restService.PostAtualizarTrabalhosEmLoteAsync(ids, sobrescreverGatilhoIgnorandoTipo, trabalhoDefinicaoJson)); }