예제 #1
0
        public bool Update(int id, RequestLine rl)
        {
            //do so only updating the one you want
            if (rl == null)
            {
                throw new Exception("requestline cannot be null");
            }
            if (id != rl.Id)
            {
                throw new Exception("Id and requestline.Id must match");
            }

            context.Entry(rl).State = EntityState.Modified;//tells state that it is an update not add

            try {
                context.SaveChanges();//trap exception for a dup vendor by doing a try catch
                RecalcRequestTotal(rl.RequestId);
            } catch (DbUpdateException ex) {
                //if get it what will we do
                throw new Exception("requestline must be unique", ex);
                //give developer the origianl exception thrown by doing ex above
            } catch (Exception ex) {
                throw;
            }
            return(true);
        }
예제 #2
0
        public async Task <IActionResult> PutRequestLine(int id, RequestLine requestLine)
        {
            if (id != requestLine.Id)
            {
                return(BadRequest());
            }

            _context.Entry(requestLine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RequestLineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            RecalculateTotal(requestLine.RequestId);

            return(NoContent());
        }
예제 #3
0
        /// <exception cref="Org.Apache.Http.MethodNotSupportedException"></exception>
        public virtual IHttpRequest NewHttpRequest(RequestLine requestline)
        {
            Args.NotNull(requestline, "Request line");
            string method = requestline.GetMethod();

            if (IsOneOf(Rfc2616CommonMethods, method))
            {
                return(new BasicHttpRequest(requestline));
            }
            else
            {
                if (IsOneOf(Rfc2616EntityEncMethods, method))
                {
                    return(new BasicHttpEntityEnclosingRequest(requestline));
                }
                else
                {
                    if (IsOneOf(Rfc2616SpecialMethods, method))
                    {
                        return(new BasicHttpRequest(requestline));
                    }
                    else
                    {
                        throw new MethodNotSupportedException(method + " method not supported");
                    }
                }
            }
        }
예제 #4
0
 public async Task <IActionResult> PutRequestLine(int id, RequestLine requestLine)
 {
     if (id != requestLine.Id)
     {
         return(BadRequest());
     }
     _context.Entry(requestLine).State = EntityState.Modified;
     if (requestLine.Quantity > 0)
     {
         try {
             await _context.SaveChangesAsync();
             await CalcSubtotal(requestLine.RequestId);
         }
         catch (DbUpdateConcurrencyException) {
             if (!RequestLineExists(id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
     }
     else
     {
         return(StatusCode(405));                /////// CHECKBACK
     }
     return(NoContent());
 }
        public async Task <IActionResult> PutRequestLine(int id, RequestLine requestLine)
        {
            if (id != requestLine.Id)
            {
                return(BadRequest());
            }

            _context.Entry(requestLine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                //call recalculate
                var success = RecalculateRequestTotal(id);
                if (!success)
                {
                    return(this.StatusCode(500));
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RequestLineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,RequestId,ProductId,Quantity")] RequestLine requestLine)
        {
            if (id != requestLine.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(requestLine);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RequestLineExists(requestLine.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(requestLine));
        }
예제 #7
0
 //overload delete
 public bool Delete(RequestLine rl)
 {
     context.Requestlines.Remove(rl);
     context.SaveChanges();
     RecalcRequestTotal(rl.RequestId);
     return(true);
 }
예제 #8
0
 /// <exception cref="Apache.Http.ProtocolException"></exception>
 public RequestWrapper(IHttpRequest request) : base()
 {
     Args.NotNull(request, "HTTP request");
     this.original = request;
     SetParams(request.GetParams());
     SetHeaders(request.GetAllHeaders());
     // Make a copy of the original URI
     if (request is IHttpUriRequest)
     {
         this.uri     = ((IHttpUriRequest)request).GetURI();
         this.method  = ((IHttpUriRequest)request).GetMethod();
         this.version = null;
     }
     else
     {
         RequestLine requestLine = request.GetRequestLine();
         try
         {
             this.uri = new URI(requestLine.GetUri());
         }
         catch (URISyntaxException ex)
         {
             throw new ProtocolException("Invalid request URI: " + requestLine.GetUri(), ex);
         }
         this.method  = requestLine.GetMethod();
         this.version = request.GetProtocolVersion();
     }
     this.execCount = 0;
 }
예제 #9
0
        public void printRelationshipRequests()
        {
            IEnumerable <Datas.RelationshipRequest> relationshipRequests = from ar in Bdd.DbAccess.RelationshipRequests
                                                                           where ar.idCalled == App.user.ID
                                                                           select ar;


            this.sPRelationshipRequest.Children.Clear();
            foreach (Datas.RelationshipRequest request in relationshipRequests)
            {
                Datas.User caller = (from u in Bdd.DbAccess.Users
                                     where u.ID == request.idCaller
                                     select u).FirstOrDefault();
                if (caller == null)
                {
                    return;
                }
                Datas.Grade grade = (from g in Bdd.DbAccess.Grades
                                     where g.ID == caller.idGrade
                                     select g).FirstOrDefault();
                if (grade == null)
                {
                    return;
                }

                RequestLine line = new RequestLine();
                line.setName(caller.username, caller.ID);
                line.setGrade(grade.name);
                this.sPRelationshipRequest.Children.Add(line);
            }
        }
        public async Task <ActionResult <RequestLine> > PostRequestLines(RequestLine requestLines)
        {
            _context.RequestLines.Add(requestLines);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRequestLines", new { id = requestLines.Id }, requestLines));
        }
예제 #11
0
        // Структура http-запроса: https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
        public static Request StupidParse(byte[] requestBytes)
        {
            string requestString = Encoding.ASCII.GetString(requestBytes);

            RequestLine requestLine = ParseRequestLine(requestString, out int readCharsCount);

            List <Header> headers = ParseHeaders(requestString, ref readCharsCount);

            if (headers == null)
            {
                return(null);
            }

            int readBytesCount = Encoding.ASCII.GetBytes(requestString.Substring(0, readCharsCount)).Length;

            byte[] messageBody = ParseMessageBody(requestBytes, headers, readBytesCount);
            if (messageBody == null)
            {
                return(null);
            }

            return(new Request
            {
                Method = requestLine.Method,
                RequestUri = requestLine.RequestUri,
                HttpVersion = requestLine.HttpVersion,
                Headers = headers,
                MessageBody = messageBody
            });
        }
예제 #12
0
 private void Initialize()
 {
     RequestLine.Clear();
     HeaderList.Clear();
     MessageBody = null;
     c           = TextStore.ReadChar();
 }
        public RequestLine Update(RequestLine requestLine)
        {
            if (requestLine == null)
            {
                throw new Exception("Can't be null");
            }
            var DBRequestLine = _context.RequestLines.SingleOrDefault(x => x.Id == requestLine.Id);

            if (DBRequestLine == null)
            {
                throw new Exception("Can't find Requestline in database!");
            }
            else
            {
                try {
                    DBRequestLine.Quantity  = requestLine.Quantity;
                    DBRequestLine.ProductId = requestLine.ProductId;
                    int OriginalRequestID = DBRequestLine.RequestId;
                    DBRequestLine.RequestId = requestLine.RequestId;
                    _context.SaveChanges();
                    RecalculateTotal(OriginalRequestID);
                    RecalculateTotal(requestLine.RequestId);
                } catch (DbUpdateException ex) {
                    throw new Exception("Must be unique", ex);
                } catch (Exception) {
                    throw;
                }
            }
            return(requestLine);
        }
예제 #14
0
 public static bool Delete(RequestLine requestline)
 {
     // edit checking goes here
     context.RequestLines.Remove(requestline);
     RecalcTotal(requestline.RequestId);
     return(true);
 }
예제 #15
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,ProductId,RequestId")] RequestLine requestLine)
        {
            if (id != requestLine.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(requestLine);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RequestLineExists(requestLine.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", requestLine.ProductId);
            ViewData["RequestId"] = new SelectList(_context.Requests, "Id", "DeliveryMode", requestLine.RequestId);
            return(View(requestLine));
        }
예제 #16
0
        //Create a follow up form containing a list of special requests made during the operation
        public FollowUpSectionForm()
        {
            InitializeComponent();
            RequestLine requestLine = new RequestLine();

            requestLine.doRequestLine(this);
        }
예제 #17
0
 private static void QuantityException(RequestLine requestLine)
 {
     if (requestLine.Quantity < 1)
     {
         throw new Exception("Quantity must be greater than 0");
     }
 }
예제 #18
0
        public void Test2()
        {
            var url     = "GET /docs/index.html HTTP/1.1\r\n";
            var example = new RequestLine();
            var b       = example.Match(url).RemainingText();

            Assert.True(example.Match(url).Success());
        }
예제 #19
0
        public void Test1()
        {
            var url     = "GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1\r\n";
            var example = new RequestLine();
            var b       = example.Match(url).RemainingText();

            Assert.True(example.Match(url).Success());
        }
예제 #20
0
        public void Test4()
        {
            var url     = "POST /myform.html HTTP/1.1\r\n";
            var example = new RequestLine();
            var b       = example.Match(url).RemainingText();

            Assert.True(example.Match(url).Success());
        }
예제 #21
0
 public override byte[] GetHeader(params HttpHeader[] rewrites)
 {
     sb.Clear();
     sb.Append(RequestLine.ToString());
     HeaderList.Format(sb, rewrites);
     sb.Append("\r\n");
     return(Encoding.GetBytes(sb.ToString()));
 }
        public async Task <ActionResult <RequestLine> > PostRequestLine(RequestLine requestLine)
        {
            _context.RequestLine.Add(requestLine);
            await _context.SaveChangesAsync();

            //GetTotal(requestid: requestLine);
            return(CreatedAtAction("GetRequestLine", new { id = requestLine.Id }, requestLine));
        }
예제 #23
0
        public void ToStringTest(string method, string protocol, string version, string result)
        {
            var instance = new RequestLine {
                Method = method, Protocol = protocol, Version = version
            };

            Assert.Equal(instance.ToString(), result);
            Assert.Equal($"{instance}", result);
        }
예제 #24
0
        public void Invalid(string method, string protocol, string version)
        {
            var instance = new RequestLine {
                Method = method, Protocol = protocol, Version = version
            };

            Assert.False(instance.Valid);
            Assert.Throws <InvalidOperationException>(() => instance.Validate());
        }
예제 #25
0
        public void Valid(string method, string protocol, string version)
        {
            var instance = new RequestLine {
                Method = method, Protocol = protocol, Version = version
            };

            Assert.True(instance.Valid);
            Assert.True(instance.Validate() != null);
        }
        // non-javadoc, see interface LineFormatter
        public virtual CharArrayBuffer FormatRequestLine(CharArrayBuffer buffer, RequestLine
                                                         reqline)
        {
            Args.NotNull(reqline, "Request line");
            CharArrayBuffer result = InitBuffer(buffer);

            DoFormatRequestLine(result, reqline);
            return(result);
        }
예제 #27
0
 /// <summary>Returns the request line of this request.</summary>
 /// <remarks>Returns the request line of this request.</remarks>
 /// <seealso cref="BasicHttpRequest(string, string)">BasicHttpRequest(string, string)
 ///     </seealso>
 public virtual RequestLine GetRequestLine()
 {
     if (this.requestline == null)
     {
         this.requestline = new BasicRequestLine(this.method, this.uri, HttpVersion.Http11
                                                 );
     }
     return(this.requestline);
 }
예제 #28
0
        public void you_can_ask_for_the_query_parameters()
        {
            var requestLine = new RequestLine("GET", new Uri("http://xxx?name=value"));
            var instance = new Request(requestLine);
            var theParameters = instance.RequestLine.Parameters;

            Assert.AreEqual(1, theParameters.Count, "Expected one parameters");
            Assert.AreEqual("value", theParameters[0].Value, "Unexpected value for the first parameter");
        }
예제 #29
0
        public async Task <ActionResult <RequestLine> > PostRequestLine(RequestLine requestLine)
        {
            _context.RequestLines.Add(requestLine);
            await _context.SaveChangesAsync();

            await RecalculateRequestLines(requestLine.RequestId);

            return(CreatedAtAction("GetRequestLine", new { id = requestLine.Id }, requestLine));
        }
예제 #30
0
    public IActionResult Update([FromBody] CrudViewModel <RequestLine> payload)
    {
        RequestLine RequestLine = payload.value;

        _context.RequestLine.Update(RequestLine);
        _context.SaveChanges();
        this.UpdateRequest(RequestLine.RequestId);
        return(Ok(RequestLine));
    }
예제 #31
0
        public void Should_Parse_Request_Line()
        {
            var line = new [] { "GET https://www.example.com HTTP/1.1" };

            var requestLine = new RequestLine(line);

            Assert.AreEqual("GET", requestLine.Method);
            Assert.AreEqual("https://www.example.com", requestLine.Url);
            Assert.AreEqual("HTTP/1.1", requestLine.HttpVersion);
        }
예제 #32
0
        public void what_happens_when_a_parameter_is_in_the_query_string_with_the_same_name_twice()
        {
            var requestLine = new RequestLine("GET", new Uri("http://xxx?name=value&name=value_1"));
            var theParameters = requestLine.Parameters;

            Assert.AreEqual(2, theParameters.Count, "Expected two separate parameters, one for each instance in the query string");

            Assert.AreEqual("name"		, theParameters[0].Name, "Unexpected name for the first item");
            Assert.AreEqual("value"		, theParameters[0].Value, "Unexpected value for the first item");
            Assert.AreEqual("name"		, theParameters[1].Name, "Unexpected name for the second item");
            Assert.AreEqual("value_1"	, theParameters[1].Value, "Unexpected value for the seciond item");
        }
예제 #33
0
파일: Request.cs 프로젝트: sq/Fracture
        private IEnumerator<object> RequestTask(ListenerContext context, SocketDataAdapter adapter)
        {
            var startedWhen = DateTime.UtcNow;
            bool successful = false;

            try {
                const int headerBufferSize = 1024 * 32;
                const int bodyBufferSize = 1024 * 128;
                const double requestLineTimeout = 5;

                // RFC2616:
                // Words of *TEXT MAY contain characters from character sets other than ISO-8859-1 [22]
                //  only when encoded according to the rules of RFC 2047 [14].
                Encoding headerEncoding;
                try {
                    headerEncoding = Encoding.GetEncoding("ISO-8859-1");
                } catch {
                    headerEncoding = Encoding.ASCII;
                }

                Request request;
                RequestBody body;
                HeaderCollection headers;
                long bodyBytesRead = 0;
                long? expectedBodyLength = null;

                var reader = new AsyncTextReader(adapter, headerEncoding, headerBufferSize, false);
                string requestLineText;

                while (true) {
                    var fRequestLine = reader.ReadLine();
                    var fRequestOrTimeout = Scheduler.Start(new WaitWithTimeout(fRequestLine, requestLineTimeout));

                    yield return fRequestOrTimeout;

                    if (fRequestOrTimeout.Failed) {
                        if (!(fRequestOrTimeout.Error is TimeoutException))
                            OnRequestError(fRequestOrTimeout.Error);

                        yield break;
                    }

                    if (fRequestLine.Failed) {
                        if (!(fRequestLine.Error is SocketDisconnectedException))
                            OnRequestError(fRequestLine.Error);

                        yield break;
                    }

                    requestLineText = fRequestLine.Result;

                    // RFC2616:
                    // In the interest of robustness, servers SHOULD ignore any empty line(s) received where a
                    //  Request-Line is expected. In other words, if the server is reading the protocol stream
                    //   at the beginning of a message and receives a CRLF first, it should ignore the CRLF.
                    if ((requestLineText != null) && (requestLineText.Trim().Length == 0))
                        continue;

                    break;
                }

                var requestLineParsed = DateTime.UtcNow;

                headers = new HeaderCollection();
                while (true) {
                    var fHeaderLine = reader.ReadLine();
                    yield return fHeaderLine;

                    if (String.IsNullOrWhiteSpace(fHeaderLine.Result))
                        break;

                    headers.Add(new Header(fHeaderLine.Result));
                }

                var headersParsed = DateTime.UtcNow;

                var expectHeader = (headers.GetValue("Expect") ?? "").ToLowerInvariant();
                var expectsContinue = expectHeader.Contains("100-continue");

                string hostName;
                if (headers.Contains("Host")) {
                    hostName = String.Format("http://{0}", headers["Host"].Value);
                } else {
                    var lep = (IPEndPoint)adapter.Socket.LocalEndPoint;
                    hostName = String.Format("http://{0}:{1}", lep.Address, lep.Port);
                }

                var requestLine = new RequestLine(hostName, requestLineText);

                var remainingBytes = reader.DisposeAndGetRemainingBytes();
                bodyBytesRead += remainingBytes.Count;

                var connectionHeader = (headers.GetValue("Connection") ?? "").ToLowerInvariant();
                var shouldKeepAlive =
                    ((requestLine.Version == "1.1") || connectionHeader.Contains("keep-alive")) &&
                    !connectionHeader.Contains("close");

                if (headers.Contains("Content-Length"))
                    expectedBodyLength = long.Parse(headers["Content-Length"].Value);

                body = new RequestBody(remainingBytes, expectedBodyLength);

                if (expectsContinue)
                    yield return adapter.Write(Continue100, 0, Continue100.Length);

                request = new Request(
                    this, adapter, shouldKeepAlive,
                    requestLine, headers, body
                );

                IncomingRequests.Enqueue(request);

                var requestEnqueued = DateTime.UtcNow;
                DateTime? requestBodyRead = null;

                // FIXME: I think it's technically accepted to send a body without a content-length, but
                //  it seems to be impossible to make that work right.
                if (expectedBodyLength.HasValue) {
                    using (var bodyBuffer = BufferPool<byte>.Allocate(bodyBufferSize))
                    while (bodyBytesRead < expectedBodyLength.Value) {
                        long bytesToRead = Math.Min(expectedBodyLength.Value - bodyBytesRead, bodyBufferSize);

                        if (bytesToRead <= 0)
                            break;

                        var fBytesRead = adapter.Read(bodyBuffer.Data, 0, (int)bytesToRead);
                        yield return fBytesRead;

                        if (fBytesRead.Failed) {
                            if (fBytesRead.Error is SocketDisconnectedException)
                                break;

                            body.Failed(fBytesRead.Error);
                            OnRequestError(fBytesRead.Error);
                            yield break;
                        }

                        var bytesRead = fBytesRead.Result;

                        bodyBytesRead += bytesRead;
                        body.Append(bodyBuffer.Data, 0, bytesRead);
                    }

                    requestBodyRead = DateTime.UtcNow;
                }

                body.Finish();
                successful = true;

                request.Timing = new Request.TimingData {
                    Line = (requestLineParsed - startedWhen),
                    Headers = (headersParsed - requestLineParsed),
                    Queue = (requestEnqueued - headersParsed),
                    Body = (requestBodyRead - requestEnqueued)
                };
            } finally {
                if (!successful)
                    adapter.Dispose();
            }
        }
예제 #34
0
파일: Request.cs 프로젝트: sq/Fracture
            internal Request(
                HttpServer server, SocketDataAdapter adapter, bool shouldKeepAlive,
                RequestLine line, HeaderCollection headers, RequestBody body
            )
            {
                QueuedWhenUTC = DateTime.UtcNow;
                WeakServer = new WeakReference(server);

                LocalEndPoint = adapter.Socket.LocalEndPoint;
                RemoteEndPoint = adapter.Socket.RemoteEndPoint;

                Line = line;
                Headers = headers;
                Body = body;
                Response = new Response(this, adapter, shouldKeepAlive);

                server.OnRequestCreated(this);
            }
예제 #35
0
 public void it_leaves_query_string_in_uri_if_there_is_one()
 {
     var requestLine = new RequestLine("GET", new Uri("http://xxx?name=value"));
     var instance = new Request(requestLine);
     Assert.That(instance.RequestLine.Uri, Is.EqualTo(new Uri("http://xxx?name=value")), "Expected the Uri to stay the same");
 }