Ejemplo n.º 1
0
        } // @ internal static Fishie[] GetFishes(string rod, string zone, string bait, bool wanted)

        internal static void ToggleWanted(Fishie fish)
        {
            XmlDocument xmlDoc     = GetFishDB(fish.rod);
            string      xpathQuery = string.Format("/Rod/Fish[@name=\"{0}\"]", fish.name);
            XmlNode     fishNode   = xmlDoc.SelectSingleNode(xpathQuery);

            fishNode.Attributes["wanted"].Value = ("Yes" == fishNode.Attributes["wanted"].Value) ? "No" : "Yes";
            FishDBChanged(fish.rod);
        } // @ internal static void ToggleWanted(Fishie fish)
Ejemplo n.º 2
0
        } // @ internal static Fishie[] GetFishes(string rod, string zone, string bait, bool wanted)

        /// <summary>
        /// Toggle if a fish is wanted or unwanted and record the change in the XML DBs
        /// </summary>
        /// <param name="fish">Fish to toggle</param>
        internal static void ToggleWanted(Fishie fish)
        {
            XmlDocument xmlDoc     = GetFishDB(fish.rod);
            string      xpathQuery = string.Format(XPathFormatFishByNameAndIDs, fish.name, fish.ID1, fish.ID2, fish.ID3);
            XmlNode     fishNode   = xmlDoc.SelectSingleNode(xpathQuery);

            fishNode.Attributes[XMLAttrWanted].Value = (Resources.Yes == fishNode.Attributes[XMLAttrWanted].Value) ? Resources.No : Resources.Yes;
            FishDBChanged(fish.rod);
        } // @ internal static void ToggleWanted(Fishie fish)
Ejemplo n.º 3
0
        } // @ private static XmlDocument GetFishDB(string rod)

        /// <summary>
        /// Get all fishes in an XML fish DB that are wanted or unwanted for a rod, zone, and bait
        /// </summary>
        /// <param name="rod">the rod name</param>
        /// <param name="zone">the zone name</param>
        /// <param name="bait">the bait name</param>
        /// <param name="wanted">true to select wanted fish, false for unwanted fish</param>
        /// <returns>array of <c>Fishie</c> that match the conditions passed</returns>
        internal static IEnumerable <Fishie> GetFishes(string rod, string zone, string bait, bool wanted)
        {
            XmlDocument xmlDoc     = GetFishDB(rod);
            string      xpathQuery = string.Format(XPathFormatFishByZoneBaitAndWanted, zone, bait, wanted ? Resources.Yes : Resources.No);
            XmlNodeList nodes      = xmlDoc.SelectNodes(xpathQuery);

            Fishie[] fishes = new Fishie[nodes.Count];
            int      i      = 0;

            foreach (XmlNode node in nodes)
            {
                fishes[i++] = new Fishie(node.Attributes[XMLAttrName].Value, rod, node.Attributes[XMLAttrID1].Value, node.Attributes[XMLAttrID2].Value, node.Attributes[XMLAttrID3].Value);
            }

            return(fishes);
        } // @ internal static Fishie[] GetFishes(string rod, string zone, string bait, bool wanted)
Ejemplo n.º 4
0
        } // @ private static XmlDocument GetFishDB(string rod)

        internal static Fishie[] GetFishes(string rod, string zone, string bait, bool wanted)
        {
            XmlDocument xmlDoc     = GetFishDB(rod);
            string      xpathQuery = string.Format("/Rod/Fish[Zones/Zone=\"{0}\"][Baits/Bait=\"{1}\"][@wanted=\"{2}\"]", zone, bait, wanted ? "Yes" : "No");
            XmlNodeList nodes      = xmlDoc.SelectNodes(xpathQuery);

            Fishie[] fishes = new Fishie[nodes.Count];
            int      i      = 0;

            foreach (XmlNode node in nodes)
            {
                //old: fishes[i++] = new Fishie(node.Attributes["name"].Value, rod, node.Attributes["ID1"].Value, node.Attributes["ID2"].Value, node.Attributes["ID3"].Value, node.Attributes["ID4"].Value);
                fishes[i++] = new Fishie(node.Attributes["name"].Value, rod, node.Attributes["ID1"].Value, node.Attributes["ID2"].Value, node.Attributes["ID3"].Value);
            }

            return(fishes);
        } // @ internal static Fishie[] GetFishes(string rod, string zone, string bait, bool wanted)
