Exemple #1
0
        public void TestCustomProperties()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var conn = CreateHttpConnection("http://tempuri.org", "en");

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

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

            Assert.NotNull(props);
            Assert.Equal(2, props.Length);
            Assert.True(Array.IndexOf <string>(props, HttpServerConnectionProperties.PROP_USER_AGENT) >= 0);
            Assert.True(Array.IndexOf <string>(props, HttpServerConnectionProperties.PROP_BASE_URL) >= 0);

            //It is of type string
            var type = isvc.GetCustomPropertyType(HttpServerConnectionProperties.PROP_USER_AGENT);

            Assert.Equal(typeof(string), type);
            type = isvc.GetCustomPropertyType(HttpServerConnectionProperties.PROP_BASE_URL);
            Assert.Equal(typeof(string), type);

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

            Assert.Equal("MapGuide Maestro API Unit Test Fixture", agent);

            //BaseUrl is read-only
            try
            {
                isvc.SetCustomProperty(HttpServerConnectionProperties.PROP_BASE_URL, "http://mylocalhost/mapguide");
                Assert.True(false, "Should've thrown exception");
            }
            catch { }
        }
Exemple #2
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 { }
        }
Exemple #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            using (new WaitCursor(this))
            {
                try
                {
                    PreferedSite ps = null;

                    if (_selectedIndex == 0) //HTTP
                    {
                        var builder = new System.Data.Common.DbConnectionStringBuilder();
                        builder["Url"]                  = _http.Server;                                                                       //NOXLATE
                        builder["Username"]             = _http.Username;                                                                     //NOXLATE
                        builder["Password"]             = _http.Password;                                                                     //NOXLATE
                        builder["Locale"]               = _http.Language;                                                                     //NOXLATE
                        builder["AllowUntestedVersion"] = true;                                                                               //NOXLATE

                        string agent = "MapGuide Maestro v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //NOXLATE

                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", builder.ToString());                              //NOXLATE
                        _conn.SetCustomProperty("UserAgent", agent);                                                                          //NOXLATE

                        //Update preferred site entry if it exists
                        int index = 0;
                        foreach (PreferedSite s in _http.GetSites())
                        {
                            if (s.SiteURL == _http.Server)
                            {
                                ps = s;
                                break;
                            }
                            else
                            {
                                index++;
                            }
                        }

                        if (ps == null)
                        {
                            ps = new PreferedSite();
                        }

                        if (ps.ApprovedVersion == null)
                        {
                            ps.ApprovedVersion = new Version(0, 0, 0, 0);
                        }

                        if (_conn.SiteVersion > _conn.MaxTestedVersion && _conn.SiteVersion > ps.ApprovedVersion)
                        {
                            if (MessageBox.Show(this, Strings.UntestedServerVersion, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) != DialogResult.Yes)
                            {
                                return;
                            }
                        }

                        try
                        {
                            ps.SiteURL         = _http.Server;
                            ps.StartingPoint   = _http.StartingPoint;
                            ps.Username        = _http.Username;
                            ps.SavePassword    = chkSavePassword.Checked;
                            ps.ApprovedVersion = ps.ApprovedVersion > _conn.SiteVersion ? ps.ApprovedVersion : _conn.SiteVersion;
                            if (ps.SavePassword)
                            {
                                ps.UnscrambledPassword = _http.Password;
                            }
                            else
                            {
                                ps.ScrambledPassword = string.Empty;
                            }

                            if (index >= _siteList.Sites.Length)
                            {
                                _siteList.AddSite(ps);
                            }

                            //_siteList.AutoConnect = chkAutoConnect.Checked;
                            _siteList.PreferedSite = index;
                            var ci = _http.SelectedCulture;
                            if (ci != null)
                            {
                                _siteList.GUILanguage = ci.Name;
                            }
                            _siteList.Save();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else if (_selectedIndex == 1) //Native
                    {
                        System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
                        builder["ConfigFile"] = LocalNativeLoginCtrl.LastIniPath;                                         //NOXLATE
                        builder["Username"]   = _localNative.Username;                                                    //NOXLATE
                        builder["Password"]   = _localNative.Password;                                                    //NOXLATE
                        builder["Locale"]     = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName; //NOXLATE
                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", builder.ToString());   //NOXLATE
                    }
                    else //Local
                    {
                        NameValueCollection param = new NameValueCollection();
                        param["ConfigFile"] = LocalLoginCtrl.LastIniPath;                            //NOXLATE
                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.Local", param); //NOXLATE
                    }

                    _conn.AutoRestartSession = true;

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (TargetInvocationException ex)
                {
                    //We don't care about the outer exception
                    string msg = ex.InnerException.Message;
                    if (msg.IndexOf("MgConnectionFailedException") >= 0)
                    {
                        new ConnectionErrorDialog().ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show(this, string.Format(Strings.ConnectionFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    if (msg.IndexOf("MgConnectionFailedException") >= 0)
                    {
                        new ConnectionErrorDialog().ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show(this, string.Format(Strings.ConnectionFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemple #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            using (new WaitCursor(this))
            {
                try
                {
                    PreferedSite ps = null;

                    if (_selectedIndex == 0) //HTTP
                    {
                        var builder = new System.Data.Common.DbConnectionStringBuilder();
                        builder["Url"] = _http.Server; //NOXLATE
                        builder["Username"] = _http.Username; //NOXLATE
                        builder["Password"] = _http.Password; //NOXLATE
                        builder["Locale"] = _http.Language; //NOXLATE
                        builder["AllowUntestedVersion"] = true; //NOXLATE

                        string agent = "MapGuide Maestro v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //NOXLATE

                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http", builder.ToString()); //NOXLATE
                        _conn.SetCustomProperty("UserAgent", agent); //NOXLATE

                        //Update preferred site entry if it exists
                        int index = 0;
                        foreach (PreferedSite s in _http.GetSites())
                        {
                            if (s.SiteURL == _http.Server)
                            {
                                ps = s;
                                break;
                            }
                            else
                                index++;
                        }

                        if (ps == null)
                            ps = new PreferedSite();

                        if (ps.ApprovedVersion == null)
                            ps.ApprovedVersion = new Version(0, 0, 0, 0);

                        if (_conn.SiteVersion > _conn.MaxTestedVersion && _conn.SiteVersion > ps.ApprovedVersion)
                        {
                            if (MessageBox.Show(this, Strings.UntestedServerVersion, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) != DialogResult.Yes)
                                return;
                        }

                        try
                        {
                            ps.SiteURL = _http.Server;
                            ps.StartingPoint = _http.StartingPoint;
                            ps.Username = _http.Username;
                            ps.SavePassword = chkSavePassword.Checked;
                            ps.ApprovedVersion = ps.ApprovedVersion > _conn.SiteVersion ? ps.ApprovedVersion : _conn.SiteVersion;
                            if (ps.SavePassword)
                                ps.UnscrambledPassword = _http.Password;
                            else
                                ps.ScrambledPassword = string.Empty;

                            if (index >= _siteList.Sites.Length)
                                _siteList.AddSite(ps);

                            //_siteList.AutoConnect = chkAutoConnect.Checked;
                            _siteList.PreferedSite = index;
                            var ci = _http.SelectedCulture;
                            if (ci != null)
                            {
                                _siteList.GUILanguage = ci.Name;
                            }
                            _siteList.Save();
                        }
                        catch (Exception)
                        {

                        }
                    }
                    else if (_selectedIndex == 1) //Native
                    {
                        System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
                        builder["ConfigFile"] = LocalNativeLoginCtrl.LastIniPath; //NOXLATE
                        builder["Username"] = _localNative.Username; //NOXLATE
                        builder["Password"] = _localNative.Password; //NOXLATE
                        builder["Locale"] = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName; //NOXLATE
                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", builder.ToString()); //NOXLATE
                    }
                    else //Local
                    {
                        NameValueCollection param = new NameValueCollection();
                        param["ConfigFile"] = LocalLoginCtrl.LastIniPath; //NOXLATE
                        _conn = ConnectionProviderRegistry.CreateConnection("Maestro.Local", param); //NOXLATE
                    }

                    _conn.AutoRestartSession = true;

                    this.DialogResult = DialogResult.OK;
                    this.Close();

                }
                catch (TargetInvocationException ex)
                {
                    //We don't care about the outer exception
                    string msg = ex.InnerException.Message;
                    MessageBox.Show(this, string.Format(Strings.ConnectionFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    MessageBox.Show(this, string.Format(Strings.ConnectionFailedError, msg), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }