Esempio n. 1
0
        /// <summary>
        /// Script a object using SMO and write to a file.
        /// </summary>
        /// <param name="sqlScriptGetter">Function that returns the SMO scripts for an object</param>
        /// <param name="objectName">SQL object name</param>
        /// <param name="schemaName">Schema name or null</param>
        /// <param name="objectType">Type of SQL object</param>
        /// <returns>Location object representing URI and range of the script file</returns>
        internal Location[] GetSqlObjectDefinition(
            ScriptGetter sqlScriptGetter,
            string objectName,
            string schemaName,
            string objectType)
        {
            StringCollection scripts      = sqlScriptGetter(objectName, schemaName);
            string           tempFileName = (schemaName != null) ? Path.Combine(this.tempPath, string.Format("{0}.{1}.sql", schemaName, objectName))
                                                : Path.Combine(this.tempPath, string.Format("{0}.sql", objectName));

            if (scripts != null)
            {
                int lineNumber = 0;
                using (StreamWriter scriptFile = new StreamWriter(File.Open(tempFileName, FileMode.Create, FileAccess.ReadWrite)))
                {
                    foreach (string script in scripts)
                    {
                        string createSyntax = string.Format("CREATE {0}", objectType);
                        if (script.IndexOf(createSyntax, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            scriptFile.WriteLine(script);
                            lineNumber = GetStartOfCreate(script, createSyntax);
                        }
                    }
                }
                return(GetLocationFromFile(tempFileName, lineNumber));
            }
            else
            {
                this.error        = true;
                this.errorMessage = SR.PeekDefinitionNoResultsError;
                return(null);
            }
        }
Esempio n. 2
0
 public Task <string> GetScript()
 {
     if (_script == null)
     {
         _script = ScriptGetter.Invoke();
     }
     return(_script);
 }
 /// <summary>
 /// Add the given type, scriptgetter and the typeName string to the respective dictionaries
 /// </summary>
 private void AddSupportedType(DeclarationType type, ScriptGetter scriptGetter, string typeName, string quickInfoType)
 {
     sqlScriptGetters.Add(type, scriptGetter);
     sqlObjectTypes.Add(type, typeName);
     if (!string.IsNullOrEmpty(quickInfoType))
     {
         sqlScriptGettersFromQuickInfo.Add(quickInfoType.ToLowerInvariant(), scriptGetter);
         sqlObjectTypesFromQuickInfo.Add(quickInfoType.ToLowerInvariant(), typeName);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Add the given type, scriptgetter and the typeName string to the respective dictionaries
 /// </summary>
 private void AddSupportedType(DeclarationType type, ScriptGetter scriptGetter, string typeName)
 {
     sqlScriptGetters.Add(type, scriptGetter);
     sqlObjectTypes.Add(type, typeName);
 }