Exemplo n.º 1
0
        public static Task <TInsertAsync2Key> InsertAsync <TElement, TInsertAsync2Key>(this QueryExpressionBuilder.xSelect <TInsertAsync2Key, TElement> source, TElement value)
        {
            //Console.WriteLine("enter InsertAsync");
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestWebInsert\Application.cs

            var z = new TaskCompletionSource <TInsertAsync2Key>();

            // was it manually set?
            //QueryExpressionBuilder.WithConnectionAsync(
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                InsertAsync(source, cc, value).ContinueWith(
                    task =>
                {
                    //Console.WriteLine("after InsertAsync");

                    z.SetResult(task.Result);
                }
                    );
            }
                );
            //Console.WriteLine("exit InsertAsync");
            return(z.Task);
        }
Exemplo n.º 2
0
        // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\Experimental\QueryExpressionBuilder.IDbConnection.Count.cs
        // X:\jsc.svn\examples\javascript\Test\TestSQLiteConnection\TestSQLiteConnection\Application.cs
        // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\Experimental\QueryExpressionBuilder.IDbConnection.Insert.cs
        // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs

        // X:\jsc.svn\examples\javascript\LINQ\ClickCounter\ClickCounter\Application.cs
        public static Task <long> CountAsync <TElement>(this IQueryStrategy <TElement> source)
        {
            var z = new TaskCompletionSource <long>();

            // was it manually set?
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                CountAsync(source, cc).ContinueWithResult(z.SetResult);
            }
                );
            return(z.Task);
        }
Exemplo n.º 3
0
        // will this work for jvm yet?
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150911/mysql



        public static Task <IEnumerable <TElement> > AsEnumerableAsync <TElement>(this IQueryStrategy <TElement> source)
        {
            // X:\jsc.svn\examples\javascript\LINQ\LINQWebCamAvatars\LINQWebCamAvatars\Application.cs

            var z = new TaskCompletionSource <IEnumerable <TElement> >();

            // was it manually set?
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                AsEnumerableAsync(source, cc).ContinueWithResult(z.SetResult);
            }
                );
            return(z.Task);
        }
        public static Task <TElement> FirstOrDefaultAsync <TElement>(this IQueryStrategy <TElement> source)
        {
            // X:\jsc.svn\examples\javascript\LINQ\ClickCounter\ClickCounter\Application.cs

            var z = new TaskCompletionSource <TElement>();

            // was it manually set?
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                FirstOrDefaultAsync(source, cc).ContinueWithResult(z.SetResult);
            }
                );
            return(z.Task);
        }
Exemplo n.º 5
0
        public static async Task <IEnumerable <TElement> > AsEnumerableAsync <TElement>(this IQueryStrategy <TElement> source, IDbConnection cc)
        {
            Console.WriteLine("enter AsEnumerable");
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectMath\Program.cs

            var c = QueryExpressionBuilder.GetSelectCommand(source, cc);


            Console.WriteLine("before ExecuteReader");
            // this wont work for chrome?
            var r = await c.ExecuteReaderAsync();

            Console.WriteLine("after ExecuteReader");

            return(QueryExpressionBuilder.ReadToElements(r, source));
        }
Exemplo n.º 6
0
        public static Task <TInsertAsync3Key> InsertAsync <TElement, TInsertAsync3Key>(this QueryExpressionBuilder.xSelect <TInsertAsync3Key, TElement> source, IDbConnection cc, TElement value)
        {
            // in CLR and in browser this would work.

            var xDbCommand = QueryExpressionBuilder.GetInsertCommand(source, cc, value) as DbCommand;

            // why ExecuteNonQueryAsync is not part of CLR, now we need to link in SQLite and PHP!

            if (xDbCommand != null)
            {
                //Console.WriteLine("before ExecuteNonQueryAsync");
                var n = xDbCommand.ExecuteNonQueryAsync();
                // n = Id = 0x00000001, Status = RanToCompletion, Method = "{null}", Result = "1"

                var c = new TaskCompletionSource <TInsertAsync3Key>();

                n.ContinueWith(
                    task =>
                {
                    // jsc makes all Keys of long, yet data layer seems to talk int?
                    long LastInsertRowId = IDbConnectionExtensions.GetLastInsertRowId(cc);

                    //Console.WriteLine("InsertAsync " + new { LastInsertRowId });

                    c.SetResult(
                        (TInsertAsync3Key)(object)LastInsertRowId
                        );
                }
                    );

                return(c.Task);
            }


            // how would this work in the browser if scriptcorelib does not yet provide the implementation?
            //var xMySQLCommand = c as System.Data.MySQL.MySQLCommand;
            //if (xMySQLCommand != null)
            //{
            //    var n = xMySQLCommand.ExecuteNonQueryAsync();
            //    return n;
            //}

            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs
            // should we report back the new key?

            throw new NotSupportedException();
        }
        // to be called by the xlsx generated types inside ctor?
        public static IQueryStrategy <TElement> Create <TElement>(this IQueryStrategy <TElement> source)
        {
            // no need to call if database already has it, yet how would we know if we are stateless?

            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectMath\Program.cs


            // was it manually set?
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                Create(source, cc);     //.ContinueWith(z.SetResult);
            }
                );

            return(source);
        }
