private void AddCreateUniqueConstraintBatch(Index index, QuoteType quoteType) { List <ColumnWithSortOrder> columns = new List <ColumnWithSortOrder>(); foreach (var member in index.Members) { Column column = index.Parent.Columns.FirstOrDefault(c => c.Name == member.Column); columns.Add( ScriptFactory.ColumnWithSortOrder( ScriptFactory.ColumnReferenceExpression( ScriptFactory.MultiPartIdentifier( ScriptFactory.Identifier(member.Column, quoteType)), ColumnType.Regular), SortOrder.Ascending)); } UniqueConstraintDefinition uniqueConstraint = ScriptFactory.UniqueConstraintDefinition( ScriptFactory.Identifier(index.Name, quoteType), false, index.IsClustered, null, null, null, columns ); AddBatch(ScriptFactory.AlterTableAddTableElement( ScriptFactory.TableDefinition( null, null, new List <ConstraintDefinition> { uniqueConstraint }, null), Generator.GenerateSchemaObjectName(index.Parent, quoteType))); }
public string Generate(ScriptFactory factory) { var tw = new StringWriter(); Generate(factory, tw); return(tw.ToString()); }
public void Generate(ScriptFactory factory, TextWriter tw) { foreach (var unit in _unitQueue) { unit.Generate(factory, tw); } }
public void AddCreateForeignKeyBatch(ForeignKey key, QuoteType quoteType = QuoteType.NotQuoted) { var first = key.ForeignKeyColumns.FirstOrDefault(); var pkTable = key.Parent.Parent.Tables.FirstOrDefault(t => t.Name == key.PkTable); ForeignKeyConstraintDefinition uniqueConstraint = ScriptFactory.ForeignKeyConstraintDefinition( ScriptFactory.Identifier(key.Name, quoteType), false, Generator.GenerateSchemaObjectName(pkTable, quoteType), DeleteUpdateAction.NotSpecified, DeleteUpdateAction.NotSpecified, key.ForeignKeyColumns.Select(fkc => ScriptFactory.Identifier(fkc.FkColumn, quoteType)), key.ForeignKeyColumns.Select(fkc => ScriptFactory.Identifier(fkc.PkColumn, quoteType)) ); AddBatch(ScriptFactory.AlterTableAddTableElement( ScriptFactory.TableDefinition( null, null, new List <ConstraintDefinition> { uniqueConstraint }, null), Generator.GenerateSchemaObjectName(key.Parent, quoteType))); }
public ICommand GetCommand() { var input = connectedPlayer.ReceiveInput(); switch (input.ToLower()) { //TODO This needs to use the command SwitchState to switch to room state. case "enter": IRoom startRoom = (IRoom)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.InitialRoom, null); connectedPlayer.Move(startRoom); break; case "world": var game = Director.Server.Game as Game.DefaultGame; if (game != null) { connectedPlayer.SendMessage("Save Success!"); return(new SaveWorldFileCommand()); } break; case "quit": connectedPlayer.Disconnect(); break; } // We Don't have any commands here yet... but we will! (EnterCommand, JoinCommand, SaveCommand, OptionsCommand, QuitCommand etc) return(new InvalidCommand()); }
public LazyLoadScript(ScriptFactory scriptFactory, string scriptString, ScriptContext scriptContext) { m_scriptFactory = scriptFactory; m_scriptString = scriptString; m_scriptContext = scriptContext; m_worldModel = scriptFactory.WorldModel; }
public virtual IEnumerable <T> ApplyFilter <T>([NotNull] IEnumerable <T> source, [NotNull] string filterExpression) { Assert.ArgumentNotNull(source, "source"); Assert.ArgumentNotNull(filterExpression, "filterExpression"); SpeakDateTimeExtractor extractor = new SpeakDateTimeExtractor(); filterExpression = extractor.Extract(filterExpression); SpeakFreeTextSearchExtractor <T> freeTextSearchExtractor = new SpeakFreeTextSearchExtractor <T>(); filterExpression = freeTextSearchExtractor.Extract(filterExpression); SpeakExpressionLocalizer localizer = new SpeakExpressionLocalizer(); filterExpression = localizer.Update(filterExpression); IEnumerable <string> references = new[] { Assembly.GetAssembly(typeof(Order)).Location, Assembly.GetAssembly(typeof(Queryable)).Location }; string code = string.Format(CodeTemplate, typeof(IQueryable <T>).IsAssignableFrom(source.GetType()) ? "System.Linq.IQueryable" : "System.Collections.Generic.IEnumerable", typeof(T).FullName, filterExpression); Script script = ScriptFactory.Compile(filterExpression, references, code, "C#"); Assert.IsTrue(script.IsValid, "Unable to apply the filter. Expression compilation failed."); return(script.InvokeDefaultMethod <IEnumerable <T> >(source)); }
public static IdentityOptions CreateIdentityOptions(Column column) { return(ScriptFactory.IdentityOptions( false, ScriptFactory.IntegerLiteral(column.IdentityIncrement.ToString()), ScriptFactory.IntegerLiteral(column.IdentitySeed.ToString()))); }
public ScriptFactory addFactory(Type classType, LAYOUT_TYPE type) { ScriptFactory factory = createFactory(classType, type); mFactoryList.Add(factory.getType(), factory); return(factory); }
private void ReadScript(String language) { var line = ""; var builder = new StringBuilder(); while (true) { line = Reader.ReadLine(); if (line == "endscript") { break; } builder.AppendLine(line); } if (ScriptReceived != null) { try { var script = ScriptFactory.Create(language, builder.ToString()); ScriptReceived(this, new ScriptEventArgs(this, script)); } catch (Exception ex) { SendMessage("Compile Error: " + ex.Message); } } }
/// <summary> /// Creates a new <seealso cref="ExecutableScript" /> from a dynamic resource. Dynamic means that the source /// is an expression which will be evaluated during execution. /// </summary> /// <param name="language"> the language of the script </param> /// <param name="resourceExpression"> the expression which evaluates to the resource path </param> /// <param name="scriptFactory"> the script factory used to create the script </param> /// <returns> the newly created script </returns> /// <exception cref="NotValidException"> if language is null or empty or resourceExpression is null </exception> public static ExecutableScript GetScriptFromResourceExpression(string language, IExpression resourceExpression, ScriptFactory scriptFactory) { EnsureUtil.EnsureNotEmpty(typeof(NotValidException), "Script language", language); EnsureUtil.EnsureNotNull(typeof(NotValidException), "Script resource expression", resourceExpression); return(scriptFactory.CreateScriptFromResource(language, resourceExpression)); }
public LazyLoadScript(ScriptFactory scriptFactory, string scriptString, ScriptContext scriptContext) { m_scriptFactory = scriptFactory; m_scriptString = scriptString; m_scriptContext = scriptContext; m_worldModel = scriptFactory.WorldModel; }
public static ColumnDefinition Column(string columnName, DataTypeReference dataType, bool nullable = false, QuoteType quoteType = QuoteType.NotQuoted) { return(Column(ScriptFactory.Identifier(columnName, quoteType), dataType, nullable)); }
public IScript Create(string script, ScriptContext scriptContext) { string callback = Utility.GetScript(script.Substring(Keyword.Length).Trim()); IScript callbackScript = ScriptFactory.CreateScript(callback); return(new OnReadyScript(scriptContext, ScriptFactory, callbackScript)); }
public IScript Create(string script, Element proc) { string callback = Utility.GetScript(script.Substring(8).Trim()); IScript callbackScript = ScriptFactory.CreateScript(callback); return(new OnReadyScript(ScriptFactory, callbackScript)); }
private void InitializationDuJoueur() { Human = ScriptFactory.GetGameObjectHuman(); HumanPropertie = ScriptFactory.GetScriptAttachedOnGO <ScriptPnjProperties>(Human); HumanDeplacement = ScriptFactory.GetScriptAttachedOnGO <ScriptDeplacementSupervise>(Human); HumanDeplacement.CanMove = true; }
public void AddDefaultConstraintBatches(IEnumerable <Table> tables, QuoteType quoteType = QuoteType.NotQuoted) { var definitions = new List <TableDefaultConstraint>(); AddBatch(Generator.GeneratePrintStatement($"========== Creating Default Constraints ==========")); foreach (Table table in tables) { foreach (var column in table.Columns) { if (!string.IsNullOrEmpty(column.DefaultName)) { definitions.Add(new TableDefaultConstraint { Constraint = ScriptFactory.DefaultConstraintDefinition( ScriptFactory.Identifier(column.Name, quoteType), ScriptFactory.Identifier(column.DefaultName, quoteType), false, ScriptFactory.ParenthesisExpression(ScriptFactory.IntegerLiteral(column.DefaultValue))), Table = table }); } } } AddDefaultConstraints(definitions, quoteType); }
public IEnumerable <ColumnDefinition> GenerateColumnDefinitions(Table table, QuoteType quoteType = QuoteType.NotQuoted) { List <ColumnDefinition> columns = new List <ColumnDefinition>(); foreach (var column in table.Columns) { SqlDataType sqlDataType = SqlDataType.Parse(column.DataType); DataTypeReference dataType = GenerateDataTypeReference(sqlDataType); if (column.IsIdentity) { ColumnDefinition columnDef = ScriptFactory.IdentityColumn(column.Name, dataType, CreateIdentityOptions(column), quoteType); columns.Add(columnDef); } else if (column.RowGuid) { if (!string.IsNullOrEmpty(column.DefaultValue)) { ColumnDefinition rowGuidCol = ScriptFactory.ColumnDefinition(column.Name, column.DefaultValue, column.DefaultName, dataType, column.AllowNulls, column.RowGuid, quoteType); columns.Add(rowGuidCol); } } else { columns.Add(ScriptFactory.ColumnDefinition(column.Name, dataType, column.AllowNulls, quoteType)); } } return(columns); }
public SchemaObjectName GenerateSchemaAndIdentifierName(string schemaName, string identifierName, QuoteType quoteType = QuoteType.NotQuoted) { SchemaObjectName objectName = new SchemaObjectName(); objectName.Identifiers.AddRange(ScriptFactory.Identifier(schemaName, quoteType), ScriptFactory.Identifier(identifierName, quoteType)); return(objectName); }
public SchemaObjectName GenerateStoredProcedureName(string procedureName, Table table, QuoteType quoteType = QuoteType.NotQuoted) { SchemaObjectName objectName = new SchemaObjectName(); objectName.Identifiers.AddRange(ScriptFactory.Identifier(table.Schema, quoteType), ScriptFactory.Identifier(procedureName, quoteType)); return(objectName); }
public CreateProcedureStatement GenerateUpdateStoredProcedure(Table table, QuoteType quoteType = QuoteType.NotQuoted) { var pkColumn = table.Indexes.SingleOrDefault(x => x.IsPrimary).Name; var columnNames = GetColumnNamesWithoutPrimaryKey(table, pkColumn); string storedProcedureName = string.Concat("Update", table.Name); var parameters = CreateProcedureParameters(table, true); var setClauses = new List <SetClause>(); string primaryKeyName = ""; foreach (var column in table.Columns) { if (column.IsPrimaryKey()) { primaryKeyName = column.Name; continue; } setClauses.Add(ScriptFactory.EqualsAssignmentSetClause( ScriptFactory.ColumnReference(column.Name, quoteType), ScriptFactory.IdentifierLiteral( CreateProcedureParameterVariableName(column), QuoteType.NotQuoted))); } StatementList statements = ScriptFactory.List( ScriptFactory.Update(ScriptFactory.UpdateSpecification(null, ScriptFactory.Where( ScriptFactory.BooleanEqualsComparison(ScriptFactory.IdentifierLiteral(primaryKeyName, quoteType), ScriptFactory.VariableReference(primaryKeyName))), CreateNamedTableReference(table, quoteType), null, null, null, setClauses))); return(ScriptFactory.CreateProcedure(false, ScriptFactory.ProcedureReference( GenerateStoredProcedureName(storedProcedureName, table, quoteType)), ScriptFactory.List( ScriptFactory.BeginEndBlock(statements)), null, null, parameters)); }
public CreateProcedureStatement GenerateFindStoredProcedure(Table table, QuoteType quoteType = QuoteType.NotQuoted) { Database database = table.Parent; var pkColumn = GetPrimaryKeyColumnName(table); var columnNames = GetColumnNamesWithoutPrimaryKey(table, pkColumn); var pkDataType = table.Columns.Single(x => x.Name == pkColumn).DataType.ToSqlDataTypeOption(); string storedProcedureName = string.Concat("Find", table.Name); var parameters = new List <ProcedureParameter>(); parameters.Add(ScriptFactory.ProcedureParameter( ScriptFactory.Identifier(MakeVariableName(pkColumn)), false, ScriptFactory.SqlDataType(pkDataType))); StatementList statements = ScriptFactory.List( ScriptFactory.Select( default(Identifier), ScriptFactory.Query( ScriptFactory.From(ScriptFactory.NamedTableReference(GenerateSchemaObjectName(table, quoteType))), ScriptFactory.Where(ScriptFactory.BooleanEqualsComparison(ScriptFactory.IdentifierLiteral(pkColumn, quoteType), ScriptFactory.VariableReference(pkColumn))), ScriptFactory.TopRowFilter(false, false, ScriptFactory.IntegerLiteral("1")), ScriptFactory.ElementList(columnNames.Select(x => ScriptFactory.SelectScalarExpression(x, quoteType))) ) ) ); return(ScriptFactory.CreateProcedure(false, ScriptFactory.ProcedureReference( GenerateStoredProcedureName(storedProcedureName, table, quoteType)), ScriptFactory.List( ScriptFactory.BeginEndBlock(statements)), null, null, parameters)); }
public SchemaObjectName GenerateSchemaObjectName(Column column, QuoteType quoteType = QuoteType.NotQuoted) { var retVal = new SchemaObjectName(); retVal.Identifiers.Add(ScriptFactory.Identifier(column.Parent.Name, quoteType)); retVal.Identifiers.Add(ScriptFactory.Identifier(column.Name, quoteType)); return(retVal); }
private void realmsBtnAddRealm_Click(object sender, EventArgs e) { //We need to make sure we never have a duplicate name. int value = 1; string newName = "New Realm" + value; //New Realm1 //Once we have a Realm with a unique name, this will become true bool validName = false; //Loop until we have a valid Realm name that is not duplicated. while (!validName) { //In the event this is the first Realm. //Prevents infinit loop //Since we have zero Realms that exists, of course the first one will be valid. if (Editor.Game.World.GetRealms().Length == 0) { validName = true; } //Loop through each Realm and check it's name foreach (var r in Editor.Game.World.GetRealms()) { //We found a match, so it's considered a duplicate. if (r.Name == newName) { //Increase our number value++; //Update our name newName = "New Realm" + value; } else { //Otherwise we are good to go validName = true; } } } //Grab a new instance of the default IRealm specified in the engine settings IRealm realm = (IRealm)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.RealmScript, null); if (realm == null) { //In the event the scripts didn't compile or are missing MessageBox.Show("There are currently no Realm scripts that exist. Please create a script that inherits from MudDesigner.Engine.Environments.BaseRealm", "Mud Designer Editor : Realms", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Set the name we built realm.Name = newName; //Add it to the World Editor.Game.World.AddRealm(realm); //Add it and select it on our Realm List Collection realmsLstExistingRealms.Items.Add(realm.Name); realmsLstExistingRealms.SelectedItem = realm.Name; }
public void AddCreateTableBatch(Table table, QuoteType quoteType = QuoteType.NotQuoted) { AddBatch(Generator.GeneratePrintStatement($"Creating table [{table.Schema}].[{table.Name}]")); AddBatch( ScriptFactory.CreateTable(false, false, false, Generator.GenerateSchemaObjectName(table, quoteType), ScriptFactory.TableDefinition(null, Generator.GenerateColumnDefinitions(table, quoteType)))); }
public IScript Create(string script, Element proc) { // Get script after "firsttime" keyword script = script.Substring(9).Trim(); string firstTime = Utility.GetScript(script); IScript firstTimeScript = ScriptFactory.CreateScript(firstTime); return(new FirstTimeScript(firstTimeScript)); }
public IScript Create(string script, ScriptContext scriptContext) { string afterExpr; string param = Utility.GetParameter(script, out afterExpr); string loop = Utility.GetScript(afterExpr); IScript loopScript = ScriptFactory.CreateScript(loop); return(new WhileScript(scriptContext, ScriptFactory, new Expression <bool>(param, scriptContext), loopScript)); }
public IScript Create(string script, ScriptContext scriptContext) { // Get script after "firsttime" keyword script = script.Substring(9).Trim(); string firstTime = Utility.GetScript(script); IScript firstTimeScript = ScriptFactory.CreateScript(firstTime); return(new FirstTimeScript(WorldModel, ScriptFactory, firstTimeScript)); }
public IScript Create(string script, Element proc) { string afterExpr; string param = Utility.GetParameter(script, out afterExpr); string loop = Utility.GetScript(afterExpr); IScript loopScript = ScriptFactory.CreateScript(loop); return(new WhileScript(new Expression(param, GameLoader), loopScript)); }
public IScript Create(string script, Element proc) { string afterExpr; string expr = Utility.GetParameter(script, out afterExpr); string then = Utility.GetScript(afterExpr); IScript thenScript = ScriptFactory.CreateScript(then, proc); return(new IfScript(new Expression(expr, GameLoader), thenScript)); }
public LayoutScript createScript(LAYOUT_TYPE type, string name, GameLayout layout) { ScriptFactory factory = mScriptFactoryManager.getFactory(type); if (factory != null) { return(factory.createScript(layout, name)); } return(null); }
public static void Menu() { var menu = new StringBuilder("1. Copy database \n2. Copy excel\n3. Copy xml script\n4. Report\n5. PhoneBook"); System.Console.WriteLine(menu); var input = System.Console.ReadLine(); int option; if (!int.TryParse(input, out option)) { System.Console.WriteLine("Invalid option"); } else { switch (option) { case (int)Options.DB: Copier.Begin(); break; case (int)Options.EXCEL: var excels = new List<ExcelCopier> { //new WorkbookCopier(@"K:\SQL_DATA\BD\Estimation Pipeline 2014 06 25.xlsm"), //new QualificationCopier(@"C:\Users\jing\Desktop\Doc\BD database verticals 2015 02 24.rock.xlsx"), new SmallQuoteCopier(@"C:\dev\BDWorkbook\Small-Medium quote costing workbook_v8.37.xlsm"), //new SpecCopier(@"K:\SQL_DATA\BD\estimation\Small-Medium quote costing workbook_v8.30.test.xlsm") }; foreach (var excel in excels) { excel.Begin(); } break; case (int)Options.SCRIPT: var file = AppDomain.CurrentDomain.BaseDirectory + "script.xml"; var template = new ScriptXmlTemplate(); var factory = new ScriptFactory(); var qualifications = new QualificationCreator(); var cleaningQuestions = new CleaningQuestionCreator(); foreach (var script in factory) { template.Scripts.Add(script.Create()); } foreach (var creator in qualifications.Creators) { template.Scripts.Add(creator.Create()); } foreach (var creator in cleaningQuestions.Creators) { template.Scripts.Add(creator.Create()); } SerializeHelper.Create(file, template); System.Console.WriteLine("File is saved to " + file); System.Console.ReadLine(); break; case (int)Options.Report: using (var context = new SiteResourceEntities()) { var helper = new ReportHelper(new UnitOfWork(context)); foreach (var report in context.WeeklyReports) { context.Entry(report).State = EntityState.Deleted; } helper.GenerateWeeklyHistory(DateTime.Today); helper.GenerateWeeklyHistory(DateTime.Today.AddDays(-7)); helper.GenerateWeeklyHistory(DateTime.Today.AddDays(-14)); foreach (var report in context.FullReports) { context.Entry(report).State = EntityState.Deleted; } helper.GenerateFullHistory(DateTime.Today); helper.GenerateFullHistory(DateTime.Today.AddDays(-7)); helper.GenerateFullHistory(DateTime.Today.AddDays(-14)); context.SaveChanges(); } break; case (int)Options.PhoneBook: System.Console.WriteLine("Please enter the Excel path"); var filePath = System.Console.ReadLine(); if (!System.IO.File.Exists(filePath)) { System.Console.WriteLine("Error: File does not exists at {0}", filePath); System.Console.ReadLine(); } else { new PhoneBookCopier(filePath).Begin(); } break; case (int)Options.Test: new SpecCopier(@"K:\SQL_DATA\BD\estimation\Small-Medium quote costing workbook_v8.30.test.xlsm").Begin(); break; default: System.Console.WriteLine("Invalid option"); System.Console.ReadLine(); break; } } }