Пример #1
0
 public void SetOutputContext(BehaviourTreeExecutionNode node)
 {
     foreach (System.Collections.Generic.KeyValuePair <string, string> record in node.contextLink)
     {
         if (record.Key.StartsWith("out_"))
         {
             this.agent.GetContext()[record.Value] = PropertyReader.GetValue(this, record.Key);
         }
     }
 }
Пример #2
0
        public void GetValue_Indexer2D()
        {
            var reader = new PropertyReader <Foo>();
            var foo    = new Foo
            {
                Bar = "baz"
            };

            Assert.AreEqual("a8", reader.GetValue <int, int, string>(foo, null, 1, 8));
        }
Пример #3
0
        /// <summary>
        /// Renders the specified ASP.NET Session value and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
        {
            if (this.Variable == null)
            {
                return;
            }

            var context = HttpContextAccessor.HttpContext;

            if (context?.Session == null)
            {
                return;
            }
#if !NETSTANDARD_1plus
            var value = PropertyReader.GetValue(Variable, k => context.Session[k], EvaluateAsNestedProperties);
#else
            if (context.Items == null)
            {
                return;
            }

            if (context.Features.Get <ISessionFeature>()?.Session == null)
            {
                return;
            }

            //because session.get / session.getstring also creating log messages in some cases, this could lead to stackoverflow issues.
            //We remember on the context.Items that we are looking up a session value so we prevent stackoverflows
            if (context.Items.ContainsKey(NLogRetrievingSessionValue))
            {
                //prevent stackoverflow
                return;
            }

            context.Items[NLogRetrievingSessionValue] = true;
            object value;
            try
            {
                value = PropertyReader.GetValue(Variable, k => context.Session.GetString(k), EvaluateAsNestedProperties);
            }
            catch (Exception ex)
            {
                InternalLogger.Warn(ex, "Retrieving session value failed. ");
                return;
            }
            finally
            {
                context.Items.Remove(NLogRetrievingSessionValue);
            }
#endif
            var formatProvider = GetFormatProvider(logEvent, Culture);
            builder.Append(Convert.ToString(value, formatProvider));
        }
Пример #4
0
        /// <summary>
        /// Renders the specified ASP.NET Session value and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder" /> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
        {
            if (Variable == null)
            {
                return;
            }

            var context = HttpContextAccessor.HttpContext;

            if (context?.Session == null)
            {
                InternalLogger.Trace("aspnet-session - HttpContext Session is null");
                return;
            }

#if !ASP_NET_CORE
            var value = PropertyReader.GetValue(Variable, context.Session, (session, key) => session.Count > 0 ? session[key] : null, EvaluateAsNestedProperties);
#else
            //because session.get / session.getstring also creating log messages in some cases, this could lead to stackoverflow issues.
            //We remember on the context.Items that we are looking up a session value so we prevent stackoverflows
            if (context.Items == null || context.Features.Get <ISessionFeature>()?.Session == null)
            {
                return;
            }

            if (context.Items.Count > 0 && context.Items.ContainsKey(NLogRetrievingSessionValue))
            {
                return;
            }

            context.Items[NLogRetrievingSessionValue] = true;

            object value;
            try
            {
                value = PropertyReader.GetValue(Variable, context.Session, (session, key) => session.GetString(key), EvaluateAsNestedProperties);
            }
            catch (Exception ex)
            {
                InternalLogger.Warn(ex, "aspnet-session - Retrieving session value failed.");
                return;
            }
            finally
            {
                context.Items.Remove(NLogRetrievingSessionValue);
            }
#endif
            if (value != null)
            {
                var formatProvider = GetFormatProvider(logEvent, Culture);
                builder.Append(Convert.ToString(value, formatProvider));
            }
        }
        /// <summary>
        /// Renders the specified ASP.NET Item value and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
        {
            if (Variable == null)
            {
                return;
            }

            var context        = HttpContextAccessor.HttpContext;
            var value          = PropertyReader.GetValue(Variable, context?.Items, LookupItemValue, EvaluateAsNestedProperties);
            var formatProvider = GetFormatProvider(logEvent, Culture);

            builder.Append(Convert.ToString(value, formatProvider));
        }
Пример #6
0
        /// <summary>
        /// Renders the specified ASP.NET Item value and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
        {
            if (Variable == null)
            {
                return;
            }
            var context = HttpContextAccessor.HttpContext;

            Func <string, object> getVal = k => context.Items[k];

            var value = PropertyReader.GetValue(Variable, getVal, EvaluateAsNestedProperties);

            builder.Append(Convert.ToString(value, CultureInfo.CurrentUICulture));
        }
Пример #7
0
        public void GetValue_Property()
        {
            var reader = new PropertyReader <Foo>();
            var foo    = new Foo
            {
                Bar = "baz"
            };

            Assert.AreEqual("baz", reader.GetValue <string>(foo, nameof(Foo.Bar)));

            reader.GetValues(foo, new ExpressionList <Foo>
            {
                x => x.Bar
            });
        }
Пример #8
0
        /// <summary>
        /// Renders the specified ASP.NET Item value and appends it to the specified <see cref="StringBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
        /// <param name="logEvent">Logging event.</param>
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            if (Variable == null)
            {
                return;
            }

            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            var value = PropertyReader.GetValue(Variable, k => context.Items[k], EvaluateAsNestedProperties);

            builder.Append(Convert.ToString(value, CultureInfo.CurrentUICulture));
        }
    void AddParameterField(BehaviourTreeExecutionNode node, PropertyReader.Variable variable)
    {
        GUILayout.BeginHorizontal();

        object initialValue = PropertyReader.GetValue(node.task, variable.name);

        GUI.color = Color.black;
        GUILayout.Label(variable.name.Split('_')[1], GUI.skin.label);

        GUI.color = Color.white;

        object value = null;

        if (variable.type == typeof(string))
        {
            value = EditorGUILayout.TextField((string)initialValue);
        }
        else if (variable.type == typeof(float))
        {
            value = EditorGUILayout.FloatField((float)initialValue);
        }
        else if (variable.type == typeof(int))
        {
            value = EditorGUILayout.IntField((int)initialValue);
        }
        else if (variable.type == typeof(double))
        {
            value = EditorGUILayout.DoubleField((double)initialValue);
        }
        else if (variable.type == typeof(bool))
        {
            value = EditorGUILayout.Toggle((bool)initialValue);
        }

        if (value == null)
        {
            GUILayout.EndHorizontal();
            return;
        }

        if (value != initialValue)
        {
            SerializedObject taskSerializedAsset = new SerializedObject(node.task);

            taskSerializedAsset.Update();

            PropertyReader.SetValue(node.task, variable.name, value);

            SerializedProperty p = taskSerializedAsset.FindProperty(variable.name);

            if (value is string)
            {
                p.stringValue = (string)value;
            }
            else if (value is float)
            {
                p.floatValue = (float)value;
            }
            else if (value is int)
            {
                p.intValue = (int)value;
            }
            else if (value is double)
            {
                p.doubleValue = (double)value;
            }
            else if (value is bool)
            {
                p.boolValue = (bool)value;
            }

            taskSerializedAsset.ApplyModifiedProperties();

            BehaviourTreeEditorWindow.SaveNodeAnChildren(node);
        }

        GUILayout.EndHorizontal();
    }