public virtual void UiBtnFormCommandImportAction(Object param) { OpenFileDialog ofdlg = new OpenFileDialog(); ofdlg.Filter = "JSON-files(*.json)|*.json"; ofdlg.DefaultExt = "json"; ofdlg.Title = "Select a source to import"; if (ofdlg.ShowDialog() != DialogResult.OK) { return; } try { string jsonString = File.ReadAllText(ofdlg.FileName); DbContextSerializable srcContext = JsonConvert.DeserializeObject <DbContextSerializable>(jsonString); if (srcContext.CommonStaffs != null) { if (SerializableDbContext.CommonStaffs == null) { SerializableDbContext.CommonStaffs = new List <CommonStaffSerializable>(); } foreach (CommonStaffSerializable commonStaffSerializable in srcContext.CommonStaffs) { if (!SerializableDbContext.CommonStaffs.Any(s => s.FileType == commonStaffSerializable.FileType)) { SerializableDbContext.CommonStaffs.Add(commonStaffSerializable); } } if (SelectedModel.ViewName == ContextItemViewName) { if (SelectedModel.CommonStaffs == null) { SelectedModel.CommonStaffs = new List <CommonStaffSerializable>(); } foreach (CommonStaffSerializable commonStaffSerializable in srcContext.CommonStaffs) { if (!SelectedModel.CommonStaffs.Any(s => s.FileType == commonStaffSerializable.FileType)) { SelectedModel.CommonStaffs.Add(commonStaffSerializable); } } } } OnCreatedActionsChanged(); System.Windows.Forms.MessageBox.Show("Data was imported successfully", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); if (SelectedModel.ViewName != ContextItemViewName) { OnContextChanged.DoNotify(this); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Error:" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public virtual void ImportBtnCommandAction(Object param) { OpenFileDialog ofdlg = new OpenFileDialog(); ofdlg.Filter = "JSON-files(*.json)|*.json"; ofdlg.DefaultExt = "json"; ofdlg.Title = "Select a source to import"; if (ofdlg.ShowDialog() != DialogResult.OK) { return; } try { string jsonString = File.ReadAllText(ofdlg.FileName); DbContextSerializable srcContext = JsonConvert.DeserializeObject <DbContextSerializable>(jsonString); if (CurrentDbContext == null) { return; } if (CurrentDbContext.ModelViews == null) { CurrentDbContext.ModelViews = new List <ModelViewSerializable>(); } foreach (ModelViewSerializable itm in srcContext.ModelViews) { if (itm.RootEntityClassName != SelectedEntity.CodeElementName) { continue; } if (CurrentDbContext.ModelViews.Any(m => m.ViewName == itm.ViewName)) { continue; } ModelViewSerializable destItm = itm.ModelViewSerializableGetCopy(this.DestinationProject, this.DefaultProjectNameSpace, this.DestinationFolder, this.DbSetProppertyName, this.SelectedEntity); CurrentDbContext.ModelViews.Add(destItm); ModelViews.Add(destItm); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Error:" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public void OnSelectedDbContextChanged() { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (SelectedDbContext == null) { DbContext = null; OnSelectedFeatureContext(); } string projectName = ""; if (SelectedDbContext.CodeElementRef != null) { if (SelectedDbContext.CodeElementRef.ProjectItem != null) { projectName = SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName; } } if (!string.IsNullOrEmpty(projectName)) { string locFileName = Path.Combine(projectName, SelectedDbContext.CodeElementFullName, JsonExtension); locFileName = locFileName.Replace("\\", "."); string solutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); locFileName = Path.Combine(solutionDirectory, locFileName); if (File.Exists(locFileName)) { string jsonString = File.ReadAllText(locFileName); DbContext = JsonConvert.DeserializeObject <DbContextSerializable>(jsonString); OnSelectedFeatureContext(); } else { DbContext = new DbContextSerializable(); OnSelectedFeatureContext(); } } else { DbContext = null; OnSelectedFeatureContext(); } }
private void OnContextChanged(Object sender) { if (CreateWebApiUC == null) { return; } if (CreateWebApiUC.DataContext == null) { return; } if ((CreateWebApiUC.DataContext as CreateWebApiViewModel).SerializableDbContext == null) { return; } if ((CreateWebApiUC.DataContext as CreateWebApiViewModel).ModelViews == null) { return; } ModelViewSerializable mv = (CreateWebApiUC.DataContext as CreateWebApiViewModel).ModelViews.Where(m => m.ViewName == (CreateWebApiUC.DataContext as CreateWebApiViewModel).ContextItemViewName).FirstOrDefault(); if (mv == null) { return; } DbContextSerializable cn = (CreateWebApiUC.DataContext as CreateWebApiViewModel).SerializableDbContext; if (cn.CommonStaffs == null) { return; } if (mv.CommonStaffs == null) { mv.CommonStaffs = new List <CommonStaffSerializable>(); } mv.CommonStaffs.Clear(); foreach (CommonStaffSerializable csf in cn.CommonStaffs) { mv.CommonStaffs.Add(csf); } }
public override void SaveBtnCommandAction(Object param) { DbContextSerializable localDbContext = (CreateWebApiUC.DataContext as CreateWebApiViewModel).SerializableDbContext; ModelViewSerializable modelViewSerializable = (GenerateUC.DataContext as GenerateCommonStaffViewModel).GeneratedModelView; ModelViewSerializable existedModelViewSerializable = localDbContext.ModelViews.FirstOrDefault(mv => mv.ViewName == modelViewSerializable.ViewName); if (existedModelViewSerializable != null) { existedModelViewSerializable.ScalarProperties = modelViewSerializable.ScalarProperties; existedModelViewSerializable.WebApiServiceName = modelViewSerializable.WebApiServiceName; existedModelViewSerializable.IsWebApiSelectAll = modelViewSerializable.IsWebApiSelectAll; existedModelViewSerializable.IsWebApiSelectManyWithPagination = modelViewSerializable.IsWebApiSelectManyWithPagination; existedModelViewSerializable.IsWebApiSelectOneByPrimarykey = modelViewSerializable.IsWebApiSelectOneByPrimarykey; existedModelViewSerializable.IsWebApiAdd = modelViewSerializable.IsWebApiAdd; existedModelViewSerializable.IsWebApiUpdate = modelViewSerializable.IsWebApiUpdate; existedModelViewSerializable.IsWebApiDelete = modelViewSerializable.IsWebApiDelete; existedModelViewSerializable.WebApiServiceProject = modelViewSerializable.WebApiServiceProject; existedModelViewSerializable.WebApiServiceDefaultProjectNameSpace = modelViewSerializable.WebApiServiceDefaultProjectNameSpace; existedModelViewSerializable.WebApiServiceFolder = modelViewSerializable.WebApiServiceFolder; existedModelViewSerializable.UIFormProperties = modelViewSerializable.UIFormProperties; existedModelViewSerializable.UIListProperties = modelViewSerializable.UIListProperties; } else { localDbContext.ModelViews.Add(modelViewSerializable); } string projectName = ""; if ((CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementRef != null) { if ((CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementRef.ProjectItem != null) { projectName = (CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName; } } if (!string.IsNullOrEmpty(projectName)) { string locFileName = Path.Combine(projectName, (CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementFullName, JsonExtension); locFileName = locFileName.Replace("\\", "."); SolutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); locFileName = Path.Combine(SolutionDirectory, locFileName); string jsonString = JsonConvert.SerializeObject(localDbContext); File.WriteAllText(locFileName, jsonString); } try { SolutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); string FlNm = Path.Combine( SolutionDirectory, Path.GetDirectoryName(modelViewSerializable.WebApiServiceProject), modelViewSerializable.WebApiServiceFolder, modelViewSerializable.WebApiServiceName + (GenerateUC.DataContext as GenerateCommonStaffViewModel).FileExtension); File.WriteAllText(FlNm, (GenerateUC.DataContext as GenerateCommonStaffViewModel).GenerateText); DestinationProject.ProjectItems.AddFromFile(FlNm); MessageBox.Show(SuccessNotification, "Done", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception e) { MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void OnDbContextChanged() { bool isChanged = CurrentDbContext == null; string locFileName = ""; if (!isChanged) { isChanged = ((SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext == null); } if (!isChanged) { isChanged = string.IsNullOrEmpty(CurrentDbContext.DbContextProjectUniqueName) || string.IsNullOrEmpty(CurrentDbContext.DbContextFullClassName); } if (!isChanged) { isChanged = !CurrentDbContext.DbContextFullClassName.Equals((SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementFullName); } if (!isChanged) { //CurrentDbContext.DbContextProject isChanged = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef == null; if (!isChanged) { isChanged = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef.ProjectItem == null; } if (!isChanged) { isChanged = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject == null; } if (!isChanged) { isChanged = !CurrentDbContext.DbContextProjectUniqueName.Equals( (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName, StringComparison.OrdinalIgnoreCase); } } if (isChanged) { string projectName = ""; if ((SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef != null) { if ((SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef.ProjectItem != null) { projectName = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName; } } if (!string.IsNullOrEmpty(projectName)) { locFileName = Path.Combine(projectName, (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementFullName, JsonExtension); locFileName = locFileName.Replace("\\", "."); SolutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); locFileName = Path.Combine(SolutionDirectory, locFileName); } } if (!string.IsNullOrEmpty(locFileName)) { if (File.Exists(locFileName)) { string jsonString = System.IO.File.ReadAllText(locFileName); CurrentDbContext = JsonConvert.DeserializeObject <DbContextSerializable>(jsonString); } else { if (CurrentDbContext == null) { CurrentDbContext = new DbContextSerializable(); } CurrentDbContext.DbContextClassName = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementName; CurrentDbContext.DbContextFullClassName = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementFullName; CurrentDbContext.DbContextProjectUniqueName = (SelectSourceEntityUC.DataContext as SelectEntityForGivenDbContextViewModel).SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName; if (CurrentDbContext.ModelViews == null) { CurrentDbContext.ModelViews = new List <ModelViewSerializable>(); } else { CurrentDbContext.ModelViews.Clear(); } } return; } if (isChanged) { if (CurrentDbContext == null) { CurrentDbContext = new DbContextSerializable(); } CurrentDbContext.DbContextClassName = ""; CurrentDbContext.DbContextFullClassName = ""; CurrentDbContext.DbContextProjectUniqueName = ""; if (CurrentDbContext.ModelViews == null) { CurrentDbContext.ModelViews = new List <ModelViewSerializable>(); } else { CurrentDbContext.ModelViews.Clear(); } } }
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)); }
public override void SaveBtnCommandAction(Object param) { DbContextSerializable localDbContext = (CreateWebApiUC.DataContext as CreateWebApiViewModel).SerializableDbContext; ModelViewSerializable modelViewSerializable = (GenerateUC.DataContext as GenerateCommonStaffViewModel).GeneratedModelView; if (modelViewSerializable.ViewName == (CreateWebApiUC.DataContext as CreateWebApiViewModel).ContextItemViewName) { localDbContext.CommonStaffs = modelViewSerializable.CommonStaffs; if ((SelectFolderUC.DataContext as SelectFolderViewModel).SelectedModel != null) { (SelectFolderUC.DataContext as SelectFolderViewModel).SelectedModel.CommonStaffs = localDbContext.CommonStaffs; } if (localDbContext.CommonStaffs != null) { CommonStaffSerializable commonStaffSerializable = localDbContext.CommonStaffs .Where(c => c.FileType == (SelectFolderUC.DataContext as SelectFolderViewModel).T4SelectedFolder) .FirstOrDefault(); if (commonStaffSerializable != null) { commonStaffSerializable.Extension = (GenerateUC.DataContext as GenerateCommonStaffViewModel).FileExtension; } } } else { ModelViewSerializable existedModelViewSerializable = localDbContext.ModelViews.FirstOrDefault(mv => mv.ViewName == modelViewSerializable.ViewName); if (modelViewSerializable.CommonStaffs != null) { CommonStaffSerializable commonStaffSerializable = modelViewSerializable.CommonStaffs .Where(c => c.FileType == (SelectFolderUC.DataContext as SelectFolderViewModel).T4SelectedFolder) .FirstOrDefault(); if (commonStaffSerializable != null) { commonStaffSerializable.Extension = (GenerateUC.DataContext as GenerateCommonStaffViewModel).FileExtension; } } if (existedModelViewSerializable != null) { existedModelViewSerializable.ScalarProperties = modelViewSerializable.ScalarProperties; existedModelViewSerializable.CommonStaffs = modelViewSerializable.CommonStaffs; existedModelViewSerializable.UIFormProperties = modelViewSerializable.UIFormProperties; existedModelViewSerializable.UIListProperties = modelViewSerializable.UIListProperties; } else { localDbContext.ModelViews.Add(modelViewSerializable); } } (SelectFolderUC.DataContext as SelectFolderViewModel).OnCreatedActionsChanged(); string projectName = ""; if ((CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementRef != null) { if ((CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementRef.ProjectItem != null) { projectName = (CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName; } } if (!string.IsNullOrEmpty(projectName)) { string locFileName = Path.Combine(projectName, (CreateWebApiUC.DataContext as CreateWebApiViewModel).SelectedDbContext.CodeElementFullName, JsonExtension); locFileName = locFileName.Replace("\\", "."); SolutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); locFileName = Path.Combine(SolutionDirectory, locFileName); string jsonString = JsonConvert.SerializeObject(localDbContext); File.WriteAllText(locFileName, jsonString); } try { // insert code here SolutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); string FlNm = Path.Combine( //SolutionDirectory, //Path.GetDirectoryName((CreateWebApiUC.DataContext as CreateWebApiViewModel).DestinationProject), (InvitationUC.DataContext as InvitationViewModel).DestinationProjectRootFolder, (CreateWebApiUC.DataContext as CreateWebApiViewModel).DestinationFolder, (SelectFolderUC.DataContext as SelectFolderViewModel).FileName + (GenerateUC.DataContext as GenerateCommonStaffViewModel).FileExtension); File.WriteAllText(FlNm, (GenerateUC.DataContext as GenerateCommonStaffViewModel).GenerateText); DestinationProject.ProjectItems.AddFromFile(FlNm); MessageBox.Show(SuccessNotification, "Done", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception e) { MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
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 static void UpdateDbContext(DTE2 Dte, Project DestinationProject, SolutionCodeElement SelectedDbContext, DbContextSerializable dbContextSerializable, ModelViewSerializable modelViewSerializable, string ContextItemViewName, string T4SelectedFolder, string DestinationProjectRootFolder, string DestinationFolder, string DestinationSubFolder, string FileName, string FileExtension, string GenerateText) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (modelViewSerializable.ViewName == ContextItemViewName) { dbContextSerializable.CommonStaffs = modelViewSerializable.CommonStaffs; if (dbContextSerializable.CommonStaffs == null) { dbContextSerializable.CommonStaffs = new List <CommonStaffSerializable>(); } CommonStaffSerializable commonStaffSerializable = dbContextSerializable.CommonStaffs .Where(c => c.FileType == T4SelectedFolder) .FirstOrDefault(); if (commonStaffSerializable != null) { commonStaffSerializable.Extension = FileExtension; } } else { ModelViewSerializable existedModelViewSerializable = dbContextSerializable.ModelViews.FirstOrDefault(mv => mv.ViewName == modelViewSerializable.ViewName); if (modelViewSerializable.CommonStaffs != null) { CommonStaffSerializable commonStaffSerializable = modelViewSerializable.CommonStaffs .Where(c => c.FileType == T4SelectedFolder) .FirstOrDefault(); if (commonStaffSerializable != null) { commonStaffSerializable.Extension = FileExtension; } } if (existedModelViewSerializable != null) { existedModelViewSerializable.CommonStaffs = modelViewSerializable.CommonStaffs; existedModelViewSerializable.UIFormProperties = modelViewSerializable.UIFormProperties; existedModelViewSerializable.UIListProperties = modelViewSerializable.UIListProperties; } else { dbContextSerializable.ModelViews.Add(modelViewSerializable); } } string projectName = ""; if (SelectedDbContext.CodeElementRef != null) { if (SelectedDbContext.CodeElementRef.ProjectItem != null) { projectName = SelectedDbContext.CodeElementRef.ProjectItem.ContainingProject.UniqueName; } } string SolutionDirectory = System.IO.Path.GetDirectoryName(Dte.Solution.FullName); if (!string.IsNullOrEmpty(projectName)) { string locFileName = Path.Combine(projectName, SelectedDbContext.CodeElementFullName, "json"); locFileName = locFileName.Replace("\\", "."); locFileName = Path.Combine(SolutionDirectory, locFileName); string jsonString = JsonConvert.SerializeObject(dbContextSerializable); File.WriteAllText(locFileName, jsonString); } string FlNm = ""; if (string.IsNullOrEmpty(DestinationSubFolder)) { FlNm = Path.Combine( DestinationProjectRootFolder, DestinationFolder); } else { FlNm = Path.Combine( DestinationProjectRootFolder, DestinationFolder, DestinationSubFolder); } System.IO.Directory.CreateDirectory(FlNm); FlNm = Path.Combine(FlNm, FileName + FileExtension); File.WriteAllText(FlNm, GenerateText); DestinationProject.ProjectItems.AddFromFile(FlNm); }