Beispiel #1
0
        private static void SaveFunc(string[] obj)
        {
            logger.Log("Save function invoked", LogLevel.INFO);

            if (rootItem == null)
            {
                logger.Log("Save function invoked but no object has been read", LogLevel.WARNING);

                Console.WriteLine("You have to read object first.");
                Console.WriteLine("If you're having issues with the program type 'help' for more instructions.");
                return;
            }

            if (obj.Length != 1)
            {
                return;
            }
            try
            {
                DataContext.InjectSaveFilePathService(CommandLineSaveFilePathService.Create(obj[0]));
                DataContext.SaveDataCommand.Execute("Save");
            }
            catch (UnauthorizedAccessException e)
            {
                logger.Log("Unauthorized access !! \n" + e, LogLevel.ERROR);

                Console.WriteLine("Unauthorized access! Probably wrong PATH or you don't have enough privilages to save it in desired destination");
                return;
            }

            Console.WriteLine("Save: " + DataContext.SaveFileName);

            logger.Log("Correctly saved to file:\n" + DataContext.SaveFileName, LogLevel.INFO);
        }
        public static CommandLineSaveFilePathService Create(string filePath)
        {
            CommandLineSaveFilePathService commandLineSaveFilePathService = new CommandLineSaveFilePathService
            {
                _filePath = filePath
            };

            return(commandLineSaveFilePathService);
        }