Пример #1
0
        private static object RunBaselineOption(BaselineOption opts)
        {
            try
            {
                //use default app directory when not specified explicitly
                if (string.IsNullOrEmpty(opts.Path))
                {
                    opts.Path = Environment.CurrentDirectory;
                }

                //use environment variable when not specified explicitly
                if (string.IsNullOrEmpty(opts.ConnectionString))
                {
                    var environmentService = new EnvironmentService();
                    opts.ConnectionString = environmentService.GetEnvironmentVariable("YUNIQLX_BASELINE_CONNECTION_STRING");
                }

                var baselineService = new BaselineService();
                baselineService.Run(opts.ConnectionString, opts.Path);

                TraceService.Info($"Initialized {opts.Path}.");
            }
            catch (Exception ex)
            {
                TraceService.Error($"Failed to execute init function. {Environment.NewLine}{ex.ToString()}");
                throw;
            }

            return(0);
        }
Пример #2
0
        private void GenerateSchemaBasedScriptFiles(string connectionString, Scripter scripter, string destinationDirectory, List <Urn> urns)
        {
            var serverConnection = CreateServerConnection(connectionString);
            var server           = new Server(serverConnection);

            try
            {
                server.ConnectionContext.Connect();

                var sequenceNo = 1;
                foreach (var urn in urns)
                {
                    if (processedUrns.Contains(urn))
                    {
                        continue;
                    }

                    var smo = server.GetSmoObject(urn) as ScriptNameObjectBase;
                    if (null != smo)
                    {
                        var baseFileName = $"{smo.Name}";

                        if (smo is ScriptSchemaObjectBase)
                        {
                            var ssmo = smo as ScriptSchemaObjectBase;
                            if (!string.IsNullOrEmpty(ssmo.Schema))
                            {
                                baseFileName = $"{ssmo.Schema}.{ssmo.Name}";
                            }
                        }

                        scripter.Options.FileName = Path.Combine(destinationDirectory, $"{sequenceNo.ToString("000")}-{baseFileName}.sql");
                        scripter.Script(new Urn[] { urn });

                        processedUrns.Add(urn);
                        sequenceNo++;

                        TraceService.Info($"Generated script file {scripter.Options.FileName}");
                    }
                    else
                    {
                        TraceService.Error($"Failed to generate scripts for urn: {urn}");
                    }
                }
            }
            catch (Exception ex)
            {
                TraceService.Error($"Error generating schema files. {ex.ToString()}");
                throw;
            }
            finally
            {
                if (server.ConnectionContext.IsOpen)
                {
                    server.ConnectionContext.Disconnect();
                    server = null;
                }
            }
        }
Пример #3
0
 private void Scripter_ScriptingError(object sender, ScriptingErrorEventArgs e)
 {
     TraceService.Error($"Error scripting {e.Current.Value}. {e.InnerException.ToString()}");
 }