コード例 #1
0
        public PingConnectionString(string connectionString) : base(connectionString)
        {
            _Host = new Lazy <string>(() =>
            {
                return
                (Pairs.GetFirstString("Address")
                 ?? Pairs.GetFirstWithoutKey()
                 ?? throw new Exception("Address parameter is undefined"));
            });

            _Timeout = new Lazy <int>(() =>
            {
                return(Pairs.GetFirstInt("Timeout", defVal: 2000, min: 1, max: 120000));
            });

            _Ttl = new Lazy <int>(() =>
            {
                return(Pairs.GetFirstInt("Ttl", defVal: 64, min: 1, max: 255));
            });

            _Size = new Lazy <int>(() =>
            {
                return(Pairs.GetFirstInt("Size", defVal: 32, min: 1, max: 128 * 1024));
            });

            _AllowFragment = new Lazy <bool>(() =>
            {
                return(Pairs.GetFirstBool("AllowFragment", defVal: true));
            });
        }
コード例 #2
0
        public HttpConnectionString(string connectionString) : base(connectionString)
        {
            _Uri = new Lazy <string>(() =>
            {
                var ret = Pairs.GetFirstString("Uri") ?? Pairs.GetFirstWithoutKey();
                if (string.IsNullOrEmpty(ret))
                {
                    throw new ArgumentException("Uri parameter is expected");
                }
                return(ret);
            });

            _Timeout = new Lazy <int>(() =>
            {
                return(Pairs.GetFirstInt("Timeout", defVal: 30000, min: 1));
            });

            _Method = new Lazy <string>(() =>
            {
                return(Pairs.GetFirstString("Method") ?? "Get");
            });

            _Payload = new Lazy <string>(() =>
            {
                return(Pairs.GetFirstString("Payload"));
            });

            _ExpectedStatus = new Lazy <ExpectedStatusCodes>(() =>
            {
                string v = Pairs.GetFirstString("Valid Status");
                return(v == null ? ExpectedStatusCodes.Normal : new ExpectedStatusCodes(v));
            });

            _AllowUntrusted = new Lazy <bool>(() =>
            {
                return(Pairs.GetFirstBool("Allow Untrusted", true));
            });

            _Headers = new Lazy <IEnumerable <Header> >(() =>
            {
                var lookup = Pairs
                             .Where(x => x.HasKey && x.Key.TrimStart().StartsWith("*"))
                             .ToLookup(x => x.Key.TrimStart(), x => x.Value);

                List <Header> ret = new List <Header>();
                foreach (var item in lookup)
                {
                    ret.Add(new Header()
                    {
                        Name   = item.Key.Substring(1),
                        Values = new List <string>(item.ToList())
                    });
                }

                // if (Debugger.IsAttached && ConnectionString.IndexOf("Smart") >= 0) Debugger.Break();
                return(ret);
            });
        }