Пример #1
0
        public void TestSimpleFunctionObjectArgument()
        {
            using (var form = new BrowserTestForm())
            {
                var bridge = new ScriptingBridge(form.WebBrowser, true);
                var waiter = new WaitForFormsEvent();
                form.WebBrowser.DocumentCompleted += (sender, args) =>
                {
                    var parameter = new ParameterObject();
                    var result    = bridge.InvokeFunction <ParameterObject>("anObject.simpleArgumentFunction", parameter);
                    Assert.Equal(parameter.TestDate, result.TestDate);
                    Assert.Equal(parameter.TestString, result.TestString);

                    waiter.SetEvent();
                };

                form.Show();
                form.WebBrowser.Url = new Uri(String.Format("file:///{0}/TestPage.html", Directory.GetCurrentDirectory()));

                // Wait for the document to load.
                Assert.True(waiter.WaitForEvent(2000));
            }
        }
Пример #2
0
        void BtnGCNCreateClick(object sender, EventArgs e)
        {
            // On vérifie
            // coordonnées
            Double dLat = Double.MaxValue;
            Double dLon = Double.MaxValue;
            String sLat = "";
            String sLon = "";
            bool   bOK  = ParameterObject.TryToConvertCoordinates(tbGCNCenter.Text, ref sLat, ref sLon);

            if (sLat != CoordConvHMI._sErrorValue)
            {
                dLat = MyTools.ConvertToDouble(sLat);
            }
            if (sLon != CoordConvHMI._sErrorValue)
            {
                dLon = MyTools.ConvertToDouble(sLon);
            }
            if (!bOK)
            {
                DisplayError(lblGCNCentre.Text, _daddy.GetTranslator().GetString("WaypointCoord"), tbGCNCenter.Text, "");
                return;
            }

            // nom
            if (tbGCNName.Text == "")
            {
                DisplayError(lblGCNNom.Text, _daddy.GetTranslator().GetString("lblnotempty"), tbGCNName.Text, "");
                return;
            }

            // radius
            Int32 radius = 0;

            if (!Int32.TryParse(tbGCNRadius.Text, out radius))
            {
                DisplayError(lblGCNRadius.Text, _daddy.GetTranslator().GetString("lblnotnumber"), tbGCNRadius.Text, "");
                return;
            }

            // email
            if ((cbGCNEmails.Visible) && (cbGCNEmails.SelectedIndex == -1))
            {
                DisplayError(lblGCNEmail.Text, _daddy.GetTranslator().GetString("lblvalue"), "", "");
                return;
            }

            String email = "";

            if (cbGCNEmails.Items.Count != 0)
            {
                int pos = cbGCNEmails.SelectedIndex;
                email = cbGCNEmails.Items[pos].ToString();
            }

            // type
            // au moins une croix quelque part...
            // int associé au type de cache, nom du type de cache, liste des commandes POST pour kind of notif
            // Tuple<int, string, List<String>
            // on va créer un dico avec comme clé le type de cache
            Dictionary <String, Tuple <int, string, List <String> > > dicoCreation = new Dictionary <string, Tuple <int, string, List <string> > >();

            // On parcourt toutes les lignes, sauf la première qui correspond aux types
            for (int i = 1; i < lvGCNGrid.Items.Count; i++)
            {
                // On a l'item
                EXListViewItem lvi = (EXListViewItem)(lvGCNGrid.Items[i]);

                // On parcourt ses sous items
                for (int k = 1; k < lvi.SubItems.Count; k++)
                {
                    EXBoolListViewSubItem svi = lvi.SubItems[k] as EXBoolListViewSubItem;
                    if (svi != null)
                    {
                        // On a une valeur checkable
                        if (svi.BoolValue)
                        {
                            // Et elle est checkée !!
                            // On construit ce qu'il nous faut maintenant
                            //msg += listOfCacheTypes[k-1] + " " + listOfCacheTypesId[k-1] + " " + listOfAlloweKindPerCacheType[i-1].Item1 + " " + listOfAlloweKindPerCacheType[i-1].Item2[k-1] + "\r\n";


                            String typeofcache         = listOfCacheTypes[k - 1];
                            int    typeofcacheid       = listOfCacheTypesId[k - 1];
                            String kindofnotifreadable = listOfAlloweKindPerCacheType[i - 1].Item1;
                            String kindofnotifpost     = "ctl00$ContentBody$LogNotify$cblLogTypeList$" + listOfAlloweKindPerCacheType[i - 1].Item2[k - 1];
                            if (dicoCreation.ContainsKey(typeofcache))
                            {
                                // On met à jour la liste des kind of notif
                                Tuple <int, string, List <String> > obj = dicoCreation[typeofcache];
                                obj.Item3.Add(kindofnotifpost);
                            }
                            else
                            {
                                Tuple <int, string, List <String> > obj = new Tuple <int, string, List <string> >(typeofcacheid, typeofcache, new List <string>(new string[] { kindofnotifpost }));
                                dicoCreation.Add(typeofcache, obj);
                            }
                        }
                    }
                }
            }

            if (dicoCreation.Count == 0)
            {
                DisplayError(lblGCNGrid.Text, _daddy.GetTranslator().GetString("lblvalue"), "", "");
                return;
            }

            /*
             * foreach(KeyValuePair<String, Tuple<int, string, List<String>>> pair in dicoCreation)
             * {
             *      Tuple<int, string, List<String>> obj = pair.Value;
             *      msg += obj.Item1.ToString() + " " + obj.Item2 + " -> ";
             *      foreach(String s in obj.Item3)
             *      {
             *              msg += s + " ";
             *      }
             *      msg += "\r\n";
             * }
             * _daddy.MSG(msg);
             * return;
             */

            // On est valide, on peut créer
            _daddy._cacheDetail._gmap.ControlTextLatLon = null;

            // Go création
            CookieContainer cookieJar = _daddy.CheckGCAccount(true, false);
            String          url       = "https://www.geocaching.com/notify/edit.aspx";
            bool            error     = false;

            foreach (KeyValuePair <String, Tuple <int, string, List <String> > > pair in dicoCreation)
            {
                Tuple <int, string, List <String> > obj = pair.Value;
                // On demande la page par défaut pour initialiser une nouvelle demande
                HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
                objRequest.Proxy           = _daddy.GetProxy(); // Là encore, on peut virer le proxy si non utilisé (NULL)
                objRequest.CookieContainer = cookieJar;         // surtout récupérer le container de cookie qui est maintenant renseigné avec le cookie d'authentification
                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                String          post_response;
                using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
                {
                    post_response = responseStream.ReadToEnd();
                    responseStream.Close();
                }
                // On regarde si on a un message de warning
                if (NotificationsManager.CheckWarningMessage(_daddy, post_response))
                {
                    // Shit
                    error = true;
                    break;
                }

                // Une mise à jour pour définir le type de cache
                String post_string = NotificationsManager.GeneratePostString(_daddy, post_response, dLat, dLon, radius, tbGCNName.Text, obj, email, true);
                post_response = NotificationsManager.GeneratePostRequets(_daddy, url, post_string, cookieJar);

                // Une mise à jour pour définir le type de notif
                post_string   = NotificationsManager.GeneratePostString(_daddy, post_response, dLat, dLon, radius, tbGCNName.Text, obj, email, true);
                post_response = NotificationsManager.GeneratePostRequets(_daddy, url, post_string, cookieJar);
                if (NotificationsManager.CheckValidationMessage(_daddy, post_response))
                {
                    // Shit
                    error = true;
                    break;
                }
            }
            if (!error)
            {
                _daddy.MsgActionDone(this);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #3
0
    public void MyLongCalculations(object myvalues)
    {
        ParameterObject values = (ParameterObject)myvalues;

        this.uiDispatcher.BeginInvoke(/*a calculations delegate*/);
    }
Пример #4
0
 public MultiUnorderedConstructorType(ParameterObject paramObj)
     : this(paramObj.Text, paramObj.Number)
 {
 }
Пример #5
0
        public void TestSimpleFunctionObjectArgument()
        {
            using (var form = new BrowserTestForm())
            {

                var bridge = new ScriptingBridge(form.WebBrowser, true);
                var waiter = new WaitForFormsEvent();
                form.WebBrowser.DocumentCompleted += (sender, args) =>
                {

                    var parameter = new ParameterObject();
                    var result = bridge.InvokeFunction<ParameterObject>("anObject.simpleArgumentFunction", parameter);
                    Assert.Equal(parameter.TestDate, result.TestDate);
                    Assert.Equal(parameter.TestString, result.TestString);

                    waiter.SetEvent();
                };

                form.Show();
                form.WebBrowser.Url = new Uri(String.Format("file:///{0}/TestPage.html", Directory.GetCurrentDirectory()));

                // Wait for the document to load.
                Assert.True(waiter.WaitForEvent(2000));
            }
        }
Пример #6
0
        /// <summary>
        /// Create a message box
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="title">Title</param>
        /// <param name="icon">Icon</param>
        /// <param name="extraCheckBox">Title for an extra checkbox at the bottom of the message box. If NULL or type different of BOOL or label empty, no extra checkbox</param>
        /// <param name="translator">reference to a translator to translate OK and Cancel buttons</param>
        /// <param name="lblYes">If not null and not empty, label for the Yes button (of key forthis label if translator provided)</param>
        /// <param name="lblNo">If not null and not empty, label for the No button (of key forthis label if translator provided)</param>
        /// <returns>result of user validation</returns>
        public static DialogResult Show(String msg, String title, MessageBoxIcon icon, ParameterObject extraCheckBox, TranslationManager translator, String lblYes = null, String lblNo = null)
        {
            MyMessageBox box = new MyMessageBox(msg, title, icon, null, extraCheckBox, translator, lblYes, lblNo);

            box.TopMost = true;
            DialogResult dr = box.ShowDialog();

            return(dr);
        }
Пример #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="title">Title</param>
        /// <param name="icon">Icon</param>
        /// <param name="img">custom image to display</param>
        /// <param name="extraCheckBox">Title for an extra checkbox at the bottom of the message box. If NULL or type different of BOOL or label empty, no extra checkbox</param>
        /// <param name="translator">reference to a translator to translate OK and Cancel buttons</param>
        /// <param name="lblYes">If not null and not empty, label for the Yes button (of key forthis label if translator provided)</param>
        /// <param name="lblNo">If not null and not empty, label for the No button (of key forthis label if translator provided)</param>
        public MyMessageBox(String msg, String title, MessageBoxIcon icon, Image img, ParameterObject extraCheckBox, TranslationManager translator, String lblYes = null, String lblNo = null)
        {
            InitializeComponent();
            _extraCheckBox = extraCheckBox;
            _bYesNo        = false;
            this.Text      = title;
            textBox1.Text  = msg;
            Icon  ico    = null;
            Image iImage = img;

            /*
             *  None,
             *  Hand, Stop, Error = 16,
             *  Question = 32,
             *  Exclamation, Warning = 48,
             *  Information, Asterisk = 64,
             */
            switch (icon)
            {
            case MessageBoxIcon.Exclamation:     // also = Warning
                ico = SystemIcons.Exclamation;
                break;

            case MessageBoxIcon.Error:  // also = Error, Stop
                ico = SystemIcons.Error;
                if (iImage == null)     // si on a fourni une image, on ne l'écrase pas
                {
                    iImage = GetMajorFailureImg();
                }
                break;

            case MessageBoxIcon.Information:     // also = Asterix
                ico = SystemIcons.Information;
                break;

            case MessageBoxIcon.None:
                ico = null;
                break;

            case MessageBoxIcon.Question:
                ico     = SystemIcons.Question;
                _bYesNo = true;
                break;

            default:
                ico = SystemIcons.Information;
                break;
            }

            if (ico != null)
            {
                pictureBox1.Image = ico.ToBitmap();
                this.Icon         = ico;
            }

            if (iImage != null)
            {
                /*
                 * int hDisp = pictureBox2.Top - textBox1.Top - 1;
                 * textBox1.Height = hDisp;
                 */

                // Position on the left edge
                pictureBox2.Left = 3;

                // Center in the middle of the window
                int w = iImage.Width;
                int h = iImage.Height;

                if (h >= this.ClientSize.Height)
                {
                    pictureBox2.Top = 0;
                }
                else
                {
                    pictureBox2.Top = (this.ClientSize.Height - h) / 2;
                }
                pictureBox2.Image = iImage;

                textBox1.Left = pictureBox2.Left + pictureBox2.Width + 3;
                int tw = this.ClientSize.Width - textBox1.Left - 3;
                if (tw > 0)
                {
                    textBox1.Width = tw;
                }

                pictureBox1.Visible = false;
            }

            if (translator != null)
            {
                if (_bYesNo)
                {
                    if (String.IsNullOrEmpty(lblYes))
                    {
                        button1.Text = translator.GetString("BtnYes");
                    }
                    else
                    {
                        button1.Text = translator.GetString(lblYes);
                    }
                    if (String.IsNullOrEmpty(lblNo))
                    {
                        button2.Text = translator.GetString("BtnNo");
                    }
                    else
                    {
                        button2.Text = translator.GetString(lblNo);
                    }
                }
                else
                {
                    button1.Text = translator.GetString("BtnTrueOK");
                    button2.Text = translator.GetString("BtnCancel");
                }
            }
            else
            {
                if (_bYesNo)
                {
                    if (String.IsNullOrEmpty(lblYes))
                    {
                        button1.Text = "Yes";
                    }
                    else
                    {
                        button1.Text = lblYes;
                    }
                    if (String.IsNullOrEmpty(lblNo))
                    {
                        button2.Text = "No";
                    }
                    else
                    {
                        button2.Text = lblNo;
                    }
                }
                else
                {
                    button1.Text = "OK";
                    button2.Text = "Cancel";
                }
            }

            // On essaie d'adapter la largeur de TextBox1 à son contenu
            // On va prendre la ligne la plus large
            if (msg != "")
            {
                List <String> lignes   = msg.Split('\n').ToList <string>();
                String        lignemax = "";
                foreach (String ligne in lignes)
                {
                    if (ligne.Length > lignemax.Length)
                    {
                        lignemax = ligne;
                    }
                }
                // Maintenant on calcule la largeur max de cette ligne
                try
                {
                    Size s = TextRenderer.MeasureText(lignemax, this.Font);
                    // On va limiter à _iMaxWidth x _iMaxHeight pour la fenêtre TextBox
                    s = new Size(Math.Min(_iMaxWidth, 50 + s.Width), Math.Min(_iMaxHeight, 50 + s.Height * lignes.Count()));
                    Size sold   = textBox1.Size;
                    int  deltaw = Math.Max(0, s.Width - sold.Width);
                    int  deltah = Math.Max(0, s.Height - sold.Height);
                    this.Size = new Size(this.Size.Width + deltaw, this.Size.Height + deltah);
                }
                catch (Exception)
                {
                }
            }


            // Extra checkbox ?
            if ((_extraCheckBox != null) && (_extraCheckBox.eType == ParameterObject.ParameterType.Bool) && (String.IsNullOrEmpty(_extraCheckBox.DisplayName) == false))
            {
                int iMarge  = 2;
                int iHeight = 20;

                this.Size = new Size(this.Size.Width, this.Size.Height + iHeight + 2 * iMarge);

                CheckBox checkBox1 = new CheckBox();
                checkBox1.AutoSize = true;
                checkBox1.Location = new System.Drawing.Point(textBox1.Location.X, textBox1.Location.Y + textBox1.Size.Height + iMarge);
                checkBox1.Name     = "checkBox";
                checkBox1.Size     = new System.Drawing.Size(80, iHeight);
                checkBox1.Text     = _extraCheckBox.DisplayName;
                checkBox1.UseVisualStyleBackColor = true;
                checkBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
                if (_extraCheckBox.Value == "True")
                {
                    checkBox1.Checked = true;
                }
                this.Controls.Add(checkBox1);
                _extraCheckBox.Ctrl = checkBox1;
            }


            CenterButtons();
        }
 public MultiUnorderedConstructorType(ParameterObject paramObj)
     : this(paramObj.Text, paramObj.Number)
 {
 }
Пример #9
0
        void BtnGCNGUpdateClick(object sender, EventArgs e)
        {
            String fct = "updatepublishnotifications";

            try
            {
                if (!SpecialFeatures.SpecialFeaturesMgt.AreSpecialFeaturesEnabled())
                {
                    return;
                }
                CookieContainer cookieJar = _daddy.CheckGCAccount(true, false);
                if (cookieJar == null)
                {
                    return;
                }

                List <GCNotification> associatedGCN;
                List <String>         ids = GetSelectedIds(out associatedGCN);
                if (ids.Count == 0)
                {
                    _daddy.MsgActionWarning(this, _daddy.GetTranslator().GetString("LblErrorNoSelectionElt"));
                    return;
                }

                List <ParameterObject> lst = new List <ParameterObject>();
                lst.Add(new ParameterObject(ParameterObject.ParameterType.Coordinates /*good*/, _daddy.GetInitialCoordinates(), "latlon", _daddy.GetTranslator().GetString("ParamCenterLatLon"), _daddy.GetTranslator().GetStringM("TooltipParamLatLon")));

                ParametersChanger changer = new ParametersChanger();
                changer.HandlerDisplayCoord = _daddy.HandlerToDisplayCoordinates;
                changer.DisplayCoordImage   = _daddy.GetImageSized("Earth");
                changer.Title         = _daddy.GetTranslator().GetString("updatepublishnotifications");
                changer.BtnCancel     = _daddy.GetTranslator().GetString("BtnCancel");
                changer.BtnOK         = _daddy.GetTranslator().GetString("BtnOk");
                changer.ErrorFormater = _daddy.GetTranslator().GetString("ErrWrongParameter");
                changer.ErrorTitle    = _daddy.GetTranslator().GetString("Error");
                changer.Parameters    = lst;
                changer.Font          = _daddy.Font;
                changer.Icon          = _daddy.Icon;

                // Force creation du get handler on control
                changer.CreateControls();
                _daddy._cacheDetail._gmap.ControlTextLatLon = changer.CtrlCallbackCoordinates;

                if (changer.ShowDialog() == DialogResult.OK)
                {
                    _daddy._cacheDetail._gmap.ControlTextLatLon = null;
                    Double dlon = Double.MaxValue;
                    Double dlat = Double.MaxValue;
                    if (ParameterObject.SplitLongitudeLatitude(lst[0].Value, ref dlon, ref dlat))
                    {
                        foreach (String id in ids)
                        {
                            NotificationsManager.UpdateNotificationsImpl(_daddy, id, cookieJar, dlat, dlon);
                        }

                        _daddy.MsgActionDone(this);
                    }
                }
                else
                {
                    _daddy._cacheDetail._gmap.ControlTextLatLon = null;
                }
            }
            catch (Exception ex)
            {
                _daddy.ShowException("", _daddy.GetTranslator().GetString(fct), ex);
            }
        }