private BaseGenerator SearchGenerator(string target, BaseGenerator parent = null) { BaseGenerator _parent; if (parent == null) { _parent = root; } else { _parent = parent; } for (int i = 0; i < _parent.Generators.Count; i++) { BaseGenerator _gen, generator = (BaseGenerator)_parent.Generators[i]; if (generator.Name == target) { return(generator); } _gen = SearchGenerator(target, generator); if (_gen != null) { return(_gen); } } return(null); }
private bool AddToGenerator(string target, BaseGenerator child, BaseGenerator parent = null) { BaseGenerator _parent; if (parent == null) { _parent = root; } else { _parent = parent; } for (int i = 0; i < _parent.Generators.Count; i++) { BaseGenerator generator = (BaseGenerator)_parent.Generators[i]; if (generator.Name == target) { generator.Add(child); return(true); } if (AddToGenerator(target, child, generator)) { return(true); } } return(false); }
protected virtual void SetMapParameters() { if (RandomizeParameters) { MapSize.x = (int)(UnityEngine.Random.Range(0, 200) / 2) * 2 + 1; MapSize.y = (int)(UnityEngine.Random.Range(0, 200) / 2) * 2 + 1; MinRoomSize.x = (int)(UnityEngine.Random.Range(0, MapSize.x / 5) / 2) * 2 + 1; MinRoomSize.y = (int)(UnityEngine.Random.Range(0, MapSize.y / 5) / 2) * 2 + 1; MaxRoomSize.x = (int)(UnityEngine.Random.Range(MinRoomSize.x + 1, MapSize.x / 2) / 2) * 2 + 1; MaxRoomSize.y = (int)(UnityEngine.Random.Range(MinRoomSize.y + 1, MapSize.x / 2) / 2) * 2 + 1; NumberOfRoomPlacementRetries = UnityEngine.Random.Range(0, 1000); KeepSameDirectionPercentage = UnityEngine.Random.Range(0, 100); PossibilityToAddAnotherConnection = UnityEngine.Random.Range(0, 100); AdditionalConnectionAttempts = UnityEngine.Random.Range(0, 5); PercentageOfTilesToKeep = UnityEngine.Random.Range(0, 100); } Map = new RandomlySizedRegionsGenerator((int)MapSize.x, (int)MapSize.y) { MaxRegionHeight = (int)MaxRoomSize.y, MaxRegionWidth = (int)MaxRoomSize.x, MinRegionHeight = (int)MinRoomSize.y, MinRegionWidth = (int)MinRoomSize.x, NumberOfRoomPlacementRetries = NumberOfRoomPlacementRetries, KeepSameDirectionPercentage = KeepSameDirectionPercentage, AddAnotherConnectionPercentage = PossibilityToAddAnotherConnection, AdditionalConnectionAttempts = AdditionalConnectionAttempts, TilesToKeepPercentage = PercentageOfTilesToKeep }; }
public Tile(int x, int y, BaseGenerator parent) { this.X = x; this.Y = y; this.ParentMap = parent; Type = ETileType.WALL; }
static void Main(string[] args) { BaseGenerator baseGenerator = new BaseGenerator(); baseGenerator.AddGenerator(new CalifornicationGenerator.CalifornicationGenerator()); baseGenerator.AddGenerator(new UriGenerator()); Assembly asm = Assembly.LoadFrom("../../../../PrimetiveGenerators/bin/Debug/PrimetiveGenerators.dll"); var types = asm.GetTypes(); foreach (var type in types) { if (!type.IsAbstract && type.GetInterface("IBaseGenerator") != null) { baseGenerator.AddGenerator((IBaseGenerator)Activator.CreateInstance(type)); } } IGenerator generator = new DTOGenerator(baseGenerator); var book = generator.Generate(typeof(Book)); Console.WriteLine(book.ToString()); Console.ReadKey(); }
/// <summary> /// Runs the generator and saves the content into Portable directory. /// </summary> /// <param name="generator">The generator to use for outputting the text of the cs file</param> /// <param name="fileName">The name of the cs file</param> /// <param name="subNamespace">Adds an additional directory for the namespace</param> void ExecuteGeneratorPortable(BaseGenerator generator, string fileName, string subNamespace = null) { generator.Config = this.config; var text = generator.TransformText(); WriteFile(config.Namespace, subNamespace, fileName, text, this.outputDirPortable); }
/// <summary> /// Runs the generator and saves the content in the test directory. /// </summary> /// <param name="generator">The generator to use for outputting the text of the cs file</param> /// <param name="fileName">The name of the cs file</param> /// <param name="subNamespace">Adds an additional directory for the namespace</param> void ExecuteTestGenerator(BaseGenerator generator, string fileName, string subNamespace = null) { generator.Config = this.config; var text = generator.TransformText(); WriteFile("Marshalling", null, fileName, text, this.testDirectory); }
/// <summary> /// Runs the generator and saves the content in the test directory. /// </summary> /// <param name="generator">The generator to use for outputting the text of the cs file</param> /// <param name="fileName">The name of the cs file</param> /// <param name="subNamespace">Adds an additional directory for the namespace</param> void ExecuteCustomizationTestGenerator(BaseGenerator generator, string fileName, string subNamespace = null) { generator.Config = this.config; var text = generator.TransformText(); WriteFile("Customizations", subNamespace, fileName, text, this.testDirectory); }
private bool DeleteGenerator(string target, BaseGenerator parent = null) { BaseGenerator _parent; if (parent == null) { _parent = root; } else { _parent = parent; } for (int i = 0; i < _parent.Generators.Count; i++) { BaseGenerator generator = (BaseGenerator)_parent.Generators[i]; if (generator.Name == target) { _parent.Generators.RemoveAt(i); return(true); } if (DeleteGenerator(target, generator)) { return(true); } } return(false); }
void SelectGenerator() { switch (generationType) { case GenerationType.NewestFirst: generator = new NewestGenerator(this); break; case GenerationType.Random: generator = new RandomGenerator(this); break; case GenerationType.NewestRandom: generator = new NewestRandomGenerator(this, splitPercent); break; case GenerationType.NewestOldest: generator = new NewestOldestGenerator(this, splitPercent); break; case GenerationType.OldestRandom: generator = new OldestRandomGenerator(this, splitPercent); break; } }
public override void Initialize() { BaseGenerator baseGenerator = new BaseGenerator(); baseGenerator.Generate(this); GenerateMesh(); _needRebuild = false; }
public override T[] GetInstance(Random random) { T[] result = new T[ArrayLenght]; int i = 0; foreach (T t in BaseGenerator.GetInstances(random, ArrayLenght)) { result[i] = t; i++; } return result; }
private bool GenerateDiscreteRandom() { My_Random_Discrete_Base rand = null; if (RadiobuttonDiscretteBernoulli.IsChecked == true) { double p = randomParametersDiscretteRandom.TextBoxParameterp.GetDoubleValue(); rand = new Bernoulli(p); } if (RadiobuttonDiscretteBinomial.IsChecked == true) { long n = randomParametersDiscretteRandom.TextBoxParametern.GetIntegerValue(); double p = randomParametersDiscretteRandom.TextBoxParameterp.GetDoubleValue(); rand = new Binomial(n, p); } if (RadiobuttonDiscretteEquilikely.IsChecked == true) { long a = randomParametersDiscretteRandom.TextBoxParametera.GetIntegerValue(); long b = randomParametersDiscretteRandom.TextBoxParameterb.GetIntegerValue(); rand = new Equilikely(a, b); } if (RadiobuttonDiscretteGeometric.IsChecked == true) { double p = randomParametersDiscretteRandom.TextBoxParameterp.GetDoubleValue(); rand = new Geometric(p); } if (RadiobuttonDiscrettePascal.IsChecked == true) { long n = randomParametersDiscretteRandom.TextBoxParametern.GetIntegerValue(); double p = randomParametersDiscretteRandom.TextBoxParameterp.GetDoubleValue(); rand = new Pascal(n, p); } if (RadiobuttonDiscrettePoisson.IsChecked == true) { double m = randomParametersDiscretteRandom.TextBoxParameterm.GetDoubleValue(); rand = new Poisson(m); } if (RadiobuttonDiscretteSimple.IsChecked == true) { int d = randomParametersDiscretteRandom.TextBoxParameterRange.GetIntegerValue(); rand = new SimpleDiscrete(d); } rand.SizeVector = genSettings.Size; if (timeUnitUserControlClock.TimeInterval.GetTimeUnitInFS() == 0) { MessageBox.Show("Time must be non zero", "Error!", MessageBoxButton.OK); return(false); } rand.TimeStep = timeUnitUserControlDiscretteRandom.TimeInterval; generator = rand; return(true); }
private bool GenerateContinuousRandom() { My_Random_Continuous_Base rand = null; if (RadiobuttonContinuousChisquare.IsChecked == true) { long n = randomParametersContinuousRandom.TextBoxParametern.GetIntegerValue(); rand = new Chisquare(n); } if (RadiobuttonContinuousErlang.IsChecked == true) { long n = randomParametersContinuousRandom.TextBoxParametern.GetIntegerValue(); double b = randomParametersContinuousRandom.TextBoxParameterb.GetDoubleValue(); rand = new Erlang(n, b); } if (RadiobuttonContinuousExponential.IsChecked == true) { double m = randomParametersContinuousRandom.TextBoxParameterm.GetDoubleValue(); rand = new Exponential(m); } if (RadiobuttonContinuousLognormal.IsChecked == true) { double a = randomParametersContinuousRandom.TextBoxParametera.GetDoubleValue(); double b = randomParametersContinuousRandom.TextBoxParameterb.GetDoubleValue(); rand = new Lognormal(a, b); } if (RadiobuttonContinuousNormal.IsChecked == true) { double m = randomParametersContinuousRandom.TextBoxParameterm.GetDoubleValue(); double s = randomParametersContinuousRandom.TextBoxParameters.GetDoubleValue(); rand = new Normal(m, s); } if (RadiobuttonContinuousSimple.IsChecked == true) { double d = randomParametersContinuousRandom.TextBoxParameterRange.GetDoubleValue(); rand = new SimpleContinuous(d); } if (RadiobuttonContinuousStudent.IsChecked == true) { long n = randomParametersContinuousRandom.TextBoxParametern.GetIntegerValue(); rand = new Student(n); } rand.SizeVector = genSettings.Size; if (timeUnitUserControlClock.TimeInterval.GetTimeUnitInFS() == 0) { MessageBox.Show("Time must be non zero", "Error!", MessageBoxButton.OK); return(false); } rand.TimeStep = timeUnitUserControlContinuousRandom.TimeInterval; generator = rand; return(true); }
public override T?GetInstance(Random random) { if (random.Next(nullProbabilityFactor) == 0) { return(default(T)); } else { return(BaseGenerator.GetInstance(random)); } }
//Cài đặt object trước khi sử dụng public virtual void Setup(EItemType type, float velocity, BaseGenerator generator) { timerCounter = 0; this.type = type; this.velocity = velocity; this.generator = generator; generator.rootLevel.mainController.mainPlayer.OnPlayerDieEvent += player_OnLevelOver; this.gameObject.SetActive(true); if (rig != null) rig.velocity = Vector2.left * velocity; }
private bool GenerateConstant() { Constant constant = new Constant(); constant.GenValue = genSettings.PrivilegeValue; constant.IntegerValue = TextBoxConstantInteger.GetIntegerValue(); constant.DoubleValue = TextBoxConstantInteger.GetDoubleValue(); constant.EnumerableValue = ComboboxConstantenumerativeValue.SelectedItem; constant.SizeVector = genSettings.Size; generator = constant; return(true); }
private void add_Click(object sender, EventArgs e) { BaseGenerator generator; using (var form = new Add()) { if (form.ShowDialog() != DialogResult.OK) { return; } if (SearchGenerator(form.GeneratorName) != null) { MessageBox.Show("Генератор с таким названием уже существует!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } switch (form.Type) { case Generators.Types.GeneratorType.BASE: generator = new BaseGenerator(form.GeneratorName, form.Count); break; case Generators.Types.GeneratorType.RAND: generator = new RandomGenerator(form.GeneratorName, form.Count); break; case Generators.Types.GeneratorType.STEP: generator = new GeneratorWithStep(form.GeneratorName, form.Count, form.FirstNumber, form.Step); break; default: return; } } if (this.treeView.SelectedNode == null) { this.root.Add(generator); AddToTree(generator); return; } BaseGenerator parent = SearchGenerator(this.treeView.SelectedNode.Text); parent.Add(generator); this.treeView.BeginUpdate(); AddToTree(generator, this.treeView.SelectedNode); this.treeView.EndUpdate(); }
private string GenArrayWriteCode(Type valueType, BaseGenerator gen) { return(string.Format( " int size = d.Length;\n"+ " o.Write(size);\n"+ " for(int i = 0; i < size; ++i)\n"+ " {{\n"+ " {0};\n"+ " }}\n"+ "", gen.WriteExpression(valueType, "d[i]") )); }
private string GenListReadCode(Type type, Type valueType, BaseGenerator gen) { return(string.Format( " int size = o.ReadInt32();\n"+ " d = new {0}(size);\n"+ " for(int i = 0; i < size; ++i)\n"+ " {{\n"+ " {1} elem;\n"+ " {2};\n"+ " d.Add(elem);\n"+ " }}\n"+ "", TypeName(type), gen.TypeName(valueType), gen.ReadExpression(valueType, "elem") )); }
private bool GenerateCounter() { Counter counter = null; if (RadiobuttonCounterBinary.IsChecked == true) { counter = new BinaryCounter(); } if (RadiobuttonCounterGray.IsChecked == true) { counter = new GrayCounter(); } if (RadiobuttonCounterJohnson.IsChecked == true) { counter = new JohnsonCounter(); } if (RadiobuttonCounterOneHot.IsChecked == true) { counter = new Circular1(); } if (RadiobuttonCounterOneZero.IsChecked == true) { counter = new Circular0(); } counter.IsUpDirection = RadiobuttonCounterUp.IsChecked == true; counter.StepCount = (uint)TextBoxCounterChangeBy.GetIntegerValue(); counter.CurrentValue = DataConvertorUtils.ToBitArray(TextBoxCounterStartValue.GetIntegerValue(), (int)genSettings.Size); if (counter.CurrentValue == null) { MessageBox.Show(string.Format("You have errors, when enter StartValue for {0}. It must be one \'0\' and other \'1\'(Circular0) or one \'1\' and other \'0\'(Circular1)", counter.ToString()), "Error!"); return(false); } if (timeUnitUserControlClock.TimeInterval.GetTimeUnitInFS() == 0) { MessageBox.Show("Time must be non zero", "Error!", MessageBoxButton.OK); return(false); } counter.TimeStep = timeUnitUserControlCounter.TimeInterval; generator = counter; return(true); }
/// <summary> /// Generates the name of the file. /// </summary> /// <param name="entity">The entity.</param> /// <param name="component">The component identifier.</param> /// <returns></returns> public string GenerateFileName(DatabaseEntity entity, GeneratorComponent component) { if (FormBaseTemplateConfiguration.Instance.ValidateForm(false)) { BaseGenerator generator = new BaseGenerator(Settings, entity); switch (component.Id) { case (int)eBaseTemplateComponent.DOMAIN: { return(generator.DomainClassName + _defaultFileExtension); } case (int)eBaseTemplateComponent.DATA_ACCESS: { return(generator.DataAccessClassName + _defaultFileExtension); } case (int)eBaseTemplateComponent.DATA_ACCESS_ASYNC: { return(generator.DataAccessClassName + _defaultFileExtension); } } } return(string.Empty); }
/// <summary> /// Generates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="component">The component identifier.</param> /// <returns></returns> public string Generate(DatabaseEntity entity, GeneratorComponent component) { if (FormBaseTemplateConfiguration.Instance.ValidateForm()) { BaseGenerator generator = new BaseGenerator(Settings, entity); switch (component.Id) { case (int)eBaseTemplateComponent.DOMAIN: { return(generator.GenerateCodeDomain()); } case (int)eBaseTemplateComponent.DATA_ACCESS: { return(generator.GenerateCodeDataAccess()); } case (int)eBaseTemplateComponent.DATA_ACCESS_ASYNC: { return(generator.GenerateCodeDataAccessAsync()); } } } return(string.Empty); }
private void SetCounterGenerator_Executed(object sender, ExecutedRoutedEventArgs e) { try { GeneratorDialog diag = new GeneratorDialog(cursorViewer.Selection.Variable, GeneratorType.Counter); if (diag.ShowDialog() == true) { BaseGenerator generator = diag.Generator; generator.Fill(cursorViewer.Selection.Variable.Signal, cursorViewer.Selection.Start, cursorViewer.Selection.End); cursorViewer.Selection = null; UpdateSignalView(); core.IsModified = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void OpenFile(object sender, EventArgs e) { if (this.openFile.ShowDialog() != DialogResult.OK) { return; } using (var fs = this.openFile.OpenFile()) { this.root = BaseGenerator.Load(fs); this.treeView.BeginUpdate(); this.treeView.Nodes.Clear(); for (int i = 0; i < this.root.Generators.Count; i++) { BaseGenerator generator = (BaseGenerator)this.root.Generators[i]; AddToTree(generator); } this.treeView.EndUpdate(); } }
/// <summary> /// Generates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="component">The component identifier.</param> /// <returns></returns> public string Generate(DatabaseEntity entity, GeneratorComponent component) { if (FormBaseTemplateConfiguration.Instance.ValidateForm()) { BaseGenerator generator = new BaseGenerator(Settings, entity); switch (component.Id) { case (int)eBaseTemplateComponent.SAVE: { return(generator.GenerateScriptSave()); } case (int)eBaseTemplateComponent.GET_BY_ID: { return(generator.GenerateScriptGetById()); } case (int)eBaseTemplateComponent.LIST_ALL: { return(generator.GenerateScriptListAll()); } case (int)eBaseTemplateComponent.DELETE: { return(generator.GenerateScriptDelete()); } } } return(string.Empty); }
/// <summary> /// Generates the name of the file. /// </summary> /// <param name="entity">The entity.</param> /// <param name="component">The component identifier.</param> /// <returns></returns> public string GenerateFileName(DatabaseEntity entity, GeneratorComponent component) { if (FormBaseTemplateConfiguration.Instance.ValidateForm(false)) { BaseGenerator generator = new BaseGenerator(Settings, entity); switch (component.Id) { case (int)eBaseTemplateComponent.SAVE: { return(generator.SaveStoredProcedureName + _defaultFileExtension); } case (int)eBaseTemplateComponent.GET_BY_ID: { return(generator.GetByIdStoredProcedureName + _defaultFileExtension); } case (int)eBaseTemplateComponent.LIST_ALL: { return(generator.ListAllStoredProcedureName + _defaultFileExtension); } case (int)eBaseTemplateComponent.DELETE: { return(generator.DeleteStoredProcedureName + _defaultFileExtension); } } } return(string.Empty); }
private void AddToTree(BaseGenerator generator, TreeNode node = null) { TreeNode treeNode; if (node == null) { treeNode = treeView.Nodes.Add(generator.Name); } else { treeNode = node.Nodes.Add(generator.Name); } if (generator.Generators.Count != 0) { foreach (BaseGenerator child in generator.Generators) { this.AddToTree(child, treeNode); } } }
private string GenArrayReadCode(Type valueType, BaseGenerator gen) { string valueTypeName = gen.TypeName(valueType); string str = ""; if (valueTypeName.Contains("[]")) { valueTypeName = valueTypeName.Substring(0, valueTypeName.IndexOf('[')); str = "[]"; } return(string.Format( " int size = o.ReadInt32();\n"+ " d = new {0}[size]{2};\n"+ " for(int i = 0; i < size; ++i)\n"+ " {{\n"+ " {1};\n"+ " }}\n"+ "", valueTypeName, gen.ReadExpression(valueType, "d[i]"), str )); }
/// <summary> /// Generate DDL for current dialog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GenerateDdl_OnExecuted(object sender, ExecutedRoutedEventArgs e) { DatabaseModelDesigner designer; if (TryGetSelectedDesigner(out designer)) { var ddlGenerator = BaseGenerator.CreateGenerator(designer.ViewModel.TableViewModels.Select(t => t.Model), designer.ViewModel.ConnectionInfoViewModels.Select(t => t.RelationshipModel), SessionProvider.Instance.ConnectionType, SessionProvider.Instance.Username); string sql = ddlGenerator.GenerateDdl(); var panel = new QueryPanel { Text = sql }; panel.QueryResultReady += PanelOnQueryResultReady; panel.BuildNewQueryPanel(this, $"{designer.ViewModel.DiagramTitle}_DDL"); MainDocumentPane.Children.Add(panel.Anchorable); int indexOf = MainDocumentPane.Children.IndexOf(panel.Anchorable); MainDocumentPane.SelectedContentIndex = indexOf; } }
/// <summary> /// Парсит конструкцию SWITCH. /// </summary> private static void ParseSwitch(TokenList body) { BaseGenerator generator = CodeManager.GetGenerator(parseMode); for (int index = 0; index < body.Count; index++) { TokenList nextTokens = body.GetRange(index); Token currentToken = body[index]; Token nextToken = body.Get(index + 1); if (currentToken.TypeIs(TokenType.NextLine)) { lineIndex++; continue; } // случай <expression>: if (currentToken.TypeIs(KeywordType.Case) && body[index + 2].TypeIs(TokenType.Colon)) { TokenList caseBody = GetCaseBody(nextTokens, out index, index); generator.AddCaseConstruction(nextToken); Parse(caseBody, out _); } // по_умолчанию: else if (currentToken.TypeIs(KeywordType.Default) && body[index + 1].TypeIs(TokenType.Colon)) { TokenList defaultBody = GetCaseBody(nextTokens, out index, index); generator.AddDefaultCaseConstruction(); Parse(defaultBody, out _); } // завершить; else if (currentToken.TypeIs(KeywordType.Break)) { generator.AddBreak(); } } }