示例#1
0
        public void TestCustomProperties()
        {
            var builder = new RequestBuilder(new Uri("http://tempuri.org"), "en");
            var conn = new HttpServerConnection(builder);

            //Work through the interface
            IServerConnection isvc = (IServerConnection)conn;

            //UserAgent is exposed as a custom property
            var props = isvc.GetCustomPropertyNames();

            Assert.IsNotNull(props);
            Assert.AreEqual(props.Length, 2);
            Assert.IsTrue(Array.IndexOf<string>(props, HttpServerConnection.PROP_USER_AGENT) >= 0);
            Assert.IsTrue(Array.IndexOf<string>(props, HttpServerConnection.PROP_BASE_URL) >= 0);

            //It is of type string
            var type = isvc.GetCustomPropertyType(HttpServerConnection.PROP_USER_AGENT);
            Assert.AreEqual(type, typeof(string));
            type = isvc.GetCustomPropertyType(HttpServerConnection.PROP_BASE_URL);
            Assert.AreEqual(type, typeof(string));

            //We can set and get it
            isvc.SetCustomProperty(HttpServerConnection.PROP_USER_AGENT, "MapGuide Maestro API Unit Test Fixture");
            var agent = (string)isvc.GetCustomProperty(HttpServerConnection.PROP_USER_AGENT);
            Assert.AreEqual(agent, "MapGuide Maestro API Unit Test Fixture");

            //BaseUrl is read-only
            try
            {
                isvc.SetCustomProperty(HttpServerConnection.PROP_BASE_URL, "http://mylocalhost/mapguide");
                Assert.Fail("Should've thrown exception");
            }
            catch { }
        }
 internal HttpCoordinateSystemCatalog(HttpServerConnection con, RequestBuilder req)
 {
     m_con = con;
     m_req = req;
 }
示例#3
0
        private void InitConnection(Uri hosturl, string username, string password, string locale, bool allowUntestedVersion, string geoRestUrl, string geoRestConfigPath)
        {
            if (!string.IsNullOrEmpty(geoRestUrl))
            {
                _geoRestConn = new GeoRestConnection(geoRestUrl, geoRestConfigPath);
            }

            m_reqBuilder = new RequestBuilder(hosturl, locale);
            mAnonymousUser = (username == "Anonymous");

            _cred = new NetworkCredential(username, password);
            string req = m_reqBuilder.CreateSession();

            m_username = username;
            m_password = password;

            try
            {
                this.RestartSession();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to connect, please check network connection and login information.\nExtended error info: " + NestedExceptionMessageProcessor.GetFullMessage(ex), ex);
            }

            if (!allowUntestedVersion)
                ValidateVersion(this.SiteVersion);
            m_username = username;
            m_password = password;
        }
示例#4
0
        private void InitConnection(Uri hosturl, string sessionid, string locale, bool allowUntestedVersion, string geoRestUrl, string geoRestConfigPath)
        {
            DisableAutoSessionRecovery();
            if (!string.IsNullOrEmpty(geoRestUrl))
            {
                _geoRestConn = new GeoRestConnection(geoRestUrl, geoRestConfigPath);
            }

            m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid, true);
            string req = m_reqBuilder.GetSiteVersion();
            SiteVersion sv = null;
            try
            {
                sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), OpenRead(req));
            }
            catch (Exception ex)
            {
                sv = null;
                bool ok = false;
                try
                {
                    //Retry, and append missing path, if applicable
                    if (!hosturl.ToString().EndsWith("/mapagent/mapagent.fcgi"))
                    {
                        string tmp = hosturl.ToString();
                        if (!tmp.EndsWith("/"))
                            tmp += "/";
                        hosturl = new Uri(tmp + "mapagent/mapagent.fcgi");
                        m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid, true);
                        req = m_reqBuilder.GetSiteVersion();
                        sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), OpenRead(req));
                        ok = true;
                    }
                }
                catch { }

                if (!ok) //Report original error
                    throw new Exception("Failed to connect, perhaps session is expired?\nExtended error info: " + NestedExceptionMessageProcessor.GetFullMessage(ex), ex);
            }
            if (!allowUntestedVersion)
                ValidateVersion(sv);

            lock (SyncRoot)
            {
                m_siteVersion = new Version(sv.Version);
            }
        }
