Ejemplo n.º 1
0
        public static void Apply(this ElementNode parent, IElementNavigator nav, string name = null)
        {
            var n = ElementNode.FromNavigator(nav);

            if (name != null)
            {
                n.Name = name;
            }
            parent.Add(n);
        }
Ejemplo n.º 2
0
#pragma warning restore 618

        static void MaskElement(ElementNode element)
        {
            if (null != element)
            {
                element.childNodes.Clear();
                element.Add(new CommentNode("Removed", element));
                element.text       = null;
                element.attributes = null;
            }
        }
        public static void AddSecurityTag(this ElementNode node, ProcessResult result)
        {
            if (node == null)
            {
                return;
            }

            if (result.ProcessRecords.Count == 0)
            {
                return;
            }

            ElementNode metaNode = node.GetMeta();
            Meta        meta     = metaNode?.ToPoco <Meta>() ?? new Meta();

            if (result.IsRedacted && !meta.Security.Any(x =>
                                                        string.Equals(x.Code, SecurityLabels.REDACT.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.REDACT);
            }

            if (result.IsAbstracted && !meta.Security.Any(x =>
                                                          string.Equals(x.Code, SecurityLabels.ABSTRED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.ABSTRED);
            }

            if (result.IsCryptoHashed && !meta.Security.Any(x =>
                                                            string.Equals(x.Code, SecurityLabels.CRYTOHASH.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.CRYTOHASH);
            }

            if (result.IsPerturbed && !meta.Security.Any(x =>
                                                         string.Equals(x.Code, SecurityLabels.PERTURBED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.PERTURBED);
            }

            ElementNode newMetaNode = ElementNode.FromElement(meta.ToTypedElement());

            if (metaNode == null)
            {
                node.Add(s_provider, newMetaNode);
            }
            else
            {
                node.Replace(s_provider, metaNode, newMetaNode);
            }
        }
Ejemplo n.º 4
0
        public void InitTitlebar(IRootElement nodeBase)
        {
            Titlebar = new TitlebarContext(nodeBase);
            ElementNode.Add(Titlebar.ElementNode);

            Titlebar.TitlebarMouseDown = args =>
            {
                WindowingService.WindowTitleBarDown(args, this);
            };

            Titlebar.TitlebarMouseUp = args =>
            {
                WindowingService.WindowTitleBarUp(args, this);
            };
        }
        public void AddSecurityTag(ElementNode node, ProcessResult result)
        {
            if (node == null || result.ProcessRecords.Count == 0)
            {
                return;
            }

            var metaNode = (ElementNode)node.GetMeta();
            var meta     = metaNode?.ToPoco <Meta>() ?? new Meta();

            if (result.IsRedacted && !meta.Security.Any(x =>
                                                        string.Equals(x.Code, SecurityLabels.REDACT.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.REDACT);
            }

            if (result.IsAbstracted && !meta.Security.Any(x =>
                                                          string.Equals(x.Code, SecurityLabels.ABSTRED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.ABSTRED);
            }

            if (result.IsCryptoHashed && !meta.Security.Any(x =>
                                                            string.Equals(x.Code, SecurityLabels.CRYTOHASH.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.CRYTOHASH);
            }

            if (result.IsEncrypted && !meta.Security.Any(x =>
                                                         string.Equals(x.Code, SecurityLabels.MASKED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.MASKED);
            }

            if (result.IsPerturbed && !meta.Security.Any(x =>
                                                         string.Equals(x.Code, SecurityLabels.PERTURBED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.PERTURBED);
            }

            if (result.IsSubstituted && !meta.Security.Any(x =>
                                                           string.Equals(x.Code, SecurityLabels.SUBSTITUTED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.SUBSTITUTED);
            }

            if (result.IsGeneralized && !meta.Security.Any(x =>
                                                           string.Equals(x.Code, SecurityLabels.GENERALIZED.Code, StringComparison.InvariantCultureIgnoreCase)))
            {
                meta.Security.Add(SecurityLabels.GENERALIZED);
            }

            var newMetaNode = ElementNode.FromElement(meta.ToTypedElement());

            if (metaNode == null)
            {
                node.Add(s_provider, newMetaNode, _metaNodeName);
            }
            else
            {
                node.Replace(s_provider, metaNode, newMetaNode);
            }
        }
Ejemplo n.º 6
0
        private ProcessResult SubstituteNode(ElementNode node, ElementNode replacementNode, HashSet <ElementNode> visitedNodes, HashSet <ElementNode> keepNodes)
        {
            var processResult = new ProcessResult();

            if (node == null || replacementNode == null || visitedNodes.Contains(node))
            {
                return(processResult);
            }

            // children names to replace, multiple to multiple replacement
            var replaceChildrenNames = replacementNode.Children().Select(element => element.Name).ToHashSet();

            foreach (var name in replaceChildrenNames)
            {
                var children       = node.Children(name).Cast <ElementNode>().ToList();
                var targetChildren = replacementNode.Children(name).Cast <ElementNode>().ToList();

                int i = 0;
                foreach (var child in children)
                {
                    if (visitedNodes.Contains(child))
                    {
                        // Skip replacement if child already processed before.
                        i++;
                        continue;
                    }
                    else if (i < targetChildren.Count)
                    {
                        // We still have target nodes, do replacement
                        SubstituteNode(child, targetChildren[i++], visitedNodes, keepNodes);
                    }
                    else if (keepNodes.Contains(child))
                    {
                        // Substitute with an empty node when no target node available but we need to keep this node
                        SubstituteNode(child, GetDummyNode(), visitedNodes, keepNodes);
                    }
                    else
                    {
                        // Remove source node when no target node available and we don't need to keep the source node
                        node.Remove(child);
                    }
                }

                while (i < targetChildren.Count)
                {
                    // Add extra target nodes, create a new copy before adding
                    node.Add(s_provider, ElementNode.FromElement(targetChildren[i++]));
                }
            }

            // children nodes not presented in replacement value, we need either remove or keep a dummy copy
            var nonReplacementChildren = node.Children()
                                         .Where(element => !replaceChildrenNames.Contains(element.Name))
                                         .Cast <ElementNode>().ToList();

            foreach (var child in nonReplacementChildren)
            {
                if (visitedNodes.Contains(child))
                {
                    continue;
                }
                else if (keepNodes.Contains(child))
                {
                    SubstituteNode(child, GetDummyNode(), visitedNodes, keepNodes);
                }
                else
                {
                    node.Remove(child);
                }
            }

            node.Value = replacementNode.Value;
            processResult.AddProcessRecord(AnonymizationOperations.Substitute, node);
            return(processResult);
        }
 private static void MaskElement(ElementNode element)
 {
     if (element != null)
     {
         element.childNodes.Clear();
         element.Add(new CommentNode("Removed", element));
         element.text = null;
         element.attributes = null;
     }
 }
Ejemplo n.º 8
0
 public void InitContentPane(IRootElement nodeBase)
 {
     ContentPane = new ContentPaneContext(nodeBase);
     ElementNode.Add(ContentPane.ElementNode);
 }
Ejemplo n.º 9
0
 public void InitTabSection(IRootElement nodeBase)
 {
     TabSection = new TabSectionContext(nodeBase);
     ElementNode.Add(TabSection.ElementNode);
 }