/// <summary> /// Generate sample data button click handler /// </summary> protected void btnGenerate_Click(object sender, EventArgs e) { if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.WebAnalytics", "ManageData")) { RedirectToAccessDenied("CMS.WebAnalytics", "ManageData"); } // Check whether range is defined if ((ucSampleFrom.SelectedDateTime == DateTimeHelper.ZERO_TIME) || (ucSampleTo.SelectedDateTime == DateTimeHelper.ZERO_TIME)) { ShowError(GetString("analyt.settings.invalidrangegenerate")); return; } // Try start sample data generator if (SampleDataGenerator.GenerateSampleData(ucSampleFrom.SelectedDateTime, ucSampleTo.SelectedDateTime, SiteContext.CurrentSiteID, drpGenerateObjects.SelectedValue)) { EnableControls(false); ViewState["GeneratorStarted"] = true; } // Start refresh timer timeRefresh.Enabled = true; // Display info label and loading image ReloadInfoPanel(); }
public override TemplateOutput Generate() { TemplateOutput retVal = new TemplateOutput(); try { var entityTypes = ProcessModel.MetadataSourceModel.GetEntityTypesByRegEx(excludeRegExPattern: RegexExclude, includeRegExPattern: RegexInclude); foreach (var entity in entityTypes) { string entityName = Inflector.Pascalize(entity.ClrType.Name); string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity, fileName: Consts.OUT_sampleData); outputfile = outputfile.Replace("[tablename]", entityName).Replace("[tablepluralname]", Inflector.Pluralize(entityName)); string filepath = outputfile; var generator = new SampleDataGenerator(inflector: Inflector); int sampleDataCount = 0; if (int.TryParse(SampleDataCount, out int sampleCount)) { sampleDataCount = sampleCount; } else { ProcessModel.Errors.Add("Unable to parse the SampleDataCount from the blueprint"); sampleCount = 3; // Use 3 if we can parse the value } int sampleDataDigits = 2; if (int.TryParse(SampleDataDigits, out int sampleDigits)) { Debug.WriteLine($"Successfully parsed \"{SampleDataDigits}\" to {sampleDigits}"); sampleDataCount = sampleDigits; } else { Debug.WriteLine($"Failed trying to parse \"{SampleDataDigits}\" to a number"); ProcessModel.Errors.Add("Unable to parse the SampleDataDigits from the blueprint"); sampleCount = 2; // Use 2 if we can't parse the value } string generatedCode = generator.GenerateSampleData( entity: entity, sqliteModelDataNamespace: SqliteModelDataNamespace, prependSchemaNameIndicator: PrependSchemaNameIndicator, sampleDataCount: sampleDataCount, sampleDataDigits: sampleDataDigits ); retVal.Files.Add(new OutputFile() { Content = generatedCode, Name = filepath }); } } catch (Exception ex) { base.AddError(ref retVal, ex, Enums.LogLevel.Error); } AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error); return(retVal); }