示例#1
0
        public void Build(bool updateDefinitions)
        {
            _cache = new DefinitionCache();
            var profiles = new ProfileLocator(_token);

            mergeBuiltInCommands(updateDefinitions, profiles);
            // Reverse paths to handle global first then local
            var paths = profiles.GetPathsCurrentProfiles().Reverse().ToArray();

            foreach (var path in paths)
            {
                mergeExternalCommands(updateDefinitions, path);
            }

            // Add default language
            if (_defaultLanguage != null)
            {
                var lang = _cache.Get(new[] { _defaultLanguage });
                if (lang != null)
                {
                    var parameters = lang.Parameters;
                    foreach (var usage in parameters)
                    {
                        // Don't override existing commands with default language
                        if (_cache.Get(new[] { usage.Name }) == null)
                        {
                            _cache.Add(usage);
                        }
                    }
                }
            }
        }
示例#2
0
        private void listProfiles()
        {
            var profileLocator = new ProfileLocator(Environment.CurrentDirectory);

            Console.WriteLine("Active global profile: " + profileLocator.GetActiveGlobalProfile());
            Console.WriteLine("Active local profile:  " + profileLocator.GetActiveLocalProfile());
            var globalProfiles =
                profileLocator.GetProfilesForPath(
                    profileLocator.GetGlobalProfilesRoot());

            globalProfiles.Insert(0, "default");
            Console.WriteLine();
            Console.WriteLine("Global profiles:");
            globalProfiles.ForEach(x => Console.WriteLine("\t" + x));

            if (Directory.Exists(profileLocator.GetLocalProfilesRoot()))
            {
                var localProfiles =
                    profileLocator.GetProfilesForPath(
                        profileLocator.GetLocalProfilesRoot());
                localProfiles.Insert(0, "default");
                Console.WriteLine();
                Console.WriteLine("Local profiles:");
                localProfiles.ForEach(x => Console.WriteLine("\t" + x));
            }

            Console.WriteLine();
        }
示例#3
0
        private string  getLanguageInstallPath(Package package, bool forcelocal)
        {
            var language = _locator
                           .Locate()
                           .FirstOrDefault(x => x.GetLanguage() == package.Language);

            if (language == null)
            {
                Logger.Write("Failed to locate language " + package.Language);
                return(null);
            }
            var basepath = Path.GetDirectoryName(language.FullPath);

            if (forcelocal)
            {
                var profiles = new ProfileLocator(_token);
                basepath = Path.Combine(profiles.GetLocalProfilePath(profiles.GetActiveLocalProfile()), "languages");
            }
            return
                (Path.Combine(
                     Path.Combine(
                         basepath,
                         language.GetLanguage() + "-files"),
                     package.Target.Replace("language-", "") + "s"));
        }
示例#4
0
        private List <string> getLanguagePaths()
        {
            var orderedProfilePaths = new List <string>();
            var profiles            = new ProfileLocator(_keyPath);
            var profilePath         = profiles.GetGlobalProfilePath("default");

            if (profilePath != null)
            {
                orderedProfilePaths.Add(Path.Combine(profilePath, "languages"));
            }
            profilePath = profiles.GetGlobalProfilePath(profiles.GetActiveGlobalProfile());
            if (profilePath != null)
            {
                orderedProfilePaths.Add(Path.Combine(profilePath, "languages"));
            }
            profilePath = profiles.GetLocalProfilePath("default");
            if (profilePath != null)
            {
                orderedProfilePaths.Add(Path.Combine(profilePath, "languages"));
            }
            profilePath = profiles.GetLocalProfilePath(profiles.GetActiveLocalProfile());
            if (profilePath != null)
            {
                orderedProfilePaths.Add(Path.Combine(profilePath, "languages"));
            }

            var paths = new List <string>();

            foreach (var plugin in _pluginLocator().Locate())
            {
                addLanguagePath(plugin, orderedProfilePaths, ref paths);
            }
            paths.Reverse();
            return(paths);
        }
