Example #1
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;
        }
Example #2
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);
            }
        }