/// <exclude /> public static ActionNode Deserialize(Dictionary <string, string> serializedValueCollection, bool removeEntiresFromCollection = false) { string treeId = StringConversionServices.DeserializeValueString(serializedValueCollection[TreeIdSerializedKeyName]); int actionNodeId = StringConversionServices.DeserializeValueInt(serializedValueCollection[ActionNodeIdSerializedKeyName]); if (removeEntiresFromCollection) { serializedValueCollection.Remove(TreeIdSerializedKeyName); serializedValueCollection.Remove(ActionNodeIdSerializedKeyName); } Tree tree = TreeFacade.GetTree(treeId); return(tree?.GetActionNode(actionNodeId)); }
public Dictionary <EntityToken, IEnumerable <EntityToken> > GetParents(IEnumerable <EntityToken> entityTokens) { Dictionary <EntityToken, IEnumerable <EntityToken> > result = new Dictionary <EntityToken, IEnumerable <EntityToken> >(); foreach (EntityToken entityToken in entityTokens) { TreeNodeDynamicContext dynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Up) { CurrentEntityToken = entityToken }; if (entityToken is TreeSimpleElementEntityToken || entityToken is TreeFunctionElementGeneratorEntityToken) { var parentEntityTokenSource = entityToken as IEntityTokenContainingParentEntityToken; try { result.Add(entityToken, new[] { parentEntityTokenSource.GetParentEntityToken() }); } catch (Exception ex) { string treeId; if (entityToken is TreeSimpleElementEntityToken) { treeId = (entityToken as TreeSimpleElementEntityToken).TreeNodeId; } else if (entityToken is TreeFunctionElementGeneratorEntityToken) { treeId = (entityToken as TreeFunctionElementGeneratorEntityToken).TreeNodeId; } else { throw new InvalidOperationException("This code should not be reachable."); } Log.LogError("TreeFacade", "The tree '{0}' failed to return parent entity tokens and are ignored", treeId); Log.LogError("TreeFacade", ex); } } else if (entityToken is TreeDataFieldGroupingElementEntityToken) { TreeDataFieldGroupingElementEntityToken treeDataFieldGroupingElementEntityToken = entityToken as TreeDataFieldGroupingElementEntityToken; string treeId = entityToken.Source; try { Tree tree = TreeFacade.GetTree(treeId); string treeNodeId = treeDataFieldGroupingElementEntityToken.TreeNodeId; TreeNode treeNode = tree.GetTreeNode(treeNodeId); dynamicContext.FieldGroupingValues = treeDataFieldGroupingElementEntityToken.GroupingValues; dynamicContext.FieldFolderRangeValues = treeDataFieldGroupingElementEntityToken.FolderRangeValues; dynamicContext.CurrentTreeNode = treeNode; result.Add(entityToken, treeNode.ParentNode.GetEntityTokens(entityToken, dynamicContext)); } catch (Exception ex) { Log.LogError("TreeFacade", $"The tree '{treeId}' failed to return parent entity tokens and are ignored"); Log.LogError("TreeFacade", ex); } } else if (entityToken is DataEntityToken) { DataEntityToken dataEntityToken = entityToken as DataEntityToken; Type interfaceType = dataEntityToken.InterfaceType; foreach (Tree tree in TreeFacade.AllTrees) { List <TreeNode> treeNodes; if (!tree.BuildProcessContext.DataInteraceToTreeNodes.TryGetValue(interfaceType, out treeNodes)) { continue; } IEnumerable <EntityToken> concatList = null; foreach (TreeNode treeNode in treeNodes) { try { dynamicContext.CurrentTreeNode = treeNode; concatList = concatList.ConcatOrDefault(treeNode.ParentNode.GetEntityTokens(entityToken, dynamicContext)); } catch (Exception ex) { Log.LogError("TreeFacade", $"The tree '{treeNode.Tree.TreeId}' failed to return parent entity tokens and are ignored"); Log.LogError("TreeFacade", ex); } } if (concatList != null) { // Filtering the current element to avoid loops while resolving security concatList = concatList.Where(e => !entityToken.Equals(e)); IEnumerable <EntityToken> existingList; if (result.TryGetValue(entityToken, out existingList)) { result[entityToken] = existingList.Concat(concatList); } else { result.Add(entityToken, concatList); } } } } else if (entityToken is TreePerspectiveEntityToken) { result.Add(entityToken, new[] { TreeSharedRootsFacade.SharedRootFolders[entityToken.Id].AttachmentPoint.AttachingPoint.EntityToken }); } } return(result); }
public IEnumerable <Element> GetChildren(EntityToken parentEntityToken, Dictionary <string, string> piggybag) { TreeSharedRootsFacade.Initialize(Context.ProviderName); List <Tree> trees; if (parentEntityToken is TreePerspectiveEntityToken) { if (TreeSharedRootsFacade.SharedRootFolders.ContainsKey(parentEntityToken.Id)) { trees = TreeSharedRootsFacade.SharedRootFolders[parentEntityToken.Id].Trees; } else { trees = new List <Tree>(); } } else { if (piggybag.ContainsKey(StringConstants.PiggybagTreeId)) { string treeId = piggybag.Where(f => f.Key == StringConstants.PiggybagTreeId).SingleOrDefault().Value; Tree tree = TreeFacade.GetTree(treeId); if (tree == null) { return new Element[] { } } ; trees = new List <Tree> { tree }; } else { trees = new List <Tree>(); int counter = 0; while (true) { string key = StringConstants.PiggybagSharedTreeId + (counter++); if (!piggybag.ContainsKey(key)) { break; } string treeId = piggybag[key]; Tree tree = TreeFacade.GetTree(treeId); if (tree != null) { trees.Add(tree); } } } } IEnumerable <Element> result = new List <Element>(); foreach (Tree tree in trees) { TreeNodeDynamicContext dynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down) { ElementProviderName = this.Context.ProviderName, Piggybag = piggybag, CurrentEntityToken = parentEntityToken }; try { if (parentEntityToken is TreePerspectiveEntityToken) { TreeNode treeNode = tree.RootTreeNode; dynamicContext.CurrentTreeNode = treeNode; IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext); result = result.ConcatOrDefault(elements); } else if (parentEntityToken is TreeSimpleElementEntityToken) { TreeNode treeNode = tree.GetTreeNode(parentEntityToken.Id); if (treeNode == null) { throw new InvalidOperationException("Tree is out of sync"); } dynamicContext.CurrentTreeNode = treeNode; IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext); result = result.ConcatOrDefault(elements); } else if (parentEntityToken is TreeFunctionElementGeneratorEntityToken) { TreeNode treeNode = tree.GetTreeNode(parentEntityToken.Id); if (treeNode == null) { throw new InvalidOperationException("Tree is out of sync"); } dynamicContext.CurrentTreeNode = treeNode; IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext); result = result.ConcatOrDefault(elements); } else if (parentEntityToken is TreeDataFieldGroupingElementEntityToken) { TreeDataFieldGroupingElementEntityToken castedParentEntityToken = parentEntityToken as TreeDataFieldGroupingElementEntityToken; TreeNode treeNode = tree.GetTreeNode(parentEntityToken.Id); if (treeNode == null) { throw new InvalidOperationException("Tree is out of sync"); } dynamicContext.CurrentTreeNode = treeNode; dynamicContext.FieldGroupingValues = castedParentEntityToken.GroupingValues; dynamicContext.FieldFolderRangeValues = castedParentEntityToken.FolderRangeValues; IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext); result = result.ConcatOrDefault(elements); } else if (parentEntityToken is DataEntityToken) { DataEntityToken dataEntityToken = parentEntityToken as DataEntityToken; Type interfaceType = dataEntityToken.InterfaceType; List <TreeNode> treeNodes; if (tree.BuildProcessContext.DataInteraceToTreeNodes.TryGetValue(interfaceType, out treeNodes) == false) { throw new InvalidOperationException(); } string parentNodeId = piggybag.GetParentIdFromPiggybag(); TreeNode treeNode = treeNodes.Where(f => f.ParentNode.Id == parentNodeId).SingleOrDefault(); if (treeNode == null) { throw new InvalidOperationException("Tree is out of sync"); } dynamicContext.CurrentTreeNode = treeNode; IEnumerable <Element> elements = treeNode.ChildNodes.GetElements(parentEntityToken, dynamicContext); result = result.ConcatOrDefault(elements); } else { throw new NotImplementedException("Unhandled entityt token type"); } result = result.Evaluate(); } catch (Exception ex) { LoggingService.LogError("TreeFacade", string.Format("Getting elements from the three '{0}' failed", tree.TreeId)); LoggingService.LogError("TreeFacade", ex); Element errorElement = ShowErrorElementHelper.CreateErrorElement( StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "KeyFacade.ErrorTreeNode.Label"), tree.TreeId, ex.Message); return(new Element[] { errorElement }); } } return(result); } }