Exemple #1
0
        public Result <FileData> ConvertFile(string filename, string[] data)
        {
            try
            {
                var isFileHasAppriopriateExtension = _fileChecker.IsFileHasAppriopriateExtension(filename);

                if (!isFileHasAppriopriateExtension)
                {
                    return(new Result <FileData>(NieprawidloweRozszerzenie));
                }
                var result = new FileData
                {
                    FileName = filename,
                    RawData  = data,
                };

                var dataModel = GetDataModel(result.RawData);
                result.Observations    = dataModel.Value.Rows;
                result.DataDescription = dataModel.Value.Columns;
                result.Attributes      = _attributeColumnConverter.ConvertColumns2Attributes(result.DataDescription).ToArray();
                var length      = result.Observations.Length;
                var dataObject  = result.Observations.Take(length * 2 / 3).ToArray();
                var testObjects = result.Observations.Except(dataObject).ToArray();
                DataObjectHelper.SchemeObject = null;
                result.DataObjects            = ConvertRows2DataObjects(result.Attributes, dataObject);
                result.TestObjects            = ConvertRows2DataObjects(result.Attributes, testObjects, result.DataObjects.Max(x => x.Id + 1));

                var joinedSring = string.Empty;
                if (result.RawData != null)
                {
                    joinedSring = result.RawData.Aggregate(joinedSring,
                                                           (current, nextRow) => current + nextRow + Environment.NewLine);
                }

                var newLineSignLength = Environment.NewLine.Length;

                result.JoinedString = joinedSring.Remove(joinedSring.Length - newLineSignLength, newLineSignLength);;

                return(new Result <FileData>(result));
            }
            catch (Exception e)
            {
                return(new Result <FileData>(e));
            }
        }
        private void ReadFile()
        {
            _openFileDialog.ShowDialog();
            var exist     = _fileChecker.IsFileExsist(_openFileDialog.FileName);
            var extension = _fileChecker.IsFileHasAppriopriateExtension(_openFileDialog.FileName);

            if (!(extension && exist))
            {
                ErrorBox(NieprawidlowyPlik);
            }

            var fileName = _openFileDialog.SafeFileName;
            var rawData  = _fileReader.GetFileContent(_openFileDialog.FileName);

            _fileName     = fileName;
            _rawData      = rawData;
            RawDataString = string.Join("\n", rawData);
            ((DelegateCommand)CmdComputeData).RaiseCanExecuteChanged();
        }