Exemplo n.º 1
0
        private List <MaterialCategoryDefinition> SetMaterialCategoryOption(MaterialQueryOptions queryOptions, List <Material> materialList)
        {
            var materialCategoryDefinitionList = new List <MaterialCategoryDefinition>();

            if (queryOptions.IncludeMaterialCategory)
            {
                var materialCategoryList =
                    materialList.Where(x => x.MaterialCategoryCode != null)
                    .Select(x => (object)x.MaterialCategoryCode)
                    .Distinct()
                    .ToList();

                List <object>[] materialCategoryParts = materialCategoryList.Partition(PartitionCount);

                foreach (List <object> part in materialCategoryParts)
                {
                    List <string> queryList = new AbapQuery()
                                              .Set(QueryOperator.In("ZZEXTWG", part))
                                              .GetQuery();

                    using var connection = _serviceProvider.GetService <IRfcConnection>();
                    connection.Connect();
                    using var tableFunction = _serviceProvider.GetService <IReadTable <MaterialCategoryDefinition> >();
                    var definitions = tableFunction.GetTable(connection, queryList);
                    if (definitions.Any())
                    {
                        materialCategoryDefinitionList.AddRange(definitions);
                    }
                }
            }

            return(materialCategoryDefinitionList);
        }
Exemplo n.º 2
0
        private List <Task> SetMaterialDefinitionOptionAsync(MaterialQueryOptions queryOptions, List <Material> materialList,
                                                             ConcurrentQueue <MaterialDefinition> definitionList)
        {
            var taskList = new List <Task>();

            if (queryOptions.IncludeDefinition)
            {
                var             list  = materialList.Where(x => x.Code != null).Select(x => (object)x.Code).ToList();
                List <object>[] parts = list.Partition(PartitionCount);

                foreach (List <object> part in parts)
                {
                    List <string> query = new AbapQuery()
                                          .Set(QueryOperator.In("MATNR", part))
                                          .GetQuery();

                    taskList.Add(Task.Run(() =>
                    {
                        using var connection = _serviceProvider.GetService <IRfcConnection>();
                        connection.Connect();
                        using var tableFunction = _serviceProvider.GetService <IReadTable <MaterialDefinition> >();
                        var definitions         = tableFunction.GetTable(connection, query);
                        foreach (MaterialDefinition definition in definitions)
                        {
                            definitionList.Enqueue(definition);
                        }
                    }));
                }
            }

            return(taskList);
        }
Exemplo n.º 3
0
        private List <MaterialDefinition> SetMaterialDefinitionOption(MaterialQueryOptions queryOptions, List <Material> materialList)
        {
            var definitionList = new List <MaterialDefinition>();

            if (queryOptions.IncludeDefinition)
            {
                var             list  = materialList.Where(x => x.Code != null).Select(x => (object)x.Code).ToList();
                List <object>[] parts = list.Partition(PartitionCount);

                foreach (List <object> part in parts)
                {
                    List <string> query = new AbapQuery()
                                          .Set(QueryOperator.In("MATNR", part))
                                          .GetQuery();


                    using IRfcConnection connection = _serviceProvider.GetService <IRfcConnection>();
                    connection.Connect();
                    using IReadTable <MaterialDefinition> tableFunction = _serviceProvider.GetService <IReadTable <MaterialDefinition> >();
                    List <MaterialDefinition> definitions = tableFunction.GetTable(connection, query);
                    if (definitions.Any())
                    {
                        definitionList.AddRange(definitions);
                    }
                }
            }

            return(definitionList);
        }
Exemplo n.º 4
0
        private List <Task> SetMaterialCategoryOptionAsync(MaterialQueryOptions queryOptions, List <Material> materialList,
                                                           ConcurrentQueue <MaterialCategoryDefinition> materialCategoryDefinitionList, SemaphoreSlim semaphoreSlim = null)
        {
            var taskList = new List <Task>();

            if (!queryOptions.IncludeMaterialCategory)
            {
                return(taskList);
            }

            var materialCategoryList =
                materialList.Where(x => x.MaterialCategoryCode != null)
                .Select(x => (object)x.MaterialCategoryCode)
                .Distinct()
                .ToList();

            List <object>[] materialCategoryParts = materialCategoryList.Partition(PartitionCount);

            foreach (List <object> part in materialCategoryParts)
            {
                List <string> queryList = new AbapQuery()
                                          .Set(QueryOperator.In("ZZEXTWG", part))
                                          .GetQuery();

                taskList.Add(Task.Run(async() =>
                {
                    try
                    {
                        if (semaphoreSlim != null)
                        {
                            await semaphoreSlim.WaitAsync();
                        }
                        using IRfcClient client = _serviceProvider.GetRequiredService <IRfcClient>();
                        List <MaterialCategoryDefinition> definitions = await client.GetTableDataAsync <MaterialCategoryDefinition>(queryList, includeUnsafeFields: true);
                        foreach (MaterialCategoryDefinition definition in definitions)
                        {
                            materialCategoryDefinitionList.Enqueue(definition);
                        }
                    }
                    finally
                    {
                        if (semaphoreSlim != null)
                        {
                            semaphoreSlim.Release();
                        }
                    }
                }));
            }

            return(taskList);
        }