Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, this is a simple console app used to test the SqlScanner class.");

            var messageList = new List <Azure>();

            var inputFilePath  = @"c:\sqltest\tests\input\";
            var outputFilePath = @"c:\sqltest\tests\output\";

            var filePaths = Directory.GetFiles(inputFilePath, "*.SqlDataProvider");

            foreach (var filePath in filePaths)
            {
                var fileName     = filePath.Replace(inputFilePath, "");
                var azureScanner = new ScriptScanner();
                messageList.AddRange(azureScanner.ProcessAzure(filePath, outputFilePath + fileName));
            }

            filePaths = Directory.GetFiles(outputFilePath, "*.SqlDataProvider");

            foreach (var filePath in filePaths)
            {
                var fileName     = filePath.Replace(inputFilePath, "");
                var azureScanner = new ScriptScanner();
                messageList.AddRange(azureScanner.LogAzure(filePath));
            }

            foreach (var azure in messageList)
            {
                Console.WriteLine(azure.ToString());
            }

            Console.WriteLine("Done.");

            Console.ReadKey();
        }
Esempio n. 2
0
        public void ProcessScripts(List <VerificationMessage> r, Package package, Models.Manifest manifest)
        {
            try
            {
                var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                Directory.CreateDirectory(tempPath);
                var messageList  = new List <Azure>();
                var azureScanner = new ScriptScanner();

                foreach (var sqlScriptFile in manifest.InstallScripts)
                {
                    if (!File.Exists(sqlScriptFile.TempFilePath) || sqlScriptFile.IsUnInstall)
                    {
                        continue;
                    }

                    //we have script files, now let's see if they will work in Azure.
                    string fileName;

                    if (sqlScriptFile.TempFilePath.Contains("\\"))
                    {
                        var fileParts = sqlScriptFile.TempFilePath.Split('\\');
                        fileName = fileParts[fileParts.Length - 1];
                    }
                    else
                    {
                        fileName = sqlScriptFile.Name;
                    }

                    messageList.AddRange(azureScanner.ProcessAzure(sqlScriptFile.TempFilePath,
                                                                   tempPath + "\\" + fileName));
                }

                //var outputFilePaths = Directory.GetFiles(tempPath, "*.SqlDataProvider");
                var outputFilePaths = Directory.GetFiles(tempPath, "*.sql");

                package.SQLOutputPath = tempPath;

                foreach (var filePath in outputFilePaths)
                {
                    messageList.AddRange(azureScanner.LogAzure(filePath));
                }

                foreach (var azure in messageList)
                {
                    var messageType = azure.MessageType.ToString();

                    if (messageType == Models.MessageTypes.Error.ToString())
                    {
                        r.Add(new VerificationMessage
                        {
                            Message     = azure.ToString(),
                            MessageType = Models.MessageTypes.Error,
                            MessageId   = new Guid("6f6ed7be-c182-4baf-a369-809b7d99549a"),
                            Rule        = GetType().ToString()
                        });
                    }
                    else if (messageType == Models.MessageTypes.Info.ToString())
                    {
                        //r.Add(new Models.VerificationMessage { Message = azure.ToString(), MessageType = Models.MessageTypes.Info, MessageId = new Guid("1d4eba86-a23f-4bd0-afdf-430ed4c4a2a8"), Rule = GetType().ToString() });
                    }
                    else if (messageType == Models.MessageTypes.SystemError.ToString())
                    {
                        r.Add(new VerificationMessage
                        {
                            Message     = azure.ToString(),
                            MessageType = Models.MessageTypes.SystemError,
                            MessageId   = new Guid("a2cb34dd-c882-4302-ade0-d38c75e98fa2"),
                            Rule        = GetType().ToString()
                        });
                    }
                    else if (messageType == Models.MessageTypes.Warning.ToString())
                    {
                        r.Add(new VerificationMessage
                        {
                            Message     = azure.ToString(),
                            MessageType = Models.MessageTypes.Warning,
                            MessageId   = new Guid("3a9452d3-dce5-4f78-93af-12645ae224ac"),
                            Rule        = GetType().ToString()
                        });
                    }
                    else
                    {
                        r.Add(new VerificationMessage
                        {
                            Message     = "Could not parse the SQL Azure error message type.",
                            MessageType = Models.MessageTypes.SystemError,
                            MessageId   = new Guid("4fef4b2c-4b8d-4ff9-b345-072a53a84a35"),
                            Rule        = GetType().ToString()
                        });
                    }
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine("There was an issue with the SQL Azure scanner", exc.Message);
                r.Add(new VerificationMessage
                {
                    Message     = "An Error occurred while processing Rules.Manifest.Components.Scripts: " + exc.Message,
                    MessageType = Models.MessageTypes.SystemError,
                    MessageId   = new Guid("6addcb0f-41c7-4b8f-b521-ca5f92d26285"),
                    Rule        = GetType().ToString()
                });
            }
        }