Ejemplo n.º 1
0
        protected override void ReadImplementation(IResponseReader responseReader, ushort _)
        {
            uint wholeTime      = responseReader.ReadUInt();
            uint fractionalTime = (byte)responseReader.ReadByte();

            Value = (decimal?)Convert.ToDecimal(wholeTime + (fractionalTime * 0.01));
        }
Ejemplo n.º 2
0
        protected override void ReadImplementation(IResponseReader responseReader, ushort size)
        {
            if (size == 3)
            {
                Value = (Capabilities) new Capabilities
                {
                    MaxRxFrame    = (byte)responseReader.ReadByte(),
                    MaxTxFrame    = (byte)responseReader.ReadByte(),
                    MinInterframe = (byte)responseReader.ReadByte()
                };
            }
            else if (size == 2)
            {
                Value = (Capabilities) new Capabilities();

                for (int i = 0; i < 2; i++)
                {
                    Value.Code0x01[i] = (byte)responseReader.ReadByte();
                }
            }
            else if (size == 11)
            {
                Value = (Capabilities) new Capabilities();

                for (int i = 0; i < 11; i++)
                {
                    Value.Code0x02[i] = (byte)responseReader.ReadByte();
                }
            }

            Value = Value;
        }
 public StormglassParametersProvider(IResponseReader respReader, IWebServerHelper webHelper)
 {
     Weather         = new WeatherCharacterization();
     this.webHelper  = webHelper;
     this.respReader = respReader;
     paramsFiller    = new StormglassioParametersFiller();
 }
Ejemplo n.º 4
0
 public AuthenticationApi(IMemoryCache cache, IConfiguration configuration, IHttpService httpService, IResponseReader responseReader)
 {
     _cache          = cache;
     _configuration  = configuration;
     _httpService    = httpService;
     _responseReader = responseReader;
 }
Ejemplo n.º 5
0
        public static string ReadDCS(this IResponseReader reader)
        {
            var cc = new ControlCodes();

            var code = reader.ReadNext();

            switch (code)
            {
            case 27:
                reader.ReadOrDie((byte)'P');
                break;

            default:
                throw new Exception($"Expected DCS, found {code}");
            }


            var result = "";

            while (!result.EndsWith(cc.ST) && !result.EndsWith((char)(0x9c)))
            {
                var c = reader.ReadNextChar();
                result += c;
            }

            if (result.EndsWith(cc.ST))
            {
                return(result.Substring(0, result.Length - 2));
            }
            else
            {
                return(result.Substring(0, result.Length - 1));
            }
        }
 public void DisplayStormglassioWeather(IResponseReader respReader)
 {
     if (StormglassioParamsFiller.FillParameters(stormglassioWebHelper, respReader))
     {
         writer.Parameters = StormglassioParamsFiller.Parameters;
         Answer           += writer.ShowSiteWeather();
     }
 }
        protected override void ReadImplementation(IResponseReader responseReader, ushort _)
        {
            byte hour   = (byte)responseReader.ReadByte();
            byte minute = (byte)responseReader.ReadByte();
            byte second = (byte)responseReader.ReadByte();

            Value = (TimeSpan?)new TimeSpan(hour, minute, second);
        }
Ejemplo n.º 8
0
 public StormglassioWeatherDisplayer(IWebServerHelper stormglassioHelper, IParametersFiller <StormglassDataHolder> stormglassioParamsFiller,
                                     IResponseReader respReader, ConsoleWriter writer)
 {
     ParamsFiller = stormglassioParamsFiller;
     Writer       = writer;
     WebHelper    = stormglassioHelper;
     RespReader   = respReader;
 }
 public void DisplayTomorrowioWeather(IResponseReader respReader)
 {
     if (TomorrowioParamsFiller.FillParameters(tomorrowioWebHelper, respReader))
     {
         writer.Parameters = TomorrowioParamsFiller.Parameters;
         Answer           += writer.ShowSiteWeather();
     }
 }
 public TomorrowioWeatherDisplayer(IWebServerHelper tomorrowioHelper, IParametersFiller <TomorrowDataHolder> tomorrowioParamsFiller,
                                   IResponseReader respReader, ConsoleWriter writer)
 {
     ParamsFiller = tomorrowioParamsFiller;
     Writer       = writer;
     WebHelper    = tomorrowioHelper;
     RespReader   = respReader;
 }
