public CacheEntry?Get(Urn urn) { if (!DoesCacheExist()) { return(null); } using FileStream cache = CacheDatabase.Open(FileMode.Open); using BinaryReader reader = new(cache); using BinaryWriter writer = new(cache); // Skip file header reader.BaseStream.Seek(FILE_MAGIC.Length, SeekOrigin.Begin); // Loop through items in cache until target URN is found byte[] targetUrnBytes = Encoding.Default.GetBytes(urn.ToString()); while (reader.BaseStream.Position < reader.BaseStream.Length) { // Read entry if (reader.ReadByte() != byte.MaxValue) { continue; } CacheEntry entry = CacheEntry.ReadFromStream(reader); // Check for equality if (entry.urnBytes.SequenceEqual(targetUrnBytes)) { return(entry); } } return(null); }
public void Open(string serverName, string fullName, Urn urn, string text) { string key = urn.ToString(); IObjectExplorerService objExplorer = ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService)) as IObjectExplorerService; var test = ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService)) as IObjectExplorerService; var node = objExplorer.FindNode(key); if (node != null) { objExplorer.SynchronizeTree(node); } Document existingDocument; if (_openedDocuments.TryGetValue(key, out existingDocument)) { existingDocument.Activate(); } else if (text != null) { var script = ServiceCache.ScriptFactory.CreateNewBlankScript(ScriptType.Sql) as SqlScriptEditorControl; script.EditorText = text; _openedDocuments[key] = _applicationObject.ActiveDocument; string fullPath = Properties.Settings.Default.ResolveProjectRoot(); if (!fullPath.EndsWith("\\")) { fullPath += '\\'; } fullPath += serverName + '\\' + fullName.Replace('.', '\\').Replace(':', '_') + ".sql"; _applicationObject.ActiveDocument.Save(fullPath); } }
public static string GetNotificationTag(Urn urn) { string tag = urn.ToString().Replace(':', '_'); if (tag.Length > 64) { tag = tag.Substring(0, 64); } return(tag); }
protected CatalogSubject(SystemResourceScheme Scheme, string host, string Name, INodeCatalogSubject Parent = null) { this.Parent = Parent; this.Scheme = Scheme; this.IsRoot = Parent == null; this.SymbolicHost = host; this.Name = IsRoot ? $"/{host}/{Name}" : Name; this.Lineage = DeriveLineage().ToList(); this.RelativeLocation = IsRoot ? this.Name : DeriveRelativeLocation(); this.Urn = DeriveUrn(); this.LineageSegments = Urn.NonSchemeComponents.Zip(RelativeLocation.Split('/'), (x, y) => (x, y)).ToList(); this.Segment = (Urn.ToString(), RelativeLocation.ToString()); }
public void Remove(Urn urn) { if (!DoesCacheExist()) { return; } using FileStream cache = CacheDatabase.Open(FileMode.Open); using BinaryReader reader = new(cache); using BinaryWriter writer = new(cache); // Skip file header reader.BaseStream.Seek(FILE_MAGIC.Length, SeekOrigin.Begin); // Loop through items in cache until target URN is found byte[] targetUrnBytes = Encoding.Default.GetBytes(urn.ToString()); while (reader.BaseStream.Position < reader.BaseStream.Length) { // Read entry long entryPos = writer.BaseStream.Position; if (reader.ReadByte() != byte.MaxValue) { continue; } CacheEntry entry = CacheEntry.ReadFromStream(reader); // Check for equality if (entry.urnBytes.SequenceEqual(targetUrnBytes)) { // Delete cached file, if it exists var downloadItem = entry.GetDownloadItem(); if (downloadItem.Exists) { downloadItem.RecursiveDelete(); } // Zero out entry, acts like a NOP slide writer.BaseStream.Seek(entryPos, SeekOrigin.Begin); for (int i = 0; i < entry.Length; i++) { writer.Write(byte.MinValue); } break; } } }
public async Task <PreflightConcepts> GetConceptsByUniversalIdAsync(Urn universalId) { using (var cn = new SqlConnection(opts.ConnectionString)) { await cn.OpenAsync(); var conceptId = universalId.ToString(); var grid = await cn.QueryMultipleAsync( ConceptPreflightSql.singleId, new { id = conceptId, user = user.UUID, groups = GroupMembership.From(user), admin = user.IsAdmin }, commandTimeout : opts.DefaultTimeout, commandType : CommandType.StoredProcedure ); return(PreflightReader.ReadConcepts(grid)); } }
public void Add(Urn urn, string version, FileSystemInfo downloadItem) { if (TryGet(urn, out var cachedEntry) && version != cachedEntry.Value.GetVersion()) { Remove(urn); } CacheEntry entry = new() { urnBytes = Encoding.Default.GetBytes(urn.ToString()), versionBytes = Encoding.Default.GetBytes(version.ToString()), downloadItemBytes = Encoding.Default.GetBytes(downloadItem.FullName), }; // Write lengths, then data using BinaryWriter file = new(CacheDatabase.Open(FileMode.Append)); entry.WriteToStream(file); }
internal DataTable GetColumnNames(Server server, Urn urn, bool isDw) { List <string> filterExpressions = new List <string>(); if (server.Version.Major >= 10) { // We don't have to include sparce columns as all the sparce columns data. // Can be obtain from column set columns. filterExpressions.Add("@IsSparse=0"); } // Check if we're called for EDIT for SQL2016+/Sterling+. // We need to omit temporal columns if such are present on this table. if (server.Version.Major >= 13 || (DatabaseEngineType.SqlAzureDatabase == server.DatabaseEngineType && server.Version.Major >= 12)) { // We're called in order to generate a list of columns for EDIT TOP N rows. // Don't return auto-generated, auto-populated, read-only temporal columns. filterExpressions.Add("@GeneratedAlwaysType=0"); } // Check if we're called for SQL2017/Sterling+. // We need to omit graph internal columns if such are present on this table. if (server.Version.Major >= 14 || (DatabaseEngineType.SqlAzureDatabase == server.DatabaseEngineType && !isDw)) { // from Smo.GraphType: // 0 = None // 1 = GraphId // 2 = GraphIdComputed // 3 = GraphFromId // 4 = GraphFromObjId // 5 = GraphFromIdComputed // 6 = GraphToId // 7 = GraphToObjId // 8 = GraphToIdComputed // // We only want to show types 0, 2, 5, and 8: filterExpressions.Add("(@GraphType=0 or @GraphType=2 or @GraphType=5 or @GraphType=8)"); } Request request = new Request(); // If we have any filters on the columns, add them. if (filterExpressions.Count > 0) { request.Urn = String.Format("{0}/Column[{1}]", urn.ToString(), string.Join(" and ", filterExpressions.ToArray())); } else { request.Urn = String.Format("{0}/Column", urn.ToString()); } request.Fields = new String[] { "Name" }; // get the columns in the order they were created OrderBy order = new OrderBy(); order.Dir = OrderBy.Direction.Asc; order.Field = "ID"; request.OrderByList = new OrderBy[] { order }; Enumerator en = new Enumerator(); // perform the query. DataTable dt = null; EnumResult result = en.Process(server.ConnectionContext, request); if (result.Type == ResultType.DataTable) { dt = result; } else { dt = ((DataSet)result).Tables[0]; } return(dt); }
public override string ToString() => urn.ToString();
private void ScriptDependencies(IEnumerable <DependencyCollectionNode> dependencies) { Logger.WriteLine("Scripting dependencies:"); var tableOptions = new ScriptingOptions { WithDependencies = false, ScriptSchema = true, Indexes = true, IncludeIfNotExists = true, NoAssemblies = true }; var procFuncOptions = new ScriptingOptions { WithDependencies = true, ScriptSchema = true, IncludeIfNotExists = true, NoAssemblies = true }; var assemblyOptions = new ScriptingOptions { WithDependencies = true, ScriptSchema = true, IncludeIfNotExists = true, NoAssemblies = false }; var script = new Scripter(_sourceServer); foreach (DependencyCollectionNode node in dependencies) { Urn urn = node.Urn; if (node.Urn.Type == "UnresolvedEntity") { continue; } Logger.WriteLine(" - Generating scripts from {0}", urn); switch (urn.Type) { case "Table": script.Options = tableOptions; break; case "SqlAssembly": script.Options = assemblyOptions; break; default: script.Options = procFuncOptions; break; } StringCollection scripts = script.Script(new[] { urn }); foreach (string scr in scripts) { Logger.WriteLine(" - Executing script on {0}: {1}", _targetDatabase.Urn, scr); _targetDatabase.ExecuteNonQuery(scr); } if (SqlSmoObject.GetTypeFromUrnSkeleton(urn) == typeof(Table)) { if (Tables.Contains(urn.ToString())) { Logger.WriteLine(" - Table already exists so skipping data copy"); } else { CopyDependentData((Table)_sourceServer.GetSmoObject(urn)); } } } }
private bool ShouldIgnore(string propertyName, Urn urnObj) { bool bRet = false; for (int k = 0; k < ignorePropertyForObject.Count; k++) { if (((PropertyAndObject)ignorePropertyForObject[k]).PropertyName == propertyName && ((PropertyAndObject)ignorePropertyForObject[k]).Urn.ToString() == urnObj.ToString()) return true; } return bRet; }
private bool ShouldIgnore(Urn urnObject) { return ignoreObject.Contains(urnObject.ToString()); }