示例#1
0
 public void InstallFrameworks(IProjectSource source, Framework framework, ScriptEngine engine)
 {
     foreach (var impl in _frameworks.Where(impl => framework.HasFlag(impl.Framework)))
     {
         impl.Install(source, engine);
     }
 }
 public void Install(IProjectSource source, ScriptEngine engine)
 {
     if (source is IScript == false)
     {
         return;
     }
 }
示例#3
0
 public void Install(IProjectSource source, ScriptEngine engine)
 {
     if (source is IScript == false)
     {
         return;
     }
 }
 public void InstallFrameworks(IProjectSource source, Framework framework, ScriptEngine engine)
 {
     foreach (var impl in _frameworks.Where(impl => framework.HasFlag(impl.Framework)))
     {
         impl.Install(source, engine);
     }
 }
示例#5
0
        private Task <TestResult> RunTestAsync(IProjectSource script, ITest test)
        {
            var completionSource = new TaskCompletionSource <TestResult>();

            ThreadPool.QueueUserWorkItem(state => RunTest(completionSource, script, test));

            return(completionSource.Task);
        }
示例#6
0
        public Framework DetectFrameworks(IProjectSource script)
        {
            var result = _detectors.Aggregate(Framework.None, (f, detector) => f | detector.Analyze(script));

            var resolved = ResolveConflicts(result);

            _logger.Debug($"Framework detect: {script}: {resolved.ToString()}");

            return(resolved);
        }
        public Framework DetectFrameworks(IProjectSource script)
        {
            var result = _detectors.Aggregate(Framework.None, (f, detector) => f | detector.Analyze(script));

            var resolved = ResolveConflicts(result);

            _logger.Debug($"Framework detect: {script}: {resolved.ToString()}");

            return resolved;
        }
        public void Install(IProjectSource source, ScriptEngine engine)
        {
            if (source is IScript == false)
            {
                return;
            }

            var console = new BrowserConsole((IScript) source);

            engine.AddHostObject(nameof(console), console);
        }
示例#9
0
        public void Install(IProjectSource source, ScriptEngine engine)
        {
            if (source is IScript == false)
            {
                return;
            }

            var console = new BrowserConsole((IScript)source);

            engine.AddHostObject(nameof(console), console);
        }
示例#10
0
        private void RunTest(TaskCompletionSource <TestResult> completionSource, IProjectSource source, ITest test)
        {
            var logger = LogManager.GetCurrentClassLogger();

            var engine = _runtimeFactory.GetRuntime();

            try
            {
                logger.Debug("Installing frameworks into V8 execution context");

                _frameworkDetector.InstallFrameworks(source, source.Frameworks, engine);

                logger.Info($"Executing script: {test.Name}");

                var code = $"{{{WrapInCallExpression(test.RawCode)}}}";

                Func <Status, TestResult> transform =
                    status => new TestResult
                {
                    Test   = test,
                    Status = status,
                    Logs   = source.Logs
                };

                TestResult testResult;
                try
                {
                    engine.Evaluate(code);

                    testResult = transform(Status.Success);
                }
                catch (Exception ex)
                {
                    source.Logs.Add(Tuple.Create(DateTime.Now, Severity.Error, $"Uncaught exception: {ex}"));

                    testResult = transform(Status.Failed);
                }

                test.Result = testResult;

                completionSource.SetResult(testResult);

                _publisher.Publish(testResult);
            }
            catch (Exception ex)
            {
                completionSource.SetException(ex);
            }
            finally
            {
                engine.Dispose();
            }
        }
