Пример #1
0
        public override object DoRun()
        {
            if (string.IsNullOrEmpty(File))
            {
                throw new ArgumentException("Filename must be specified.");
            }

            if (File.ToLower().EndsWith(".dll"))
            {
                var file = FileFinder.Find(File);

                if (Technique == Technique.Show)
                {
                    return(new InformativeAnswer($"Dll file exists {file}"));
                }

                var pluggedInTypes = TypeRegistry.Register(file);

                if (pluggedInTypes.Any())
                {
                    return(new SuccessAnswer($"Loaded {pluggedInTypes.Count()} plugins from \n\t {file}"));
                }
                else
                {
                    return(new WarningAnswer("No plugins were loaded."));
                }
            }
            else
            {
                var file = FileFinder.Find(File);

                if (Technique == Technique.Show)
                {
                    Process.Start("explorer.exe", file);
                    return(new InformativeAnswer($"Opening file {file}"));
                }

                var fileObjectAccess = new FileObjectAccess(file, ServiceLocator.Instance.Resolve <ITypeRegistry>());
                var data             = fileObjectAccess.GetAll();

                Interpreter.Data.Include(fileObjectAccess);

                Interpreter.Plan = data.OfType <IKeyword>();

                var corruptObjects = data.OfType <CorruptObject>();
                if (corruptObjects.Any())
                {
                    return
                        (new ExceptionAnswer("Invalid Keywords found in file.").With(
                             new ExceptionAnswer(string.Join("\n\t", corruptObjects))));
                }

                return(new SuccessAnswer("File loaded successfully."));
            }
        }
Пример #2
0
        public IEnumerable <object> RecursiveRead(string parentPath)
        {
            if (string.IsNullOrEmpty(FileName))
            {
                throw new InvalidOperationException("An Include object was passed to the system without FileName specified");
            }

            var fullPath = FileFinder.Find(FileName);

            if (File.Exists(fullPath))
            {
                return(new FileObjectAccess(fullPath, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll());
            }

            var directoryName = System.IO.Path.GetDirectoryName(parentPath);

            if (directoryName != null)
            {
                fullPath = System.IO.Path.Combine(directoryName, FileName);
                if (File.Exists(fullPath))
                {
                    return(new FileObjectAccess(fullPath, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll());
                }
            }

            try
            {
                var includedData = new FileObjectAccess(FileFinder.Find(FileName), ServiceLocator.Instance.Resolve <ITypeRegistry>());

                return(includedData.GetAll());
            }
            catch (Exception)
            {
                throw new IOException($"Included file '{FileName}' in '{this.ToString()}' was not found.");
            }
        }