示例#5
0
        private string getInstallPath(Package package, ProfileLocator profiles, string activeProfile)
        {
            string installPath;

            if (package.Target.StartsWith("language-"))
            {
                var path = getLanguageInstallPath(package, !_useGlobal);
                if (path == null)
                {
                    _dispatch("error|could not find language to install language dependent package in");
                    return(null);
                }
                if (_useGlobal && !profiles.IsGlobal(path))
                {
                    _dispatch("error|cannot install language dependent package globally as language is installed locally.");
                    return(null);
                }
                return(path);
            }
            if (_useGlobal)
            {
                installPath = profiles.GetGlobalProfilePath(activeProfile);
            }
            else
            {
                installPath = profiles.GetLocalProfilePath(activeProfile);
            }
            if (installPath == null)
            {
                _dispatch("error|the current location does not have an initialized config point");
                return(null);
            }
            return(Path.Combine(installPath, package.Target + "s"));
        }
示例#6
0
        private void listProfilePaths()
        {
            var profileLocator = new ProfileLocator(Environment.CurrentDirectory);

            foreach (var path in profileLocator.GetPathsCurrentProfiles())
            {
                Console.WriteLine(path);
            }
        }
示例#7
0
        public string GetLocalPath(string profile)
        {
            var locator     = new ProfileLocator(_keyPath);
            var profilePath = locator.GetLocalProfilePath(profile);

            if (profilePath == null)
            {
                return(profilePath);
            }
            return(getPath(profilePath));
        }
示例#8
0
        public Script(string token, string workingDirectory, string file)
        {
            _file             = file;
            _token            = token;
            Name              = Path.GetFileNameWithoutExtension(file);
            Description       = "";
            _workingDirectory = workingDirectory;
            var profiles = new ProfileLocator(_token);

            _globalProfileName = profiles.GetActiveGlobalProfile();
            _localProfileName  = profiles.GetActiveLocalProfile();
        }
示例#9
0
        private void construct(string file, string keyPath, Action <string, string> outputDispatcher, Action <string> dispatch, bool dispatchErrors)
        {
            _file             = file;
            _keyPath          = keyPath;
            _outputDispatcher = outputDispatcher;
            _dispatch         = dispatch;
            _dispatchErrors   = dispatchErrors;
            var profiles = new ProfileLocator(_keyPath);

            _globalProfileName = profiles.GetActiveGlobalProfile();
            _localProfileName  = profiles.GetActiveLocalProfile();
            getEvents();
        }
示例#10
0
        public ReactiveScriptReader(string path, Func <PluginLocator> locator, Action <string, string> outputDispatcher, Action <string> dispatch)
        {
            _keyPath          = path;
            _outputDispatcher = outputDispatcher;
            _dispatch         = dispatch;
            var profiles = new ProfileLocator(_keyPath);

            _localScriptsPathDefault  = getPath(profiles.GetLocalProfilePath("default"));
            _localScriptsPath         = getPath(profiles.GetLocalProfilePath(profiles.GetActiveLocalProfile()));
            _globalScriptsPathDefault = getPath(profiles.GetGlobalProfilePath("default"));
            _globalScriptsPath        = getPath(profiles.GetGlobalProfilePath(profiles.GetActiveGlobalProfile()));
            _pluginLocator            = locator;
        }
示例#11
0
        private string getProfilePath(Args args, string name)
        {
            var profileLocator = new ProfileLocator(Environment.CurrentDirectory);

            if (args.IsGlobal)
            {
                return(profileLocator.GetGlobalProfilePath(name));
            }
            else
            {
                return(profileLocator.GetLocalProfilePath(name));
            }
        }
示例#12
0
        private string getActiveProfile(Args args)
        {
            var profileLocator = new ProfileLocator(Environment.CurrentDirectory);

            if (args.IsGlobal)
            {
                return(profileLocator.GetActiveGlobalProfile());
            }
            else
            {
                return(profileLocator.GetActiveLocalProfile());
            }
        }
示例#13
0
        public void Remove(string source)
        {
            var package = getPackage(source);

            if (package == null)
            {
                _dispatch(string.Format("error|there is no package {0} to remove", source));
                return;
            }
            var profiles = new ProfileLocator(_token);
            var isGlobal = profiles.IsGlobal(package.File);

            removePackage(package, Path.GetDirectoryName(Path.GetDirectoryName(package.File)), isGlobal);
            _dispatch(string.Format("Removed package {0}", package.Signature));
        }
