示例#1
0
        public bool Run(DefinitionCacheItem cmd, IEnumerable <string> args)
        {
            var arguments = args.ToList();

            Logger.Write("Removing the command name from parameters: " + arguments[0]);
            arguments.RemoveAt(0);
            if (cmd.Type == DefinitionCacheItemType.Script || cmd.Type == DefinitionCacheItemType.LanguageScript)
            {
                Logger.Write("Running command as script");
                var script = new Script(Bootstrapper.Settings.RootPath, Environment.CurrentDirectory, cmd.Location);
                var sb     = new StringBuilder();
                // On language commands remove the second argument too if
                // it matches the command name (oi langcommand vs oi C# langcommand)
                if (cmd.Type == DefinitionCacheItemType.LanguageScript &&
                    arguments.Count > 0 &&
                    Bootstrapper.Settings.EnabledLanguages.Contains(args.ElementAt(0)))
                {
                    Logger.Write("Removing second parameter from language command as it's a language script prefixed by language: " + arguments[0]);
                    arguments.RemoveAt(0);
                }
                for (int i = 0; i < arguments.Count; i++)
                {
                    sb.Append(" \"" + arguments[i] + "\"");
                }
                script.Run(
                    sb.ToString(),
                    (command) => {
                    Bootstrapper.DispatchAndCompleteMessage(
                        command,
                        () => {
                        Logger.Write("Writing end of command");
                        script.Write("end-of-command");
                    });
                });
            }
            else if (cmd.Type == DefinitionCacheItemType.Language)
            {
                Logger.Write("Running command as language command");
                var language = new LanguagePlugin(cmd.Location, Bootstrapper.DispatchMessage);
                // If default language command add original parameter
                if (args.ElementAt(0) != language.GetLanguage())
                {
                    arguments.Insert(0, args.ElementAt(0));
                }
                language.Run(arguments.ToArray());
            }
            else
            {
                Logger.Write("Running command as built in command");
                var command = Bootstrapper.GetDefaultHandlers()
                              .FirstOrDefault(x => x.Command == args.ElementAt(0));
                if (command == null)
                {
                    return(false);
                }
                command.Execute(arguments.ToArray());
            }
            return(true);
        }
示例#2
0
 public PluginPattern(LanguagePlugin plugin)
 {
     Plugin   = plugin;
     Patterns = new List <string>();
     Logger.Write("Getting file types for " + plugin.FullPath);
     Patterns.AddRange(
         Plugin
         .GetCrawlFileTypes()
         .Split(new string[]   {
         "|"
     }, StringSplitOptions.RemoveEmptyEntries));
     FilesToHandle = new List <string>();
 }
 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)));
 }
示例#4
0
        private void addLanguagePath(LanguagePlugin plugin, List <string> rootPaths, ref List <string> paths)
        {
            var pluginRoot = Path.GetDirectoryName(plugin.FullPath);
            var index      = rootPaths.IndexOf(pluginRoot);

            foreach (var root in rootPaths.Skip(index))
            {
                var path =
                    Path.Combine(
                        root,
                        Path.Combine(
                            plugin.GetLanguage() + "-files",
                            "rscripts"));
                if (!Directory.Exists(path))
                {
                    continue;
                }
                paths.Add(path);
            }
        }
示例#5
0
        public void languagePluginlvlUpVerifyDatabaseInsertTest()
        {
            var plugin = new SVNPlugin();

            plugin.Analyze();

            var langPlugin = new LanguagePlugin();

            langPlugin.Compute();

            var collection = new DatabaseManager()
                             .GetDatabase()
                             .GetCollection <IUser>(typeof(IUser).Name);

            foreach (var user in collection.FindAll())
            {
                var exp = user.ExperiencePoints[typeof(LanguageExperience).Name];
                Assert.AreEqual(Environment.UserName, exp.Name);
                Assert.AreEqual(2, exp.Level);
                Assert.AreEqual(20, exp.ExperiencePoints);
            }
        }
示例#6
0
 public LanguageHandler(LanguagePlugin plugin)
 {
     _plugin = plugin;
     Command = _plugin.GetLanguage();
 }
