예제 #1
0
        /// <summary>
        /// Saving to Disk , this fucntion needs to be Async and have a Status Datatrigger for View animation.
        /// </summary>
        private void SaveTheDeck()
        {
            IsBusy = true;

            try
            {
                GenerateRootPath();

                CreatedTime = DateTime.Now;
                CreatedBy   = Environment.UserName;

                List <CardPair> _pairs = Collection.ToList();

                foreach (CardPair pair in _pairs)
                {
                    if (pair.IsDeleted)
                    {
                        Collection.Remove(pair);
                        continue;
                    }
                }

                foreach (CardPair pair in Collection)
                {
                    CopyResources(pair.Card1);
                    CopyResources(pair.Card2);
                }

                string path = RootPath + "\\deck.xml";


                File.Delete(path);

                FileStream fs = File.Create(path);

                XmlSerializer SerializerObj = new XmlSerializer(typeof(CardDeck));
                SerializerObj.Serialize(fs, this);

                fs.Close();

                if (!MainViewModel.Instance.Decks.Collection.Contains(this))
                {
                    MainViewModel.Instance.Decks.Collection.Add(this);
                }

                Taskbar.AddEntryToJumpList(ZipPath, Title);

                DeckPackagingHelper.PackageDeck(RootPath, Title);
            }
            catch (Exception e)
            {
                Utils.LogException(MethodBase.GetCurrentMethod(), e);

                //There are some problem Saving the Deck..
                IsBusy = false;
            }

            IsBusy  = false;
            IsDirty = false;

            Count = _cardPairs.Count;
        }