Example #1
0
File: FFT.cs Project: Jonarw/filter
        /// <summary>
        ///     Computes the FFT over real-valued input data. Only the positive half of the hermitian symmetric fourier spectrum is
        ///     returned.
        /// </summary>
        /// <param name="input">The real-valued input data.</param>
        /// <param name="n">The desired fft length. If set, the <paramref name="input" /> is zero-padded to <paramref name="n" />.</param>
        /// <returns>The positive half of the hermitian-symmetric spectrum, including DC and Nyquist/2.</returns>
        public static IReadOnlyList <Complex> RealFft(IEnumerable <double> input, int n = -1)
        {
            if (n < 0)
            {
                input = input.ToReadOnlyList();
                n     = input.Count();
            }

            if (n == 0)
            {
                return(Enumerable.Empty <Complex>().ToReadOnlyList());
            }

            return(FftProvider.RealFft(input.ToReadOnlyList(n), n));
        }
Example #2
0
        private protected ServiceElementWithAttributesInfo(IEnumerable <ServiceAttributeInfo> attributes, IReadOnlyList <ServicePart> parts)
            : base(parts)
        {
            Attributes = attributes.ToReadOnlyList();

            var obsoleteAttributes = GetAttributes("obsolete");

            if (obsoleteAttributes.Count > 1)
            {
                AddValidationError(ServiceDefinitionUtility.CreateDuplicateAttributeError(obsoleteAttributes[1]));
            }
            var obsoleteAttribute = obsoleteAttributes.Count == 0 ? null : obsoleteAttributes[0];

            if (obsoleteAttribute != null)
            {
                IsObsolete = true;

                foreach (var obsoleteParameter in obsoleteAttribute.Parameters)
                {
                    if (obsoleteParameter.Name == "message")
                    {
                        ObsoleteMessage = obsoleteParameter.Value;
                    }
                    else
                    {
                        AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(obsoleteAttribute.Name, obsoleteParameter));
                    }
                }
            }

            var tagNames      = new List <string>();
            var tagAttributes = GetAttributes("tag");

            foreach (var tagAttribute in tagAttributes)
            {
                string tagName = null;
                foreach (var tagParameter in tagAttribute.Parameters)
                {
                    if (tagParameter.Name == "name")
                    {
                        tagName = tagParameter.Value;
                    }
                    else
                    {
                        AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(tagParameter.Name, tagParameter));
                    }
                }

                if (tagName != null)
                {
                    tagNames.Add(tagName);
                }
                else
                {
                    AddValidationError(new ServiceDefinitionError("'tag' attribute is missing required 'name' parameter.", tagAttribute.Position));
                }
            }

            TagNames = tagNames;
        }
Example #3
0
        /// <summary>
        /// Creates an error set.
        /// </summary>
        public ServiceErrorSetInfo(string name, IEnumerable <ServiceErrorInfo> errors, IEnumerable <ServiceAttributeInfo>?attributes, string?summary, IEnumerable <string>?remarks, params ServicePart[] parts)
            : base(name, attributes, summary, remarks, parts)
        {
            Errors = errors.ToReadOnlyList();

            ValidateNoDuplicateNames(Errors, "error");
        }
Example #4
0
        /// <summary>
        /// Creates a service.
        /// </summary>
        public ServiceInfo(string name, IEnumerable <IServiceMemberInfo> members = null, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, IEnumerable <string> remarks = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Members    = members.ToReadOnlyList();
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Remarks    = remarks.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);

            foreach (var member in Members)
            {
                if (!(member is ServiceMethodInfo) && !(member is ServiceDtoInfo) && !(member is ServiceEnumInfo) && !(member is ServiceErrorSetInfo))
                {
                    throw new ServiceDefinitionException($"Unsupported member type '{member.GetType()}'.");
                }
            }

            ServiceDefinitionUtility.ValidateNoDuplicateNames(Members, "service member");
            m_membersByName = new ReadOnlyDictionary <string, IServiceMemberInfo>(Members.ToDictionary(x => x.Name, x => x));

            foreach (var field in Methods.SelectMany(x => x.RequestFields.Concat(x.ResponseFields)).Concat(Dtos.SelectMany(x => x.Fields)))
            {
                GetFieldType(field);
            }
        }
Example #5
0
        /// <summary>
        /// Creates an enumerated type.
        /// </summary>
        public ServiceEnumInfo(string name, IEnumerable <ServiceEnumValueInfo>?values = null, IEnumerable <ServiceAttributeInfo>?attributes = null, string?summary = null, IEnumerable <string>?remarks = null, params ServicePart[] parts)
            : base(name, attributes, summary, remarks, parts)
        {
            Values = values.ToReadOnlyList();

            ValidateNoDuplicateNames(Values, "enumerated value");
        }
Example #6
0
        /// <summary>
        ///     Applies a circular shift to the provided vector.
        /// </summary>
        /// <param name="series">The vector.</param>
        /// <param name="amount">The shift amount.</param>
        /// <returns></returns>
        public static IEnumerable <double> CircularShift(this IEnumerable <double> series, int amount)
        {
            var list = series.ToReadOnlyList();

            amount = Dsp.Mod(amount, list.Count);
            return(list.Skip(amount).Concat(list.Take(amount)));
        }
Example #7
0
		/// <summary> Creates a new set (which isn't a subset) from the specified elements. </summary>
		public Subset(IEnumerable<T> elements)
		{
			Contract.Requires(elements != null);

			this.items = elements.ToReadOnlyList();
			this.indices = null;
		}
Example #8
0
        internal void OnItemsSourceChanging(IEnumerable oldValue, IEnumerable newValue)
        {
            // wrap up enumerable, IList, IList<T>, and IReadOnlyList<T>
            var itemSourceAsList = newValue?.ToReadOnlyList();

            // allow interception of itemSource
            var onCollectionChanged = _onCollectionChanged;

            itemSourceAsList = OnItemsSourceChanging(itemSourceAsList, ref onCollectionChanged);
            if (itemSourceAsList == null)
            {
                throw new InvalidOperationException(
                          "OnItemsSourceChanging must return non-null itemSource as IReadOnlyList");
            }

            // keep callback alive
            _onCollectionChangedProxy = onCollectionChanged;

            // dispatch CollectionChangedEvent to ItemView without a strong reference to ItemView and
            // synchronize dispatch and element access via CollectionSynchronizationContext protocol
            _itemSourceProxy?.Dispose();
            _itemSourceProxy = new ItemsSourceProxy(
                itemsSource: newValue,
                itemsSourceAsList: itemSourceAsList,
                onCollectionChanged: new WeakReference <NotifyCollectionChangedEventHandler>(_onCollectionChangedProxy)
                );

            OnItemsSourceChanged(oldValue, newValue);
        }
Example #9
0
        /// <summary>
        /// Creates a service.
        /// </summary>
        public ServiceInfo(string name, IEnumerable <ServiceMemberInfo> members, IEnumerable <ServiceAttributeInfo>?attributes = null, string?summary = null, IEnumerable <string>?remarks = null, params ServicePart[] parts)
            : base(name, attributes, summary, remarks, parts)
        {
            Members = members.ToReadOnlyList();

            ValidateName();
            ValidateNoDuplicateNames(Members, "service member");

            var unsupportedMember = Members.FirstOrDefault(x => !(x is ServiceMethodInfo || x is ServiceDtoInfo || x is ServiceEnumInfo || x is ServiceErrorSetInfo));

            if (unsupportedMember != null)
            {
                throw new InvalidOperationException($"Unsupported member type: {unsupportedMember.GetType()}");
            }

            m_membersByName = Members.GroupBy(x => x.Name).ToDictionary(x => x.First().Name, x => x.First());

            m_typesByName = new Dictionary <string, ServiceTypeInfo>();
            foreach (var fieldGroup in GetDescendants().OfType <ServiceFieldInfo>().GroupBy(x => x.TypeName))
            {
                var type = ServiceTypeInfo.TryParse(fieldGroup.Key, FindMember);
                if (type != null)
                {
                    m_typesByName.Add(fieldGroup.Key, type);
                }
                else
                {
                    AddValidationErrors(fieldGroup.Select(x => new ServiceDefinitionError($"Unknown field type '{x.TypeName}'.", x.GetPart(ServicePartKind.TypeName)?.Position)));
                }
            }
        }
Example #10
0
        /// <summary>
        ///     Instantiates a new <see cref="DefaultPageProvider"/> with the specified collection of <see cref="Page"/>s.
        /// </summary>
        /// <param name="pages"> The collection of <see cref="Page"/>s. </param>
        public DefaultPageProvider(IEnumerable<Page> pages)
        {
            if (pages == null)
                throw new ArgumentNullException(nameof(pages));

            Pages = pages.ToReadOnlyList();
        }
Example #11
0
 public RdmServiceElement(string name, RdmTypeReference type, IEnumerable <Annotation> annotations, Position position)
 {
     Name        = name;
     Type        = type;
     Annotations = annotations.ToReadOnlyList();
     Position    = position;
 }
Example #12
0
 public RdmEnumType(string name, IReadOnlyList <RdmEnumMember> members, bool isFlags, IEnumerable <Annotation> annotations = null, Position position = default)
 {
     Name        = name;
     Members     = members;
     IsFlags     = isFlags;
     Annotations = annotations.ToReadOnlyList();
 }
Example #13
0
        /// <summary>
        /// Creates a DTO.
        /// </summary>
        public ServiceDtoInfo(string name, IEnumerable <ServiceFieldInfo> fields = null, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, IEnumerable <string> remarks = null, params ServicePart[] parts)
            : base(name, attributes, summary, remarks, parts)
        {
            Fields = fields.ToReadOnlyList();

            ValidateNoDuplicateNames(Fields, "field");
        }
Example #14
0
        public static IActiveValue <bool> ActiveSequenceEqual <TSource>(this IActiveList <TSource> source, IEnumerable <TSource> otherSource)
        {
            var comparer = EqualityComparer <TSource> .Default;

            return(new ActiveSequenceEqual <TSource, object>(source, otherSource.ToReadOnlyList(), (o1, o2)
                                                             => comparer.Equals(o1, o2), null));
        }
        public StageSeedConfig(IStageIdentity stage, IEnumerable <IGenerationPhase> phases)
        {
            IStageSeedConfigContracts.Constructor(stage, phases);

            this.StageIdentity    = stage;
            this.PhasesToGenerate = phases.ToReadOnlyList();
        }
Example #16
0
 public CopyFiles(IEnumerable <FilePath> SourceFiles, FolderPath TargetFolder, bool Overwrite = true, bool CreateFolder = true)
 {
     this.SourceFiles  = SourceFiles.ToReadOnlyList();
     this.TargetFolder = TargetFolder;
     this.Overwrite    = Overwrite;
     this.CreateFolder = CreateFolder;
     this.SpecName     = FormatSpecName(TargetFolder.FolderName);
 }
Example #17
0
 internal FieldContainer(ModuleSchema schema, string name, string description, ModuleAddress address, string path,
                         int size, IEnumerable <FieldBase> fields)
     : base(schema, name, description, address, path)
 {
     Fields       = fields.ToReadOnlyList(field => field.WithParent(this));
     Size         = size;
     fieldsByName = Lazy.Create(() => Fields.ToDictionary(f => f.Name).AsReadOnly());
 }
Example #18
0
        private protected ServiceMemberInfo(string name, IEnumerable <ServiceAttributeInfo>?attributes, string?summary, IEnumerable <string>?remarks, IReadOnlyList <ServicePart> parts)
            : base(attributes, parts)
        {
            Name    = name ?? throw new ArgumentNullException(nameof(name));
            Summary = summary ?? "";
            Remarks = remarks.ToReadOnlyList();

            ValidateName();
        }
Example #19
0
        public Path([NotNull] IEnumerable <Subpath> subpaths)
        {
            Subpaths = subpaths.ToReadOnlyList();

            if (Subpaths.Any(x => x == null))
            {
                throw new ArgumentException();
            }
        }
        /// <summary>
        /// Creates a service attribute.
        /// </summary>
        public ServiceAttributeInfo(string name, IEnumerable <ServiceAttributeParameterInfo>?parameters = null, params ServicePart[] parts)
            : base(parts)
        {
            Name       = name ?? throw new ArgumentNullException(nameof(name));
            Parameters = parameters.ToReadOnlyList();

            ValidateName();
            ValidateNoDuplicateNames(Parameters, "attribute parameter");
        }
Example #21
0
        /// <summary>
        /// Creates a method.
        /// </summary>
        public ServiceMethodInfo(string name, IEnumerable <ServiceFieldInfo>?requestFields = null, IEnumerable <ServiceFieldInfo>?responseFields = null, IEnumerable <ServiceAttributeInfo>?attributes = null, string?summary = null, IEnumerable <string>?remarks = null, params ServicePart[] parts)
            : base(name, attributes, summary, remarks, parts)
        {
            RequestFields  = requestFields.ToReadOnlyList();
            ResponseFields = responseFields.ToReadOnlyList();

            ValidateNoDuplicateNames(RequestFields, "request field");
            ValidateNoDuplicateNames(ResponseFields, "response field");
        }
Example #22
0
 public Polyline([NotNull] IEnumerable <Point> points)
 {
     Points      = points.ToReadOnlyList();
     BoundingBox = new Box(
         Points.Select(x => x.X).Min(),
         Points.Select(x => x.X).Max(),
         Points.Select(x => x.Y).Min(),
         Points.Select(x => x.Y).Max());
 }
Example #23
0
        /// <summary>
        ///     Calculates the standard deviation of a sequence.
        /// </summary>
        /// <param name="values">The sequence.</param>
        /// <param name="mean">The mean of the sequence.</param>
        /// <returns>The standard deviation of the sequence.</returns>
        public static double StandardDeviation(this IEnumerable <double> values, double mean)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            var valueslist = values.ToReadOnlyList();

            return(Math.Sqrt(valueslist.Variance(mean)));
        }
Example #24
0
        /// <summary>
        ///     Calculates the variance of a sequence.
        /// </summary>
        /// <param name="values">The sequence.</param>
        /// <returns>The variance of the sequence.</returns>
        public static double Variance(this IEnumerable <double> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            var valueslist = values.ToReadOnlyList();

            return(Variance(valueslist, valueslist.Average()));
        }
        public MultiPolygon3(IEnumerable <IPolygon3> components)
        {
            _components = components.ToReadOnlyList();

            _componentCount   = _components.Count();
            _totalVertexCount = _components.Select(p => p.InPlane.CountVertices()).Sum();

            _vertices = new VertexCollection(this);
            _edges    = new EdgeColllection(this);
            _faces    = new FaceCollection(this);
            _undirectedEdgeComparer = new UndirectedEdgeComparerImpl(this);
        }
Example #26
0
        public BlogSettingsHelper(IEnumerable<BlogSetting> blogSettings)
        {
            if (blogSettings == null)
            {
                throw new ArgumentNullException(nameof(blogSettings));
            }

            this.blogSettings = blogSettings.ToReadOnlyList();

            this.BlogKeys =
                this.blogSettings.Select(x => new BlogKey(x.BlogKey)).Where(x => x.HasValue).ToReadOnlyList();
        }
Example #27
0
        public IModelledFunction SelectBest(IEnumerable <IModelledFunction> modelledFunctions,
                                            IEnumerable <double> observedValues)
        {
            modelledFunctions.ThrowIfNullOrEmpty(nameof(modelledFunctions));
            observedValues.ThrowIfNullOrEmpty(nameof(observedValues));

            IReadOnlyList <double> enumeratedValues = observedValues.ToReadOnlyList();

            return(modelledFunctions
                   .Select(modelledFunction => CalculateRSquaredValue(modelledFunction, enumeratedValues))
                   .MaxBy(result => result.rSquaredValue)
                   .modelledFunction);
        }
Example #28
0
        /// <summary>
        /// Creates an attribute.
        /// </summary>
        public ServiceAttributeInfo(string name, IEnumerable <ServiceAttributeParameterInfo> parameters = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Parameters = parameters.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
            ServiceDefinitionUtility.ValidateNoDuplicateNames(Parameters, "attribute parameter");
        }
Example #29
0
        protected void SetCoefficients(IEnumerable <double> a, IEnumerable <double> b)
        {
            this.A = a.ToReadOnlyList();
            this.B = b.ToReadOnlyList();

            var n = this.A.Count;

            if (n != this.B.Count)
            {
                throw new ArgumentException();
            }

            this.Order = n - 1;
        }
Example #30
0
File: FFT.cs Project: Jonarw/filter
        /// <summary>
        ///     Computes an oversampled FFT over real-valued input data. Only the positive half of the hermitian symmetric fourier
        ///     spectrum is returned.
        /// </summary>
        /// <param name="input">The real-valued input data.</param>
        /// <param name="oversampling">The oversampling factor</param>
        /// <param name="n">The desired fft length. If set, the <paramref name="input" /> is zero-padded to <paramref name="n" />.</param>
        /// <returns>The positive half of the hermitian-symmetric spectrum, including DC and Nyquist/2.</returns>
        public static IEnumerable <Complex> RealOversampledFft(IEnumerable <double> input, int oversampling, int n = -1)
        {
            var inputlist = input.ToReadOnlyList();

            if (n < 0)
            {
                n = inputlist.Count;
            }

            n *= oversampling;
            var fft = FftProvider.RealFft(inputlist, n);

            return(fft.SparseSeries(oversampling));
        }
Example #31
0
            /// <summary>
            /// Create the bond code bit mask, lowest bit is whether the path is
            /// odd/even then the other bits are whether the bonds are in a ring or
            /// not.
            /// </summary>
            /// <param name="enumBonds">bonds to encode</param>
            /// <returns>the bond code</returns>
            static int BondCode(IEnumerable <IBond> enumBonds)
            {
                var bonds = enumBonds.ToReadOnlyList();
                var code  = bonds.Count & 0x1;

                for (int i = 0; i < bonds.Count; i++)
                {
                    if (bonds[i].IsInRing)
                    {
                        code |= 0x1 << (i + 1);
                    }
                }
                return(code);
            }
 public SqlEnumDefinitionExpression(IEnumerable<string> labels)
     : this(labels.ToReadOnlyList())
 {
 }
		public SqlCreateTableExpression(SqlTableExpression table, bool ifNotExist, IEnumerable<SqlColumnDefinitionExpression> columnExpressions, IEnumerable<Expression> tableConstraintExpressions)
			: this(table, ifNotExist, columnExpressions.ToReadOnlyList(), tableConstraintExpressions.ToReadOnlyList())
		{
		}
 public SqlFunctionCallExpression(Type type, string userDefinedFunctionName, IEnumerable<Expression> arguments)
     : this(type, SqlFunction.UserDefined, arguments.ToReadOnlyList())
 {
     this.UserDefinedFunctionName = userDefinedFunctionName;
 }
		public SqlTupleExpression(IEnumerable<Expression> subExpressions, Type type)
			: this(subExpressions.ToReadOnlyList(), type)
		{
		}
 public SqlForeignKeyConstraintExpression(string constraintName, IEnumerable<string> columnNames, SqlReferencesColumnExpression referencesColumnExpression)
     : this(constraintName, columnNames.ToReadOnlyList(), referencesColumnExpression)
 {
 }
Example #37
0
 public SqlAlterTableExpression(Expression table, IEnumerable<SqlConstraintActionExpression> actions)
     : this(table, actions.ToReadOnlyList())
 {
 }
Example #38
0
 public SqlSelectExpression ChangeColumns(IEnumerable<SqlColumnDeclaration> columns, bool columnsAlreadyOrdered)
 {
     return new SqlSelectExpression(this.Type, this.Alias, columnsAlreadyOrdered ? columns.ToReadOnlyList() : columns.OrderBy(c => c.Name).ToReadOnlyList(), this.From, this.Where, this.OrderBy, this.GroupBy, this.Distinct, this.Take, this.Skip, this.ForUpdate);
 }
        private async Task<object> CompleteValue(ExecutionContext context, GraphType fieldType, IEnumerable<Field> fields, object result, List<ExecutionError> executionErrors )
        {
            IReadOnlyList<Field> fieldsAsReadOnlyList = fields.ToReadOnlyList();

            NonNullGraphType fieldTypeAsNonNullType = fieldType as NonNullGraphType;
            if( fieldTypeAsNonNullType != null )
            {
                GraphType type = context.Schema.FindType( fieldTypeAsNonNullType.Type );
                object completed = await CompleteValue( context, type, fieldsAsReadOnlyList, result, executionErrors );
                if ( completed == null )
                {
                    Field field = fieldsAsReadOnlyList != null ? fieldsAsReadOnlyList.FirstOrDefault() : null;
                    string fieldName = field != null ? field.Name : null;
                    throw new ExecutionError("Cannot return null for non-null type. Field: {0}, Type: {1}!."
                        .ToFormat(fieldName, type.Name));
                }

                return completed;
            }

            if ( result == null )
            {
                return null;
            }

            ScalarGraphType fieldTypeAsScalarGraphType = fieldType as ScalarGraphType;
            if ( fieldTypeAsScalarGraphType != null )
            {
                object coercedValue = fieldTypeAsScalarGraphType.Coerce( result );

                return coercedValue;
            }

            ListGraphType fieldTypeAsListGraphType = fieldType as ListGraphType;
            if ( fieldTypeAsListGraphType  != null )
            {
                IEnumerable list = result as IEnumerable;
                if ( list == null )
                {
                    throw new ExecutionError("User error: expected an IEnumerable list though did not find one.");
                }

                GraphType itemType = context.Schema.FindType( fieldTypeAsListGraphType.Type );

                IEnumerable results = await list.MapAsync(async item =>
                {
                    return await CompleteValue( context, itemType, fieldsAsReadOnlyList, item, executionErrors );
                });

                return results;
            }

            ObjectGraphType fieldTypeAsObjectGraphType = fieldType as ObjectGraphType;
            InterfaceGraphType fieldTypeAsInterfaceGraphType = fieldType as InterfaceGraphType;
            if( fieldTypeAsInterfaceGraphType != null )
            {
                fieldTypeAsObjectGraphType = fieldTypeAsInterfaceGraphType.ResolveType( result );
            }

            if( fieldTypeAsObjectGraphType == null )
            {
                return null;
            }

            Dictionary<string, IEnumerable<Field>> subFields = new Dictionary<string, IEnumerable<Field>>();
            fieldsAsReadOnlyList.Apply( field =>
            {
                subFields = CollectFields( context, fieldTypeAsObjectGraphType, field.Selections, subFields );
            });

            return await ExecuteFields( context, fieldTypeAsObjectGraphType, result, subFields, executionErrors );
        }
 public SqlColumnDefinitionExpression(string columnName, Expression columnTypeName, IEnumerable<Expression> constraintExpressions)
     : this(columnName, columnTypeName, constraintExpressions.ToReadOnlyList())
 {
 }
 public SqlReferencesColumnExpression(SqlTableExpression referencedTable, SqlColumnReferenceDeferrability deferrability, IEnumerable<string> referencedColumnNames, SqlColumnReferenceAction onDelete, SqlColumnReferenceAction onUpdate)
     : this(referencedTable, deferrability, referencedColumnNames.ToReadOnlyList(), onDelete, onUpdate)
 {
 }
 public SqlCreateIndexExpression(string indexName, SqlTableExpression table, bool unique, bool lowercaseIndex, IndexType indexType, bool ifNotExist, IEnumerable<SqlIndexedColumnExpression> columns)
     : this(indexName, table, unique, lowercaseIndex, indexType, ifNotExist, columns.ToReadOnlyList())
 {
 }
Example #43
0
 public SqlQueryFormatResult(string commandText, IEnumerable<Tuple<Type, object>> parameterValues)
     : this(commandText, parameterValues.ToReadOnlyList())
 {
 }
Example #44
0
 public SqlSelectExpression(Type type, string alias, IEnumerable<SqlColumnDeclaration> columns, Expression from, Expression where, IEnumerable<Expression> orderBy, bool forUpdate)
     : this(type, alias, columns.ToReadOnlyList(), from, where, orderBy.ToReadOnlyList(), null, false, null, null, forUpdate)
 {
 }
 public SqlStatementListExpression(IEnumerable<Expression> statements)
     : this(statements.ToReadOnlyList())
 {
 }
Example #46
0
 public SqlSelectExpression(Type type, string alias, IEnumerable<SqlColumnDeclaration> columns, Expression from, Expression where, IEnumerable<Expression> orderBy, IEnumerable<Expression> groupBy, bool distinct, Expression skip, Expression take, bool forUpdate)
     : this(type, alias, columns.ToReadOnlyList(), from, where, orderBy.ToReadOnlyList(), groupBy.ToReadOnlyList(), distinct, skip, take, forUpdate)
 {
 }
Example #47
0
		/// <summary> Calls the code to be tested, namely creating the AST. </summary>
		/// <param name="testExpressions"> The test expressions to be parsed into an AST. </param>
		/// <param name="cachingMethod"> The caching method to use in parsing. </param>
		/// <returns> null if no AST was found for the test case, and the (first) AST otherwise. </returns>
		internal static ASTBaseNode GetAST(IEnumerable<IExpression<TestDomain>> testExpressions, SortedReadOnlyList<ICompositeNotationForm<TestDomain>> enabledNotations)
		{
			var builder = new TestASTBuilder(enabledNotations);
			var trees = builder.GetAbstractSyntaxTrees(testExpressions.ToReadOnlyList()).ToList();
			Contract.Assert(trees.All(tree => tree == null || !IsImpossible(tree)), "An AST succeeded with the Impossible domain");
			return trees.FirstOrDefault(ast => ast != null);
		}
Example #48
0
 public BindResult(IEnumerable<SqlColumnDeclaration> columns, IEnumerable<SqlOrderByExpression> orderings)
 {
     this.Columns = columns.ToReadOnlyList();
     this.Orderings = orderings.ToReadOnlyList();
 }
        private bool ShouldIncludeNode( ExecutionContext context, IEnumerable<Directive> directives )
        {
            IReadOnlyList<Directive> directivesAsReadOnlyList = directives.ToReadOnlyList();

            if( directivesAsReadOnlyList != null )
            {
                Directive directive = directivesAsReadOnlyList.Find( DirectiveGraphType.Skip.Name );
                if (directive != null)
                {
                    IReadOnlyDictionary<string, object> values = GetArgumentValues(
                        context.Schema,
                        DirectiveGraphType.Skip.Arguments,
                        directive.Arguments,
                        context.Variables);
                    return !((bool) values["if"]);
                }

                directive = directivesAsReadOnlyList.Find( DirectiveGraphType.Include.Name );
                if (directive != null)
                {
                    IReadOnlyDictionary<string, object> values = GetArgumentValues(
                        context.Schema,
                        DirectiveGraphType.Include.Arguments,
                        directive.Arguments,
                        context.Variables);
                    return (bool) values["if"];
                }
            }

            return true;
        }
Example #50
0
 public SqlInsertIntoExpression(SqlTableExpression table, IEnumerable<string> columnNames, IEnumerable<string> returningAutoIncrementColumnNames, IEnumerable<Expression> valueExpressions)
     : this(table, columnNames.ToReadOnlyList(), returningAutoIncrementColumnNames.ToReadOnlyList(), valueExpressions.ToReadOnlyList())
 {
 }
        private async Task<object> ResolveField( ExecutionContext context, ObjectGraphType parentType, object source, IEnumerable<Field> fields, List<ExecutionError> executionErrors )
        {
            context.CancellationToken.ThrowIfCancellationRequested();

            IReadOnlyList<Field> fieldsAsReadOnlyList = fields.ToReadOnlyList();

            Field field = fieldsAsReadOnlyList.First();

            FieldType fieldDefinition = GetFieldDefinition(context.Schema, parentType, field);
            if (fieldDefinition == null)
            {
                return null;
            }

            IReadOnlyDictionary<string, object> arguments = GetArgumentValues(context.Schema, fieldDefinition.Arguments, field.Arguments, context.Variables);

            Func<ResolveFieldContext, object> defaultResolve =
                ctx =>
                {
                    return ctx.Source != null ? GetProperyValue(ctx.Source, ctx.FieldAst.Name) : null;
                };

            try
            {
                ResolveFieldContext resolveContext = new ResolveFieldContext(
                    field.Name,
                    field,
                    fieldDefinition,
                    context.Schema.FindType( fieldDefinition.Type ),
                    parentType,
                    arguments,
                    context.RootValue,
                    source,
                    context.Schema,
                    context.Operation,
                    context.Fragments,
                    context.Variables,
                    context.CancellationToken,
                    context.UserContext );

                Func<ResolveFieldContext, object> resolve = fieldDefinition.Resolve ?? defaultResolve;
                object result = resolve( resolveContext );

                Task resultAsTask = result as Task;
                if( resultAsTask != null )
                {
                    await resultAsTask;
                    result = GetProperyValue( resultAsTask, "Result" );
                }

                if ( fieldDefinition.IsPluralIdentifyingRootField )
                {
                    ThrowIfPluralIdentifyingRootFieldRequirementsNotMet(
                        result,
                        resolveContext );
                }
                
                __Field parentTypeAsField = parentType as __Field;
                Type resultAsType = result as Type;
                if ( parentTypeAsField != null &&
                     resultAsType != null )
                {
                    result = context.Schema.FindType( resultAsType );
                }

                return await CompleteValue(
                    context,
                    context.Schema.FindType( fieldDefinition.Type ),
                    fieldsAsReadOnlyList,
                    result,
                    executionErrors );
            }
            catch( Exception exception )
            {
                executionErrors.Add(
                    new ExecutionError( string.Format( "Error trying to resolve {0}.", field.Name ), exception ) );

                return null;
            }
        }
 public SqlFunctionCallExpression(Type type, SqlFunction function, IEnumerable<Expression> arguments)
     : this(type, function, arguments.ToReadOnlyList())
 {
 }