public virtual void ClearCacheObjectTypes(string typeName) { var type = TypeFinder.GetTypeByName(typeName); if (type == null) { return; } var isInterface = type.IsInterface; using (new WriteLock(_locker)) { foreach (var key in MemoryCache .Where(x => { // x.Value is Lazy<object> and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = DictionaryCacheProviderBase.GetSafeLazyValue((Lazy <object>)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) return(value == null || (isInterface ? (type.IsInstanceOfType(value)) : (value.GetType() == type))); }) .Select(x => x.Key) .ToArray()) // ToArray required to remove { MemoryCache.Remove(key); } } }
public override IDictionary <string, object> ToValueEditor(object configuration) { var config = base.ToValueEditor(configuration); if (config.TryGetValue(DataSource, out var dataSource) && dataSource is JArray array && array.Count > 0) { var item = array[0]; // NOTE: Using `TypeFinder` here, as `TypeLoader` doesn't expose the `GetTypeByName` method. [LK:2019-06-06] var type = TypeFinder.GetTypeByName(item.Value <string>("type")); if (type != null) { var serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new ConfigurationFieldContractResolver(), Converters = new List <JsonConverter>(new[] { new FuzzyBooleanConverter() }) }); var source = item["value"].ToObject(type, serializer) as IDataListSource; var options = source?.GetItems() ?? Enumerable.Empty <DataListItem>(); config.Add(Items, options); } config.Remove(DataSource); } if (config.ContainsKey(ListEditor)) { config.Remove(ListEditor); } return(config); }
/// <inheritdoc /> public virtual void ClearOfType(string typeName) { var type = TypeFinder.GetTypeByName(typeName); if (type == null) { return; } var isInterface = type.IsInterface; try { EnterWriteLock(); foreach (var entry in GetDictionaryEntries() .Where(x => { // entry.Value is Lazy<object> and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = GetSafeLazyValue((Lazy <object>)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) return(value == null || (isInterface ? (type.IsInstanceOfType(value)) : (value.GetType() == type))); }) .ToArray()) { RemoveEntry((string)entry.Key); } } finally { ExitWriteLock(); } }
public override IDictionary <string, object> ToValueEditor(object configuration) { var config = base.ToValueEditor(configuration); if (config.TryGetValue(Items, out var items) && items is JArray array && array.Count > 0) { var types = new List <Type>(); foreach (var item in array) { var type = TypeFinder.GetTypeByName(item.Value <string>()); if (type != null) { types.Add(type); } } config[Items] = _service.GetConfigurationEditors <IConfigurationEditorItem>(types); config[OrderBy] = string.Empty; // Set to empty, so to preserve the selected order. } if (config.ContainsKey(OverlayView) == false) { config.Add(OverlayView, IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath)); } return(config); }
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { if (inter is JArray array) { var items = new List <IConfigurationEditorItem>(); foreach (var item in array) { var type = TypeFinder.GetTypeByName(item.Value <string>("type")); if (type != null) { var serializer = JsonSerializer.CreateDefault(new Serialization.ConfigurationFieldJsonSerializerSettings()); if (item["value"].ToObject(type, serializer) is IConfigurationEditorItem obj) { items.Add(obj); } } } return(items); } return(base.ConvertIntermediateToObject(owner, propertyType, referenceCacheLevel, inter, preview)); }
public void ClearCacheObjectTypes(string typeName) { var type = TypeFinder.GetTypeByName(typeName); if (type == null) { return; } var isInterface = type.IsInterface; foreach (var kvp in _items .Where(x => { // entry.Value is Lazy<object> and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = DictionaryCacheProviderBase.GetSafeLazyValue(x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) return(value == null || (isInterface ? (type.IsInstanceOfType(value)) : (value.GetType() == type))); })) { _items.TryRemove(kvp.Key, out _); } }
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { if (inter is JArray array) { var items = new List <IConfigurationEditorItem>(); foreach (var item in array) { // NOTE: Using `TypeFinder` here, as `TypeLoader` doesn't expose the `GetTypeByName` method. [LK:2019-06-06] var type = TypeFinder.GetTypeByName(item.Value <string>("type")); if (type != null) { var serializer = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new ConfigurationFieldContractResolver(), Converters = new List <JsonConverter>(new[] { new FuzzyBooleanConverter() }) }); if (item["value"].ToObject(type, serializer) is IConfigurationEditorItem obj) { items.Add(obj); } } } return(items); } return(base.ConvertIntermediateToObject(owner, propertyType, referenceCacheLevel, inter, preview)); }
private void InvokeInternalAction(string methodName, params object[] parameters) { try { if (_internalType == null && string.IsNullOrWhiteSpace(_fullyQualifiedTypeName) == false) { _internalType = TypeFinder.GetTypeByName(_fullyQualifiedTypeName); } if (_internalType != null) { var method = _internalType.GetMethod(methodName); if (method != null) { if (_internalInstance == null) { _internalInstance = Activator.CreateInstance(_internalType); } if (_internalInstance != null) { method.Invoke(_internalInstance, parameters); } } } } catch (Exception ex) { LogHelper.Error <UseInternalActionFilterAttribute>(methodName, ex); } }
public override IDictionary <string, object> ToValueEditor(object configuration) { var config = base.ToValueEditor(configuration); if (config.TryGetValue(Items, out var items) && items is JArray array && array.Count > 0) { var item = array[0]; var type = TypeFinder.GetTypeByName(item.Value <string>("type")); if (type != null) { var serializer = JsonSerializer.CreateDefault(new Serialization.ConfigurationFieldJsonSerializerSettings()); var source = item["value"].ToObject(type, serializer) as IDataListSource; var options = source?.GetItems() ?? Enumerable.Empty <DataListItem>(); config[Items] = options; } } return(config); }
public override IDictionary <string, object> ToValueEditor(object configuration) { var config = base.ToValueEditor(configuration); if (config.TryGetValue(Items, out var items) && items is JArray array && array.Count > 0) { var item = array[0]; var type = TypeFinder.GetTypeByName(item.Value <string>("type")); if (type != null) { // TODO: [LK:2020-01-13] Investigate this. Look to reuse same code as DataList. var source = item["value"].ToObject(type) as IDataListSource; var sourceConfig = item["value"].ToObject <Dictionary <string, object> >(); var options = source?.GetItems(sourceConfig) ?? Enumerable.Empty <DataListItem>(); config[Items] = options; } } return(config); }
/// <summary> /// Returns the Razor view with mocked viewmodel. /// </summary> /// <param name="path"></param> /// <param name="code"></param> /// <returns></returns> public ActionResult PatternWithModel(string path, string code) { object model = null; var patternPath = Path.Combine(Constants.RazorPatternViewsPath, path); var modelTypeName = RazorParser.GetModelTypeName(code); if (!string.IsNullOrEmpty(modelTypeName)) { var modelType = TypeFinder.GetTypeByName(modelTypeName); if (modelType != null) { // get the full file path of the mock data JSON file var patternDataPath = Server.MapPath(patternPath.Replace(".cshtml", ".json")); model = MockBuilder.Create(modelType, patternDataPath); } } return(PartialView(patternPath, model)); }
/// <summary> /// Creates a file system based Lucene <see cref="Lucene.Net.Store.Directory"/> with the correct locking guidelines for Umbraco /// </summary> /// <param name="folderName"> /// The folder name to store the index (single word, not a fully qualified folder) (i.e. Internal) /// </param> /// <returns></returns> public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string folderName) { var dirInfo = new DirectoryInfo(Path.Combine(IOHelper.MapPath(SystemDirectories.Data), "TEMP", "ExamineIndexes", folderName)); if (!dirInfo.Exists) { System.IO.Directory.CreateDirectory(dirInfo.FullName); } //check if there's a configured directory factory, if so create it and use that to create the lucene dir var configuredDirectoryFactory = ConfigurationManager.AppSettings["Umbraco.Examine.LuceneDirectoryFactory"]; if (!configuredDirectoryFactory.IsNullOrWhiteSpace()) { //this should be a fully qualified type var factoryType = TypeFinder.GetTypeByName(configuredDirectoryFactory); if (factoryType == null) { throw new NullReferenceException("No directory type found for value: " + configuredDirectoryFactory); } var directoryFactory = (IDirectoryFactory)Activator.CreateInstance(factoryType); return(directoryFactory.CreateDirectory(dirInfo)); } //no dir factory, just create a normal fs directory var luceneDir = new SimpleFSDirectory(dirInfo); //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the appdomain //terminates and in some rare cases would only allow unlocking of the file if IIS is forcefully terminated. Instead we'll rely on the simplefslock //which simply checks the existence of the lock file // The full syntax of this is: new NoPrefixSimpleFsLockFactory(dirInfo) // however, we are setting the DefaultLockFactory in startup so we'll use that instead since it can be managed globally. luceneDir.SetLockFactory(DirectoryFactory.DefaultLockFactory(dirInfo)); return(luceneDir); }