/// <summary>
        /// Initializes a new instance of the <see cref="PrimaryKeyFunctionField"/> class.
        /// </summary>
        /// <param name="uniqueKeyElement">The table element.</param>
        public PrimaryKeyFunctionField(UniqueElement uniqueKeyElement)
        {
            // Initialize the object.
            this.Name             = "primaryKeyFunction";
            this.uniqueKeyElement = uniqueKeyElement;

            //        /// <summary>
            //        /// Used to get the primary key from the record.
            //        /// </summary>
            //        private Func<Buyer, object> primaryKeyFunction = ((Expression<Func<Buyer, object>>)(b => b.BuyerId)).Compile();
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(
                    SyntaxFactory.GenericName(
                        SyntaxFactory.Identifier("Func"))
                    .WithTypeArgumentList(
                        SyntaxFactory.TypeArgumentList(
                            SyntaxFactory.SeparatedList <TypeSyntax>(
                                new SyntaxNodeOrToken[]
            {
                SyntaxFactory.IdentifierName(this.uniqueKeyElement.Table.Name),
                SyntaxFactory.Token(SyntaxKind.CommaToken),
                SyntaxFactory.PredefinedType(
                    SyntaxFactory.Token(SyntaxKind.ObjectKeyword)),
            }))))
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier("primaryKeyFunction"))
                        .WithInitializer(this.Initializer))))
                          .WithModifiers(PrimaryKeyFunctionField.Modifiers)
                          .WithLeadingTrivia(PrimaryKeyFunctionField.DocumentationComment);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetMethod"/> class.
        /// </summary>
        /// <param name="uniqueKeyElement">The unique constraint schema.</param>
        public GetMethod(UniqueElement uniqueKeyElement)
        {
            // Initialize the object.  Note that we decorate the name of every method that's not the primary key to prevent ambiguous signatures.
            this.uniqueKeyElement = uniqueKeyElement;
            this.Name             = $"Get{this.uniqueKeyElement.Table.Name}";

            //        /// <summary>
            //        /// Gets a specific <see cref="Province"/> record.
            //        /// </summary>
            //        /// <param name="provinceId">The primary key identifier.</param>
            //        /// <returns>The result of the GET verb.</returns>
            //        [HttpGet("{provinceId}")]
            //        public async Task<IActionResult> GetProvince([FromRoute] int provinceId)
            //        {
            //            <Body>
            //        }
            this.Syntax = SyntaxFactory.MethodDeclaration(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("Task"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                            SyntaxFactory.IdentifierName("IActionResult")))),
                SyntaxFactory.Identifier(this.Name))
                          .WithAttributeLists(this.Attributes)
                          .WithModifiers(GetMethod.Modifiers)
                          .WithParameterList(this.Parameters)
                          .WithBody(this.Body)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the syntax for the creation of an anonymous type.
        /// </summary>
        /// <param name="uniqueKeyElement">The description of a unique key.</param>
        /// <param name="variableName">The name of the variable holding the keys.</param>
        /// <returns>An expression that builds an anonymous type from a table description.</returns>
        public static SeparatedSyntaxList <ArgumentSyntax> GetMemberSyntax(UniqueElement uniqueKeyElement, string variableName)
        {
            SeparatedSyntaxList <ArgumentSyntax> findParameters;

            if (uniqueKeyElement.Columns.Count == 1)
            {
                //                    country = this.dataModel.Countries.CountryCountryCodeKey.Find(countryCountryCodeKeyCountryCode);
                ColumnElement columnElement = uniqueKeyElement.Columns[0].Column;
                string        propertyName  = columnElement.Name;
                findParameters = SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                    SyntaxFactory.Argument(
                        SyntaxFactory.MemberAccessExpression(
                            SyntaxKind.SimpleMemberAccessExpression,
                            SyntaxFactory.IdentifierName(variableName),
                            SyntaxFactory.IdentifierName(propertyName))));
            }
            else
            {
                //                    region = this.dataModel.Regions.RegionExternalKey.Find((regionExternalKeyName, regionExternalKeyCountryCode));
                List <SyntaxNodeOrToken> keys = new List <SyntaxNodeOrToken>();
                foreach (ColumnReferenceElement columnReferenceElement in uniqueKeyElement.Columns)
                {
                    if (keys.Count != 0)
                    {
                        keys.Add(SyntaxFactory.Token(SyntaxKind.CommaToken));
                    }

                    ColumnElement columnElement = columnReferenceElement.Column;
                    string        attributeName = columnElement.Name.ToVariableName();
                    keys.Add(
                        SyntaxFactory.Argument(
                            SyntaxFactory.MemberAccessExpression(
                                SyntaxKind.SimpleMemberAccessExpression,
                                SyntaxFactory.IdentifierName(variableName),
                                SyntaxFactory.IdentifierName(attributeName))));
                }

                findParameters = SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                    SyntaxFactory.Argument(
                        SyntaxFactory.TupleExpression(
                            SyntaxFactory.SeparatedList <ArgumentSyntax>(keys))));
            }

            // This is either the parameter or a tuple that can be used as parameters to a 'Find' operation.
            return(findParameters);
        }
Esempio n. 4
0
        /// <summary>
        /// Constructs an initializer for a unique index.
        /// </summary>
        /// <param name="uniqueElement">The unique index description.</param>
        /// <returns>Code to initialize a unique index.</returns>
        private static ExpressionSyntax GetUniqueInitializer(UniqueElement uniqueElement)
        {
            //        new ForeignIndex<Account,Item>("AccountSymbolKey")
            ExpressionSyntax expressionSyntax = SyntaxFactory.ObjectCreationExpression(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("UniqueIndex"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                            SyntaxFactory.IdentifierName(uniqueElement.Table.Name)))))
                                                .WithArgumentList(
                SyntaxFactory.ArgumentList(
                    SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                        SyntaxFactory.Argument(
                            SyntaxFactory.LiteralExpression(
                                SyntaxKind.StringLiteralExpression,
                                SyntaxFactory.Literal(uniqueElement.Name))))));

            // .HasIndex(a => a.ItemId)
            expressionSyntax = SyntaxFactory.InvocationExpression(
                SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    expressionSyntax,
                    SyntaxFactory.IdentifierName("HasIndex")))
                               .WithArgumentList(
                SyntaxFactory.ArgumentList(
                    SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                        SyntaxFactory.Argument(UniqueKeyExpression.GetUniqueKey(uniqueElement)))));

            //  .HasFilter(a => a.Symbol != null)
            if (uniqueElement.IsNullable)
            {
                expressionSyntax = SyntaxFactory.InvocationExpression(
                    SyntaxFactory.MemberAccessExpression(
                        SyntaxKind.SimpleMemberAccessExpression,
                        expressionSyntax,
                        SyntaxFactory.IdentifierName("HasFilter")))
                                   .WithArgumentList(
                    SyntaxFactory.ArgumentList(
                        SyntaxFactory.SingletonSeparatedList <ArgumentSyntax>(
                            SyntaxFactory.Argument(NullableKeyFilterExpression.GetNullableKeyFilter(uniqueElement)))));
            }

            return(expressionSyntax);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DictionaryField"/> class.
        /// </summary>
        /// <param name="uniqueKeyElement">The table schema.</param>
        public DictionaryField(UniqueElement uniqueKeyElement)
        {
            // Initialize the object.
            this.uniqueKeyElement = uniqueKeyElement;

            // This is the name of the field.
            this.Name = "dictionary";

            //        /// <summary>
            //        /// The dictionary containing the index.
            //        /// </summary>
            //        private Dictionary<Guid, ProvinceRow> dictionary = new Dictionary<Guid, ProvinceRow>();
            this.Syntax = SyntaxFactory.FieldDeclaration(
                SyntaxFactory.VariableDeclaration(this.Type)
                .WithVariables(
                    SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                        SyntaxFactory.VariableDeclarator(
                            SyntaxFactory.Identifier(this.Name))
                        .WithInitializer(this.Initializer))))
                          .WithModifiers(DictionaryField.Modifiers)
                          .WithLeadingTrivia(DictionaryField.DocumentationComment);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericUniqueIndexProperty"/> class.
        /// </summary>
        /// <param name="uniqueKeyElement">The unique key element.</param>
        public GenericUniqueIndexProperty(UniqueElement uniqueKeyElement)
        {
            // Initialize the object.
            this.uniqueKeyElement = uniqueKeyElement;
            this.Name             = this.uniqueKeyElement.Name;

            //        /// <summary>
            //        /// Gets the BuyerExternalId0Key unique index.
            //        /// </summary>
            //        public UniqueIndex<Buyer> BuyerExternalId0Key { get; } = new UniqueIndex<Buyer>("BuyerExternalId0Key").HasIndex(b => b.ExternalId0);
            this.Syntax = SyntaxFactory.PropertyDeclaration(
                SyntaxFactory.GenericName(
                    SyntaxFactory.Identifier("UniqueIndex"))
                .WithTypeArgumentList(
                    SyntaxFactory.TypeArgumentList(
                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                            SyntaxFactory.IdentifierName(this.uniqueKeyElement.Table.Name)))),
                SyntaxFactory.Identifier(this.Name))
                          .WithModifiers(GenericUniqueIndexProperty.Modifiers)
                          .WithAccessorList(GenericUniqueIndexProperty.AccessorList)
                          .WithLeadingTrivia(this.DocumentationComment);
        }
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Shows the appropriate context menu, depending on the supplied Visual Context, for the specified pointed object.
        /// Returns the generated context menu.
        /// </summary>
        public ContextMenu ShowContextMenu(FrameworkElement VisualContext, UniqueElement PointedObject, UniqueElement DefaultPointedObject = null, Action CloseAction = null)
        {
            ContextMenu Result = null;

            if (PointedObject == null)
            {
                PointedObject = DefaultPointedObject;
            }

            if (PointedObject is Idea)
            {
                PointedObject = ((Idea)PointedObject).MainSymbol;
            }

            if (PointedObject is View)
            {
                Result = CurrentView.Presenter.DisplayContextMenu <View>((View)PointedObject, ContextMenuOptionsForViews, CloseAction);
            }
            else
            if (PointedObject is VisualSymbol)
            {
                Result = CurrentView.Presenter.DisplayContextMenu <VisualSymbol>((VisualSymbol)PointedObject, ContextMenuOptionsForVisualSymbols, CloseAction);
            }
            else
            if (PointedObject is VisualConnector)
            {
                Result = CurrentView.Presenter.DisplayContextMenu <VisualConnector>((VisualConnector)PointedObject, ContextMenuOptionsForVisualConnectors, CloseAction);
            }
            else
            if (PointedObject is VisualComplement)
            {
                Result = CurrentView.Presenter.DisplayContextMenu <VisualComplement>((VisualComplement)PointedObject, ContextMenuOptionsForVisualComplements, CloseAction);
            }

            return(Result);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates an argument that creates a lambda expression for extracting the key from a class.
        /// </summary>
        /// <param name="uniqueKeyElement">The unique key element.</param>
        /// <param name="isAnonymous">Indicates we should create an anonymous key for Entity Framework.</param>
        /// <returns>An argument that extracts a key from an object.</returns>
        public static ExpressionSyntax GetUniqueKey(UniqueElement uniqueKeyElement, bool isAnonymous = false)
        {
            // Validate the parameter
            if (uniqueKeyElement == null)
            {
                throw new ArgumentNullException(nameof(uniqueKeyElement));
            }

            // Used as a variable when constructing the lambda expression.
            string abbreviation = uniqueKeyElement.Table.Name[0].ToString(CultureInfo.InvariantCulture).ToLowerInvariant();

            // This will create an expression for extracting the key from record.
            CSharpSyntaxNode syntaxNode = null;

            if (uniqueKeyElement.Columns.Count == 1)
            {
                // A simple key can be used like a value type.
                syntaxNode = SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    SyntaxFactory.IdentifierName(abbreviation),
                    SyntaxFactory.IdentifierName(uniqueKeyElement.Columns[0].Column.Name));
            }
            else
            {
                // A Compound key must be constructed from an anomymous type.
                List <SyntaxNodeOrToken> keyElements = new List <SyntaxNodeOrToken>();
                foreach (ColumnReferenceElement columnReferenceElement in uniqueKeyElement.Columns)
                {
                    if (keyElements.Count != 0)
                    {
                        keyElements.Add(SyntaxFactory.Token(SyntaxKind.CommaToken));
                    }

                    if (isAnonymous)
                    {
                        keyElements.Add(
                            SyntaxFactory.AnonymousObjectMemberDeclarator(
                                SyntaxFactory.MemberAccessExpression(
                                    SyntaxKind.SimpleMemberAccessExpression,
                                    SyntaxFactory.IdentifierName(abbreviation),
                                    SyntaxFactory.IdentifierName(columnReferenceElement.Column.Name))));
                    }
                    else
                    {
                        keyElements.Add(
                            SyntaxFactory.Argument(
                                SyntaxFactory.MemberAccessExpression(
                                    SyntaxKind.SimpleMemberAccessExpression,
                                    SyntaxFactory.IdentifierName(abbreviation),
                                    SyntaxFactory.IdentifierName(columnReferenceElement.Column.Name))));
                    }
                }

                if (isAnonymous)
                {
                    // b => b.BuyerId or b => new { b.BuyerId, b.ExternalId0 }
                    syntaxNode = SyntaxFactory.AnonymousObjectCreationExpression(
                        SyntaxFactory.SeparatedList <AnonymousObjectMemberDeclaratorSyntax>(keyElements.ToArray()));
                }
                else
                {
                    // b => b.BuyerId or p => ValueTuple.Create(p.Name, p.CountryCode)
                    syntaxNode = SyntaxFactory.InvocationExpression(
                        SyntaxFactory.MemberAccessExpression(
                            SyntaxKind.SimpleMemberAccessExpression,
                            SyntaxFactory.IdentifierName("ValueTuple"),
                            SyntaxFactory.IdentifierName("Create")))
                                 .WithArgumentList(
                        SyntaxFactory.ArgumentList(
                            SyntaxFactory.SeparatedList <ArgumentSyntax>(keyElements.ToArray())));
                }
            }

            //            this.BuyerKey = new UniqueIndex<Buyer>("BuyerKey").HasIndex(b => b.BuyerId);
            return(SyntaxFactory.SimpleLambdaExpression(SyntaxFactory.Parameter(SyntaxFactory.Identifier(abbreviation)), syntaxNode));
        }
