private void RefreshCodeBlocks(HiveId attrTypeId, CSharpCodeBlockType cSharpCodeType) { var delegateParameter = new Tuple <HiveId, CSharpCodeBlockType>(attrTypeId, cSharpCodeType); //check if we have this registered (multiple ids may exist for the same delegate, but in thsi case it will never be true) var ids = CodeDelegateVirtualPath.GetVirtualPathIdsForDelegate(delegateParameter).ToArray(); if (ids.Any()) { var codeDelegateId = ids.First(); CodeDelegateVirtualPath.TryUpdate(codeDelegateId, delegateParameter); } }
private void RefreshCodeBlocks(HiveId attrTypeId, CSharpCodeBlockType cSharpCodeType) { var delegateParameter = new Tuple<HiveId, CSharpCodeBlockType>(attrTypeId, cSharpCodeType); //check if we have this registered (multiple ids may exist for the same delegate, but in thsi case it will never be true) var ids = CodeDelegateVirtualPath.GetVirtualPathIdsForDelegate(delegateParameter).ToArray(); if (ids.Any()) { var codeDelegateId = ids.First(); CodeDelegateVirtualPath.TryUpdate(codeDelegateId, delegateParameter); } }
/// <summary> /// Ensures that the code delegate for the filter is in the CodeDelegatesCollection /// </summary> /// <param name="backOfficeRequestContext"></param> /// <param name="dataTypeId"></param> /// <param name="blockType"></param> /// <param name="codedelegate"> </param> /// <returns></returns> private static string SetupCodeDelegate( IBackOfficeRequestContext backOfficeRequestContext, HiveId dataTypeId, CSharpCodeBlockType blockType, Func <object, string, string> codedelegate) { var delegateParameter = new Tuple <HiveId, CSharpCodeBlockType>(dataTypeId, blockType); //first, check if we have this registered (multiple ids may exist for the same delegate, but in thsi case it will never be true) var ids = CodeDelegateVirtualPath.GetVirtualPathIdsForDelegate(delegateParameter).ToArray(); if (ids.Any()) { return(ids.First()); } //need to lookup the data type to get its alias as we'll use this for the path using (var uow = backOfficeRequestContext.Application.Hive.OpenReader <IContentStore>()) { var dt = uow.Repositories.Schemas.Get <AttributeType>(true, dataTypeId).SingleOrDefault(); if (dt == null) { throw new InvalidOperationException("Could not find AttributeType with id " + dataTypeId); } //create a unique path for our object which will be used in the virtual path creation, if we don't set this //then the ToString of the object key will be used which is much harder to debug. var path = dt.Alias + "_" + delegateParameter.Item2 + "_" + delegateParameter.GetHashCode().ToString().Replace("-", "0"); //only alphanumeric chars allowed var virtualPathId = CodeDelegateVirtualPath.GetOrCreateVirtualPathId(delegateParameter, path); //add the delegate to the collection CodeDelegatesCollection.TryAdd(virtualPathId, codedelegate); return(virtualPathId); } }