Ejemplo n.º 5
0
        } // @ internal static void AddNewFish(ref string fish, string zone, string bait, string rod, string ID1, string ID2, string ID3, string ID4, bool wanted)

        internal static void ChangeName(Fishie fish, string newName)
        {
            XmlDocument xmlDoc = GetFishDB(fish.rod);
            //old: string xpathQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"][@ID4=\"{4}\"]", fish.name, fish.ID1, fish.ID2, fish.ID3, fish.ID4);
            //old: string xpathOldQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"][@ID4=\"{4}\"]", newName, fish.ID1, fish.ID2, fish.ID3, fish.ID4);
            string xpathQuery    = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"]", fish.name, fish.ID1, fish.ID2, fish.ID3);
            string xpathOldQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"]", newName, fish.ID1, fish.ID2, fish.ID3);
            //check if there is already an entry with same ID and name = newName, if there is, merge the 2 entries
            XmlNode oldFishNode = xmlDoc.SelectSingleNode(xpathOldQuery);
            XmlNode fishNode    = xmlDoc.SelectSingleNode(xpathQuery);

            if (null == oldFishNode)
            {
                fishNode.Attributes["name"].Value = newName;
                FishDBChanged(fish.rod);
            }
            else
            {
                //merging (union of Zones and Baits)
                XmlNodeList zones = fishNode["Zones"].ChildNodes;
                XmlNodeList baits = fishNode["Baits"].ChildNodes;

                foreach (XmlNode zone in zones)
                {
                    if (null == oldFishNode.SelectSingleNode("Zones/Zone[text()=\"" + zone.InnerText + "\"]"))
                    {
                        XmlNode zoneNode = oldFishNode["Zones"].AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "Zone", xmlDoc.NamespaceURI));
                        zoneNode.InnerText = zone.InnerText;
                    }
                }

                foreach (XmlNode bait in baits)
                {
                    if (null == oldFishNode.SelectSingleNode("Baits/Bait[text()=\"" + bait.InnerText + "\"]"))
                    {
                        XmlNode baitNode = oldFishNode["Baits"].AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "Bait", xmlDoc.NamespaceURI));
                        baitNode.InnerText = bait.InnerText;
                    }
                }

                xmlDoc["Rod"].RemoveChild(fishNode);
                FishDBChanged(fish.rod);
            }
        } // @ internal static void ChangeName(Fishie fish, string newName)
Ejemplo n.º 6
0
 internal static void ToggleWanted(Fishie fish)
 {
     XmlDocument xmlDoc = GetFishDB(fish.rod);
     string xpathQuery = string.Format("/Rod/Fish[@name=\"{0}\"]", fish.name);
     XmlNode fishNode = xmlDoc.SelectSingleNode(xpathQuery);
     fishNode.Attributes["wanted"].Value = ("Yes" == fishNode.Attributes["wanted"].Value) ? "No" : "Yes";
     FishDBChanged(fish.rod);
 }
Ejemplo n.º 7
0
        internal static Fishie[] GetFishes(string rod, string zone, string bait, bool wanted)
        {
            XmlDocument xmlDoc = GetFishDB(rod);
            string xpathQuery = string.Format("/Rod/Fish[Zones/Zone=\"{0}\"][Baits/Bait=\"{1}\"][@wanted=\"{2}\"]", zone, bait, wanted ? "Yes" : "No");
            XmlNodeList nodes = xmlDoc.SelectNodes(xpathQuery);
            Fishie[] fishes = new Fishie[nodes.Count];
            int i = 0;

            foreach(XmlNode node in nodes)
            {
                //old: fishes[i++] = new Fishie(node.Attributes["name"].Value, rod, node.Attributes["ID1"].Value, node.Attributes["ID2"].Value, node.Attributes["ID3"].Value, node.Attributes["ID4"].Value);
                fishes[i++] = new Fishie(node.Attributes["name"].Value, rod, node.Attributes["ID1"].Value, node.Attributes["ID2"].Value, node.Attributes["ID3"].Value);
            }

            return fishes;
        }
