public UiConfigurationService(IFileSystemService fileSystemService, IWebHostEnvironment hostingEnvironment, IJsonSerializerService jsonSerializerService, IAdapterSettingService adapterSettingService)
 {
     _fileSystemService     = fileSystemService;
     _hostingEnvironment    = hostingEnvironment;
     _jsonSerializerService = jsonSerializerService;
     _adapterSettingService = adapterSettingService;
 }
Пример #2
0
 public MqttAdapterDbService(IJsonSerializerService jsonSerializerService, IRepositoryService repositoryService, IEntityFactory entityFactory, IModelFactory modelFactory)
 {
     _jsonSerializerService = jsonSerializerService ?? throw new System.ArgumentNullException(nameof(jsonSerializerService));
     _entityFactory         = entityFactory ?? throw new System.ArgumentNullException(nameof(entityFactory));
     _modelFactory          = modelFactory ?? throw new System.ArgumentNullException(nameof(modelFactory));
     _repositoryService     = repositoryService ?? throw new System.ArgumentNullException(nameof(repositoryService));
 }
Пример #3
0
 public MqttAdapterService(IMqttAdapterFactory mqttAdapterFactory, IWebHostEnvironment webHostEnvironment, IFileSystemService fileSystemService, IJsonSerializerService jsonSerializerService)
 {
     _mqttAdapterFactory    = mqttAdapterFactory;
     _webHostEnvironment    = webHostEnvironment;
     _fileSystemService     = fileSystemService;
     _jsonSerializerService = jsonSerializerService;
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ClimaCellService"/> class. A wrapper for the
        ///     <see href="https://developer.climacell.co/">climacell API</see>.
        /// </summary>
        /// <param name="apiKey">A climacell API key.</param>
        /// <param name="baseUri">Base URI for the climacell API. Defaults to https://api.climacell.co/v3/weather/.</param>
        /// <param name="httpClient">An optional HTTP client to contact an API with (useful for mocking data for testing).</param>
        /// <param name="jsonSerializerService">An optional JSON Serializer to handle converting the response string to an object.</param>
        public ClimaCellService(string apiKey, Uri baseUri = null, IHttpClient httpClient = null, IJsonSerializerService jsonSerializerService = null)
        {
            if (string.IsNullOrWhiteSpace(apiKey))
            {
                throw new ArgumentException($"{nameof(apiKey)} cannot be empty.");
            }

            this.apiKey                = apiKey;
            this.baseUri               = baseUri ?? new Uri("https://api.climacell.co/v3/weather/");
            this.httpClient            = httpClient ?? new ZipHttpClient();
            this.jsonSerializerService = jsonSerializerService ?? new JsonNetJsonSerializerService();
        }
Пример #5
0
 public MqttAdapterFactory(
     IMessageBroker messageBroker,
     IJsonSerializerService jsonSerializerService,
     IEncodingService encodingService,
     IMqttAdapterDbService mqttAdapterDbService,
     IControllerStateService controllerStateService,
     IModelFactory modelFactory)
 {
     _messageBroker          = messageBroker;
     _jsonSerializerService  = jsonSerializerService;
     _encodingService        = encodingService;
     _mqttAdapterDbService   = mqttAdapterDbService ?? throw new ArgumentNullException(nameof(mqttAdapterDbService));
     _controllerStateService = controllerStateService ?? throw new ArgumentNullException(nameof(controllerStateService));
     _modelFactory           = modelFactory ?? throw new ArgumentNullException(nameof(modelFactory));
 }
Пример #6
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="next"></param>
 /// <param name="option"></param>
 public CustomExceptionMiddleWare(RequestDelegate next,
                                  CustomExceptionMiddleWareOption option,
                                  IJsonSerializerService jsonSerializerService,
                                  ILogger <CustomExceptionMiddleWare> logger)
 {
     _next   = next;
     _option = option;
     exceptionStatusCodeDic = new Dictionary <int, string>
     {
         { 401, "未授权的请求" },
         { 404, "找不到该页面" },
         { 403, "访问被拒绝" },
         { 500, "服务器发生意外的错误" }
         //其余状态自行扩展
     };
     _jsonSerializerService = jsonSerializerService;
     _logger = logger;
 }
Пример #7
0
            public void ContextSetup()
            {
                const string filePath      = @"C:\some\dir";
                var          configuration = new StubApplicationConfiguration {
                    StorageFilePath = filePath
                };

                _stubbedModel = new MasterModel();

                var fileSystem = S <IFileSystem>();

                fileSystem.Stub(x => x.FileExists(filePath)).Return(false);

                IJsonSerializerService doNotUseJsonSerializer = null;

                var storage = new FileSystemStorage(fileSystem, doNotUseJsonSerializer, configuration);

                _result = storage.ReadMasterModel();
            }
Пример #8
0
 /// <summary>
 /// Creates a <see cref="BlockOptionsFactory{T}"/>.
 /// </summary>
 /// <param name="jsonSerializerService">The service that handles JSON deserialization.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="jsonSerializerService"/> is <c>null</c>.</exception>
 public BlockOptionsFactory(IJsonSerializerService jsonSerializerService)
 {
     _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
 }
Пример #9
0
 public EntityRepository(IEntityFactory modelFactory, IJsonSerializerService jsonSerializerService)
 {
     _modelFactory          = modelFactory ?? throw new ArgumentNullException(nameof(modelFactory));
     _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
 }
 public Mock <BlockOptionsFactory <IDummyOptions> > CreateMockBlockOptionsFactory(IJsonSerializerService jsonSerializerService = null)
 {
     return(_mockRepository.Create <BlockOptionsFactory <IDummyOptions> >(jsonSerializerService ?? _mockRepository.Create <IJsonSerializerService>().Object));
 }
Пример #11
0
 public SettingsProvider(IFileSystemService fileSystemService, IJsonSerializerService jsonSerializerService)
 {
     _fileSystemService     = fileSystemService ?? throw new global::System.ArgumentNullException(nameof(fileSystemService));
     _jsonSerializerService = jsonSerializerService ?? throw new global::System.ArgumentNullException(nameof(jsonSerializerService));
 }
Пример #12
0
 /// <summary>
 ///     Attempts to deserialize and initialize the parent class with the <see cref="HttpResponseMessage"/> using the
 ///         <see cref="IJsonSerializerService"/> defined in the calling <see cref="ClimaCellService"/> instance.
 /// </summary>
 public static Task Deserialize(HttpResponseMessage responseMessage, IJsonSerializerService jsonSerializerService)
 => throw new NotImplementedException();
Пример #13
0
        /// <summary>
        ///     Attempts to initalize a new <see cref="Daily"/> from the responding <see cref="HttpResponseMessage"/>, and deserializes the response content
        ///     using the <see cref="IJsonSerializerService"/> defined in the calling <see cref="ClimaCellService"/> instance and appends all model objects into the <see cref="ForecastResponse{T}.DataPoints"/> collection.
        ///
        ///     After deserializing, it'll then convert the private <see cref="_model"/> objects into the more readable public Daily <see cref="Model"/> using <see cref="_model.ToDaily(_model)"/>.
        /// </summary>
        public static new async Task <Daily> Deserialize(HttpResponseMessage responseMessage, IJsonSerializerService jsonSerializerService)
        {
            Daily d = new Daily()
            {
                Response = new ClimaCellResponse(responseMessage)
            };

            try
            {
                var models = await jsonSerializerService.DeserializeJsonAsync <List <_model> >(responseMessage.Content?.ReadAsStringAsync()).ConfigureAwait(false);

                d._dataPoints = models.ConvertAll(d => _model.ToDaily(d));
            }
            catch (FormatException e)
            {
                d.Response.IsSuccessStatus = false;
                d.Response.ReasonPhrase    = $"Error parsing results: {e?.InnerException?.Message ?? e.Message}";
            }
            return(d);
        }
Пример #14
0
 public WeatherAdapter(WeatherAdapterInitializationArgument weatherAdapterInitializationArgument,
                       IJsonSerializerService jsonSerializerService,
                       IEncodingService encodingService) : this(jsonSerializerService, encodingService)
 {
     _weatherAdapterInitializationArgument = weatherAdapterInitializationArgument;
 }
Пример #15
0
 public WeatherAdapter(IJsonSerializerService jsonSerializerService, IEncodingService encodingService)
 {
     _jsonSerializerService = jsonSerializerService;
     _encodingService       = encodingService;
 }
 public FizzBuzzResponseHandler(IJsonSerializerService jsonSerializerService)
 {
     JsonSerializerService = jsonSerializerService;
 }
Пример #17
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="jsonSerializerService"></param>
 public HttpRequestService(IJsonSerializerService jsonSerializerService)
 {
     _jsonSerializerService = jsonSerializerService;
 }
Пример #18
0
        /// <summary>
        ///     Attempts to initalize a new <see cref="Hourly"/> from the responding <see cref="HttpResponseMessage"/>, and deserializes the response content
        ///     using the <see cref="IJsonSerializerService"/> defined in the calling <see cref="ClimaCellService"/> instance and appends all model objects into the <see cref="ForecastResponse{T}.DataPoints"/> collection.
        /// </summary>
        public static new async Task <Nowcast> Deserialize(HttpResponseMessage responseMessage, IJsonSerializerService jsonSerializerService)
        {
            Nowcast h = new Nowcast()
            {
                Response = new ClimaCellResponse(responseMessage)
            };

            try
            {
                h._dataPoints = await jsonSerializerService.DeserializeJsonAsync <List <Nowcast.Model> >(responseMessage.Content?.ReadAsStringAsync()).ConfigureAwait(false);
            }
            catch (FormatException e)
            {
                h.Response.IsSuccessStatus = false;
                h.Response.ReasonPhrase    = $"Error parsing results: {e?.InnerException?.Message ?? e.Message}";
            }
            return(h);
        }
Пример #19
0
 public FileSystemStorage(IFileSystem fileSystem, IJsonSerializerService jsonSerializer, IApplicationConfiguration configuration)
 {
     _fileSystem     = fileSystem;
     _jsonSerializer = jsonSerializer;
     _configuration  = configuration;
 }
Пример #20
0
 public SerializerService(IJsonSerializerService jsonSerializerService)
 {
     _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
 }
Пример #21
0
        /// <summary>
        ///     Attempts to deserialize and initialize the parent class with the response content using the
        ///         <see cref="IJsonSerializerService"/> defined in the calling <see cref="ClimaCellService"/> instance.
        /// </summary>
        public static new async Task <Realtime> Deserialize(HttpResponseMessage responseMessage, IJsonSerializerService jsonSerializerService)
        {
            Realtime r;

            try
            {
                r = await jsonSerializerService.DeserializeJsonAsync <Realtime>(responseMessage.Content?.ReadAsStringAsync()).ConfigureAwait(false);

                if (r != null)
                {
                    r.Response = new ClimaCellResponse(responseMessage);
                }
                else
                {
                    r = new Realtime {
                        Response = new ClimaCellResponse(responseMessage)
                    };
                }
            }
            catch (FormatException e)
            {
                r = new Realtime
                {
                    Response = new ClimaCellResponse
                    {
                        IsSuccessStatus = false,
                        ReasonPhrase    = $"Error parsing results: {e?.InnerException?.Message ?? e.Message}"
                    }
                };
            }
            return(r);
        }
Пример #22
0
        private static async Task <TouTiaoResponse <T> > ParseContent <T>(HttpResponseMessage response) where T : class
        {
            TouTiaoResponse <T> res = new TouTiaoResponse <T>()
            {
                IsSuccessStatus = response.IsSuccessStatusCode
            };

            if (!res.IsSuccessStatus)
            {
                return(null);
            }

            var contentType = response.Content.Headers.ContentType;

            switch (contentType.MediaType)
            {
            case "application/json":
                break;

            default:
                res.Response = response.Content as T;
                return(res);
            }

            Task <String> responseContent = response.Content?.ReadAsStringAsync();

            jsonSerializerService = jsonSerializerService
                                    ?? new JsonNetJsonSerializerService();

            try
            {
                res.Error =
                    await jsonSerializerService.DeserializeJsonAsync <TouTiaoError>(responseContent).ConfigureAwait(false);

                if (res.Error.errcode == 0 && String.IsNullOrEmpty(res.Error.errmsg))
                {
                    res.Error = null;
                }

                if (null == res.Error)
                {
                    res.Response =
                        await jsonSerializerService.DeserializeJsonAsync <T>(responseContent).ConfigureAwait(false);

                    if (null != res.Response)
                    {
                        res.IsSuccessStatus = true;
                    }
                }
            }
            catch (FormatException e)
            {
                res.Response             = null;
                res.IsSuccessStatus      = false;
                res.ResponseReasonPhrase = $"Error parsing results: {e?.InnerException?.Message ?? e.Message}";
            }

            if (null != res.Response)
            {
                response.Headers.TryGetValues("x-tt-timestamp", out var responseTimeHeader);
                res.Headers = new ResponseHeaders
                {
                    CacheControl = response.Headers.CacheControl,
                    ResponseTime = responseTimeHeader?.FirstOrDefault(),
                    ContentType  = response.Content.Headers.ContentType
                };
            }

            return(res);
        }
Пример #23
0
 public AdapterFactory(IMessageBroker messageBroker, IJsonSerializerService jsonSerializerService, IEncodingService endEncodingService)
 {
     _messageBroker         = messageBroker;
     _jsonSerializerService = jsonSerializerService;
     _endEncodingService    = endEncodingService;
 }
Пример #24
0
 public CustomCommandConfigurationService(IFileSystemService fileSystemService, IJsonSerializerService jsonSerializerService, ICustomCommandService customCommandService)
 {
     _fileSystemService     = fileSystemService ?? throw new ArgumentNullException(nameof(fileSystemService));
     _jsonSerializerService = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
     _customCommandService  = customCommandService ?? throw new ArgumentNullException(nameof(customCommandService));
 }