Ejemplo n.º 1
0
        public void SetObject(EditorObject ob)
        {
            foreach (GUIElement element in elements)
            {
                element.Parent = null;
            }
            elements.Clear();

            if (ob != null)
            {
                Visible = true;
                Title   = string.Format("Edit {0}", ob.EditorName);

                Type type = ob.GetType();
                foreach (var prop in type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    foreach (var attr in prop.GetCustomAttributes(true))
                    {
                        EditableField field = attr as EditableField;
                        if (field != null)
                        {
                            TryCreateEditField(ob, prop, field);
                        }
                    }
                }
            }
            else
            {
                Visible = false;
            }
        }
Ejemplo n.º 2
0
        public override void AddEditorToRoot(EditableField field)
        {
            var grp = GetGroup(field.PropertyData.Group);

            grp.Fields.Add(field);
            (grp.View as TableSection).Add(field.EditorView as Cell);
        }
Ejemplo n.º 3
0
        private void ProcessFile()
        {
            this.Controls.Clear();

            if (!this.LoadFile())
            {
                return;
            }

            this.Controls.Add(new LiteralControl("<table>"));

            foreach (ViewableField field in this.File.Fields)
            {
                this.Controls.Add(new LiteralControl("<tr>"));

                /// Header
                this.Controls.Add(new LiteralControl("<th align=\"left\">"));
                this.Controls.Add(new LiteralControl(field.FormField.Name));
                this.Controls.Add(new LiteralControl("</th>"));


                this.Controls.Add(new LiteralControl("</tr>"));
                this.Controls.Add(new LiteralControl("<tr>"));


                /// value
                this.Controls.Add(new LiteralControl("<td style=\"padding: 2px; border: solid 1px black;\">"));

                if (field.Metadata.ControlType == FieldControlType.Checkbox)
                {
                    /// multiple values
                    string[] checkedTextValues = EditableField.ParseTextForCheckboxValue(field.CurrentValue);
                    string   outputstring      = string.Empty;
                    foreach (Formcode code in field.LookupCodes)
                    {
                        if (checkedTextValues.Contains(code.Id.ToString()))
                        {
                            outputstring += code.Label + ", ";
                        }
                    }
                    if (outputstring.Length > 0)
                    {
                        outputstring = outputstring.Remove(outputstring.Length - 2);
                    }
                    this.Controls.Add(new LiteralControl(outputstring + "&nbsp;"));
                }
                else
                {
                    this.Controls.Add(new LiteralControl(field.CurrentValue + "&nbsp;"));
                }
                this.Controls.Add(new LiteralControl("</td>"));

                this.Controls.Add(new LiteralControl("</tr>"));
            }


            this.Controls.Add(new LiteralControl("</table>"));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the random value and records it to <paramref name="value"/> parameter.
        /// For value generation uses randomization attributes, for example:
        /// <see cref="RandomizeStringSettingsAttribute" />, <see cref="RandomizeNumberSettingsAttribute" />, <see cref="RandomizeIncludeAttribute" />, etc.
        /// Also executes <see cref="TriggerEvents.BeforeSet" /> and <see cref="TriggerEvents.AfterSet" /> triggers.
        /// </summary>
        /// <typeparam name="TOwner">The type of the owner page object.</typeparam>
        /// <param name="field">The editable field control.</param>
        /// <param name="value">The generated value.</param>
        /// <returns>The instance of the owner page object.</returns>
        public static TOwner SetRandom <TOwner>(this EditableField <decimal?, TOwner> field, out int value)
            where TOwner : PageObject <TOwner>
        {
            field.SetRandom(out decimal? decimalValue);

            value = (int)decimalValue;

            return(field.Owner);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets the random value and records it to <paramref name="value"/> parameter.
        /// For value generation uses randomization attributes, for example:
        /// <see cref="RandomizeStringSettingsAttribute" />, <see cref="RandomizeNumberSettingsAttribute" />, <see cref="RandomizeIncludeAttribute" />, etc.
        /// Also executes <see cref="TriggerEvents.BeforeSet" /> and <see cref="TriggerEvents.AfterSet" /> triggers.
        /// </summary>
        /// <typeparam name="TData">The type of the control's data.</typeparam>
        /// <typeparam name="TOwner">The type of the owner page object.</typeparam>
        /// <param name="field">The editable field control.</param>
        /// <param name="value">The generated value.</param>
        /// <returns>The instance of the owner page object.</returns>
        public static TOwner SetRandom <TData, TOwner>(this EditableField <TData?, TOwner> field, out TData value)
            where TData : struct
            where TOwner : PageObject <TOwner>
        {
            field.SetRandom(out TData? nullableValue);

            value = (TData)nullableValue;

            return(field.Owner);
        }
Ejemplo n.º 6
0
        public override Element GetEditor(EditableField field, object obj)
        {
            Element view    = null;
            var     lblText = ObjectEditor.Translate(field.PropertyData.Title);
            Label   lbl     = new Label()
            {
                Text = lblText
            };

            if (view == null)
            {
                if (field.PropertyData.Readonly)
                {
                    view = new Label()
                    {
                        BindingContext = field,
                        Text           = field.Value.ToString()
                    };
                    view.SetBinding(Entry.TextProperty, nameof(field.Value));
                }
                else
                {
                    var type = field.SourceProperty.PropertyType;
                    if (type == typeof(string) || type == typeof(int))
                    {
                        view = new Entry()
                        {
                            Text = field.Value.ToString()
                        };
                        view.SetBinding(EntryCell.TextProperty, nameof(field.Value));
                    }
                    else if (type == typeof(bool))
                    {
                        view = new Switch()
                        {
                        };
                        view.SetBinding(Switch.IsToggledProperty, nameof(field.Value));
                    }
                    else if (type == typeof(DateTime))
                    {
                        view = new DatePicker()
                        {
                        };
                        view.SetBinding(DatePicker.DateProperty, nameof(field.Value));
                    }
                    if (view != null)
                    {
                        view.BindingContext = field;
                    }
                }
            }
            return(view as Element);
        }
Ejemplo n.º 7
0
        public static TOwner SetWithSpeed <T, TOwner>(this EditableField <T, TOwner> editableField, T value, double interval)
            where TOwner : PageObject <TOwner>
        {
            editableField.Focus();

            foreach (var character in value.ToString())
            {
                editableField.Owner
                .Press(character.ToString())
                .Wait(interval);
            }

            return(editableField.Owner);
        }
Ejemplo n.º 8
0
        protected static void SetAndVerifyValues <T, TPage>(EditableField <T, TPage> control, params T[] values)
            where TPage : PageObject <TPage>
        {
            control.Should.Exist();

            for (int i = 0; i < values.Length; i++)
            {
                control.Set(values[i]);
                control.Should.Equal(values[i]);
                Assert.That(control.Value, Is.EqualTo(values[i]));

                if (i > 0 && !Equals(values[i], values[i - 1]))
                {
                    control.Should.Not.Equal(values[i - 1]);
                }
            }
        }
Ejemplo n.º 9
0
        void TryCreateEditField(EditorObject ob, PropertyInfo prop, EditableField attr)
        {
            float y        = elements.Count * FIELD_Y_AREA;
            UDim2 position = new UDim2(0, 0, 0, y + 25);

            GUILabel label     = null;
            string   labelText = string.Format("{0}:", attr.Name);

            Type type = prop.PropertyType;

            if (type == typeof(bool))
            {
                GUICheckbox checkbox;
                form.AddLabledCheckbox(labelText, (bool)prop.GetValue(ob), position,
                                       out label, out checkbox);
                elements.Add(checkbox);

                checkbox.OnCheckChanged += (sender, e) =>
                {
                    prop.SetValue(ob, e);
                };
            }
            else if (type == typeof(string))
            {
                GUITextField field;
                form.AddLabledTextField(labelText, (string)prop.GetValue(ob), position,
                                        out label, out field);
                elements.Add(field);

                field.OnTextChanged += (sender, e) =>
                {
                    prop.SetValue(ob, e);
                };
            }

            if (label != null)
            {
                elements.Add(label);
            }
        }
Ejemplo n.º 10
0
        void CreateFromTemplate()
        {
            try
            {
                List <string> listIDs = new List <string>();
                listIDs.Add("List ID One");
                List <string> segmentIDs = new List <string>();
                segmentIDs.Add("Segment ID One");

                // Prepare the template content
                TemplateContent templateContent = new TemplateContent();

                List <EditableField> singlelines = new List <EditableField>();
                EditableField        singleline  = new EditableField();
                singleline.Content = "This is a heading";
                singleline.Href    = "http://example.com/";
                singlelines.Add(singleline);
                templateContent.Singlelines = singlelines;

                List <EditableField> multilines = new List <EditableField>();
                EditableField        multiline  = new EditableField();
                multiline.Content = "<p>This is example</p><p>multiline <a href=\"http://example.com\">content</a>...</p>";
                multilines.Add(multiline);
                templateContent.Multilines = multilines;

                List <EditableField> images = new List <EditableField>();
                EditableField        image  = new EditableField();
                image.Content = "http://example.com/image.png";
                image.Alt     = "This is alt text for an image";
                image.Href    = "http://example.com/";
                images.Add(image);
                templateContent.Images = images;

                List <Repeater>     repeaters = new List <Repeater>();
                Repeater            repeater  = new Repeater();
                List <RepeaterItem> items     = new List <RepeaterItem>();
                RepeaterItem        item      = new RepeaterItem();
                item.Layout = "My layout";

                // Just using the same data for Singlelines, Multilines,
                // and Images as above in this example.
                item.Singlelines = singlelines;
                item.Multilines  = multilines;
                item.Images      = images;

                repeater.Items = items;
                repeaters.Add(repeater);
                templateContent.Repeaters = repeaters;

                // templateContent as defined above would be used to fill the content of
                // a template with markup similar to the following:
                // <html>
                // <head><title>My Template</title></head>
                // <body>
                //     <p><singleline>Enter heading...</singleline></p>
                //     <div><multiline>Enter description...</multiline></div>
                //     <img id="header-image" editable="true" width="500" />
                //     <repeater>
                //     <layout label="My layout">
                //         <div class="repeater-item">
                //         <p><singleline></singleline></p>
                //         <div><multiline></multiline></div>
                //         <img editable="true" width="500" />
                //         </div>
                //     </layout>
                //     </repeater>
                //     <p><unsubscribe>Unsubscribe</unsubscribe></p>
                // </body>
                // </html>

                string campaignID = Campaign.CreateFromTemplate(
                    auth,
                    "Your Client ID",
                    "Campaign Subject",
                    "Campaign Name",
                    "From Name",
                    "*****@*****.**",
                    "*****@*****.**",
                    listIDs,
                    segmentIDs,
                    "Template ID",
                    templateContent);

                Console.WriteLine("Campaign ID: " + campaignID);
            }
            catch (CreatesendException ex)
            {
                ErrorResult error = (ErrorResult)ex.Data["ErrorResult"];
                Console.WriteLine(error.Code);
                Console.WriteLine(error.Message);
            }
            catch (Exception ex)
            {
                // Handle some other failure
                Console.WriteLine(ex.ToString());
            }
        }
Ejemplo n.º 11
0
 protected static void SetAndVerifyValue <T, TPage>(EditableField <T, TPage> control, T value)
     where TPage : PageObject <TPage>
 {
     control.Set(value);
     VerifyEquals(control, value);
 }
Ejemplo n.º 12
0
        public override Element GetEditor(EditableField field, object parent)
        {
            Element view = null;

            if (view == null)
            {
                if (field.PropertyData.Readonly)
                {
                    view = new TextCell()
                    {
                        Text           = ObjectEditor.Translate(field.PropertyData.Title),
                        BindingContext = field,
                        Detail         = field.Value.ToString()
                    };
                    view.SetBinding(TextCell.DetailProperty, nameof(field.Value));
                }
                else
                {
                    var type = field.SourceProperty.PropertyType;
                    if (field.PropertyData.RelationTo != null)
                    {
                        var inst = Activator.CreateInstance(field.PropertyData.RelationTo);
                        if (inst is IEditorRelation rel)
                        {
                            view = new RelationCell(rel)
                            {
                                Text = ObjectEditor.Translate(field.PropertyData.Title)
                            };
                            view.SetBinding(DateCell.ValueProperty, nameof(field.Value));
                        }
                    }
                    else if (type == typeof(string) || type == typeof(int))
                    {
                        view = new EntryCell()
                        {
                            Label = ObjectEditor.Translate(field.PropertyData.Title)
                        };
                        view.SetBinding(EntryCell.TextProperty, nameof(field.Value));
                    }
                    else if (type == typeof(bool))
                    {
                        view = new SwitchCell()
                        {
                            Text = ObjectEditor.Translate(field.PropertyData.Title)
                        };
                        view.SetBinding(SwitchCell.OnProperty, nameof(field.Value));
                    }
                    else if (type == typeof(DateTime))
                    {
                        view = new DateCell()
                        {
                            Text = ObjectEditor.Translate(field.PropertyData.Title)
                        };
                        view.SetBinding(DateCell.ValueProperty, nameof(field.Value));
                    }
                    if (view != null)
                    {
                        view.BindingContext = field;
                    }
                }
            }
            return(view as Element);
        }
Ejemplo n.º 13
0
 public override void AddEditorToRoot(EditableField field)
 {
     stack.Children.Add(field.EditorView as View);
 }
Ejemplo n.º 14
0
 public abstract void AddEditorToRoot(EditableField field);
Ejemplo n.º 15
0
 public abstract Element GetEditor(EditableField field, object obj);