// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <SubItems> lst = null;

            using (var ctx = new SubItemsRepository())
            {
                lst = await ctx.GetSubItemsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <SubItemsExcelLine, List <SubItemsExcelLine> >
            {
                dataToPrint = lst.Select(x => new SubItemsExcelLine
                {
                    ItemNumber = x.ItemNumber,


                    ItemDescription = x.ItemDescription,


                    Quantity = x.Quantity,


                    QtyAllocated = x.QtyAllocated
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <xcuda_Supplementary_unit> lst = null;

            using (var ctx = new xcuda_Supplementary_unitRepository())
            {
                lst = await ctx.Getxcuda_Supplementary_unitByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <xcuda_Supplementary_unitExcelLine, List <xcuda_Supplementary_unitExcelLine> >
            {
                dataToPrint = lst.Select(x => new xcuda_Supplementary_unitExcelLine
                {
                    Suppplementary_unit_quantity = x.Suppplementary_unit_quantity,


                    Suppplementary_unit_code = x.Suppplementary_unit_code,


                    Suppplementary_unit_name = x.Suppplementary_unit_name,


                    IsFirstRow = x.IsFirstRow
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#3
0
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <EmptyFullCode> lst = null;

            using (var ctx = new EmptyFullCodeRepository())
            {
                lst = await ctx.GetEmptyFullCodesByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <EmptyFullCodeExcelLine, List <EmptyFullCodeExcelLine> >
            {
                dataToPrint = lst.Select(x => new EmptyFullCodeExcelLine
                {
                    EmptyFullCodeName = x.EmptyFullCodeName,


                    EmptyFullDescription = x.EmptyFullDescription
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <Customs_Procedure> lst = null;

            using (var ctx = new Customs_ProcedureRepository())
            {
                lst = await ctx.GetCustoms_ProcedureByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <Customs_ProcedureExcelLine, List <Customs_ProcedureExcelLine> >
            {
                dataToPrint = lst.Select(x => new Customs_ProcedureExcelLine
                {
                    Extended_customs_procedure = x.Extended_customs_procedure,


                    National_customs_procedure = x.National_customs_procedure,


                    IsDefault = x.IsDefault
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#5
0
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <TariffSupUnitLkps> lst = null;

            using (var ctx = new TariffSupUnitLkpsRepository())
            {
                lst = await ctx.GetTariffSupUnitLkpsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <TariffSupUnitLkpsExcelLine, List <TariffSupUnitLkpsExcelLine> >
            {
                dataToPrint = lst.Select(x => new TariffSupUnitLkpsExcelLine
                {
                    // TariffCategoryCode = x.TariffCategoryCode ,


                    SuppUnitCode2 = x.SuppUnitCode2,


                    SuppUnitName2 = x.SuppUnitName2,


                    SuppQty = x.SuppQty
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#6
0
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <OverShortSuggestedDocument> lst = null;

            using (var ctx = new OverShortSuggestedDocumentRepository())
            {
                lst = await ctx.GetOverShortSuggestedDocumentsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <OverShortSuggestedDocumentExcelLine, List <OverShortSuggestedDocumentExcelLine> >
            {
                dataToPrint = lst.Select(x => new OverShortSuggestedDocumentExcelLine
                {
                    CNumber = x.CNumber,


                    ReferenceNumber = x.ReferenceNumber
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#7
0
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <Document_Type> lst = null;

            using (var ctx = new Document_TypeRepository())
            {
                lst = await ctx.GetDocument_TypeByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <Document_TypeExcelLine, List <Document_TypeExcelLine> >
            {
                dataToPrint = lst.Select(x => new Document_TypeExcelLine
                {
                    Type_of_declaration = x.Type_of_declaration,


                    Declaration_gen_procedure_code = x.Declaration_gen_procedure_code
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <CounterPointPOs> lst = null;

            using (var ctx = new CounterPointPOsRepository())
            {
                lst = await ctx.GetCounterPointPOsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <CounterPointPOsExcelLine, List <CounterPointPOsExcelLine> >
            {
                dataToPrint = lst.Select(x => new CounterPointPOsExcelLine
                {
                    PurchaseOrderNo = x.PurchaseOrderNo,


                    Date = x.Date,


                    LineNumber = x.LineNumber,


                    Downloaded = x.Downloaded
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
        internal async Task Send2Excel(string path, DataGrid GridData)
        {
            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(() =>
                {
                    var s = new ExportToExcel <SaleReportLine, List <SaleReportLine> >();
                    s.StartUp();

                    try
                    {
                        var data = GridData.ItemsSource.OfType <SaleReportLine>();
                        if (data != null)
                        {
                            s.dataToPrint = data.ToList();
                            s.SaveReport(path);
                        }

                        StatusModel.StatusUpdate();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    s.ShutDown();
                },
                                            CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <CounterPointSalesDetails> lst = null;

            using (var ctx = new CounterPointSalesDetailsRepository())
            {
                lst = await ctx.GetCounterPointSalesDetailsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <CounterPointSalesDetailsExcelLine, List <CounterPointSalesDetailsExcelLine> >
            {
                dataToPrint = lst.Select(x => new CounterPointSalesDetailsExcelLine
                {
                    INVNO = x.INVNO,


                    SEQ_NO = x.SEQ_NO,


                    ITEM_NO = x.ITEM_NO,


                    ITEM_DESCR = x.ITEM_DESCR,


                    QUANTITY = x.QUANTITY,


                    COST = x.COST,


                    ACCT_NO = x.ACCT_NO,


                    CUSTOMER_NAME = x.CUSTOMER_NAME,


                    DATE = x.DATE,


                    TAX_AMT = x.TAX_AMT,


                    UNIT_WEIGHT = x.UNIT_WEIGHT,


                    QTY_UNIT = x.QTY_UNIT
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#11
0
 public TaskWrapper(StaTaskScheduler staScheduler, Color background)
 {
     // Create the task (it just runs forever until dispose is called)
     _task = Task.Factory.StartNew(() =>
     {
         Run(this, _cancel.Token, background);
     }, _cancel.Token, TaskCreationOptions.LongRunning, staScheduler);
 }
示例#12
0
 public RoundRobinManager(StaTaskScheduler staScheduler)
 {
     // Create the task (it just runs forever until dispose is called)
     _task = Task.Factory.StartNew(() =>
     {
         Run(_addRemoveQueue, _waitHandle, _cancel.Token);
     }, _cancel.Token, TaskCreationOptions.LongRunning, staScheduler);
 }
示例#13
0
        private static Grpc.Core.Server StartServer([NotNull] MicroserverArguments arguments,
                                                    out IServiceHealth health)
        {
            // TODO: Move to ProSuite
            var healthService = new HealthServiceImpl();

            health = null;             // new ServiceHealth(healthService);

            int maxThreadCount = arguments.MaxParallel;

            if (maxThreadCount <= 0)
            {
                maxThreadCount = Environment.ProcessorCount - 1;
            }

            var taskScheduler = new StaTaskScheduler(maxThreadCount);

            var removeOverlapsServiceImpl = new RemoveOverlapsGrpcImpl(taskScheduler)
            {
                //Health = health
            };

            var advancedReshapeServiceImpl = new AdvancedReshapeGrpcImpl(taskScheduler);
            var changeAlongServiceImpl     = new ChangeAlongGrpcImpl(taskScheduler);

            //health.SetStatus(removeOverlapsServiceImpl.GetType(), true);

            ServerCredentials serverCredentials =
                GrpcServerUtils.GetServerCredentials(arguments.Certificate,
                                                     arguments.PrivateKeyFile);

            var oneGb = (int)Math.Pow(1024, 3);

            IList <ChannelOption> channelOptions = GrpcServerUtils.CreateChannelOptions(oneGb);

            var server =
                new Grpc.Core.Server(channelOptions)
            {
                Services =
                {
                    RemoveOverlapsGrpc.BindService(removeOverlapsServiceImpl),
                    ReshapeGrpc.BindService(advancedReshapeServiceImpl),
                    ChangeAlongGrpc.BindService(changeAlongServiceImpl)
                    //Health.BindService(healthService)
                },
                Ports =
                {
                    new ServerPort(arguments.HostName, arguments.Port, serverCredentials)
                }
            };

            server.Start();

            _msg.InfoFormat("Service is listening on host {0}, port {1}.", arguments.HostName,
                            arguments.Port);

            return(server);
        }
示例#14
0
 private SboAddon(string nameSpace, string name)
 {
     Namespace       = nameSpace;
     Name            = name;
     UiTaskScheduler = new StaTaskScheduler(1);
     TaskScheduler   = new SboTaskScheduler(TimeSpan.FromSeconds(30));
     Events          = new SboAddonEvents();
     Cache           = new MemoryCache(Name);
 }
示例#15
0
        public RemoteDataManager(IEventPublisher publisher)
        {
            CurrentBitcoinPrice = 0;
            _staTaskScheduler   = new StaTaskScheduler(Environment.ProcessorCount);
            _exchanges          = new List <IExchangeWrapper>();
            _publisher          = publisher;

            _publisher.GetEvent <UserSettingsUpdatedEvent>().Subscribe(OnSettingsUpdate);
        }
示例#16
0
 // Constructor
 public ActionManager(ILoggerService logger, IWindowService windowService)
 {
     _loadedActions    = new Dictionary <string, IAction>();
     RunningActions    = new ObservableCollection <RunningActionTask>();
     _staTaskScheduler = new StaTaskScheduler(Environment.ProcessorCount);
     _logger           = logger;
     _windowService    = windowService;
     Instance          = this;
 }
示例#17
0
        public T GetResultByCondition <T>(Func <T> getFunc, Func <T, bool> conditionFunc)
        {
            Exception lastException = null;

            using (var tokenSource = new CancellationTokenSource())
            {
                var token = tokenSource.Token;
                using (var sta = new StaTaskScheduler(1))
                {
                    var f    = new TaskFactory <T>(token, TaskCreationOptions.AttachedToParent, TaskContinuationOptions.ExecuteSynchronously, sta);
                    var task = f.StartNew(() =>
                    {
                        var cancelFlag = false;
                        while (!cancelFlag)
                        {
                            try
                            {
                                if (token.IsCancellationRequested)
                                {
                                    token.ThrowIfCancellationRequested();
                                }

                                var result = getFunc.Invoke();
                                if (result != null && conditionFunc.Invoke(result))
                                {
                                    return(result);
                                }
                            }
                            catch (OperationCanceledException e)
                            {
                                lastException = e;
                                cancelFlag    = true;
                            }
                            catch (Exception e)
                            {
                                _logger.Debug($"Exception: {e.Message}.{Environment.NewLine}{e.StackTrace}");
                                lastException = e;
                            }

                            Thread.Sleep(_retryTimeoutInMSec);
                        }

                        throw lastException ?? new OperationCanceledException("Operation was canceled!");
                    }, token, TaskCreationOptions.AttachedToParent, sta);
                    if (!task.Wait(_timeoutInMSec))
                    {
                        tokenSource.Cancel();
                    }
                    else if (task.IsCompleted)
                    {
                        return(task.Result);
                    }
                }
            }
            throw lastException ?? new TimeoutException("The operation has timed-out");
        }
示例#18
0
        public CameraPool(int numThreads, Color background)
        {
            _staScheduler = new StaTaskScheduler(numThreads);

            _tasks = new TaskWrapper[numThreads];
            for (int cntr = 0; cntr < numThreads; cntr++)
            {
                _tasks[cntr] = new TaskWrapper(_staScheduler, background);
            }
        }
示例#19
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var scheduler = new StaTaskScheduler(1);

            UpdateStatus("Searching...");
            Task.Factory.StartNew(() =>
            {
                Dispatcher.BeginInvoke(new Action(UpdatePatient));
            }, CancellationToken.None, TaskCreationOptions.None, scheduler);
        }
        public void ConstructingWithCustomNumberOfThreadsSetsTheCorrectNumberOfThreads()
        {
            // arrange
            const int threadsToUse = 2;

            // act
            var sut = new StaTaskScheduler(threadsToUse);

            // assert
            sut.Threads.Should().Be(threadsToUse);
        }
        public void DefaultConstructorSetCorrectNumberOfThreads()
        {
            // arrange
            var expectedThreads = Environment.ProcessorCount;

            // act
            var sut = new StaTaskScheduler();

            // assert
            sut.Threads.Should().Be(expectedThreads);
        }
        internal async Task ExportDocSetSalesReport(AsycudaDocumentSetEx docSet, string folder)
        {
            var doclst =
                await
                SalesDataRepository.Instance.GetSalesDocuments(
                    docSet.AsycudaDocumentSetId)
                .ConfigureAwait(false);

            if (doclst == null || !doclst.ToList().Any())
            {
                return;
            }
            StatusModel.StartStatusUpdate("Exporting Files", doclst.Count());

            var exceptions = new ConcurrentQueue <Exception>();

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(() =>
                {
                    var s = new ExportToExcel <SaleReportLine, List <SaleReportLine> >();
                    s.StartUp();
                    foreach (var doc in doclst)
                    {
                        try
                        {
                            var data = GetDocumentSalesReport(doc.ASYCUDA_Id).Result;
                            if (data != null)
                            {
                                string path = Path.Combine(folder,
                                                           !string.IsNullOrEmpty(doc.CNumber) ? doc.CNumber : doc.ReferenceNumber + ".xls");
                                s.dataToPrint = data.ToList();
                                s.SaveReport(path);
                            }
                            else
                            {
                                File.Create(Path.Combine(folder, doc.CNumber ?? doc.ReferenceNumber + ".xls"));
                            }
                            StatusModel.StatusUpdate();
                        }
                        catch (Exception ex)
                        {
                            exceptions.Enqueue(ex);
                        }
                    }
                    s.ShutDown();
                },
                                            CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }
示例#23
0
 static async Task Main(string[] args)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         StaTaskScheduler scheduler = new StaTaskScheduler(64);
         await Task.Factory.StartNew(() => Run(args), CancellationToken.None, TaskCreationOptions.None, scheduler);
     }
     else
     {
         Run(args);
     }
 }
    protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        // consider moving it to singleton instance to improve performance
        var staTaskScheduler = new StaTaskScheduler(100);

        return(Task.Factory.StartNew <HttpResponseMessage>(() =>
        {
            //somethign that does its magic and returns a HttpResponseMessag
            return new HttpResponseMessage();
        }, cancellationToken,
                                                           TaskCreationOptions.None,
                                                           staTaskScheduler));
    }
        public async Task Send2Excel(string folder, AsycudaDocument doc)
        {
            if (doc != null)
            {
                using (var ctx = new AsycudaDocumentRepository())
                {
                    var doctype = await ctx.GetAsycudaDocument(doc.ASYCUDA_Id.ToString()).ConfigureAwait(false);

                    if (doctype.DocumentType == "IM7")
                    {
                        return;
                    }
                }
            }

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(() =>
                {
                    var s = new ExportToExcel <SaleReportLine, List <SaleReportLine> >();
                    s.StartUp();

                    try
                    {
                        folder   = Path.GetDirectoryName(folder);
                        var data = GetDocumentSalesReport(doc.ASYCUDA_Id).Result;
                        if (data != null)
                        {
                            string path = Path.Combine(folder,
                                                       !string.IsNullOrEmpty(doc.CNumber) ? doc.CNumber : doc.ReferenceNumber + ".xls");

                            s.dataToPrint = data.ToList();
                            s.SaveReport(path);
                        }
                        else
                        {
                            s.dataToPrint = new List <SaleReportLine>();
                            File.Create(Path.Combine(folder, doc.CNumber ?? doc.ReferenceNumber + ".xls"));
                        }
                        StatusModel.StatusUpdate();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    s.ShutDown();
                },
                                            CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#26
0
        public QualityVerificationGrpcImpl(
            Func <VerificationRequest, IBackgroundVerificationInputs> inputsFactoryMethod,
            int maxThreadCount)
        {
            _verificationInputsFactoryMethod = inputsFactoryMethod;

            if (maxThreadCount <= 0)
            {
                maxThreadCount = Environment.ProcessorCount - 1;
            }

            _staThreadScheduler = new StaTaskScheduler(maxThreadCount);

            EnvironmentUtils.SetUserNameProvider(_userNameProvider);
        }
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <OverShortDetailsEX> lst = null;

            using (var ctx = new OverShortDetailsEXRepository())
            {
                lst = await ctx.GetOverShortDetailsByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <OverShortDetailsEXExcelLine, List <OverShortDetailsEXExcelLine> >
            {
                dataToPrint = lst.Select(x => new OverShortDetailsEXExcelLine
                {
                    ReceivedQty = x.ReceivedQty,


                    ItemNumber = x.ItemNumber,


                    ItemDescription = x.ItemDescription,


                    Cost = x.Cost,


                    InvoiceQty = x.InvoiceQty,


                    Status = x.Status,


                    ReceivedValue = x.ReceivedValue,


                    InvoiceValue = x.InvoiceValue
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
示例#28
0
// Send to Excel Implementation


        public async Task Send2Excel()
        {
            IEnumerable <EntryDataEx> lst = null;

            using (var ctx = new EntryDataExRepository())
            {
                lst = await ctx.GetEntryDataExByExpressionNav(vloader.FilterExpression, vloader.NavigationExpression).ConfigureAwait(continueOnCapturedContext: false);
            }
            if (lst == null || !lst.Any())
            {
                MessageBox.Show("No Data to Send to Excel");
                return;
            }
            var s = new ExportToExcel <EntryDataExExcelLine, List <EntryDataExExcelLine> >
            {
                dataToPrint = lst.Select(x => new EntryDataExExcelLine
                {
                    Type = x.Type,


                    DutyFreePaid = x.DutyFreePaid,


                    Total = x.Total,


                    InvoiceDate = x.InvoiceDate,


                    InvoiceNo = x.InvoiceNo,


                    ImportedTotal = x.ImportedTotal,


                    ImportedLines = x.ImportedLines,


                    TotalLines = x.TotalLines
                }).ToList()
            };

            using (var sta = new StaTaskScheduler(numberOfThreads: 1))
            {
                await Task.Factory.StartNew(s.GenerateReport, CancellationToken.None, TaskCreationOptions.None, sta).ConfigureAwait(false);
            }
        }
        public async Task ThreadIsCorrectlySetAsSta()
        {
            // arrange
            var            sut           = new StaTaskScheduler();
            ApartmentState?receivedState = null;
            var            act           = new Action(() =>
            {
                receivedState = Thread.CurrentThread.GetApartmentState();
            });

            // act
            await Task.Factory.StartNew(act, CancellationToken.None, TaskCreationOptions.None, sut);

            // assert
            receivedState.Should().NotBeNull();
            receivedState.Should().Be(ApartmentState.STA);
        }
        public void RunningTaskSynchronouslyWillCorrectlySwitchToStaThread()
        {
            // arrange
            ApartmentState?receivedState = null;
            var            sut           = new StaTaskScheduler(1);
            var            act1          = new Action(() => { receivedState = Thread.CurrentThread.GetApartmentState(); });
            var            task          = new Task(act1);

            Thread.CurrentThread.GetApartmentState().Should().Be(ApartmentState.MTA);

            // act
            task.RunSynchronously(sut);

            // assert
            receivedState.Should().NotBeNull();
            receivedState.Should().Be(ApartmentState.STA);
        }