예제 #1
0
 /// <summary>
 /// Deserializes xml markup from file into an MappingGroup object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output MappingGroup object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out MappingGroup obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(MappingGroup);
     try
     {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
예제 #2
0
        private void LoadResults()
        {
            if (treeView.SelectedItem == null)
            {
                resultsText.Text = string.Empty;
                return;
            }

            TreeViewItem  item   = treeView.SelectedItem as TreeViewItem;
            MappingGroup  group  = item.Tag as MappingGroup;
            MappingColumn column = item.Tag as MappingColumn;

            if (group != null)
            {
                List <XmlNode> contexts = GetContext(group);
                string         results  = string.Empty;

                foreach (var context in contexts)
                {
                    results += context.OuterXml + "\r\n\r\n";
                }

                resultsText.Text = results;
            }
            else if (column != null)
            {
                var            parent   = item.Parent as TreeViewItem;
                List <XmlNode> contexts = parent != null?GetContext(parent.Tag as MappingGroup) : new List <XmlNode>(new XmlNode[] { xmlDoc.DocumentElement });

                string results = string.Empty;

                foreach (var context in contexts)
                {
                    try
                    {
                        var selectedNodes = context.SelectNodes(column.Value, nsManager);

                        foreach (XmlNode selectedNode in selectedNodes)
                        {
                            results += selectedNode.InnerXml + "\r\n\r\n";
                        }
                    }
                    catch { }
                }

                resultsText.Text = results;
            }
        }
예제 #3
0
        private void xpathText_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            LoadResults();

            TreeViewItem  item   = treeView.SelectedItem as TreeViewItem;
            MappingGroup  group  = item.Tag as MappingGroup;
            MappingColumn column = item.Tag as MappingColumn;

            removeButton.IsEnabled           =
                moveUpButton.IsEnabled       =
                    moveDownButton.IsEnabled = false;

            if (group != null)
            {
                ItemCollection list = item.Parent is TreeViewItem ? ((TreeViewItem)item.Parent).Items : ((TreeView)item.Parent).Items;
            }
        }
예제 #4
0
        protected virtual void ProcessGroup(MappingGroup groupConfig, XmlNode parentNode, XmlNamespaceManager nsManager, int parentId, string parentName)
        {
            XmlNodeList groupNodes = null;

            try
            {
                groupNodes = parentNode.SelectNodes(groupConfig.Context, nsManager);
            }
            catch (Exception ex)
            {
                Log(string.Format("XPATH error when selecting context for the group {0}: {1}", groupConfig.TableName, ex.Message));
                return;
            }

            if (groupNodes.Count == 0)
            {
                return;
            }

            foreach (XmlElement groupNode in groupNodes)
            {
                Dictionary <MappingColumn, object> groupColumnData = new Dictionary <MappingColumn, object>();

                var parentCol = new MappingColumn()
                {
                    Name    = parentName + "Id",
                    Heading = parentName + "Id"
                };
                groupColumnData.Add(parentCol, parentId);

                foreach (var colConfig in groupConfig.Column)
                {
                    string xpath     = colConfig.Value;
                    string cellValue = GetValue(xpath, groupNode, nsManager, colConfig.IsNarrative);
                    groupColumnData.Add(colConfig, cellValue);
                }

                int nextId = InsertData(groupConfig.TableName, groupColumnData);

                foreach (var childGroup in groupConfig.Group)
                {
                    ProcessGroup(childGroup, groupNode, nsManager, nextId, groupConfig.TableName);
                }
            }
        }
예제 #5
0
        private void ProcessGroup(DbConnection conn, MappingGroup groupConfig, XmlNode parentNode, XmlNamespaceManager nsManager, int parentId, string parentName)
        {
            var groupNodes = parentNode.SelectNodes(groupConfig.Context, nsManager);

            if (groupNodes.Count == 0)
            {
                return;
            }

            foreach (XmlElement groupNode in groupNodes)
            {
                Dictionary <MappingColumn, object> groupColumnData = new Dictionary <MappingColumn, object>();

                MappingColumn parentCol = new MappingColumn()
                {
                    Name    = parentName + "Id",
                    Heading = parentName + "Id"
                };

                groupColumnData.Add(parentCol, parentId);

                foreach (var colConfig in groupConfig.Column)
                {
                    string xpath     = colConfig.Value;
                    string cellValue = GetValue(xpath, groupNode, nsManager, colConfig.IsNarrative);
                    groupColumnData.Add(colConfig, cellValue);
                }

                int nextId = InsertData(groupConfig.TableName, groupColumnData);

                foreach (var childGroup in groupConfig.Group)
                {
                    ProcessGroup(conn, childGroup, groupNode, nsManager, nextId, groupConfig.TableName);
                }
            }
        }
예제 #6
0
        private void addGroupButton_Click(object sender, RoutedEventArgs e)
        {
            TreeViewItem        item      = treeView.SelectedItem as TreeViewItem;
            ItemCollection      treeList  = null;
            List <MappingGroup> groupList = null;

            if (item == null || (item.Tag is MappingColumn && item.Parent is TreeView))
            {
                treeList  = treeView.Items;
                groupList = config.Group;
            }
            else if (item.Tag is MappingGroup)
            {
                treeList  = item.Items;
                groupList = ((MappingGroup)item.Tag).Group;
            }
            else if (item.Tag is MappingColumn && item.Parent is TreeViewItem && ((TreeViewItem)item.Parent).Tag is MappingGroup)
            {
                treeList  = ((TreeViewItem)item.Parent).Items;
                groupList = ((MappingGroup)(((TreeViewItem)item.Parent).Tag)).Group;
            }

            MappingGroup newGroup = new MappingGroup();

            newGroup.TableName = "NewGroup";
            newGroup.Context   = "./";
            groupList.Add(newGroup);

            TreeViewItem newGroupItem = new TreeViewItem();

            newGroupItem.Tag    = newGroup;
            newGroupItem.Header = "NewGroup";

            treeList.Add(newGroupItem);
            newGroupItem.IsSelected = true;
        }
        private static void ValidateGroup(MappingGroup group)
        {
            MappingConfig.ValidateColumns(group.TableName, group.Column);

            group.Group.ForEach(g => MappingConfig.ValidateGroup(g));
        }
        private ADOX.Table CreateGroupTable(ADOX.CatalogClass cat, ADOX.Table parentTable, MappingGroup group, bool createIndex)
        {
            var newTable = CreateTable(cat, parentTable, group.TableName, group.Column, createIndex);

            foreach (var childGroup in group.Group)
            {
                int index = group.Group.IndexOf(childGroup);            // MDB has maximum of 32 indexes per table
                CreateGroupTable(cat, newTable, childGroup, index < 31);
            }

            return(newTable);
        }
예제 #9
0
 public static bool Deserialize(string input, out MappingGroup obj)
 {
     System.Exception exception = null;
     return(Deserialize(input, out obj, out exception));
 }
예제 #10
0
 public static bool LoadFromFile(string fileName, out MappingGroup obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }