Example #1
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var iterable = _iterable.Compose(
                input,
                parentPath);

            if (!iterable.IsSuccess)
            {
                throw new NotImplementedException("handle possible problems");
            }


            if (iterable.Value is JArray array)
            {
                var results = new List <Composition>();

                foreach (var jToken in array)
                {
                    var scopedInput = GetScopedInput(
                        input,
                        jToken);

                    var composition = _lambdaOperation.Compose(
                        scopedInput,
                        parentPath);

                    if (!composition.IsSuccess)
                    {
                        throw new NotImplementedException("handle possible problems");
                    }

                    results.Add(composition);
                }

                return(new CorrectComposition(
                           new JArray(
                               results.Select(x => x.Value).ToArray())));
            }
            else
            {
                var scopedInput = GetScopedInput(
                    input,
                    iterable.Value);

                var composition = _lambdaOperation.Compose(
                    scopedInput,
                    parentPath);

                if (!composition.IsSuccess)
                {
                    throw new NotImplementedException("handle possible problems");
                }

                return(new CorrectComposition(
                           new JArray(composition.Value)));
            }
        }
Example #2
0
        public void ComposeSeries(int firstRegisterAddress, int registerCount, MessageType messageType, OperationType operationType, byte[] expected)
        {
            // Arrange
            // fill checkSums
            expected[3] = CheckSum.Crc8(expected.AsSpan().Slice(0, 3).ToArray());
            expected[expected.Length - 1] = CheckSum.Crc8(expected.AsSpan().Slice(0, expected.Length - 1).ToArray());

            IRegisterMessage message = _messageFactory.CreateSeries(firstRegisterAddress, registerCount, operationType, messageType);

            // Act
            byte[] actual = _composer.Compose(message, out IReadOnlyCollection <IRegisterGroup> composedGroups);

            // Assert
            Assert.Equal(expected, actual);
        }
Example #3
0
        public ConditionResult Evaluate(JObject input)
        {
            var left = _left.Compose(
                input,
                Path.Root);

            if (!left.IsSuccess)
            {
                return(new ConditionResult.Failure(new []
                {
                    new ConditionFailed(
                        left.Errors),
                }));
            }

            var right = _right.Compose(
                input,
                Path.Root);

            if (!right.IsSuccess)
            {
                return(new ConditionResult.Failure(new[]
                {
                    new ConditionFailed(
                        left.Errors),
                }));
            }

            var areEqual = JToken.DeepEquals(
                left.Value,
                right.Value);

            return(new ConditionResult.Success(
                       areEqual));
        }
        public ElementComposition Compose(
            JObject input,
            Path parentPath,
            int index)
        {
            var composition = _composerToSpread.Compose(
                input,
                parentPath);

            if (!composition.IsSuccess)
            {
                return(InnerCompositionFailed(
                           parentPath,
                           index,
                           composition));
            }

            if (composition.Value is JArray jArray)
            {
                return(new ElementComposition.Success(
                           index,
                           jArray));
            }

            return(new ElementComposition.Success(
                       index,
                       new[] { composition.Value }));
        }
Example #5
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var iterable = _iterable.Compose(
                input,
                parentPath);

            if (!iterable.IsSuccess)
            {
                throw new NotImplementedException("handle possible problems");
            }

            if (iterable.Value is JArray array)
            {
                var results = new List <JToken>();

                foreach (var jToken in array)
                {
                    var scopedInput = GetScopedInput(
                        input,
                        jToken);

                    var conditionResult = _condition.Evaluate(
                        scopedInput);

                    if (!conditionResult.IsSuccess)
                    {
                        throw new NotImplementedException("handle possible problems");
                    }

                    if (conditionResult.Value)
                    {
                        results.Add(jToken);
                    }
                }

                return(new CorrectComposition(
                           new JArray(results.ToArray())));
            }
            else
            {
                var scopedInput = GetScopedInput(
                    input,
                    iterable.Value);

                var conditionResult = _condition.Evaluate(
                    scopedInput);


                if (!conditionResult.IsSuccess)
                {
                    throw new NotImplementedException("handle possible problems");
                }

                return(new CorrectComposition(
                           new JArray(iterable.Value)));
            }
        }