示例#14
0
 private string getLanguagePath(bool createLocal, LanguagePlugin language, string dir)
 {
     if (createLocal)
     {
         var profiles = new ProfileLocator(_token);
         var path     = profiles.GetLocalProfilePath(profiles.GetActiveLocalProfile());
         return(Path.Combine(path, "languages", language.GetLanguage() + "-files", dir));
     }
     return
         (Path.Combine(
              Path.GetDirectoryName(language.FullPath),
              Path.Combine(
                  language.GetLanguage() + "-files",
                  dir)));
 }
示例#15
0
        public void Update(string packageToken)
        {
            var source = _packageFetcher.Fetch(packageToken);

            if (source == null)
            {
                _dispatch("error|cannot find the package you are trying to update to");
                return;
            }
            if (!File.Exists(source.Package))
            {
                _dispatch("error|cannot find the package you are trying to update to");
                return;
            }
            Package packageToUpdate = null;

            prepareForAction(
                source.Package,
                (package) => {
                packageToUpdate = getPackages(true)
                                  .FirstOrDefault(x => x.ID == package.ID);
                if (packageToUpdate == null)
                {
                    _dispatch("error|the package you are trying to update is not installed");
                    return(null);
                }
                var profiles = new ProfileLocator(_token);
                _useGlobal   = profiles.IsGlobal(packageToUpdate.File);
                return(Path.GetDirectoryName(Path.GetDirectoryName(packageToUpdate.File)));
            },
                (args) => {
                if (args.Match == null)
                {
                    printUnexistingUpdate(args.Package.ID, args.Package);
                }
                else
                {
                    update(source.Package, packageToUpdate, args);
                }
                return(true);
            });
            if (source.IsTemporaryPackage)
            {
                File.Delete(source.Package);
            }
        }
示例#16
0
        public List <Snippet> GetSnippets()
        {
            var list    = new List <Snippet>();
            var locator = new ProfileLocator(_token);
            var paths   = locator.GetPathsCurrentProfiles();

            foreach (var path in paths)
            {
                var dir = System.IO.Path.Combine(path, "snippets");
                if (Directory.Exists(dir))
                {
                    addFiles(list, dir);
                }
                scanLanguages(list, path);
            }
            return(list);
        }
示例#17
0
        private IEnumerable <Package> getPackages(bool all)
        {
            var profiles = new ProfileLocator(_token);
            var packages = new List <Package>();

            profiles.GetFilesCurrentProfiles("package.json").ToList()
            .ForEach(x => {
                try {
                    Logger.Write("Reading package " + x);
                    var package = Package.Read(x);
                    if (package != null)
                    {
                        packages.Add(package);
                    }
                } catch {
                }
            });
            return(packages);
        }
示例#18
0
        private DefinitionCache writeBuiltInCommands(string file, ProfileLocator profiles)
        {
            var builtInCache = new DefinitionCache();

            foreach (var cmd in _builtIn())
            {
                var item = builtInCache
                           .Add(
                    DefinitionCacheItemType.BuiltIn,
                    null,
                    DateTime.Now,
                    false,
                    true,
                    cmd.Name,
                    cmd.Usage.Description);
                add(builtInCache, item, cmd.Usage.Parameters);
            }
            writeCache(profiles.AppRootPath, builtInCache);
            return(builtInCache);
        }
示例#19
0
        private Package getPackage(string name)
        {
            Logger.Write("Looking for package " + name);
            var profiles = new ProfileLocator(_token);
            var packages = new List <Package>();

            profiles.GetFilesCurrentProfiles("package.json").ToList()
            .ForEach(x => {
                try {
                    Logger.Write("Reading package " + x);
                    var package = Package.Read(x);
                    if (package != null)
                    {
                        Logger.Write("adding package {0} ({1})", package.ID, package.Version);
                        packages.Add(package);
                    }
                } catch (Exception ex) {
                    Logger.Write(ex);
                }
            });
            return(packages.FirstOrDefault(x => x.ID == name));
        }
示例#20
0
        public void Start(string token)
        {
            token = fixPath(token);
            var appdir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Logger.Write("Initializing code engine");
            initCodeEngine(token, appdir);
            Logger.Write("Running init script for " + appdir);
            runInitScript(token, appdir);
            Logger.Write("Initalizing language plugins");
            _pluginLocator().Locate().ToList()
            .ForEach(plugin => {
                var language = plugin.GetLanguage();
                Logger.Write("Initializing " + language);
                runInitScript(token, Path.Combine(Path.GetDirectoryName(plugin.FullPath), language + "-files"));
            });
            var locator     = new ProfileLocator(token);
            var profilePath = locator.GetLocalProfilePath(locator.GetActiveLocalProfile());

            Logger.Write("Running init script for " + profilePath);
            runInitScript(token, profilePath);
        }
