コード例 #1
0
        private void AppendSettingsNode(OBJS.Data Data, XmlNode ParentRoot, XmlDocument Document)
        {
            foreach (OBJS.Data.DataValue DataValue in Data.GetDataValues())
            {
                XmlElement ItemValue = Document.CreateElement(DataValue.Name);
                if (DataValue.Value == string.Empty || DataValue.Value == null)
                {
                    ItemValue.IsEmpty = true;
                }
                else
                {
                    ItemValue.InnerText = DataValue.Value;
                }

                if (DataValue.Attributes.Count != 0)
                {
                    foreach (OBJS.Data.DataValue Attributes in DataValue.Attributes)
                    {
                        XmlAttribute typeAttr = Document.CreateAttribute(Attributes.Name);
                        typeAttr.InnerText = Attributes.Value;
                        ItemValue.Attributes.Append(typeAttr);
                    }
                }
                ParentRoot.AppendChild(ItemValue);
            }

            foreach (OBJS.Data NestedData in Data.GetNestedData())
            {
                HandleSetData(NestedData, ParentRoot, Document, "");
            }
        }
コード例 #2
0
ファイル: GetObjectLogic.cs プロジェクト: jufman/XMLDatabase
        private static void GetNestedMulitNodeItems(object Item, Type NewObject, OBJS.Data Data)
        {
            List <PropertyInfo> NestedProps = GetProprites(OBJS.Types.NestedMulitNode, NewObject);

            foreach (PropertyInfo NestedProp in NestedProps)
            {
                OBJS.XMLDatabaseRetriveItem XMLDatabaseRetriveItem = (OBJS.XMLDatabaseRetriveItem)NestedProp.GetCustomAttributes(typeof(OBJS.XMLDatabaseRetriveItem), true).FirstOrDefault();

                string DataSetName = (XMLDatabaseRetriveItem.DataSet == string.Empty) ? NestedProp.Name : XMLDatabaseRetriveItem.DataSet;

                List <OBJS.Data> NestedData = Data.GetNestedData(DataSetName);
                foreach (OBJS.Data NestedSettingsData in NestedData)
                {
                    List <OBJS.Data.DataValue> NestedDettingsData = NestedSettingsData.GetAllNodes(XMLDatabaseRetriveItem.ItemName);

                    Type ListType = NestedProp.PropertyType.GetGenericArguments()[0];

                    System.Collections.IList IList = (System.Collections.IList)NestedProp.GetValue(Item, null);
                    foreach (OBJS.Data.DataValue Node in NestedDettingsData)
                    {
                        IList.Add(GetItemObject(ListType, new List <OBJS.Data.DataValue>()
                        {
                            Node
                        }));
                    }
                }
            }
        }
