public SQLStoredProcedureViewAllTemplate(ModelRoot model, CustomView view, bool singleFile, StringBuilder grantSB) : base(model) { _view = view; _singleFile = singleFile; _grantSB = grantSB; }
public SQLSelectViewTemplate(ModelRoot model, CustomView currentView, StringBuilder grantSB) { _model = model; _currentView = currentView; _grantSB = grantSB; }
public ViewEntityGeneratedTemplate(ModelRoot model, CustomView currentTable) : base(model) { _item = currentTable; }
public ViewEntityGeneratedTemplate(ModelRoot model, CustomView view) : base(model) { _item = view; }
private void AppendMappingFragment(CustomView view) { sb.AppendFormat(" <MappingFragment StoreEntitySet=\"{0}\">", view.PascalName).AppendLine(); sb.AppendLine(" <ScalarProperty Name=\"pk\" ColumnName=\"__pk\" />"); foreach (var currentColumn in view.GetColumns().Where(x => x.Generated).OrderBy(x => x.Name)) { sb.AppendFormat(" <ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", currentColumn.PascalName, currentColumn.DatabaseName).AppendLine(); } sb.AppendFormat(" </MappingFragment>").AppendLine(); }
public ViewEntityExtenderTemplate(ModelRoot model, CustomView table) : base(model) { _currentView = table; }
public static string GetSqlCreateView(CustomView view, bool isInternal) { var sb = new StringBuilder(); sb.AppendLine("if exists(select * from sys.objects where name = '" + view.DatabaseName + "' and type = 'V' and type_desc = 'VIEW')"); sb.AppendLine("drop view [" + view.GetSQLSchema() + "].[" + view.DatabaseName + "]"); if (isInternal) { sb.AppendLine("--MODELID: " + view.Key); } sb.AppendLine("GO"); sb.AppendLine(); sb.AppendLine("CREATE VIEW [" + view.GetSQLSchema() + "].[" + view.DatabaseName + "]"); sb.AppendLine("AS"); sb.AppendLine(); sb.AppendLine(view.SQL); if (isInternal) { sb.AppendLine("--MODELID,BODY: " + view.Key); } sb.AppendLine("GO"); sb.AppendLine("exec sp_refreshview N'[" + view.GetSQLSchema() + "].[" + view.DatabaseName + "]';"); if (isInternal) { sb.AppendLine("--MODELID: " + view.Key); } sb.AppendLine("GO"); sb.AppendLine(); return sb.ToString(); }
public ViewEntityExtenderTemplate(ModelRoot model, CustomView view) : base(model) { _currentView = view; }
public DatasiteViewItemTemplate(ModelRoot model, CustomView item, string templateLocation) : base(model) { _item = item; _templateLocation = templateLocation; }
//private void PopulateRelationships(TreeNode parentNode) //{ // try // { // Random rnd = new Random(); // SortedList<string, DataTreeItem> relationList = new SortedList<string, DataTreeItem>(); // //Current Tables // foreach (Table t in this.CurrentDatabase.Tables) // { // //Remove invalid links. Something is very wrong // RelationCollection relationCollection = t.GetRelations(); // for (int ii = relationCollection.Count - 1; ii >= 0; ii--) // { // Relation relationshipItem = relationCollection[ii]; // int errorCount = 0; // foreach (ColumnRelationship relationshipLinkItem in relationshipItem.ColumnRelationships) // { // if ((relationshipLinkItem.ChildColumnRef == null) || (relationshipLinkItem.ParentColumnRef == null)) // errorCount++; // } // if (errorCount > 0) t.Relationships.RemoveAt(ii); // } // //Remove Errors // //If the table exists in the new graph... // foreach (Relation relation in relationCollection) // { // Table t2 = this.NewDatabase.Tables[t.Name]; // DataTreeItem dti = new DataTreeItem(relation.RoleName); // dti.Name = relation.ToLongString(); // if (t2 == null) // { // //The table was removed so the relationship was removed // dti.State = DataTreeItem.DataTreeItemStateConstants.Delete; // } // else // { // //If the name changed then it was modified // Relation[] r2List = t2.GetRelations().GetFromMatch(relation); // if (r2List.Length == 0) // { // dti.State = DataTreeItem.DataTreeItemStateConstants.Delete; // } // else if (r2List.Length == 1) // { // if (r2List[0].RoleName != relation.RoleName) // dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; // } // else if (r2List.Length > 1) // { // //There are multiple relationships for this table/column combination // bool found = false; // foreach (Relation r2 in r2List) // { // #region OLD CODE // //if (r2.RoleName == relation.RoleName) found = true; // //string parentTableName1 = ((Table)r2.ParentTableRef.Object).Name; // //string parentTableName2 = ((Table)relation.ParentTableRef.Object).Name; // //SortedDictionary<string, ColumnRelationship> list1 = new SortedDictionary<string,ColumnRelationship>(); // //foreach (ColumnRelationship cr in r2.ColumnRelationships) // //{ // // list1.Add(((Column)cr.ChildColumnRef.Object).Name, cr); // //} // //SortedDictionary<string, ColumnRelationship> list2 = new SortedDictionary<string, ColumnRelationship>(); // //foreach (ColumnRelationship cr in relation.ColumnRelationships) // //{ // // list2.Add(((Column)cr.ChildColumnRef.Object).Name, cr); // //} // //string parentColName1 = string.Empty; // //foreach (string key in list1.Keys) // //{ // // parentColName1 += key; // //} // //string parentColName2 = string.Empty; // //foreach (string key in list2.Keys) // //{ // // parentColName2 += key; // //} // ////string parentCol // //if ((parentTableName1 == parentTableName2) && (parentColName1 == parentColName2)) // // found = true; // #endregion // if (r2.Equals(relation)) found = true; // } // if (!found) // dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; // } // } // //If there is a duplicate then add a FAKE ROLE to it // if (relationList.ContainsKey(relation.ToLongString().ToLower())) // { // relation.RoleName = "ROLE" + rnd.Next(10000, 100000); // relationList.Add(relation.ToLongString().ToLower(), dti); // } // else // { // relationList.Add(relation.ToLongString().ToLower(), dti); // } // } // } // //Added Relationships // foreach (Table t in this.NewDatabase.Tables) // { // foreach (Reference reference in t.Relationships) // { // Relation r = (Relation)reference.Object; // string relationName = r.ToLongString(); // if (this.CurrentDatabase.Tables.Contains(t.Name)) // { // //If the old model has this table // Table t2 = this.CurrentDatabase.Tables[t.Name]; // if ((t2 != null) && (t2.GetRelations().GetFromMatch(r).Length == 0)) // relationList.Add(relationName.ToLower(), new DataTreeItem(relationName, DataTreeItem.DataTreeItemStateConstants.Added)); // } // else // { // //Table and Relation not in old model // if (!relationList.ContainsKey(relationName.ToLower())) // { // relationList.Add(relationName.ToLower(), new DataTreeItem(relationName, DataTreeItem.DataTreeItemStateConstants.Added)); // } // else // { // int loop = 1; // while (relationList.ContainsKey((relationName + "_RELATION" + loop).ToLower())) // { // loop++; // } // relationName += "_RELATION" + loop; // relationList.Add(relationName.ToLower(), new DataTreeItem(relationName, DataTreeItem.DataTreeItemStateConstants.Added)); // } // } // } // } // //Now add to tree // foreach (string relationKey in relationList.Keys) // { // var relationNode = new TreeNode(relationList[relationKey].Name); // relationNode.Tag = relationList[relationKey]; // if (relationList[relationKey].State == DataTreeItem.DataTreeItemStateConstants.Added) // relationNode.ForeColor = Color.Green; // if (relationList[relationKey].State == DataTreeItem.DataTreeItemStateConstants.Delete) // relationNode.ForeColor = Color.Red; // if (relationList[relationKey].State == DataTreeItem.DataTreeItemStateConstants.Modified) // relationNode.ForeColor = Color.Blue; // parentNode.Nodes.Add(relationNode); // } // this.BrandNodes(parentNode.Nodes); // } // catch (Exception ex) // { // throw; // } //} #endregion #region PopulateStoredProcedures //private void PopulateStoredProcedures(TreeNode parentNode) //{ // try // { // SortedList<string, DataTreeItem> itemCache = new SortedList<string, DataTreeItem>(); // //Current Items // foreach (CustomStoredProcedure storedProcedure in this.CurrentDatabase.CustomStoredProcedures) // { // DataTreeItem dti = new DataTreeItem(storedProcedure.Name); // if (this.NewDatabase.CustomStoredProcedures.Contains(storedProcedure.Name)) // dti.Name = this.NewDatabase.CustomStoredProcedures[storedProcedure.Name].Name; // //Check for deleted status // if (!this.NewDatabase.CustomStoredProcedures.Contains(storedProcedure.Name)) // dti.State = DataTreeItem.DataTreeItemStateConstants.Delete; // else if (this.NewDatabase.CustomStoredProcedures[storedProcedure.Name].Name != storedProcedure.Name) // dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; // else if (this.NewDatabase.CustomStoredProcedures[storedProcedure.Name].GetColumns().GetCorePropertiesHash() != storedProcedure.GetColumns().GetCorePropertiesHash()) // dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; // itemCache.Add(storedProcedure.Name.ToLower(), dti); // } // //Added Items // foreach (CustomStoredProcedure t in this.NewDatabase.CustomStoredProcedures) // { // if (!this.CurrentDatabase.CustomStoredProcedures.Contains(t.Name)) // itemCache.Add(t.Name.ToLower(), new DataTreeItem(t.Name, DataTreeItem.DataTreeItemStateConstants.Added)); // } // //Now add to tree // foreach (string storedProcedureKey in itemCache.Keys) // { // var newNode = new TreeNode(itemCache[storedProcedureKey].Name); // newNode.Tag = itemCache[storedProcedureKey]; // if (itemCache[storedProcedureKey].State == DataTreeItem.DataTreeItemStateConstants.Added) // newNode.ForeColor = Color.Green; // if (itemCache[storedProcedureKey].State == DataTreeItem.DataTreeItemStateConstants.Delete) // newNode.ForeColor = Color.Red; // if (itemCache[storedProcedureKey].State == DataTreeItem.DataTreeItemStateConstants.Modified) // newNode.ForeColor = Color.Blue; // parentNode.Nodes.Add(newNode); // CustomStoredProcedure oldStoredProcedure = this.CurrentDatabase.CustomStoredProcedures[storedProcedureKey]; // CustomStoredProcedure newStoredProcedure = this.NewDatabase.CustomStoredProcedures[storedProcedureKey]; // if (oldStoredProcedure == null) oldStoredProcedure = new CustomStoredProcedure(this.CurrentDatabase.Root); // if (newStoredProcedure == null) newStoredProcedure = new CustomStoredProcedure(this.NewDatabase.Root); // //Create list of all columns (new and old) // SortedList<string, DataTreeItem> columns = new SortedList<string, DataTreeItem>(); // foreach (Reference r in oldStoredProcedure.Columns) // { // CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)r.Object; // DataTreeItem dti = new DataTreeItem(column.Name); // //Check for deleted status // if (this.NewDatabase.CustomStoredProcedures.Contains(itemCache[oldStoredProcedure.Name.ToLower()].Name)) // { // CustomStoredProcedureColumn statusColumn = this.NewDatabase.CustomStoredProcedures[itemCache[oldStoredProcedure.Name.ToLower()].Name].GetColumns().FirstOrDefault(x => x.Name == column.Name); // if (statusColumn == null) // dti.State = DataTreeItem.DataTreeItemStateConstants.Delete; // else if (column.CorePropertiesHash != statusColumn.CorePropertiesHash) // dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; // } // columns.Add(column.Name.ToLower(), dti); // } // //Added Columns // if (oldStoredProcedure.Name == string.Empty) // { // foreach (CustomStoredProcedureColumn column in this.NewDatabase.CustomStoredProcedures[storedProcedureKey].GetColumns()) // { // columns.Add(column.Name.ToLower(), new DataTreeItem(column.Name, DataTreeItem.DataTreeItemStateConstants.Added)); // } // } // else // { // if (this.NewDatabase.CustomStoredProcedures.Contains(itemCache[oldStoredProcedure.Name.ToLower()].Name)) // { // foreach (CustomStoredProcedureColumn column in this.NewDatabase.CustomStoredProcedures[itemCache[oldStoredProcedure.Name.ToLower()].Name].GetColumns()) // { // CustomStoredProcedureColumn statusColumn = this.CurrentDatabase.CustomStoredProcedures[itemCache[oldStoredProcedure.Name.ToLower()].Name].GetColumns().FirstOrDefault(x => x.Name == column.Name); // if (statusColumn == null) // columns.Add(column.Name.ToLower(), new DataTreeItem(column.Name, DataTreeItem.DataTreeItemStateConstants.Added)); // } // } // } // //Now load columns into tree // if (this.NewDatabase.CustomStoredProcedures.Contains(oldStoredProcedure.Name)) // { // foreach (string columnKey in columns.Keys) // { // var columnNode = new TreeNode(columns[columnKey].Name); // if (columns[columnKey].State == DataTreeItem.DataTreeItemStateConstants.Added) // columnNode.ForeColor = Color.Green; // if (columns[columnKey].State == DataTreeItem.DataTreeItemStateConstants.Delete) // columnNode.ForeColor = Color.Red; // if (columns[columnKey].State == DataTreeItem.DataTreeItemStateConstants.Modified) // columnNode.ForeColor = Color.Blue; // columnNode.Tag = columns[columnKey]; // newNode.Nodes.Add(columnNode); // } // } // } // this.BrandNodes(parentNode.Nodes); // } // catch (Exception ex) // { // throw; // } //} #endregion private void PopulateViews(TreeNode parentNode) { try { var itemCache = new SortedList<string, DataTreeItem>(); //Current Items foreach (CustomView view in this.CurrentDatabase.CustomViews) { var dti = new DataTreeItem(view.Name); if (this.NewDatabase.CustomViews.Contains(view.Name)) dti.Name = this.NewDatabase.CustomViews[view.Name].Name; //Check for deleted status if (!this.NewDatabase.CustomViews.Contains(view.Name)) dti.State = DataTreeItem.DataTreeItemStateConstants.Delete; else if (this.NewDatabase.CustomViews[view.Name].Name != view.Name) dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; else if (this.NewDatabase.CustomViews[view.Name].GetColumns().GetCorePropertiesHash() != view.GetColumns().GetCorePropertiesHash()) dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; itemCache.Add(view.Name.ToLower(), dti); } //Added Items foreach (CustomView t in this.NewDatabase.CustomViews) { if (!this.CurrentDatabase.CustomViews.Contains(t.Name)) itemCache.Add(t.Name.ToLower(), new DataTreeItem(t.Name, DataTreeItem.DataTreeItemStateConstants.Added)); } //Now add to tree foreach (var viewKey in itemCache.Keys) { var viewNode = new TreeNode(itemCache[viewKey].Name); viewNode.Checked = true; viewNode.ImageIndex = 4; viewNode.Tag = itemCache[viewKey]; //if (itemCache[viewKey].State == DataTreeItem.DataTreeItemStateConstants.Added) // viewNode.ForeColor = Color.Green; //if (itemCache[viewKey].State == DataTreeItem.DataTreeItemStateConstants.Delete) // viewNode.ForeColor = Color.Red; //if (itemCache[viewKey].State == DataTreeItem.DataTreeItemStateConstants.Modified) // viewNode.ForeColor = Color.Blue; parentNode.Nodes.Add(viewNode); var oldView = this.CurrentDatabase.CustomViews[viewKey]; var newView = this.NewDatabase.CustomViews[viewKey]; if (oldView == null) oldView = new CustomView(this.CurrentDatabase.Root); if (newView == null) newView = new CustomView(this.NewDatabase.Root); //Create list of all columns (new and old) var columns = new SortedList<string, DataTreeItem>(); foreach (Reference r in oldView.Columns) { var column = (CustomViewColumn)r.Object; var dti = new DataTreeItem(column.Name); //Check for deleted status if (this.NewDatabase.CustomViews.Contains(itemCache[oldView.Name.ToLower()].Name)) { var statusColumn = this.NewDatabase.CustomViews[itemCache[oldView.Name.ToLower()].Name].GetColumns().FirstOrDefault(x => x.Name == column.Name); if (statusColumn == null) dti.State = DataTreeItem.DataTreeItemStateConstants.Delete; else if (column.CorePropertiesHash != statusColumn.CorePropertiesHash) dti.State = DataTreeItem.DataTreeItemStateConstants.Modified; } columns.Add(column.Name.ToLower(), dti); } #region Added Columns //if (oldView.Name == string.Empty) //{ // foreach (CustomViewColumn column in this.NewDatabase.CustomViews[viewKey].GetColumns()) // { // columns.Add(column.Name.ToLower(), new DataTreeItem(column.Name, DataTreeItem.DataTreeItemStateConstants.Added)); // } //} //else //{ // if (this.NewDatabase.CustomViews.Contains(itemCache[oldView.Name.ToLower()].Name)) // { // foreach (CustomViewColumn column in this.NewDatabase.CustomViews[itemCache[oldView.Name.ToLower()].Name].GetColumns()) // { // CustomViewColumn statusColumn = this.CurrentDatabase.CustomViews[itemCache[oldView.Name.ToLower()].Name].GetColumns().FirstOrDefault(x => x.Name == column.Name); // if (statusColumn == null) // columns.Add(column.Name.ToLower(), new DataTreeItem(column.Name, DataTreeItem.DataTreeItemStateConstants.Added)); // } // } //} ////Now load columns into tree //if (this.NewDatabase.CustomViews.Contains(oldView.Name)) //{ // foreach (string columnKey in columns.Keys) // { // var columnNode = new TreeNode(columns[columnKey].Name); // if (columns[columnKey].State == DataTreeItem.DataTreeItemStateConstants.Added) // columnNode.ForeColor = Color.Green; // if (columns[columnKey].State == DataTreeItem.DataTreeItemStateConstants.Delete) // columnNode.ForeColor = Color.Red; // if (columns[columnKey].State == DataTreeItem.DataTreeItemStateConstants.Modified) // columnNode.ForeColor = Color.Blue; // columnNode.Tag = columns[columnKey]; // viewNode.Nodes.Add(columnNode); // } //} #endregion } } catch (Exception ex) { throw; } }
public ImportColumns(CustomView view, ReferenceCollection columnList) : this() { _view = view; _columnList = columnList; }