Exemplo n.º 1
0
 public MySqlDbExportSaveOptions()
 {
     DumpOptions       = new MySqlDbExportOptions();
     PathToMySqlFile   = "";
     _dictionary       = new List <DictionaryDbObjects>();
     _connectionString = new MySqlConnectionStringBuilder().ConnectionString;
 }
Exemplo n.º 2
0
        public MySqlDumpFacade(MySqlDbExportOptions options, string saveToFile, string credentialsFile, List <string> tables) : this(options, saveToFile, credentialsFile)
        {
            _arguments.Append(" --tables ");

            foreach (var table in tables)
            {
                _arguments.AppendFormat(" {0} ", table);
            }

            _tables = tables;
        }
Exemplo n.º 3
0
        public MySqlDumpFacade(MySqlDbExportOptions options, string saveToFile, string credentialsFile)
        {
            if (options == null)
            {
                throw new Exception("MySqlDump start options are not valid");
            }

            if (string.IsNullOrEmpty(saveToFile))
            {
                throw new Exception("MySqlDump file Path is not set");
            }

            if (string.IsNullOrEmpty(credentialsFile))
            {
                throw new Exception("Options to start export action are not completed.");
            }

            _credentialsFile = credentialsFile;

            _arguments    = new StringBuilder();
            _dumpOutput   = new StringBuilder();
            _errorsOutput = new StringBuilder();
            _logInfo      = new StringBuilder();

            _dumpFilePath = Utilities.GetMySqlAppInstallLocation("MySQL for Visual Studio");
            if (!string.IsNullOrEmpty(_dumpFilePath))
            {
                _dumpFilePath = Path.Combine(_dumpFilePath, @"Dependencies\mysqldump.exe");
            }

            IVsOutputWindow outWindow       = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
            Guid            generalPaneGuid = VSConstants.GUID_OutWindowGeneralPane;

            if (outWindow != null)
            {
                outWindow.CreatePane(ref generalPaneGuid, "General", 1, 0);
                outWindow.GetPane(ref generalPaneGuid, out _generalPane);
            }

            _tables = null;

            saveTofilePath = saveToFile;
            BuildCommandLine(options);
        }
Exemplo n.º 4
0
        public MySqlDbExport(MySqlDbExportOptions options, string outputFilePath, MySqlConnection conn, List <string> tables, bool overwriteFile)
        {
            if (options == null)
            {
                throw new Exception("Export options are not valid");
            }

            if (conn == null)
            {
                throw new Exception("Connection is not valid for the Export operation");
            }

            if (string.IsNullOrEmpty(outputFilePath))
            {
                throw new Exception("Path to save dump file is not set.");
            }

            if (tables != null)
            {
                _tables = tables;
            }

            ExportOptions  = options;
            OutputFilePath = outputFilePath;

            var connBuilder = new MySqlConnectionStringBuilder(conn.ConnectionString);

            ExportOptions.host     = connBuilder.Server;
            ExportOptions.port     = (int)connBuilder.Port;
            ExportOptions.database = connBuilder.Database;

            if (connBuilder.SslMode != MySqlSslMode.Required)
            {
                ExportOptions.ssl_cert = connBuilder.CertificateFile;
            }

            _fileName     = string.Empty;
            _appendToFile = !overwriteFile;
            CreateIsolatedFile(conn);
        }
Exemplo n.º 5
0
        public MySqlDbExportSaveOptions(MySqlDbExportOptions optionsForDump,
                                        string completePathToMySqlFile,
                                        Dictionary <string, BindingList <DbSelectedObjects> > dictionaryToDbObjects,
                                        string connectionStringToUse)
        {
            DumpOptions       = optionsForDump;
            PathToMySqlFile   = completePathToMySqlFile;
            _connectionString = connectionStringToUse;

            foreach (var items in dictionaryToDbObjects)
            {
                foreach (var item in items.Value)
                {
                    var objectToExport = new DictionaryDbObjects();
                    objectToExport.DatabaseName = items.Key;
                    objectToExport.ObjectName   = item.DbObjectName;
                    objectToExport.ObjectType   = item.Kind;
                    objectToExport.Selected     = item.Selected;
                    _dictionary.Add(objectToExport);
                }
            }
        }
Exemplo n.º 6
0
        internal void BuildCommandLine(MySqlDbExportOptions options)
        {
            Type type = options.GetType();

            IList <PropertyInfo> props = new List <PropertyInfo>(type.GetProperties(BindingFlags.Public | BindingFlags.Instance));

            foreach (var prop in props)
            {
                if (prop != null)
                {
                    string value;
                    options.dictionary.TryGetValue(prop, out value);

                    if (value == null)
                    {
                        continue;
                    }

                    var propType = prop.PropertyType;
                    switch (propType.ToString())
                    {
                    case "System.Boolean":
                        bool propValue;
                        propValue = (bool)prop.GetValue(options, null);
                        _arguments.AppendFormat(" {0}{1} ", value, !propValue ? "=false": "");
                        break;

                    case "System.String":
                        string sValue;
                        sValue = (string)prop.GetValue(options, null);
                        if (!string.IsNullOrEmpty(sValue))
                        {
                            if (!prop.Name.Equals("database"))
                            {
                                _arguments.AppendFormat(" {0}={1}", value, sValue);
                            }
                            else
                            {
                                _database = sValue;
                            }
                        }
                        break;

                    case "System.Int32":
                        int intValue;
                        intValue = (int)prop.GetValue(options, null);
                        if (prop.Name.Equals("max_allowed_packet", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (intValue < 1024)
                            {
                                _arguments.AppendFormat(" {0}={1}MB", value, intValue.ToString());
                            }
                            else
                            {
                                _arguments.AppendFormat(" {0}=1G", value);
                            }
                        }
                        else
                        {
                            _arguments.AppendFormat(" {0}={1}", value, intValue.ToString());
                        }
                        break;
                    }
                }
            }
            //TODO add a new property to define variables
            // so we can accept a ON/OFF value
            _arguments.Append(" --set-gtid-purged=OFF --protocol=TCP ");
            _arguments.AppendFormat(" \"{0}\"", _database);
        }