示例#21
0
        private void listProfilesRaw()
        {
            var profileLocator = new ProfileLocator(Environment.CurrentDirectory);

            Console.WriteLine("active-global|" + profileLocator.GetActiveGlobalProfile() + "|" + profileLocator.GetGlobalProfilePath(profileLocator.GetActiveGlobalProfile()));
            Console.WriteLine("active-local|" + profileLocator.GetActiveLocalProfile() + "|" + profileLocator.GetLocalProfilePath(profileLocator.GetActiveLocalProfile()));
            var globalProfiles =
                profileLocator.GetProfilesForPath(
                    profileLocator.GetGlobalProfilesRoot());

            globalProfiles.Insert(0, "default");
            globalProfiles.ForEach(x => Console.WriteLine("global|" + x + "|" + profileLocator.GetGlobalProfilePath(x)));

            if (Directory.Exists(profileLocator.GetLocalProfilesRoot()))
            {
                var localProfiles =
                    profileLocator.GetProfilesForPath(
                        profileLocator.GetLocalProfilesRoot());
                localProfiles.Insert(0, "default");
                localProfiles.ForEach(x => Console.WriteLine("local|" + x + "|" + profileLocator.GetLocalProfilePath(x)));
            }
        }
示例#22
0
        public AppSettings(string path, Func <IEnumerable <ICommandHandler> > handlers, Func <IEnumerable <ICommandHandler> > pluginHandlers)
        {
            _path = path;
            SourcePrioritization = new string[] {};
            var locator = new ProfileLocator(fixPath(Environment.CurrentDirectory));

            RootPath = locator.GetLocalProfilePath("default");
            if (RootPath == null)
            {
                RootPath = fixPath(Directory.GetCurrentDirectory());
            }
            else
            {
                RootPath = System.IO.Path.GetDirectoryName(RootPath);
            }
            var reader = new ConfigReader(RootPath);

            var defaultLanguage = reader.Get("default.language");

            if (defaultLanguage != null)
            {
                DefaultLanguage = defaultLanguage;
            }

            var enabledLanguages = reader.Get("enabled.languages");

            if (enabledLanguages != null)
            {
                EnabledLanguages = splitValue(enabledLanguages);
            }

            var prioritizedSources = reader.Get("oi.source.prioritization");

            if (prioritizedSources != null)
            {
                SourcePrioritization = splitValue(prioritizedSources);
            }
        }
示例#23
0
        private void mergeBuiltInCommands(bool updateDefinitions, ProfileLocator profiles)
        {
            var builtInFile  = Path.Combine(profiles.AppRootPath, "oi-definitions.json");
            var builtInCache = new DefinitionCache();

            if (File.Exists(builtInFile))
            {
                builtInCache = appendDefinitions(builtInFile);
                var updated = builtInCache.GetOldestItem();
                if (updateDefinitions && updated != null && fileTime(System.Reflection.Assembly.GetExecutingAssembly().Location) > updated.Updated)
                {
                    builtInCache = writeBuiltInCommands(builtInFile, profiles);
                }
            }
            else
            {
                if (updateDefinitions)
                {
                    Logger.Write("Could not find definition file: " + builtInFile);
                    builtInCache = writeBuiltInCommands(builtInFile, profiles);
                }
            }
            _cache.Merge(_enabledLanguages, builtInCache);
        }
