Exemplo n.º 1
0
        /// <inheritdoc />
        public void Configure(IReadAccessor <string> reader)
        {
            ArgumentGuard.NotNull(reader, nameof(reader));

            string traceMsg = Tracer.FormatCall("Configure");

            try
            {
                logger_.Log(traceMsg);

#pragma warning disable IDE0018 // Inline variable declaration
                string value;
#pragma warning restore IDE0018 // Inline variable declaration
                if (reader.TryGetValue(this, "MonitorHost", out value))
                {
                    MonitorHost = bool.Parse(value);
                }

                if (reader.TryGetValue(this, "MonitorProcessesByName", out value))
                {
                    MonitorProcessesByName =
                        string.IsNullOrEmpty(value) ? null : new Regex(value);
                }

                if (reader.TryGetValue(this, "MonitorProcessesById", out value))
                {
                    MonitorProcessesById = value.ToInt32();
                }

                if (reader.TryGetValue(this, "MonitorWindowsByTitle", out value))
                {
                    MonitorWindowsByTitle =
                        string.IsNullOrEmpty(value) ? null : new Regex(value);
                }

                if (reader.TryGetValue(this, "CapturePadding", out value))
                {
                    CapturePadding =
                        string.IsNullOrEmpty(value) ? default(RectangularMargins) : RectangularMargins.Parse(value);
                }

                logger_.Verbose("{0} succeeded", traceMsg);
            }
            catch (Exception ex)
            {
                CommonUtils.LogExceptionStackTrace(logger_, Stage.Check, StageType.CaptureScreenshot, ex);
                throw;
            }
        }
Exemplo n.º 2
0
        internal static void WriteInner(AccessorMembers members, IReadAccessor reader, Utf8JsonWriter writer, IShaped value, JsonSerializerOptions options)
        {
            if (value.Body != null)
            {
                foreach (var field in value.Fields)
                {
                    if (!members.TryGetValue(field, out var member))
                    {
                        continue;
                    }

                    if (!member.CanRead)
                    {
                        continue;
                    }

                    // key:
                    var propertyName = options.PropertyNamingPolicy?.ConvertName(member.Name) ?? member.Name;
                    writer.WritePropertyName(propertyName);

                    // value (can be null):
                    reader.TryGetValue(value.Body, member.Name, out var item);
                    JsonSerializer.Serialize(writer, item, options);
                }
            }
        }
        private static object ResolveValue(object @object, IEnumerable <IFieldTransform> transforms, IReadAccessor accessor, AccessorMember v)
        {
            foreach (var field in transforms)
            {
                if (field.TryTransform(accessor, @object, v, out var transformed))
                {
                    return(transformed);
                }
            }

            accessor.TryGetValue(@object, v.Name, out var untransformed);
            return(untransformed);
        }
Exemplo n.º 4
0
        internal static void WriteInner(AccessorMembers members, IReadAccessor reader, Utf8JsonWriter writer, DeltaAnnotated <T> value, JsonSerializerOptions options)
        {
            if (value.Data != null)
            {
                foreach (var member in members)
                {
                    if (!member.CanRead)
                    {
                        continue;
                    }

                    // key:
                    var propertyName = options.PropertyNamingPolicy?.ConvertName(member.Name) ?? member.Name;
                    writer.WritePropertyName(propertyName);

                    // value (can be null):
                    reader.TryGetValue(value.Data, member.Name, out var item);
                    JsonSerializer.Serialize(writer, item, options);
                }
            }

            WriteAnnotation(writer, value);
        }