public Models.CustomDocumentListDisplay FindCustomDocumentListDisplay(string hostName, string databaseId, string documentCollectionId)
        {
            Models.CustomDocumentListDisplay customListDisplay = null;
            var customDocumentListDisplayCollectionForHost     = SettingsProvider.CustomDocumentListDisplayCollection.Find(s => s.HostName == hostName);

            if (customDocumentListDisplayCollectionForHost != null && customDocumentListDisplayCollectionForHost.Items.Count > 0)
            {
                customListDisplay = customDocumentListDisplayCollectionForHost.Items.Find(i => i.DocumentCollectionId == documentCollectionId && i.DatabaseId == databaseId);
            }
            return(customListDisplay);
        }
        public bool GetCustomDocumentDisplayIdentifier(
            List <dynamic> docs,
            Models.CustomDocumentListDisplay customListDisplay,
            string customDocumentDisplayIdentifier,
            out string customDisplayPattern,
            out string sortField,
            bool useDirectAccess = false)
        {
            customDisplayPattern = null;
            sortField            = "id";

            try
            {
                string testField;

                if (customListDisplay != null)
                {
                    customDisplayPattern = customListDisplay.DisplayPattern;
                    testField            = customListDisplay.SortBy;
                    sortField            = customListDisplay.SortBy;
                }
                else
                {
                    customDisplayPattern = customDocumentDisplayIdentifier;
                    testField            = customDisplayPattern;
                    sortField            = customDisplayPattern;
                }
                if (!string.IsNullOrWhiteSpace(testField))
                {
                    var useCustom = false;
                    var firstDoc  = docs.First();

                    try
                    {
                        var name = DynamicHelper.GetPropertyValue(firstDoc, testField, useDirectAccess);
                        useCustom = true;
                    }
                    catch (Exception) { }

                    return(useCustom);
                }
            }
            catch (Exception ex)
            {
                var m = ex;
            }
            return(false);
        }
 private void btnSettingToggle_Click(object sender, EventArgs e)
 {
     if (_setting == null)
     {
         CreateNewSetting();
         SetAllSettingFields();
     }
     else
     {
         var dlgResult = MessageBox.Show("Are you sure that you want to remove the setting?", "Remove setting?",
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dlgResult == DialogResult.Yes)
         {
             _setting = null;
         }
     }
     SetStatusForSettingFields(_setting != null);
 }
        public void SaveCustomDocumentListDisplay(string hostName, Models.CustomDocumentListDisplay cdld)
        {
            // Re-read from file to make sure we have latest version:
            SettingsProvider.ReadCustomDocumentListDisplayCollectionsFromFile();
            var existing = FindCustomDocumentListDisplay(hostName, cdld.DatabaseId, cdld.DocumentCollectionId);

            if (existing != null)
            {
                SettingsProvider.CustomDocumentListDisplayCollection.Find(s => s.HostName == hostName)
                .Items.Find(i => i.DocumentCollectionId == cdld.DocumentCollectionId)
                .DisplayPattern = cdld.DisplayPattern;

                SettingsProvider.CustomDocumentListDisplayCollection.Find(s => s.HostName == hostName)
                .Items.Find(i => i.DocumentCollectionId == cdld.DocumentCollectionId)
                .SortBy = cdld.SortBy;

                SettingsProvider.CustomDocumentListDisplayCollection.Find(s => s.HostName == hostName)
                .Items.Find(i => i.DocumentCollectionId == cdld.DocumentCollectionId)
                .ReverseSort = cdld.ReverseSort;

                SettingsProvider.SaveCustomDocumentListDisplayCollectionToFile();
            }
            else
            {
                var hostNode = SettingsProvider.CustomDocumentListDisplayCollection.Find(s => s.HostName == hostName);
                if (hostNode != null)
                {
                    SettingsProvider.CustomDocumentListDisplayCollection.Find(s => s.HostName == hostName).Items.Add(cdld);
                    SettingsProvider.SaveCustomDocumentListDisplayCollectionToFile();
                }
                else
                {
                    SettingsProvider.CustomDocumentListDisplayCollection.Add(new CustomDocumentListDisplayCollection
                    {
                        HostName = hostName,
                        Items    = new List <Models.CustomDocumentListDisplay> {
                            cdld
                        }
                    });
                    SettingsProvider.SaveCustomDocumentListDisplayCollectionToFile();
                }
            }
        }
        private void CustomDocumentListDisplayForm_Load(object sender, EventArgs e)
        {
            lblCannotSaveHint.Text = "";
            Text = "Configure Document Listing settings";
            tbDefaultGlobalFieldName.Text = Settings.Default.CustomDocumentDisplayIdentifier;

            gbCustom.Text = string.Format("Custom Document Listing settings for {0}/{1}", _databaseId, _documentCollectionId);

            _propertyKeysForDocument = DynamicHelper.GetPropertyKeysForDynamic(_firstDocument);
            foreach (var prop in _propertyKeysForDocument)
            {
                cbSortFields.Items.Add(prop);
            }

            _setting = _customDocumentListDisplayManager.FindCustomDocumentListDisplay(_hostName, _databaseId, _documentCollectionId);

            SetStatusForSettingFields(_setting != null);

            SetAllSettingFields();
        }
        private void CreateNewSetting()
        {
            _setting = new CustomDocumentListDisplay.Models.CustomDocumentListDisplay
            {
                DatabaseId           = _databaseId,
                DocumentCollectionId = _documentCollectionId,
                SortBy         = "id",
                DisplayPattern = "{id}"
            };

            if (_propertyKeysForDocument.Contains(Settings.Default.CustomDocumentDisplayIdentifier))
            {
                _setting.SortBy = Settings.Default.CustomDocumentDisplayIdentifier;
                if (Settings.Default.CustomDocumentDisplayIdentifier == "id")
                {
                    _setting.DisplayPattern = string.Format("{{{0}}}", Settings.Default.CustomDocumentDisplayIdentifier);
                }
                else
                {
                    _setting.DisplayPattern = string.Format("{{{0}}} [{{id}}]", Settings.Default.CustomDocumentDisplayIdentifier);
                }
            }
        }