예제 #1
0
        /// <summary>
        /// Registers a new connection provider
        /// </summary>
        /// <param name="entry">The provider entry.</param>
        /// <param name="method">The factory method.</param>
        public static void RegisterProvider(ConnectionProviderEntry entry, ConnectionFactoryMethod method)
        {
            string name = entry.Name.ToUpper();

            if (_ctors.ContainsKey(name))
            {
                throw new ArgumentException(string.Format(Strings.ErrorProviderAlreadyRegistered, entry.Name));
            }

            _ctors[name] = method;
            _providers.Add(entry);
        }
예제 #2
0
        static ConnectionProviderRegistry()
        {
            _ctors     = new Dictionary <string, ConnectionFactoryMethod>();
            _providers = new List <ConnectionProviderEntry>();
            _callCount = new Dictionary <string, int>();

            var dir  = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            var path = System.IO.Path.Combine(dir, PROVIDER_CONFIG);

            _dllRoot = System.IO.Path.GetDirectoryName(path);

            XmlDocument doc = new XmlDocument();

            doc.Load(path);

            XmlNodeList providers = doc.SelectNodes("//ConnectionProviderRegistry/ConnectionProvider"); //NOXLATE

            foreach (XmlNode prov in providers)
            {
                string name = prov["Name"].InnerText.ToUpper(); //NOXLATE
                string desc = prov["Description"].InnerText;    //NOXLATE
                string dll  = prov["Assembly"].InnerText;       //NOXLATE
                string type = prov["Type"].InnerText;           //NOXLATE

                if (!System.IO.Path.IsPathRooted(dll))
                {
                    dll = System.IO.Path.Combine(_dllRoot, dll);
                }

                try
                {
                    Assembly asm = Assembly.LoadFrom(dll);
                    MaestroApiProviderAttribute[] attr = asm.GetCustomAttributes(typeof(MaestroApiProviderAttribute), true) as MaestroApiProviderAttribute[];
                    if (attr != null && attr.Length == 1)
                    {
                        name = attr[0].Name.ToUpper();
                        desc = attr[0].Description;
                        var impl = attr[0].ImplType;
                        _ctors[name] = new ConnectionFactoryMethod((initParams) =>
                        {
                            BindingFlags flags     = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance;
                            IServerConnection conn = (IServerConnection)impl.InvokeMember(null, flags, null, null, new object[] { initParams });
                            return(conn);
                        });
                        _providers.Add(new ConnectionProviderEntry(name, desc, dll, attr[0].IsMultiPlatform));
                        _callCount[name] = 0;
                    }
                }
                catch
                {
                }
            }
        }
예제 #3
0
        static ConnectionProviderRegistry()
        {
            _ctors     = new Dictionary <string, ConnectionFactoryMethod>();
            _providers = new List <ConnectionProviderEntry>();
            _callCount = new Dictionary <string, int>();

            //Maestro.Http is now built-in
            var httpProvider = HTTP_PROVIDER.ToUpper();

            _ctors[httpProvider] = new ConnectionFactoryMethod((initParams) =>
            {
                var conn = new HttpServerConnection(initParams);
                return(conn);
            });
            _providers.Add(new ConnectionProviderEntry(httpProvider, "HTTP Connection Provider", null, true));
            _callCount[httpProvider] = 0;
        }
