public void DoGenerateViewModel(DTE2 Dte, ITextTemplating textTemplating, SelectedItem DestinationSelectedItem, string T4TempatePath, ModelView modelView) { this.GenerateText = ""; this.GenerateError = ""; GeneratedModelView = new ModelViewSerializable(); modelView.ModelViewAssingTo(GeneratedModelView); ITextTemplatingSessionHost textTemplatingSessionHost = (ITextTemplatingSessionHost)textTemplating; textTemplatingSessionHost.Session = textTemplatingSessionHost.CreateSession(); TPCallback tpCallback = new TPCallback(); textTemplatingSessionHost.Session["Model"] = GeneratedModelView; if (string.IsNullOrEmpty(GenText)) { this.GenerateText = textTemplating.ProcessTemplate(T4TempatePath, File.ReadAllText(T4TempatePath), tpCallback); } else { this.GenerateText = textTemplating.ProcessTemplate(T4TempatePath, GenText, tpCallback); } FileExtension = tpCallback.FileExtension; if (tpCallback.ProcessingErrors != null) { foreach (TPError tpError in tpCallback.ProcessingErrors) { this.GenerateError = tpError.ToString() + "\n"; } } IsReady.DoNotify(this, string.IsNullOrEmpty(this.GenerateError)); }
public void DoGenerateDbContext(DTE2 Dte, ITextTemplating textTemplating, string templatePath, string DestinationNameSpace, string DestinationClassName) { this.GenerateText = ""; this.GenerateError = ""; OnPropertyChanged("GenerateText"); OnPropertyChanged("GenerateError"); ITextTemplatingSessionHost textTemplatingSessionHost = (ITextTemplatingSessionHost)textTemplating; textTemplatingSessionHost.Session = textTemplatingSessionHost.CreateSession(); TPCallback tpCallback = new TPCallback(); textTemplatingSessionHost.Session["DestinationNameSpace"] = DestinationNameSpace; textTemplatingSessionHost.Session["DestinationClassName"] = DestinationClassName; if (string.IsNullOrEmpty(GenText)) { this.GenerateText = textTemplating.ProcessTemplate(templatePath, File.ReadAllText(templatePath), tpCallback); } else { this.GenerateText = textTemplating.ProcessTemplate(templatePath, GenText, tpCallback); } FileExtension = tpCallback.FileExtension; if (tpCallback.ProcessingErrors != null) { foreach (TPError tpError in tpCallback.ProcessingErrors) { this.GenerateError = tpError.ToString() + "\n"; } } OnPropertyChanged("GenerateText"); OnPropertyChanged("GenerateError"); IsReady.DoNotify(this, string.IsNullOrEmpty(this.GenerateError)); }
public string GeneratePrimKeyStatement() { ITextTemplatingSessionHost textTemplatingSessionHost = (ITextTemplatingSessionHost)textTemplating; textTemplatingSessionHost.Session = textTemplatingSessionHost.CreateSession(); TPCallback tpCallback = new TPCallback(); List <string> primKeyProperties = new List <string>(); foreach (FluentAPIExtendedProperty itm in this.PrimaryKeyProperties) { primKeyProperties.Add(itm.PropName); } string tempatePath = Path.Combine(TemplateFolder, SelectedTemplate); textTemplatingSessionHost.Session["PrimKeyProperties"] = primKeyProperties; string result = textTemplating.ProcessTemplate(tempatePath, T4TempateText, tpCallback); if (tpCallback.ProcessingErrors != null) { if (tpCallback.ProcessingErrors.Count > 0) { string GenerateError = "Error: "; foreach (TPError tpError in tpCallback.ProcessingErrors) { GenerateError = GenerateError + tpError.ToString() + "\n"; } MessageBox.Show(GenerateError, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } } return(result); }
public static GeneratorBatchStep DoGenerateViewModel(DTE2 Dte, ITextTemplating textTemplating, string T4TempatePath, DbContextSerializable SerializableDbContext, ModelViewSerializable model, string defaultProjectNameSpace = null) { GeneratorBatchStep result = new GeneratorBatchStep() { GenerateText = "", GenerateError = "", FileExtension = "", T4TempatePath = T4TempatePath, }; if ((model == null) || (SerializableDbContext == null)) { result.GenerateError = "Model and/or Context is not defined"; return(result); } ITextTemplatingSessionHost textTemplatingSessionHost = (ITextTemplatingSessionHost)textTemplating; textTemplatingSessionHost.Session = textTemplatingSessionHost.CreateSession(); TPCallback tpCallback = new TPCallback(); textTemplatingSessionHost.Session["Model"] = model; textTemplatingSessionHost.Session["Context"] = SerializableDbContext; textTemplatingSessionHost.Session["DefaultProjectNameSpace"] = string.IsNullOrEmpty(defaultProjectNameSpace) ? "" : defaultProjectNameSpace; result.GenerateText = textTemplating.ProcessTemplate(T4TempatePath, File.ReadAllText(result.T4TempatePath), tpCallback); result.FileExtension = tpCallback.FileExtension; if (tpCallback.ProcessingErrors != null) { foreach (TPError tpError in tpCallback.ProcessingErrors) { result.GenerateError += tpError.ToString() + "\n"; } } return(result); }
public string GenerateForeignKeyStatement() { if ((EntityNonScalarPropertiesIndex < 0) || (EntityNonScalarProperties.Count <= EntityNonScalarPropertiesIndex)) { return(null); } if ((PrincipalNonScalarPropertiesIndex < 0) || (PrincipalNonScalarProperties.Count <= PrincipalNonScalarPropertiesIndex)) { return(null); } if ((ForeignKeyTypesIndex < 0) || (ForeignKeyTypes.Count <= ForeignKeyTypesIndex)) { return(null); } ITextTemplatingSessionHost textTemplatingSessionHost = (ITextTemplatingSessionHost)textTemplating; textTemplatingSessionHost.Session = textTemplatingSessionHost.CreateSession(); TPCallback tpCallback = new TPCallback(); List <string> foreignKeyProperties = new List <string>(); foreach (FluentAPIExtendedProperty itm in this.ForeignKeyProperties) { foreignKeyProperties.Add(itm.PropName); } string tempatePath = ""; //Path.Combine(TemplateFolder, SelectedTemplate); textTemplatingSessionHost.Session["MasterClassFullName"] = masterCodeClassFullName; textTemplatingSessionHost.Session["IsRequired"] = (ForeignKeyTypes[ForeignKeyTypesIndex] == NavigationTypeEnum.OneToMany) || (ForeignKeyTypes[ForeignKeyTypesIndex] == NavigationTypeEnum.OneToOne); textTemplatingSessionHost.Session["WillCascadeOnDelete"] = IsCascadeOnDelete; textTemplatingSessionHost.Session["NavigationName"] = EntityNonScalarProperties[EntityNonScalarPropertiesIndex]; textTemplatingSessionHost.Session["InverseNavigationName"] = PrincipalNonScalarProperties[PrincipalNonScalarPropertiesIndex].PropName; textTemplatingSessionHost.Session["ForeignKeyProperties"] = foreignKeyProperties; string result = textTemplating.ProcessTemplate(tempatePath, T4TempateText, tpCallback); if (tpCallback.ProcessingErrors != null) { if (tpCallback.ProcessingErrors.Count > 0) { string GenerateError = "Error: "; foreach (TPError tpError in tpCallback.ProcessingErrors) { GenerateError = GenerateError + tpError.ToString() + "\n"; } MessageBox.Show(GenerateError, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } } return(result); }
public void DoGenerateFeature(DTE2 Dte, ITextTemplating textTemplating, string T4TempatePath, DbContextSerializable SerializableDbContext, FeatureContextSerializable SerializableFeatureContext, FeatureSerializable feature, AllowedFileTypesSerializable AllowedFileTypes, string defaultProjectNameSpace = null) { this.GenerateText = ""; this.GenerateError = ""; IsReady.DoNotify(this, false); if ((feature == null) || (SerializableDbContext == null) || (SerializableFeatureContext == null)) { return; } GeneratedFeature = feature; ITextTemplatingSessionHost textTemplatingSessionHost = (ITextTemplatingSessionHost)textTemplating; textTemplatingSessionHost.Session = textTemplatingSessionHost.CreateSession(); TPCallback tpCallback = new TPCallback(); textTemplatingSessionHost.Session["AllowedFileTypes"] = AllowedFileTypes; textTemplatingSessionHost.Session["Feature"] = GeneratedFeature; textTemplatingSessionHost.Session["FeatureContext"] = SerializableFeatureContext; textTemplatingSessionHost.Session["Context"] = SerializableDbContext; textTemplatingSessionHost.Session["DefaultProjectNameSpace"] = string.IsNullOrEmpty(defaultProjectNameSpace) ? "" : defaultProjectNameSpace; if (string.IsNullOrEmpty(GenText)) { this.GenerateText = textTemplating.ProcessTemplate(T4TempatePath, File.ReadAllText(T4TempatePath), tpCallback); } else { this.GenerateText = textTemplating.ProcessTemplate(T4TempatePath, GenText, tpCallback); } FileExtension = tpCallback.FileExtension; if (tpCallback.ProcessingErrors != null) { foreach (TPError tpError in tpCallback.ProcessingErrors) { this.GenerateError += tpError.ToString() + "\n"; } } IsReady.DoNotify(this, string.IsNullOrEmpty(this.GenerateError)); }