示例#24
0
        public void Handle(Guid clientID, CommandMessage message)
        {
            if (clientID == Guid.Empty)
            {
                return;
            }
            if (message.Arguments.Count != 1)
            {
                return;
            }
            var tokenHint = message.Arguments[0];
            var locator   = new ProfileLocator(fixPath(tokenHint));
            var response  = "not-running";
            var tokenPath = locator.GetLocalProfilesRoot();

            if (tokenPath != null)
            {
                tokenPath = Path.GetDirectoryName(tokenPath);
                switch (message.Command)
                {
                case "get-token-path":
                    response = tokenPath;
                    break;

                case "get-token-endpoint":
                    var instance = (new CodeEngineDispatcher(new FS())).GetInstances().FirstOrDefault(x => matchPath(tokenPath, x.Key));
                    if (instance != null)
                    {
                        response = string.Format("127.0.0.1:{0}", instance.Port);
                    }
                    break;

                case "get-token-event-endpoint":
                    var events = (new OpenIDE.Core.EventEndpointIntegrarion.EventClient(tokenPath)).GetInstance();
                    if (events != null)
                    {
                        response = string.Format("127.0.0.1:{0}", events.Port);
                    }
                    break;

                case "get-token-output-endpoint":
                    var output = (new OpenIDE.Core.OutputEndpointIntegration.OutputClient(tokenPath)).GetInstance();
                    if (output != null)
                    {
                        response = string.Format("127.0.0.1:{0}", output.Port);
                    }
                    break;

                case "get-token-editor-endpoint":
                    var editor = (new OpenIDE.Core.EditorEngineIntegration.EngineLocator(new FS()))
                                 .GetInstances()
                                 .FirstOrDefault(x => x.Key == tokenPath);
                    if (editor != null)
                    {
                        response = string.Format("127.0.0.1:{0}", editor.Port);
                    }
                    break;
                }
            }
            _endpoint.Send(message.CorrelationID + response, clientID);
        }
示例#25
0
        public void Start(
            string path,
            ICacheBuilder cache,
            ICrawlResult crawlReader,
            PluginLocator pluginLocator,
            EventEndpoint eventDispatcher,
            string[] ignoreDirectories)
        {
            _cache           = cache;
            _crawlReader     = crawlReader;
            _eventDispatcher = eventDispatcher;
            Logger.Write("Setting up file trackers");
            Logger.Write("Setting up token file trackers");
            _tracker = new FileChangeTracker((x) => {
                if (x.Path.StartsWith(Path.Combine(path, ".OpenIDE")))
                {
                    return;
                }
                _eventDispatcher.Send(
                    "codemodel raw-filesystem-change-" +
                    x.Type.ToString().ToLower() +
                    " \"" + x.Path + "\"");
            });
            Logger.Write("Setting up local file trackers");
            _localTracker = new FileChangeTracker((x) => {
                _eventDispatcher.Send(
                    "codemodel raw-filesystem-change-" +
                    x.Type.ToString().ToLower() +
                    " \"" + x.Path + "\"");
            });
            Logger.Write("Setting up global file trackers");
            _globalTracker = new FileChangeTracker((x) => {
                _eventDispatcher.Send(
                    "codemodel raw-filesystem-change-" +
                    x.Type.ToString().ToLower() +
                    " \"" + x.Path + "\"");
            });
            Logger.Write("Adding plugins to cache");
            var plugins = pluginLocator.Locate().ToList();

            foreach (var x in plugins)
            {
                var plugin = new PluginPattern(x);
                _plugins.Add(plugin);
                _cache.Plugins.Add(
                    new CachedPlugin(x.GetLanguage(), plugin.Patterns));
                Logger.Write("Added plugin " + x.GetLanguage());
            }
            var locator     = new ProfileLocator(path);
            var profilePath = locator.GetLocalProfilePath(locator.GetActiveLocalProfile());

            if (Directory.Exists(profilePath))
            {
                Logger.Write("Starting tracker for {0}", path);
                _tracker.Start(path, getFilter(), handleChanges, ignoreDirectories);
            }
            else
            {
                Logger.Write("No local configuration point so not starting file tracker");
            }
            if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
            {
                if (Directory.Exists(profilePath))
                {
                    Logger.Write("Starting tracker for {0}", profilePath);
                    _localTracker.Start(profilePath, getFilter(), handleChanges, ignoreDirectories);
                }
            }
            var globalPath = locator.GetGlobalProfilePath(locator.GetActiveGlobalProfile());

            if (Directory.Exists(globalPath))
            {
                Logger.Write("Starting tracker for {0}", globalPath);
                _globalTracker.Start(globalPath, getFilter(), handleChanges, ignoreDirectories);
            }
        }
示例#26
0
 public SourceLocator(string token, string[] sourcePrioritization)
 {
     _token = token;
     _sourcePrioritization = sourcePrioritization;
     _locator = new ProfileLocator(_token);
 }
