Exemplo n.º 1
0
        public async Task <AuditResult> Run(AuditRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var cmd = new WhereCmd()
            {
                EnableDebugging = request.EnableLogging
            };
            var nodePath = await cmd.GetNodePath();

            if (String.IsNullOrEmpty(nodePath) || !File.Exists(nodePath))
            {
                throw new Exception("Couldn't find NodeJs. Please, install NodeJs and make shure than PATH variable defined.");
            }

            var npm = new Npm(nodePath)
            {
                EnableDebugging = request.EnableLogging
            };
            var npmPath = await npm.GetNpmPath();

            var sm      = new ScriptMaker();
            var content = sm.Produce(request, npmPath);

            if (!sm.Save(content))
            {
                throw new Exception($"Couldn't save JS script to %temp% directory. Path: {sm.TempFileName}");
            }

            try
            {
                var node = new Node()
                {
                    EnableDebugging = request.EnableLogging
                };
                var stdoutJson = await node.Run(sm.TempFileName);

                var obj = parseJson(stdoutJson);
                return(await Task.FromResult(obj));
            }
            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(ex.Message) && Regex.IsMatch(ex.Message, @"Cannot find module[\s\S]+?node_modules\\lighthouse'"))
                {
                    throw new Exception("Lighthouse is not installed. Please, execute `npm install -g lighthouse` in console.");
                }
                throw;
            }
            finally
            {
                if (!npm.EnableDebugging)
                {
                    sm.Delete();
                }
            }
        }
Exemplo n.º 2
0
 public static void OpenWindow <T>(SearchWindowContext context,
                                   Action <Type> selectCallback,
                                   IEnumerable <Type> types        = null,
                                   string title                    = null,
                                   Func <Type, string> nameGetter  = null,
                                   Func <Type, string> groupGetter = null,
                                   Func <Type, Texture> iconGetter = null,
                                   ScriptMaker newScriptMaker      = null)
 {
     SearchWindow.Open(context, Create <T>(selectCallback, types, title, nameGetter, groupGetter, iconGetter, newScriptMaker));
 }
Exemplo n.º 3
0
    public static TypeSearchProvider Create <T>(Action <Type> selectCallback,
                                                IEnumerable <Type> types        = null,
                                                string title                    = null,
                                                Func <Type, string> nameGetter  = null,
                                                Func <Type, string> groupGetter = null,
                                                Func <Type, Texture> iconGetter = null,
                                                ScriptMaker newScriptMaker      = null)
    {
        var instance = CreateInstance <TypeSearchProvider>();

        instance.Init <T>(selectCallback, types, title, nameGetter, groupGetter, iconGetter, newScriptMaker);
        return(instance);
    }
Exemplo n.º 4
0
 public void Init <T>(Action <Type> selectCallback,
                      IEnumerable <Type> types        = null,
                      string title                    = null,
                      Func <Type, string> nameGetter  = null,
                      Func <Type, string> groupGetter = null,
                      Func <Type, Texture> iconGetter = null,
                      ScriptMaker newScriptMaker      = null)
 {
     type                = typeof(T);
     this.title          = title;
     this.types          = types;
     this.selectCallback = selectCallback;
     this.nameGetter     = nameGetter;
     this.groupGetter    = groupGetter;
     this.iconGetter     = iconGetter;
     this.newScriptMaker = newScriptMaker;
 }
Exemplo n.º 5
0
 private static void On_LoadGame()
 {
     ScriptMaker.OnLoad();
     Game.Print("Welcome to Script Maker :)");
 }