public string DumpSelectedObjects() { StringBuilder sb = new StringBuilder(); try { pbDump.Value = 0; pbDump.Maximum = _selectedObjects.Count; pbDump.Visible = true; IList <DbObjectInfo> objects = this.SelectedObjects; foreach (DbObjectInfo info in objects) { if (!IsObjectTypeValid(info.ObjType)) { continue; } string objType = DbObjectListUtils.EncodeObjectType(info.ObjType); sb.AppendLine(objType + "=" + QualifiedStr(info.Owner) + "." + QualifiedStr(info.Name)); pbDump.Value++; pbDump.Invalidate(); } } finally { pbDump.Visible = false; } return(sb.ToString()); }
private void LoadFromObjectExplorer() { if (HostServicesSingleton.HostServices == null || HostServicesSingleton.HostServices.ObjectExplorerService == null) { throw new InvalidOperationException("ObjectExplorer is not active or visible!"); } IList <ObjectExplorerNode> selNodes = HostServicesSingleton.HostServices.ObjectExplorerService.SelNodes; StringBuilder sb = new StringBuilder(); string template = "{0}=[{1}].[{2}]"; string objType = String.Empty; foreach (ObjectExplorerNode node in selNodes) { if (!DBObjectType.CanTypeBeDumpedForScriptingWizardUsage(node.Type) || node.ConnParams == null) { continue; } if (node.ConnParams.Server != _cp.Server || !node.DatabaseName.Equals(_cp.Database, StringComparison.InvariantCultureIgnoreCase)) { continue; } objType = DbObjectListUtils.EncodeObjectExplorerNodeType(node.Type); sb.AppendLine(String.Format(template, objType, node.Owner, node.Name)); } PrepareObjectFromContent(sb.ToString()); }
public void PrepareObjectFromContent(string content) { _selectedObjects.Clear(); bsDest.DataSource = null; string newContent = content.Replace("\r", String.Empty); string pattern = @"(?<ObjType>SPR|FNC|TBL|TRG|VW)\s*\=\s*\[{0,1}\s*(?<Schema>\w*)\s*\]{0,1}\s*\.{1}\s*\[{0,1}\s*(?<ObjName>\w*)\s*\]{0,1}\s*"; MatchCollection matches = Regex.Matches(newContent, pattern, RegexOptions.IgnoreCase); string objType = String.Empty; string schema = String.Empty; string objName = String.Empty; DbObjectInfo sel = null; foreach (Match m in matches) { if (!m.Success) { continue; } objType = String.Empty; schema = String.Empty; objName = String.Empty; objType = m.Groups["ObjType"].Value; schema = m.Groups["Schema"].Value; objName = m.Groups["ObjName"].Value; if (String.IsNullOrEmpty(objType) || String.IsNullOrEmpty(schema) || String.IsNullOrEmpty(objName)) { continue; } objType = DbObjectListUtils.DecodeObjectType(objType); if (!IsObjectTypeValid(objType)) { continue; } if (string.IsNullOrEmpty(objType)) { continue; } sel = new DbObjectInfo(); sel.Name = objName; sel.Owner = schema; sel.ObjType = objType; _selectedObjects.Add(sel); } bsDest.DataSource = _selectedObjects; }