Exemple #1
0
        /// <summary>
        /// <para>Asserts that a given HTTP call was sent with expected JSON content.</para>
        /// </summary>
        ///
        /// <para>Asserts that a metadata field has expected structure and property values.
        /// See <a href="https://cloudinary.com/documentation/admin_api#generic_structure_of_a_metadata_field">
        /// Generic structure of a metadata field in API reference.</a></para>
        /// <param name="mockedCloudinary">An instance of the <see cref="Cloudinary"/> class with mocked HttpClient.</param>
        /// <param name="type"> The type of value that can be assigned to the metadata field.</param>
        /// <param name="externalId">A unique identification string for the metadata field.</param>
        /// <param name="dataSourceEntry">(Optional) Data source for a given field.</param>
        private static void AssertEncodedRequestFields(MockedCloudinary mockedCloudinary, string type, string externalId,
                                                       EntryParams dataSourceEntry = null)
        {
            var requestJson = JToken.Parse(mockedCloudinary.HttpRequestContent);

            Assert.AreEqual(type, requestJson["type"].Value <string>());
            Assert.AreEqual(externalId, requestJson["label"].Value <string>());
            Assert.AreEqual(externalId, requestJson["external_id"].Value <string>());

            if (dataSourceEntry == null)
            {
                return;
            }

            var firstDataSource = requestJson["datasource"]["values"].First;

            Assert.AreEqual(dataSourceEntry.Value, firstDataSource["value"].Value <string>());
            Assert.AreEqual(dataSourceEntry.ExternalId, firstDataSource["external_id"].Value <string>());
        }
Exemple #2
0
 public ParametersViewEntry     AddEntry(EntryParams entryParams)
 {
     return(this.AddOrUpdateEntry(null, entryParams, null, true, false));
 }
Exemple #3
0
        private ParametersViewEntry     AddOrUpdateEntry(ParametersViewEntry entry, EntryParams entryParams, object entryValue,
                                                         bool create, bool update)
        {
            if (null == m_container)
            {
                return(null);
            }


            if (create)
            {
                m_entries.RemoveAllDeadObjects();
            }


            object editedValue = null;

            Transform  childControl         = null;
            GameObject labelGameObject      = null;
            Text       label                = null;
            GameObject emptySpaceGameObject = null;

            if (create)
            {
                // create label
                labelGameObject = CreateChildInContainer(this.labelPrefab);
                label           = labelGameObject.GetComponentInChildren <Text> ();
                label.text      = entryParams.displayName;
            }
            else
            {
                // elements are already created => we can obtain them from entry
                label           = entry.label;
                childControl    = entry.transform;
                labelGameObject = entry.labelGameObject;
            }


            // create appropriate UI control for the specified display type

            var displayType = entryParams.displayType;

            if (displayType == EntryDisplayType.String || displayType == EntryDisplayType.FloatTextBox || displayType == EntryDisplayType.IntegerTextBox)
            {
                InputField inputField = null;

                if (create)
                {
                    // create input field

                    childControl = CreateChildInContainer(this.inputFieldPrefab).transform;
                    entry        = childControl.gameObject.AddComponentIfDoesntExist <ParametersViewEntry> ();

                    inputField = childControl.GetComponentInChildren <InputField> ();
                    if (entryParams.maxLength > 0)
                    {
                        inputField.characterLimit = entryParams.maxLength;
                    }
                    switch (displayType)
                    {
                    case EntryDisplayType.FloatTextBox:
                        inputField.contentType = InputField.ContentType.DecimalNumber;
                        break;

                    case EntryDisplayType.IntegerTextBox:
                        inputField.contentType = InputField.ContentType.IntegerNumber;
                        break;
                    }
                }

                inputField = childControl.GetComponentInChildren <InputField> ();

                if (update)
                {
                    inputField.text = entryValue.ToString();
                }

                entry.control = inputField;

                // get current value
                switch (displayType)
                {
                case EntryDisplayType.String:
                    editedValue = inputField.text;
                    break;

                case EntryDisplayType.FloatTextBox:
                    float floatValue;
                    if (float.TryParse(inputField.text, out floatValue))
                    {
                        editedValue = floatValue;
                    }
                    break;

                case EntryDisplayType.IntegerTextBox:
                    int intValue;
                    if (int.TryParse(inputField.text, out intValue))
                    {
                        editedValue = intValue;
                    }
                    break;
                }
            }
            else if (displayType == EntryDisplayType.FloatSlider || displayType == EntryDisplayType.IntegerSlider)
            {
                Slider slider = null;

                if (create)
                {
                    // create slider

                    childControl = CreateChildInContainer(this.sliderPrefab).transform;
                    entry        = childControl.gameObject.AddComponentIfDoesntExist <ParametersViewEntry> ();

                    slider              = childControl.GetComponentInChildren <Slider> ();
                    slider.minValue     = entryParams.minValue;
                    slider.maxValue     = entryParams.maxValue;
                    slider.wholeNumbers = (displayType == EntryDisplayType.IntegerSlider);

                    // add script for updating label
                    var updater = slider.gameObject.AddComponentIfDoesntExist <ParametersViewSliderLabelUpdate> ();
                    updater.entryName = entryParams.displayName;
                    updater.label     = label;
                }

                slider = childControl.GetComponentInChildren <Slider> ();

                if (update)
                {
                    if (displayType == EntryDisplayType.FloatSlider)
                    {
                        slider.value = (float)entryValue;
                    }
                    else
                    {
                        slider.value = (int)entryValue;
                    }

                    // also add current value to label
                    label.text = entryParams.displayName + " : " + entryValue.ToString();
                }

                entry.control = slider;

                // get current value
                switch (displayType)
                {
                case EntryDisplayType.FloatSlider:
                    editedValue = (float)slider.value;
                    break;

                case EntryDisplayType.IntegerSlider:
                    editedValue = (int)slider.value;
                    break;
                }
            }
            else if (displayType == EntryDisplayType.Boolean)
            {
                // toggle

                if (create)
                {
                    childControl = CreateChildInContainer(this.togglePrefab).transform;
                    entry        = childControl.gameObject.AddComponentIfDoesntExist <ParametersViewEntry> ();

                    // reduce label height, and set text of toggle label
                    label.text = "";
                    label.rectTransform.SetNormalizedRectAndAdjustAnchors(Rect.zero);

                    childControl.GetComponentInChildren <Text> ().text = " " + entryParams.displayName;
                }

                Toggle toggle = childControl.GetComponentInChildren <Toggle> ();

                if (update)
                {
                    toggle.isOn = (bool)entryValue;
                }

                entry.control = toggle;

                // get current value
                editedValue = toggle.isOn;
            }


            if (create)
            {
                // create empty space
                emptySpaceGameObject = CreateChildInContainer(this.emptySpacePrefab);
            }


            if (create)
            {
                // now that control is created, we can assign references in entry script

                entry.labelGameObject      = labelGameObject;
                entry.emptySpaceGameObject = emptySpaceGameObject;
            }


            entry.editedValue = editedValue;

            if (create)
            {
                // TODO: make a copy
                entry.entryParams = entryParams;
            }

            return(entry);
        }