예제 #4
0
        /// <summary>
        /// Creates an initialized <see cref="IServerConnection"/> object given the provider name and connection string
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="connectionString"></param>
        /// <remarks>
        /// The Maestro.Local provider (that wraps mg-desktop) and Maestro.LocalNative providers (that wraps the official MapGuide API)
        /// are unique in that it has global connection state. What this means is that subsequent connections after the first one for
        /// these providers may re-use existing state for the first connection. The reason for this is that creating this connection
        /// internally calls MgdPlatform.Initialize(iniFile) and MapGuideApi.MgInitializeWebTier(iniFile) respectively, that initializes
        /// the necessary library parameters in the process space of your application. Creating another connection will call
        /// MgdPlatform.Initialize and MapGuideApi.MgInitializeWebTier again, but these methods are by-design only made to be called once
        /// as subsequent calls are returned immediately.
        ///
        /// Basically, the connection parameters you pass in are for initializing the provider the first time round. Subsequent calls may not
        /// (most likely will not) respect the values of your connection parameters.
        ///
        /// You can programmatically check this via the <see cref="P:OSGeo.MapGuide.MaestroAPI.ConnectionProviderEntry.HasGlobalState"/> property
        /// </remarks>
        /// <returns></returns>
        public static IServerConnection CreateConnection(string provider, string connectionString)
        {
            string name = provider.ToUpper();

            if (!_ctors.ContainsKey(name))
            {
                throw new ArgumentException(string.Format(Strings.ErrorProviderNotRegistered, provider));
            }

            ConnectionProviderEntry prv = FindProvider(provider);

            if (prv != null && !prv.IsMultiPlatform && Platform.IsRunningOnMono)
            {
                throw new NotSupportedException(string.Format(Strings.ErrorProviderNotUsableForYourPlatform, provider));
            }

            ConnectionFactoryMethod method = _ctors[name];

            NameValueCollection initParams = ParseConnectionString(connectionString);
            IServerConnection   result     = method(initParams);

            _callCount[name]++;
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Registers a new connection provider
        /// </summary>
        /// <param name="entry">The provider entry.</param>
        /// <param name="method">The factory method.</param>
        public static void RegisterProvider(ConnectionProviderEntry entry, ConnectionFactoryMethod method)
        {
            string name = entry.Name.ToUpper();
            if (_ctors.ContainsKey(name))
                throw new ArgumentException(string.Format(Strings.ErrorProviderAlreadyRegistered, entry.Name));

            _ctors[name] = method;
            _providers.Add(entry);
        }
예제 #6
0
        static ConnectionProviderRegistry()
        {
            _ctors = new Dictionary<string, ConnectionFactoryMethod>();
            _providers = new List<ConnectionProviderEntry>();
            _callCount = new Dictionary<string, int>();

            var dir = System.IO.Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            var path = System.IO.Path.Combine(dir, PROVIDER_CONFIG);

            _dllRoot = System.IO.Path.GetDirectoryName(path);

            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlNodeList providers = doc.SelectNodes("//ConnectionProviderRegistry/ConnectionProvider"); //NOXLATE
            foreach (XmlNode prov in providers)
            {
                string name = prov["Name"].InnerText.ToUpper(); //NOXLATE
                string desc = prov["Description"].InnerText; //NOXLATE
                string dll = prov["Assembly"].InnerText; //NOXLATE
                string type = prov["Type"].InnerText; //NOXLATE

                if (!System.IO.Path.IsPathRooted(dll))
                    dll = System.IO.Path.Combine(_dllRoot, dll);

                try
                {
                    Assembly asm = Assembly.LoadFrom(dll);
                    MaestroApiProviderAttribute[] attr = asm.GetCustomAttributes(typeof(MaestroApiProviderAttribute), true) as MaestroApiProviderAttribute[];
                    if (attr != null && attr.Length == 1)
                    {
                        name = attr[0].Name.ToUpper();
                        desc = attr[0].Description;
                        var impl = attr[0].ImplType;
                        _ctors[name] = new ConnectionFactoryMethod((initParams) =>
                        {
                            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance;
                            IServerConnection conn = (IServerConnection)impl.InvokeMember(null, flags, null, null, new object[] { initParams });
                            return conn;
                        });
                        _providers.Add(new ConnectionProviderEntry(name, desc, dll, attr[0].IsMultiPlatform));
                        _callCount[name] = 0;
                    }
                }
                catch
                {

                }
            }
        }