static void ExecuteScripts(ScriptPackage package)
        {
            ScriptExecutor executor = new ScriptExecutor();

            if (_selectedSwitches.HasFlag(Switches.Verbose))
                executor.LogUpdated += new ScriptExecutor.LogChanged(executor_LogUpdated);
            else if (!_selectedSwitches.HasFlag(Switches.Verbose) && !_selectedSwitches.HasFlag(Switches.Quiet))
                foreach (Script script in package.Scripts)
                    script.StatusChanged += new Script.ScriptChange(script_StatusChanged);

            executor.ExecuteScripts(package.Scripts);

            while (executor.IsExecuting)
                Thread.Sleep(1000);

            foreach (Script script in package.Scripts)
            {
                if (script.Status == ScriptStatus.Disabled || script.Status == ScriptStatus.Executed)
                    continue;

                Environment.ExitCode = 1;
                System.Console.WriteLine("One or more scripts failed to execute properly.");
                break;
            }
        }
 public PackageScriptResource(ScriptPackage package, string scriptLocation, string content)
 {
     this._package = package;
     this._scriptLocation = scriptLocation;
     this._content = content;
 }
        private static void ListScripts(ScriptPackage package)
        {
            foreach (Script script in package.Scripts)
            {
                System.Console.WriteLine(string.Join("\t", script.ContentResource.Location, script.ScriptType, script.Connection.ConnectionName));

                if (_selectedSwitches.HasFlag(Switches.Verbose))
                {
                    System.Console.WriteLine(script.ScriptContents);
                    System.Console.WriteLine(script.Connection.ConnectionString);
                }
            }
        }
        private static ScriptPackage LoadPackage(string path)
        {
            if (!File.Exists(path))
                ExitProgram("File '" + path + "' does not exist.", true);

            ScriptPackage package = new ScriptPackage();
            package.Load(_packageFile);
            return package;
        }
        private void SaveScriptPackage_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            SaveFileDialog packageSave = new SaveFileDialog();
            packageSave.CheckFileExists = false;
            packageSave.Filter = SCRIPT_PACKAGE_FILTER;
            packageSave.AddExtension = true;
            packageSave.DefaultExt = "sp";

            if (packageSave.ShowDialog() != true)
                return;

            ScriptPackage package = new ScriptPackage();
            var scripts = (from ScriptWrapper wrapper in Scripts
                           select wrapper.Script);

            package.Scripts.Add(scripts);
            package.Save(packageSave.FileName);
        }
        private void LoadScriptPackage_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog packageLoad = new OpenFileDialog();
            packageLoad.Filter = SCRIPT_PACKAGE_FILTER;
            packageLoad.CheckFileExists = true;

            if (packageLoad.ShowDialog() != true)
                return;

            ScriptPackage package = new ScriptPackage();
            package.Load(packageLoad.FileName);

            this.Scripts.Clear();
            foreach (Script script in package.Scripts)
            {
                DatabaseConnection matchingConnection = (from connection in DatabaseConnections
                                                         where connection.ConnectionString == script.Connection.ConnectionString
                                                         select connection).FirstOrDefault();

                if (matchingConnection == null)
                {
                    matchingConnection = new DatabaseConnection("[PACKAGE] " + script.Connection.ConnectionName, script.Connection.ConnectionString);
                    this.DatabaseConnections.Add(matchingConnection);
                }

                script.Connection = matchingConnection;
                this.Scripts.Add(new ScriptWrapper(script));
            }
        }
 public PackageScriptResource(ScriptPackage package, string scriptLocation, string content)
 {
     this._package        = package;
     this._scriptLocation = scriptLocation;
     this._content        = content;
 }