Exemplo n.º 1
0
        static void Main(string[] args)
        {
            serializer   = new JsonSerializerService();
            readerWriter = new ReadWriteService();

            Students bob = new Students()
            {
                FirstName = "Bob",
                LastName  = "Bobsky",
                Age       = 37,
                Pets      = new string[] { "Dog1", "Dog2", "Dog3", "Cat1" }
            };

            string jsonString = serializer.SerializeStudent(bob);

            readerWriter.WriteFile(filePath, jsonString);

            string   jsonFormFile = readerWriter.ReadFile(filePath);
            Students student      = serializer.DeserializeStudent(jsonFormFile);

            string   newtonsoftJasonString = JsonConvert.SerializeObject(student);
            Students newtonsoftStudent     = JsonConvert.DeserializeObject <Students>(jsonFormFile);

            Console.ReadLine();
        }
 public EmployeeController(IRepositoryMachine <Employee> repo,
                           JsonSerializerService jsonService,
                           IHostingEnvironment hostingEnv,
                           IMapper mapper) : base(repo, mapper, null)
 {
     this.jsonService = jsonService;
     this.hostingEnv  = hostingEnv;
 }
 public ImportBase()
 {
     LoggingService    = DependencyResolver.GetService <ILoggingService>();
     CommandDispatcher = DependencyResolver.GetService <ICommandDispatcher>();
     QueryDispatcher   = DependencyResolver.GetService <IQueryDispatcher>();
     Configuration     = DependencyResolver.GetService <IConfigurationRegistry>();
     SerializerService = new JsonSerializerService();
 }
    public async Task Run()
    {
        var data = await PostcodeScraper.Run();

        File.Delete(DataLocations.LocalitiesPath);
        JsonSerializerService.Serialize(data, DataLocations.LocalitiesPath);
        await Verify(data.Take(10));
    }
Exemplo n.º 5
0
 // GET: api/PurchaseLineExtend
 public PurchaseLineExtendController(IRepositorySageX3Extend <PurchaseLineExtend> repo,
                                     IRepositoryDapperSageX3 <PurchaseRequestLinePureViewModel> repoPrLinePure,
                                     IMapper mapper,
                                     IHelperService helper,
                                     JsonSerializerService jsonService) : base(repo, mapper, helper, jsonService)
 {
     this.repositoryPrLinePure = repoPrLinePure;
 }
Exemplo n.º 6
0
        public IDictionary <string, string> Execute(string url, string method, string jsonData, string authorization, DateTime dateNow)
        {
            try
            {
                _logger.Debug(string.Format(
                                  "Start request to {0}, method: {1}, with json: {2}, authorization: {3}, dateTime: {4}",
                                  url, method, string.IsNullOrEmpty(jsonData) ? "-" : jsonData, authorization, dateNow));

                var request = WebRequest.Create(url) as HttpWebRequest;
                if (request == null)
                {
                    return(null);
                }

                request.Method      = method;
                request.UserAgent   = "puntopagos-sdk-" + Assembly.GetExecutingAssembly().GetName().Version;
                request.Accept      = "application/json";
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("Fecha", dateNow.ToString("r"));
                request.Headers.Add("Autorizacion", authorization);
                _logger.Debug("Add all headers");
                if (!string.IsNullOrEmpty(jsonData))
                {
                    _logger.Debug("Start to write stream json");
                    var content = GetContentByte(jsonData);
                    request.ContentLength = content.Length;

                    var dataStream = request.GetRequestStream();
                    dataStream.Write(content, 0, content.Length);
                    dataStream.Close();
                    _logger.Debug("End to write stream json, close stream");
                }
                _logger.Debug("Start to call response");
                var response = request.GetResponse() as HttpWebResponse;
                if (response == null)
                {
                    return(null);
                }
                _logger.Debug("End to call response");
                _logger.Debug("Start to read response");
                var responseDataStream = response.GetResponseStream();
                if (responseDataStream == null)
                {
                    return(null);
                }

                var reader = new StreamReader(responseDataStream);
                var json   = reader.ReadToEnd();
                _logger.Debug("End to read response, start to Deserialize Json");
                return(JsonSerializerService.DeserializeFromString(json));
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error when execute url: {0} and method: {1}", url, method), ex);
                throw;
            }
        }
 // GET: api/TaskStatusMaster
 public TaskStatusMasterController(IRepositorySageX3Extend <TaskStatusMaster> repo,
                                   IRepositorySageX3Extend <TaskStatusDetail> repoDetail,
                                   IMapper mapper,
                                   IHelperService helper,
                                   JsonSerializerService jsonService
                                   ) : base(repo, mapper, helper, jsonService)
 {
     this.repositoryDetail = repoDetail;
 }
