public static void AddDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!contexts.Contains(context))
            {
                contexts.Add(context);
                Save();
                if (ConnectionContextAdded != null)
                {
                    ConnectionContextAdded(null, new DatabaseConnectionContextEventArgs(context));
                }
            }
        }
Ejemplo n.º 2
0
        internal static void Initialize(string configFile)
        {
            DatabaseConnectionSettingsCollection connections = null;

            if (File.Exists(configFile))
            {
                try {
                    using (FileStream fs = File.OpenRead(configFile)) {
                        XmlSerializer serializer = new XmlSerializer(typeof(DatabaseConnectionSettingsCollection));
                        connections = (DatabaseConnectionSettingsCollection)serializer.Deserialize(fs);
                    }
                } catch {
                    LoggingService.LogError(AddinCatalog.GetString("Unable to load stored SQL connection information."));
                    File.Delete(configFile);
                }
            }

            contexts = new DatabaseConnectionContextCollection();
            if (connections != null)
            {
                StringBuilder sb = new StringBuilder();
                foreach (DatabaseConnectionSettings settings in connections)
                {
                    IDbFactory fac = DbFactoryService.GetDbFactory(settings);
                    if (fac == null)
                    {
                        sb.Append("Error: unable to load database provider '");
                        sb.Append(settings.ProviderIdentifier);
                        sb.Append("' for connection '");
                        sb.Append(settings.Name);
                        sb.Append("'");
                        sb.Append(Environment.NewLine);
                        continue;
                    }

                    contexts.Add(new DatabaseConnectionContext(settings));
                }

                if (sb.Length > 0)
                {
                    Exception ex = new Exception(sb.ToString());
                    QueryService.RaiseException(ex);
                }
            }
        }
Ejemplo n.º 3
0
        public static void AddDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!DatabaseConnectionContextExist(context.ConnectionSettings))
            {
                contexts.Add(context);
                Save();
                if (ConnectionContextAdded != null)
                {
                    ConnectionContextAdded(null, new DatabaseConnectionContextEventArgs(context));
                }
            }
            else
            {
                throw new DuplicatedConnectionContextException(context.ConnectionSettings.Name);
            }
        }