Пример #1
0
        /// <summary>
        /// Creates information system from selected file.
        /// </summary>
        /// <returns>Information system.</returns>
        public static InformationSystem CreateFromFile(IDataFileParser parser, FileManager fileManager)
        {
            InformationSystem result = new InformationSystem()
            {
                Rows       = parser.Parse(fileManager.FileStream),
                Confidence = 0.0m,
                Support    = 0.0m,
                Name       = fileManager.FileName
            };

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Created dataset from uploaded file.
        /// </summary>
        /// <param name="fileName">Uploaded file name.</param>
        /// <param name="file">Stream which contains uploaed file.</param>
        public void ProcessUploadedFile(string fileName, Stream file)
        {
            if (file == null)
            {
                try
                {
                    file = new FileStream(fileName, FileMode.Open);
                }
                catch (IOException)
                {
                    View.NotifyAboutNoPermissionsToFile();

                    return;
                }
            }

            FileManager manager = null;

            try
            {
                manager = new FileManager(file, fileName);
            }
            catch (PartialAssociationRulesException ex)
            {
                if (ex.Exception == ExceptionsList.UnsuportedFileSelected)
                {
                    View.NotifyAboutUnsupportedFileSelected();
                }

                return;
            }

            IDataFileParser parser =
                Bootstrapper.ServiceLocator.GetService <IDataFileParser>(manager.Type);

            if (ApplicationModel.System != null)
            {
                InformationSystem sys = null;
                try
                {
                    sys = InformationSystem.CreateFromFile(parser, manager);
                }
                catch (PartialAssociationRulesException ex)
                {
                    switch (ex.Exception)
                    {
                    case ExceptionsList.ArgumentCountIncorrect:
                        View.NotifyAboutArgumentCountIncorrect();
                        break;

                    case ExceptionsList.RowsNotParsedCorrectly:
                        View.NotifyAboutRowsNotParsedCorrectly();
                        break;

                    case ExceptionsList.IncorrectNumberOfFilesInArchive:
                        View.NotifyAboutIncorrectNumberOfFilesInArchive();
                        break;

                    case ExceptionsList.IncorrectArchive:
                        View.NotifyAboutIncorrectArchive();
                        break;
                    }

                    return;
                }

                ApplicationModel.System.Rows = sys.Rows;
                View.SetStartupValues();
            }
            else
            {
                //TODO. Find out why I've added this else statement..
                ApplicationModel.System = InformationSystem.CreateFromFile(parser, manager);
            }

            viewModel.DataSetName        = manager.FileName;
            viewModel.ObjectsQuantity    = ApplicationModel.System.Rows.Count;
            viewModel.AttributesQuantity = ApplicationModel.System.Rows[0].Attributes.Count;

#if WEB
            //Thread.Sleep(2000);
            //   UpdateSummaryUP();
            viewModel.UpdateSummaryUP = true;
#endif
        }