/// <summary>
        ///  Read all objects in a file
        /// </summary>
        /// <param name="fileName">The text file. May contain only one or multiple objects</param>
        /// <returns>List of ApplicationObjects</returns>
        public static List <ApplicationObject> ReadNavObjects(string fileName)
        {
            TxtFileModelInfo modelInfo = new TxtFileModelInfo();
            TxtImporter      importer  = new TxtImporter(modelInfo);

            try
            {
                using (var instream = new FileStream(fileName, FileMode.Open))
                {
                    List <ApplicationObject> objects = importer.ImportFromStream(instream);
                    if (objects != null && objects.Count > 0)
                    {
                        return(objects);
                    }
                    else
                    {
                        Console.WriteLine(@"Object could not be read from file {0}", fileName);
                    }
                }
            }
            catch (Microsoft.Dynamics.Nav.Model.IO.Txt.TxtImportException e)
            {
                Console.WriteLine(@"Exception while reading {0}: {1}", fileName, e.Message);
                Console.WriteLine(@"Source line {0}, col {1}: {2}", e.LineNo, e.LinePos, e.Line);
            }
            catch (System.IO.IOException e)
            {
                Console.WriteLine(@"Exception while reading {0}: {1}", fileName, e.Message);
            }
            return(new List <ApplicationObject>());
        }
        public void LoadFromTextFile(string fileName)
        {
            Stream           sourceStream     = new FileStream(fileName, FileMode.Open);
            TxtImportOptions txtImportOptions = new TxtImportOptions();
            TxtImporter      txtImporter      = new TxtImporter(TxtFileModelInfo.Instance, txtImportOptions);

            this.AppObjects = txtImporter.ImportFromStream(sourceStream);
            sourceStream.Close();
            sourceStream.Dispose();
        }
Exemple #3
0
        /// <summary>
        /// Entry-point of the app
        /// </summary>
        /// <param name="args">
        /// - first argument should be the zip path
        /// </param>
        static void Main(string[] args)
        {
            string currentFolderPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            // gets static parameters from exe arguments
            if (args != null && args.Length >= 1)
            {
                _zipFilename = args[0];
            }
            if (args != null && args.Length >= 2)
            {
                _connectionString = args[1];
            }

            // check if the zip filename is provided,
            // if it is not provided, then set it to default one
            // (there should be a zip provided in .\Resources\)
            if (string.IsNullOrWhiteSpace(_zipFilename) || !File.Exists(_zipFilename))
            {
                _zipFilename = Path.Combine(currentFolderPath, DEFAULT_ZIP_FILENAME);
                if (!File.Exists(_zipFilename))
                {
                    Console.WriteLine("Zip file that contains txt hymns is not provided or not found!");
                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(_connectionString))
            {
                _connectionString = DEFAULT_CONNECTION_STRING;
            }
            // replace {APP_PATH} by current path
            _connectionString = _connectionString.Replace(APP_PATH, currentFolderPath);

            IProgressLogger progressLogger = new ConsoleProgressLogger();
            IDataRepository dataRepository = new SQLiteDataRepository(_connectionString, progressLogger);

            dataRepository.CreateSchemaIfNotExists();
            TxtImporter importer = new TxtImporter(dataRepository, progressLogger)
            {
                InputArhiveFilename = _zipFilename
            };

            importer.Import();

            Console.WriteLine();
            Console.WriteLine("Type [Return] key to exit...");
            Console.ReadLine();
        }