private async Task ComputeCoverSample(Task waitRun)
        {
            var fileData   = _fileReaderProvider.ConvertFile(_fileName, _rawData);
            var low        = LOW ?? 0;
            var high       = HIGH ?? 2;
            var paramInput = ParamInput ?? 1;
            var step       = UseStep ? Step.Value : 0;
            var method     = SelectedMethod;



            var result = await
                         _coverMatrixManager.GetMatrix(fileData.Value, low, high, method,
                                                       paramInput, step, Progress, waitRun);

            if (result == null || waitRun.IsCompleted)
            {
                ShowButtons(false, true, false);
                return;
            }

            if (result.HasErrors())
            {
                ErrorBox(result);
                ShowButtons(false, true, false);
                return;
            }

            CoverSample                     = result.Value;
            result.Value.SHIGH              = high;
            result.Value.SLOW               = low;
            result.Value.STEP               = step;
            result.Value.SelecteMethod      = method.MethodName;
            result.Value.SelecteMethodParam = paramInput;
            CoverMatrixDataTable            = CoverSample.CoverResult.DataMatrix.DataTable;
            Progress.Progress               = 100;

            CanEnable = true;
            ShowButtons(false, true, true);
        }
Пример #2
0
        private async Task <Result <IEnumerable <FileContentResult> > > GetCoverSampleResult(InputData inputData)
        {
            try
            {
                var method = _groupingManager.GetGroupingMethods().FirstOrDefault(x => x.MethodName.Equals(inputData.MethodName));

                if (method is null)
                {
                    return(new Result <IEnumerable <FileContentResult> >(NieOdnalezionoPodanejMetodyGrupujacej));
                }

                Thread.CurrentThread.IsBackground = true;
                _thread = Thread.CurrentThread;

                var progressBarModel = new ProgressBarModel();

                var step = inputData.Step.HasValue ? Convert.ToDouble(inputData.Step) : 0;

                var source = new CancellationTokenSource();
                var token  = source.Token;

                var waitRun = Task.Run(() =>
                {
                    while (!token.IsCancellationRequested)
                    {
                    }

                    token.ThrowIfCancellationRequested();
                }, token);

                var result = await
                             _coverMatrixManager.GetMatrix(inputData.File, inputData.Low, inputData.High, method,
                                                           inputData.ParamInput, step, progressBarModel, waitRun);

                var dataTxt          = DateTime.Now.ToFileTimeUtc() + "DataMatrixTxt.txt";
                var testTxt          = DateTime.Now.ToFileTimeUtc() + "TestTxt.txt";
                var dataMatrixStream = _txtExportert.GetTxtStream(result.Value.CoverResult.DataMatrix.DataTable);
                var testMatrixStream = _txtExportert.GetTxtStream(result.Value.CoverResult.TestMatrix.DataTable);

                var excelName = $"{result.Value.FileName.Replace(" ", "").Replace(".", "").Replace('-', '_').ToUpper()}_SLOW_{result.Value.SLOW}_SHIGH_{result.Value.SHIGH}_STEP_{result.Value.STEP}_METHOD_{result.Value.SelecteMethod.Replace(' ', '_').ToUpper().Replace('Ó', 'O').Replace('Ś', 'S').Replace('Ć', 'C')}_PARAM_{result.Value.SelecteMethodParam}_GRADE_{result.Value.CoverResult.Grade}.xlsx";

                var excelStream = _excelWriter.ExportToStream(
                    result.Value,
                    result.Value.CoverResult.DataMatrix.DataTable,
                    result.Value.CoverResult.TestMatrix.DataTable);

                if (excelStream.HasErrors())
                {
                    return(new Result <IEnumerable <FileContentResult> >(excelStream.Error));
                }

                progressBarModel.Progress = 100;

                var array = new[] {
                    File(testMatrixStream, "application/txt", testTxt),
                    File(dataMatrixStream, "application/txt", dataTxt),
                    File(excelStream.Value, "application/xlsx", excelName)
                };

                return(new Result <IEnumerable <FileContentResult> >(array));
            }
            catch (ThreadAbortException e)
            {
                return(new Result <IEnumerable <FileContentResult> >(e.Message));
            }
            catch (OperationCanceledException e)
            {
                return(new Result <IEnumerable <FileContentResult> >(e.Message));
            }
            catch (Exception e)
            {
                return(new Result <IEnumerable <FileContentResult> >(e.Message));
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }