/// <summary> /// Gets the table name which should match the main XML element which /// is the child of ROOT. /// </summary> /// <param name="xmlFile">The xml data file path.</param> /// <returns>The table name, without the schema name.</returns> public virtual DbObjectName GetTableNameFromXmlElement(IScriptFile xmlFile) { Debug.Assert(xmlFile != null); if (!fileSystem.Exists(xmlFile.Path)) { throw new SqlMigrationException( string.Format( "Could not find the XML data file {0}", xmlFile.Path)); } using (Stream content = xmlFile.GetContentStream()) { XPathDocument doc = new XPathDocument(content); XPathNavigator navi = doc.CreateNavigator(); navi.MoveToRoot(); if (!navi.MoveToFirstChild()) // ROOT { throw new SqlMigrationException( "XML document is empty. Could not find ROOT element."); } if (!navi.MoveToFirstChild()) // Table { throw new SqlMigrationException( "XML document contains no table data. Could not find table element."); } string elem = navi.LocalName; elem = elem.Replace("<", "").Replace(">", "").Trim(); return(elem); } }
/// <summary> /// The build change script. /// </summary> /// <param name="changes">The changes.</param> /// <returns>A string containing the contents of the provided change files</returns> public string BuildChangeScript(IDictionary <decimal, IScriptFile> changes) { StringBuilder changeScript = new StringBuilder(); this.undoToken = this.configurationService.DatabaseService.GetScriptFromFile(DatabaseScriptEnum.UndoToken); this.tokenReplacer.CurrentVersion = changes.Keys.Min() - 1; this.AppendScript(DatabaseScriptEnum.ChangeScriptHeader, changeScript); decimal[] sortedKeys = changes.Keys.OrderBy(k => k).ToArray(); foreach (decimal key in sortedKeys) { IScriptFile scriptFile = changes[key]; this.tokenReplacer.Script = scriptFile; this.AppendScript(DatabaseScriptEnum.ScriptHeader, changeScript); this.AppendScriptBody(changeScript, scriptFile.Contents, false); this.AppendScript(DatabaseScriptEnum.ScriptFooter, changeScript); } this.AppendScript(DatabaseScriptEnum.ChangeScriptFooter, changeScript); return(changeScript.ToString()); }
public static FileVariable Create(IScriptFile file, AccessModifier access, string @namespace, string name, TypeReference type, bool readOnly, int line, int column, int codeHash, VariableContainerAction resetter, VariableContainerAction creator, VariableContainerAction initializer) { var vcOwnerAccess = VariableContainer.Create(@namespace, name, type, readOnly); vcOwnerAccess.FileLine = line; vcOwnerAccess.FileColumn = column; vcOwnerAccess.CodeHash = codeHash; vcOwnerAccess.Tag = new Dictionary <Type, Object>(); if (resetter != null) { vcOwnerAccess.DataResetter = resetter; } if (creator != null) { vcOwnerAccess.DataCreator = creator; } if (initializer != null) { vcOwnerAccess.DataInitializer = initializer; } return(new FileVariable(file, access, line, null, @namespace, name, vcOwnerAccess, vcOwnerAccess.Container.UniqueID)); }
public static IExecutor CreateExecutor(IDatabase db, IScriptFile script) { if (script.IsXml) { if (db.Root.DriverString != "SQL") { string msg = "Loading of XML data is not currently supported " + "by SqlMigration for your RDMS."; throw new NotSupportedException(msg); } return(new SqlServerBulkXmlExecutor()); } else { if (db.Root.DriverString == "SQL") { return(new SqlServerBatchExecutor()); } else { return(new BatchExecutor()); } } }
/// <summary> /// Executes the specified SQL script in batches. /// </summary> /// <param name="db">The database instance to run the script against.</param> /// <param name="sqlFile">The T-SQL script to execute.</param> public virtual void Execute(IDatabase db, IScriptFile sqlFile) { Throw.If(db, "db").IsNull(); Throw.If(!sqlFile.IsSql, "sqlFile"); if (!fileSystem.Exists(sqlFile.Path)) { throw new SqlMigrationException( string.Format( "Could not find the SQL script file {0}", sqlFile.Path)); } string[] sqlBatches; if (!string.IsNullOrEmpty(BatchDelimiter)) { Regex regex = new Regex("^" + BatchDelimiter, RegexOptions.IgnoreCase | RegexOptions.Multiline); sqlBatches = regex.Split(fileSystem.ReadToEnd(sqlFile.Path)); } else { sqlBatches = new string[1]; sqlBatches[0] = fileSystem.ReadToEnd(sqlFile.Path); } currentScript = sqlFile; currentDb = db; ExecuteSqlInternal(sqlBatches); }
public FileElement(IScriptFile file, int line, IFileElement parentElement, string @namespace, string name, AccessModifier access, FileElementType type) { m_parentFile = file; m_line = line; m_baseElement = null; m_parentElement = parentElement; m_elementName = name; m_accessModifier = access; m_elementType = type; if (String.IsNullOrEmpty(@namespace)) { m_elementFullName = m_elementName; } else { m_elementFullName = @namespace + "." + m_elementName; } //if (m_parentElement != null) //{ // m_elementFullName = m_parentElement.FullName + "." + m_elementName; //} //else //{ //} }
public FileDatatable( IScriptFile file, AccessModifier access, int line, IDatatable parentElement, string @namespace, string name) : base(file, line, parentElement, @namespace, name, access, FileElementType.Datatable) { }
public ScriptEditor(EngineDescription buildInfo, IScriptFile scriptFile, IStreamManager streamManager) { _buildInfo = buildInfo; _scriptFile = scriptFile; InitializeComponent(); var thrd = new Thread(DecompileScripts); thrd.SetApartmentState(ApartmentState.STA); thrd.Start(streamManager); }
public ScriptEditor(IScriptFile scriptFile, IStreamManager streamManager, string scriptDefsFile) { _scriptFile = scriptFile; _scriptDefsFile = scriptDefsFile; InitializeComponent(); Thread thrd = new Thread(DecompileScripts); thrd.SetApartmentState(ApartmentState.STA); thrd.Start(streamManager); }
public ScriptEditor(EngineDescription buildInfo, IScriptFile scriptFile, IStreamManager streamManager, ICacheFile casheFile, Endian endian) { _endian = endian; _buildInfo = buildInfo; _opcodes = _buildInfo.ScriptInfo; _scriptFile = scriptFile; _streamManager = streamManager; _cashefile = casheFile; // If a game contains hsdt tags, it uses a newer Blam Script syntax. Currently the compiler only supports the old syntax. _hasNewSyntax = _buildInfo.Layouts.HasLayout("hsdt"); InitializeComponent(); // Disable user input. Enable it again when all background tasks have been completed. txtScript.IsReadOnly = true; // Enable code completion only if the compiler supports this game. if (!_hasNewSyntax) { txtScript.TextArea.GotFocus += EditorGotFocus; txtScript.TextArea.LostFocus += EditorLostFocus; txtScript.TextArea.TextEntering += EditorTextEntering; txtScript.TextArea.TextEntered += EditorTextEntered; txtScript.TextArea.Document.Changed += EditorTextChanged; } App.AssemblyStorage.AssemblySettings.PropertyChanged += Settings_SettingsChanged; SetHighlightColor(); SearchPanel srch = SearchPanel.Install(txtScript); var bconv = new System.Windows.Media.BrushConverter(); var srchbrsh = (System.Windows.Media.Brush)bconv.ConvertFromString("#40F0F0F0"); srch.MarkerBrush = srchbrsh; txtScript.SyntaxHighlighting = LoadSyntaxHighlighting(); // With syntax highlighting and HTML formatting, copying text takes ages. Disable the HTML formatting for copied text. DataObject.AddSettingDataHandler(txtScript, onTextViewSettingDataHandler); _progress = new Progress <int>(i => { progressBar.Value = i; }); itemShowInformation.IsChecked = App.AssemblyStorage.AssemblySettings.ShowScriptInfo; itemDebugData.IsChecked = App.AssemblyStorage.AssemblySettings.OutputCompilerDebugData; // Enable compilation only for supported games. if (_buildInfo.Name.Contains("Reach") || _buildInfo.Name.Contains("Halo 3") && _buildInfo.HeaderSize != 0x800 && !_buildInfo.Name.Contains("ODST")) { compileButton.Visibility = Visibility.Visible; progressReporter.Visibility = Visibility.Visible; } }
public virtual void Execute(IDatabase db, IScriptFile xmlFile) { Throw.If(db, "db").IsNull(); Throw.If(xmlFile, "xmlFile").IsNull(); Throw.If(!xmlFile.IsXml, "xmlFile"); DbObjectName tableName = GetTableNameFromXmlElement(xmlFile); ITable table = MyMetaUtil.GetTableOrThrow(db, tableName); LoadTable(table, xmlFile.Path); }
public FileVariable( IScriptFile file, AccessModifier access, int line, IFileElement parentElement, string @namespace, string name, IValueContainerOwnerAccess variableAccess, int id) : base(file, line, parentElement, @namespace, name, access, FileElementType.FileVariable) { m_variableAccess = variableAccess; m_id = id; }
private void LoadScriptFiles(IReader reader) { // Scripts are just loaded from scnr for now... if (_tags != null && _buildInfo.Layouts.HasLayout("scnr")) { ITag scnr = _tags.FindTagByClass("scnr"); if (scnr != null) { ScriptFiles = new IScriptFile[1]; ScriptFiles[0] = new ThirdGenScenarioScriptFile(scnr, ScenarioName, MetaArea, StringIDs, _buildInfo); return; } } ScriptFiles = new IScriptFile[0]; }
private void LoadScriptFiles(IReader reader) { if (_tags != null && _buildInfo.Layouts.HasLayout("hsdt")) { int tagCount = 0; IEnumerable <ITag> scripttags = _tags.FindTagsByClass("hsdt"); ITag scnr = _tags.FindTagByClass("scnr"); if (scnr == null) { ScriptFiles = new IScriptFile[0]; return; } foreach (ITag aHS in scripttags) { tagCount++; } ScriptFiles = new IScriptFile[tagCount]; int i = 0; foreach (ITag aHS in scripttags) { string tagname = _fileNames.GetTagName(aHS.Index); ScriptFiles[i] = new ThirdGenScenarioScriptFile(scnr, aHS, tagname, MetaArea, StringIDs, _buildInfo, _expander); i++; } return; } else if (_tags != null && _buildInfo.Layouts.HasLayout("scnr")) { ITag scnr = _tags.FindTagByClass("scnr"); if (scnr != null) { ScriptFiles = new IScriptFile[1]; ScriptFiles[0] = new ThirdGenScenarioScriptFile(scnr, ScenarioName, MetaArea, StringIDs, _buildInfo, _expander); return; } } ScriptFiles = new IScriptFile[0]; }
private void LoadScriptFiles() { if (_tags != null) { ScriptFiles = new IScriptFile[0]; if (_buildInfo.Layouts.HasLayout("scnr")) { //caches are intended for 1 scenario, so only load the *real* one ITag hs = _tags.GetGlobalTag(CharConstant.FromString("scnr")); if (hs != null) { ScriptFiles = new IScriptFile[1]; ScriptFiles[0] = new ScnrScriptFile(hs, _fileNames.GetTagName(hs.Index), MetaArea, _buildInfo, StringIDs, _expander, Allocator); } } } }
private void LoadScriptFiles() { if (_tags != null) { if (_buildInfo.Layouts.HasLayout("hsdt")) { ScriptFiles = _tags.FindTagsByGroup("hsdt").Select(t => new HsdtScriptFile(t, _fileNames.GetTagName(t.Index), MetaArea, _buildInfo, StringIDs, _expander)).ToArray(); } else if (_buildInfo.Layouts.HasLayout("scnr")) { ScriptFiles = _tags.FindTagsByGroup("scnr").Select(t => new ScnrScriptFile(t, _fileNames.GetTagName(t.Index), MetaArea, _buildInfo, StringIDs, _expander, Allocator)).ToArray(); } else { ScriptFiles = new IScriptFile[0]; } } }
internal static IProcedureReference <T> Create <T>(IScriptFile file, string @namespace, string name, ContextLogOption logOption, T runtime) where T : class { if (file == null) { throw new ArgumentNullException("file"); } if (runtime == null) { throw new ArgumentNullException("runtime"); } var fp = new FileProcedure(file, AccessModifier.Public, -1, null, @namespace, name, logOption, true); fp.SetRuntimeProcedure(runtime as Delegate); var referenceType = typeof(Reference <>).MakeGenericType(typeof(T)); fp.m_reference = (IProcedureReference)Activator.CreateInstance(referenceType, fp); return(fp.m_reference as IProcedureReference <T>); }
public static object ParseExpression(IScriptFile fileContext, string expression) { var builder = FileBuilder.ParseExpression(fileContext as ScriptFile, m_addonManager, expression); if (builder.Errors.ErrorCount > 0) { throw new Exception("Error parsing expression: " + builder.Errors[0].Message); } var result = builder.Listener.GetExpressionResult(); if (result.IsUnresolvedIdentifier) { result = new SBExpressionData(Expression.Constant(result.Value)); } var expressionAsObject = Expression.Convert(result.ExpressionCode, typeof(object)); return(Expression.Lambda <Func <object> >(expressionAsObject).Compile()()); }
public FileProcedure( IScriptFile file, AccessModifier access, int line, IFileElement parentElement, string @namespace, string name, ContextLogOption logOption = ContextLogOption.Normal, bool separateStateLevel = true) : base(file, line, parentElement, @namespace, name, access, FileElementType.ProcedureDeclaration) { m_callContextParameter = Expression.Parameter(typeof(ICallContext), "callcontext"); //var delegatetype = (m_runtimeProcedure != null) ? m_runtimeProcedure.GetType() : typeof(UnresolvedProcedureType); //m_parametersInternal.Add(new IdentifierInfo("callcontext", "callcontext", IdentifierType.Parameter, delegatetype, m_callContextParameter)); m_returnLabel = Expression.Label(); this.LogOption = logOption; this.Flags = (this.Flags & ProcedureFlags.SeparateStateLevel) | (separateStateLevel ? ProcedureFlags.SeparateStateLevel : ProcedureFlags.None); }
private void LoadScriptFiles() { ScriptFiles = new IScriptFile[0]; if (_tags != null) { List <IScriptFile> l_scriptfiles = new List <IScriptFile>(); if (_buildInfo.Layouts.HasLayout("scnr")) { foreach (ITag hs in _tags.FindTagsByGroup("scnr")) { l_scriptfiles.Add(new ScnrScriptFile(hs, _fileNames.GetTagName(hs.Index), MetaArea, _buildInfo, StringIDs, _expander, Allocator)); } } else { return; } ScriptFiles = l_scriptfiles.ToArray(); } }
public ScriptEditor(EngineDescription buildInfo, IScriptFile scriptFile, IStreamManager streamManager, Endian endian) { _endian = endian; _buildInfo = buildInfo; _scriptFile = scriptFile; _showInfo = App.AssemblyStorage.AssemblySettings.ShowScriptInfo; InitializeComponent(); var thrd = new Thread(DecompileScripts); thrd.SetApartmentState(ApartmentState.STA); thrd.Start(streamManager); SearchPanel srch = SearchPanel.Install(txtScript); var bconv = new System.Windows.Media.BrushConverter(); var srchbrsh = (System.Windows.Media.Brush)bconv.ConvertFromString("#40F0F0F0"); srch.MarkerBrush = srchbrsh; App.AssemblyStorage.AssemblySettings.PropertyChanged += Settings_SettingsChanged; SetHighlightColor(); }
private void ReInsertFileInNamespaceList(IScriptFile file) { // Remove from any list foreach (var list in m_namespaceLists) { if (list.Value.Item1.Contains(file)) { list.Value.Item1.Remove(file); } } // Add to existing list if on exist foreach (var list in m_namespaceLists) { if (String.Equals(file.Namespace, list.Name, StringComparison.InvariantCulture)) { list.Value.Item1.Add(file); return; } } // Create new list and add file to that var newlist = this.CreateNewList(file.Namespace); newlist.Value.Item1.Add(file); }
private void LoadScriptFiles(IReader reader) { // Scripts are just loaded from scnr for now... if (_tags != null && _buildInfo.Layouts.HasLayout("scnr")) { int scnrCount = 0; IEnumerable <ITag> scnrs = _tags.FindTagsByClass("scnr"); foreach (ITag aScnr in scnrs) { scnrCount++; } ScriptFiles = new IScriptFile[scnrCount]; int i = 0; foreach (ITag aScnr in scnrs) { string tagname = _fileNames.GetTagName(aScnr.Index).TrimStart('\\'); ScriptFiles[i] = new FourthGenScenarioScriptFile(aScnr, tagname, MetaArea, StringIDs, _buildInfo); i++; } return; // ITag scnr = _tags.FindTagByClass("scnr"); // if (scnr != null) // { // ScriptFiles = new IScriptFile[1]; // ScriptFiles[0] = new FourthGenScenarioScriptFile(scnr, ScenarioName, MetaArea, StringIDs, _buildInfo); // return; // } } ScriptFiles = new IScriptFile[0]; }
private void LoadScriptFiles(IReader reader) { ScriptFiles = new IScriptFile[0]; if (_tags != null) { List <ThirdGenScenarioScriptFile> l_scriptfiles = new List <ThirdGenScenarioScriptFile>(); if (_buildInfo.Layouts.HasLayout("hsdt")) { ITag mainScenario = _tags.GetGlobalTag(CharConstant.FromString("scnr")); if (mainScenario == null) { return; } foreach (ITag hs in _tags.FindTagsByGroup("hsdt")) { l_scriptfiles.Add(new ThirdGenScenarioScriptFile(mainScenario, hs, _fileNames.GetTagName(hs.Index), MetaArea, StringIDs, _buildInfo, _expander)); } } else if (_buildInfo.Layouts.HasLayout("scnr")) { foreach (ITag hs in _tags.FindTagsByGroup("scnr")) { l_scriptfiles.Add(new ThirdGenScenarioScriptFile(hs, _fileNames.GetTagName(hs.Index), MetaArea, StringIDs, _buildInfo, _expander)); } } else { return; } ScriptFiles = l_scriptfiles.ToArray(); } }
public FileTestList(IScriptFile file, AccessModifier access, int line, IFileElement parentElement, string @namespace, string name) : base(file, line, parentElement, @namespace, name, access, FileElementType.TestList) { }
public SingleBuildFile(IScriptFile file) { _file = file; return; }
private static int Main(string[] args) { object consoleResourceUserObject = new object(); int retval = 0; Console.WriteLine("StepBro console application. Type 'stepbro --help' to show the help text."); m_commandLineOptions = StepBro.Core.General.CommandLineParser.Parse <CommandLineOptions>(null, args); if (m_commandLineOptions.HasParsingErrors) { return(-1); } try { StepBroMain.Initialize(); if (m_commandLineOptions.Verbose) { var logSinkManager = StepBro.Core.Main.GetService <ILogSinkManager>(); logSinkManager.Add(new ConsoleLogSink()); } if (!String.IsNullOrEmpty(m_commandLineOptions.InputFile)) { if (m_commandLineOptions.Verbose) { Console.WriteLine("Filename: {0}", m_commandLineOptions.InputFile); } IScriptFile file = null; try { file = StepBroMain.LoadScriptFile(consoleResourceUserObject, m_commandLineOptions.InputFile); if (file == null) { retval = -1; Console.WriteLine("Error: Loading script file failed ( " + m_commandLineOptions.InputFile + " )"); } } catch (Exception ex) { retval = -1; Console.WriteLine("Error: Loading script file failed: " + ex.GetType().Name + ", " + ex.Message); } if (file != null) { var parsingSuccess = StepBroMain.ParseFiles(true); if (parsingSuccess) { if (!String.IsNullOrEmpty(m_commandLineOptions.TargetElement)) { IFileElement element = StepBroMain.TryFindFileElement(m_commandLineOptions.TargetElement); if (element != null && element is IFileProcedure) { var procedure = element as IFileProcedure; object[] arguments = m_commandLineOptions?.Arguments.Select( (a) => StepBroMain.ParseExpression(procedure?.ParentFile, a)).ToArray(); try { object result = StepBroMain.ExecuteProcedure(procedure, arguments); if (result != null) { Console.WriteLine("Procedure execution ended. Result: " + result.ToString()); } else { Console.WriteLine("Procedure execution ended."); } } catch (TargetParameterCountException) { retval = -1; Console.WriteLine("Error: The number of arguments does not match the target procedure."); } } else if (element != null && element is ITestList) { throw new NotImplementedException("Handling of test list tarteg not implemented."); } else { retval = -1; if (element == null) { Console.WriteLine($"Error: File element named '{m_commandLineOptions.TargetElement} was not found."); } else { Console.WriteLine($"Error: File element type for '{m_commandLineOptions.TargetElement} cannot be used as an execution target."); } } } } else { Console.WriteLine("Parsing errors!"); foreach (var err in file.Errors.GetList()) { if (!err.JustWarning) { Console.WriteLine($" Line {err.Line}: {err.Message}"); } } retval = -1; } } } else { // If no file should be opened, what then? retval = -1; Console.WriteLine("Error: File could not be opened."); } } catch (Exception ex) { Console.WriteLine($"Error: {ex.GetType().Name}, {ex.Message}"); retval = -1; } finally { StepBroMain.Deinitialize(); } if (m_commandLineOptions.AwaitKeypress) { Console.WriteLine("<press any key to continue>"); while (!Console.KeyAvailable) { System.Threading.Thread.Sleep(25); } Console.ReadKey(); } return(retval); }
public ErrorInfo(IScriptFile script, IErrorData parsingError) : this(ErrorType.ParsingError, parsingError.JustWarning ? "Warning" : "Error", parsingError.Message, script.FilePath, parsingError.Line) { }
public ErrorCollector(IScriptFile file, bool throwOnSyntax = false) { m_file = file; m_throwOnSyntax = throwOnSyntax; }
private void LoadScriptFiles(IReader reader) { // Scripts are just loaded from scnr for now... if (_tags != null && _buildInfo.Layouts.HasLayout("scnr")) { int scnrCount = 0; IEnumerable<ITag> scnrs = _tags.FindTagsByClass("scnr"); foreach (ITag aScnr in scnrs) scnrCount++; ScriptFiles = new IScriptFile[scnrCount]; int i = 0; foreach (ITag aScnr in scnrs) { string tagname = _fileNames.GetTagName(aScnr.Index).TrimStart('\\'); ScriptFiles[i] = new FourthGenScenarioScriptFile(aScnr, tagname, MetaArea, StringIDs, _buildInfo); i++; } return; // ITag scnr = _tags.FindTagByClass("scnr"); // if (scnr != null) // { // ScriptFiles = new IScriptFile[1]; // ScriptFiles[0] = new FourthGenScenarioScriptFile(scnr, ScenarioName, MetaArea, StringIDs, _buildInfo); // return; // } } ScriptFiles = new IScriptFile[0]; }
public SingleBuildFile( IScriptFile file ) { _file = file; return; }