コード例 #3
0
ファイル: GetObjectLogic.cs プロジェクト: jufman/XMLDatabase
        private static void GetNestedItems(object Item, Type NewObject, OBJS.Data Data)
        {
            List <PropertyInfo> NestedProps = GetProprites(OBJS.Types.NestedList, NewObject);

            foreach (PropertyInfo NestedProp in NestedProps)
            {
                OBJS.XMLDatabaseRetriveItem XMLDatabaseRetriveItem = (OBJS.XMLDatabaseRetriveItem)NestedProp.GetCustomAttributes(typeof(OBJS.XMLDatabaseRetriveItem), true).FirstOrDefault();

                string DataSetName = (XMLDatabaseRetriveItem.DataSet == string.Empty) ? NestedProp.Name : XMLDatabaseRetriveItem.DataSet;

                List <OBJS.Data> NestedDettingsData = Data.GetNestedData(DataSetName);

                try
                {
                    foreach (OBJS.Data DataValues in NestedDettingsData)
                    {
                        Type ListType = NestedProp.PropertyType.GetGenericArguments()[0];
                        if (XMLDatabaseRetriveItem.NestedListClassType != null)
                        {
                            ListType = XMLDatabaseRetriveItem.NestedListClassType;
                        }

                        System.Collections.IList IList = (System.Collections.IList)NestedProp.GetValue(Item, null);
                        if (IList == null)
                        {
                            Type   genericListType = typeof(List <>);
                            Type[] typeArgs        = new[] { ListType };
                            var    generic         = genericListType.MakeGenericType(typeArgs);
                            IList = (System.Collections.IList)Activator.CreateInstance(generic);
                            NestedProp.SetValue(Item, IList, null);
                        }
                        object ItemObject = GetItem(DataValues, ListType, null);
                        IList.Add(ItemObject);
                    }
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }
        }
コード例 #4
0
        private bool AppendNode(OBJS.Data Data, XmlNode ParentRoot, XmlDocument Document)
        {
            XmlNode NewItem = Document.CreateNode(XmlNodeType.Element, Data.DefaultItemName, null);

            foreach (OBJS.Data.DataValue DataValue in Data.GetDataValues())
            {
                XmlElement ItemValue = Document.CreateElement(DataValue.Name);
                if (DataValue.Value == string.Empty || DataValue.Value == null)
                {
                    ItemValue.IsEmpty = true;
                }
                else
                {
                    ItemValue.InnerText = DataValue.Value;
                }

                if (DataValue.Attributes.Count != 0)
                {
                    foreach (OBJS.Data.DataValue Attributes in DataValue.Attributes)
                    {
                        XmlAttribute typeAttr = Document.CreateAttribute(Attributes.Name);
                        typeAttr.InnerText = Attributes.Value;
                        ItemValue.Attributes.Append(typeAttr);
                    }
                }
                NewItem.AppendChild(ItemValue);
            }

            foreach (OBJS.Data NestedData in Data.GetNestedData())
            {
                HandleSetData(NestedData, NewItem, Document, "");
            }

            ParentRoot.AppendChild(NewItem);

            return(true);
        }
コード例 #5
0
        private List <OBJS.Data> HandleLoadData(OBJS.Data DataSet, XmlNode Document, string ParentNode = "//DataStore/", string Location = "//DataStore")
        {
            List <OBJS.Data> Data = new List <OBJS.Data>();

            int id = 1;

            string SearchClause = "";

            if (DataSet.SearchClause != string.Empty)
            {
                SearchClause = "[" + DataSet.SearchClause + "]";
            }

            XmlNodeList nodes = Document.SelectNodes(ParentNode + DataSet.DataSet + "/" + DataSet.DefaultItemName + SearchClause);

            foreach (XmlNode node in nodes)
            {
                OBJS.Data FoundData = new OBJS.Data();

                FoundData.DataSet  = DataSet.DataSet;
                FoundData.ID       = id;
                FoundData.Location = Location + "/" + DataSet.DataSet + "/" + DataSet.DefaultItemName + "[" + id + "]";

                foreach (OBJS.Data.DataValue DataValue in DataSet.GetDataValues())
                {
                    string      value     = string.Empty;
                    XmlNodeList DataNodes = node.SelectNodes(DataValue.Name);

                    foreach (XmlNode DataNode in DataNodes)
                    {
                        OBJS.Data.DataValue DataValues = new OBJS.Data.DataValue();

                        if (DataNode != null)
                        {
                            value = DataNode.InnerText;
                            foreach (XmlAttribute XmlAttribute in DataNode.Attributes)
                            {
                                OBJS.Data.DataValue Attribute = new OBJS.Data.DataValue();

                                Attribute.Name     = XmlAttribute.Name;
                                Attribute.Value    = XmlAttribute.Value;
                                Attribute.Location = Location + "/" + DataSet.DataSet + "/" + DataSet.DefaultItemName + "[" + id + "]/" + DataValue.Name;

                                DataValues.Attributes.Add(Attribute);
                            }
                        }

                        DataValues.Value    = value;
                        DataValues.Name     = DataValue.Name;
                        DataValues.Location = Location + "/" + DataSet.DataSet + "/" + DataSet.DefaultItemName + "[" + id + "]/" + DataValue.Name;

                        FoundData.GetDataValues().Add(DataValues);
                    }
                }

                foreach (OBJS.Data DataValue in DataSet.GetNestedData())
                {
                    if (DataValue.IsSettingsItem)
                    {
                        OBJS.Data NestedData = HandleLoadSettings(DataValue, node, FoundData.Location + "/", FoundData.Location);
                        FoundData.AddData(NestedData);
                    }
                    else
                    {
                        List <OBJS.Data> NestedData = HandleLoadData(DataValue, node, FoundData.Location + "/", FoundData.Location);
                        FoundData.AddData(NestedData);
                    }
                }

                Data.Add(FoundData);
                id++;
            }

            return(Data);
        }