private void SetUserPreferences() { UserPreferences.Add("Document_Language_Code", DocumentLanguageCode); UserPreferences.Add("Document_Version", Version); var cookie = Request.Cookies["AbpDocsPreferences"]; if (cookie != null) { var keyValues = cookie.Split("|"); foreach (var keyValue in keyValues) { if (keyValue.Split("=").Length < 2) { continue; } var key = keyValue.Split("=")[0]; var value = keyValue.Split("=")[1]; UserPreferences.Add(key, value); UserPreferences.Add(key + "_Value", DocumentPreferences?.Parameters?.FirstOrDefault(p => p.Name == key) ?.Values.FirstOrDefault(v => v.Key == value).Value); } } var query = Request.Query; foreach (var(key, value) in query) { if (UserPreferences.ContainsKey(key)) { UserPreferences.Remove(key); UserPreferences.Remove(key + "_Value"); } UserPreferences.Add(key, value); UserPreferences.Add(key + "_Value", DocumentPreferences?.Parameters?.FirstOrDefault(p => p.Name == key)?.Values .FirstOrDefault(v => v.Key == value).Value); } if (DocumentPreferences?.Parameters == null) { return; } foreach (var parameter in DocumentPreferences.Parameters) { if (!UserPreferences.ContainsKey(parameter.Name)) { UserPreferences.Add(parameter.Name, parameter.Values.FirstOrDefault().Key); UserPreferences.Add(parameter.Name + "_Value", parameter.Values.FirstOrDefault().Value); } } }
private async Task <List <DocumentPartialTemplateContent> > GetDocumentPartialTemplatesAsync() { var partialTemplatesInDocument = await _documentSectionRenderer.GetPartialTemplatesInDocumentAsync(Document.Content); if (!partialTemplatesInDocument?.Any(t => t.Parameters != null) ?? true) { return(null); } foreach (var partialTemplates in partialTemplatesInDocument) { foreach (var parameter in partialTemplates.Parameters) { if (!UserPreferences.ContainsKey(parameter.Key)) { UserPreferences.Add(parameter.Key, parameter.Value); } else { UserPreferences[parameter.Key] = parameter.Value; } } } var contents = new List <DocumentPartialTemplateContent>(); foreach (var partialTemplate in partialTemplatesInDocument) { var content = (await _documentAppService.GetAsync(new GetDocumentInput { LanguageCode = DocumentLanguageCode, Name = partialTemplate.Path, ProjectId = Project.Id, Version = Version })).Content; contents.Add(new DocumentPartialTemplateContent { Path = partialTemplate.Path, Content = content }); } return(contents); }
private static void LoadSettings() { IEnumerable <MethodInfo> methodInfos = TypeFinder.FindAllAttributes <OptionsSetting>(); _settings = methodInfos.ToList(); UserPreferences.Clear(); foreach (MethodInfo setting in _settings) { try { if (!TryGetAttribute(setting, out OptionsSetting attr)) { continue; } if (UserPreferences.ContainsKey(attr.Name.ToLower())) { continue; } string defaultValue = attr.DefaultValue != null?attr.DefaultValue.ToString() : string.Empty; if (!string.IsNullOrWhiteSpace(attr.defaultValueMethodName)) { object classObj = CreateClass(setting.DeclaringType); MethodInfo defaultValueMethod = setting.DeclaringType.GetMethod(attr.defaultValueMethodName); if (defaultValueMethod.GetGenericArguments().Length == 0) { defaultValue = defaultValueMethod.Invoke(classObj, new object[0]).ToString(); } DisposeTemp(); } UserPreferences.Add(attr.Name.ToLower(), defaultValue); } catch { } } }
public static void ChangeOption(string optionName, object parameter, bool log = true, bool save = true) { optionName = optionName.ToLower(); int targetsCount = 0; foreach (MethodInfo setting in Settings) { DisposeTemp(); try { if (!TryGetAttribute(setting, out OptionsSetting attr)) { continue; } if (!TryGetSettingValueType(setting, out Type valueType)) { continue; } object param = parameter; if (parameter is string) { param = Convert.ChangeType(parameter, valueType); } if ((optionName != attr.Name.ToLower() || param.GetType() != valueType) && (param.GetType() == typeof(int) || !valueType.IsEnum)) { continue; } var obj = CreateClass(setting.DeclaringType); setting.Invoke(obj, new object[] { param }); targetsCount++; string saveSetting = param.ToString(); if (!UserPreferences.ContainsKey(optionName)) { UserPreferences.Add(optionName, string.Empty); } UserPreferences[optionName] = saveSetting; } catch { } } DisposeTemp(); if (log) { qDebug.Log(targetsCount != 0 ? $"Changed '{optionName}' to '{parameter}'" : $"Couldn't find setting '{optionName}'!", targetsCount != 0 ? "settings" : "error"); } if (save) { SaveSetting(optionName, parameter.ToString()); } }