示例#5
0
        /// <summary>
        /// Restarts the server session, and creates a new session ID
        /// </summary>
        /// <param name="throwException">If set to true, the call throws an exception if the call failed</param>
        /// <returns>True if the creation succeed, false otherwise</returns>
        protected override bool RestartSessionInternal(bool throwException)
        {
            if (m_username == null || m_password == null)
                if (throwException)
                    throw new Exception("Cannot recreate session, because connection was not opened with username and password");
                else
                    return false;

            Uri hosturl = new Uri(m_reqBuilder.HostURI);
            string locale = m_reqBuilder.Locale;
            string oldSessionId = m_reqBuilder.SessionID;

            try
            {
                RequestBuilder reqb = new RequestBuilder(hosturl, locale);
                WebClient wc = new WebClient();
                wc.Credentials = new NetworkCredential(m_username, m_password);
                string req = reqb.CreateSession();

                try
                {
                    reqb.SessionID = System.Text.Encoding.Default.GetString(wc.DownloadData(req));
                    if (reqb.SessionID.IndexOf("<") >= 0)
                        throw new Exception("Invalid server token recieved: " + reqb.SessionID);
                    else
                        CheckAndRaiseSessionChanged(oldSessionId, reqb.SessionID);
                }
                catch (Exception ex)
                {
                    reqb.SessionID = null;
                    bool ok = false;
                    try
                    {
                        //Retry, and append missing path, if applicable
                        if (!hosturl.ToString().EndsWith("/mapagent/mapagent.fcgi"))
                        {
                            string tmp = hosturl.ToString();
                            if (!tmp.EndsWith("/"))
                                tmp += "/";
                            hosturl = new Uri(tmp + "mapagent/mapagent.fcgi");
                            reqb = new RequestBuilder(hosturl, locale);
                            req = reqb.CreateSession();
                            reqb.SessionID = System.Text.Encoding.Default.GetString(wc.DownloadData(req));
                            if (reqb.SessionID.IndexOf("<") >= 0)
                                throw new Exception("Invalid server token recieved: " + reqb.SessionID);
                            ok = true;
                        }
                    }
                    catch {}

                    if (!ok)
                    {
                        if (throwException) //Report original error
                        {
                            if (ex is WebException) //These exceptions, we just want the underlying message. No need for 50 bajillion nested exceptions
                                throw;
                            else //We don't know what this could be so grab everything
                                throw new Exception("Failed to connect, perhaps session is expired?\nExtended error info: " + ex.Message, ex);
                        }
                        else
                            return false;
                    }
                    else
                    {
                        CheckAndRaiseSessionChanged(oldSessionId, reqb.SessionID);
                    }
                }

                //Reset cached items
                lock (SyncRoot)
                {
                    m_siteVersion = new Version(((SiteVersion)DeserializeObject(typeof(SiteVersion), wc.OpenRead(reqb.GetSiteVersion()))).Version);

                    m_featureProviders = null;
                    m_cachedProviderCapabilities = null;
                    m_reqBuilder = reqb;
                }

                return true;
            }
            catch
            {
                if (throwException)
                    throw;
                else
                    return false;
            }
        }
示例#6
0
 internal HttpServerConnection(RequestBuilder builder)
     : this()
 {
     m_reqBuilder = builder;
 }
示例#7
0
        public void TestServiceCapabilities()
        {
            var builder = new RequestBuilder(new Uri("http://tempuri.org"), "en");
            var conn = new HttpServerConnection(builder);
            conn.SetSiteVersion(new Version(1, 2, 0));

            //Work through the interface
            IServerConnection isvc = (IServerConnection)conn;
            int[] stypes = isvc.Capabilities.SupportedServices;
            foreach (int st in stypes)
            {
                try
                {
                    IService svc = isvc.GetService(st);
                }
                catch
                {
                    Assert.Fail("Supported service type mismatch");
                }
            }

            conn.SetSiteVersion(new Version(2, 0, 0));

            stypes = isvc.Capabilities.SupportedServices;
            foreach (int st in stypes)
            {
                try
                {
                    IService svc = isvc.GetService(st);
                }
                catch
                {
                    Assert.Fail("Supported service type mismatch");
                }
            }
        }