Ejemplo n.º 1
0
        public static void DeployFile(string newCode)
        {
            if (String.IsNullOrEmpty(ConnectionString))
            {
                var connectDialog = new ConnectDialog();
                connectDialog.ShowDialog();
                ConnectionString = connectDialog.ConnectionString;

                if (String.IsNullOrEmpty(ConnectionString))
                {
                    return;
                }
            }

            var procedures    = ScriptDom.GetProcedures(newCode);
            var deployScripts = new List <string>();

            foreach (var procedure in procedures)
            {
                OutputPane.WriteMessage("Deploying {0}", procedure.ProcedureReference.Name.ToQuotedString());
                Deploy(BuildIfNotExistsStatements(procedure));
                Deploy(ChangeCreateToAlter(procedure, newCode));
                OutputPane.WriteMessage("Deploying {0}...Done", procedure.ProcedureReference.Name.ToQuotedString());
            }

            var functions = ScriptDom.GetFunctions(newCode);

            foreach (var function in functions)
            {
                OutputPane.WriteMessage("Deploying {0}", function.Name.ToQuotedString());
                if (function.ReturnType is SelectFunctionReturnType)
                {
                    Deploy(BuildIfNotExistsStatementsInlineFunction(function));
                }
                else
                {
                    Deploy(BuildIfNotExistsStatements(function));
                }

                Deploy(ChangeCreateToAlter(function, newCode));
                OutputPane.WriteMessage("Deploying {0}...Done", function.Name.ToQuotedString());
            }

            foreach (var statement in deployScripts)
            {
                Deploy(statement);
            }
            //Deploy();
        }
Ejemplo n.º 2
0
        public static string GetDeployScript(string newCode)
        {
            var procedures    = ScriptDom.GetProcedures(newCode);
            var deployScripts = new List <string>();

            foreach (var procedure in procedures)
            {
                OutputPane.WriteMessage("Generating Deploy Script for {0}", procedure.ProcedureReference.Name.ToQuotedString());
                deployScripts.Add(BuildIfNotExistsStatements(procedure));
                deployScripts.Add(ChangeCreateToAlter(procedure, newCode));
            }

            var functions = ScriptDom.GetFunctions(newCode);

            foreach (var function in functions)
            {
                OutputPane.WriteMessage("Generating script for {0}", function.Name.ToQuotedString());
                if (function.ReturnType is SelectFunctionReturnType)
                {
                    deployScripts.Add(BuildIfNotExistsStatementsInlineFunction(function));
                }
                else
                {
                    deployScripts.Add(BuildIfNotExistsStatements(function));
                }

                deployScripts.Add(ChangeCreateToAlter(function, newCode));
            }

            StringBuilder script = new StringBuilder();

            foreach (var statement in deployScripts)
            {
                script.AppendFormat("{0}\r\nGO\r\n", statement);
            }

            return(script.ToString());
        }
Ejemplo n.º 3
0
        protected override void UpdateWordAdornments()
        {
            try
            {
                var dte = (DTE)VsServiceProvider.Get(typeof(DTE));

                if (dte.ActiveDocument == null)
                {
                    return;
                }

                if (RequestedPoint.Snapshot.ContentType.TypeName != "SQL Server Tools" || !RequestedPoint.Snapshot.ContentType.BaseTypes.Any(p => p.IsOfType("code")))
                {
                    return;
                }



                try
                {
                    var store = CodeCoverageStore.Get;

                    var path = dte.ActiveDocument.FullName;

                    if (store.ObjectsInFile(path) == null)
                    {
                        return;
                    }

                    var yellowWordSpans = new List <SnapshotSpan>();
                    var redWordSpans    = new List <SnapshotSpan>();

                    if (null != store && CodeCoverageTaggerSettings.Enabled)
                    {
                        var documentKey = string.Format("{0}:{1}", RequestedPoint.Snapshot.Length, RequestedPoint.Snapshot.Version.VersionNumber);

                        var script = GetCurrentDocumentText(dte);

                        foreach (var proc in ScriptDom.GetProcedures(script))
                        {
                            var name = proc?.ProcedureReference.Name.ToNameString();

                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }

                            var statements = store.GetCoveredStatements(name, path);

                            if (statements == null)
                            {
                                continue;
                            }

                            if (statements.Any(p => p.TimeStamp < File.GetLastWriteTimeUtc(path)))
                            {
                                continue;
                            }

                            foreach (var statement in statements)
                            {
                                var offset = proc.StartOffset + (int)statement.Offset;
                                if (offset + statement.Length > script.Length)
                                {
                                    continue; //bad things!
                                }
                                if (statement.Length > -1)
                                {
                                    var span = new SnapshotSpan(new SnapshotPoint(RequestedPoint.Snapshot, offset), (int)statement.Length + 1);
                                    yellowWordSpans.Add(span);
                                }
                                else
                                {
                                    var span = new SnapshotSpan(new SnapshotPoint(RequestedPoint.Snapshot, offset), (proc.FragmentLength - offset));
                                    yellowWordSpans.Add(span);
                                }
                            }
                        }

                        foreach (var proc in ScriptDom.GetFunctions(script))
                        {
                            var name = proc?.Name.ToNameString();

                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }

                            var statements = store.GetCoveredStatements(name, path);

                            if (statements == null)
                            {
                                continue;
                            }

                            foreach (var statement in statements)
                            {
                                var offset = proc.StartOffset + (int)statement.Offset;
                                if (offset + statement.Length > script.Length)
                                {
                                    continue; //bad things!
                                }
                                if (statement.Length > -1)
                                {
                                    var span = new SnapshotSpan(new SnapshotPoint(RequestedPoint.Snapshot, offset), (int)statement.Length + 1);
                                    yellowWordSpans.Add(span);
                                }
                                else
                                {
                                    var span = new SnapshotSpan(new SnapshotPoint(RequestedPoint.Snapshot, offset), (proc.FragmentLength - offset) + 1);
                                    yellowWordSpans.Add(span);
                                }
                            }
                        }

                        if (documentKey != string.Format("{0}:{1}", RequestedPoint.Snapshot.Length, RequestedPoint.Snapshot.Version.VersionNumber))
                        {
                            return;
                        }
                    }



                    var currentRequest = RequestedPoint;
                    var word           = TextStructureNavigator.GetExtentOfWord(currentRequest);
                    var currentWord    = word.Span;

                    //If another change hasn't happened, do a real update
                    if (currentRequest == RequestedPoint)
                    {
                        SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(yellowWordSpans), new NormalizedSnapshotSpanCollection(redWordSpans), currentWord);
                    }
                }

                catch (Exception)
                {
                    // MessageBox.Show("2 - e : " + e.Message + " \r\n " + e.StackTrace);
                }
            }
            catch (Exception)
            {
                // MessageBox.Show("2 - e : " + e.Message + " \r\n " + e.StackTrace);
            }
        }