Example #6
0
 /// <summary>
 /// Writes records of type T, using the specified composer to compose the file.
 /// </summary>
 /// <typeparam name="T">The type of objects to write/compose.</typeparam>
 /// <param name="stream">The <see cref="Stream"/> to write to.</param>
 /// <param name="values">The values to write to the file.</param>
 /// <param name="composer">The <see cref="IComposer{T}"/> to use when writing the file.</param>
 /// <param name="lineseparator">The lineseparator to use (see <see cref="DEFAULTLINESEPARATOR"/>).</param>
 public void WriteRecords <T>(Stream stream, IEnumerable <T> values, IComposer <T> composer, string lineseparator = DEFAULTLINESEPARATOR)
 {
     using (var w = new StreamWriter(stream, composer.Encoding))
     {
         foreach (var v in values)
         {
             w.Write(composer.Compose(v) + lineseparator);
         }
     }
 }
Example #7
0
        public string SaySomething(params string[] something)
        {
            var phrase = this.GetType().Name;

            phrase = phrase + " uses " + composer.GetType().Name + ":";

            //compose things
            something.ToList().ForEach(s => phrase = composer.Compose(phrase, s));

            return(phrase);
        }
Example #8
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var conditionResult = _condition.Evaluate(input);

            return(conditionResult.Value
                ? _ifComposer.Compose(
                       input,
                       parentPath)
                : _elseComposer.Compose(
                       input,
                       parentPath));
        }
Example #9
0
        public Jiml.Result Evaluate(JObject input)
        {
            var result = _composer.Compose(
                input: input,
                parentPath: Path.Root);

            if (result.IsSuccess)
            {
                return(new Jiml.Result(
                           result.Value));
            }

            return(new Jiml.Result(
                       result.Errors));
        }
Example #10
0
        public ElementComposition Compose(
            JObject input,
            Path parentPath,
            int index)
        {
            var composition = _innerComposer.Compose(
                input,
                parentPath.Append(
                    $"[{index}]"));

            return(composition.IsSuccess
                ? CompositionSuccess(
                       index,
                       composition)
                : CompositionFailure(
                       index,
                       composition));
        }
Example #11
0
        public Option <PropertyComposition> Compose(
            JObject input,
            Path parentPath)
        {
            var composition = _innerComposer.Compose(
                input,
                parentPath.AddSegment(Name));

            if (composition.IsSuccess)
            {
                return(new PropertyComposition.Success(
                           Name,
                           composition.Value));
            }

            return(new PropertyComposition.Failure(
                       Name,
                       composition.Errors));
        }
Example #12
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var iterable = _iterable.Compose(
                input,
                parentPath);

            if (!iterable.IsSuccess)
            {
                throw new NotImplementedException("handle possible problems");
            }

            var initialAccumulator = _initialAccumulator.Compose(
                input,
                parentPath);

            if (!initialAccumulator.IsSuccess)
            {
                throw new NotImplementedException("handle possible problems");
            }

            var accValue = initialAccumulator.Value;

            if (iterable.Value is JArray array)
            {
                foreach (var jToken in array)
                {
                    var scopedInput = GetScopedInput(
                        input,
                        jToken,
                        accValue);

                    var composition = _reducer.Compose(
                        scopedInput,
                        parentPath);

                    if (!composition.IsSuccess)
                    {
                        throw new NotImplementedException("handle possible problems");
                    }

                    accValue = composition.Value;
                }

                return(new CorrectComposition(accValue));
            }
            else
            {
                var scopedInput = GetScopedInput(
                    input,
                    iterable.Value,
                    accValue);

                var composition = _reducer.Compose(
                    scopedInput,
                    parentPath);

                if (!composition.IsSuccess)
                {
                    throw new NotImplementedException("handle possible problems");
                }

                return(new CorrectComposition(composition.Value));
            }
        }
Example #13
0
        public ActionResult Index()
        {
            var players = composer.Compose <List <PlayerInformation> >().UsingParameters <PlayerInformationParameters>(new PlayerInformationParameters());

            return(View());
        }