Esempio n. 1
0
        public static bool SaveDecks(Account account)
        {
            bool blnRet = false;

            List <Deck> lstDecks = Reflection.GetDecks();

            if (lstDecks != null && (lstDecks.Count > 0 && lstDecks[0].Cards.Count > 0) && !s_blnSaveDecksInProgress)
            {
                s_blnSaveDecksInProgress = true;

                List <CachedDeck> lstCachedDecks = new List <CachedDeck>();

                for (int i = 0; i < lstDecks.Count; i++)
                {
                    Deck deck = lstDecks[i];

                    CachedDeck cachedDeck = new CachedDeck()
                    {
                        Id          = deck.Id,
                        Name        = deck.Name,
                        Hero        = deck.Hero,
                        IsWild      = deck.IsWild,
                        Type        = deck.Type,
                        SeasonId    = deck.SeasonId,
                        CardBackId  = deck.CardBackId,
                        HeroPremium = deck.HeroPremium,
                        Cards       = deck.Cards.ToCachedCards()
                    };

                    lstCachedDecks.Add(cachedDeck);
                }

                string strPath = DustUtilityPlugin.GetFullFileName(account, DecksString);

                if (File.Exists(strPath))
                {
                    File.Delete(strPath);
                }
                else
                {
                }

                using (StreamWriter writer = new StreamWriter(strPath))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List <CachedDeck>));

                    serializer.Serialize(writer, lstCachedDecks);
                }

                blnRet = true;

                s_blnSaveDecksInProgress = false;
            }
            else
            {
            }

            return(blnRet);
        }
Esempio n. 2
0
        public static List <Deck> LoadDecks(Account account)
        {
            List <Deck> lstRet = new List <Deck>();

            try
            {
                string strPath = DustUtilityPlugin.GetFullFileName(account, DecksString);

                if (File.Exists(strPath))
                {
                    List <CachedDeck> lstCachedDecks = FileManager.Load <List <CachedDeck> >(strPath);

                    for (int i = 0; i < lstCachedDecks.Count; i++)
                    {
                        CachedDeck cachedDeck = lstCachedDecks[i];

                        Deck deck = new Deck()
                        {
                            Id          = cachedDeck.Id,
                            Name        = cachedDeck.Name,
                            Hero        = cachedDeck.Hero,
                            IsWild      = cachedDeck.IsWild,
                            Type        = cachedDeck.Type,
                            SeasonId    = cachedDeck.SeasonId,
                            CardBackId  = cachedDeck.CardBackId,
                            HeroPremium = cachedDeck.HeroPremium,
                            Cards       = cachedDeck.Cards.ToCards()
                        };

                        lstRet.Add(deck);
                    }
                }
                else
                {
                }
            }
            catch (System.Exception ex)
            {
                Log.WriteLine($"Exception occured while loading decks: {ex}", LogType.Error);
            }

            return(lstRet);
        }
Esempio n. 3
0
        public static List <Deck> LoadDecks(Account account)
        {
            List <Deck> lstRet = new List <Deck>();

            string strPath = DustUtilityPlugin.GetFullFileName(account, DecksString);

            if (File.Exists(strPath))
            {
                List <CachedDeck> lstCachedDecks = new List <CachedDeck>();

                using (StreamReader reader = new StreamReader(strPath))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List <CachedDeck>));

                    lstCachedDecks = (List <CachedDeck>)serializer.Deserialize(reader);
                }

                for (int i = 0; i < lstCachedDecks.Count; i++)
                {
                    CachedDeck cachedDeck = lstCachedDecks[i];

                    Deck deck = new Deck()
                    {
                        Id          = cachedDeck.Id,
                        Name        = cachedDeck.Name,
                        Hero        = cachedDeck.Hero,
                        IsWild      = cachedDeck.IsWild,
                        Type        = cachedDeck.Type,
                        SeasonId    = cachedDeck.SeasonId,
                        CardBackId  = cachedDeck.CardBackId,
                        HeroPremium = cachedDeck.HeroPremium,
                        Cards       = cachedDeck.Cards.ToCards()
                    };

                    lstRet.Add(deck);
                }
            }
            else
            {
            }

            return(lstRet);
        }