示例#11
0
        public Framework Analyze(IProjectSource source)
        {
            if (source.File != null)
            {
                Func <string[], string, bool> compare =
                    (possible, ext) => possible.Any(t => string.Equals(ext, t, StringComparison.InvariantCultureIgnoreCase));

                if (compare(Constants.FileExtensions.TypeScript, source.File.Extension))
                {
                    return(Framework.TypeScript);
                }

                if (compare(Constants.FileExtensions.CoffeeScript, source.File.Extension) ||
                    compare(Constants.FileExtensions.CSharp, source.File.Extension))
                {
                    return(GetLanguageFromCoffeeScriptOrCSharp(source));
                }

                if (compare(Constants.FileExtensions.JavaScript, source.File.Extension))
                {
                    return(Framework.JavaScript);
                }
            }

            if (string.IsNullOrEmpty(source.Content))
            {
                return(Framework.None);
            }

            var referenceExp = new Regex("^///(\\s*)?<reference",
                                         RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);

            if (referenceExp.IsMatch(source.Content))
            {
                return(Framework.TypeScript);
            }

            var amdExp = new Regex("^///(\\s*)?<amd-dependency",
                                   RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);

            if (amdExp.IsMatch(source.Content))
            {
                return(Framework.TypeScript);
            }

            return(Framework.None);
        }
示例#12
0
        public Framework Analyze(IProjectSource source)
        {
            if (source is IScript == false)
            {
                return(Framework.None);
            }

            var script = (IScript)source;

            var matches = script.ExpressionTree.Search <CallExpression>(IsRequireCall);

            if (matches.Any(IsRequireWithStringArgument))
            {
                return(Framework.NodeJs);
            }

            return(Framework.None);
        }
示例#13
0
        public Framework Analyze(IProjectSource source)
        {
            if (source is IScript == false)
            {
                return(Framework.None);
            }

            var script = (IScript)source;

            var matches = script.ExpressionTree.Search <CallExpression>(IsJasmineInvocation);

            if (matches.Any())
            {
                return(Framework.Jasmine);
            }

            return(Framework.None);
        }
示例#14
0
 private static Task FetchDependencyMapItems(IProjectSource source, IProjectReference project, List <Tuple <IProjectReference, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]>, Dictionary <IProjectFile, NugetDefinition> > > model)
 {
     return(Task.Run(() =>
     {
         try
         {
             var nugetDep = source.GetAllNugetDependencies(project, false);
             var nugetDef = source.GetAllNugetDefinitions(project, false);
             // Dictionary<Tuple<IProjectFile, IProjectInformation>, NugetDependency[]>
             if (nugetDep.Count > 0 || nugetDep.Count > 0)
             {
                 model.Add(new Tuple <IProjectReference, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]>, Dictionary <IProjectFile, NugetDefinition> >
                               (project, nugetDep, nugetDef));
             }
         }
         catch (Exception ex)
         {
             throw new Exception("Failed for project: " + project.GetName(), ex);
         }
     }));
 }
示例#15
0
        /// <summary>
        /// Attempt a best guess at whether a file contains C# or CoffeeScript code (both languages share the same file extension)
        /// </summary>
        private static Framework GetLanguageFromCoffeeScriptOrCSharp(IProjectSource source)
        {
            if (string.IsNullOrEmpty(source.Content))
            {
                return(Framework.None);
            }

            using (var sr = new StringReader(source.Content))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.StartsWith("#"))
                    {
                        return(Framework.CoffeeScript);
                    }

                    if (line.StartsWith("//") ||
                        line.StartsWith("using") ||
                        line.StartsWith("namespace") ||
                        line.StartsWith("class"))
                    {
                        return(Framework.CSharp);
                    }

                    return(Framework.CoffeeScript);
                }
            }

            return(Framework.None);
        }
