Пример #1
0
        /// <inheritdoc />
        async Task <Result <T, IError> > IStep <T> .Run(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            using (stateMonad.Logger.BeginScope(Name))
            {
                object[] GetEnterStepArgs()
                {
                    var properties = AllProperties
                                     .ToDictionary(x => x.Name, x => x.GetLogName());

                    return(new object[] { Name, properties });
                }

                LogSituation.EnterStep.Log(stateMonad, this, GetEnterStepArgs());

                var result = await Run(stateMonad, cancellationToken);

                if (result.IsFailure)
                {
                    LogSituation.ExitStepFailure.Log(stateMonad, this, Name, result.Error.AsString);
                }
                else
                {
                    var resultValue = SerializeOutput(result.Value);

                    LogSituation.ExitStepSuccess.Log(stateMonad, this, Name, resultValue);
                }

                return(result);
Пример #2
0
        private void LazyInitializeDerivedCollections()
        {
            _allProperties = new Lazy <IReadOnlyList <ResourceProperty> >(
                () =>

                // Add locally defined identifying properties first
                Properties.Where(p => p.IsIdentifying)

                // Add reference properties, identifying references first, followed by required, and then optional
                .Concat(
                    References
                    .OrderByDescending(
                        r => (r.Association.IsIdentifying ? 100: 0)
                        + (r.IsRequired ? 10 : 0))
                    .SelectMany(r => r.Properties))

                // Add non-identifying properties
                .Concat(Properties.Where(p => !p.IsIdentifying))
                .Distinct(ModelComparers.ResourcePropertyNameOnly)
                .ToList());

            _allPropertyByName = new Lazy <IReadOnlyDictionary <string, ResourceProperty> >(
                () =>
                AllProperties.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _propertyByName = new Lazy <IReadOnlyDictionary <string, ResourceProperty> >(
                () =>
                Properties
                .ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _embeddedObjectByName = new Lazy <IReadOnlyDictionary <string, EmbeddedObject> >(
                () =>
                EmbeddedObjects.ToDictionary(
                    x => x.PropertyName,
                    x => x,
                    StringComparer.InvariantCultureIgnoreCase));

            // Added lazy initialization of dictionary
            _extensionByName = new Lazy <IReadOnlyDictionary <string, Extension> >(
                () =>
                Extensions.ToDictionary(
                    x => x.PropertyName,
                    x => x,
                    StringComparer.InvariantCultureIgnoreCase));

            _collectionByName = new Lazy <IReadOnlyDictionary <string, Collection> >(
                () =>
                Collections.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _referenceByName = new Lazy <IReadOnlyDictionary <string, Reference> >(
                () =>
                References.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _allMembers = new Lazy <IReadOnlyList <ResourceMemberBase> >(
                () => LazyInitializeAllMembers()
                .ToList());

            _memberByName = new Lazy <IReadOnlyDictionary <string, ResourceMemberBase> >(
                () => AllMembers.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _memberNamesInvolvedInJsonCollisions = new Lazy <IReadOnlyList <string> >(
                () =>
            {
                var allProposedNames =
                    AllMembers.Select(
                        p =>
                        Tuple.Create(
                            p.PropertyName,
                            JsonNamingConvention.ProposeJsonPropertyName(p.ParentFullName.Name, p.PropertyName)))
                    .ToList();

                var proposedJsonNames = new HashSet <string>();
                var rejectedJsonNames = new HashSet <string>();

                foreach (var nameAndProposedName in allProposedNames)
                {
                    if (!proposedJsonNames.Add(nameAndProposedName.Item2))
                    {
                        rejectedJsonNames.Add(nameAndProposedName.Item2);
                    }
                }

                return(allProposedNames
                       .Where(t => rejectedJsonNames.Contains(t.Item2))
                       .Select(t => t.Item1)
                       .ToList());
            }
                );
        }