Exemplo n.º 1
0
        protected virtual void ProcessFile(XmlDocument xmlDoc, XmlNamespaceManager nsManager, FileInfo fileInfo)
        {
            Dictionary <MappingColumn, object> headerColumnData = new Dictionary <MappingColumn, object>();

            MappingColumn headerCol = new MappingColumn()
            {
                Name    = "FILENAME",
                Heading = "FILENAME"
            };

            headerColumnData.Add(headerCol, fileInfo.Name);

            // Read the header columns
            foreach (var colConfig in config.Column)
            {
                string xpath     = colConfig.Value;
                string cellValue = GetValue(xpath, xmlDoc.DocumentElement, nsManager, colConfig.IsNarrative);
                headerColumnData.Add(colConfig, cellValue);
            }

            int recordId = InsertData(config.TableName, headerColumnData);

            if (recordId < 0)
            {
                return;
            }

            foreach (var groupConfig in config.Group)
            {
                ProcessGroup(groupConfig, xmlDoc, nsManager, recordId, config.TableName);
            }
        }
Exemplo n.º 2
0
        public void AddData(MappingGroup group, MappingColumn column, string data, bool isBold = false)
        {
            ExcelData excelColumn = new ExcelData()
            {
                Group  = group,
                Column = column,
                Data   = data == null ? string.Empty : data
            };

            currentRow.Data.Add(excelColumn);

            // Add a heading if one doesn't arleady exist
            int dataCount    = currentRow.Data.Count(y => y.Column == column);
            int headingCount = headings.Count(y => y.Column == column);

            if (headingCount < dataCount)
            {
                int insertIndex = -1;

                if (group != null)
                {
                    var lastHeading = headings.LastOrDefault(y => y.Group == group);

                    if (lastHeading != null)
                    {
                        insertIndex = headings.LastIndexOf(lastHeading);
                    }

                    if (insertIndex < 0 && group.Parent != null)
                    {
                        lastHeading = headings.LastOrDefault(y => y.Group == group.Parent);

                        if (lastHeading != null)
                        {
                            insertIndex = headings.LastIndexOf(lastHeading);
                        }
                    }
                }

                ExcelHeading newHeading = new ExcelHeading()
                {
                    Group     = group,
                    Column    = column,
                    DataIndex = headingCount
                };

                if (insertIndex >= 0)
                {
                    headings.Insert(insertIndex + 1, newHeading);
                }
                else
                {
                    headings.Add(newHeading);
                }
            }
        }
Exemplo n.º 3
0
        private void addColumn_Click(object sender, RoutedEventArgs e)
        {
            TreeViewItem         item       = treeView.SelectedItem as TreeViewItem;
            ItemCollection       treeList   = null;
            List <MappingColumn> columnList = null;

            if (item == null)
            {
                treeList   = treeView.Items;
                columnList = config.Column;
            }
            else if (item.Tag is MappingGroup)
            {
                treeList   = item.Items;
                columnList = ((MappingGroup)item.Tag).Column;
            }
            else if (item.Tag is MappingColumn)
            {
                treeList   = ((TreeViewItem)item.Parent).Items;
                columnList = item.Parent is TreeView ? config.Column : ((MappingGroup)((TreeViewItem)item.Parent).Tag).Column;
            }

            MappingColumn newColumn = new MappingColumn();

            newColumn.Name  = "newColumn";
            newColumn.Value = "./";
            columnList.Add(newColumn);

            TreeViewItem newColumnItem = new TreeViewItem();

            newColumnItem.Header = "newColumn";
            newColumnItem.Tag    = newColumn;

            TreeViewItem firstGroup = null;

            foreach (TreeViewItem nextItem in treeList)
            {
                if (nextItem.Tag is MappingGroup)
                {
                    firstGroup = nextItem;
                    break;
                }
            }

            if (firstGroup != null)
            {
                treeList.Insert(treeList.IndexOf(firstGroup), newColumnItem);
            }
            else
            {
                treeList.Add(newColumnItem);
            }

            newColumnItem.IsSelected = true;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Deserializes xml markup from file into an MappingColumn object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output MappingColumn 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 MappingColumn obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(MappingColumn);
     try
     {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Deserializes workflow markup into an MappingColumn object
 /// </summary>
 /// <param name="input">string workflow markup to deserialize</param>
 /// <param name="obj">Output MappingColumn 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 Deserialize(string input, out MappingColumn obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(MappingColumn);
     try
     {
         obj = Deserialize(input);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
        private void LoadColumn(MappingColumn column, TreeViewItem parent = null)
        {
            TreeViewItem item = new TreeViewItem();

            item.Header = column.Name;
            item.Tag    = column;

            if (parent == null)
            {
                treeView.Items.Add(item);
            }
            else
            {
                parent.Items.Add(item);
            }
        }
Exemplo n.º 8
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;
            }
        }
Exemplo n.º 9
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);
                }
            }
        }
Exemplo n.º 10
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);
                }
            }
        }
Exemplo n.º 11
0
 public static bool LoadFromFile(string fileName, out MappingColumn obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
Exemplo n.º 12
0
 public static bool Deserialize(string input, out MappingColumn obj)
 {
     System.Exception exception = null;
     return(Deserialize(input, out obj, out exception));
 }