Exemplo n.º 1
0
        public override async Task FollowUp()
        {
            Storage.RemoveByLabel(ColumnHeadersCrateLabel);
            //If file is not uploaded we hide file description
            if (string.IsNullOrEmpty(ActivityUI.FilePicker.Value))
            {
                Storage.RemoveByLabel(ColumnHeadersCrateLabel);
                Storage.RemoveByLabel(TabularUtilities.ExtractedFieldsCrateLabel);
                ActivityUI.ClearFileDescription();
                SelectedFileDescription = null;
            }
            else
            {
                var previousValues = SelectedFileDescription;
                //Update column header only if new file was uploaded
                if (previousValues == null || previousValues.Key != ActivityUI.FilePicker.Value)
                {
                    Storage.RemoveByLabel(ColumnHeadersCrateLabel);
                    Storage.RemoveByLabel(TabularUtilities.ExtractedFieldsCrateLabel);
                    var selectedFileDescription = new KeyValueDTO(ActivityUI.FilePicker.Value, ExtractFileName(ActivityUI.FilePicker.Value));

                    CrateSignaller.MarkAvailableAtRuntime <StandardTableDataCM>(RunTimeCrateLabel, true)
                    .AddFields((await _excelUtils.GetColumnHeaders(selectedFileDescription.Key)).Select(x => new FieldDTO(x)));

                    ActivityUI.MarkFileAsUploaded(selectedFileDescription.Value, selectedFileDescription.Key);
                    SelectedFileDescription = selectedFileDescription;

                    // Process table and get the Table and optionally (if one row) fields crate
                    var fileAsByteArray = await _excelUtils.GetExcelFileAsByteArray(ActivityUI.FilePicker.Value);

                    var tableCrates = GetExcelFileDescriptionCrates(fileAsByteArray, ActivityUI.FilePicker.Value, null, false);

                    foreach (var crate in tableCrates)
                    {
                        Storage.ReplaceByLabel(crate);
                    }

                    Storage.ReplaceByLabel(CreateExternalObjectHandlesCrate());
                }
            }

            Storage.Add(Crate.FromContent(FileCrateLabel, new StandardFileDescriptionCM()
            {
                Filename = FileCrateLabel
            }));
        }