Exemplo n.º 1
0
            private bool ParseBody()
            {
                if (_bodyOnly)
                {
                    _contentLength = _responseText.Length;
                }

                _continuation = false;
                if (_contentLength > 0)
                {
                    var endIndex = _position + _contentLength;
                    if (_currentResponseTextLength + _contentExtraLength < endIndex)
                    {
                        if (_contentQueue.Count == 0)
                        {
                            _responseText = Compact();
                            return(true);
                        }
                        var packet = _contentQueue.Dequeue();
                        _responseText        = Compact() + packet.Content;
                        _contentExtraLength += packet.Utf8ExtraLength;
                        ParseBody();
                        return(false);
                    }
                    _body      = Body.From(_responseText.Substring(_position, endIndex - _position - _contentExtraLength));
                    _position += _contentLength - _contentExtraLength;
                }
                else
                {
                    _body = Body.Empty;
                }
                NextStep();

                return(false);
            }
Exemplo n.º 2
0
 private void ParseBody()
 {
     _continuation = false;
     if (_contentLength > 0)
     {
         var endIndex = _position + _contentLength;
         if (_requestText.Length < endIndex)
         {
             if (_contentQueue.Count == 0)
             {
                 _requestText = Compact();
                 throw new OutOfContentException();
             }
             _requestText = Compact() + _contentQueue.Dequeue();
             ParseBody();
         }
         else
         {
             _body      = Body.From(_requestText.Substring(_position, endIndex - _position));
             _position += _contentLength;
             NextStep();
         }
     }
     else
     {
         _body = Body.Empty;
         NextStep();
     }
 }
Exemplo n.º 3
0
            private bool ParseBody()
            {
                _continuation = false;
                if (_contentLength > 0)
                {
                    var endIndex = _position + _contentLength;
                    if (_requestText.Length < endIndex)
                    {
                        if (_contentQueue.Count == 0)
                        {
                            _requestText = Compact();
                            return(true);
                        }

                        _requestText = Compact() + _contentQueue.Dequeue();
                        ParseBody();
                    }
                    else
                    {
                        _body      = Body.From(_requestText.Substring(_position, endIndex - _position));
                        _position += _contentLength;
                        NextStep();
                    }
                }
                else
                {
                    _body = Body.Empty;
                    NextStep();
                }

                return(false);
            }
Exemplo n.º 4
0
 public Case(TokenSpan span, IExpression?pattern, When?when, Body?body)
 {
     Span    = span;
     Pattern = pattern;
     When    = when;
     Body    = body;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Produces the rollbar data.
        /// </summary>
        /// <returns>Rollbar Data DTO or null (if packaging is not applicable in some cases).</returns>
        protected override Data?ProduceRollbarData()
        {
            Data?data = null;

            switch (this._objectToPackage)
            {
            case Data dataObj:
                data = dataObj;
                break;

            case IRollbarPackage rollbarPackageObj:
                data = rollbarPackageObj.PackageAsRollbarData();
                break;

            default:
                Body?body = this._objectToPackage as Body;
                if (body == null)
                {
                    body = RollbarUtility.PackageAsPayloadBody(this._objectToPackage, ref this._custom);
                }

                data = new Data(null, body, this._custom);
                break;
            }

            if (data != null && !string.IsNullOrWhiteSpace(this._rollbarDataTitle))
            {
                data.Title = this._rollbarDataTitle;
            }

            return(data);
        }
 string?AddNamesToXml(Body?body)
 {
     if (body == null)
     {
         return("");
     }
     return(body.FormattedXml());
 }
Exemplo n.º 7
0
            private void Reset()
            {
                // DO NOT RESET: (1) contentQueue, (2) position, (3) responseText, (4) headers, (5) fullResponses

                _body             = null;
                _contentLength    = 0;
                _continuation     = false;
                _outOfContentTime = 0;
                _status           = 0;
                _version          = null;
            }
Exemplo n.º 8
0
            private void Reset()
            {
                // DO NOT RESET: (1) contentQueue, (2) position, (3) requestText, (4) headers, (5) fullRequests

                _body             = null;
                _contentLength    = 0;
                _continuation     = false;
                _method           = null;
                _outOfContentTime = 0;
                _version          = null;
                _uri = null;
            }
Exemplo n.º 9
0
        public void TestCreateFromDef()
        {
            Body?       body       = BodyFactory.CreateBody(new World(new Vector2(0, 0)));
            CircleShape?shape      = new CircleShape(1, 1);
            FixtureDef? fixtureDef = new FixtureDef
            {
                Shape       = shape,
                Friction    = 0.3f,
                Restitution = 0.5f
            };

            fixture = FixtureFactory.CreateFromDef(body, fixtureDef);
        }
Exemplo n.º 10
0
    protected Response(Version?version, ResponseStatus status, Headers <ResponseHeader> headers, Body?entity)
    {
        Version = version;
        Status  = status;
        var statusDescription = status.GetDescription();

        StatusCode = statusDescription.Substring(0, statusDescription.IndexOf(' '));
        Entity     = EntityFrom(headers, entity !);
        Headers    = AddMissingContentLengthHeader(headers);
    }
Exemplo n.º 11
0
 public static Response Of(Version?version, ResponseStatus statusCode, Headers <ResponseHeader> headers, Body?entity)
 => new Response(version, statusCode, headers, entity);
        private Item?ScanForTargets(VineTile branch)
        {
            Hull    parent   = Behavior.Parent;
            Vector2 worldPos = Behavior.GetWorldPosition() + branch.Position;
            Vector2 pos      = parent.Position + Behavior.Offset + branch.Position;

            Vector2 diameter    = ConvertUnits.ToSimUnits(new Vector2(branch.Rect.Width / 2f, branch.Rect.Height / 2f));
            Vector2 topLeft     = ConvertUnits.ToSimUnits(pos) - diameter;
            Vector2 bottomRight = ConvertUnits.ToSimUnits(pos) + diameter;

            int  highestPriority = 0;
            Item?currentItem     = null;

            foreach (Item item in Item.ItemList.Where(it => !Behavior.ClaimedTargets.Contains(it)))
            {
                if (Behavior.IgnoredTargets.ContainsKey(item))
                {
                    continue;
                }

                int priority = 0;
                foreach (BallastFloraBehavior.AITarget target in Behavior.Targets)
                {
                    if (!target.Matches(item) || target.Priority <= highestPriority)
                    {
                        continue;
                    }
                    priority = target.Priority;
                    break;
                }

                if (priority == 0)
                {
                    continue;
                }

                if (item.Submarine != parent.Submarine || Vector2.Distance(worldPos, item.WorldPosition) > Behavior.Sight)
                {
                    continue;
                }

                Vector2 itemSimPos = ConvertUnits.ToSimUnits(item.Position);

#if DEBUG || UNSTABLE
                Tuple <Vector2, Vector2> debugLine1 = Tuple.Create(parent.Position - ConvertUnits.ToDisplayUnits(topLeft), parent.Position - ConvertUnits.ToDisplayUnits(itemSimPos - diameter));
                Tuple <Vector2, Vector2> debugLine2 = Tuple.Create(parent.Position - ConvertUnits.ToDisplayUnits(bottomRight), parent.Position - ConvertUnits.ToDisplayUnits(itemSimPos + diameter));
                Behavior.debugSearchLines.Add(debugLine2);
                Behavior.debugSearchLines.Add(debugLine1);
#endif

                Body?body1 = Submarine.CheckVisibility(itemSimPos - diameter, topLeft);
                if (Blocks(body1, item))
                {
                    continue;
                }

                Body?body2 = Submarine.CheckVisibility(itemSimPos + diameter, bottomRight);
                if (Blocks(body2, item))
                {
                    continue;
                }

                highestPriority = priority;
                currentItem     = item;
            }

            if (currentItem != null)
            {
                foreach (BallastFloraBranch existingBranch in Behavior.Branches)
                {
                    if (Behavior.BranchContainsTarget(existingBranch, currentItem))
                    {
                        Behavior.ClaimTarget(currentItem, existingBranch);
                        return(null);
                    }
                }

                return(currentItem);
            }

            return(null);
Exemplo n.º 13
0
 public bool TryGetBody(int id, [NotNullWhen(true)] out Body?body)
 {
     return(_bodies.TryGetValue(id, out body));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Packages as payload data.
        /// </summary>
        /// <param name="utcTimestamp">The UTC timestamp of when the object-to-log was captured.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="level">The level.</param>
        /// <param name="obj">The object.</param>
        /// <param name="custom">The custom.</param>
        /// <returns>Data.</returns>
        public static Data?PackageAsPayloadData(
            DateTime utcTimestamp,
            IRollbarLoggerConfig rollbarConfig,
            ErrorLevel level,
            object obj,
            IDictionary <string, object?>?custom = null
            )
        {
            if (!rollbarConfig.RollbarDeveloperOptions.Enabled)
            {
                // nice shortcut:
                return(null);
            }

            if (level < rollbarConfig.RollbarDeveloperOptions.LogLevel)
            {
                // nice shortcut:
                return(null);
            }

            Data?data = obj as Data;

            if (data != null)
            {
                //we do not have to update the timestamp of the data here
                //because we already have the incoming object to log of DTOs.Data type
                //so the timestamp value assigned during its construction should work better:
                data.Level = level;
                return(data);
            }

            IRollbarPackage?rollbarPackagingStrategy = obj as IRollbarPackage;

            if (rollbarPackagingStrategy != null)
            {
                data = rollbarPackagingStrategy.PackageAsRollbarData();
                if (data != null)
                {
                    data.Environment = rollbarConfig?.RollbarDestinationOptions.Environment;
                    data.Level       = level;
                    //update the data timestamp from the data creation timestamp to the passed
                    //object-to-log capture timestamp:
                    data.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(utcTimestamp);
                }
                return(data);
            }

            Body?body = obj as Body;

            if (body == null)
            {
                body = RollbarUtility.PackageAsPayloadBody(obj, ref custom);
            }

            data       = new Data(rollbarConfig, body, custom);
            data.Level = level;
            //update the data timestamp from the data creation timestamp to the passed
            //object-to-log capture timestamp:
            data.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(utcTimestamp);
            return(data);
        }