Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = Name.GetHashCode();

            hash += LoadedScripts.Select(script => script.GetHashCode()).Sum();
            return(hash);
        }
Exemplo n.º 2
0
        private string GetUniqueTestName(string name)
        {
            var newName = name;
            var i       = 0;

            while (LoadedScripts.Any(script => script.Name == newName))
            {
                newName = name + ++i;
            }

            return(newName);
        }
        public override void LoadAndParseScripts()
        {
            try
            {
                string[] scriptFiles = Directory.GetFiles(Constants.PatchersDir, Constants.ScriptFilePattern, SearchOption.TopDirectoryOnly).Select(Path.GetFullPath).ToArray();

                foreach (string file in scriptFiles)
                {
                    try
                    {
                        var script = JsonConvert.DeserializeObject <PatcherScript>(File.ReadAllText(file), new JsonSerializerSettings
                        {
                            DefaultValueHandling = DefaultValueHandling.Ignore,
                            NullValueHandling    = NullValueHandling.Ignore,
                            DateFormatString     = "dd.MM.yyyy"
                        });

                        if (ScriptEngineHelpers.ValidateScript(script))
                        {
                            ScriptEngineHelpers.AddPlaceholders(script);
                            ScriptEngineHelpers.ParsePlaceholders(script);
                            ScriptEngineHelpers.AddTargetFilesText(script);

                            LoadedScripts.Add(script);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error($"Error while loading the script file -> ({Path.GetFileName(file)})\r\n{(Program.IsDebugModeEnabled ? "\r\n" : string.Empty)}{ex.Message}{(Program.IsDebugModeEnabled ? $"\r\n{ex.StackTrace}" : string.Empty)}");
                        IsLoadingError = true;
                        FrmMain.Instance.grpReleaseInfo.Enabled = true;
                    }
                }

                if (LoadedScripts.Count > 0)
                {
                    FrmMain.Instance.grpPatcherInfo.Enabled = true;
                    FrmMain.Instance.grpReleaseInfo.Enabled = true;
                    FrmMain.Instance.txtReleaseInfo.Enabled = true;
                    FrmMain.Instance.chkMakeBackup.Enabled  = true;
                    FrmMain.Instance.btnPatch.Enabled       = true;
                }
            }
            catch
            {
                // ignored
            }
        }
Exemplo n.º 4
0
        public bool Similar(object obj)
        {
            var f = obj as TestFixture;

            if (f == null)
            {
                return(false);
            }

            if (f.Name != Name)
            {
                return(false);
            }

            return(LoadedScripts.SequenceEqual(f.LoadedScripts, new SimilarEqualityComparer()));
        }
Exemplo n.º 5
0
        private void ReplaceScriptWithName(string name, Script value)
        {
            var s = GetScriptWithName(name);

            if (s == null)
            {
                Logger.Logi(LogType.Error, "Tried to replace script value with name '" + name + "' but it was not found.");
            }

            var addedScriptIndex = LoadedScripts.Count - 1;
            var instertIntoIndex = LoadedScripts.IndexOf(s);

            RemoveScript(s);
            AddScript(s);
            MoveScriptBefore(addedScriptIndex, instertIntoIndex);
        }
Exemplo n.º 6
0
        private void UpdateLoadedScripts()
        {
            DataTable DT = new DataTable();

            DT.Columns.Add("Filename", typeof(string));
            DT.Columns.Add("Compilation Result", typeof(string));
            DT.Columns.Add("Effect count", typeof(int));
            DT.Columns.Add("Toy count", typeof(int));

            foreach (Script S in Pinball.Scripts)
            {
                int    ToyCnt            = 0;
                int    EffectCnt         = 0;
                string CompilationResult = "";
                if (S.Compiled)
                {
                    EffectCnt         = S.Assembly.GetTypes().Count(p => typeof(IEffect).IsAssignableFrom(p) && !p.IsAbstract);
                    ToyCnt            = S.Assembly.GetTypes().Count(p => typeof(IToy).IsAssignableFrom(p) && !p.IsAbstract);
                    CompilationResult = "OK";
                }
                else
                {
                    if (S.CompilationException != null)
                    {
                        CompilationResult = S.CompilationException.Message;
                    }
                    else
                    {
                        CompilationResult = "Not compiled";
                    }
                }
                DT.Rows.Add(S.File.FullName, CompilationResult, EffectCnt, ToyCnt);
            }

            LoadedScripts.ClearSelection();
            LoadedScripts.Columns.Clear();
            LoadedScripts.AutoGenerateColumns = true;
            LoadedScripts.DataSource          = DT;
            LoadedScripts.Refresh();
            LoadedScripts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);

            UpdateScriptTypes();
        }
