示例#1
0
        public void FillIn(XmlElement elem)
        {
            EnableStrings     = elem.GetAttribute("strings") == "1";
            PlaceholderPrefix = elem.GetAttribute("placeholder_prefix");
            PlaceholderSuffix = elem.GetAttribute("placeholder_suffix");

            Operations = new List <FileOperation>();
            for (var i = 0; i < elem.ChildNodes.Count; i++)
            {
                var child = elem.ChildNodes[i];
                if (!(child is XmlElement))
                {
                    continue;
                }

                Type op_type;
                if (!FileOperation.FileOperationsByKey.TryGetValue(child.Name, out op_type))
                {
                    throw new Exception($"Unknown file operation: {child.Name}");
                }

                var op = FileOperation.CreateFileOperation <FileOperation>(child.Name, op_type);
                op.FillIn(child as XmlElement);

                Operations.Add(op);
            }
        }
示例#2
0
        public static FileOperation Copy(FileOperation op)
        {
            Type op_type;

            if (!FileOperation.FileOperationsByKey.TryGetValue(op.Key, out op_type))
            {
                throw new Exception($"Unknown file operation: {op.Key}");
            }

            var new_op = FileOperation.CreateFileOperation <FileOperation>(op.Key, op_type);

            op.CopyTo(new_op);

            return(new_op);
        }
示例#3
0
        public override void FillInChild(XmlNode node)
        {
            if (!(node is XmlElement))
            {
                return;
            }

            var child = (XmlElement)node;

            if (child.Name == "SourceFiles")
            {
                SourceFiles = new List <string>();

                for (var i = 0; i < child.ChildNodes.Count; i++)
                {
                    var innerchild = child.ChildNodes[i] as XmlElement;
                    if (innerchild == null)
                    {
                        continue;
                    }

                    if (innerchild.Name != "SourceFile")
                    {
                        throw new Exception("Children of SourceFiles must be SourceFile elements");
                    }

                    if (innerchild.ChildNodes.Count < 1 || !(innerchild.ChildNodes[0] is XmlText))
                    {
                        throw new Exception("SourceFile elements must have a text child");
                    }

                    SourceFiles.Add(((XmlText)innerchild.ChildNodes[0]).Value);
                }
            }
            else if (child.Name == "SourcePattern")
            {
                if (child.ChildNodes.Count < 1 || !(child.ChildNodes[0] is XmlText))
                {
                    throw new Exception("SourcePattern elements must have a text child");
                }

                SourcePattern = ((XmlText)child.ChildNodes[0]).Value.Trim();
            }
            else if (child.Name == "TargetFiles")
            {
                TargetFiles = new List <string>();

                for (var i = 0; i < child.ChildNodes.Count; i++)
                {
                    var innerchild = child.ChildNodes[i] as XmlElement;
                    if (innerchild == null)
                    {
                        continue;
                    }

                    if (innerchild.Name != "TargetFile")
                    {
                        throw new Exception("Children of TargetFiles must be TargetFile elements");
                    }

                    if (innerchild.ChildNodes.Count < 1 || !(innerchild.ChildNodes[0] is XmlText))
                    {
                        throw new Exception("TargetFile elements must have a text child");
                    }

                    TargetFiles.Add(((XmlText)innerchild.ChildNodes[0]).Value);
                }
            }
            else if (child.Name == "TargetExceptionRules")
            {
                TargetExceptionRules = new List <Regex>();

                for (var i = 0; i < child.ChildNodes.Count; i++)
                {
                    var innerchild = child.ChildNodes[i] as XmlElement;
                    if (innerchild == null)
                    {
                        continue;
                    }

                    if (innerchild.Name != "TargetExceptionRule")
                    {
                        throw new Exception("Children of TargetExceptionRules must be TargetExceptionRule elements");
                    }

                    if (innerchild.ChildNodes.Count < 1 || !(innerchild.ChildNodes[0] is XmlText))
                    {
                        throw new Exception("TargetExceptionRule elements must have a text child");
                    }

                    TargetExceptionRules.Add(new Regex(((XmlText)innerchild.ChildNodes[0]).Value));
                }
            }
            else if (child.Name == "TargetPattern")
            {
                if (child.ChildNodes.Count < 1 || !(child.ChildNodes[0] is XmlText))
                {
                    throw new Exception("TargetPattern elements must have a text child");
                }

                TargetPattern = ((XmlText)child.ChildNodes[0]).Value.Trim();
            }
            else if (child.Name == "Operations")
            {
                for (var i = 0; i < child.ChildNodes.Count; i++)
                {
                    var innerchild = child.ChildNodes[i] as XmlElement;
                    if (innerchild == null)
                    {
                        continue;
                    }

                    Type op_type;
                    if (!FileOperation.FileOperationsByKey.TryGetValue(innerchild.Name, out op_type))
                    {
                        throw new Exception($"Unknown file operation: {innerchild.Name}");
                    }

                    var op = FileOperation.CreateFileOperation <FileOperation>(innerchild.Name, op_type);
                    op.FillIn(innerchild as XmlElement);

                    Operations.Add(op);
                }
            }
            else if (child.Name == "Mode")
            {
                if (child.ChildNodes.Count < 1 || !(child.ChildNodes[0] is XmlText))
                {
                    throw new Exception("Mode elements must have a text child");
                }

                Mode = (BulkMode)Enum.Parse(typeof(BulkMode), ((XmlText)child.ChildNodes[0]).Value.Trim(), true);
            }
        }