示例#27
0
        public string GetGlobalPath(string profile)
        {
            var locator = new ProfileLocator(_keyPath);

            return(getPath(locator.GetGlobalProfilePath(profile)));
        }
示例#28
0
        public string GetLocalPath()
        {
            var locator = new ProfileLocator(_keyPath);

            return(GetLocalPath(locator.GetActiveLocalProfile()));
        }
示例#29
0
        public void Execute(string[] arguments)
        {
            _verbose     = arguments.Contains("-v");
            _showoutputs = arguments.Contains("-o");
            _showevents  = arguments.Contains("-e");
            _printOnlyErrorsAndInconclusives = arguments.Contains("--only-errors");
            _logging = arguments.Contains("-l");
            var profiles = new ProfileLocator(_token);

            var testFiles = new List <string>();

            if (arguments.Length > 0 && File.Exists(arguments[0]))
            {
                testFiles.Add(arguments[0]);
            }
            else
            {
                testFiles
                .AddRange(
                    getTests(profiles.GetLocalProfilePath("default")));
                testFiles
                .AddRange(
                    getTests(profiles.GetGlobalProfilePath("default")));
                testFiles
                .AddRange(
                    getTests(
                        Path.GetDirectoryName(
                            Assembly.GetExecutingAssembly().Location)));
            }

            foreach (var testFile in testFiles)
            {
                _testRunLocation = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString());
                Console.WriteLine("Testing: {0}", testFile);
                var eventListenerStarted = false;
                var systemStarted        = false;
                var runCompleted         = false;
                var eventListener        = new Thread(() => {
                    var eventSocketClient = new EventStuff.EventClient(
                        (line) => {
                        if (line == "codeengine started")
                        {
                            log("Code engine started");
                            systemStarted = true;
                        }
                        if (line == "codeengine stopped")
                        {
                            log("Code engine stopped");
                            runCompleted = true;
                        }
                        _events.Add(line);
                    });
                    while (true)
                    {
                        eventSocketClient.Connect(_testRunLocation);
                        eventListenerStarted = true;
                        if (!eventSocketClient.IsConnected)
                        {
                            Thread.Sleep(10);
                            if (runCompleted || systemStarted)
                            {
                                break;
                            }
                            continue;
                        }
                        log("Event listener connected");
                        while (eventSocketClient.IsConnected)
                        {
                            Thread.Sleep(10);
                        }
                        break;
                    }
                    eventListenerStarted = false;
                });
                var     isQuerying = false;
                var     useEditor  = false;
                var     tests      = new List <string>();
                Process proc       = null;
                try {
                    Directory.CreateDirectory(_testRunLocation);
                    _events  = new List <string>();
                    _outputs = new List <string>();
                    _asserts = new List <string>();

                    log("Initializing test location");
                    runCommand("init");
                    // Make sure we run tests in default profile is
                    // this by any chance overloaded in init command
                    runCommand("profile load default");
                    eventListener.Start();

                    new Thread(() => {
                        log("Starting test process");
                        var testProc = new Process();
                        try {
                            testProc
                            .Query(
                                testFile,
                                _testRunLocation,
                                false,
                                Environment.CurrentDirectory,
                                (error, line) => {
                                if (line == "initialized" || line.StartsWith("initialized|"))
                                {
                                    log("Test file initialized");
                                    proc       = testProc;
                                    var chunks = line.Split(new[] { '|' });
                                    if (chunks.Length > 1 && chunks[1] == "editor")
                                    {
                                        while (!eventListenerStarted)
                                        {
                                            Thread.Sleep(10);
                                        }
                                        log("Starting editor");
                                        new Process().Run("oi", "editor test", false, _testRunLocation);
                                        log("Editor launched");
                                        useEditor = true;
                                    }
                                    else
                                    {
                                        log("System started");
                                        systemStarted = true;
                                    }
                                    return;
                                }
                                if (line == "end-of-conversation")
                                {
                                    isQuerying = false;
                                    return;
                                }
                                handleFeedback(proc, error, line);
                            });
                        } catch (Exception ex) {
                            handleFeedback(testProc, true, "A fatal error occured while running " + testFile + Environment.NewLine + ex.Message);
                        }
                        isQuerying   = false;
                        runCompleted = true;
                    }).Start();
                } catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }

                log("Waiting for system to complete loading");
                while (!systemStarted)
                {
                    Thread.Sleep(10);
                }

                log("Getting tests");
                isQuerying = ask(proc, "get-tests");
                while (isQuerying)
                {
                    Thread.Sleep(10);
                }
                tests.AddRange(
                    _summary.ToString()
                    .Replace("\t", "")
                    .Split(
                        new[] { Environment.NewLine },
                        StringSplitOptions.RemoveEmptyEntries));

                foreach (var test in tests)
                {
                    if (_currentTest != null)
                    {
                        writeInconclusive();
                    }
                    log("Running test: " + test);
                    _outputs.Clear();
                    _events.Clear();
                    _asserts.Clear();
                    _currentTest = test;
                    _summary     = new StringBuilder();
                    if (_verbose)
                    {
                        Console.Write(_currentTest + "...");
                    }
                    isQuerying = ask(proc, "test|" + _currentTest);
                    while (isQuerying)
                    {
                        Thread.Sleep(10);
                    }
                }

                if (useEditor)
                {
                    log("Shuting down editor");
                    new Process().Run("oi", "editor command kill", false, _testRunLocation);
                }

                log("Shuting down system");
                ask(proc, "shutdown");
                while (!runCompleted)
                {
                    Thread.Sleep(10);
                }

                log("Waiting for event listener to stop");
                while (eventListenerStarted)
                {
                    Thread.Sleep(10);
                }

                if (Directory.Exists(_testRunLocation))
                {
                    Directory.Delete(_testRunLocation, true);
                }

                if (_currentTest != null)
                {
                    writeInconclusive();
                }
                _currentTest = null;
                log("Test run finished");
                Console.WriteLine();
            }
        }