Exemplo n.º 8
0
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150911/mysql
        // ! to track down jvm issues, lets name generics with method name
        public static Task <TInsertAsync1Key[]> InsertAsync <TElement, TInsertAsync1Key>(this QueryExpressionBuilder.xSelect <TInsertAsync1Key, TElement> source, params TElement[] collection)
        {
            // tested by?


            // used by
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectAverage\Program.cs
            // x:\jsc.svn\examples\javascript\linq\test\auto\testselect\testweborderbythengroupby\application.cs
            //Console.WriteLine("enter InsertAsync");
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs

            var v = new __InsertAsync <TElement, TInsertAsync1Key>
            {
                source     = source,
                collection = collection
            };

            //v.Invoke();
            QueryExpressionBuilder.WithConnection(v.Invoke);


            return(v.z.Task);
        }
Exemplo n.º 9
0
        // X:\jsc.svn\examples\javascript\Test\TestSQLiteConnection\TestSQLiteConnection\Application.cs
        // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\Experimental\QueryExpressionBuilder.IDbConnection.Insert.cs


        public static Task <TKey[]> InsertAsync <TElement, TKey>(this QueryExpressionBuilder.xSelect <TKey, TElement> source, params TElement[] collection)
        {
            // used by
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectAverage\Program.cs
            // x:\jsc.svn\examples\javascript\linq\test\auto\testselect\testweborderbythengroupby\application.cs
            //Console.WriteLine("enter InsertAsync");
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs

            var z = new TaskCompletionSource <TKey[]>();

            // was it manually set?
            //QueryExpressionBuilder.WithConnectionAsync(
            QueryExpressionBuilder.WithConnection(
                (IDbConnection cc) =>
            {
                var i = from c in collection
                        select InsertAsync(source, cc, c);


                //Task.Factory.ContinueWhenAll(
                // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Threading\Tasks\Task\Task.WhenAll.cs
                // X:\jsc.svn\examples\java\hybrid\test\JVMCLRWhenAll\JVMCLRWhenAll\Program.cs
                Task.WhenAll(i.ToArray()).ContinueWith(
                    delegate
                {
                    //Console.WriteLine("after InsertAsync");

                    z.SetResult(
                        i.Select(x => x.Result).ToArray()
                        );
                }
                    );
            }
                );
            //Console.WriteLine("exit InsertAsync");
            return(z.Task);
        }
        //  x:\jsc.svn\core\scriptcorelib.extensions\scriptcorelib.extensions\query\experimental\queryexpressionbuilder.sum.cs

        public static Task <long> SumAsync(this IQueryStrategy <long> source)
        {
            Console.WriteLine("enter SumAsync");
            // tested by
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestWebSumLong\Application.cs


            var z = new TaskCompletionSource <long>();

            //QueryExpressionBuilder.WithConnectionAsync(
            QueryExpressionBuilder.WithConnection(
                async cc =>
            {
                Console.WriteLine("enter WithConnection SumAsync");

                var xDbCommand = QueryExpressionBuilder.GetScalarCommand(
                    source,
                    cc: cc,
                    Operand: QueryExpressionBuilder.xReferencesOfLong.SumOfLongReference.Method
                    );

                Console.WriteLine("enter WithConnection SumAsync before ExecuteScalarAsync");
                // will WithConnection actually wait or terminate?
                // never returns?
                var __value = await xDbCommand.ExecuteScalarAsync();

                Console.WriteLine("enter WithConnection SumAsync after ExecuteScalarAsync " + new { __value });

                z.SetResult(
                    (long)__value
                    );
            }
                );

            return(z.Task);
        }
        // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\Query\Experimental\QueryExpressionBuilderAsync.SumAsync.cs

        public static long Sum(this IQueryStrategy <long> source)
        {
            var value = default(long);

            // tested by
            // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSQLiteCLRSumLong\Program.cs

            QueryExpressionBuilder.WithConnection(
                cc =>
            {
                var xDbCommand = QueryExpressionBuilder.GetScalarCommand(
                    source,
                    cc: cc,
                    Operand: QueryExpressionBuilder.xReferencesOfLong.SumOfLongReference.Method
                    );

                var __value = xDbCommand.ExecuteScalar();

                value = (long)__value;
            }
                );

            return(value);
        }