Ejemplo n.º 1
0
        public async Task <Material> GetMaterialAsync(string materialCode)
        {
            List <string> whereClause = new AbapQuery().Set(QueryOperator.Equal("MATNR", materialCode))
                                        .And(QueryOperator.NotEqual("LVORM", true, RfcDataTypes.BOOLEAN_X)).GetQuery();

            using IRfcClient sapClient = _serviceProvider.GetRequiredService <IRfcClient>();
            return((await sapClient.GetTableDataAsync <Material>(whereClause)).FirstOrDefault());
        }
Ejemplo n.º 2
0
        public async Task <List <Material> > GetMaterialsByPrefixAsync(string materialCodePrefix, int recordCount = 5)
        {
            List <string> whereClause = new AbapQuery().Set(QueryOperator.StartsWith("MATNR", materialCodePrefix))
                                        .And(QueryOperator.NotEqual("LVORM", true, RfcDataTypes.BOOLEAN_X)).GetQuery();

            using IRfcClient sapClient = _serviceProvider.GetRequiredService <IRfcClient>();
            return(await sapClient.GetTableDataAsync <Material>(whereClause, rowCount : recordCount, includeUnsafeFields : true));
        }
Ejemplo n.º 3
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);
        }