Ejemplo n.º 8
0
        internal static void ChangeName(Fishie fish, string newName)
        {
            XmlDocument xmlDoc = GetFishDB(fish.rod);
            //old: string xpathQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"][@ID4=\"{4}\"]", fish.name, fish.ID1, fish.ID2, fish.ID3, fish.ID4);
            //old: string xpathOldQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"][@ID4=\"{4}\"]", newName, fish.ID1, fish.ID2, fish.ID3, fish.ID4);
            string xpathQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"]", fish.name, fish.ID1, fish.ID2, fish.ID3);
            string xpathOldQuery = string.Format("/Rod/Fish[@name=\"{0}\"][@ID1=\"{1}\"][@ID2=\"{2}\"][@ID3=\"{3}\"]", newName, fish.ID1, fish.ID2, fish.ID3);
            //check if there is already an entry with same ID and name = newName, if there is, merge the 2 entries
            XmlNode oldFishNode = xmlDoc.SelectSingleNode(xpathOldQuery);
            XmlNode fishNode = xmlDoc.SelectSingleNode(xpathQuery);

            if(null == oldFishNode)
            {
                fishNode.Attributes["name"].Value = newName;
                FishDBChanged(fish.rod);
            }
            else
            {
                //merging (union of Zones and Baits)
                XmlNodeList zones = fishNode["Zones"].ChildNodes;
                XmlNodeList baits = fishNode["Baits"].ChildNodes;

                foreach(XmlNode zone in zones)
                {
                    if(null == oldFishNode.SelectSingleNode("Zones/Zone[text()=\"" + zone.InnerText + "\"]"))
                    {
                        XmlNode zoneNode = oldFishNode["Zones"].AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "Zone", xmlDoc.NamespaceURI));
                        zoneNode.InnerText = zone.InnerText;
                    }
                }

                foreach(XmlNode bait in baits)
                {
                    if(null == oldFishNode.SelectSingleNode("Baits/Bait[text()=\"" + bait.InnerText + "\"]"))
                    {
                        XmlNode baitNode = oldFishNode["Baits"].AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "Bait", xmlDoc.NamespaceURI));
                        baitNode.InnerText = bait.InnerText;
                    }
                }

                xmlDoc["Rod"].RemoveChild(fishNode);
                FishDBChanged(fish.rod);
            }
        }
Ejemplo n.º 9
0
        } // @ internal static void AddNewFish(ref string fish, string zone, string bait, string rod, string ID1, string ID2, string ID3, string ID4, bool wanted)

        /// <summary>
        /// Rename a fish.
        /// </summary>
        /// <param name="fish">Old fish name</param>
        /// <param name="newName">New fish name</param>
        /// <param name="fromDB">true if the rename is from the DB. This overrides
        /// saving the XML files, due to issues from repeated saves.</param>
        internal static void ChangeName(Fishie fish, string newName, bool fromDB)
        {
            XmlDocument xmlDoc      = GetFishDB(fish.rod);
            XmlNode     oldFishNode = xmlDoc.SelectSingleNode(string.Format(XPathFormatFishByNameAndIDs, newName, fish.ID1, fish.ID2, fish.ID3));
            XmlNode     fishNode    = xmlDoc.SelectSingleNode(string.Format(XPathFormatFishByNameAndIDs, fish.name, fish.ID1, fish.ID2, fish.ID3));

            // If there is no fish by the name being renamed from, return
            // TODO log this somehow
            if (null == fishNode)
            {
                return;
            }

            //check if there is already an entry with same ID and name = newName, if there is, merge the 2 entries
            if (null == oldFishNode)
            {
                // Not an entry with the same ID and name
                fishNode.Attributes[XMLAttrName].Value = newName;
                // Mark for adding to DB if it's a new fish being renamed
                if (null != fishNode.Attributes[XMLAttrNew])
                {
                    SetNew(fish.rod, fishNode, fishNode);
                }
                else
                {
                    SetRenamed(fish.name, fishNode);
                }
                if (!fromDB)
                {
                    FishDBChanged(fish.rod);
                }
            }
            else
            {
                //merging (union of Zones and Baits)
                XmlNodeList zones = fishNode[XMLNodeZones].ChildNodes;
                XmlNodeList baits = fishNode[XMLNodeBaits].ChildNodes;

                foreach (XmlNode zone in zones)
                {
                    if (null == oldFishNode.SelectSingleNode(string.Format(XPathFormatZoneByName, zone.InnerText)))
                    {
                        XmlNode zoneNode = oldFishNode[XMLNodeZones].AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, XMLNodeZone, xmlDoc.NamespaceURI));
                        zoneNode.InnerText = zone.InnerText;
                    }
                }

                foreach (XmlNode bait in baits)
                {
                    if (null == oldFishNode.SelectSingleNode(string.Format(XPathFormatBaitByName, bait.InnerText)))
                    {
                        XmlNode baitNode = oldFishNode[XMLNodeBaits].AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, XMLNodeBait, xmlDoc.NamespaceURI));
                        baitNode.InnerText = bait.InnerText;
                    }
                }

                xmlDoc[XMLNodeRod].RemoveChild(fishNode);
                if (!fromDB)
                {
                    SetRenamed(fish.name, fishNode);
                    FishDBChanged(fish.rod);
                }
            }
        } // @ internal static void ChangeName(Fishie fish, string newName)