Ejemplo n.º 11
0
 public RequestHandler(IJsonRpcErrorFactory errorFactory, HeaderJsonRpcSerializer headerJsonRpcSerializer, INestedContextFactory nestedContextFactory, IResponseReader responseReader, IOptions <JsonRpcOptions> options, ILogger <RequestHandler> log)
 {
     this.errorFactory            = errorFactory;
     this.headerJsonRpcSerializer = headerJsonRpcSerializer;
     this.nestedContextFactory    = nestedContextFactory;
     this.responseReader          = responseReader;
     this.log     = log;
     this.options = options.Value;
 }
Ejemplo n.º 12
0
        static void ReadOrDie(this IResponseReader reader, byte expected)
        {
            var ch = reader.ReadNext();

            if (ch != expected)
            {
                throw new Exception($"expected {expected} but read {ch}");
            }
        }
Ejemplo n.º 13
0
 public WombatController(ILogger <WombatController> logger, IBurrowUpdater updater, IResponseReader reader,
                         IResponseHelper helper, IHistoryHandler historyHandler)
 {
     _logger         = logger;
     _updater        = updater;
     _reader         = reader;
     _helper         = helper;
     _historyHandler = historyHandler;
 }
Ejemplo n.º 14
0
 protected override void ReadImplementation(IResponseReader responseReader, ushort _)
 {
     Value = new UserInfo
     {
         Weight = responseReader.ReadUShort(),
         Units  = (UnitType)responseReader.ReadByte(),
         Age    = responseReader.ReadByte(),
         Gender = (Gender)responseReader.ReadByte()
     };
 }
        public LogicalConnection(ClientOptions options, RequestIdCounter requestIdCounter)
        {
            _clientOptions    = options;
            _requestIdCounter = requestIdCounter;
            _msgPackContext   = options.MsgPackContext;
            _logWriter        = options.LogWriter;

            _physicalConnection = new NetworkStreamPhysicalConnection();
            _responseReader     = new ResponseReader(_clientOptions, _physicalConnection);
            _requestWriter      = new RequestWriter(_clientOptions, _physicalConnection);
        }
        protected override void ReadImplementation(IResponseReader responseReader, ushort _)
        {
            byte[] serialBytes = new byte[9];

            for (int i = 0; i < 9; i++)
            {
                serialBytes[i] = (byte)responseReader.ReadByte();
            }

            Value = (string?)System.Text.Encoding.ASCII.GetString(serialBytes);
        }
 protected override void ReadImplementation(IResponseReader responseReader, ushort _)
 {
     Value = (ProductVersion?)new ProductVersion
     {
         ManufacturerId  = (byte)responseReader.ReadByte(),
         CID             = (byte)responseReader.ReadByte(),
         Model           = (byte)responseReader.ReadByte(),
         HardwareVersion = (ushort)responseReader.ReadUShort(),
         SoftwareVersion = (ushort)responseReader.ReadUShort()
     };
 }
Ejemplo n.º 18
0
        protected override void ReadImplementation(IResponseReader responseReader, ushort _)
        {
            byte          size       = (byte)responseReader.ReadByte();
            List <ushort> heartbeats = new List <ushort>();

            for (int i = 0; i < size; i += 2)
            {
                heartbeats.Add((ushort)responseReader.ReadUShort());
            }

            Value = (ushort[]?)heartbeats.ToArray();
        }
Ejemplo n.º 19
0
        public override sealed async Task <T> ReadResponse(IResponseReader reader)
        {
            var line = await reader.ReadLine();

            StorageCommandResult result;
            T actualResult;

            if (Util.TryParseStorageCommandResult(line.Parts[0], out result) && TryConvertResult(result, out actualResult))
            {
                return(actualResult);
            }
            throw Util.CreateUnexpectedResponseLine(this, line.Line);
        }
 public bool FillParameters(IWebServerHelper webHelper, IResponseReader respReader)
 {
     tomorrowRequestFiller.FillRequestURL(webHelper);
     if (webHelper.MakeRequest())
     {
         respReader.Response = webHelper.Response;
         string             json = respReader.GetResponseInfo();
         TomorrowDataHolder tomorrowDataHolder = JsonConvert.DeserializeObject <TomorrowDataHolder>(json);
         Parameters = tomorrowMapper.GetParameters(tomorrowDataHolder);
         return(true);
     }
     return(false);
 }
 public bool FillParameters(IWebServerHelper webHelper, IResponseReader respReader)
 {
     stormglassRequestFiller.FillRequestURL(webHelper);
     if (webHelper.MakeRequest())
     {
         respReader.Response = webHelper.Response;
         string json = respReader.GetResponseInfo();
         StormGlassDataHolder stormglassDataHolder = JsonConvert.DeserializeObject <StormGlassDataHolder>(json);
         Parameters = stormglassMapper.GetParameters(stormglassDataHolder);
         return(true);
     }
     return(false);
 }
 public bool FillParameters(IWebServerHelper webHelper, IResponseReader respReader)
 {
     RequestURLFiller.FillRequestURL(webHelper);
     if (webHelper.MakeRequest())
     {
         respReader.Response = webHelper.Response;
         string json = respReader.GetResponseInfo();
         ExtractParameters(json);
         return(true);
     }
     Answer = webHelper.Answer;
     return(false);
 }
