Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            string[] input = new string[] { "test", "rock", "fun" };
            SubsetsGenerator <string> allSubsets = new SubsetsGenerator <string>(input);

            allSubsets.PrintSubsets(2);
        }
Ejemplo n.º 2
0
        public void Test3()
        {
            var set             = new int[] { 1, 2 };
            var expectedSubsets = new List <int[]>()
            {
                new int[0], new int[] { 1 }, new int[] { 2 }, new int[] { 1, 2 }
            };
            var actualSubsets = SubsetsGenerator.GenerateSubstes(set).ToList();

            Assert.That(actualSubsets, Is.EquivalentTo(expectedSubsets));
        }
Ejemplo n.º 3
0
        public void Test1()
        {
            var set             = new int[] {};
            var expectedSubsets = new List <int[]>()
            {
                new int[0]
            };
            var actualSubsets = SubsetsGenerator.GenerateSubstes(set).ToList();

            Assert.That(actualSubsets, Is.EqualTo(expectedSubsets));
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            string[] elements = new string[] { "hi", "a", "b" };
            SubsetsGenerator<string> generator = new SubsetsGenerator<string>(elements);
            generator.PrintSubsets(2);

            // Alternative input. Can use any type data in an IEnumerable collection due to generics
            // Uncomment to see it in action:
            // List<char> charElements = new List<char>();
            // charElements.Add('a');
            // charElements.Add('b');
            // charElements.Add('c');
            // charElements.Add('d');
            // SubsetsGenerator<char> altGen = new SubsetsGenerator<char>(charElements);
            // altGen.PrintSubsets(3);
        }
Ejemplo n.º 5
0
        public async Task Invoke(QueryContext <TService> ctx)
        {
            DbSetInfo dbSetInfo = ctx.Request.GetDbSetInfo() ?? throw new InvalidOperationException($"Could not get the DbSet for {ctx.Request.dbSetName}");
            IDataHelper <TService> dataHelper = ctx.ServiceContainer.GetDataHelper();
            IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper();
            RunTimeMetadata metadata = ctx.Service.GetMetadata();

            MethodDescription method = metadata.GetQueryMethod(ctx.Request.dbSetName, ctx.Request.queryName);

            LinkedList <object> methParams = new LinkedList <object>();

            for (int i = 0; i < method.parameters.Count; ++i)
            {
                methParams.AddLast(ctx.Request.paramInfo.GetValue(method.parameters[i].name, method, dataHelper));
            }

            RequestContext req = QueryContext <TService> .CreateRequestContext(ctx.Service, ctx.Request);

            using (RequestCallContext callContext = new RequestCallContext(req))
            {
                MethodInfoData methodData  = method.GetMethodData();
                object         instance    = serviceHelper.GetMethodOwner(methodData);
                object         invokeRes   = methodData.MethodInfo.Invoke(instance, methParams.ToArray());
                QueryResult    queryResult = (QueryResult)await serviceHelper.GetMethodResult(invokeRes);

                IEnumerable <object> entities  = queryResult.Result;
                int?              totalCount   = queryResult.TotalCount;
                RowGenerator      rowGenerator = new RowGenerator(dbSetInfo, entities, dataHelper);
                IEnumerable <Row> rows         = rowGenerator.CreateRows();

                SubsetsGenerator subsetsGenerator = new SubsetsGenerator(metadata, dataHelper);
                SubsetList       subResults       = subsetsGenerator.CreateSubsets(queryResult.subResults);

                ctx.Response.names      = dbSetInfo.GetNames();
                ctx.Response.totalCount = totalCount;
                ctx.Response.rows       = rows;
                ctx.Response.subsets    = subResults;
                ctx.Response.extraInfo  = queryResult.extraInfo;
            }

            await _next(ctx);
        }
Ejemplo n.º 6
0
        public async Task Invoke(CRUDContext <TService> ctx)
        {
            IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper();
            IDataHelper <TService> dataHelper = ctx.ServiceContainer.GetDataHelper();

            Metadata.RunTimeMetadata metadata       = ctx.Service.GetMetadata();
            ChangeSetRequest         changeSet      = ctx.Request;
            IChangeSetGraph          graph          = ctx.Properties.Get <IChangeSetGraph>(CRUDContext <TService> .CHANGE_GRAPH_KEY) ?? throw new InvalidOperationException("Could not get Graph changes from properties");
            CRUDServiceMethods       serviceMethods = ctx.Properties.Get <CRUDServiceMethods>(CRUDContext <TService> .CHANGE_METHODS_KEY) ?? throw new InvalidOperationException("Could not get CRUD Service methods from properties");

            RequestContext req = CRUDContext <TService> .CreateRequestContext(ctx.Service, changeSet);

            using (RequestCallContext callContext = new RequestCallContext(req))
            {
                await serviceMethods.ExecuteChangeSet();

                await serviceHelper.AfterExecuteChangeSet(changeSet);

                await serviceMethods.AfterChangeSetExecuted();

                foreach (RowInfo rowInfo in graph.AllList)
                {
                    if (rowInfo.changeType != ChangeType.Deleted)
                    {
                        serviceHelper.UpdateRowInfoAfterUpdates(rowInfo);
                    }
                }

                SubResultList subResults = new SubResultList();
                await serviceHelper.AfterChangeSetCommited(changeSet, subResults);

                await serviceMethods.AfterChangeSetCommited(subResults);

                SubsetsGenerator subsetsGenerator = new SubsetsGenerator(metadata, dataHelper);
                ctx.Response.subsets = subsetsGenerator.CreateSubsets(subResults);
            }


            await _next(ctx);
        }
Ejemplo n.º 7
0
 public static void Main(string[] args)
 {
     string[] input = new string[] { "test", "rock", "fun" };
     SubsetsGenerator<string> allSubsets = new SubsetsGenerator<string>(input);
     allSubsets.PrintSubsets(2);
 }