示例#16
0
        public void Install(IProjectSource source, ScriptEngine engine)
        {
            if (source is IScript == false)
            {
                return;
            }

            var script = (IScript) source;

            var requireImpl = _componentContext.Resolve<RequireDefine>(
                new TypedParameter(typeof (ScriptEngine), engine),
                new TypedParameter(typeof (IScript), script));

            engine.AddHostObject(nameof(requireImpl), requireImpl);

            engine.Execute(
                @"var require = function (names, callback) {
                    var list = new mscorlib.System.Collections.ArrayList();

                    if (names && typeof names !== 'string') {
                        for (var i = 0; i < names.length; ++i) {
                          list.Add(names[i]);
                        }
                    }

                    var loaded = typeof name !== 'string'
                        ? requireImpl.RequireMultiple(list)
                        : requireImpl.RequireSingle(names);

                    if (typeof callback === 'function') {
                      return callback.apply(null, loaded);
                    }

                    return loaded;
                  };");

            engine.Execute(
              @"var define = function (name, deps, body) {
                  if (typeof name !== 'string') {
                      body = deps;
                      deps = name;
                      name = null;
                  }

                  if (deps instanceof Array === false) {
                    if (body == null && deps != null) {
                      body = deps;
                      deps = [];
                    }

                    body = deps;

                    deps = [];
                  }

                  var CallbackType = mscorlib.System.Func(mscorlib.System.Collections.ArrayList, mscorlib.System.Object);

                  var cb = new CallbackType(function(deps) {
                    if (typeof body === 'function') {
                      var transformed = [];

                      for (var i = 0; i < deps.Count; ++i) {
                        transformed.push(deps[i]);
                      }

                      return body.apply(null, deps);
                    }

                    return body;
                  });

                  var list = new mscorlib.System.Collections.ArrayList();

                  if (deps) {
                    for (var i = 0; i < deps.length; ++i) {
                      list.Add(deps[i]);
                    }
                  }

                  requireImpl.DefineModule(name, list, cb);

                  return require(name);
                };

                define['amd'] = true;");
        }
 public void Install(IProjectSource source, ScriptEngine engine)
 {
     // TODO(cbond): Find and run Jasmine framework code
 }
示例#18
0
        public ProcessProjectSources()
        {
            //We need to go through each type to see what needs to run. We open and close the connection since there are some long
            //calls before we hit up the DB again
            var configsToProcess = GetTypesThatNeedToRun();

            foreach (var config in configsToProcess)
            {
                var  domain = AppDomain.CurrentDomain.Load(config.AssemblyName);
                Type type   = domain.GetType(config.FullClassName);

                //we will only use only instance of the project source adapter
                IProjectSource projectSource = Activator.CreateInstance(type) as IProjectSource;
                if (projectSource == null)
                {
                    //if we couldnt initialize the type then the string is probably wrong so throw an error
                    throw new Exception();
                }

                //go through each instance for that adapter and call to get data and save it
                //pull back all of the data before writing any to the db so we dont have to keep a transaction open and
                //we dont risk writing part of the data but not all of it
                //a dictionary is kept so we can associate our projectSourceId to its entries
                var entriesFromSource = new Dictionary <int, IEnumerable <SourceEntryObj> >();
                foreach (var sourceInstance in config.ProjectSources)
                {
                    projectSource.Configure(sourceInstance.Configuration);
                    entriesFromSource.Add(sourceInstance.Id, projectSource.GetEntriesSince(config.LastRun ?? DateTime.MinValue));
                }

                using (var db = GetDb())
                {
                    using (var transaction = new TransactionScope())
                    {
                        //go through each source
                        foreach (var source in entriesFromSource)
                        {
                            //go through each entry for that source
                            foreach (var entry in source.Value)
                            {
                                //check and see if an entry already exists for that Id. If it does then update it, otherwise create a new one
                                ProjectSourceEntry dbEntry = db.ProjectSourceEntries.SingleOrDefault(e => e.SourceEntryId == entry.Id);
                                if (dbEntry == null)
                                {
                                    dbEntry = new ProjectSourceEntry
                                    {
                                        SourceEntryId   = entry.Id.Value,
                                        ProjectSourceId = source.Key,
                                        CreatedBy       = System.Environment.UserName,
                                        CreatedOn       = DateTime.Now
                                    };

                                    db.ProjectSourceEntries.AddObject(dbEntry);
                                }
                                else
                                {
                                    dbEntry.UpdatedBy = System.Environment.UserName;
                                    dbEntry.UpdatedOn = DateTime.Now;
                                }

                                dbEntry.Title   = entry.Title;
                                dbEntry.Message = entry.Message;
                                db.SaveChanges();
                            }
                        }

                        //regrab the config since we already closed the connection that grabbed the config
                        var configToUpdate = db.ProjectSourceTypes.Single(p => p.Id == config.Id);
                        configToUpdate.LastRun = DateTime.Now;
                        configToUpdate.NextRun = configToUpdate.LastRun.Value.AddMinutes(configToUpdate.Interval);
                        db.SaveChanges();

                        transaction.Complete();
                    }
                }
            }
        }