示例#30
0
        private bool install(string packageToken, string[] acceptedVersions)
        {
            var source = _packageFetcher.Fetch(packageToken);

            if (source == null || !File.Exists(source.Package))
            {
                _dispatch("error|could not find package " + packageToken);
                return(false);
            }

            if (isMetaPackage(source.Package))
            {
                installMetaPackage(source);
                return(true);
            }

            string activeProfile   = null;
            var    actionSucceeded = prepareForAction(
                source.Package,
                (package) => {
                var profiles = new ProfileLocator(_token);
                if (_useGlobal)
                {
                    activeProfile = profiles.GetActiveGlobalProfile();
                }
                else
                {
                    activeProfile = profiles.GetActiveLocalProfile();
                }
                var installPath = getInstallPath(package, profiles, activeProfile);
                if (installPath == null)
                {
                    return(null);
                }
                Logger.Write("Installing the package in " + installPath);
                return(installPath);
            },
                (args) => {
                if (args.Match != null)
                {
                    Logger.Write("found matching package " + args.Match);
                    var command = Path.GetFileNameWithoutExtension(args.Match);
                    var package = getPackage(command);
                    if (package != null)
                    {
                        Logger.Write("loaded package " + package.ID);
                        if (acceptedVersions != null)
                        {
                            if (acceptedVersions.Length > 0 && !acceptedVersions.Any(x => x == package.Version))
                            {
                                var versions = "";
                                foreach (var version in acceptedVersions)
                                {
                                    versions += version + ",";
                                }
                                versions = versions.Trim(new[] { ',' });
                                _dispatch(string.Format("error|dependency {0} ({1}) is installed. Accepted versions are {2}", args.Package.ID, package.Version, versions));
                                return(false);
                            }
                        }
                        Logger.Write(string.Format("skipping {0} ({1}) already installed", package.ID, package.Version));
                    }
                    else
                    {
                        _dispatch(string.Format("error|the package with the command {0} conflicts with the package you are trying to install", command));
                    }
                }
                 else if (acceptedVersions != null && !acceptedVersions.Any(x => x == args.Package.Version))
                {
                    var versions = "";
                    foreach (var version in acceptedVersions)
                    {
                        versions += version + ",";
                    }
                    versions = versions.Trim(new[] { ',' });
                    _dispatch(string.Format("error|dependency {0} of version {1} is not a valid. Accepted versions are {2}", args.Package.ID, args.Package.Version, versions));
                    return(false);
                }
                else
                {
                    installPackage(source.Package, args.Package, args.TempPath, args.InstallPath, activeProfile);
                }
                return(true);
            });

            if (source.IsTemporaryPackage)
            {
                File.Delete(source.Package);
            }
            return(actionSucceeded);
        }