Exemplo n.º 8
0
        public HttpServerService(JsonSerializerService jsonSerializerService, ILoggerFactory loggerFactory)
        {
            _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _logger = loggerFactory.CreateLogger <HttpServerService>();
        }
Exemplo n.º 9
0
        public void given_error_json_response_from_punto_pago_when_call_json_serializer_then_return_check_transaction_response_dto()
        {
            const string json = "{\"respuesta\":\"99\",\"token\":\"9XJ08401WN0071839\",\"error\":\"Pago Rechazado\"}";

            var checkTransactionDto = new CheckTransactionResponseDto(JsonSerializerService.DeserializeFromString(json));

            Assert.IsTrue(checkTransactionDto.WithError, "WithError");
            Assert.AreEqual(checkTransactionDto.Token, "9XJ08401WN0071839", "Token");
            Assert.AreEqual(checkTransactionDto.ErrorMessage, "Pago Rechazado", "ErrorMessage");
        }
Exemplo n.º 10
0
 public PurchaseOrderHeaderController(IRepositorySageX3Extend <PurchaseOrderHeader> repo,
                                      IRepositorySageX3Extend <PurchaseExtend> repoPurchase,
                                      IRepositorySageX3Extend <PurchaseLineExtend> repoPurchaseLine,
                                      IMapper mapper,
                                      IHelperService helper,
                                      JsonSerializerService jsonService) : base(repo, mapper, helper, jsonService)
 {
     this.repositoryPurchase     = repoPurchase;
     this.repositoryPurchaseLine = repoPurchaseLine;
 }
Exemplo n.º 11
0
 public ImportBase()
 {
     LoggingService         = DependencyResolver.Current.GetService <ILoggingService>();
     CommandDispatcher      = DependencyResolver.Current.GetService <ICommandDispatcher>();
     QueryDispatcher        = DependencyResolver.Current.GetService <IQueryDispatcher>();
     Configuration          = DependencyResolver.Current.GetService <IConfigurationRegistry>();
     SerializerService      = new JsonSerializerService();
     SourceConnectionString = DependencyResolver.Current.GetService <IConfiguration>().GetConnectionString("StockTradingAnalysis_MSSQL_Migration_Source");
     TargetConnectionString = DependencyResolver.Current.GetService <IConfiguration>().GetConnectionString("StockTradingAnalysis_MSSQL_Migration_Target");
 }
        public void DeserializeShouldWorkWithDifferentCLassesIfStructureIsTheSame()
        {
            var test = new TestClass()
            {
                TestProperty = "This is a test"
            };
            var testSerialized = JsonConvert.SerializeObject(test);

            var testDeserialized = new JsonSerializerService().Deserialize <CompatipleOtherTestClass>(testSerialized);
        }
 public GenericSageX3ExtendController(
     IRepositorySageX3Extend <Entity> repo,
     IMapper mapper,
     IHelperService helper,
     JsonSerializerService jsonService)
 {
     this.repository          = repo;
     this.mapper              = mapper;
     this.DefaultJsonSettings = jsonService.Create();
     this.helperService       = helper;
 }