示例#19
0
 public int CompareTo(IProjectSource other)
 {
     throw new NotImplementedException();
 }
示例#20
0
 public CacheControl(IProjectSource source, Configuration config) : base(@"Cache.db")
 {
     _source = source;
     _config = config;
 }
示例#21
0
 public int CompareTo(IProjectSource other)
 {
     throw new NotImplementedException();
 }
示例#22
0
 public int CompareTo(IProjectSource other)
 {
     return string.Compare(File.Name, other.File.Name, StringComparison.InvariantCultureIgnoreCase);
 }
示例#23
0
        public void Install(IProjectSource source, ScriptEngine engine)
        {
            if (source is IScript == false)
            {
                return;
            }

            var script = (IScript)source;

            var requireImpl = _componentContext.Resolve <RequireDefine>(
                new TypedParameter(typeof(ScriptEngine), engine),
                new TypedParameter(typeof(IScript), script));

            engine.AddHostObject(nameof(requireImpl), requireImpl);

            engine.Execute(
                @"var require = function (names, callback) {
                    var list = new mscorlib.System.Collections.ArrayList();

                    if (names && typeof names !== 'string') {
                        for (var i = 0; i < names.length; ++i) {
                          list.Add(names[i]);
                        }
                    }

                    var loaded = typeof name !== 'string'
                        ? requireImpl.RequireMultiple(list)
                        : requireImpl.RequireSingle(names);
  
                    if (typeof callback === 'function') {
                      return callback.apply(null, loaded);
                    }

                    return loaded;
                  };");

            engine.Execute(
                @"var define = function (name, deps, body) {
                  if (typeof name !== 'string') {
                      body = deps;
                      deps = name;
                      name = null;
                  }

                  if (deps instanceof Array === false) {
                    if (body == null && deps != null) {
                      body = deps;
                      deps = [];
                    }

                    body = deps;

                    deps = [];
                  }
 
                  var CallbackType = mscorlib.System.Func(mscorlib.System.Collections.ArrayList, mscorlib.System.Object);

                  var cb = new CallbackType(function(deps) {
                    if (typeof body === 'function') {
                      var transformed = [];

                      for (var i = 0; i < deps.Count; ++i) {
                        transformed.push(deps[i]);
                      }

                      return body.apply(null, deps);
                    }

                    return body;
                  });

                  var list = new mscorlib.System.Collections.ArrayList();

                  if (deps) {
                    for (var i = 0; i < deps.length; ++i) {
                      list.Add(deps[i]);
                    }
                  }
    
                  requireImpl.DefineModule(name, list, cb);

                  return require(name);
                };

                define['amd'] = true;");
        }
示例#24
0
 public Framework Analyze(IProjectSource source)
 {
     return(Framework.jQuery); // FIXME(cbond): Detect usage of jQuery
 }
示例#25
0
 public void Install(IProjectSource source, ScriptEngine engine)
 {
     // TODO(cbond): Find and run Jasmine framework code
 }
示例#26
0
 public int CompareTo(IProjectSource other)
 {
     return(string.Compare(File.Name, other.File.Name, StringComparison.InvariantCultureIgnoreCase));
 }