Exemplo n.º 7
0
        private bool LoadFromPath(Scope globalScope, object self, string /*!*/ path, RubyEncoding /*!*/ pathEncoding, LoadFlags flags, out object loaded)
        {
            Assert.NotNull(pathEncoding, path);

            string[] sourceFileExtensions;
            if ((flags & LoadFlags.AnyLanguage) != 0)
            {
                sourceFileExtensions = DomainManager.Configuration.GetFileExtensions();
            }
            else
            {
                sourceFileExtensions = DomainManager.Configuration.GetFileExtensions(_context);
            }

            IList <ResolvedFile> files = FindFile(path, (flags & LoadFlags.AppendExtensions) != 0, sourceFileExtensions);

            if (files.Count == 0)
            {
                // MRI: doesn't throw an exception if the path is in $" (performs resolution first though):
                if (AlreadyLoaded(path, null, flags, sourceFileExtensions))
                {
                    loaded = null;
                    return(false);
                }
                throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", path));
            }

            ResolvedFile file = files.First();

            string pathWithExtension = path;

            if (file.AppendedExtension != null)
            {
                pathWithExtension += file.AppendedExtension;
            }

            if (AlreadyLoaded(path, files, flags) || _unfinishedFiles.Contains(file.Path))
            {
                if ((flags & LoadFlags.ResolveLoaded) != 0)
                {
                    if (file.SourceUnit != null)
                    {
                        Scope loadedScope;
                        if (!LoadedScripts.TryGetValue(file.Path, out loadedScope))
                        {
                            throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", file.Path));
                        }
                        loaded = loadedScope;
                    }
                    else
                    {
                        loaded = Platform.LoadAssemblyFromPath(file.Path);
                    }
                }
                else
                {
                    loaded = null;
                }
                return(false);
            }

            try {
                // save path as is, no canonicalization nor combination with an extension or directory:
                _unfinishedFiles.Push(file.Path);

                if (file.SourceUnit != null)
                {
                    AddScriptLines(file.SourceUnit);

                    ScriptCode compiledCode;
                    if (file.SourceUnit.LanguageContext == _context)
                    {
                        compiledCode = CompileRubySource(file.SourceUnit, flags);
                    }
                    else
                    {
                        compiledCode = file.SourceUnit.Compile();
                    }
                    loaded = Execute(globalScope, compiledCode);
                }
                else
                {
                    Debug.Assert(file.Path != null);
                    try {
                        Assembly assembly = Platform.LoadAssemblyFromPath(file.Path);
                        DomainManager.LoadAssembly(assembly);
                        loaded = assembly;
                    } catch (Exception e) {
                        throw RubyExceptions.CreateLoadError(e);
                    }
                }

                FileLoaded(MutableString.Create(file.Path, pathEncoding), flags);
            } finally {
                _unfinishedFiles.Pop();
            }

            return(true);
        }
Exemplo n.º 8
0
 private IList <Script> GetAllHooks()
 {
     return(LoadedScripts.Where(s => s.Name == k_Setup || s.Name == k_TearDown || s.Name == k_OneTimeSetup || s.Name == k_OneTimeTeardown).ToList());
 }
Exemplo n.º 9
0
 private IList <Script> GetAllTests()
 {
     return(LoadedScripts.Where(s => s.Name != k_Setup && s.Name != k_TearDown && s.Name != k_OneTimeSetup && s.Name != k_OneTimeTeardown).ToList());
 }
Exemplo n.º 10
0
 private Script GetScriptWithName(string name)
 {
     return(LoadedScripts.FirstOrDefault(s => s.Name == name));
 }