コード例 #1
0
        //get value for key (name)
        public object Get(ValueDto req)
        {
            var value = new Value ().PopulateWith (req);
            value.Hash=DHTServerCtx.HashFunction.apply (req.Key);
            var redir = this.checkRedirect (value.Hash, req.Key);
            if (redir != null) {
                return redir;
            }
            var found = Db.Select<Value> (q => q.HashHexString == value.HashHexString);

            if (found.IsEmpty()) {
                return new HttpResult { StatusCode = HttpStatusCode.NotFound };
            }

            var valueDto = found.Select (v => new ValueDto ().PopulateWith (v)).First ();
            return new ValueDtoResponse (valueDto);
        }
コード例 #2
0
        //create or update value for key (name)
        public object Put(ValueDto req)
        {
            var value = new Value ().PopulateWith (req);
            value.Hash=DHTServerCtx.HashFunction.apply (req.Key);
            var redir = this.checkRedirect (value.Hash, req.Key);
            if (redir != null) {
                return redir;
            }

            var found = Db.Select<Value> (q => q.HashHexString == value.HashHexString);

            if (found.IsEmpty()) {
                Db.Insert<Value> (value);
            } else {
                Db.Save<Value> (value);
            }

            return new HttpResult { StatusCode = HttpStatusCode.Accepted };
        }
コード例 #3
0
        //delete value for key (name)
        public object Delete(ValueDto req)
        {
            var value = new Value ().PopulateWith (req);
            value.Hash=DHTServerCtx.HashFunction.apply (req.Key);

            var redir = this.checkRedirect (value.Hash, req.Key);
            if (redir != null) {
                return redir;
            }

            var found = Db.Select<Value> (q => q.HashHexString == value.HashHexString);

            if (found.IsEmpty()) {
                return new HttpResult { StatusCode = HttpStatusCode.NotFound };
            }

            Db.Delete<Value> (q => q.HashHexString == value.HashHexString);
            return new HttpResult { StatusCode = HttpStatusCode.NoContent };
        }