Exemplo n.º 14
0
 public ResourceService(
     StorageService storageService,
     JsonSerializerService jsonSerializerService,
     GlobalVariablesService globalVariablesService,
     ILogger <ResourceService> logger)
 {
     _storageService         = storageService ?? throw new ArgumentNullException(nameof(storageService));
     _jsonSerializerService  = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
     _globalVariablesService = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public void DeserializeShouldDeserializeAnObject()
        {
            var test = new TestClass()
            {
                TestProperty = "This is a test"
            };
            var testSerialized = JsonConvert.SerializeObject(test);

            var testDeserialized = new JsonSerializerService().Deserialize <TestClass>(testSerialized);

            test.TestProperty.Should().BeEquivalentTo(testDeserialized.TestProperty);
        }
Exemplo n.º 16
0
        public HttpRequestInterceptor(string uriTemplate, Func <IDictionary <object, object>, IDictionary <object, object> > handler, JsonSerializerService jsonSerializerService, ILogger logger)
        {
            _handler = handler ?? throw new ArgumentNullException(nameof(handler));
            _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (uriTemplate == null)
            {
                throw new ArgumentNullException(nameof(uriTemplate));
            }
            _routeTemplate = TemplateParser.Parse(uriTemplate);
        }
Exemplo n.º 17
0
        public ResourceService(StorageService storageService, JsonSerializerService jsonSerializerService, GlobalVariablesService globalVariablesService, ILoggerFactory loggerFactory)
        {
            _storageService         = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _jsonSerializerService  = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
            _globalVariablesService = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _logger = loggerFactory.CreateLogger <ResourceService>();
        }
 // GET: api/PurchaseExtends
 public PurchaseExtendsController(IRepositorySageX3Extend <PurchaseExtend> repo,
                                  IRepositorySageX3Extend <PurchaseLineExtend> repoPurchaseLine,
                                  IRepositoryDapperSageX3 <PurchaseRequestPureViewModel> repoPrPure,
                                  IRepositoryDapperSageX3 <PrOutStandingViewModel> repoPrOutStanding,
                                  IMapper mapper,
                                  IHelperService helper,
                                  JsonSerializerService jsonService) : base(repo, mapper, helper, jsonService)
 {
     this.repositoryPurchaseLine = repoPurchaseLine;
     this.repositoryPrPure       = repoPrPure;
     // Dapper
     this.repositoryPrOutStanding = repoPrOutStanding;
 }
Exemplo n.º 19
0
        public async void SerializationTest1()
        {
            var logServiceMoq        = new Mock <ILogService>();
            var serializationService = new JsonSerializerService(logServiceMoq.Object);

            var fakeCvService = new FakeCvService();
            var cvs           = await fakeCvService.GetAllCvs();

            var cv = cvs.ElementAt(0);

            var json = await serializationService.Serialize(cv);

            Console.WriteLine(json);
        }
        public void given_json_response_with_error_from_punto_pago_when_call_json_serializer_then_return_transaction_response_dto_with_error()
        {
            const string json = "{\"respuesta\":\"99\",\"token\":\"9XJ08401WN0071839\",\"trx_id\":\"9787415132\"}";

            _configuration.Setup(x => x.GetProcessTransactionUrl()).Returns("/url");
            var transactionResponseDto = new CreateTransactionResponseDto(JsonSerializerService.DeserializeFromString(json), _configuration.Object);

            Assert.AreEqual("9XJ08401WN0071839", transactionResponseDto.Token);
            Assert.AreEqual(9787415132, transactionResponseDto.TransactionId);
            Assert.IsTrue(transactionResponseDto.WithError);
            Assert.IsNull(transactionResponseDto.PaymentMethod);
            Assert.IsNull(transactionResponseDto.Currency);
            Assert.IsNullOrEmpty(transactionResponseDto.ErrorMessage);
            Assert.AreEqual("/url/9XJ08401WN0071839", transactionResponseDto.ProcessUrl);
        }
Exemplo n.º 21
0
        public void ChoseSerializationType(string inputPath, string outputPath, string outputType)
        {
            outputType = outputType.ToLower();
            switch (outputType)
            {
            case "json":
                var jsonSerializationService = new JsonSerializerService();
                jsonSerializationService.SerializeToJson(inputPath, outputPath);
                break;

            default:
                var xmlSerializerService = new XmlSerializerService();
                xmlSerializerService.SerializeToXml(inputPath, outputPath);
                break;
            }
        }
Exemplo n.º 22
0
        public void given_default_json_response_from_punto_pago_when_call_json_serializer_then_return_check_transaction_response_dto()
        {
            const string json =
                "{\"respuesta\":\"00\",\"token\":\"9XJ08401WN0071839\",\"trx_id\":9787415132,\"medio_pago\":\"999\",\"monto\":1000000.00,\"fecha_aprobacion\":\"2009-06-15T20:49:00\",\"numero_operacion\":\"7897851487\",\"codigo_autorizacion\":\"34581\"}";

            var checkTransactionDto = new CheckTransactionResponseDto(JsonSerializerService.DeserializeFromString(json));

            Assert.IsFalse(checkTransactionDto.WithError, "WithError");
            Assert.AreEqual(checkTransactionDto.Token, "9XJ08401WN0071839", "Token");
            Assert.AreEqual(checkTransactionDto.TransactionId, 9787415132, "TransactionId");
            Assert.IsNull(checkTransactionDto.PaymentMethod, "PaymentMethod");
            Assert.AreEqual(checkTransactionDto.Currency.Amount, 1000000, "Amount");
            Assert.AreEqual(checkTransactionDto.DateTimeAcceptance, new DateTime(2009, 6, 15, 20, 49, 00), "DateTimeAcceptance");
            Assert.AreEqual(checkTransactionDto.OperationNumber, "7897851487", "OperationNumber");
            Assert.AreEqual(checkTransactionDto.AuthorizationCode, "34581", "AuthorizationCode");
        }
Exemplo n.º 23
0
        public HttpServerService(JsonSerializerService jsonSerializerService, PythonEngineService pythonEngineService, ILoggerFactory loggerFactory)
        {
            _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _logger = loggerFactory.CreateLogger <HttpServerService>();

            if (pythonEngineService == null)
            {
                throw new ArgumentNullException(nameof(pythonEngineService));
            }
            pythonEngineService.RegisterSingletonProxy(new HttpClientPythonProxy());
            pythonEngineService.RegisterSingletonProxy(new HttpServerPythonProxy(this));
        }
Exemplo n.º 24
0
    public StorageService(JsonSerializerService jsonSerializerService, ILogger <StorageService> logger)
    {
        _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
        _logger = logger;

        var paths = new StoragePaths();

        BinPath  = paths.BinPath;
        DataPath = paths.DataPath;

        if (logger == null)
        {
            throw new ArgumentNullException(nameof(logger));
        }

        logger.Log(LogLevel.Information, $"Bin path  = {BinPath}");
        logger.Log(LogLevel.Information, $"Data path = {DataPath}");
    }
Exemplo n.º 25
0
        public IDictionary <string, string> GetDataFromRequest(WebRequest request)
        {
            try
            {
                _logger.Debug("Start to read request.");
                var responseDataStream = request.GetRequestStream();

                var reader = new StreamReader(responseDataStream);
                var json   = reader.ReadToEnd();
                _logger.Debug("End to read request, start to Deserialize Json");
                return(JsonSerializerService.DeserializeFromString(json));
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error when get response from url: {0} and method: {1}", request.RequestUri, request.Method), ex);
                throw;
            }
        }
Exemplo n.º 26
0
    public static async Task Run()
    {
        var codes = await PartyCodeScraper.Run();

        var htmlPath          = Path.Combine(DataLocations.TempPath, "partycodes.html");
        var partyRegisterPath = Path.Combine(DataLocations.TempPath, "partyRegister.json");

        File.Delete(htmlPath);
        File.Delete(partyRegisterPath);
        var url = "https://www.aec.gov.au/parties_and_representatives/party_registration/Registered_parties/";

        try
        {
            await Downloader.DownloadFile(htmlPath, url);

            var jsonUrl = (await File.ReadAllLinesAsync(htmlPath))
                          .Single(x => x.Contains("/Parties_and_Representatives/Party_Registration/Registered_parties/files/register"))
                          .Split('"')[1];
            await Downloader.DownloadFile(partyRegisterPath, $"https://www.aec.gov.au{jsonUrl}");

            var          aecParties = JsonSerializerService.Deserialize <PartyData>(partyRegisterPath);
            List <Party> parties    = new();
            foreach (var detail in aecParties.Details)
            {
                var party = DetailToParty(detail, codes);
                parties.Add(party);
            }

            File.Delete(DataLocations.PartiesJsonPath);
            JsonSerializerService.Serialize(parties, DataLocations.PartiesJsonPath);
        }
        catch (Exception exception)
        {
            throw new($"Failed to parse {htmlPath} {htmlPath}", exception);
        }
    }
Exemplo n.º 27
0
 public EventStoreRepository(ISQLConnectionFactory connectionFactory, JsonSerializerService serializerService)
 {
     _connectionFactory = connectionFactory;
     _serializerService = serializerService;
 }
Exemplo n.º 28
0
 public HttpServerService(JsonSerializerService jsonSerializerService, ILogger <HttpServerService> logger)
 {
     _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemplo n.º 29
0
 public HttpRequestConverter(JsonSerializerService jsonSerializerService)
 {
     _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
 }
Exemplo n.º 30
0
 // GET: api/TaskStatusDetail
 public TaskStatusDetailController(IRepositorySageX3Extend <TaskStatusDetail> repo,
                                   IMapper mapper,
                                   IHelperService helper,
                                   JsonSerializerService jsonService) : base(repo, mapper, helper, jsonService)
 {
 }