示例#1
0
 private async Task <LocalScriptFile> LoadScriptAsync(string scriptFile)
 {
     _logger.Verbose($"{scriptFile}: Loading");
     try
     {
         return(new LocalScriptFile(scriptFile, await Hashing.GetHashAsync(_fs, scriptFile).ConfigureAwait(false)));
     }
     catch (Exception exc)
     {
         var script = new LocalScriptFile(scriptFile, await Hashing.GetHashAsync(_fs, scriptFile).ConfigureAwait(false));
         script.AddError(exc.Message, LocalFileErrorLevel.Error);
         _logger.Error($"{scriptFile}: {exc.Message}");
         return(script);
     }
 }
示例#2
0
        private async Task <LocalScriptListFile> LoadScriptListAsync(IDictionary <string, LocalScriptFile> scripts, string scriptListFile, bool shouldTryLoadingReferences)
        {
            _logger.Verbose($"{scriptListFile}: Loading");
            var scriptRefs = new List <LocalScriptFile>();

            try
            {
                var scriptRefPaths = await _scriptListSerializer.GetScriptsAsync(scriptListFile);

                foreach (var scriptRefRelativePath in scriptRefPaths)
                {
                    string fullPath = GetReferenceFullPath(scriptListFile, scriptRefRelativePath);
                    if (scripts.TryGetValue(fullPath, out var scriptRef))
                    {
                        scripts.Remove(fullPath);
                        scriptRefs.Add(scriptRef);
                    }
                    else if (_ignoredPaths.Any(p => fullPath.StartsWith(p)))
                    {
                        continue;
                    }
                    else if (shouldTryLoadingReferences)
                    {
                        var script = await LoadScriptAsync(fullPath);

                        scriptRefs.Add(script);
                    }
                    else
                    {
                        var script = new LocalScriptFile(fullPath, null);
                        script.AddError($"Script that does not exist: '{fullPath}'", LocalFileErrorLevel.Error);
                        scriptRefs.Add(script);
                    }
                }

                if (scriptRefs == null || scriptRefs.Count <= 0)
                {
                    return(null);
                }

                var scriptsWithErrors = scriptRefs.Where(s => s.Status > LocalFileErrorLevel.None).ToList();
                var scriptList        = new LocalScriptListFile(scriptListFile, Hashing.GetHash(scriptRefPaths), scriptRefs.ToArray());
                if (scriptsWithErrors.Count == 1)
                {
                    scriptList.AddError($"Script {scriptsWithErrors[0].FullPath} has an issue: {scriptsWithErrors[0].Errors[0].Error}", scriptsWithErrors[0].Status);
                }
                else if (scriptsWithErrors.Count > 1)
                {
                    scriptList.AddError($"{scriptsWithErrors.Count} scripts have issues. First issue: {scriptsWithErrors[0].Errors[0].Error}", scriptsWithErrors[0].Status);
                }

                return(scriptList);
            }
            catch (Exception exc)
            {
                var scriptList = new LocalScriptListFile(scriptListFile, null, scriptRefs.ToArray());
                scriptList.AddError(exc.Message, LocalFileErrorLevel.Error);
                _logger.Error($"{scriptListFile}: {exc.Message}");
                return(scriptList);
            }
        }