Exemple #4
0
        public ActionResult Search([FromBody] EntryParams parameters)
        {
            var id         = parameters?.Id;
            var searchTerm = parameters?.SearchTerm;
            var begin      = parameters?.Begin;
            var end        = parameters?.End;
            var startDate  = parameters?.StartDate;
            var endDate    = parameters?.EndDate;
            var tags       = parameters?.Tags;
            var reverse    = parameters?.Reverse;

            if (!begin.HasValue || !end.HasValue)
            {
                begin = 1;
                end   = 20;
            }

            var resultList = new List <Entry>();

            // Get entry by id if provided.
            if (id.HasValue)
            {
                Entry e = Database.GetEntry(id.Value);

                if (e != null)
                {
                    resultList.Add(e);
                }
            }

            else
            {
                resultList = Database.Entries;
            }

            IEnumerable <Entry> results = resultList;

            // Filter entries by tags if provided.
            if (tags != null && tags.Count > 0)
            {
                results = results.Where(e => tags.All(tag => e.Tags.Contains(tag)));
            }

            // Filter entries by search term if provided.
            if (!string.IsNullOrEmpty(searchTerm))
            {
                results = results.Where(e => e.Text.ContainsIgnoreCase(searchTerm));
            }

            // Filter entries by dates if provided.
            if (startDate.HasValue)
            {
                results = results.Where(e => startDate <= e.StartTime);
            }

            if (endDate.HasValue)
            {
                results = results.Where(e => e.StartTime < endDate);
            }

            resultList = results.ToList();
            resultList.Sort();

            if (!(reverse.HasValue && reverse.Value))
            {
                resultList.Reverse();
            }

            if (1 <= begin.Value && begin.Value < resultList.Count)
            {
                int be = begin.Value;
                int en = end.Value;

                if (begin.Value < 1)
                {
                    be = 1;
                }

                if (end.Value >= resultList.Count)
                {
                    en = resultList.Count;
                }

                int range = en - be + 1;

                resultList = resultList.GetRange(be - 1, range);
            }

            return(Ok(resultList));
        }