Esempio n. 9
0
        public static string Process(string input1, string input2, string input3)
        {
            string output = string.Empty;

            switch (input3)
            {
            case "add":
                output = Addition.Add(input1, input2).ToString();
                break;

            case "subtraction":
                output = Subtraction.Sub(input1, input2).ToString();
                break;

            case "multiplication":
                output = Multiplication.Mul(input1, input2).ToString();
                break;

            case "division":
                output = Division.Div(input1, input2).ToString();
                break;

            case "divby3notby6":
                output = Divisionbythreenotbysix.Run(input1).ToString();
                break;

            case "armstrongornot":
                output = Armstrongnumber.Check(input1).ToString();
                break;

            case "factorial":
                output = Factorial.Calculate(input1).ToString();
                break;

            case "palindrome":
                output = PalindromeNumber.Find(input1).ToString();
                break;

            case "reverse":
                output = ReverseNumber.Reverse(input1).ToString();
                break;

            case "sumofdigits":
                output = Sumofdigits.Find(input1).ToString();
                break;

            case "decimaltobinary":
                output = DecimaltoBinary.Converts(input1).ToString();
                break;

            case "numberincharacter":
                output = NumbersInCharacters.Print(input1).ToString();
                break;

            case "strreverse":
                output = StringReverse.Reverse(input1).ToString();
                break;

            case "duplicate":
                output = DuplicateElement.Find(input1).ToString();
                break;

            case "unique":
                output = UniqueElement.Return(input1).ToString();
                break;

            case "strpalindrome":
                output = StringPalindrome.Find(input1).ToString();
                break;

            case "length":
                output = StringLength.Calculate(input1).ToString();
                break;

            case "vowels":
                output = NumofVowels.Print(input1).ToString();
                break;

            case "search":
                output = CharacterSearching.Search(input1, input2).ToString();
                break;

            case "count":
                output = WordCount.Count(input1).ToString();
                break;

            case "date":
                output = DateandTime.Calculate(input1).ToString();
                break;
            }
            return(output);
        }