Ejemplo n.º 23
0
        public override async Task <bool> ReadResponse(IResponseReader reader)
        {
            var responseLine = await reader.ReadLine();

            if (responseLine.Parts[0] == "DELETED")
            {
                return(true);
            }
            if (responseLine.Parts[0] == "NOT_FOUND")
            {
                return(false);
            }
            throw Util.CreateUnexpectedResponseLine(this, responseLine.Line);
        }
Ejemplo n.º 24
0
        public OrientRepo(
            IJsonManger jsonManager_, ITokenBuilder tokenBuilder_, ITypeConverter typeConverter_, ITextBuilder textBuilder_,
            IWebManager webManger_, IResponseReader responseReader_)
        {
            this.jm  = jsonManager_;
            this.tb  = tokenBuilder_;
            this.tk  = typeConverter_;
            this.txb = textBuilder_;
            this.wm  = webManger_;
            this.ir  = responseReader_;

            AuthUrl    = txb.Build(TokenRepo.authUrl, new OrientAuthenticationURLFormat());
            CommandUrl = txb.Build(TokenRepo.commandUrl, new OrientCommandURLFormat());
        }
 protected override void ReadImplementation(IResponseReader responseReader, ushort _)
 {
     Value = (StrokeStatistics?)new StrokeStatistics()
     {
         Distance      = (ushort)responseReader.ReadUShort(),
         DriveTime     = (byte)responseReader.ReadByte(),
         RecoveryTime  = (ushort)responseReader.ReadUShort(),
         Length        = (byte)responseReader.ReadByte(),
         Count         = (ushort)responseReader.ReadUShort(),
         Peak          = (ushort)responseReader.ReadUShort(),
         ImpulseForce  = (ushort)responseReader.ReadUShort(),
         AverageForce  = (ushort)responseReader.ReadUShort(),
         WorkPerStroke = (ushort)responseReader.ReadUShort()
     };
 }
Ejemplo n.º 26
0
        public override async Task <MemcachedItem> ReadResponse(IResponseReader reader)
        {
            var result = await reader.ReadItem();

            if (result != null)
            {
                var nextItem = await reader.ReadItem();

                if (nextItem != null)
                {
                    throw new MemcachedException("Memcached returned more items than expected.");
                }
            }
            return(result);
        }
Ejemplo n.º 27
0
        public override async Task <ulong?> ReadResponse(IResponseReader reader)
        {
            var line = await reader.ReadLine();

            if (line.Parts[0] == "NOT_FOUND")
            {
                return(null);
            }
            ulong result;

            if (ulong.TryParse(line.Parts[0], out result))
            {
                return(result);
            }
            throw Util.CreateUnexpectedResponseLine(this, line.Line);
        }
Ejemplo n.º 28
0
        public void Read(IResponseReader responseReader)
        {
            if (ResponseSize == 0)
            {
                return;
            }

            ushort size = (ushort)responseReader.ReadByte();

            if (size == ResponseSize)
            {
                ReadImplementation(responseReader, size);
            }
            else
            {
                throw new InvalidOperationException($"Unexpected size. Encountered size [{size}] and expected [{ResponseSize}].");
            }
        }
 protected override void ReadImplementation(IResponseReader responseReader, ushort _)
 {
     Value = (DisplayUnitsType?)responseReader.ReadByte();
 }
Ejemplo n.º 30
0
 protected override void ReadImplementation(IResponseReader responseReader, ushort _)
 {
     Value = (OperationalState?)responseReader.ReadByte();
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Adds the reader to this crawler object. This means that the reader
        /// will be called for all subsequent web requests. This method returns
        /// the instance of this crawler to support method chaining.
        /// </summary>
        /// <param name="responseReader">The response reader.</param>
        /// <returns>
        /// Returns this instance to support method chaining.
        /// </returns>
        public Crawler AddReader( IResponseReader responseReader )
        {
            this.responseReaders.Add( responseReader );

            return this;
        }