示例#7
0
        private DefinitionCache buildDefinitions(string file)
        {
            var cache = new DefinitionCache();
            var dir   = Path.GetDirectoryName(file);

            // Add languages
            var            languagePath    = Path.Combine(dir, "languages");
            LanguagePlugin defaultLanguage = null;

            foreach (var language in _languages(languagePath))
            {
                var item = cache.Add(
                    DefinitionCacheItemType.Language,
                    language.FullPath,
                    DateTime.Now,
                    false,
                    true,
                    language.GetLanguage(),
                    "Commands for the " + language.GetLanguage() + " plugin");
                add(cache, item, language.GetUsages());
            }

            // Add language scripts
            var currentLanguages = cache
                                   .Definitions
                                   .Where(x => x.Type == DefinitionCacheItemType.Language)
                                   .ToList();
            var otherLocationLanguages = _cache
                                         .Definitions
                                         .Where(x => x.Type == DefinitionCacheItemType.Language && !currentLanguages.Any(y => y.Name == x.Name))
                                         .ToList();

            foreach (var item in currentLanguages)
            {
                var languageScriptPath =
                    Path.Combine(
                        Path.Combine(
                            languagePath, item.Name + "-files"),
                        "scripts");
                if (!Directory.Exists(languageScriptPath))
                {
                    continue;
                }
                Logger.Write("Adding scripts from " + languageScriptPath);
                var languageScripts = new ScriptFilter().GetScripts(languageScriptPath);
                foreach (var scriptFile in languageScripts)
                {
                    Logger.Write("Script " + scriptFile);
                    var script = new Script(_token, _workingDirectory, scriptFile)
                                 .SetUsageDispatcher((msg) => {
                        if (msg.StartsWith("error|"))
                        {
                            printError(msg);
                        }
                    });
                    var usages     = script.Usages;                 // Description is built when fetching usages
                    var scriptItem = item.Append(
                        DefinitionCacheItemType.LanguageScript,
                        scriptFile,
                        DateTime.Now,
                        false,
                        true,
                        script.Name,
                        script.Description);
                    add(cache, scriptItem, usages);
                }
            }
            foreach (var language in otherLocationLanguages)
            {
                var languageScriptPath =
                    Path.Combine(
                        Path.Combine(
                            languagePath, language.Name + "-files"),
                        "scripts");
                if (!Directory.Exists(languageScriptPath))
                {
                    continue;
                }
                var item = cache.Add(
                    DefinitionCacheItemType.Language,
                    "placehoder-for-language-in-different-location",
                    DateTime.Now,
                    false,
                    true,
                    language.Name,
                    "");
                add(cache, item, new BaseCommandHandlerParameter[] {});
                Logger.Write("Adding scripts from " + languageScriptPath);
                var languageScripts = new ScriptFilter().GetScripts(languageScriptPath);
                foreach (var scriptFile in languageScripts)
                {
                    Logger.Write("Script " + scriptFile);
                    var script = new Script(_token, _workingDirectory, scriptFile)
                                 .SetUsageDispatcher((msg) => {
                        if (msg.StartsWith("error|"))
                        {
                            printError(msg);
                        }
                    });
                    var usages     = script.Usages;                 // Description is built when fetching usages
                    var scriptItem = item.Append(
                        DefinitionCacheItemType.LanguageScript,
                        scriptFile,
                        DateTime.Now,
                        false,
                        true,
                        script.Name,
                        script.Description);
                    add(cache, scriptItem, usages);
                }
            }

            // Add scripts
            var scriptPath = Path.Combine(dir, "scripts");

            Logger.Write("Adding scripts from " + scriptPath);
            var scripts = new ScriptFilter().GetScripts(scriptPath);

            foreach (var scriptFile in scripts)
            {
                Logger.Write("Adding script " + scriptPath);
                var script = new Script(_token, _workingDirectory, scriptFile)
                             .SetUsageDispatcher((msg) => {
                    if (msg.StartsWith("error|"))
                    {
                        printError(msg);
                    }
                });
                var usages = script.Usages;                 // Description is built when fetching usages
                var item   = cache.Add(
                    DefinitionCacheItemType.Script,
                    scriptFile,
                    DateTime.Now,
                    false,
                    true,
                    script.Name,
                    script.Description);
                add(cache, item, usages);
            }

            writeCache(dir, cache);
            return(cache);
        }